@@ -10,71 +10,71 @@ discard block |
||
10 | 10 | { |
11 | 11 | use \Anax\DI\TInjectable; |
12 | 12 | |
13 | - public $id; |
|
13 | + public $id; |
|
14 | 14 | |
15 | 15 | |
16 | - /** |
|
17 | - * Get the table name. |
|
18 | - * |
|
19 | - * @return string with the table name. |
|
20 | - */ |
|
21 | - public function getSource() |
|
22 | - { |
|
23 | - return strtolower(implode('', array_slice(explode('\\', get_class($this)), -1))); |
|
24 | - } |
|
16 | + /** |
|
17 | + * Get the table name. |
|
18 | + * |
|
19 | + * @return string with the table name. |
|
20 | + */ |
|
21 | + public function getSource() |
|
22 | + { |
|
23 | + return strtolower(implode('', array_slice(explode('\\', get_class($this)), -1))); |
|
24 | + } |
|
25 | 25 | |
26 | - /** |
|
27 | - * Find and return all. |
|
28 | - * |
|
29 | - * @return array |
|
30 | - */ |
|
31 | - public function findAll() |
|
32 | - { |
|
33 | - $this->db->select() |
|
34 | - ->from($this->getSource()); |
|
26 | + /** |
|
27 | + * Find and return all. |
|
28 | + * |
|
29 | + * @return array |
|
30 | + */ |
|
31 | + public function findAll() |
|
32 | + { |
|
33 | + $this->db->select() |
|
34 | + ->from($this->getSource()); |
|
35 | 35 | |
36 | - $this->db->execute(); |
|
37 | - $this->db->setFetchModeClass(__CLASS__); |
|
38 | - return $this->db->fetchAll(); |
|
39 | - } |
|
36 | + $this->db->execute(); |
|
37 | + $this->db->setFetchModeClass(__CLASS__); |
|
38 | + return $this->db->fetchAll(); |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * Get object properties. |
|
43 | - * |
|
44 | - * @return array with object properties. |
|
45 | - */ |
|
46 | - public function getProperties() |
|
47 | - { |
|
48 | - $properties = get_object_vars($this); |
|
49 | - unset($properties['di']); |
|
50 | - unset($properties['db']); |
|
41 | + /** |
|
42 | + * Get object properties. |
|
43 | + * |
|
44 | + * @return array with object properties. |
|
45 | + */ |
|
46 | + public function getProperties() |
|
47 | + { |
|
48 | + $properties = get_object_vars($this); |
|
49 | + unset($properties['di']); |
|
50 | + unset($properties['db']); |
|
51 | 51 | |
52 | - return $properties; |
|
53 | - } |
|
52 | + return $properties; |
|
53 | + } |
|
54 | 54 | |
55 | 55 | |
56 | - /** |
|
57 | - * Find and return specific. |
|
58 | - * |
|
59 | - * @return this |
|
60 | - */ |
|
61 | - public function find($id) |
|
62 | - { |
|
56 | + /** |
|
57 | + * Find and return specific. |
|
58 | + * |
|
59 | + * @return this |
|
60 | + */ |
|
61 | + public function find($id) |
|
62 | + { |
|
63 | 63 | $this->db->select() |
64 | - ->from($this->getSource()) |
|
65 | - ->where("id = ?"); |
|
64 | + ->from($this->getSource()) |
|
65 | + ->where("id = ?"); |
|
66 | 66 | |
67 | 67 | $this->db->execute([$id]); |
68 | 68 | return $this->db->fetchInto($this); |
69 | - } |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * Save current object/row. |
|
73 | - * |
|
74 | - * @param array $values key/values to save or empty to use object properties. |
|
75 | - * |
|
76 | - * @return boolean true or false if saving went okey. |
|
77 | - */ |
|
71 | + /** |
|
72 | + * Save current object/row. |
|
73 | + * |
|
74 | + * @param array $values key/values to save or empty to use object properties. |
|
75 | + * |
|
76 | + * @return boolean true or false if saving went okey. |
|
77 | + */ |
|
78 | 78 | public function save($values = []) |
79 | 79 | { |
80 | 80 | |
@@ -86,151 +86,151 @@ discard block |
||
86 | 86 | } else { |
87 | 87 | return $this->create($values); |
88 | 88 | } |
89 | - } |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * Set object properties. |
|
93 | - * |
|
94 | - * @param array $properties with properties to set. |
|
95 | - * |
|
96 | - * @return void |
|
97 | - */ |
|
98 | - public function setProperties($properties) |
|
99 | - { |
|
100 | - // Update object with incoming values, if any |
|
101 | - if (!empty($properties)) { |
|
102 | - foreach ($properties as $key => $val) { |
|
103 | - $this->$key = $val; |
|
104 | - } |
|
105 | - } |
|
106 | - } |
|
91 | + /** |
|
92 | + * Set object properties. |
|
93 | + * |
|
94 | + * @param array $properties with properties to set. |
|
95 | + * |
|
96 | + * @return void |
|
97 | + */ |
|
98 | + public function setProperties($properties) |
|
99 | + { |
|
100 | + // Update object with incoming values, if any |
|
101 | + if (!empty($properties)) { |
|
102 | + foreach ($properties as $key => $val) { |
|
103 | + $this->$key = $val; |
|
104 | + } |
|
105 | + } |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * Create new row. |
|
110 | - * |
|
111 | - * @param array $values key/values to save. |
|
112 | - * |
|
113 | - * @return boolean true or false if saving went okey. |
|
114 | - */ |
|
115 | - public function create($values) |
|
116 | - { |
|
117 | - $keys = array_keys($values); |
|
118 | - $values = array_values($values); |
|
108 | + /** |
|
109 | + * Create new row. |
|
110 | + * |
|
111 | + * @param array $values key/values to save. |
|
112 | + * |
|
113 | + * @return boolean true or false if saving went okey. |
|
114 | + */ |
|
115 | + public function create($values) |
|
116 | + { |
|
117 | + $keys = array_keys($values); |
|
118 | + $values = array_values($values); |
|
119 | 119 | |
120 | - $this->db->insert( |
|
121 | - $this->getSource(), |
|
122 | - $keys |
|
123 | - ); |
|
120 | + $this->db->insert( |
|
121 | + $this->getSource(), |
|
122 | + $keys |
|
123 | + ); |
|
124 | 124 | |
125 | - $res = $this->db->execute($values); |
|
125 | + $res = $this->db->execute($values); |
|
126 | 126 | |
127 | - $this->id = $this->db->lastInsertId(); |
|
127 | + $this->id = $this->db->lastInsertId(); |
|
128 | 128 | |
129 | - return $res; |
|
130 | - } |
|
129 | + return $res; |
|
130 | + } |
|
131 | 131 | |
132 | 132 | |
133 | - /** |
|
134 | - * Update row. |
|
135 | - * |
|
136 | - * @param array $values key/values to save. |
|
137 | - * |
|
138 | - * @return boolean true or false if saving went okey. |
|
139 | - */ |
|
140 | - public function update($values) |
|
141 | - { |
|
133 | + /** |
|
134 | + * Update row. |
|
135 | + * |
|
136 | + * @param array $values key/values to save. |
|
137 | + * |
|
138 | + * @return boolean true or false if saving went okey. |
|
139 | + */ |
|
140 | + public function update($values) |
|
141 | + { |
|
142 | 142 | |
143 | - $keys = array_keys($values); |
|
144 | - $values = array_values($values); |
|
143 | + $keys = array_keys($values); |
|
144 | + $values = array_values($values); |
|
145 | 145 | |
146 | - // Its update, remove id and use as where-clause |
|
147 | - unset($keys['id']); |
|
146 | + // Its update, remove id and use as where-clause |
|
147 | + unset($keys['id']); |
|
148 | 148 | |
149 | - $values[] = $this->id; |
|
149 | + $values[] = $this->id; |
|
150 | 150 | |
151 | - $this->db->update( |
|
152 | - $this->getSource(), |
|
153 | - $keys, |
|
154 | - "id = ?" |
|
155 | - ); |
|
151 | + $this->db->update( |
|
152 | + $this->getSource(), |
|
153 | + $keys, |
|
154 | + "id = ?" |
|
155 | + ); |
|
156 | 156 | |
157 | - return $this->db->execute($values); |
|
158 | - } |
|
157 | + return $this->db->execute($values); |
|
158 | + } |
|
159 | 159 | |
160 | - /** |
|
161 | - * Delete row. |
|
162 | - * |
|
163 | - * @param integer $id to delete. |
|
164 | - * |
|
165 | - * @return boolean true or false if deleting went okey. |
|
166 | - */ |
|
167 | - public function delete($id) |
|
168 | - { |
|
169 | - $this->db->delete( |
|
170 | - $this->getSource(), |
|
171 | - 'id = ?' |
|
172 | - ); |
|
160 | + /** |
|
161 | + * Delete row. |
|
162 | + * |
|
163 | + * @param integer $id to delete. |
|
164 | + * |
|
165 | + * @return boolean true or false if deleting went okey. |
|
166 | + */ |
|
167 | + public function delete($id) |
|
168 | + { |
|
169 | + $this->db->delete( |
|
170 | + $this->getSource(), |
|
171 | + 'id = ?' |
|
172 | + ); |
|
173 | 173 | |
174 | - return $this->db->execute([$id]); |
|
175 | - } |
|
174 | + return $this->db->execute([$id]); |
|
175 | + } |
|
176 | 176 | |
177 | 177 | |
178 | - /** |
|
179 | - * Build a select-query. |
|
180 | - * |
|
181 | - * @param string $columns which columns to select. |
|
182 | - * |
|
183 | - * @return $this |
|
184 | - */ |
|
185 | - public function query($columns = '*') |
|
186 | - { |
|
187 | - $this->db->select($columns) |
|
188 | - ->from($this->getSource()); |
|
178 | + /** |
|
179 | + * Build a select-query. |
|
180 | + * |
|
181 | + * @param string $columns which columns to select. |
|
182 | + * |
|
183 | + * @return $this |
|
184 | + */ |
|
185 | + public function query($columns = '*') |
|
186 | + { |
|
187 | + $this->db->select($columns) |
|
188 | + ->from($this->getSource()); |
|
189 | 189 | |
190 | - return $this; |
|
191 | - } |
|
190 | + return $this; |
|
191 | + } |
|
192 | 192 | |
193 | - /** |
|
194 | - * Build the where part. |
|
195 | - * |
|
196 | - * @param string $condition for building the where part of the query. |
|
197 | - * |
|
198 | - * @return $this |
|
199 | - */ |
|
200 | - public function where($condition) |
|
201 | - { |
|
202 | - $this->db->where($condition); |
|
193 | + /** |
|
194 | + * Build the where part. |
|
195 | + * |
|
196 | + * @param string $condition for building the where part of the query. |
|
197 | + * |
|
198 | + * @return $this |
|
199 | + */ |
|
200 | + public function where($condition) |
|
201 | + { |
|
202 | + $this->db->where($condition); |
|
203 | 203 | |
204 | - return $this; |
|
205 | - } |
|
204 | + return $this; |
|
205 | + } |
|
206 | 206 | |
207 | - /** |
|
208 | - * Build the where part. |
|
209 | - * |
|
210 | - * @param string $condition for building the where part of the query. |
|
211 | - * |
|
212 | - * @return $this |
|
213 | - */ |
|
214 | - public function andWhere($condition) |
|
215 | - { |
|
216 | - $this->db->andWhere($condition); |
|
207 | + /** |
|
208 | + * Build the where part. |
|
209 | + * |
|
210 | + * @param string $condition for building the where part of the query. |
|
211 | + * |
|
212 | + * @return $this |
|
213 | + */ |
|
214 | + public function andWhere($condition) |
|
215 | + { |
|
216 | + $this->db->andWhere($condition); |
|
217 | 217 | |
218 | - return $this; |
|
219 | - } |
|
218 | + return $this; |
|
219 | + } |
|
220 | 220 | |
221 | - /** |
|
222 | - * Execute the query built. |
|
223 | - * |
|
224 | - * @param array $params |
|
225 | - * |
|
226 | - * @return $this |
|
227 | - */ |
|
228 | - public function execute($params = []) |
|
229 | - { |
|
230 | - $this->db->execute($this->db->getSQL(), $params); |
|
231 | - $this->db->setFetchModeClass(__CLASS__); |
|
221 | + /** |
|
222 | + * Execute the query built. |
|
223 | + * |
|
224 | + * @param array $params |
|
225 | + * |
|
226 | + * @return $this |
|
227 | + */ |
|
228 | + public function execute($params = []) |
|
229 | + { |
|
230 | + $this->db->execute($this->db->getSQL(), $params); |
|
231 | + $this->db->setFetchModeClass(__CLASS__); |
|
232 | 232 | |
233 | - return $this->db->fetchAll(); |
|
234 | - } |
|
233 | + return $this->db->fetchAll(); |
|
234 | + } |
|
235 | 235 | |
236 | 236 | } |