FS_Entity

The NextGEN Gallery FS Entity class.

Defined (1)

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

/freemius/includes/entities/class-fs-entity.php  
  1. class FS_Entity { 
  2. /** 
  3. * @var number 
  4. */ 
  5. public $id; 
  6. /** 
  7. * @var string Datetime value in 'YYYY-MM-DD HH:MM:SS' format. 
  8. */ 
  9. public $updated; 
  10. /** 
  11. * @var string Datetime value in 'YYYY-MM-DD HH:MM:SS' format. 
  12. */ 
  13. public $created; 
  14.  
  15. /** 
  16. * @param bool|object $entity 
  17. */ 
  18. function __construct( $entity = false ) { 
  19. if ( ! ( $entity instanceof stdClass ) ) { 
  20. return; 
  21.  
  22. $props = fs_get_object_public_vars( $this ); 
  23.  
  24. foreach ( $props as $key => $def_value ) { 
  25. $this->{$key} = isset( $entity->{$key} ) ? 
  26. $entity->{$key} : 
  27. $def_value; 
  28.  
  29. static function get_type() { 
  30. return 'type'; 
  31.  
  32. /** 
  33. * @author Vova Feldman (@svovaf) 
  34. * @since 1.0.6 
  35. * @param FS_Entity $entity1 
  36. * @param FS_Entity $entity2 
  37. * @return bool 
  38. */ 
  39. static function equals( $entity1, $entity2 ) { 
  40. if ( is_null( $entity1 ) && is_null( $entity2 ) ) { 
  41. return true; 
  42. } else if ( is_object( $entity1 ) && is_object( $entity2 ) ) { 
  43. return ( $entity1->id == $entity2->id ); 
  44. } else if ( is_object( $entity1 ) ) { 
  45. return is_null( $entity1->id ); 
  46. } else { 
  47. return is_null( $entity2->id ); 
  48.  
  49. private $_is_updated = false; 
  50.  
  51. /** 
  52. * Update object property. 
  53. * @author Vova Feldman (@svovaf) 
  54. * @since 1.0.9 
  55. * @param string|array[string]mixed $key 
  56. * @param string|bool $val 
  57. * @return bool 
  58. */ 
  59. function update( $key, $val = false ) { 
  60. if ( ! is_array( $key ) ) { 
  61. $key = array( $key => $val ); 
  62.  
  63. $is_updated = false; 
  64.  
  65. foreach ( $key as $k => $v ) { 
  66. if ( $this->{$k} === $v ) { 
  67. continue; 
  68.  
  69. if ( ( is_string( $this->{$k} ) && is_numeric( $v ) || 
  70. ( is_numeric( $this->{$k} ) && is_string( $v ) ) ) && 
  71. $this->{$k} == $v 
  72. ) { 
  73. continue; 
  74.  
  75. // Update value. 
  76. $this->{$k} = $v; 
  77.  
  78. $is_updated = true; 
  79.  
  80. $this->_is_updated = $is_updated; 
  81.  
  82. return $is_updated; 
  83.  
  84. /** 
  85. * Checks if entity was updated. 
  86. * @author Vova Feldman (@svovaf) 
  87. * @since 1.0.9 
  88. * @return bool 
  89. */ 
  90. function is_updated() { 
  91. return $this->_is_updated; 
  92.  
  93. /** 
  94. * @param $id 
  95. * @author Vova Feldman (@svovaf) 
  96. * @since 1.1.2 
  97. * @return bool 
  98. */ 
  99. static function is_valid_id($id) { 
  100. return is_numeric($id);