Naguro_Modules_Repository

The WooCommerce Naguro Connect Naguro Modules Repository class.

Defined (1)

The class is defined in the following location(s).

/includes/naguro/repositories/class-modules-repository.php  
  1. class Naguro_Modules_Repository extends Naguro_Repository { 
  2.  
  3. /** 
  4. * @param $slug 
  5. * @return Naguro_Module_Model 
  6. */ 
  7. public static function get_module_by_slug( $slug ) { 
  8. $modules = self::get_modules(); 
  9.  
  10. foreach ( $modules as $key => $module ) { 
  11. if ( $module->slug === $slug ) { 
  12. return $module; 
  13.  
  14. return false; 
  15.  
  16. public static function get_active_modules() { 
  17. $modules = self::get_modules(); 
  18.  
  19. foreach ( $modules as $key => $module ) { 
  20. if ( ! $module->active ) { 
  21. unset( $modules[ $key ] ); 
  22.  
  23. return $modules; 
  24.  
  25. public static function get_locked_modules() { 
  26. $modules = self::get_modules(); 
  27.  
  28. foreach ( $modules as $key => $module ) { 
  29. if ( $module->unlocked ) { 
  30. unset( $modules[ $key ] ); 
  31.  
  32. return $modules; 
  33.  
  34. public static function get_unlocked_modules() { 
  35. $modules = self::get_modules(); 
  36.  
  37. foreach ( $modules as $key => $module ) { 
  38. if ( ! $module->unlocked ) { 
  39. unset( $modules[ $key ] ); 
  40.  
  41. return $modules; 
  42.  
  43. public static function get_modules() { 
  44. $transient_data = get_transient( 'naguro_modules' ); 
  45. $active_modules_array = get_option('naguro_active_modules', array() ); 
  46.  
  47. if ( false !== $transient_data && ! empty( $transient_data ) ) { 
  48. foreach ( $transient_data as $key => $module ) { 
  49. if ( in_array( $module->slug, $active_modules_array ) ) { 
  50. $transient_data[ $key ]->active = true; 
  51. } else { 
  52. $transient_data[ $key ]->active = false; 
  53.  
  54. return $transient_data; 
  55.  
  56. $request = new Naguro_Get_Modules_Request( array() ); 
  57. $modules = $request->do_request(); 
  58. $modules = json_decode($modules['body']); 
  59.  
  60. $module_map = array( 
  61. 'core' => 'Naguro_Core_Module',  
  62. 'overlay' => 'Naguro_Overlay_Module',  
  63. 'shirt' => 'Naguro_Shirt_Module',  
  64. ); 
  65.  
  66. $module_array = array(); 
  67.  
  68. foreach ( $modules->data as $module ) { 
  69. if ( isset( $module_map[ $module->slug ] ) ) { 
  70. $module_object = new $module_map[ $module->slug ](); 
  71. $module_object->slug = $module->slug; 
  72. $module_object->name = $module->name; 
  73. $module_object->description = $module->description; 
  74. $module_object->always_on = $module->always_on; 
  75. $module_object->unlocked = $module->unlocked; 
  76. $module_object->purchase_url = $module->purchase_url; 
  77.  
  78. if ( in_array( $module->slug, $active_modules_array ) ) { 
  79. $module_object->active = true; 
  80.  
  81. $module_array[ $module->slug ] = $module_object; 
  82.  
  83. set_transient( 'naguro_modules', $module_array, DAY_IN_SECONDS ); 
  84.  
  85. return $module_array;