| 1 |
<?php |
| 2 |
/** |
| 3 |
* |
| 4 |
*/ |
| 5 |
|
| 6 |
/** |
| 7 |
* |
| 8 |
*/ |
| 9 |
abstract class CJTServicesEntityModel { |
| 10 |
|
| 11 |
/** |
| 12 |
* put your comment there... |
| 13 |
* |
| 14 |
* @param mixed $data |
| 15 |
* @return CJTServicesItemModel |
| 16 |
*/ |
| 17 |
public function __construct($data = null) { |
| 18 |
# Make sure data is array |
| 19 |
if( ! $data ) { |
| 20 |
$data = array(); |
| 21 |
} |
| 22 |
# Fill with data |
| 23 |
$this->exchangeArray( $data ); |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* put your comment there... |
| 28 |
* |
| 29 |
* @param mixed $data |
| 30 |
*/ |
| 31 |
public function exchangeArray($data) { |
| 32 |
# Fetch properties for all model members |
| 33 |
foreach ( get_object_vars( $this ) as $name => $value ) { |
| 34 |
$this->$name = isset( $data[ $name ] ) ? $data[ $name ] : null; |
| 35 |
} |
| 36 |
# Chain |
| 37 |
return $this; |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* put your comment there... |
| 42 |
* |
| 43 |
*/ |
| 44 |
public function getArray() { |
| 45 |
# Gett all vars |
| 46 |
$vars = get_object_vars( $this ); |
| 47 |
# Exclude NULL values |
| 48 |
foreach ( $vars as $name => $value ) { |
| 49 |
if ( $value === null ) { |
| 50 |
unset( $vars[ $name ] ); |
| 51 |
} |
| 52 |
} |
| 53 |
return $vars; |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* put your comment there... |
| 58 |
* |
| 59 |
* @param CJTServicesEntityModel $model |
| 60 |
* @return CJTServicesEntityModel |
| 61 |
*/ |
| 62 |
public function isEqual(CJTServicesEntityModel & $model) { |
| 63 |
return md5( print_r( get_object_vars( $this ), true ) ) == md5( print_r( get_object_vars( $model ), true ) ); |
| 64 |
} |
| 65 |
} |
| 66 |
|