PluginProbe
FluentSnippets – High-Performance Code Snippets, Header & Footer Code, Custom CSS & PHP Code Manager / 10
FluentSnippets – High-Performance Code Snippets, Header & Footer Code, Custom CSS & PHP Code Manager v10
10.56 1.2.1 10 10.1 10.2 10.3 10.31 10.32 10.33 10.34 10.50 10.51 10.52 10.53 10.55 9.0 9.0.1 9.4 trunk 1.0.0 1.1 1.2
easy-code-manager / framework / ServicesFW / EntityModel.class.php

EntityModel.class.php in FluentSnippets – High-Performance Code Snippets, Header & Footer Code, Custom CSS & PHP Code Manager 10, at framework/ServicesFW/EntityModel.class.php

145 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 *
4 */
5
6 /**
7 *
8 */
9 abstract class CJTServicesEntityModel {
10
11 /**
12 * put your comment there...
13 *
14 * @var mixed
15 */
16 protected $_propPrefix;
17
18 /**
19 * put your comment there...
20 *
21 * @param mixed $data
22 * @return CJTServicesItemModel
23 */
24 public function __construct($data = null)
25 {
26
27 # Make sure data is array
28 if(!$data)
29 {
30 $data = array();
31 }
32
33 # Fill with data
34 $this->exchangeArray($data);
35 }
36
37 /**
38 * put your comment there...
39 *
40 * @param mixed $data
41 */
42 public function exchangeArray($data)
43 {
44
45 # Fetch properties for all model members
46 foreach (get_object_vars($this) as $name => $value)
47 {
48
49 # Don't process Private properties
50 if (!$this->isPrivateProp($name))
51 {
52 $propName = $this->getPropertyName($name);
53
54 $this->$name = isset($data[$propName]) ? $data[$propName] : null;
55 }
56
57 }
58
59 # Chain
60 return $this;
61 }
62
63 /**
64 * put your comment there...
65 *
66 */
67 public function getArray()
68 {
69
70 # Gett all vars
71 $vars = get_object_vars($this);
72 $array = array();
73
74 # Exclude NULL values
75 foreach ($vars as $name => $value)
76 {
77 # Don't copy private prop or NULL fields
78 if (!$this->isPrivateProp($name) && ($value !== null))
79 {
80
81 $propName = $this->getPropertyName($name);
82
83 $array[$propName] = $value;
84 }
85
86 }
87
88 return $array;
89 }
90
91 /**
92 * put your comment there...
93 *
94 * @param mixed $name
95 */
96 protected function getPropertyName($name)
97 {
98 return "{$this->_propPrefix}{$name}";
99 }
100
101 /**
102 * put your comment there...
103 *
104 */
105 public function getVarsArray()
106 {
107
108 # Gett all vars
109 $vars = get_object_vars($this);
110
111 # Exclude NULL values
112 foreach ($vars as $name => $value)
113 {
114 if ($this->isPrivateProp($name) || ($value === null))
115 {
116 unset($vars[$name]);
117 }
118 }
119
120 return $vars;
121 }
122
123 /**
124 * put your comment there...
125 *
126 * @param CJTServicesEntityModel $model
127 * @return CJTServicesEntityModel
128 */
129 public function isEqual(CJTServicesEntityModel & $model)
130 {
131 return md5(print_r(get_object_vars($this), true)) == md5(print_r(get_object_vars($model), true));
132 }
133
134 /**
135 * put your comment there...
136 *
137 * @param mixed $name
138 */
139 protected function isPrivateProp($name)
140 {
141 return (strpos($name, '_') === 0);
142 }
143
144 }
145