@@ -10,71 +10,71 @@ discard block |
||
10 | 10 | { |
11 | 11 | use \Anax\DI\TInjectable; |
12 | 12 | |
13 | - //private $id; |
|
13 | + //private $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 | |
@@ -87,149 +87,149 @@ discard block |
||
87 | 87 | } else { |
88 | 88 | return $this->create($values); |
89 | 89 | } |
90 | - } |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * Set object properties. |
|
94 | - * |
|
95 | - * @param array $properties with properties to set. |
|
96 | - * |
|
97 | - * @return void |
|
98 | - */ |
|
99 | - public function setProperties($properties) |
|
100 | - { |
|
101 | - // Update object with incoming values, if any |
|
102 | - if (!empty($properties)) { |
|
103 | - foreach ($properties as $key => $val) { |
|
104 | - $this->$key = $val; |
|
105 | - } |
|
106 | - } |
|
107 | - } |
|
92 | + /** |
|
93 | + * Set object properties. |
|
94 | + * |
|
95 | + * @param array $properties with properties to set. |
|
96 | + * |
|
97 | + * @return void |
|
98 | + */ |
|
99 | + public function setProperties($properties) |
|
100 | + { |
|
101 | + // Update object with incoming values, if any |
|
102 | + if (!empty($properties)) { |
|
103 | + foreach ($properties as $key => $val) { |
|
104 | + $this->$key = $val; |
|
105 | + } |
|
106 | + } |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * Create new row. |
|
111 | - * |
|
112 | - * @param array $values key/values to save. |
|
113 | - * |
|
114 | - * @return boolean true or false if saving went okey. |
|
115 | - */ |
|
116 | - public function create($values) |
|
117 | - { |
|
118 | - $keys = array_keys($values); |
|
119 | - $values = array_values($values); |
|
109 | + /** |
|
110 | + * Create new row. |
|
111 | + * |
|
112 | + * @param array $values key/values to save. |
|
113 | + * |
|
114 | + * @return boolean true or false if saving went okey. |
|
115 | + */ |
|
116 | + public function create($values) |
|
117 | + { |
|
118 | + $keys = array_keys($values); |
|
119 | + $values = array_values($values); |
|
120 | 120 | |
121 | - $this->db->insert( |
|
122 | - $this->getSource(), |
|
123 | - $keys |
|
124 | - ); |
|
121 | + $this->db->insert( |
|
122 | + $this->getSource(), |
|
123 | + $keys |
|
124 | + ); |
|
125 | 125 | |
126 | - $res = $this->db->execute($values); |
|
126 | + $res = $this->db->execute($values); |
|
127 | 127 | |
128 | - $id = $this->db->lastInsertId(); |
|
128 | + $id = $this->db->lastInsertId(); |
|
129 | 129 | |
130 | - return $res; |
|
131 | - } |
|
130 | + return $res; |
|
131 | + } |
|
132 | 132 | |
133 | 133 | |
134 | - /** |
|
135 | - * Update row. |
|
136 | - * |
|
137 | - * @param array $values key/values to save. |
|
138 | - * |
|
139 | - * @return boolean true or false if saving went okey. |
|
140 | - */ |
|
141 | - public function update($values) |
|
142 | - { |
|
143 | - $keys = array_keys($values); |
|
144 | - $values = array_values($values); |
|
134 | + /** |
|
135 | + * Update row. |
|
136 | + * |
|
137 | + * @param array $values key/values to save. |
|
138 | + * |
|
139 | + * @return boolean true or false if saving went okey. |
|
140 | + */ |
|
141 | + public function update($values) |
|
142 | + { |
|
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']); |
|
148 | - $values[] = $this->id; |
|
146 | + // Its update, remove id and use as where-clause |
|
147 | + unset($keys['id']); |
|
148 | + $values[] = $this->id; |
|
149 | 149 | |
150 | - $this->db->update( |
|
151 | - $this->getSource(), |
|
152 | - $keys, |
|
153 | - "id = ?" |
|
154 | - ); |
|
150 | + $this->db->update( |
|
151 | + $this->getSource(), |
|
152 | + $keys, |
|
153 | + "id = ?" |
|
154 | + ); |
|
155 | 155 | |
156 | - return $this->db->execute($values); |
|
157 | - } |
|
156 | + return $this->db->execute($values); |
|
157 | + } |
|
158 | 158 | |
159 | - /** |
|
160 | - * Delete row. |
|
161 | - * |
|
162 | - * @param integer $id to delete. |
|
163 | - * |
|
164 | - * @return boolean true or false if deleting went okey. |
|
165 | - */ |
|
166 | - public function delete($id) |
|
167 | - { |
|
168 | - $this->db->delete( |
|
169 | - $this->getSource(), |
|
170 | - 'id = ?' |
|
171 | - ); |
|
159 | + /** |
|
160 | + * Delete row. |
|
161 | + * |
|
162 | + * @param integer $id to delete. |
|
163 | + * |
|
164 | + * @return boolean true or false if deleting went okey. |
|
165 | + */ |
|
166 | + public function delete($id) |
|
167 | + { |
|
168 | + $this->db->delete( |
|
169 | + $this->getSource(), |
|
170 | + 'id = ?' |
|
171 | + ); |
|
172 | 172 | |
173 | - return $this->db->execute([$id]); |
|
174 | - } |
|
173 | + return $this->db->execute([$id]); |
|
174 | + } |
|
175 | 175 | |
176 | 176 | |
177 | - /** |
|
178 | - * Build a select-query. |
|
179 | - * |
|
180 | - * @param string $columns which columns to select. |
|
181 | - * |
|
182 | - * @return $this |
|
183 | - */ |
|
184 | - public function query($columns = '*') |
|
185 | - { |
|
186 | - $this->db->select($columns) |
|
187 | - ->from($this->getSource()); |
|
177 | + /** |
|
178 | + * Build a select-query. |
|
179 | + * |
|
180 | + * @param string $columns which columns to select. |
|
181 | + * |
|
182 | + * @return $this |
|
183 | + */ |
|
184 | + public function query($columns = '*') |
|
185 | + { |
|
186 | + $this->db->select($columns) |
|
187 | + ->from($this->getSource()); |
|
188 | 188 | |
189 | - return $this; |
|
190 | - } |
|
189 | + return $this; |
|
190 | + } |
|
191 | 191 | |
192 | - /** |
|
193 | - * Build the where part. |
|
194 | - * |
|
195 | - * @param string $condition for building the where part of the query. |
|
196 | - * |
|
197 | - * @return $this |
|
198 | - */ |
|
199 | - public function where($condition) |
|
200 | - { |
|
201 | - $this->db->where($condition); |
|
192 | + /** |
|
193 | + * Build the where part. |
|
194 | + * |
|
195 | + * @param string $condition for building the where part of the query. |
|
196 | + * |
|
197 | + * @return $this |
|
198 | + */ |
|
199 | + public function where($condition) |
|
200 | + { |
|
201 | + $this->db->where($condition); |
|
202 | 202 | |
203 | - return $this; |
|
204 | - } |
|
203 | + return $this; |
|
204 | + } |
|
205 | 205 | |
206 | - /** |
|
207 | - * Build the where part. |
|
208 | - * |
|
209 | - * @param string $condition for building the where part of the query. |
|
210 | - * |
|
211 | - * @return $this |
|
212 | - */ |
|
213 | - public function andWhere($condition) |
|
214 | - { |
|
215 | - $this->db->andWhere($condition); |
|
206 | + /** |
|
207 | + * Build the where part. |
|
208 | + * |
|
209 | + * @param string $condition for building the where part of the query. |
|
210 | + * |
|
211 | + * @return $this |
|
212 | + */ |
|
213 | + public function andWhere($condition) |
|
214 | + { |
|
215 | + $this->db->andWhere($condition); |
|
216 | 216 | |
217 | - return $this; |
|
218 | - } |
|
217 | + return $this; |
|
218 | + } |
|
219 | 219 | |
220 | - /** |
|
221 | - * Execute the query built. |
|
222 | - * |
|
223 | - * @param array $params |
|
224 | - * |
|
225 | - * @return $this |
|
226 | - */ |
|
227 | - public function execute($params = []) |
|
228 | - { |
|
229 | - $this->db->execute($this->db->getSQL(), $params); |
|
230 | - $this->db->setFetchModeClass(__CLASS__); |
|
220 | + /** |
|
221 | + * Execute the query built. |
|
222 | + * |
|
223 | + * @param array $params |
|
224 | + * |
|
225 | + * @return $this |
|
226 | + */ |
|
227 | + public function execute($params = []) |
|
228 | + { |
|
229 | + $this->db->execute($this->db->getSQL(), $params); |
|
230 | + $this->db->setFetchModeClass(__CLASS__); |
|
231 | 231 | |
232 | - return $this->db->fetchAll(); |
|
233 | - } |
|
232 | + return $this->db->fetchAll(); |
|
233 | + } |
|
234 | 234 | |
235 | 235 | } |
@@ -12,61 +12,61 @@ |
||
12 | 12 | |
13 | 13 | private $model; |
14 | 14 | |
15 | - /** |
|
16 | - * Lists all instances of the model, (databasetable) except for noListing. |
|
17 | - * |
|
18 | - * @param $noListing params not to be listed |
|
19 | - * @param $model model object to list (create an html table from) |
|
20 | - * |
|
21 | - * @return void |
|
22 | - */ |
|
23 | - public function listAction($noListing = NULL, $model) |
|
24 | - { |
|
15 | + /** |
|
16 | + * Lists all instances of the model, (databasetable) except for noListing. |
|
17 | + * |
|
18 | + * @param $noListing params not to be listed |
|
19 | + * @param $model model object to list (create an html table from) |
|
20 | + * |
|
21 | + * @return void |
|
22 | + */ |
|
23 | + public function listAction($noListing = NULL, $model) |
|
24 | + { |
|
25 | 25 | |
26 | - $this->model = $model; |
|
27 | - $this->model->setDI($this->di); |
|
26 | + $this->model = $model; |
|
27 | + $this->model->setDI($this->di); |
|
28 | 28 | |
29 | - $all = $this->model->findAll(); |
|
29 | + $all = $this->model->findAll(); |
|
30 | 30 | |
31 | - $aContent = array(); |
|
31 | + $aContent = array(); |
|
32 | 32 | |
33 | - //gör om arrayen av objekt till en array av arrayer |
|
34 | - foreach ($all as $key1=>$value) { |
|
33 | + //gör om arrayen av objekt till en array av arrayer |
|
34 | + foreach ($all as $key1=>$value) { |
|
35 | 35 | foreach ($value as $key2=>$v){ |
36 | - if (!in_array($key2, $noListing)) { //$noListing, parametrar som inte ska vara med |
|
37 | - $aContent[$key1][$key2] = $v; |
|
38 | - } |
|
36 | + if (!in_array($key2, $noListing)) { //$noListing, parametrar som inte ska vara med |
|
37 | + $aContent[$key1][$key2] = $v; |
|
38 | + } |
|
39 | + } |
|
39 | 40 | } |
40 | - } |
|
41 | 41 | |
42 | 42 | |
43 | - $aHeading = []; |
|
44 | - //hittar objektens parametrar/tabellens kolumnnamn och skapar |
|
45 | - //en ny array av rubriker |
|
46 | - foreach ($all as $key1=>$value) { |
|
43 | + $aHeading = []; |
|
44 | + //hittar objektens parametrar/tabellens kolumnnamn och skapar |
|
45 | + //en ny array av rubriker |
|
46 | + foreach ($all as $key1=>$value) { |
|
47 | 47 | foreach ($value as $key2=>$v){ |
48 | - if (!in_array($key2, $noListing)) { //$noListing, parametrar som inte ska vara med |
|
49 | - $aHeading[] = $key2; |
|
50 | - } |
|
48 | + if (!in_array($key2, $noListing)) { //$noListing, parametrar som inte ska vara med |
|
49 | + $aHeading[] = $key2; |
|
50 | + } |
|
51 | 51 | } |
52 | 52 | break; |
53 | - } |
|
53 | + } |
|
54 | 54 | |
55 | - $chtml = new \Jovis\HTMLTable\CHTMLTable($aHeading, $aContent); |
|
55 | + $chtml = new \Jovis\HTMLTable\CHTMLTable($aHeading, $aContent); |
|
56 | 56 | |
57 | - $htmltable = $chtml->getTable(); |
|
58 | - $source = $this->model->getSource(); |
|
57 | + $htmltable = $chtml->getTable(); |
|
58 | + $source = $this->model->getSource(); |
|
59 | 59 | |
60 | 60 | |
61 | - $this->theme->setTitle("Visa alla användare"); |
|
62 | - $this->views->add('table/list-all', [ |
|
63 | - 'title' => $source, |
|
64 | - 'htmltable' => $htmltable, |
|
65 | - ]); |
|
66 | - } |
|
61 | + $this->theme->setTitle("Visa alla användare"); |
|
62 | + $this->views->add('table/list-all', [ |
|
63 | + 'title' => $source, |
|
64 | + 'htmltable' => $htmltable, |
|
65 | + ]); |
|
66 | + } |
|
67 | 67 | |
68 | - public function initAction($model){ //används för att befolka databasen, bara för att testa |
|
68 | + public function initAction($model){ //används för att befolka databasen, bara för att testa |
|
69 | 69 | $model->setDI($this->di); |
70 | 70 | $model->init(); |
71 | - } |
|
71 | + } |
|
72 | 72 | } |