@@ -437,6 +437,9 @@ discard block |
||
437 | 437 | } |
438 | 438 | } |
439 | 439 | |
440 | + /** |
|
441 | + * @param boolean $new |
|
442 | + */ |
|
440 | 443 | public function logChanges($new) { |
441 | 444 | if (!App::$cur->db->connect || !App::$cur->dashboard) { |
442 | 445 | return false; |
@@ -539,7 +542,7 @@ discard block |
||
539 | 542 | /** |
540 | 543 | * Information extractor for col relations path |
541 | 544 | * |
542 | - * @param string|array $info |
|
545 | + * @param string $info |
|
543 | 546 | * @return array |
544 | 547 | */ |
545 | 548 | public static function parseColRecursion($info) { |
@@ -625,7 +628,7 @@ discard block |
||
625 | 628 | * Generate params string for col by name |
626 | 629 | * |
627 | 630 | * @param string $colName |
628 | - * @return boolean|string |
|
631 | + * @return false|string |
|
629 | 632 | */ |
630 | 633 | public static function genColParams($colName) { |
631 | 634 | if (empty(static::$cols[$colName]) || static::$storage['type'] == 'moduleConfig') { |
@@ -780,7 +783,7 @@ discard block |
||
780 | 783 | /** |
781 | 784 | * return relations list |
782 | 785 | * |
783 | - * @return array |
|
786 | + * @return string |
|
784 | 787 | */ |
785 | 788 | public static function relations() { |
786 | 789 | return []; |
@@ -1303,7 +1306,7 @@ discard block |
||
1303 | 1306 | * |
1304 | 1307 | * @param array $params |
1305 | 1308 | * @param array $where |
1306 | - * @return boolean |
|
1309 | + * @return false|null |
|
1307 | 1310 | */ |
1308 | 1311 | public static function update($params, $where = []) { |
1309 | 1312 | static::fixPrefix($params); |
@@ -10,244 +10,244 @@ discard block |
||
10 | 10 | */ |
11 | 11 | class Model { |
12 | 12 | |
13 | - /** |
|
14 | - * Object storage type |
|
15 | - * |
|
16 | - * @var array |
|
17 | - */ |
|
18 | - public static $storage = ['type' => 'db']; |
|
19 | - |
|
20 | - /** |
|
21 | - * Object name |
|
22 | - * |
|
23 | - * @var string |
|
24 | - */ |
|
25 | - public static $objectName = ''; |
|
26 | - |
|
27 | - /** |
|
28 | - * App type for separate data storage |
|
29 | - * |
|
30 | - * @var string |
|
31 | - */ |
|
32 | - public $appType = 'app'; |
|
33 | - |
|
34 | - /** |
|
35 | - * Object current params |
|
36 | - * |
|
37 | - * @var array |
|
38 | - */ |
|
39 | - public $_params = []; |
|
40 | - |
|
41 | - /** |
|
42 | - * List of changed params in current instance |
|
43 | - * |
|
44 | - * @var array |
|
45 | - */ |
|
46 | - public $_changedParams = []; |
|
47 | - |
|
48 | - /** |
|
49 | - * Loaded relations |
|
50 | - * |
|
51 | - * @var array |
|
52 | - */ |
|
53 | - public $loadedRelations = []; |
|
54 | - |
|
55 | - /** |
|
56 | - * Model name where this model uses as category |
|
57 | - * |
|
58 | - * @var string |
|
59 | - */ |
|
60 | - public static $treeCategory = ''; |
|
61 | - |
|
62 | - /** |
|
63 | - * Model name who uses as category in this model |
|
64 | - * |
|
65 | - * @var string |
|
66 | - */ |
|
67 | - public static $categoryModel = ''; |
|
68 | - |
|
69 | - /** |
|
70 | - * Col labels |
|
71 | - * |
|
72 | - * @var array |
|
73 | - */ |
|
74 | - public static $labels = []; |
|
75 | - |
|
76 | - /** |
|
77 | - * Model forms |
|
78 | - * |
|
79 | - * @var array |
|
80 | - */ |
|
81 | - public static $forms = []; |
|
82 | - |
|
83 | - /** |
|
84 | - * Model cols |
|
85 | - * |
|
86 | - * @var array |
|
87 | - */ |
|
88 | - public static $cols = []; |
|
89 | - |
|
90 | - /** |
|
91 | - * Options group for display inforamtion from model |
|
92 | - * |
|
93 | - * @var array |
|
94 | - */ |
|
95 | - public static $view = []; |
|
96 | - |
|
97 | - /** |
|
98 | - * List of relations need loaded with item |
|
99 | - * |
|
100 | - * @var array |
|
101 | - */ |
|
102 | - public static $needJoin = []; |
|
103 | - |
|
104 | - /** |
|
105 | - * List of joins who need to laod |
|
106 | - * |
|
107 | - * @var array |
|
108 | - */ |
|
109 | - public static $relJoins = []; |
|
110 | - |
|
111 | - /** |
|
112 | - * Set params when model create |
|
113 | - * |
|
114 | - * @param array $params |
|
115 | - */ |
|
116 | - public function __construct($params = []) { |
|
13 | + /** |
|
14 | + * Object storage type |
|
15 | + * |
|
16 | + * @var array |
|
17 | + */ |
|
18 | + public static $storage = ['type' => 'db']; |
|
19 | + |
|
20 | + /** |
|
21 | + * Object name |
|
22 | + * |
|
23 | + * @var string |
|
24 | + */ |
|
25 | + public static $objectName = ''; |
|
26 | + |
|
27 | + /** |
|
28 | + * App type for separate data storage |
|
29 | + * |
|
30 | + * @var string |
|
31 | + */ |
|
32 | + public $appType = 'app'; |
|
33 | + |
|
34 | + /** |
|
35 | + * Object current params |
|
36 | + * |
|
37 | + * @var array |
|
38 | + */ |
|
39 | + public $_params = []; |
|
40 | + |
|
41 | + /** |
|
42 | + * List of changed params in current instance |
|
43 | + * |
|
44 | + * @var array |
|
45 | + */ |
|
46 | + public $_changedParams = []; |
|
47 | + |
|
48 | + /** |
|
49 | + * Loaded relations |
|
50 | + * |
|
51 | + * @var array |
|
52 | + */ |
|
53 | + public $loadedRelations = []; |
|
54 | + |
|
55 | + /** |
|
56 | + * Model name where this model uses as category |
|
57 | + * |
|
58 | + * @var string |
|
59 | + */ |
|
60 | + public static $treeCategory = ''; |
|
61 | + |
|
62 | + /** |
|
63 | + * Model name who uses as category in this model |
|
64 | + * |
|
65 | + * @var string |
|
66 | + */ |
|
67 | + public static $categoryModel = ''; |
|
68 | + |
|
69 | + /** |
|
70 | + * Col labels |
|
71 | + * |
|
72 | + * @var array |
|
73 | + */ |
|
74 | + public static $labels = []; |
|
75 | + |
|
76 | + /** |
|
77 | + * Model forms |
|
78 | + * |
|
79 | + * @var array |
|
80 | + */ |
|
81 | + public static $forms = []; |
|
82 | + |
|
83 | + /** |
|
84 | + * Model cols |
|
85 | + * |
|
86 | + * @var array |
|
87 | + */ |
|
88 | + public static $cols = []; |
|
89 | + |
|
90 | + /** |
|
91 | + * Options group for display inforamtion from model |
|
92 | + * |
|
93 | + * @var array |
|
94 | + */ |
|
95 | + public static $view = []; |
|
96 | + |
|
97 | + /** |
|
98 | + * List of relations need loaded with item |
|
99 | + * |
|
100 | + * @var array |
|
101 | + */ |
|
102 | + public static $needJoin = []; |
|
103 | + |
|
104 | + /** |
|
105 | + * List of joins who need to laod |
|
106 | + * |
|
107 | + * @var array |
|
108 | + */ |
|
109 | + public static $relJoins = []; |
|
110 | + |
|
111 | + /** |
|
112 | + * Set params when model create |
|
113 | + * |
|
114 | + * @param array $params |
|
115 | + */ |
|
116 | + public function __construct($params = []) { |
|
117 | 117 | $this->setParams($params); |
118 | - } |
|
118 | + } |
|
119 | 119 | |
120 | - public static $logging = true; |
|
120 | + public static $logging = true; |
|
121 | 121 | |
122 | - /** |
|
123 | - * return object name |
|
124 | - * |
|
125 | - * @return string |
|
126 | - */ |
|
127 | - public static function objectName() { |
|
122 | + /** |
|
123 | + * return object name |
|
124 | + * |
|
125 | + * @return string |
|
126 | + */ |
|
127 | + public static function objectName() { |
|
128 | 128 | return static::$objectName; |
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Retrn col value with col params and relations path |
|
133 | - * |
|
134 | - * @param Model $object |
|
135 | - * @param string $valuePath |
|
136 | - * @param boolean $convert |
|
137 | - * @param boolean $manageHref |
|
138 | - * @return string |
|
139 | - */ |
|
140 | - public static function getColValue($object, $valuePath, $convert = false, $manageHref = false) { |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * Retrn col value with col params and relations path |
|
133 | + * |
|
134 | + * @param Model $object |
|
135 | + * @param string $valuePath |
|
136 | + * @param boolean $convert |
|
137 | + * @param boolean $manageHref |
|
138 | + * @return string |
|
139 | + */ |
|
140 | + public static function getColValue($object, $valuePath, $convert = false, $manageHref = false) { |
|
141 | 141 | if (strpos($valuePath, ':')) { |
142 | - $rel = substr($valuePath, 0, strpos($valuePath, ':')); |
|
143 | - $param = substr($valuePath, strpos($valuePath, ':') + 1); |
|
144 | - if (!$object->$rel) { |
|
142 | + $rel = substr($valuePath, 0, strpos($valuePath, ':')); |
|
143 | + $param = substr($valuePath, strpos($valuePath, ':') + 1); |
|
144 | + if (!$object->$rel) { |
|
145 | 145 | $modelName = get_class($object); |
146 | 146 | $relations = $modelName::relations(); |
147 | 147 | if (empty($relations[$rel]['type']) || $relations[$rel]['type'] == 'one') { |
148 | - return $object->{$relations[$rel]['col']}; |
|
148 | + return $object->{$relations[$rel]['col']}; |
|
149 | 149 | } |
150 | 150 | return 0; |
151 | - } |
|
152 | - if (strpos($valuePath, ':')) { |
|
151 | + } |
|
152 | + if (strpos($valuePath, ':')) { |
|
153 | 153 | return self::getColValue($object->$rel, $param, $convert, $manageHref); |
154 | - } else { |
|
154 | + } else { |
|
155 | 155 | return $convert ? Model::resloveTypeValue($object->$rel, $param, $manageHref) : $object->$rel->$param; |
156 | - } |
|
156 | + } |
|
157 | 157 | } else { |
158 | - return $convert ? Model::resloveTypeValue($object, $valuePath, $manageHref) : $object->$valuePath; |
|
159 | - } |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * Retrun value for view |
|
164 | - * |
|
165 | - * @param Model $item |
|
166 | - * @param string $colName |
|
167 | - * @param boolean $manageHref |
|
168 | - * @return string |
|
169 | - */ |
|
170 | - public static function resloveTypeValue($item, $colName, $manageHref = false) { |
|
158 | + return $convert ? Model::resloveTypeValue($object, $valuePath, $manageHref) : $object->$valuePath; |
|
159 | + } |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * Retrun value for view |
|
164 | + * |
|
165 | + * @param Model $item |
|
166 | + * @param string $colName |
|
167 | + * @param boolean $manageHref |
|
168 | + * @return string |
|
169 | + */ |
|
170 | + public static function resloveTypeValue($item, $colName, $manageHref = false) { |
|
171 | 171 | $modelName = get_class($item); |
172 | 172 | $colInfo = $modelName::getColInfo($colName); |
173 | 173 | $type = !empty($colInfo['colParams']['type']) ? $colInfo['colParams']['type'] : 'string'; |
174 | 174 | $value = ''; |
175 | 175 | switch ($type) { |
176 | - case 'select': |
|
176 | + case 'select': |
|
177 | 177 | switch ($colInfo['colParams']['source']) { |
178 | - case 'model': |
|
178 | + case 'model': |
|
179 | 179 | $sourceValue = ''; |
180 | 180 | if ($item->$colName) { |
181 | - $sourceValue = $colInfo['colParams']['model']::get($item->$colName); |
|
181 | + $sourceValue = $colInfo['colParams']['model']::get($item->$colName); |
|
182 | 182 | } |
183 | 183 | $value = $sourceValue ? $sourceValue->name() : 'Не задано'; |
184 | 184 | break; |
185 | - case 'array': |
|
185 | + case 'array': |
|
186 | 186 | $value = !empty($colInfo['colParams']['sourceArray'][$item->$colName]) ? $colInfo['colParams']['sourceArray'][$item->$colName] : 'Не задано'; |
187 | 187 | if (is_array($value) && $value['text']) { |
188 | - $value = $value['text']; |
|
188 | + $value = $value['text']; |
|
189 | 189 | } |
190 | 190 | break; |
191 | - case 'bool': |
|
191 | + case 'bool': |
|
192 | 192 | return $item->$colName ? 'Да' : 'Нет'; |
193 | - case 'method': |
|
193 | + case 'method': |
|
194 | 194 | if (!empty($colInfo['colParams']['params'])) { |
195 | - $values = call_user_func_array([App::$cur->$colInfo['colParams']['module'], $colInfo['colParams']['method']], $colInfo['colParams']['params']); |
|
195 | + $values = call_user_func_array([App::$cur->$colInfo['colParams']['module'], $colInfo['colParams']['method']], $colInfo['colParams']['params']); |
|
196 | 196 | } else { |
197 | - $values = $colInfo['colParams']['module']->$colInfo['colParams']['method'](); |
|
197 | + $values = $colInfo['colParams']['module']->$colInfo['colParams']['method'](); |
|
198 | 198 | } |
199 | 199 | $value = !empty($values[$item->$colName]) ? $values[$item->$colName] : 'Не задано'; |
200 | 200 | break; |
201 | - case 'void': |
|
201 | + case 'void': |
|
202 | 202 | if (!empty($modelName::$cols[$colName]['value']['type']) && $modelName::$cols[$colName]['value']['type'] == 'moduleMethod') { |
203 | - return \App::$cur->{$modelName::$cols[$colName]['value']['module']}->{$modelName::$cols[$colName]['value']['method']}($item, $colName, $modelName::$cols[$colName]); |
|
203 | + return \App::$cur->{$modelName::$cols[$colName]['value']['module']}->{$modelName::$cols[$colName]['value']['method']}($item, $colName, $modelName::$cols[$colName]); |
|
204 | 204 | } |
205 | 205 | break; |
206 | - case 'relation': |
|
206 | + case 'relation': |
|
207 | 207 | $relations = $colInfo['modelName']::relations(); |
208 | 208 | $relValue = $relations[$colInfo['colParams']['relation']]['model']::get($item->$colName); |
209 | 209 | $relModel = $relations[$colInfo['colParams']['relation']]['model']; |
210 | 210 | $relModel = strpos($relModel, '\\') === 0 ? substr($relModel, 1) : $relModel; |
211 | 211 | if ($manageHref) { |
212 | - $value = $relValue ? "<a href='/admin/" . str_replace('\\', '/view/', $relModel) . "/" . $relValue->pk() . "'>" . $relValue->name() . "</a>" : 'Не задано'; |
|
212 | + $value = $relValue ? "<a href='/admin/" . str_replace('\\', '/view/', $relModel) . "/" . $relValue->pk() . "'>" . $relValue->name() . "</a>" : 'Не задано'; |
|
213 | 213 | } else { |
214 | - $value = $relValue ? $relValue->name() : 'Не задано'; |
|
214 | + $value = $relValue ? $relValue->name() : 'Не задано'; |
|
215 | 215 | } |
216 | 216 | break; |
217 | 217 | } |
218 | 218 | break; |
219 | - case 'image': |
|
219 | + case 'image': |
|
220 | 220 | $file = Files\File::get($item->$colName); |
221 | 221 | if ($file) { |
222 | - $value = '<img src="' . $file->path . '?resize=60x120" />'; |
|
222 | + $value = '<img src="' . $file->path . '?resize=60x120" />'; |
|
223 | 223 | } else { |
224 | - $value = '<img src="/static/system/images/no-image.png?resize=60x120" />'; |
|
224 | + $value = '<img src="/static/system/images/no-image.png?resize=60x120" />'; |
|
225 | 225 | } |
226 | 226 | break; |
227 | - case 'file': |
|
227 | + case 'file': |
|
228 | 228 | $file = Files\File::get($item->$colName); |
229 | 229 | if ($file) { |
230 | - $value = '<a href="' . $file->path . '">' . $file->name . '.' . $file->type->ext . '</a>'; |
|
230 | + $value = '<a href="' . $file->path . '">' . $file->name . '.' . $file->type->ext . '</a>'; |
|
231 | 231 | } else { |
232 | - $value = 'Файл не загружен'; |
|
232 | + $value = 'Файл не загружен'; |
|
233 | 233 | } |
234 | 234 | break; |
235 | - case 'bool': |
|
235 | + case 'bool': |
|
236 | 236 | $value = $item->$colName ? 'Да' : 'Нет'; |
237 | 237 | break; |
238 | - case 'void': |
|
238 | + case 'void': |
|
239 | 239 | if (!empty($colInfo['colParams']['value']['type']) && $colInfo['colParams']['value']['type'] == 'moduleMethod') { |
240 | - return \App::$cur->{$colInfo['colParams']['value']['module']}->{$colInfo['colParams']['value']['method']}($item, $colName, $colInfo['colParams']); |
|
240 | + return \App::$cur->{$colInfo['colParams']['value']['module']}->{$colInfo['colParams']['value']['method']}($item, $colName, $colInfo['colParams']); |
|
241 | 241 | } |
242 | 242 | break; |
243 | - case 'map': |
|
243 | + case 'map': |
|
244 | 244 | if ($item->$colName && json_decode($item->$colName, true)) { |
245 | - $addres = json_decode($item->$colName, true); |
|
246 | - $name = $addres['address'] ? $addres['address'] : 'lat:' . $addres['lat'] . ': lng:' . $addres['lng']; |
|
247 | - \App::$cur->libs->loadLib('yandexMap'); |
|
248 | - ob_start(); |
|
249 | - $uid = Tools::randomString(); |
|
250 | - ?> |
|
245 | + $addres = json_decode($item->$colName, true); |
|
246 | + $name = $addres['address'] ? $addres['address'] : 'lat:' . $addres['lat'] . ': lng:' . $addres['lng']; |
|
247 | + \App::$cur->libs->loadLib('yandexMap'); |
|
248 | + ob_start(); |
|
249 | + $uid = Tools::randomString(); |
|
250 | + ?> |
|
251 | 251 | <div id='map<?= $uid; ?>_container' style="display:none;"><script>/* |
252 | 252 | <div id='map<?= $uid; ?>' style="width: 100%; height: 500px"></div> |
253 | 253 | <script> |
@@ -273,45 +273,45 @@ discard block |
||
273 | 273 | */</script> |
274 | 274 | </div> |
275 | 275 | <?php |
276 | - $content = ob_get_contents(); |
|
277 | - ob_end_clean(); |
|
278 | - $onclick = 'inji.Ui.modals.show("' . addcslashes($addres['address'], '"') . '", $("#map' . $uid . '_container script").html().replace(/^\/\*/g, "").replace(/\*\/$/g, "")+"</script>","mapmodal' . $uid . '","modal-lg");'; |
|
279 | - $onclick .= 'return false;'; |
|
280 | - $value = "<a href ='#' onclick='{$onclick}' >{$name}</a>"; |
|
281 | - $value .= $content; |
|
276 | + $content = ob_get_contents(); |
|
277 | + ob_end_clean(); |
|
278 | + $onclick = 'inji.Ui.modals.show("' . addcslashes($addres['address'], '"') . '", $("#map' . $uid . '_container script").html().replace(/^\/\*/g, "").replace(/\*\/$/g, "")+"</script>","mapmodal' . $uid . '","modal-lg");'; |
|
279 | + $onclick .= 'return false;'; |
|
280 | + $value = "<a href ='#' onclick='{$onclick}' >{$name}</a>"; |
|
281 | + $value .= $content; |
|
282 | 282 | } else { |
283 | - $value = 'Местоположение не заданно'; |
|
283 | + $value = 'Местоположение не заданно'; |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | break; |
287 | - case 'dynamicType': |
|
287 | + case 'dynamicType': |
|
288 | 288 | switch ($colInfo['colParams']['typeSource']) { |
289 | - case'selfMethod': |
|
289 | + case'selfMethod': |
|
290 | 290 | $type = $item->{$colInfo['colParams']['selfMethod']}(); |
291 | 291 | if (is_array($type)) { |
292 | - if (strpos($type['relation'], ':')) { |
|
292 | + if (strpos($type['relation'], ':')) { |
|
293 | 293 | $relationPath = explode(':', $type['relation']); |
294 | 294 | $relationName = array_pop($relationPath); |
295 | 295 | $curItem = $item; |
296 | 296 | foreach ($relationPath as $path) { |
297 | - $curItem = $curItem->$path; |
|
297 | + $curItem = $curItem->$path; |
|
298 | 298 | } |
299 | 299 | $itemModel = get_class($curItem); |
300 | 300 | $relation = $itemModel::getRelation($relationName); |
301 | 301 | $sourceModel = $relation['model']; |
302 | - } else { |
|
302 | + } else { |
|
303 | 303 | $relation = static::getRelation($type['relation']); |
304 | 304 | $sourceModel = $relation['model']; |
305 | - } |
|
306 | - $inputType = 'select'; |
|
307 | - $value = $sourceModel::get($item->$colName); |
|
308 | - if ($value) { |
|
305 | + } |
|
306 | + $inputType = 'select'; |
|
307 | + $value = $sourceModel::get($item->$colName); |
|
308 | + if ($value) { |
|
309 | 309 | $value = $value->name(); |
310 | - } else { |
|
310 | + } else { |
|
311 | 311 | $value = $item->$colName; |
312 | - } |
|
312 | + } |
|
313 | 313 | } else { |
314 | - switch ($type) { |
|
314 | + switch ($type) { |
|
315 | 315 | case 'map': |
316 | 316 | if ($item->$colName && json_decode($item->$colName, true)) { |
317 | 317 | $addres = json_decode($item->$colName, true); |
@@ -351,126 +351,126 @@ discard block |
||
351 | 351 | $onclick .= 'return false;'; |
352 | 352 | $value = "<a href ='#' onclick='{$onclick}' >{$name}</a>"; |
353 | 353 | $value .= $content; |
354 | - } else { |
|
354 | + } else { |
|
355 | 355 | $value = 'Местоположение не заданно'; |
356 | - } |
|
356 | + } |
|
357 | 357 | |
358 | - break; |
|
358 | + break; |
|
359 | 359 | default: |
360 | 360 | $value = $item->$colName; |
361 | - } |
|
361 | + } |
|
362 | 362 | } |
363 | 363 | break; |
364 | 364 | } |
365 | 365 | break; |
366 | - default: |
|
366 | + default: |
|
367 | 367 | $value = $item->$colName; |
368 | 368 | break; |
369 | 369 | } |
370 | 370 | return $value; |
371 | - } |
|
372 | - |
|
373 | - /** |
|
374 | - * Fix col prefix |
|
375 | - * |
|
376 | - * @param mixed $array |
|
377 | - * @param string $searchtype |
|
378 | - * @param string $rootModel |
|
379 | - * @return null |
|
380 | - */ |
|
381 | - public static function fixPrefix(&$array, $searchtype = 'key', $rootModel = '') { |
|
371 | + } |
|
372 | + |
|
373 | + /** |
|
374 | + * Fix col prefix |
|
375 | + * |
|
376 | + * @param mixed $array |
|
377 | + * @param string $searchtype |
|
378 | + * @param string $rootModel |
|
379 | + * @return null |
|
380 | + */ |
|
381 | + public static function fixPrefix(&$array, $searchtype = 'key', $rootModel = '') { |
|
382 | 382 | if (!$rootModel) { |
383 | - $rootModel = get_called_class(); |
|
383 | + $rootModel = get_called_class(); |
|
384 | 384 | } |
385 | 385 | $cols = static::cols(); |
386 | 386 | if (!$array) { |
387 | - return; |
|
387 | + return; |
|
388 | 388 | } |
389 | 389 | if (!is_array($array)) { |
390 | - if (!isset($cols[static::colPrefix() . $array]) && isset(static::$cols[$array])) { |
|
390 | + if (!isset($cols[static::colPrefix() . $array]) && isset(static::$cols[$array])) { |
|
391 | 391 | static::createCol($array); |
392 | 392 | $cols = static::cols(true); |
393 | - } |
|
394 | - if (!isset($cols[$array]) && isset($cols[static::colPrefix() . $array])) { |
|
393 | + } |
|
394 | + if (!isset($cols[$array]) && isset($cols[static::colPrefix() . $array])) { |
|
395 | 395 | $array = static::colPrefix() . $array; |
396 | - } else { |
|
396 | + } else { |
|
397 | 397 | static::checkForJoin($array, $rootModel); |
398 | - } |
|
399 | - return; |
|
398 | + } |
|
399 | + return; |
|
400 | 400 | } |
401 | 401 | switch ($searchtype) { |
402 | - case 'key': |
|
402 | + case 'key': |
|
403 | 403 | foreach ($array as $key => $item) { |
404 | - if (!isset($cols[static::colPrefix() . $key]) && isset(static::$cols[$key])) { |
|
404 | + if (!isset($cols[static::colPrefix() . $key]) && isset(static::$cols[$key])) { |
|
405 | 405 | static::createCol($key); |
406 | 406 | $cols = static::cols(true); |
407 | - } |
|
408 | - if (!isset($cols[$key]) && isset($cols[static::colPrefix() . $key])) { |
|
407 | + } |
|
408 | + if (!isset($cols[$key]) && isset($cols[static::colPrefix() . $key])) { |
|
409 | 409 | $array[static::colPrefix() . $key] = $item; |
410 | 410 | unset($array[$key]); |
411 | 411 | $key = static::colPrefix() . $key; |
412 | - } |
|
413 | - if (is_array($array[$key])) { |
|
412 | + } |
|
413 | + if (is_array($array[$key])) { |
|
414 | 414 | static::fixPrefix($array[$key], 'key', $rootModel); |
415 | - } else { |
|
415 | + } else { |
|
416 | 416 | static::checkForJoin($key, $rootModel); |
417 | - } |
|
417 | + } |
|
418 | 418 | } |
419 | 419 | break; |
420 | - case 'first': |
|
420 | + case 'first': |
|
421 | 421 | if (isset($array[0]) && is_string($array[0])) { |
422 | - if (!isset($cols[static::colPrefix() . $array[0]]) && isset(static::$cols[$array[0]])) { |
|
422 | + if (!isset($cols[static::colPrefix() . $array[0]]) && isset(static::$cols[$array[0]])) { |
|
423 | 423 | static::createCol($array[0]); |
424 | 424 | $cols = static::cols(true); |
425 | - } |
|
426 | - if (!isset($cols[$array[0]]) && isset($cols[static::colPrefix() . $array[0]])) { |
|
425 | + } |
|
426 | + if (!isset($cols[$array[0]]) && isset($cols[static::colPrefix() . $array[0]])) { |
|
427 | 427 | $array[0] = static::colPrefix() . $array[0]; |
428 | - } else { |
|
428 | + } else { |
|
429 | 429 | static::checkForJoin($array[0], $rootModel); |
430 | - } |
|
430 | + } |
|
431 | 431 | } elseif (isset($array[0]) && is_array($array[0])) { |
432 | - foreach ($array as &$item) { |
|
432 | + foreach ($array as &$item) { |
|
433 | 433 | static::fixPrefix($item, 'first', $rootModel); |
434 | - } |
|
434 | + } |
|
435 | 435 | } |
436 | 436 | break; |
437 | 437 | } |
438 | - } |
|
438 | + } |
|
439 | 439 | |
440 | - public function logChanges($new) { |
|
440 | + public function logChanges($new) { |
|
441 | 441 | if (!App::$cur->db->connect || !App::$cur->dashboard) { |
442 | - return false; |
|
442 | + return false; |
|
443 | 443 | } |
444 | 444 | $class = get_class($this); |
445 | 445 | if (!$class::$logging) { |
446 | - return false; |
|
446 | + return false; |
|
447 | 447 | } |
448 | 448 | if (!$new && !empty($this->_changedParams)) { |
449 | - $activity = new Dashboard\Activity([ |
|
450 | - 'user_id' => \Users\User::$cur->id, |
|
451 | - 'module' => substr($class, 0, strpos($class, '\\')), |
|
452 | - 'model' => $class, |
|
453 | - 'item_id' => $this->pk(), |
|
454 | - 'type' => 'changes' |
|
455 | - ]); |
|
456 | - $changes_text = []; |
|
457 | - foreach ($this->_changedParams as $fullColName => $oldValue) { |
|
449 | + $activity = new Dashboard\Activity([ |
|
450 | + 'user_id' => \Users\User::$cur->id, |
|
451 | + 'module' => substr($class, 0, strpos($class, '\\')), |
|
452 | + 'model' => $class, |
|
453 | + 'item_id' => $this->pk(), |
|
454 | + 'type' => 'changes' |
|
455 | + ]); |
|
456 | + $changes_text = []; |
|
457 | + foreach ($this->_changedParams as $fullColName => $oldValue) { |
|
458 | 458 | $colName = substr($fullColName, strlen($class::colPrefix())); |
459 | 459 | if(isset($class::$cols[$colName]['logging']) && !$class::$cols[$colName]['logging']){ |
460 | - continue; |
|
460 | + continue; |
|
461 | 461 | } |
462 | 462 | if (strlen($oldValue) + strlen($this->_params[$fullColName]) < 200) { |
463 | - $changes_text[] = (!empty($class::$labels[$colName]) ? $class::$labels[$colName] : $colName) . ": \"{$oldValue}\" => \"{$this->$colName}\""; |
|
463 | + $changes_text[] = (!empty($class::$labels[$colName]) ? $class::$labels[$colName] : $colName) . ": \"{$oldValue}\" => \"{$this->$colName}\""; |
|
464 | 464 | } else { |
465 | - $changes_text[] = !empty($class::$labels[$colName]) ? $class::$labels[$colName] : $colName; |
|
465 | + $changes_text[] = !empty($class::$labels[$colName]) ? $class::$labels[$colName] : $colName; |
|
466 | 466 | } |
467 | - } |
|
468 | - if (!$changes_text) { |
|
467 | + } |
|
468 | + if (!$changes_text) { |
|
469 | 469 | return false; |
470 | - } |
|
471 | - $activity->changes_text = implode(', ', $changes_text); |
|
472 | - $activity->save(); |
|
473 | - foreach ($this->_changedParams as $fullColName => $oldValue) { |
|
470 | + } |
|
471 | + $activity->changes_text = implode(', ', $changes_text); |
|
472 | + $activity->save(); |
|
473 | + foreach ($this->_changedParams as $fullColName => $oldValue) { |
|
474 | 474 | $colName = substr($fullColName, strlen($class::colPrefix())); |
475 | 475 | $change = new Dashboard\Activity\Change([ |
476 | 476 | 'activity_id' => $activity->id, |
@@ -479,42 +479,42 @@ discard block |
||
479 | 479 | 'new' => $this->$colName |
480 | 480 | ]); |
481 | 481 | $change->save(); |
482 | - } |
|
482 | + } |
|
483 | 483 | } elseif ($new) { |
484 | - $activity = new Dashboard\Activity([ |
|
485 | - 'user_id' => \Users\User::$cur->id, |
|
486 | - 'module' => substr($class, 0, strpos($class, '\\')), |
|
487 | - 'model' => $class, |
|
488 | - 'item_id' => $this->pk(), |
|
489 | - 'type' => 'new' |
|
490 | - ]); |
|
491 | - $activity->save(); |
|
484 | + $activity = new Dashboard\Activity([ |
|
485 | + 'user_id' => \Users\User::$cur->id, |
|
486 | + 'module' => substr($class, 0, strpos($class, '\\')), |
|
487 | + 'model' => $class, |
|
488 | + 'item_id' => $this->pk(), |
|
489 | + 'type' => 'new' |
|
490 | + ]); |
|
491 | + $activity->save(); |
|
492 | 492 | } |
493 | 493 | return true; |
494 | - } |
|
494 | + } |
|
495 | 495 | |
496 | - /** |
|
497 | - * Check model relations path and load need relations |
|
498 | - * |
|
499 | - * @param string $col |
|
500 | - * @param string $rootModel |
|
501 | - */ |
|
502 | - public static function checkForJoin(&$col, $rootModel) { |
|
496 | + /** |
|
497 | + * Check model relations path and load need relations |
|
498 | + * |
|
499 | + * @param string $col |
|
500 | + * @param string $rootModel |
|
501 | + */ |
|
502 | + public static function checkForJoin(&$col, $rootModel) { |
|
503 | 503 | |
504 | 504 | if (strpos($col, ':') !== false) { |
505 | - $relations = static::relations(); |
|
506 | - if (isset($relations[substr($col, 0, strpos($col, ':'))])) { |
|
505 | + $relations = static::relations(); |
|
506 | + if (isset($relations[substr($col, 0, strpos($col, ':'))])) { |
|
507 | 507 | $rel = substr($col, 0, strpos($col, ':')); |
508 | 508 | $col = substr($col, strpos($col, ':') + 1); |
509 | 509 | |
510 | 510 | $type = empty($relations[$rel]['type']) ? 'to' : $relations[$rel]['type']; |
511 | 511 | switch ($type) { |
512 | - case 'to': |
|
512 | + case 'to': |
|
513 | 513 | $relCol = $relations[$rel]['col']; |
514 | 514 | static::fixPrefix($relCol); |
515 | 515 | $rootModel::$relJoins[$relations[$rel]['model'] . '_' . $rel] = [$relations[$rel]['model']::table(), $relations[$rel]['model']::index() . ' = ' . $relCol]; |
516 | 516 | break; |
517 | - case 'one': |
|
517 | + case 'one': |
|
518 | 518 | case 'many': |
519 | 519 | $relCol = $relations[$rel]['col']; |
520 | 520 | $relations[$rel]['model']::fixPrefix($relCol); |
@@ -522,44 +522,44 @@ discard block |
||
522 | 522 | break; |
523 | 523 | } |
524 | 524 | $relations[$rel]['model']::fixPrefix($col, 'key', $rootModel); |
525 | - } |
|
525 | + } |
|
526 | + } |
|
526 | 527 | } |
527 | - } |
|
528 | 528 | |
529 | - /** |
|
530 | - * Return full col information |
|
531 | - * |
|
532 | - * @param string $col |
|
533 | - * @return array |
|
534 | - */ |
|
535 | - public static function getColInfo($col) { |
|
529 | + /** |
|
530 | + * Return full col information |
|
531 | + * |
|
532 | + * @param string $col |
|
533 | + * @return array |
|
534 | + */ |
|
535 | + public static function getColInfo($col) { |
|
536 | 536 | return static::parseColRecursion($col); |
537 | - } |
|
538 | - |
|
539 | - /** |
|
540 | - * Information extractor for col relations path |
|
541 | - * |
|
542 | - * @param string|array $info |
|
543 | - * @return array |
|
544 | - */ |
|
545 | - public static function parseColRecursion($info) { |
|
537 | + } |
|
538 | + |
|
539 | + /** |
|
540 | + * Information extractor for col relations path |
|
541 | + * |
|
542 | + * @param string|array $info |
|
543 | + * @return array |
|
544 | + */ |
|
545 | + public static function parseColRecursion($info) { |
|
546 | 546 | if (is_string($info)) { |
547 | - $info = ['col' => $info, 'rawCol' => $info, 'modelName' => '', 'label' => '', 'joins' => []]; |
|
547 | + $info = ['col' => $info, 'rawCol' => $info, 'modelName' => '', 'label' => '', 'joins' => []]; |
|
548 | 548 | } |
549 | 549 | if (strpos($info['col'], ':') !== false) { |
550 | - $relations = static::relations(); |
|
551 | - if (isset($relations[substr($info['col'], 0, strpos($info['col'], ':'))])) { |
|
550 | + $relations = static::relations(); |
|
551 | + if (isset($relations[substr($info['col'], 0, strpos($info['col'], ':'))])) { |
|
552 | 552 | $rel = substr($info['col'], 0, strpos($info['col'], ':')); |
553 | 553 | $info['col'] = substr($info['col'], strpos($info['col'], ':') + 1); |
554 | 554 | $type = empty($relations[$rel]['type']) ? 'to' : $relations[$rel]['type']; |
555 | 555 | switch ($type) { |
556 | - case 'to': |
|
556 | + case 'to': |
|
557 | 557 | $relCol = $relations[$rel]['col']; |
558 | 558 | static::fixPrefix($relCol); |
559 | 559 | //$info['modelName'] = $relations[$rel]['model']; |
560 | 560 | $info['joins'][$relations[$rel]['model'] . '_' . $rel] = [$relations[$rel]['model']::table(), $relations[$rel]['model']::index() . ' = ' . $relCol]; |
561 | 561 | break; |
562 | - case 'one': |
|
562 | + case 'one': |
|
563 | 563 | $relCol = $relations[$rel]['col']; |
564 | 564 | $relations[$rel]['model']::fixPrefix($relCol); |
565 | 565 | //$info['modelName'] = $relations[$rel]['model']; |
@@ -567,94 +567,94 @@ discard block |
||
567 | 567 | break; |
568 | 568 | } |
569 | 569 | $info = $relations[$rel]['model']::parseColRecursion($info); |
570 | - } |
|
570 | + } |
|
571 | 571 | } else { |
572 | - $cols = static::cols(); |
|
573 | - if (!empty(static::$labels[$info['col']])) { |
|
572 | + $cols = static::cols(); |
|
573 | + if (!empty(static::$labels[$info['col']])) { |
|
574 | 574 | $info['label'] = static::$labels[$info['col']]; |
575 | - } |
|
575 | + } |
|
576 | 576 | |
577 | - if (isset(static::$cols[$info['col']])) { |
|
577 | + if (isset(static::$cols[$info['col']])) { |
|
578 | 578 | $info['colParams'] = static::$cols[$info['col']]; |
579 | - } elseif (isset(static::$cols[str_replace(static::colPrefix(), '', $info['col'])])) { |
|
579 | + } elseif (isset(static::$cols[str_replace(static::colPrefix(), '', $info['col'])])) { |
|
580 | 580 | $info['colParams'] = static::$cols[str_replace(static::colPrefix(), '', $info['col'])]; |
581 | - } else { |
|
581 | + } else { |
|
582 | 582 | $info['colParams'] = []; |
583 | - } |
|
584 | - if (!isset($cols[$info['col']]) && isset($cols[static::colPrefix() . $info['col']])) { |
|
583 | + } |
|
584 | + if (!isset($cols[$info['col']]) && isset($cols[static::colPrefix() . $info['col']])) { |
|
585 | 585 | $info['col'] = static::colPrefix() . $info['col']; |
586 | - } |
|
587 | - $info['modelName'] = get_called_class(); |
|
586 | + } |
|
587 | + $info['modelName'] = get_called_class(); |
|
588 | 588 | } |
589 | 589 | if (!empty(static::$labels[$info['rawCol']])) { |
590 | - $info['label'] = static::$labels[$info['rawCol']]; |
|
590 | + $info['label'] = static::$labels[$info['rawCol']]; |
|
591 | 591 | } |
592 | 592 | return $info; |
593 | - } |
|
594 | - |
|
595 | - /** |
|
596 | - * Return actual cols from data base |
|
597 | - * |
|
598 | - * @param boolean $refresh |
|
599 | - * @return array |
|
600 | - */ |
|
601 | - public static function cols($refresh = false) { |
|
593 | + } |
|
594 | + |
|
595 | + /** |
|
596 | + * Return actual cols from data base |
|
597 | + * |
|
598 | + * @param boolean $refresh |
|
599 | + * @return array |
|
600 | + */ |
|
601 | + public static function cols($refresh = false) { |
|
602 | 602 | if (static::$storage['type'] == 'moduleConfig') { |
603 | - return []; |
|
603 | + return []; |
|
604 | 604 | } |
605 | 605 | if (empty(Model::$cols[static::table()]) || $refresh) { |
606 | - Model::$cols[static::table()] = App::$cur->db->getTableCols(static::table()); |
|
606 | + Model::$cols[static::table()] = App::$cur->db->getTableCols(static::table()); |
|
607 | 607 | } |
608 | 608 | if (!Model::$cols[static::table()]) { |
609 | - static::createTable(); |
|
610 | - Model::$cols[static::table()] = App::$cur->db->getTableCols(static::table()); |
|
609 | + static::createTable(); |
|
610 | + Model::$cols[static::table()] = App::$cur->db->getTableCols(static::table()); |
|
611 | 611 | } |
612 | 612 | return Model::$cols[static::table()]; |
613 | - } |
|
614 | - |
|
615 | - /** |
|
616 | - * Return cols indexes for create tables |
|
617 | - * |
|
618 | - * @return array |
|
619 | - */ |
|
620 | - public static function indexes() { |
|
613 | + } |
|
614 | + |
|
615 | + /** |
|
616 | + * Return cols indexes for create tables |
|
617 | + * |
|
618 | + * @return array |
|
619 | + */ |
|
620 | + public static function indexes() { |
|
621 | 621 | return []; |
622 | - } |
|
623 | - |
|
624 | - /** |
|
625 | - * Generate params string for col by name |
|
626 | - * |
|
627 | - * @param string $colName |
|
628 | - * @return boolean|string |
|
629 | - */ |
|
630 | - public static function genColParams($colName) { |
|
622 | + } |
|
623 | + |
|
624 | + /** |
|
625 | + * Generate params string for col by name |
|
626 | + * |
|
627 | + * @param string $colName |
|
628 | + * @return boolean|string |
|
629 | + */ |
|
630 | + public static function genColParams($colName) { |
|
631 | 631 | if (empty(static::$cols[$colName]) || static::$storage['type'] == 'moduleConfig') { |
632 | - return false; |
|
632 | + return false; |
|
633 | 633 | } |
634 | 634 | |
635 | 635 | $params = false; |
636 | 636 | switch (static::$cols[$colName]['type']) { |
637 | - case 'select': |
|
637 | + case 'select': |
|
638 | 638 | switch (static::$cols[$colName]['source']) { |
639 | - case 'relation': |
|
639 | + case 'relation': |
|
640 | 640 | $params = 'int(11) UNSIGNED NOT NULL'; |
641 | 641 | break; |
642 | - default: |
|
642 | + default: |
|
643 | 643 | $params = 'varchar(255) NOT NULL'; |
644 | 644 | } |
645 | 645 | break; |
646 | - case 'image': |
|
646 | + case 'image': |
|
647 | 647 | case 'file': |
648 | 648 | $params = 'int(11) UNSIGNED NOT NULL'; |
649 | 649 | break; |
650 | - case 'number': |
|
650 | + case 'number': |
|
651 | 651 | $params = 'int(11) NOT NULL'; |
652 | 652 | break; |
653 | - case 'text': |
|
653 | + case 'text': |
|
654 | 654 | case 'email': |
655 | 655 | $params = 'varchar(255) NOT NULL'; |
656 | 656 | break; |
657 | - case 'html': |
|
657 | + case 'html': |
|
658 | 658 | case 'textarea': |
659 | 659 | case 'json': |
660 | 660 | case 'password': |
@@ -662,694 +662,694 @@ discard block |
||
662 | 662 | case 'map': |
663 | 663 | $params = 'text NOT NULL'; |
664 | 664 | break; |
665 | - case 'bool': |
|
665 | + case 'bool': |
|
666 | 666 | $params = 'tinyint(1) UNSIGNED NOT NULL'; |
667 | 667 | break; |
668 | - case 'decimal': |
|
668 | + case 'decimal': |
|
669 | 669 | $params = 'decimal(8, 2) NOT NULL'; |
670 | 670 | break; |
671 | - case 'date': |
|
671 | + case 'date': |
|
672 | 672 | $params = 'date NOT NULL DEFAULT 0'; |
673 | 673 | break; |
674 | - case 'dateTime': |
|
674 | + case 'dateTime': |
|
675 | 675 | $params = 'timestamp NOT NULL DEFAULT 0'; |
676 | 676 | break; |
677 | 677 | } |
678 | 678 | return $params; |
679 | - } |
|
680 | - |
|
681 | - /** |
|
682 | - * Create new col in data base |
|
683 | - * |
|
684 | - * @param string $colName |
|
685 | - * @return boolean|integer |
|
686 | - */ |
|
687 | - public static function createCol($colName) { |
|
679 | + } |
|
680 | + |
|
681 | + /** |
|
682 | + * Create new col in data base |
|
683 | + * |
|
684 | + * @param string $colName |
|
685 | + * @return boolean|integer |
|
686 | + */ |
|
687 | + public static function createCol($colName) { |
|
688 | 688 | $params = static::genColParams($colName); |
689 | 689 | if ($params === false) { |
690 | - return false; |
|
690 | + return false; |
|
691 | 691 | } |
692 | 692 | return App::$cur->db->addCol(static::table(), static::colPrefix() . $colName, $params); |
693 | - } |
|
693 | + } |
|
694 | 694 | |
695 | - public static function createTable() { |
|
695 | + public static function createTable() { |
|
696 | 696 | if (static::$storage['type'] == 'moduleConfig') { |
697 | - return true; |
|
697 | + return true; |
|
698 | 698 | } |
699 | 699 | if (!App::$cur->db) { |
700 | - return false; |
|
700 | + return false; |
|
701 | 701 | } |
702 | 702 | |
703 | 703 | $query = App::$cur->db->newQuery(); |
704 | 704 | if (!$query) { |
705 | - return false; |
|
705 | + return false; |
|
706 | 706 | } |
707 | 707 | |
708 | 708 | if (!isset($this)) { |
709 | - $tableName = static::table(); |
|
710 | - $colPrefix = static::colPrefix(); |
|
711 | - $indexes = static::indexes(); |
|
709 | + $tableName = static::table(); |
|
710 | + $colPrefix = static::colPrefix(); |
|
711 | + $indexes = static::indexes(); |
|
712 | 712 | } else { |
713 | - $tableName = $this->table(); |
|
714 | - $colPrefix = $this->colPrefix(); |
|
715 | - $indexes = $this->indexes(); |
|
713 | + $tableName = $this->table(); |
|
714 | + $colPrefix = $this->colPrefix(); |
|
715 | + $indexes = $this->indexes(); |
|
716 | 716 | } |
717 | 717 | if (App::$cur->db->tableExist($tableName)) { |
718 | - return true; |
|
718 | + return true; |
|
719 | 719 | } |
720 | 720 | $cols = [ |
721 | 721 | $colPrefix . 'id' => 'pk' |
722 | 722 | ]; |
723 | 723 | $className = get_called_class(); |
724 | 724 | if (!empty($className::$cols)) { |
725 | - foreach ($className::$cols as $colName => $colParams) { |
|
725 | + foreach ($className::$cols as $colName => $colParams) { |
|
726 | 726 | if ($colName == 'date_create') { |
727 | - $cols[$colPrefix . 'date_create'] = 'timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP'; |
|
728 | - continue; |
|
727 | + $cols[$colPrefix . 'date_create'] = 'timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP'; |
|
728 | + continue; |
|
729 | 729 | } |
730 | 730 | $params = $className::genColParams($colName); |
731 | 731 | if ($params) { |
732 | - $cols[$colPrefix . $colName] = $params; |
|
732 | + $cols[$colPrefix . $colName] = $params; |
|
733 | + } |
|
733 | 734 | } |
734 | - } |
|
735 | 735 | } |
736 | 736 | if (empty($cols[$colPrefix . 'date_create'])) { |
737 | - $cols[$colPrefix . 'date_create'] = 'timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP'; |
|
737 | + $cols[$colPrefix . 'date_create'] = 'timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP'; |
|
738 | 738 | } |
739 | 739 | $tableIndexes = []; |
740 | 740 | if ($indexes) { |
741 | - foreach ($indexes as $indexName => $index) { |
|
741 | + foreach ($indexes as $indexName => $index) { |
|
742 | 742 | $tableIndexes[] = $index['type'] . ' ' . App::$cur->db->table_prefix . $indexName . ' (' . implode(',', $index['cols']) . ')'; |
743 | - } |
|
743 | + } |
|
744 | 744 | } |
745 | 745 | |
746 | 746 | $query->createTable($tableName, $cols, $tableIndexes); |
747 | 747 | return true; |
748 | - } |
|
749 | - |
|
750 | - /** |
|
751 | - * Return table name |
|
752 | - * |
|
753 | - * @return string |
|
754 | - */ |
|
755 | - public static function table() { |
|
748 | + } |
|
749 | + |
|
750 | + /** |
|
751 | + * Return table name |
|
752 | + * |
|
753 | + * @return string |
|
754 | + */ |
|
755 | + public static function table() { |
|
756 | 756 | return strtolower(str_replace('\\', '_', get_called_class())); |
757 | - } |
|
757 | + } |
|
758 | 758 | |
759 | - /** |
|
760 | - * Return table index col name |
|
761 | - * |
|
762 | - * @return string |
|
763 | - */ |
|
764 | - public static function index() { |
|
759 | + /** |
|
760 | + * Return table index col name |
|
761 | + * |
|
762 | + * @return string |
|
763 | + */ |
|
764 | + public static function index() { |
|
765 | 765 | |
766 | 766 | return static::colPrefix() . 'id'; |
767 | - } |
|
768 | - |
|
769 | - /** |
|
770 | - * Return col prefix |
|
771 | - * |
|
772 | - * @return string |
|
773 | - */ |
|
774 | - public static function colPrefix() { |
|
767 | + } |
|
768 | + |
|
769 | + /** |
|
770 | + * Return col prefix |
|
771 | + * |
|
772 | + * @return string |
|
773 | + */ |
|
774 | + public static function colPrefix() { |
|
775 | 775 | $classPath = explode('\\', get_called_class()); |
776 | 776 | $classPath = array_slice($classPath, 1); |
777 | 777 | return strtolower(implode('_', $classPath)) . '_'; |
778 | - } |
|
779 | - |
|
780 | - /** |
|
781 | - * return relations list |
|
782 | - * |
|
783 | - * @return array |
|
784 | - */ |
|
785 | - public static function relations() { |
|
778 | + } |
|
779 | + |
|
780 | + /** |
|
781 | + * return relations list |
|
782 | + * |
|
783 | + * @return array |
|
784 | + */ |
|
785 | + public static function relations() { |
|
786 | 786 | return []; |
787 | - } |
|
788 | - |
|
789 | - /** |
|
790 | - * views list |
|
791 | - * |
|
792 | - * @return array |
|
793 | - */ |
|
794 | - public static $views = []; |
|
795 | - |
|
796 | - /** |
|
797 | - * Return name of col with object name |
|
798 | - * |
|
799 | - * @return string |
|
800 | - */ |
|
801 | - public static function nameCol() { |
|
787 | + } |
|
788 | + |
|
789 | + /** |
|
790 | + * views list |
|
791 | + * |
|
792 | + * @return array |
|
793 | + */ |
|
794 | + public static $views = []; |
|
795 | + |
|
796 | + /** |
|
797 | + * Return name of col with object name |
|
798 | + * |
|
799 | + * @return string |
|
800 | + */ |
|
801 | + public static function nameCol() { |
|
802 | 802 | return 'name'; |
803 | - } |
|
804 | - |
|
805 | - /** |
|
806 | - * Return object name |
|
807 | - * |
|
808 | - * @return string |
|
809 | - */ |
|
810 | - public function name() { |
|
803 | + } |
|
804 | + |
|
805 | + /** |
|
806 | + * Return object name |
|
807 | + * |
|
808 | + * @return string |
|
809 | + */ |
|
810 | + public function name() { |
|
811 | 811 | return $this->{$this->nameCol()} ? $this->{$this->nameCol()} : '№' . $this->pk(); |
812 | - } |
|
813 | - |
|
814 | - /** |
|
815 | - * Get single object from data base |
|
816 | - * |
|
817 | - * @param mixed $param |
|
818 | - * @param string $col |
|
819 | - * @param array $options |
|
820 | - * @return boolean|\Model |
|
821 | - */ |
|
822 | - public static function get($param, $col = null, $options = []) { |
|
812 | + } |
|
813 | + |
|
814 | + /** |
|
815 | + * Get single object from data base |
|
816 | + * |
|
817 | + * @param mixed $param |
|
818 | + * @param string $col |
|
819 | + * @param array $options |
|
820 | + * @return boolean|\Model |
|
821 | + */ |
|
822 | + public static function get($param, $col = null, $options = []) { |
|
823 | 823 | if (static::$storage['type'] == 'moduleConfig') { |
824 | - return static::getFromModuleStorage($param, $col, $options); |
|
824 | + return static::getFromModuleStorage($param, $col, $options); |
|
825 | 825 | } |
826 | 826 | if (!empty($col)) { |
827 | - static::fixPrefix($col); |
|
827 | + static::fixPrefix($col); |
|
828 | 828 | } |
829 | 829 | |
830 | 830 | if (is_array($param)) { |
831 | - static::fixPrefix($param, 'first'); |
|
831 | + static::fixPrefix($param, 'first'); |
|
832 | 832 | } |
833 | 833 | foreach (static::$relJoins as $join) { |
834 | - App::$cur->db->join($join[0], $join[1]); |
|
834 | + App::$cur->db->join($join[0], $join[1]); |
|
835 | 835 | } |
836 | 836 | static::$relJoins = []; |
837 | 837 | foreach (static::$needJoin as $rel) { |
838 | - $relations = static::relations(); |
|
839 | - if (isset($relations[$rel])) { |
|
838 | + $relations = static::relations(); |
|
839 | + if (isset($relations[$rel])) { |
|
840 | 840 | $type = empty($relations[$rel]['type']) ? 'to' : $relations[$rel]['type']; |
841 | 841 | switch ($type) { |
842 | - case 'to': |
|
842 | + case 'to': |
|
843 | 843 | $relCol = $relations[$rel]['col']; |
844 | 844 | static::fixPrefix($relCol); |
845 | 845 | App::$cur->db->join($relations[$rel]['model']::table(), $relations[$rel]['model']::index() . ' = ' . $relCol); |
846 | 846 | break; |
847 | - case 'one': |
|
847 | + case 'one': |
|
848 | 848 | $col = $relations[$rel]['col']; |
849 | 849 | $relations[$rel]['model']::fixPrefix($col); |
850 | 850 | App::$cur->db->join($relations[$rel]['model']::table(), static::index() . ' = ' . $col); |
851 | 851 | break; |
852 | 852 | } |
853 | - } |
|
853 | + } |
|
854 | 854 | } |
855 | 855 | static::$needJoin = []; |
856 | 856 | if (is_array($param)) { |
857 | - App::$cur->db->where($param); |
|
857 | + App::$cur->db->where($param); |
|
858 | 858 | } else { |
859 | - if ($col === null) { |
|
859 | + if ($col === null) { |
|
860 | 860 | |
861 | 861 | $col = static::index(); |
862 | - } |
|
863 | - if ($param !== null) { |
|
862 | + } |
|
863 | + if ($param !== null) { |
|
864 | 864 | $cols = static::cols(); |
865 | 865 | if (!isset($cols[$col]) && isset($cols[static::colPrefix() . $col])) { |
866 | - $col = static::colPrefix() . $col; |
|
866 | + $col = static::colPrefix() . $col; |
|
867 | 867 | } |
868 | 868 | App::$cur->db->where($col, $param); |
869 | - } else { |
|
869 | + } else { |
|
870 | 870 | return false; |
871 | - } |
|
871 | + } |
|
872 | 872 | } |
873 | 873 | if (!App::$cur->db->where) { |
874 | - return false; |
|
874 | + return false; |
|
875 | 875 | } |
876 | 876 | try { |
877 | - $result = App::$cur->db->select(static::table()); |
|
877 | + $result = App::$cur->db->select(static::table()); |
|
878 | 878 | } catch (PDOException $exc) { |
879 | - if ($exc->getCode() == '42S02') { |
|
879 | + if ($exc->getCode() == '42S02') { |
|
880 | 880 | static::createTable(); |
881 | - } |
|
882 | - $result = App::$cur->db->select(static::table()); |
|
881 | + } |
|
882 | + $result = App::$cur->db->select(static::table()); |
|
883 | 883 | } |
884 | 884 | if (!$result) { |
885 | - return false; |
|
885 | + return false; |
|
886 | 886 | } |
887 | 887 | return $result->fetch(get_called_class()); |
888 | - } |
|
889 | - |
|
890 | - /** |
|
891 | - * Old method |
|
892 | - * |
|
893 | - * @param type $options |
|
894 | - * @return Array |
|
895 | - */ |
|
896 | - public static function get_list($options = []) { |
|
888 | + } |
|
889 | + |
|
890 | + /** |
|
891 | + * Old method |
|
892 | + * |
|
893 | + * @param type $options |
|
894 | + * @return Array |
|
895 | + */ |
|
896 | + public static function get_list($options = []) { |
|
897 | 897 | $query = App::$cur->db->newQuery(); |
898 | 898 | if (!$query) { |
899 | - return []; |
|
899 | + return []; |
|
900 | 900 | } |
901 | 901 | if (!empty($options['where'])) |
902 | - $query->where($options['where']); |
|
902 | + $query->where($options['where']); |
|
903 | 903 | if (!empty($options['cols'])) |
904 | - $query->cols = $options['cols']; |
|
904 | + $query->cols = $options['cols']; |
|
905 | 905 | if (!empty($options['group'])) { |
906 | - $query->group($options['group']); |
|
906 | + $query->group($options['group']); |
|
907 | 907 | } |
908 | 908 | if (!empty($options['having'])) { |
909 | - $query->having($options['having']); |
|
909 | + $query->having($options['having']); |
|
910 | 910 | } |
911 | 911 | if (!empty($options['order'])) |
912 | - $query->order($options['order']); |
|
912 | + $query->order($options['order']); |
|
913 | 913 | if (!empty($options['join'])) |
914 | - $query->join($options['join']); |
|
914 | + $query->join($options['join']); |
|
915 | 915 | if (!empty($options['distinct'])) |
916 | - $query->distinct = $options['distinct']; |
|
916 | + $query->distinct = $options['distinct']; |
|
917 | 917 | |
918 | 918 | foreach (static::$relJoins as $join) { |
919 | - $query->join($join[0], $join[1]); |
|
919 | + $query->join($join[0], $join[1]); |
|
920 | 920 | } |
921 | 921 | static::$relJoins = []; |
922 | 922 | foreach (static::$needJoin as $rel) { |
923 | - $relations = static::relations(); |
|
924 | - if (isset($relations[$rel])) { |
|
923 | + $relations = static::relations(); |
|
924 | + if (isset($relations[$rel])) { |
|
925 | 925 | $type = empty($relations[$rel]['type']) ? 'to' : $relations[$rel]['type']; |
926 | 926 | switch ($type) { |
927 | - case 'to': |
|
927 | + case 'to': |
|
928 | 928 | $relCol = $relations[$rel]['col']; |
929 | 929 | static::fixPrefix($relCol); |
930 | 930 | $query->join($relations[$rel]['model']::table(), $relations[$rel]['model']::index() . ' = ' . $relCol); |
931 | 931 | break; |
932 | - case 'one': |
|
932 | + case 'one': |
|
933 | 933 | $col = $relations[$rel]['col']; |
934 | 934 | $relations[$rel]['model']::fixPrefix($col); |
935 | 935 | $query->join($relations[$rel]['model']::table(), static::index() . ' = ' . $col); |
936 | 936 | break; |
937 | 937 | } |
938 | - } |
|
938 | + } |
|
939 | 939 | } |
940 | 940 | static::$needJoin = []; |
941 | 941 | |
942 | 942 | if (!empty($options['limit'])) |
943 | - $limit = (int) $options['limit']; |
|
943 | + $limit = (int) $options['limit']; |
|
944 | 944 | else { |
945 | - $limit = 0; |
|
945 | + $limit = 0; |
|
946 | 946 | } |
947 | 947 | if (!empty($options['start'])) |
948 | - $start = (int) $options['start']; |
|
948 | + $start = (int) $options['start']; |
|
949 | 949 | else { |
950 | - $start = 0; |
|
950 | + $start = 0; |
|
951 | 951 | } |
952 | 952 | if ($limit || $start) { |
953 | - $query->limit($start, $limit); |
|
953 | + $query->limit($start, $limit); |
|
954 | 954 | } |
955 | 955 | if (isset($options['key'])) { |
956 | - $key = $options['key']; |
|
956 | + $key = $options['key']; |
|
957 | 957 | } else { |
958 | - $key = static::index(); |
|
958 | + $key = static::index(); |
|
959 | 959 | } |
960 | 960 | try { |
961 | - $query->operation = 'SELECT'; |
|
962 | - $query->table = static::table(); |
|
963 | - $queryArr = $query->buildQuery(); |
|
964 | - $result = $query->query($queryArr); |
|
961 | + $query->operation = 'SELECT'; |
|
962 | + $query->table = static::table(); |
|
963 | + $queryArr = $query->buildQuery(); |
|
964 | + $result = $query->query($queryArr); |
|
965 | 965 | } catch (PDOException $exc) { |
966 | - if ($exc->getCode() == '42S02') { |
|
966 | + if ($exc->getCode() == '42S02') { |
|
967 | 967 | static::createTable(); |
968 | 968 | $result = $query->query($queryArr); |
969 | - } else { |
|
969 | + } else { |
|
970 | 970 | throw $exc; |
971 | - } |
|
971 | + } |
|
972 | 972 | } |
973 | 973 | |
974 | 974 | if (!empty($options['array'])) { |
975 | - return $result->getArray($key); |
|
975 | + return $result->getArray($key); |
|
976 | 976 | } |
977 | 977 | $list = $result->getObjects(get_called_class(), $key); |
978 | 978 | if (!empty($options['forSelect'])) { |
979 | - $return = []; |
|
980 | - foreach ($list as $key => $item) { |
|
979 | + $return = []; |
|
980 | + foreach ($list as $key => $item) { |
|
981 | 981 | $return[$key] = $item->name(); |
982 | - } |
|
983 | - return $return; |
|
982 | + } |
|
983 | + return $return; |
|
984 | 984 | } |
985 | 985 | return $list; |
986 | - } |
|
987 | - |
|
988 | - /** |
|
989 | - * Return list of objects from data base |
|
990 | - * |
|
991 | - * @param type $options |
|
992 | - * @return type |
|
993 | - */ |
|
994 | - public static function getList($options = []) { |
|
986 | + } |
|
987 | + |
|
988 | + /** |
|
989 | + * Return list of objects from data base |
|
990 | + * |
|
991 | + * @param type $options |
|
992 | + * @return type |
|
993 | + */ |
|
994 | + public static function getList($options = []) { |
|
995 | 995 | if (static::$storage['type'] != 'db') { |
996 | - return static::getListFromModuleStorage($options); |
|
996 | + return static::getListFromModuleStorage($options); |
|
997 | 997 | } |
998 | 998 | if (!empty($options['where'])) { |
999 | - static::fixPrefix($options['where'], 'first'); |
|
999 | + static::fixPrefix($options['where'], 'first'); |
|
1000 | 1000 | } |
1001 | 1001 | if (!empty($options['group'])) { |
1002 | - static::fixPrefix($options['group'], 'first'); |
|
1002 | + static::fixPrefix($options['group'], 'first'); |
|
1003 | 1003 | } |
1004 | 1004 | if (!empty($options['order'])) { |
1005 | - static::fixPrefix($options['order'], 'first'); |
|
1005 | + static::fixPrefix($options['order'], 'first'); |
|
1006 | 1006 | } |
1007 | 1007 | if (!empty($options['having'])) { |
1008 | - static::fixPrefix($options['having'], 'first'); |
|
1008 | + static::fixPrefix($options['having'], 'first'); |
|
1009 | 1009 | } |
1010 | 1010 | return static::get_list($options); |
1011 | - } |
|
1012 | - |
|
1013 | - /** |
|
1014 | - * Get single item from module storage |
|
1015 | - * |
|
1016 | - * @param array $param |
|
1017 | - * @param string $col |
|
1018 | - * @param array $options |
|
1019 | - * @return boolean|\Model |
|
1020 | - */ |
|
1021 | - public static function getFromModuleStorage($param = null, $col = null, $options = []) { |
|
1011 | + } |
|
1012 | + |
|
1013 | + /** |
|
1014 | + * Get single item from module storage |
|
1015 | + * |
|
1016 | + * @param array $param |
|
1017 | + * @param string $col |
|
1018 | + * @param array $options |
|
1019 | + * @return boolean|\Model |
|
1020 | + */ |
|
1021 | + public static function getFromModuleStorage($param = null, $col = null, $options = []) { |
|
1022 | 1022 | if ($col === null) { |
1023 | 1023 | |
1024 | - $col = static::index(); |
|
1024 | + $col = static::index(); |
|
1025 | 1025 | } |
1026 | 1026 | if ($param == null) { |
1027 | - return false; |
|
1027 | + return false; |
|
1028 | 1028 | } |
1029 | 1029 | $classPath = explode('\\', get_called_class()); |
1030 | 1030 | if (!empty(static::$storage['options']['share'])) { |
1031 | - $moduleConfig = Config::share($classPath[0]); |
|
1031 | + $moduleConfig = Config::share($classPath[0]); |
|
1032 | 1032 | } else { |
1033 | - $moduleConfig = Config::module($classPath[0], strpos(static::$storage['type'], 'system') !== false); |
|
1033 | + $moduleConfig = Config::module($classPath[0], strpos(static::$storage['type'], 'system') !== false); |
|
1034 | 1034 | } |
1035 | 1035 | $appType = App::$cur->type; |
1036 | 1036 | if (!empty($moduleConfig['storage']['appTypeSplit'])) { |
1037 | - if (!empty($options['appType'])) { |
|
1037 | + if (!empty($options['appType'])) { |
|
1038 | 1038 | $appType = $options['appType']; |
1039 | - } |
|
1040 | - $storage = !empty($moduleConfig['storage'][$appType]) ? $moduleConfig['storage'][$appType] : []; |
|
1039 | + } |
|
1040 | + $storage = !empty($moduleConfig['storage'][$appType]) ? $moduleConfig['storage'][$appType] : []; |
|
1041 | 1041 | } else { |
1042 | - $storage = !empty($moduleConfig['storage']) ? $moduleConfig['storage'] : []; |
|
1042 | + $storage = !empty($moduleConfig['storage']) ? $moduleConfig['storage'] : []; |
|
1043 | 1043 | } |
1044 | 1044 | if (!empty($storage[$classPath[1]])) { |
1045 | - $items = $storage[$classPath[1]]; |
|
1046 | - $class = get_called_class(); |
|
1047 | - $where = is_array($param) ? $param : [$col, $param]; |
|
1048 | - foreach ($items as $key => $item) { |
|
1045 | + $items = $storage[$classPath[1]]; |
|
1046 | + $class = get_called_class(); |
|
1047 | + $where = is_array($param) ? $param : [$col, $param]; |
|
1048 | + foreach ($items as $key => $item) { |
|
1049 | 1049 | if (!Model::checkWhere($item, $where)) { |
1050 | - continue; |
|
1050 | + continue; |
|
1051 | 1051 | } |
1052 | 1052 | if (!empty($options['array'])) { |
1053 | - return $item; |
|
1053 | + return $item; |
|
1054 | 1054 | } |
1055 | 1055 | $item = new $class($item); |
1056 | 1056 | $item->appType = $appType; |
1057 | 1057 | return $item; |
1058 | - } |
|
1058 | + } |
|
1059 | 1059 | } |
1060 | 1060 | return false; |
1061 | - } |
|
1062 | - |
|
1063 | - /** |
|
1064 | - * Return list items from module storage |
|
1065 | - * |
|
1066 | - * @param array $options |
|
1067 | - * @return array |
|
1068 | - */ |
|
1069 | - public static function getListFromModuleStorage($options = []) { |
|
1061 | + } |
|
1062 | + |
|
1063 | + /** |
|
1064 | + * Return list items from module storage |
|
1065 | + * |
|
1066 | + * @param array $options |
|
1067 | + * @return array |
|
1068 | + */ |
|
1069 | + public static function getListFromModuleStorage($options = []) { |
|
1070 | 1070 | $classPath = explode('\\', get_called_class()); |
1071 | 1071 | if (!empty(static::$storage['options']['share'])) { |
1072 | - $moduleConfig = Config::share($classPath[0]); |
|
1072 | + $moduleConfig = Config::share($classPath[0]); |
|
1073 | 1073 | } else { |
1074 | - $moduleConfig = Config::module($classPath[0], strpos(static::$storage['type'], 'system') !== false); |
|
1074 | + $moduleConfig = Config::module($classPath[0], strpos(static::$storage['type'], 'system') !== false); |
|
1075 | 1075 | } |
1076 | 1076 | if (!empty($moduleConfig['storage']['appTypeSplit'])) { |
1077 | - if (empty($options['appType'])) { |
|
1077 | + if (empty($options['appType'])) { |
|
1078 | 1078 | $appType = App::$cur->type; |
1079 | - } else { |
|
1079 | + } else { |
|
1080 | 1080 | $appType = $options['appType']; |
1081 | - } |
|
1082 | - $storage = !empty($moduleConfig['storage'][$appType]) ? $moduleConfig['storage'][$appType] : []; |
|
1081 | + } |
|
1082 | + $storage = !empty($moduleConfig['storage'][$appType]) ? $moduleConfig['storage'][$appType] : []; |
|
1083 | 1083 | } else { |
1084 | - $storage = !empty($moduleConfig['storage']) ? $moduleConfig['storage'] : []; |
|
1084 | + $storage = !empty($moduleConfig['storage']) ? $moduleConfig['storage'] : []; |
|
1085 | 1085 | } |
1086 | 1086 | if (!empty($storage[$classPath[1]])) { |
1087 | - $items = []; |
|
1088 | - $class = get_called_class(); |
|
1089 | - if (isset($options['key'])) { |
|
1087 | + $items = []; |
|
1088 | + $class = get_called_class(); |
|
1089 | + if (isset($options['key'])) { |
|
1090 | 1090 | $arrayKey = $options['key']; |
1091 | - } else { |
|
1091 | + } else { |
|
1092 | 1092 | $arrayKey = static::index(); |
1093 | - } |
|
1094 | - foreach ($storage[$classPath[1]] as $key => $item) { |
|
1093 | + } |
|
1094 | + foreach ($storage[$classPath[1]] as $key => $item) { |
|
1095 | 1095 | if (!empty($options['where']) && !Model::checkWhere($item, $options['where'])) { |
1096 | - continue; |
|
1096 | + continue; |
|
1097 | 1097 | } |
1098 | 1098 | $items[$item[$arrayKey]] = new $class($item); |
1099 | - } |
|
1100 | - if (!empty($options['order'])) { |
|
1099 | + } |
|
1100 | + if (!empty($options['order'])) { |
|
1101 | 1101 | usort($items, function($a, $b) use($options) { |
1102 | - if ($a->{$options['order'][0]} > $b->{$options['order'][0]} && $options['order'][1] = 'asc') { |
|
1102 | + if ($a->{$options['order'][0]} > $b->{$options['order'][0]} && $options['order'][1] = 'asc') { |
|
1103 | 1103 | return 1; |
1104 | - } elseif ($a->{$options['order'][0]} < $b->{$options['order'][0]} && $options['order'][1] = 'asc') { |
|
1104 | + } elseif ($a->{$options['order'][0]} < $b->{$options['order'][0]} && $options['order'][1] = 'asc') { |
|
1105 | 1105 | return -1; |
1106 | - } |
|
1107 | - return 0; |
|
1106 | + } |
|
1107 | + return 0; |
|
1108 | 1108 | }); |
1109 | - } |
|
1110 | - if (!empty($options['forSelect'])) { |
|
1109 | + } |
|
1110 | + if (!empty($options['forSelect'])) { |
|
1111 | 1111 | $return = []; |
1112 | 1112 | foreach ($items as $key => $item) { |
1113 | - $return[$key] = $item->name(); |
|
1113 | + $return[$key] = $item->name(); |
|
1114 | 1114 | } |
1115 | 1115 | return $return; |
1116 | - } |
|
1117 | - return $items; |
|
1116 | + } |
|
1117 | + return $items; |
|
1118 | 1118 | } |
1119 | 1119 | return []; |
1120 | - } |
|
1120 | + } |
|
1121 | 1121 | |
1122 | - /** |
|
1123 | - * Return count of records from module storage |
|
1124 | - * |
|
1125 | - * @param array $options |
|
1126 | - * @return int |
|
1127 | - */ |
|
1128 | - public static function getCountFromModuleStorage($options = []) { |
|
1122 | + /** |
|
1123 | + * Return count of records from module storage |
|
1124 | + * |
|
1125 | + * @param array $options |
|
1126 | + * @return int |
|
1127 | + */ |
|
1128 | + public static function getCountFromModuleStorage($options = []) { |
|
1129 | 1129 | |
1130 | 1130 | $classPath = explode('\\', get_called_class()); |
1131 | 1131 | $count = 0; |
1132 | 1132 | if (empty($options['appType'])) { |
1133 | - $appType = App::$cur->type; |
|
1133 | + $appType = App::$cur->type; |
|
1134 | 1134 | } else { |
1135 | - $appType = $options['appType']; |
|
1135 | + $appType = $options['appType']; |
|
1136 | 1136 | } |
1137 | 1137 | if (!empty(static::$storage['options']['share'])) { |
1138 | - $moduleConfig = Config::share($classPath[0]); |
|
1138 | + $moduleConfig = Config::share($classPath[0]); |
|
1139 | 1139 | } else { |
1140 | - $moduleConfig = Config::module($classPath[0], strpos(static::$storage['type'], 'system') !== false); |
|
1140 | + $moduleConfig = Config::module($classPath[0], strpos(static::$storage['type'], 'system') !== false); |
|
1141 | 1141 | } |
1142 | 1142 | if (!empty($moduleConfig['storage'][$appType][$classPath[1]])) { |
1143 | - $items = $moduleConfig['storage'][$appType][$classPath[1]]; |
|
1144 | - if (empty($options['where'])) { |
|
1143 | + $items = $moduleConfig['storage'][$appType][$classPath[1]]; |
|
1144 | + if (empty($options['where'])) { |
|
1145 | 1145 | return count($items); |
1146 | - } |
|
1147 | - foreach ($items as $key => $item) { |
|
1146 | + } |
|
1147 | + foreach ($items as $key => $item) { |
|
1148 | 1148 | if (!empty($options['where'])) { |
1149 | - if (Model::checkWhere($item, $options['where'])) { |
|
1149 | + if (Model::checkWhere($item, $options['where'])) { |
|
1150 | 1150 | $count++; |
1151 | - } |
|
1151 | + } |
|
1152 | 1152 | } else { |
1153 | - $count++; |
|
1153 | + $count++; |
|
1154 | + } |
|
1154 | 1155 | } |
1155 | - } |
|
1156 | 1156 | } |
1157 | 1157 | return $count; |
1158 | - } |
|
1159 | - |
|
1160 | - /** |
|
1161 | - * Check where for module storage query |
|
1162 | - * |
|
1163 | - * @param array $item |
|
1164 | - * @param array|string $where |
|
1165 | - * @param string $value |
|
1166 | - * @param string $operation |
|
1167 | - * @param string $concatenation |
|
1168 | - * @return boolean |
|
1169 | - */ |
|
1170 | - public static function checkWhere($item = [], $where = '', $value = '', $operation = '=', $concatenation = 'AND') { |
|
1158 | + } |
|
1159 | + |
|
1160 | + /** |
|
1161 | + * Check where for module storage query |
|
1162 | + * |
|
1163 | + * @param array $item |
|
1164 | + * @param array|string $where |
|
1165 | + * @param string $value |
|
1166 | + * @param string $operation |
|
1167 | + * @param string $concatenation |
|
1168 | + * @return boolean |
|
1169 | + */ |
|
1170 | + public static function checkWhere($item = [], $where = '', $value = '', $operation = '=', $concatenation = 'AND') { |
|
1171 | 1171 | |
1172 | 1172 | if (is_array($where)) { |
1173 | - if (is_array($where[0])) { |
|
1173 | + if (is_array($where[0])) { |
|
1174 | 1174 | $result = true; |
1175 | 1175 | foreach ($where as $key => $whereItem) { |
1176 | - $concatenation = empty($whereItem[3]) ? 'AND' : strtoupper($whereItem[3]); |
|
1177 | - switch ($concatenation) { |
|
1176 | + $concatenation = empty($whereItem[3]) ? 'AND' : strtoupper($whereItem[3]); |
|
1177 | + switch ($concatenation) { |
|
1178 | 1178 | case 'AND': |
1179 | 1179 | $result = $result && forward_static_call_array(['Model', 'checkWhere'], [$item, $whereItem]); |
1180 | - break; |
|
1180 | + break; |
|
1181 | 1181 | case 'OR': |
1182 | 1182 | $result = $result || forward_static_call_array(['Model', 'checkWhere'], [$item, $whereItem]); |
1183 | - break; |
|
1184 | - } |
|
1183 | + break; |
|
1184 | + } |
|
1185 | 1185 | } |
1186 | 1186 | |
1187 | 1187 | return $result; |
1188 | - } else { |
|
1188 | + } else { |
|
1189 | 1189 | return forward_static_call_array(['Model', 'checkWhere'], array_merge([$item], $where)); |
1190 | - } |
|
1190 | + } |
|
1191 | 1191 | } |
1192 | 1192 | if (!isset($item[$where]) && !$value) { |
1193 | - return true; |
|
1193 | + return true; |
|
1194 | 1194 | } |
1195 | 1195 | if (!isset($item[$where]) && $value) { |
1196 | - return false; |
|
1196 | + return false; |
|
1197 | 1197 | } |
1198 | 1198 | if ($item[$where] == $value) { |
1199 | - return true; |
|
1199 | + return true; |
|
1200 | 1200 | } |
1201 | 1201 | return false; |
1202 | - } |
|
1203 | - |
|
1204 | - /** |
|
1205 | - * Return count of records from data base |
|
1206 | - * |
|
1207 | - * @param array $options |
|
1208 | - * @return array|int |
|
1209 | - */ |
|
1210 | - public static function getCount($options = []) { |
|
1202 | + } |
|
1203 | + |
|
1204 | + /** |
|
1205 | + * Return count of records from data base |
|
1206 | + * |
|
1207 | + * @param array $options |
|
1208 | + * @return array|int |
|
1209 | + */ |
|
1210 | + public static function getCount($options = []) { |
|
1211 | 1211 | if (static::$storage['type'] == 'moduleConfig') { |
1212 | - return static::getCountFromModuleStorage($options); |
|
1212 | + return static::getCountFromModuleStorage($options); |
|
1213 | 1213 | } |
1214 | 1214 | $query = App::$cur->db->newQuery(); |
1215 | 1215 | if (!$query) { |
1216 | - return 0; |
|
1216 | + return 0; |
|
1217 | 1217 | } |
1218 | 1218 | if (!empty($options['where'])) { |
1219 | - static::fixPrefix($options['where'], 'first'); |
|
1219 | + static::fixPrefix($options['where'], 'first'); |
|
1220 | 1220 | } |
1221 | 1221 | if (!empty($options['group'])) { |
1222 | - static::fixPrefix($options['group'], 'first'); |
|
1222 | + static::fixPrefix($options['group'], 'first'); |
|
1223 | 1223 | } |
1224 | 1224 | if (!empty($options['where'])) |
1225 | - $query->where($options['where']); |
|
1225 | + $query->where($options['where']); |
|
1226 | 1226 | if (!empty($options['join'])) |
1227 | - $query->join($options['join']); |
|
1227 | + $query->join($options['join']); |
|
1228 | 1228 | if (!empty($options['order'])) { |
1229 | - $query->order($options['order']); |
|
1229 | + $query->order($options['order']); |
|
1230 | 1230 | } |
1231 | 1231 | if (!empty($options['limit'])) |
1232 | - $limit = (int) $options['limit']; |
|
1232 | + $limit = (int) $options['limit']; |
|
1233 | 1233 | else { |
1234 | - $limit = 0; |
|
1234 | + $limit = 0; |
|
1235 | 1235 | } |
1236 | 1236 | if (!empty($options['start'])) |
1237 | - $start = (int) $options['start']; |
|
1237 | + $start = (int) $options['start']; |
|
1238 | 1238 | else { |
1239 | - $start = 0; |
|
1239 | + $start = 0; |
|
1240 | 1240 | } |
1241 | 1241 | if ($limit || $start) { |
1242 | - $query->limit($start, $limit); |
|
1242 | + $query->limit($start, $limit); |
|
1243 | 1243 | } |
1244 | 1244 | |
1245 | 1245 | foreach (static::$relJoins as $join) { |
1246 | - $query->join($join[0], $join[1]); |
|
1246 | + $query->join($join[0], $join[1]); |
|
1247 | 1247 | } |
1248 | 1248 | static::$relJoins = []; |
1249 | 1249 | foreach (static::$needJoin as $rel) { |
1250 | - $relations = static::relations(); |
|
1251 | - if (isset($relations[$rel])) { |
|
1250 | + $relations = static::relations(); |
|
1251 | + if (isset($relations[$rel])) { |
|
1252 | 1252 | $type = empty($relations[$rel]['type']) ? 'to' : $relations[$rel]['type']; |
1253 | 1253 | switch ($type) { |
1254 | - case 'to': |
|
1254 | + case 'to': |
|
1255 | 1255 | $relCol = $relations[$rel]['col']; |
1256 | 1256 | static::fixPrefix($relCol); |
1257 | 1257 | $query->join($relations[$rel]['model']::table(), $relations[$rel]['model']::index() . ' = ' . $relCol); |
1258 | 1258 | break; |
1259 | - case 'one': |
|
1259 | + case 'one': |
|
1260 | 1260 | $col = $relations[$rel]['col']; |
1261 | 1261 | $relations[$rel]['model']::fixPrefix($col); |
1262 | 1262 | $query->join($relations[$rel]['model']::table(), static::index() . ' = ' . $col); |
1263 | 1263 | break; |
1264 | 1264 | } |
1265 | - } |
|
1265 | + } |
|
1266 | 1266 | } |
1267 | 1267 | static::$needJoin = []; |
1268 | 1268 | $cols = 'COUNT('; |
1269 | 1269 | |
1270 | 1270 | if (!empty($options['distinct'])) { |
1271 | - if (is_bool($options['distinct'])) { |
|
1271 | + if (is_bool($options['distinct'])) { |
|
1272 | 1272 | $cols .= 'DISTINCT *'; |
1273 | - } else { |
|
1273 | + } else { |
|
1274 | 1274 | $cols .= "DISTINCT {$options['distinct']}"; |
1275 | - } |
|
1275 | + } |
|
1276 | 1276 | } else { |
1277 | - $cols .= '*'; |
|
1277 | + $cols .= '*'; |
|
1278 | 1278 | } |
1279 | 1279 | $cols .=') as `count`' . (!empty($options['cols']) ? ',' . $options['cols'] : ''); |
1280 | 1280 | $query->cols = $cols; |
1281 | 1281 | if (!empty($options['group'])) { |
1282 | - $query->group($options['group']); |
|
1282 | + $query->group($options['group']); |
|
1283 | 1283 | } |
1284 | 1284 | try { |
1285 | - $result = $query->select(static::table()); |
|
1285 | + $result = $query->select(static::table()); |
|
1286 | 1286 | } catch (PDOException $exc) { |
1287 | - if ($exc->getCode() == '42S02') { |
|
1287 | + if ($exc->getCode() == '42S02') { |
|
1288 | 1288 | static::createTable(); |
1289 | - } |
|
1290 | - $result = $query->select(static::table()); |
|
1289 | + } |
|
1290 | + $result = $query->select(static::table()); |
|
1291 | 1291 | } |
1292 | 1292 | if (!empty($options['group'])) { |
1293 | - $count = $result->getArray(); |
|
1294 | - return $count; |
|
1293 | + $count = $result->getArray(); |
|
1294 | + return $count; |
|
1295 | 1295 | } else { |
1296 | - $count = $result->fetch(); |
|
1297 | - return $count['count']; |
|
1298 | - } |
|
1299 | - } |
|
1300 | - |
|
1301 | - /** |
|
1302 | - * Update records in data base |
|
1303 | - * |
|
1304 | - * @param array $params |
|
1305 | - * @param array $where |
|
1306 | - * @return boolean |
|
1307 | - */ |
|
1308 | - public static function update($params, $where = []) { |
|
1296 | + $count = $result->fetch(); |
|
1297 | + return $count['count']; |
|
1298 | + } |
|
1299 | + } |
|
1300 | + |
|
1301 | + /** |
|
1302 | + * Update records in data base |
|
1303 | + * |
|
1304 | + * @param array $params |
|
1305 | + * @param array $where |
|
1306 | + * @return boolean |
|
1307 | + */ |
|
1308 | + public static function update($params, $where = []) { |
|
1309 | 1309 | static::fixPrefix($params); |
1310 | 1310 | |
1311 | 1311 | $cols = self::cols(); |
1312 | 1312 | |
1313 | 1313 | $values = []; |
1314 | 1314 | foreach ($cols as $col => $param) { |
1315 | - if (isset($params[$col])) |
|
1315 | + if (isset($params[$col])) |
|
1316 | 1316 | $values[$col] = $params[$col]; |
1317 | 1317 | } |
1318 | 1318 | if (empty($values)) { |
1319 | - return false; |
|
1319 | + return false; |
|
1320 | 1320 | } |
1321 | 1321 | |
1322 | 1322 | if (!empty($where)) { |
1323 | - static::fixPrefix($where, 'first'); |
|
1323 | + static::fixPrefix($where, 'first'); |
|
1324 | 1324 | |
1325 | - App::$cur->db->where($where); |
|
1325 | + App::$cur->db->where($where); |
|
1326 | 1326 | } |
1327 | 1327 | App::$cur->db->update(static::table(), $values); |
1328 | - } |
|
1329 | - |
|
1330 | - /** |
|
1331 | - * Return primary key of object |
|
1332 | - * |
|
1333 | - * @return mixed |
|
1334 | - */ |
|
1335 | - public function pk() { |
|
1328 | + } |
|
1329 | + |
|
1330 | + /** |
|
1331 | + * Return primary key of object |
|
1332 | + * |
|
1333 | + * @return mixed |
|
1334 | + */ |
|
1335 | + public function pk() { |
|
1336 | 1336 | return $this->{$this->index()}; |
1337 | - } |
|
1337 | + } |
|
1338 | 1338 | |
1339 | - /** |
|
1340 | - * Before save trigger |
|
1341 | - */ |
|
1342 | - public function beforeSave() { |
|
1339 | + /** |
|
1340 | + * Before save trigger |
|
1341 | + */ |
|
1342 | + public function beforeSave() { |
|
1343 | 1343 | |
1344 | - } |
|
1344 | + } |
|
1345 | 1345 | |
1346 | - /** |
|
1347 | - * Save object to module storage |
|
1348 | - * |
|
1349 | - * @param array $options |
|
1350 | - * @return boolean |
|
1351 | - */ |
|
1352 | - public function saveModuleStorage($options) { |
|
1346 | + /** |
|
1347 | + * Save object to module storage |
|
1348 | + * |
|
1349 | + * @param array $options |
|
1350 | + * @return boolean |
|
1351 | + */ |
|
1352 | + public function saveModuleStorage($options) { |
|
1353 | 1353 | |
1354 | 1354 | $col = static::index(); |
1355 | 1355 | $id = $this->pk(); |
@@ -1357,54 +1357,54 @@ discard block |
||
1357 | 1357 | $classPath = explode('\\', get_called_class()); |
1358 | 1358 | |
1359 | 1359 | if (!empty(static::$storage['options']['share'])) { |
1360 | - $moduleConfig = Config::share($classPath[0]); |
|
1360 | + $moduleConfig = Config::share($classPath[0]); |
|
1361 | 1361 | } else { |
1362 | - $moduleConfig = Config::module($classPath[0], strpos(static::$storage['type'], 'system') !== false); |
|
1362 | + $moduleConfig = Config::module($classPath[0], strpos(static::$storage['type'], 'system') !== false); |
|
1363 | 1363 | } |
1364 | 1364 | |
1365 | 1365 | if (!empty($moduleConfig['storage']['appTypeSplit'])) { |
1366 | - if (empty($options['appType'])) { |
|
1366 | + if (empty($options['appType'])) { |
|
1367 | 1367 | $appType = App::$cur->type; |
1368 | - } else { |
|
1368 | + } else { |
|
1369 | 1369 | $appType = $options['appType']; |
1370 | - } |
|
1371 | - $storage = !empty($moduleConfig['storage'][$appType]) ? $moduleConfig['storage'][$appType] : []; |
|
1370 | + } |
|
1371 | + $storage = !empty($moduleConfig['storage'][$appType]) ? $moduleConfig['storage'][$appType] : []; |
|
1372 | 1372 | } else { |
1373 | - $storage = !empty($moduleConfig['storage']) ? $moduleConfig['storage'] : []; |
|
1373 | + $storage = !empty($moduleConfig['storage']) ? $moduleConfig['storage'] : []; |
|
1374 | 1374 | } |
1375 | 1375 | if (empty($storage[$classPath[1]])) { |
1376 | - $storage[$classPath[1]] = []; |
|
1376 | + $storage[$classPath[1]] = []; |
|
1377 | 1377 | } |
1378 | 1378 | if ($id) { |
1379 | - foreach ($storage[$classPath[1]] as $key => $item) { |
|
1379 | + foreach ($storage[$classPath[1]] as $key => $item) { |
|
1380 | 1380 | if ($item[$col] == $id) { |
1381 | - $storage[$classPath[1]][$key] = $this->_params; |
|
1382 | - break; |
|
1381 | + $storage[$classPath[1]][$key] = $this->_params; |
|
1382 | + break; |
|
1383 | + } |
|
1383 | 1384 | } |
1384 | - } |
|
1385 | 1385 | } else { |
1386 | - $id = !empty($storage['scheme'][$classPath[1]]['ai']) ? $storage['scheme'][$classPath[1]]['ai'] : 1; |
|
1387 | - $this->$col = $id; |
|
1388 | - $storage['scheme'][$classPath[1]]['ai'] = $id + 1; |
|
1389 | - $storage[$classPath[1]][] = $this->_params; |
|
1386 | + $id = !empty($storage['scheme'][$classPath[1]]['ai']) ? $storage['scheme'][$classPath[1]]['ai'] : 1; |
|
1387 | + $this->$col = $id; |
|
1388 | + $storage['scheme'][$classPath[1]]['ai'] = $id + 1; |
|
1389 | + $storage[$classPath[1]][] = $this->_params; |
|
1390 | 1390 | } |
1391 | 1391 | if (!empty($moduleConfig['storage']['appTypeSplit'])) { |
1392 | - $moduleConfig['storage'][$appType] = $storage; |
|
1392 | + $moduleConfig['storage'][$appType] = $storage; |
|
1393 | 1393 | } else { |
1394 | - $moduleConfig['storage'] = $storage; |
|
1394 | + $moduleConfig['storage'] = $storage; |
|
1395 | 1395 | } |
1396 | 1396 | if (empty(static::$storage['options']['share'])) { |
1397 | - Config::save('module', $moduleConfig, $classPath[0]); |
|
1397 | + Config::save('module', $moduleConfig, $classPath[0]); |
|
1398 | 1398 | } else { |
1399 | - Config::save('share', $moduleConfig, $classPath[0]); |
|
1399 | + Config::save('share', $moduleConfig, $classPath[0]); |
|
1400 | 1400 | } |
1401 | 1401 | return true; |
1402 | - } |
|
1402 | + } |
|
1403 | 1403 | |
1404 | - /** |
|
1405 | - * Update tree path category |
|
1406 | - */ |
|
1407 | - public function changeCategoryTree() { |
|
1404 | + /** |
|
1405 | + * Update tree path category |
|
1406 | + */ |
|
1407 | + public function changeCategoryTree() { |
|
1408 | 1408 | $class = get_class($this); |
1409 | 1409 | $itemModel = $class::$treeCategory; |
1410 | 1410 | $oldPath = $this->tree_path; |
@@ -1415,572 +1415,572 @@ discard block |
||
1415 | 1415 | $categoryTreeCol = $this->colPrefix() . 'tree_path'; |
1416 | 1416 | $categoryTable = \App::$cur->db->table_prefix . $this->table(); |
1417 | 1417 | if ($oldPath) { |
1418 | - \App::$cur->db->query('UPDATE |
|
1418 | + \App::$cur->db->query('UPDATE |
|
1419 | 1419 | ' . $categoryTable . ' |
1420 | 1420 | SET |
1421 | 1421 | ' . $categoryTreeCol . ' = REPLACE(' . $categoryTreeCol . ', "' . $oldPath . $this->id . '/' . '", "' . $this->tree_path . $this->id . '/' . '") |
1422 | 1422 | WHERE ' . $categoryTreeCol . ' LIKE "' . $oldPath . $this->id . '/' . '%"'); |
1423 | 1423 | |
1424 | - \App::$cur->db->query('UPDATE |
|
1424 | + \App::$cur->db->query('UPDATE |
|
1425 | 1425 | ' . $itemsTable . ' |
1426 | 1426 | SET |
1427 | 1427 | ' . $itemTreeCol . ' = REPLACE(' . $itemTreeCol . ', "' . $oldPath . $this->id . '/' . '", "' . $this->tree_path . $this->id . '/' . '") |
1428 | 1428 | WHERE ' . $itemTreeCol . ' LIKE "' . $oldPath . $this->id . '/' . '%"'); |
1429 | 1429 | } |
1430 | 1430 | $itemModel::update([$itemTreeCol => $this->tree_path . $this->id . '/'], [$itemModel::colPrefix() . $this->index(), $this->id]); |
1431 | - } |
|
1432 | - |
|
1433 | - /** |
|
1434 | - * Return tree path |
|
1435 | - * |
|
1436 | - * @param \Model $catalog |
|
1437 | - * @return string |
|
1438 | - */ |
|
1439 | - public function getCatalogTree($catalog) { |
|
1431 | + } |
|
1432 | + |
|
1433 | + /** |
|
1434 | + * Return tree path |
|
1435 | + * |
|
1436 | + * @param \Model $catalog |
|
1437 | + * @return string |
|
1438 | + */ |
|
1439 | + public function getCatalogTree($catalog) { |
|
1440 | 1440 | $catalogClass = get_class($catalog); |
1441 | 1441 | $catalogParent = $catalogClass::get($catalog->parent_id); |
1442 | 1442 | if ($catalog && $catalogParent) { |
1443 | - if ($catalogParent->tree_path) { |
|
1443 | + if ($catalogParent->tree_path) { |
|
1444 | 1444 | return $catalogParent->tree_path . $catalogParent->id . '/'; |
1445 | - } else { |
|
1445 | + } else { |
|
1446 | 1446 | return $this->getCatalogTree($catalogParent) . $catalogParent->id . '/'; |
1447 | - } |
|
1447 | + } |
|
1448 | 1448 | } |
1449 | 1449 | return '/'; |
1450 | - } |
|
1450 | + } |
|
1451 | 1451 | |
1452 | - /** |
|
1453 | - * Update tree path item |
|
1454 | - */ |
|
1455 | - public function changeItemTree() { |
|
1452 | + /** |
|
1453 | + * Update tree path item |
|
1454 | + */ |
|
1455 | + public function changeItemTree() { |
|
1456 | 1456 | $class = get_class($this); |
1457 | 1457 | $categoryModel = $class::$categoryModel; |
1458 | 1458 | $category = $categoryModel::get($this->{$categoryModel::index()}); |
1459 | 1459 | if ($category) { |
1460 | - $this->tree_path = $category->tree_path . $category->pk() . '/'; |
|
1460 | + $this->tree_path = $category->tree_path . $category->pk() . '/'; |
|
1461 | 1461 | } else { |
1462 | - $this->tree_path = '/'; |
|
1462 | + $this->tree_path = '/'; |
|
1463 | + } |
|
1463 | 1464 | } |
1464 | - } |
|
1465 | 1465 | |
1466 | - /** |
|
1467 | - * Save object to data base |
|
1468 | - * |
|
1469 | - * @param array $options |
|
1470 | - * @return boolean|int |
|
1471 | - */ |
|
1472 | - public function save($options = []) { |
|
1466 | + /** |
|
1467 | + * Save object to data base |
|
1468 | + * |
|
1469 | + * @param array $options |
|
1470 | + * @return boolean|int |
|
1471 | + */ |
|
1472 | + public function save($options = []) { |
|
1473 | 1473 | |
1474 | 1474 | if (static::$storage['type'] == 'moduleConfig') { |
1475 | - return static::saveModuleStorage($options); |
|
1475 | + return static::saveModuleStorage($options); |
|
1476 | 1476 | } |
1477 | 1477 | $class = get_class($this); |
1478 | 1478 | if ($class::$categoryModel) { |
1479 | - $this->changeItemTree(); |
|
1479 | + $this->changeItemTree(); |
|
1480 | 1480 | } |
1481 | 1481 | if ($class::$treeCategory) { |
1482 | - $this->changeCategoryTree(); |
|
1482 | + $this->changeCategoryTree(); |
|
1483 | 1483 | } |
1484 | 1484 | if (!empty($this->_changedParams) && $this->pk()) { |
1485 | - Inji::$inst->event('modelItemParamsChanged-' . get_called_class(), $this); |
|
1485 | + Inji::$inst->event('modelItemParamsChanged-' . get_called_class(), $this); |
|
1486 | 1486 | } |
1487 | 1487 | $this->beforeSave(); |
1488 | 1488 | $values = []; |
1489 | 1489 | |
1490 | 1490 | foreach ($this->cols() as $col => $param) { |
1491 | - if (isset($this->_params[$col])) { |
|
1491 | + if (isset($this->_params[$col])) { |
|
1492 | 1492 | $values[$col] = $this->_params[$col]; |
1493 | - } |
|
1493 | + } |
|
1494 | 1494 | } |
1495 | 1495 | foreach ($class::$cols as $colName => $params) { |
1496 | - $class::fixPrefix($colName); |
|
1497 | - if (isset($params['default']) && !isset($values[$colName])) { |
|
1496 | + $class::fixPrefix($colName); |
|
1497 | + if (isset($params['default']) && !isset($values[$colName])) { |
|
1498 | 1498 | $this->_params[$colName] = $values[$colName] = $params['default']; |
1499 | - } |
|
1499 | + } |
|
1500 | 1500 | } |
1501 | 1501 | if (empty($values) && empty($options['empty'])) { |
1502 | - return false; |
|
1502 | + return false; |
|
1503 | 1503 | } |
1504 | 1504 | |
1505 | 1505 | if ($this->pk()) { |
1506 | - $new = false; |
|
1507 | - if ($this->get($this->_params[$this->index()])) { |
|
1506 | + $new = false; |
|
1507 | + if ($this->get($this->_params[$this->index()])) { |
|
1508 | 1508 | App::$cur->db->where($this->index(), $this->_params[$this->index()]); |
1509 | 1509 | App::$cur->db->update($this->table(), $values); |
1510 | - } else { |
|
1510 | + } else { |
|
1511 | 1511 | |
1512 | 1512 | $this->_params[$this->index()] = App::$cur->db->insert($this->table(), $values); |
1513 | - } |
|
1513 | + } |
|
1514 | 1514 | } else { |
1515 | - $new = true; |
|
1516 | - $this->_params[$this->index()] = App::$cur->db->insert($this->table(), $values); |
|
1515 | + $new = true; |
|
1516 | + $this->_params[$this->index()] = App::$cur->db->insert($this->table(), $values); |
|
1517 | 1517 | } |
1518 | 1518 | $this->logChanges($new); |
1519 | 1519 | App::$cur->db->where($this->index(), $this->_params[$this->index()]); |
1520 | 1520 | try { |
1521 | - $result = App::$cur->db->select($this->table()); |
|
1521 | + $result = App::$cur->db->select($this->table()); |
|
1522 | 1522 | } catch (PDOException $exc) { |
1523 | - if ($exc->getCode() == '42S02') { |
|
1523 | + if ($exc->getCode() == '42S02') { |
|
1524 | 1524 | $this->createTable(); |
1525 | - } |
|
1526 | - $result = App::$cur->db->select($this->table()); |
|
1525 | + } |
|
1526 | + $result = App::$cur->db->select($this->table()); |
|
1527 | 1527 | } |
1528 | 1528 | $this->_params = $result->fetch(); |
1529 | 1529 | if ($new) { |
1530 | - Inji::$inst->event('modelCreatedItem-' . get_called_class(), $this); |
|
1530 | + Inji::$inst->event('modelCreatedItem-' . get_called_class(), $this); |
|
1531 | 1531 | } |
1532 | 1532 | $this->afterSave(); |
1533 | 1533 | return $this->{$this->index()}; |
1534 | - } |
|
1534 | + } |
|
1535 | 1535 | |
1536 | - /** |
|
1537 | - * After save trigger |
|
1538 | - */ |
|
1539 | - public function afterSave() { |
|
1536 | + /** |
|
1537 | + * After save trigger |
|
1538 | + */ |
|
1539 | + public function afterSave() { |
|
1540 | 1540 | |
1541 | - } |
|
1541 | + } |
|
1542 | 1542 | |
1543 | - /** |
|
1544 | - * Before delete trigger |
|
1545 | - */ |
|
1546 | - public function beforeDelete() { |
|
1543 | + /** |
|
1544 | + * Before delete trigger |
|
1545 | + */ |
|
1546 | + public function beforeDelete() { |
|
1547 | 1547 | |
1548 | - } |
|
1548 | + } |
|
1549 | 1549 | |
1550 | - /** |
|
1551 | - * Delete item from module storage |
|
1552 | - * |
|
1553 | - * @param array $options |
|
1554 | - * @return boolean |
|
1555 | - */ |
|
1556 | - public function deleteFromModuleStorage($options) { |
|
1550 | + /** |
|
1551 | + * Delete item from module storage |
|
1552 | + * |
|
1553 | + * @param array $options |
|
1554 | + * @return boolean |
|
1555 | + */ |
|
1556 | + public function deleteFromModuleStorage($options) { |
|
1557 | 1557 | |
1558 | 1558 | $col = static::index(); |
1559 | 1559 | $id = $this->pk(); |
1560 | 1560 | $appType = ''; |
1561 | 1561 | $classPath = explode('\\', get_called_class()); |
1562 | 1562 | if (!empty(static::$storage['options']['share'])) { |
1563 | - $moduleConfig = Config::share($classPath[0]); |
|
1563 | + $moduleConfig = Config::share($classPath[0]); |
|
1564 | 1564 | } else { |
1565 | - $moduleConfig = Config::module($classPath[0], strpos(static::$storage['type'], 'system') !== false); |
|
1565 | + $moduleConfig = Config::module($classPath[0], strpos(static::$storage['type'], 'system') !== false); |
|
1566 | 1566 | } |
1567 | 1567 | |
1568 | 1568 | if (!empty($moduleConfig['storage']['appTypeSplit'])) { |
1569 | - if (empty($options['appType'])) { |
|
1569 | + if (empty($options['appType'])) { |
|
1570 | 1570 | $appType = App::$cur->type; |
1571 | - } else { |
|
1571 | + } else { |
|
1572 | 1572 | $appType = $options['appType']; |
1573 | - } |
|
1574 | - $storage = !empty($moduleConfig['storage'][$appType]) ? $moduleConfig['storage'][$appType] : []; |
|
1573 | + } |
|
1574 | + $storage = !empty($moduleConfig['storage'][$appType]) ? $moduleConfig['storage'][$appType] : []; |
|
1575 | 1575 | } else { |
1576 | - $storage = !empty($moduleConfig['storage']) ? $moduleConfig['storage'] : []; |
|
1576 | + $storage = !empty($moduleConfig['storage']) ? $moduleConfig['storage'] : []; |
|
1577 | 1577 | } |
1578 | 1578 | if (empty($storage[$classPath[1]])) { |
1579 | - $storage[$classPath[1]] = []; |
|
1579 | + $storage[$classPath[1]] = []; |
|
1580 | 1580 | } |
1581 | 1581 | foreach ($storage[$classPath[1]] as $key => $item) { |
1582 | 1582 | |
1583 | - if ($item[$col] == $id) { |
|
1583 | + if ($item[$col] == $id) { |
|
1584 | 1584 | unset($storage[$classPath[1]][$key]); |
1585 | 1585 | break; |
1586 | - } |
|
1586 | + } |
|
1587 | 1587 | } |
1588 | 1588 | if (!empty($moduleConfig['storage']['appTypeSplit'])) { |
1589 | - $moduleConfig['storage'][$appType] = $storage; |
|
1589 | + $moduleConfig['storage'][$appType] = $storage; |
|
1590 | 1590 | } else { |
1591 | - $moduleConfig['storage'] = $storage; |
|
1591 | + $moduleConfig['storage'] = $storage; |
|
1592 | 1592 | } |
1593 | 1593 | if (empty(static::$storage['options']['share'])) { |
1594 | - Config::save('module', $moduleConfig, $classPath[0]); |
|
1594 | + Config::save('module', $moduleConfig, $classPath[0]); |
|
1595 | 1595 | } else { |
1596 | - Config::save('share', $moduleConfig, $classPath[0]); |
|
1596 | + Config::save('share', $moduleConfig, $classPath[0]); |
|
1597 | 1597 | } |
1598 | 1598 | return true; |
1599 | - } |
|
1600 | - |
|
1601 | - /** |
|
1602 | - * Delete item from data base |
|
1603 | - * |
|
1604 | - * @param array $options |
|
1605 | - * @return boolean |
|
1606 | - */ |
|
1607 | - public function delete($options = []) { |
|
1599 | + } |
|
1600 | + |
|
1601 | + /** |
|
1602 | + * Delete item from data base |
|
1603 | + * |
|
1604 | + * @param array $options |
|
1605 | + * @return boolean |
|
1606 | + */ |
|
1607 | + public function delete($options = []) { |
|
1608 | 1608 | $this->beforeDelete(); |
1609 | 1609 | |
1610 | 1610 | if (static::$storage['type'] == 'moduleConfig') { |
1611 | - return static::deleteFromModuleStorage($options); |
|
1611 | + return static::deleteFromModuleStorage($options); |
|
1612 | 1612 | } |
1613 | 1613 | if (!empty($this->_params[$this->index()])) { |
1614 | - App::$cur->db->where($this->index(), $this->_params[$this->index()]); |
|
1615 | - $result = App::$cur->db->delete($this->table()); |
|
1616 | - if ($result) { |
|
1614 | + App::$cur->db->where($this->index(), $this->_params[$this->index()]); |
|
1615 | + $result = App::$cur->db->delete($this->table()); |
|
1616 | + if ($result) { |
|
1617 | 1617 | $this->afterDelete(); |
1618 | 1618 | return $result; |
1619 | - } |
|
1619 | + } |
|
1620 | 1620 | } |
1621 | 1621 | return false; |
1622 | - } |
|
1623 | - |
|
1624 | - /** |
|
1625 | - * Delete items from data base |
|
1626 | - * |
|
1627 | - * @param array $where |
|
1628 | - */ |
|
1629 | - public static function deleteList($where) { |
|
1622 | + } |
|
1623 | + |
|
1624 | + /** |
|
1625 | + * Delete items from data base |
|
1626 | + * |
|
1627 | + * @param array $where |
|
1628 | + */ |
|
1629 | + public static function deleteList($where) { |
|
1630 | 1630 | if (!empty($where)) { |
1631 | - static::fixPrefix($where, 'first'); |
|
1632 | - App::$cur->db->where($where); |
|
1631 | + static::fixPrefix($where, 'first'); |
|
1632 | + App::$cur->db->where($where); |
|
1633 | 1633 | } |
1634 | 1634 | App::$cur->db->delete(static::table()); |
1635 | - } |
|
1635 | + } |
|
1636 | 1636 | |
1637 | - /** |
|
1638 | - * After delete trigger |
|
1639 | - */ |
|
1640 | - public function afterDelete() { |
|
1637 | + /** |
|
1638 | + * After delete trigger |
|
1639 | + */ |
|
1640 | + public function afterDelete() { |
|
1641 | 1641 | |
1642 | - } |
|
1642 | + } |
|
1643 | 1643 | |
1644 | - /** |
|
1645 | - * find relation for col name |
|
1646 | - * |
|
1647 | - * @param string $col |
|
1648 | - * @return array|null |
|
1649 | - */ |
|
1650 | - public static function findRelation($col) { |
|
1644 | + /** |
|
1645 | + * find relation for col name |
|
1646 | + * |
|
1647 | + * @param string $col |
|
1648 | + * @return array|null |
|
1649 | + */ |
|
1650 | + public static function findRelation($col) { |
|
1651 | 1651 | |
1652 | 1652 | foreach (static::relations() as $relName => $rel) { |
1653 | - if ($rel['col'] == $col) |
|
1653 | + if ($rel['col'] == $col) |
|
1654 | 1654 | return $relName; |
1655 | 1655 | } |
1656 | 1656 | return NULL; |
1657 | - } |
|
1658 | - |
|
1659 | - /** |
|
1660 | - * Set params for model |
|
1661 | - * |
|
1662 | - * @param array $params |
|
1663 | - */ |
|
1664 | - public function setParams($params) { |
|
1657 | + } |
|
1658 | + |
|
1659 | + /** |
|
1660 | + * Set params for model |
|
1661 | + * |
|
1662 | + * @param array $params |
|
1663 | + */ |
|
1664 | + public function setParams($params) { |
|
1665 | 1665 | static::fixPrefix($params); |
1666 | 1666 | $className = get_called_class(); |
1667 | 1667 | foreach ($params as $paramName => $value) { |
1668 | - $shortName = preg_replace('!' . $this->colPrefix() . '!', '', $paramName); |
|
1669 | - if (!empty($className::$cols[$shortName])) { |
|
1668 | + $shortName = preg_replace('!' . $this->colPrefix() . '!', '', $paramName); |
|
1669 | + if (!empty($className::$cols[$shortName])) { |
|
1670 | 1670 | switch ($className::$cols[$shortName]['type']) { |
1671 | - case 'decimal': |
|
1671 | + case 'decimal': |
|
1672 | 1672 | $params[$paramName] = (float) $value; |
1673 | 1673 | break; |
1674 | - case 'number': |
|
1674 | + case 'number': |
|
1675 | 1675 | $params[$paramName] = (int) $value; |
1676 | 1676 | break; |
1677 | - case 'bool': |
|
1677 | + case 'bool': |
|
1678 | 1678 | $params[$paramName] = (bool) $value; |
1679 | 1679 | break; |
1680 | 1680 | } |
1681 | - } |
|
1681 | + } |
|
1682 | 1682 | } |
1683 | 1683 | $this->_params = array_merge($this->_params, $params); |
1684 | - } |
|
1685 | - |
|
1686 | - /** |
|
1687 | - * Return relation |
|
1688 | - * |
|
1689 | - * @param string $relName |
|
1690 | - * @return array|boolean |
|
1691 | - */ |
|
1692 | - public static function getRelation($relName) { |
|
1684 | + } |
|
1685 | + |
|
1686 | + /** |
|
1687 | + * Return relation |
|
1688 | + * |
|
1689 | + * @param string $relName |
|
1690 | + * @return array|boolean |
|
1691 | + */ |
|
1692 | + public static function getRelation($relName) { |
|
1693 | 1693 | $relations = static::relations(); |
1694 | 1694 | return !empty($relations[$relName]) ? $relations[$relName] : false; |
1695 | - } |
|
1696 | - |
|
1697 | - /** |
|
1698 | - * Load relation |
|
1699 | - * |
|
1700 | - * @param string $name |
|
1701 | - * @param array $params |
|
1702 | - * @return null|array|integer|\Model |
|
1703 | - */ |
|
1704 | - public function loadRelation($name, $params = []) { |
|
1695 | + } |
|
1696 | + |
|
1697 | + /** |
|
1698 | + * Load relation |
|
1699 | + * |
|
1700 | + * @param string $name |
|
1701 | + * @param array $params |
|
1702 | + * @return null|array|integer|\Model |
|
1703 | + */ |
|
1704 | + public function loadRelation($name, $params = []) { |
|
1705 | 1705 | $relation = static::getRelation($name); |
1706 | 1706 | if ($relation) { |
1707 | - if (!isset($relation['type'])) { |
|
1707 | + if (!isset($relation['type'])) { |
|
1708 | 1708 | $type = 'to'; |
1709 | - } else { |
|
1709 | + } else { |
|
1710 | 1710 | $type = $relation['type']; |
1711 | - } |
|
1712 | - $getCol = null; |
|
1713 | - $getParams = []; |
|
1714 | - switch ($type) { |
|
1711 | + } |
|
1712 | + $getCol = null; |
|
1713 | + $getParams = []; |
|
1714 | + switch ($type) { |
|
1715 | 1715 | case 'relModel': |
1716 | 1716 | if (!$this->pk()) { |
1717 | 1717 | return []; |
1718 | - } |
|
1719 | - $fixedCol = $relation['model']::index(); |
|
1720 | - $relation['relModel']::fixPrefix($fixedCol); |
|
1721 | - $ids = array_keys($relation['relModel']::getList(['where' => [$this->index(), $this->pk()], 'array' => true, 'key' => $fixedCol])); |
|
1722 | - if (empty($ids)) { |
|
1718 | + } |
|
1719 | + $fixedCol = $relation['model']::index(); |
|
1720 | + $relation['relModel']::fixPrefix($fixedCol); |
|
1721 | + $ids = array_keys($relation['relModel']::getList(['where' => [$this->index(), $this->pk()], 'array' => true, 'key' => $fixedCol])); |
|
1722 | + if (empty($ids)) { |
|
1723 | 1723 | if (empty($params['count'])) { |
1724 | - return []; |
|
1724 | + return []; |
|
1725 | 1725 | } else { |
1726 | - return 0; |
|
1726 | + return 0; |
|
1727 | + } |
|
1727 | 1728 | } |
1728 | - } |
|
1729 | - $getType = 'getList'; |
|
1730 | - $options = [ |
|
1731 | - 'where' => [$relation['model']::index(), implode(',', $ids), 'IN'], |
|
1732 | - 'array' => (!empty($params['array'])) ? true : false, |
|
1733 | - 'key' => (isset($params['key'])) ? $params['key'] : ((isset($relation['resultKey'])) ? $relation['resultKey'] : null), |
|
1734 | - 'start' => (isset($params['start'])) ? $params['start'] : ((isset($relation['start'])) ? $relation['start'] : null), |
|
1735 | - 'order' => (isset($params['order'])) ? $params['order'] : ((isset($relation['order'])) ? $relation['order'] : null), |
|
1736 | - 'limit' => (isset($params['limit'])) ? $params['limit'] : ((isset($relation['limit'])) ? $relation['limit'] : null), |
|
1737 | - ]; |
|
1738 | - break; |
|
1729 | + $getType = 'getList'; |
|
1730 | + $options = [ |
|
1731 | + 'where' => [$relation['model']::index(), implode(',', $ids), 'IN'], |
|
1732 | + 'array' => (!empty($params['array'])) ? true : false, |
|
1733 | + 'key' => (isset($params['key'])) ? $params['key'] : ((isset($relation['resultKey'])) ? $relation['resultKey'] : null), |
|
1734 | + 'start' => (isset($params['start'])) ? $params['start'] : ((isset($relation['start'])) ? $relation['start'] : null), |
|
1735 | + 'order' => (isset($params['order'])) ? $params['order'] : ((isset($relation['order'])) ? $relation['order'] : null), |
|
1736 | + 'limit' => (isset($params['limit'])) ? $params['limit'] : ((isset($relation['limit'])) ? $relation['limit'] : null), |
|
1737 | + ]; |
|
1738 | + break; |
|
1739 | 1739 | case 'many': |
1740 | 1740 | if (!$this->{$this->index()}) { |
1741 | 1741 | return []; |
1742 | - } |
|
1743 | - $getType = 'getList'; |
|
1744 | - $options = [ |
|
1745 | - 'join' => (isset($relation['join'])) ? $relation['join'] : null, |
|
1746 | - 'key' => (isset($params['key'])) ? $params['key'] : ((isset($relation['resultKey'])) ? $relation['resultKey'] : null), |
|
1747 | - 'array' => (!empty($params['array'])) ? true : false, |
|
1748 | - 'forSelect' => (!empty($params['forSelect'])) ? true : false, |
|
1749 | - 'order' => (isset($params['order'])) ? $params['order'] : ((isset($relation['order'])) ? $relation['order'] : null), |
|
1750 | - 'start' => (isset($params['start'])) ? $params['start'] : ((isset($relation['start'])) ? $relation['start'] : null), |
|
1751 | - 'limit' => (isset($params['limit'])) ? $params['limit'] : ((isset($relation['limit'])) ? $relation['limit'] : null), |
|
1752 | - 'appType' => (isset($params['appType'])) ? $params['appType'] : ((isset($relation['appType'])) ? $relation['appType'] : null), |
|
1753 | - 'where' => [] |
|
1754 | - ]; |
|
1755 | - $options['where'][] = [$relation['col'], $this->{$this->index()}]; |
|
1756 | - if (!empty($relation['where'])) { |
|
1742 | + } |
|
1743 | + $getType = 'getList'; |
|
1744 | + $options = [ |
|
1745 | + 'join' => (isset($relation['join'])) ? $relation['join'] : null, |
|
1746 | + 'key' => (isset($params['key'])) ? $params['key'] : ((isset($relation['resultKey'])) ? $relation['resultKey'] : null), |
|
1747 | + 'array' => (!empty($params['array'])) ? true : false, |
|
1748 | + 'forSelect' => (!empty($params['forSelect'])) ? true : false, |
|
1749 | + 'order' => (isset($params['order'])) ? $params['order'] : ((isset($relation['order'])) ? $relation['order'] : null), |
|
1750 | + 'start' => (isset($params['start'])) ? $params['start'] : ((isset($relation['start'])) ? $relation['start'] : null), |
|
1751 | + 'limit' => (isset($params['limit'])) ? $params['limit'] : ((isset($relation['limit'])) ? $relation['limit'] : null), |
|
1752 | + 'appType' => (isset($params['appType'])) ? $params['appType'] : ((isset($relation['appType'])) ? $relation['appType'] : null), |
|
1753 | + 'where' => [] |
|
1754 | + ]; |
|
1755 | + $options['where'][] = [$relation['col'], $this->{$this->index()}]; |
|
1756 | + if (!empty($relation['where'])) { |
|
1757 | 1757 | $options['where'] = array_merge($options['where'], [$relation['where']]); |
1758 | - } |
|
1759 | - if (!empty($params['where'])) { |
|
1758 | + } |
|
1759 | + if (!empty($params['where'])) { |
|
1760 | 1760 | $options['where'] = array_merge($options['where'], [$params['where']]); |
1761 | - } |
|
1762 | - break; |
|
1761 | + } |
|
1762 | + break; |
|
1763 | 1763 | case 'one': |
1764 | 1764 | $getType = 'get'; |
1765 | - $options = [$relation['col'], $this->pk()]; |
|
1766 | - break; |
|
1765 | + $options = [$relation['col'], $this->pk()]; |
|
1766 | + break; |
|
1767 | 1767 | default: |
1768 | 1768 | if ($this->$relation['col'] === NULL) { |
1769 | 1769 | return null; |
1770 | - } |
|
1771 | - $getType = 'get'; |
|
1772 | - $options = $this->$relation['col']; |
|
1773 | - $getParams['appType'] = $this->appType; |
|
1774 | - } |
|
1775 | - if (!empty($params['count'])) { |
|
1770 | + } |
|
1771 | + $getType = 'get'; |
|
1772 | + $options = $this->$relation['col']; |
|
1773 | + $getParams['appType'] = $this->appType; |
|
1774 | + } |
|
1775 | + if (!empty($params['count'])) { |
|
1776 | 1776 | if (class_exists($relation['model'])) { |
1777 | - return $relation['model']::getCount($options); |
|
1777 | + return $relation['model']::getCount($options); |
|
1778 | 1778 | } |
1779 | 1779 | return 0; |
1780 | - } else { |
|
1780 | + } else { |
|
1781 | 1781 | if (class_exists($relation['model'])) { |
1782 | - $this->loadedRelations[$name][json_encode($params)] = $relation['model']::$getType($options, $getCol, $getParams); |
|
1782 | + $this->loadedRelations[$name][json_encode($params)] = $relation['model']::$getType($options, $getCol, $getParams); |
|
1783 | 1783 | } else { |
1784 | - $this->loadedRelations[$name][json_encode($params)] = []; |
|
1784 | + $this->loadedRelations[$name][json_encode($params)] = []; |
|
1785 | 1785 | } |
1786 | - } |
|
1787 | - return $this->loadedRelations[$name][json_encode($params)]; |
|
1786 | + } |
|
1787 | + return $this->loadedRelations[$name][json_encode($params)]; |
|
1788 | 1788 | } |
1789 | 1789 | return NULL; |
1790 | - } |
|
1791 | - |
|
1792 | - /** |
|
1793 | - * Add relation item |
|
1794 | - * |
|
1795 | - * @param string $relName |
|
1796 | - * @param \Model $objectId |
|
1797 | - * @return \Model|boolean |
|
1798 | - */ |
|
1799 | - public function addRelation($relName, $objectId) { |
|
1790 | + } |
|
1791 | + |
|
1792 | + /** |
|
1793 | + * Add relation item |
|
1794 | + * |
|
1795 | + * @param string $relName |
|
1796 | + * @param \Model $objectId |
|
1797 | + * @return \Model|boolean |
|
1798 | + */ |
|
1799 | + public function addRelation($relName, $objectId) { |
|
1800 | 1800 | $relation = $this->getRelation($relName); |
1801 | 1801 | if ($relation) { |
1802 | - $rel = $relation['relModel']::get([[$relation['model']::index(), $objectId], [$this->index(), $this->pk()]]); |
|
1803 | - if (!$rel) { |
|
1802 | + $rel = $relation['relModel']::get([[$relation['model']::index(), $objectId], [$this->index(), $this->pk()]]); |
|
1803 | + if (!$rel) { |
|
1804 | 1804 | $rel = new $relation['relModel']([ |
1805 | 1805 | $relation['model']::index() => $objectId, |
1806 | 1806 | $this->index() => $this->pk() |
1807 | 1807 | ]); |
1808 | 1808 | $rel->save(); |
1809 | - } |
|
1810 | - return $rel; |
|
1809 | + } |
|
1810 | + return $rel; |
|
1811 | 1811 | } |
1812 | 1812 | return false; |
1813 | - } |
|
1814 | - |
|
1815 | - /** |
|
1816 | - * Check user access for form |
|
1817 | - * |
|
1818 | - * @param string $formName |
|
1819 | - * @return boolean |
|
1820 | - */ |
|
1821 | - public function checkFormAccess($formName) { |
|
1813 | + } |
|
1814 | + |
|
1815 | + /** |
|
1816 | + * Check user access for form |
|
1817 | + * |
|
1818 | + * @param string $formName |
|
1819 | + * @return boolean |
|
1820 | + */ |
|
1821 | + public function checkFormAccess($formName) { |
|
1822 | 1822 | if ($formName == 'manage' && !Users\User::$cur->isAdmin()) { |
1823 | - return false; |
|
1823 | + return false; |
|
1824 | 1824 | } |
1825 | 1825 | return true; |
1826 | - } |
|
1827 | - |
|
1828 | - /** |
|
1829 | - * Check access for model |
|
1830 | - * |
|
1831 | - * @param string $mode |
|
1832 | - * @param \Users\User $user |
|
1833 | - * @return boolean |
|
1834 | - */ |
|
1835 | - public function checkAccess($mode = 'write', $user = null) { |
|
1826 | + } |
|
1827 | + |
|
1828 | + /** |
|
1829 | + * Check access for model |
|
1830 | + * |
|
1831 | + * @param string $mode |
|
1832 | + * @param \Users\User $user |
|
1833 | + * @return boolean |
|
1834 | + */ |
|
1835 | + public function checkAccess($mode = 'write', $user = null) { |
|
1836 | 1836 | if (!$user) { |
1837 | - $user = \Users\User::$cur; |
|
1837 | + $user = \Users\User::$cur; |
|
1838 | 1838 | } |
1839 | 1839 | return $user->isAdmin(); |
1840 | - } |
|
1841 | - |
|
1842 | - /** |
|
1843 | - * Param and relation with params getter |
|
1844 | - * |
|
1845 | - * @param string $name |
|
1846 | - * @param array $params |
|
1847 | - * @return \Value|mixed |
|
1848 | - */ |
|
1849 | - public function __call($name, $params) { |
|
1840 | + } |
|
1841 | + |
|
1842 | + /** |
|
1843 | + * Param and relation with params getter |
|
1844 | + * |
|
1845 | + * @param string $name |
|
1846 | + * @param array $params |
|
1847 | + * @return \Value|mixed |
|
1848 | + */ |
|
1849 | + public function __call($name, $params) { |
|
1850 | 1850 | $fixedName = $name; |
1851 | 1851 | static::fixPrefix($fixedName); |
1852 | 1852 | if (isset($this->_params[$fixedName])) { |
1853 | - return new Value($this, $fixedName); |
|
1853 | + return new Value($this, $fixedName); |
|
1854 | 1854 | } elseif (isset($this->_params[$name])) { |
1855 | - return new Value($this, $name); |
|
1855 | + return new Value($this, $name); |
|
1856 | 1856 | } |
1857 | 1857 | return call_user_func_array([$this, 'loadRelation'], array_merge([$name], $params)); |
1858 | - } |
|
1859 | - |
|
1860 | - /** |
|
1861 | - * Param and relation getter |
|
1862 | - * |
|
1863 | - * @param string $name |
|
1864 | - * @return mixed |
|
1865 | - */ |
|
1866 | - public function __get($name) { |
|
1858 | + } |
|
1859 | + |
|
1860 | + /** |
|
1861 | + * Param and relation getter |
|
1862 | + * |
|
1863 | + * @param string $name |
|
1864 | + * @return mixed |
|
1865 | + */ |
|
1866 | + public function __get($name) { |
|
1867 | 1867 | $fixedName = $name; |
1868 | 1868 | static::fixPrefix($fixedName); |
1869 | 1869 | if (isset($this->_params[$fixedName])) { |
1870 | - return $this->_params[$fixedName]; |
|
1870 | + return $this->_params[$fixedName]; |
|
1871 | 1871 | } |
1872 | 1872 | if (isset($this->loadedRelations[$name][json_encode([])])) { |
1873 | - return $this->loadedRelations[$name][json_encode([])]; |
|
1873 | + return $this->loadedRelations[$name][json_encode([])]; |
|
1874 | 1874 | } |
1875 | 1875 | return $this->loadRelation($name); |
1876 | - } |
|
1877 | - |
|
1878 | - /** |
|
1879 | - * Return model value in object |
|
1880 | - * |
|
1881 | - * @param string $name |
|
1882 | - * @return \Value|null |
|
1883 | - */ |
|
1884 | - public function value($name) { |
|
1876 | + } |
|
1877 | + |
|
1878 | + /** |
|
1879 | + * Return model value in object |
|
1880 | + * |
|
1881 | + * @param string $name |
|
1882 | + * @return \Value|null |
|
1883 | + */ |
|
1884 | + public function value($name) { |
|
1885 | 1885 | $fixedName = $name; |
1886 | 1886 | static::fixPrefix($fixedName); |
1887 | 1887 | if (isset($this->_params[$fixedName])) { |
1888 | - return new Value($this, $fixedName); |
|
1888 | + return new Value($this, $fixedName); |
|
1889 | 1889 | } elseif ($this->_params[$name]) { |
1890 | - return new Value($this, $name); |
|
1890 | + return new Value($this, $name); |
|
1891 | 1891 | } |
1892 | 1892 | return null; |
1893 | - } |
|
1894 | - |
|
1895 | - /** |
|
1896 | - * Return manager filters |
|
1897 | - * |
|
1898 | - * @return array |
|
1899 | - */ |
|
1900 | - public static function managerFilters() { |
|
1893 | + } |
|
1894 | + |
|
1895 | + /** |
|
1896 | + * Return manager filters |
|
1897 | + * |
|
1898 | + * @return array |
|
1899 | + */ |
|
1900 | + public static function managerFilters() { |
|
1901 | 1901 | return []; |
1902 | - } |
|
1903 | - |
|
1904 | - /** |
|
1905 | - * Return validators for cols |
|
1906 | - * |
|
1907 | - * @return array |
|
1908 | - */ |
|
1909 | - public static function validators() { |
|
1902 | + } |
|
1903 | + |
|
1904 | + /** |
|
1905 | + * Return validators for cols |
|
1906 | + * |
|
1907 | + * @return array |
|
1908 | + */ |
|
1909 | + public static function validators() { |
|
1910 | 1910 | return []; |
1911 | - } |
|
1912 | - |
|
1913 | - /** |
|
1914 | - * Return validator by name |
|
1915 | - * |
|
1916 | - * @param string $name |
|
1917 | - * @return array |
|
1918 | - */ |
|
1919 | - public static function validator($name) { |
|
1911 | + } |
|
1912 | + |
|
1913 | + /** |
|
1914 | + * Return validator by name |
|
1915 | + * |
|
1916 | + * @param string $name |
|
1917 | + * @return array |
|
1918 | + */ |
|
1919 | + public static function validator($name) { |
|
1920 | 1920 | $validators = static::validators(); |
1921 | 1921 | if (!empty($validators[$name])) { |
1922 | - return $validators[$name]; |
|
1922 | + return $validators[$name]; |
|
1923 | 1923 | } |
1924 | 1924 | return []; |
1925 | - } |
|
1925 | + } |
|
1926 | 1926 | |
1927 | - function genViewLink() { |
|
1927 | + function genViewLink() { |
|
1928 | 1928 | $className = get_class($this); |
1929 | 1929 | $link = substr($className, 0, strpos($className, '\\')); |
1930 | 1930 | $link .= '/view/'; |
1931 | 1931 | $link .= str_replace('\\', '%5C', substr($className, strpos($className, '\\') + 1)); |
1932 | 1932 | $link .= "/{$this->id}"; |
1933 | 1933 | return $link; |
1934 | - } |
|
1935 | - |
|
1936 | - /** |
|
1937 | - * Set handler for model params |
|
1938 | - * |
|
1939 | - * @param string $name |
|
1940 | - * @param mixed $value |
|
1941 | - */ |
|
1942 | - public function __set($name, $value) { |
|
1934 | + } |
|
1935 | + |
|
1936 | + /** |
|
1937 | + * Set handler for model params |
|
1938 | + * |
|
1939 | + * @param string $name |
|
1940 | + * @param mixed $value |
|
1941 | + */ |
|
1942 | + public function __set($name, $value) { |
|
1943 | 1943 | static::fixPrefix($name); |
1944 | 1944 | $className = get_called_class(); |
1945 | 1945 | $shortName = preg_replace('!' . $this->colPrefix() . '!', '', $name); |
1946 | 1946 | if (!empty($className::$cols[$shortName])) { |
1947 | - switch ($className::$cols[$shortName]['type']) { |
|
1947 | + switch ($className::$cols[$shortName]['type']) { |
|
1948 | 1948 | case 'decimal': |
1949 | 1949 | $value = (float) $value; |
1950 | - break; |
|
1950 | + break; |
|
1951 | 1951 | case 'number': |
1952 | 1952 | $value = (int) $value; |
1953 | - break; |
|
1953 | + break; |
|
1954 | 1954 | case 'bool': |
1955 | 1955 | $value = (bool) $value; |
1956 | - break; |
|
1957 | - } |
|
1956 | + break; |
|
1957 | + } |
|
1958 | 1958 | } |
1959 | 1959 | if ((isset($this->_params[$name]) && $this->_params[$name] != $value) && !isset($this->_changedParams[$name])) { |
1960 | - $this->_changedParams[$name] = $this->_params[$name]; |
|
1960 | + $this->_changedParams[$name] = $this->_params[$name]; |
|
1961 | 1961 | } |
1962 | 1962 | |
1963 | 1963 | $this->_params[$name] = $value; |
1964 | - } |
|
1965 | - |
|
1966 | - /** |
|
1967 | - * Isset handler for model params |
|
1968 | - * |
|
1969 | - * @param string $name |
|
1970 | - * @return boolean |
|
1971 | - */ |
|
1972 | - public function __isset($name) { |
|
1964 | + } |
|
1965 | + |
|
1966 | + /** |
|
1967 | + * Isset handler for model params |
|
1968 | + * |
|
1969 | + * @param string $name |
|
1970 | + * @return boolean |
|
1971 | + */ |
|
1972 | + public function __isset($name) { |
|
1973 | 1973 | static::fixPrefix($name); |
1974 | 1974 | return isset($this->_params[$name]); |
1975 | - } |
|
1976 | - |
|
1977 | - /** |
|
1978 | - * Convert object to string |
|
1979 | - * |
|
1980 | - * @return string |
|
1981 | - */ |
|
1982 | - public function __toString() { |
|
1975 | + } |
|
1976 | + |
|
1977 | + /** |
|
1978 | + * Convert object to string |
|
1979 | + * |
|
1980 | + * @return string |
|
1981 | + */ |
|
1982 | + public function __toString() { |
|
1983 | 1983 | return $this->name(); |
1984 | - } |
|
1984 | + } |
|
1985 | 1985 | |
1986 | 1986 | } |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | $relModel = $relations[$colInfo['colParams']['relation']]['model']; |
210 | 210 | $relModel = strpos($relModel, '\\') === 0 ? substr($relModel, 1) : $relModel; |
211 | 211 | if ($manageHref) { |
212 | - $value = $relValue ? "<a href='/admin/" . str_replace('\\', '/view/', $relModel) . "/" . $relValue->pk() . "'>" . $relValue->name() . "</a>" : 'Не задано'; |
|
212 | + $value = $relValue ? "<a href='/admin/".str_replace('\\', '/view/', $relModel)."/".$relValue->pk()."'>".$relValue->name()."</a>" : 'Не задано'; |
|
213 | 213 | } else { |
214 | 214 | $value = $relValue ? $relValue->name() : 'Не задано'; |
215 | 215 | } |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | case 'image': |
220 | 220 | $file = Files\File::get($item->$colName); |
221 | 221 | if ($file) { |
222 | - $value = '<img src="' . $file->path . '?resize=60x120" />'; |
|
222 | + $value = '<img src="'.$file->path.'?resize=60x120" />'; |
|
223 | 223 | } else { |
224 | 224 | $value = '<img src="/static/system/images/no-image.png?resize=60x120" />'; |
225 | 225 | } |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | case 'file': |
228 | 228 | $file = Files\File::get($item->$colName); |
229 | 229 | if ($file) { |
230 | - $value = '<a href="' . $file->path . '">' . $file->name . '.' . $file->type->ext . '</a>'; |
|
230 | + $value = '<a href="'.$file->path.'">'.$file->name.'.'.$file->type->ext.'</a>'; |
|
231 | 231 | } else { |
232 | 232 | $value = 'Файл не загружен'; |
233 | 233 | } |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | case 'map': |
244 | 244 | if ($item->$colName && json_decode($item->$colName, true)) { |
245 | 245 | $addres = json_decode($item->$colName, true); |
246 | - $name = $addres['address'] ? $addres['address'] : 'lat:' . $addres['lat'] . ': lng:' . $addres['lng']; |
|
246 | + $name = $addres['address'] ? $addres['address'] : 'lat:'.$addres['lat'].': lng:'.$addres['lng']; |
|
247 | 247 | \App::$cur->libs->loadLib('yandexMap'); |
248 | 248 | ob_start(); |
249 | 249 | $uid = Tools::randomString(); |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | <?php |
276 | 276 | $content = ob_get_contents(); |
277 | 277 | ob_end_clean(); |
278 | - $onclick = 'inji.Ui.modals.show("' . addcslashes($addres['address'], '"') . '", $("#map' . $uid . '_container script").html().replace(/^\/\*/g, "").replace(/\*\/$/g, "")+"</script>","mapmodal' . $uid . '","modal-lg");'; |
|
278 | + $onclick = 'inji.Ui.modals.show("'.addcslashes($addres['address'], '"').'", $("#map'.$uid.'_container script").html().replace(/^\/\*/g, "").replace(/\*\/$/g, "")+"</script>","mapmodal'.$uid.'","modal-lg");'; |
|
279 | 279 | $onclick .= 'return false;'; |
280 | 280 | $value = "<a href ='#' onclick='{$onclick}' >{$name}</a>"; |
281 | 281 | $value .= $content; |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | case 'map': |
316 | 316 | if ($item->$colName && json_decode($item->$colName, true)) { |
317 | 317 | $addres = json_decode($item->$colName, true); |
318 | - $name = $addres['address'] ? $addres['address'] : 'lat:' . $addres['lat'] . ': lng:' . $addres['lng']; |
|
318 | + $name = $addres['address'] ? $addres['address'] : 'lat:'.$addres['lat'].': lng:'.$addres['lng']; |
|
319 | 319 | \App::$cur->libs->loadLib('yandexMap'); |
320 | 320 | ob_start(); |
321 | 321 | $uid = Tools::randomString(); |
@@ -347,7 +347,7 @@ discard block |
||
347 | 347 | <?php |
348 | 348 | $content = ob_get_contents(); |
349 | 349 | ob_end_clean(); |
350 | - $onclick = 'inji.Ui.modals.show("' . addcslashes($addres['address'], '"') . '", $("#map' . $uid . '_container script").html().replace(/^\/\*/g, "").replace(/\*\/$/g, "")+"</script>","mapmodal' . $uid . '","modal-lg");'; |
|
350 | + $onclick = 'inji.Ui.modals.show("'.addcslashes($addres['address'], '"').'", $("#map'.$uid.'_container script").html().replace(/^\/\*/g, "").replace(/\*\/$/g, "")+"</script>","mapmodal'.$uid.'","modal-lg");'; |
|
351 | 351 | $onclick .= 'return false;'; |
352 | 352 | $value = "<a href ='#' onclick='{$onclick}' >{$name}</a>"; |
353 | 353 | $value .= $content; |
@@ -387,12 +387,12 @@ discard block |
||
387 | 387 | return; |
388 | 388 | } |
389 | 389 | if (!is_array($array)) { |
390 | - if (!isset($cols[static::colPrefix() . $array]) && isset(static::$cols[$array])) { |
|
390 | + if (!isset($cols[static::colPrefix().$array]) && isset(static::$cols[$array])) { |
|
391 | 391 | static::createCol($array); |
392 | 392 | $cols = static::cols(true); |
393 | 393 | } |
394 | - if (!isset($cols[$array]) && isset($cols[static::colPrefix() . $array])) { |
|
395 | - $array = static::colPrefix() . $array; |
|
394 | + if (!isset($cols[$array]) && isset($cols[static::colPrefix().$array])) { |
|
395 | + $array = static::colPrefix().$array; |
|
396 | 396 | } else { |
397 | 397 | static::checkForJoin($array, $rootModel); |
398 | 398 | } |
@@ -401,14 +401,14 @@ discard block |
||
401 | 401 | switch ($searchtype) { |
402 | 402 | case 'key': |
403 | 403 | foreach ($array as $key => $item) { |
404 | - if (!isset($cols[static::colPrefix() . $key]) && isset(static::$cols[$key])) { |
|
404 | + if (!isset($cols[static::colPrefix().$key]) && isset(static::$cols[$key])) { |
|
405 | 405 | static::createCol($key); |
406 | 406 | $cols = static::cols(true); |
407 | 407 | } |
408 | - if (!isset($cols[$key]) && isset($cols[static::colPrefix() . $key])) { |
|
409 | - $array[static::colPrefix() . $key] = $item; |
|
408 | + if (!isset($cols[$key]) && isset($cols[static::colPrefix().$key])) { |
|
409 | + $array[static::colPrefix().$key] = $item; |
|
410 | 410 | unset($array[$key]); |
411 | - $key = static::colPrefix() . $key; |
|
411 | + $key = static::colPrefix().$key; |
|
412 | 412 | } |
413 | 413 | if (is_array($array[$key])) { |
414 | 414 | static::fixPrefix($array[$key], 'key', $rootModel); |
@@ -419,12 +419,12 @@ discard block |
||
419 | 419 | break; |
420 | 420 | case 'first': |
421 | 421 | if (isset($array[0]) && is_string($array[0])) { |
422 | - if (!isset($cols[static::colPrefix() . $array[0]]) && isset(static::$cols[$array[0]])) { |
|
422 | + if (!isset($cols[static::colPrefix().$array[0]]) && isset(static::$cols[$array[0]])) { |
|
423 | 423 | static::createCol($array[0]); |
424 | 424 | $cols = static::cols(true); |
425 | 425 | } |
426 | - if (!isset($cols[$array[0]]) && isset($cols[static::colPrefix() . $array[0]])) { |
|
427 | - $array[0] = static::colPrefix() . $array[0]; |
|
426 | + if (!isset($cols[$array[0]]) && isset($cols[static::colPrefix().$array[0]])) { |
|
427 | + $array[0] = static::colPrefix().$array[0]; |
|
428 | 428 | } else { |
429 | 429 | static::checkForJoin($array[0], $rootModel); |
430 | 430 | } |
@@ -456,11 +456,11 @@ discard block |
||
456 | 456 | $changes_text = []; |
457 | 457 | foreach ($this->_changedParams as $fullColName => $oldValue) { |
458 | 458 | $colName = substr($fullColName, strlen($class::colPrefix())); |
459 | - if(isset($class::$cols[$colName]['logging']) && !$class::$cols[$colName]['logging']){ |
|
459 | + if (isset($class::$cols[$colName]['logging']) && !$class::$cols[$colName]['logging']) { |
|
460 | 460 | continue; |
461 | 461 | } |
462 | 462 | if (strlen($oldValue) + strlen($this->_params[$fullColName]) < 200) { |
463 | - $changes_text[] = (!empty($class::$labels[$colName]) ? $class::$labels[$colName] : $colName) . ": \"{$oldValue}\" => \"{$this->$colName}\""; |
|
463 | + $changes_text[] = (!empty($class::$labels[$colName]) ? $class::$labels[$colName] : $colName).": \"{$oldValue}\" => \"{$this->$colName}\""; |
|
464 | 464 | } else { |
465 | 465 | $changes_text[] = !empty($class::$labels[$colName]) ? $class::$labels[$colName] : $colName; |
466 | 466 | } |
@@ -512,13 +512,13 @@ discard block |
||
512 | 512 | case 'to': |
513 | 513 | $relCol = $relations[$rel]['col']; |
514 | 514 | static::fixPrefix($relCol); |
515 | - $rootModel::$relJoins[$relations[$rel]['model'] . '_' . $rel] = [$relations[$rel]['model']::table(), $relations[$rel]['model']::index() . ' = ' . $relCol]; |
|
515 | + $rootModel::$relJoins[$relations[$rel]['model'].'_'.$rel] = [$relations[$rel]['model']::table(), $relations[$rel]['model']::index().' = '.$relCol]; |
|
516 | 516 | break; |
517 | 517 | case 'one': |
518 | 518 | case 'many': |
519 | 519 | $relCol = $relations[$rel]['col']; |
520 | 520 | $relations[$rel]['model']::fixPrefix($relCol); |
521 | - $rootModel::$relJoins[$relations[$rel]['model'] . '_' . $rel] = [$relations[$rel]['model']::table(), static::index() . ' = ' . $relCol]; |
|
521 | + $rootModel::$relJoins[$relations[$rel]['model'].'_'.$rel] = [$relations[$rel]['model']::table(), static::index().' = '.$relCol]; |
|
522 | 522 | break; |
523 | 523 | } |
524 | 524 | $relations[$rel]['model']::fixPrefix($col, 'key', $rootModel); |
@@ -557,13 +557,13 @@ discard block |
||
557 | 557 | $relCol = $relations[$rel]['col']; |
558 | 558 | static::fixPrefix($relCol); |
559 | 559 | //$info['modelName'] = $relations[$rel]['model']; |
560 | - $info['joins'][$relations[$rel]['model'] . '_' . $rel] = [$relations[$rel]['model']::table(), $relations[$rel]['model']::index() . ' = ' . $relCol]; |
|
560 | + $info['joins'][$relations[$rel]['model'].'_'.$rel] = [$relations[$rel]['model']::table(), $relations[$rel]['model']::index().' = '.$relCol]; |
|
561 | 561 | break; |
562 | 562 | case 'one': |
563 | 563 | $relCol = $relations[$rel]['col']; |
564 | 564 | $relations[$rel]['model']::fixPrefix($relCol); |
565 | 565 | //$info['modelName'] = $relations[$rel]['model']; |
566 | - $info['joins'][$relations[$rel]['model'] . '_' . $rel] = [$relations[$rel]['model']::table(), static::index() . ' = ' . $relCol]; |
|
566 | + $info['joins'][$relations[$rel]['model'].'_'.$rel] = [$relations[$rel]['model']::table(), static::index().' = '.$relCol]; |
|
567 | 567 | break; |
568 | 568 | } |
569 | 569 | $info = $relations[$rel]['model']::parseColRecursion($info); |
@@ -581,8 +581,8 @@ discard block |
||
581 | 581 | } else { |
582 | 582 | $info['colParams'] = []; |
583 | 583 | } |
584 | - if (!isset($cols[$info['col']]) && isset($cols[static::colPrefix() . $info['col']])) { |
|
585 | - $info['col'] = static::colPrefix() . $info['col']; |
|
584 | + if (!isset($cols[$info['col']]) && isset($cols[static::colPrefix().$info['col']])) { |
|
585 | + $info['col'] = static::colPrefix().$info['col']; |
|
586 | 586 | } |
587 | 587 | $info['modelName'] = get_called_class(); |
588 | 588 | } |
@@ -689,7 +689,7 @@ discard block |
||
689 | 689 | if ($params === false) { |
690 | 690 | return false; |
691 | 691 | } |
692 | - return App::$cur->db->addCol(static::table(), static::colPrefix() . $colName, $params); |
|
692 | + return App::$cur->db->addCol(static::table(), static::colPrefix().$colName, $params); |
|
693 | 693 | } |
694 | 694 | |
695 | 695 | public static function createTable() { |
@@ -718,28 +718,28 @@ discard block |
||
718 | 718 | return true; |
719 | 719 | } |
720 | 720 | $cols = [ |
721 | - $colPrefix . 'id' => 'pk' |
|
721 | + $colPrefix.'id' => 'pk' |
|
722 | 722 | ]; |
723 | 723 | $className = get_called_class(); |
724 | 724 | if (!empty($className::$cols)) { |
725 | 725 | foreach ($className::$cols as $colName => $colParams) { |
726 | 726 | if ($colName == 'date_create') { |
727 | - $cols[$colPrefix . 'date_create'] = 'timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP'; |
|
727 | + $cols[$colPrefix.'date_create'] = 'timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP'; |
|
728 | 728 | continue; |
729 | 729 | } |
730 | 730 | $params = $className::genColParams($colName); |
731 | 731 | if ($params) { |
732 | - $cols[$colPrefix . $colName] = $params; |
|
732 | + $cols[$colPrefix.$colName] = $params; |
|
733 | 733 | } |
734 | 734 | } |
735 | 735 | } |
736 | - if (empty($cols[$colPrefix . 'date_create'])) { |
|
737 | - $cols[$colPrefix . 'date_create'] = 'timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP'; |
|
736 | + if (empty($cols[$colPrefix.'date_create'])) { |
|
737 | + $cols[$colPrefix.'date_create'] = 'timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP'; |
|
738 | 738 | } |
739 | 739 | $tableIndexes = []; |
740 | 740 | if ($indexes) { |
741 | 741 | foreach ($indexes as $indexName => $index) { |
742 | - $tableIndexes[] = $index['type'] . ' ' . App::$cur->db->table_prefix . $indexName . ' (' . implode(',', $index['cols']) . ')'; |
|
742 | + $tableIndexes[] = $index['type'].' '.App::$cur->db->table_prefix.$indexName.' ('.implode(',', $index['cols']).')'; |
|
743 | 743 | } |
744 | 744 | } |
745 | 745 | |
@@ -763,7 +763,7 @@ discard block |
||
763 | 763 | */ |
764 | 764 | public static function index() { |
765 | 765 | |
766 | - return static::colPrefix() . 'id'; |
|
766 | + return static::colPrefix().'id'; |
|
767 | 767 | } |
768 | 768 | |
769 | 769 | /** |
@@ -774,7 +774,7 @@ discard block |
||
774 | 774 | public static function colPrefix() { |
775 | 775 | $classPath = explode('\\', get_called_class()); |
776 | 776 | $classPath = array_slice($classPath, 1); |
777 | - return strtolower(implode('_', $classPath)) . '_'; |
|
777 | + return strtolower(implode('_', $classPath)).'_'; |
|
778 | 778 | } |
779 | 779 | |
780 | 780 | /** |
@@ -808,7 +808,7 @@ discard block |
||
808 | 808 | * @return string |
809 | 809 | */ |
810 | 810 | public function name() { |
811 | - return $this->{$this->nameCol()} ? $this->{$this->nameCol()} : '№' . $this->pk(); |
|
811 | + return $this->{$this->nameCol()} ? $this->{$this->nameCol()} : '№'.$this->pk(); |
|
812 | 812 | } |
813 | 813 | |
814 | 814 | /** |
@@ -842,12 +842,12 @@ discard block |
||
842 | 842 | case 'to': |
843 | 843 | $relCol = $relations[$rel]['col']; |
844 | 844 | static::fixPrefix($relCol); |
845 | - App::$cur->db->join($relations[$rel]['model']::table(), $relations[$rel]['model']::index() . ' = ' . $relCol); |
|
845 | + App::$cur->db->join($relations[$rel]['model']::table(), $relations[$rel]['model']::index().' = '.$relCol); |
|
846 | 846 | break; |
847 | 847 | case 'one': |
848 | 848 | $col = $relations[$rel]['col']; |
849 | 849 | $relations[$rel]['model']::fixPrefix($col); |
850 | - App::$cur->db->join($relations[$rel]['model']::table(), static::index() . ' = ' . $col); |
|
850 | + App::$cur->db->join($relations[$rel]['model']::table(), static::index().' = '.$col); |
|
851 | 851 | break; |
852 | 852 | } |
853 | 853 | } |
@@ -862,8 +862,8 @@ discard block |
||
862 | 862 | } |
863 | 863 | if ($param !== null) { |
864 | 864 | $cols = static::cols(); |
865 | - if (!isset($cols[$col]) && isset($cols[static::colPrefix() . $col])) { |
|
866 | - $col = static::colPrefix() . $col; |
|
865 | + if (!isset($cols[$col]) && isset($cols[static::colPrefix().$col])) { |
|
866 | + $col = static::colPrefix().$col; |
|
867 | 867 | } |
868 | 868 | App::$cur->db->where($col, $param); |
869 | 869 | } else { |
@@ -927,12 +927,12 @@ discard block |
||
927 | 927 | case 'to': |
928 | 928 | $relCol = $relations[$rel]['col']; |
929 | 929 | static::fixPrefix($relCol); |
930 | - $query->join($relations[$rel]['model']::table(), $relations[$rel]['model']::index() . ' = ' . $relCol); |
|
930 | + $query->join($relations[$rel]['model']::table(), $relations[$rel]['model']::index().' = '.$relCol); |
|
931 | 931 | break; |
932 | 932 | case 'one': |
933 | 933 | $col = $relations[$rel]['col']; |
934 | 934 | $relations[$rel]['model']::fixPrefix($col); |
935 | - $query->join($relations[$rel]['model']::table(), static::index() . ' = ' . $col); |
|
935 | + $query->join($relations[$rel]['model']::table(), static::index().' = '.$col); |
|
936 | 936 | break; |
937 | 937 | } |
938 | 938 | } |
@@ -1254,12 +1254,12 @@ discard block |
||
1254 | 1254 | case 'to': |
1255 | 1255 | $relCol = $relations[$rel]['col']; |
1256 | 1256 | static::fixPrefix($relCol); |
1257 | - $query->join($relations[$rel]['model']::table(), $relations[$rel]['model']::index() . ' = ' . $relCol); |
|
1257 | + $query->join($relations[$rel]['model']::table(), $relations[$rel]['model']::index().' = '.$relCol); |
|
1258 | 1258 | break; |
1259 | 1259 | case 'one': |
1260 | 1260 | $col = $relations[$rel]['col']; |
1261 | 1261 | $relations[$rel]['model']::fixPrefix($col); |
1262 | - $query->join($relations[$rel]['model']::table(), static::index() . ' = ' . $col); |
|
1262 | + $query->join($relations[$rel]['model']::table(), static::index().' = '.$col); |
|
1263 | 1263 | break; |
1264 | 1264 | } |
1265 | 1265 | } |
@@ -1276,7 +1276,7 @@ discard block |
||
1276 | 1276 | } else { |
1277 | 1277 | $cols .= '*'; |
1278 | 1278 | } |
1279 | - $cols .=') as `count`' . (!empty($options['cols']) ? ',' . $options['cols'] : ''); |
|
1279 | + $cols .= ') as `count`'.(!empty($options['cols']) ? ','.$options['cols'] : ''); |
|
1280 | 1280 | $query->cols = $cols; |
1281 | 1281 | if (!empty($options['group'])) { |
1282 | 1282 | $query->group($options['group']); |
@@ -1409,25 +1409,25 @@ discard block |
||
1409 | 1409 | $itemModel = $class::$treeCategory; |
1410 | 1410 | $oldPath = $this->tree_path; |
1411 | 1411 | $this->tree_path = $this->getCatalogTree($this); |
1412 | - $itemsTable = \App::$cur->db->table_prefix . $itemModel::table(); |
|
1413 | - $itemTreeCol = $itemModel::colPrefix() . 'tree_path'; |
|
1412 | + $itemsTable = \App::$cur->db->table_prefix.$itemModel::table(); |
|
1413 | + $itemTreeCol = $itemModel::colPrefix().'tree_path'; |
|
1414 | 1414 | |
1415 | - $categoryTreeCol = $this->colPrefix() . 'tree_path'; |
|
1416 | - $categoryTable = \App::$cur->db->table_prefix . $this->table(); |
|
1415 | + $categoryTreeCol = $this->colPrefix().'tree_path'; |
|
1416 | + $categoryTable = \App::$cur->db->table_prefix.$this->table(); |
|
1417 | 1417 | if ($oldPath) { |
1418 | 1418 | \App::$cur->db->query('UPDATE |
1419 | - ' . $categoryTable . ' |
|
1419 | + ' . $categoryTable.' |
|
1420 | 1420 | SET |
1421 | - ' . $categoryTreeCol . ' = REPLACE(' . $categoryTreeCol . ', "' . $oldPath . $this->id . '/' . '", "' . $this->tree_path . $this->id . '/' . '") |
|
1422 | - WHERE ' . $categoryTreeCol . ' LIKE "' . $oldPath . $this->id . '/' . '%"'); |
|
1421 | + ' . $categoryTreeCol.' = REPLACE('.$categoryTreeCol.', "'.$oldPath.$this->id.'/'.'", "'.$this->tree_path.$this->id.'/'.'") |
|
1422 | + WHERE ' . $categoryTreeCol.' LIKE "'.$oldPath.$this->id.'/'.'%"'); |
|
1423 | 1423 | |
1424 | 1424 | \App::$cur->db->query('UPDATE |
1425 | - ' . $itemsTable . ' |
|
1425 | + ' . $itemsTable.' |
|
1426 | 1426 | SET |
1427 | - ' . $itemTreeCol . ' = REPLACE(' . $itemTreeCol . ', "' . $oldPath . $this->id . '/' . '", "' . $this->tree_path . $this->id . '/' . '") |
|
1428 | - WHERE ' . $itemTreeCol . ' LIKE "' . $oldPath . $this->id . '/' . '%"'); |
|
1427 | + ' . $itemTreeCol.' = REPLACE('.$itemTreeCol.', "'.$oldPath.$this->id.'/'.'", "'.$this->tree_path.$this->id.'/'.'") |
|
1428 | + WHERE ' . $itemTreeCol.' LIKE "'.$oldPath.$this->id.'/'.'%"'); |
|
1429 | 1429 | } |
1430 | - $itemModel::update([$itemTreeCol => $this->tree_path . $this->id . '/'], [$itemModel::colPrefix() . $this->index(), $this->id]); |
|
1430 | + $itemModel::update([$itemTreeCol => $this->tree_path.$this->id.'/'], [$itemModel::colPrefix().$this->index(), $this->id]); |
|
1431 | 1431 | } |
1432 | 1432 | |
1433 | 1433 | /** |
@@ -1441,9 +1441,9 @@ discard block |
||
1441 | 1441 | $catalogParent = $catalogClass::get($catalog->parent_id); |
1442 | 1442 | if ($catalog && $catalogParent) { |
1443 | 1443 | if ($catalogParent->tree_path) { |
1444 | - return $catalogParent->tree_path . $catalogParent->id . '/'; |
|
1444 | + return $catalogParent->tree_path.$catalogParent->id.'/'; |
|
1445 | 1445 | } else { |
1446 | - return $this->getCatalogTree($catalogParent) . $catalogParent->id . '/'; |
|
1446 | + return $this->getCatalogTree($catalogParent).$catalogParent->id.'/'; |
|
1447 | 1447 | } |
1448 | 1448 | } |
1449 | 1449 | return '/'; |
@@ -1457,7 +1457,7 @@ discard block |
||
1457 | 1457 | $categoryModel = $class::$categoryModel; |
1458 | 1458 | $category = $categoryModel::get($this->{$categoryModel::index()}); |
1459 | 1459 | if ($category) { |
1460 | - $this->tree_path = $category->tree_path . $category->pk() . '/'; |
|
1460 | + $this->tree_path = $category->tree_path.$category->pk().'/'; |
|
1461 | 1461 | } else { |
1462 | 1462 | $this->tree_path = '/'; |
1463 | 1463 | } |
@@ -1482,7 +1482,7 @@ discard block |
||
1482 | 1482 | $this->changeCategoryTree(); |
1483 | 1483 | } |
1484 | 1484 | if (!empty($this->_changedParams) && $this->pk()) { |
1485 | - Inji::$inst->event('modelItemParamsChanged-' . get_called_class(), $this); |
|
1485 | + Inji::$inst->event('modelItemParamsChanged-'.get_called_class(), $this); |
|
1486 | 1486 | } |
1487 | 1487 | $this->beforeSave(); |
1488 | 1488 | $values = []; |
@@ -1527,7 +1527,7 @@ discard block |
||
1527 | 1527 | } |
1528 | 1528 | $this->_params = $result->fetch(); |
1529 | 1529 | if ($new) { |
1530 | - Inji::$inst->event('modelCreatedItem-' . get_called_class(), $this); |
|
1530 | + Inji::$inst->event('modelCreatedItem-'.get_called_class(), $this); |
|
1531 | 1531 | } |
1532 | 1532 | $this->afterSave(); |
1533 | 1533 | return $this->{$this->index()}; |
@@ -1665,7 +1665,7 @@ discard block |
||
1665 | 1665 | static::fixPrefix($params); |
1666 | 1666 | $className = get_called_class(); |
1667 | 1667 | foreach ($params as $paramName => $value) { |
1668 | - $shortName = preg_replace('!' . $this->colPrefix() . '!', '', $paramName); |
|
1668 | + $shortName = preg_replace('!'.$this->colPrefix().'!', '', $paramName); |
|
1669 | 1669 | if (!empty($className::$cols[$shortName])) { |
1670 | 1670 | switch ($className::$cols[$shortName]['type']) { |
1671 | 1671 | case 'decimal': |
@@ -1942,7 +1942,7 @@ discard block |
||
1942 | 1942 | public function __set($name, $value) { |
1943 | 1943 | static::fixPrefix($name); |
1944 | 1944 | $className = get_called_class(); |
1945 | - $shortName = preg_replace('!' . $this->colPrefix() . '!', '', $name); |
|
1945 | + $shortName = preg_replace('!'.$this->colPrefix().'!', '', $name); |
|
1946 | 1946 | if (!empty($className::$cols[$shortName])) { |
1947 | 1947 | switch ($className::$cols[$shortName]['type']) { |
1948 | 1948 | case 'decimal': |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | echo $label !== false ? "<label>{$label}</label>" : ''; |
4 | 4 | $uid = Tools::randomString(); |
5 | 5 | if (!empty($options['value'])) { |
6 | - $options['value'] = json_decode($options['value'], true); |
|
6 | + $options['value'] = json_decode($options['value'], true); |
|
7 | 7 | } |
8 | 8 | ?> |
9 | 9 | <div id='map<?= $uid; ?>' class="formMap" style="width: 100%; height: 400px"></div> |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | }); |
25 | 25 | <?php |
26 | 26 | if ($options['value']) { |
27 | - ?> |
|
27 | + ?> |
|
28 | 28 | myMap<?= $uid; ?>CurPin = new ymaps.Placemark(["<?= !empty($options['value']['lat']) ? $options['value']['lat'] : '56.01'; ?>", "<?= !empty($options['value']['lng']) ? $options['value']['lng'] : '92.85'; ?>"], |
29 | 29 | {iconContent: "<?= !empty($options['value']['address']) ? $options['value']['address'] : implode(',', $options['value']); ?>"}, |
30 | 30 | {preset: 'islands#greenStretchyIcon'} |
@@ -13,14 +13,14 @@ |
||
13 | 13 | |
14 | 14 | class Map extends \Ui\ActiveForm\Input { |
15 | 15 | |
16 | - public function parseRequest($request) { |
|
16 | + public function parseRequest($request) { |
|
17 | 17 | $colName = empty($this->colParams['col']) ? $this->colName : $this->colParams['col']; |
18 | 18 | if (isset($request[$this->colName])) { |
19 | - $this->activeForm->model->{$colName} = json_encode($request[$this->colName]); |
|
19 | + $this->activeForm->model->{$colName} = json_encode($request[$this->colName]); |
|
20 | 20 | } else { |
21 | - $this->activeForm->model->{$colName} = 0; |
|
22 | - $this->activeForm->model->{$colName} = ''; |
|
21 | + $this->activeForm->model->{$colName} = 0; |
|
22 | + $this->activeForm->model->{$colName} = ''; |
|
23 | + } |
|
23 | 24 | } |
24 | - } |
|
25 | 25 | |
26 | 26 | } |
@@ -13,64 +13,64 @@ discard block |
||
13 | 13 | |
14 | 14 | class Option extends \Model { |
15 | 15 | |
16 | - public static $objectName = 'Свойство'; |
|
17 | - public static $cols = [ |
|
18 | - //Основные параметры |
|
19 | - 'name' => ['type' => 'text'], |
|
20 | - 'filter_name' => ['type' => 'text'], |
|
21 | - 'image_file_id' => ['type' => 'image'], |
|
22 | - 'code' => ['type' => 'text'], |
|
23 | - 'type' => ['type' => 'text'], |
|
24 | - 'postfix' => ['type' => 'text'], |
|
25 | - 'default_val' => ['type' => 'text'], |
|
26 | - 'view' => ['type' => 'bool'], |
|
27 | - 'searchable' => ['type' => 'bool'], |
|
28 | - //Системные |
|
29 | - 'weight' => ['type' => 'number'], |
|
30 | - 'user_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'user'], |
|
31 | - 'advance' => ['type' => 'text'], |
|
32 | - 'date_create' => ['type' => 'dateTime'], |
|
33 | - //Менеджеры |
|
34 | - 'item' => ['type' => 'dataManager', 'relation' => 'items'], |
|
35 | - ]; |
|
36 | - public static $labels = [ |
|
37 | - 'name' => 'Название', |
|
38 | - 'filter_name' => 'Название в фильтре', |
|
39 | - 'image_file_id' => 'Иконка', |
|
40 | - 'code' => 'Код', |
|
41 | - 'type' => 'Тип', |
|
42 | - 'postfix' => 'Постфикс', |
|
43 | - 'default_val' => 'Значение по умолчанию', |
|
44 | - 'view' => 'Отображается', |
|
45 | - 'searchable' => 'Используется при поиске', |
|
46 | - 'weight' => 'Вес сортировки', |
|
47 | - 'advance' => 'Дополнительные параметры', |
|
48 | - 'user_id' => 'Создатель', |
|
49 | - 'date_create' => 'Дата создания', |
|
50 | - 'item' => 'Значения для списка' |
|
51 | - ]; |
|
52 | - public static $dataManagers = [ |
|
53 | - 'manager' => [ |
|
54 | - 'name' => 'Свойства товаров', |
|
55 | - 'cols' => [ |
|
56 | - 'name', 'code', 'type', 'item', 'view', 'searchable', 'user_id', 'date_create' |
|
57 | - ], |
|
58 | - 'sortMode' => true |
|
59 | - ] |
|
60 | - ]; |
|
61 | - public static $forms = [ |
|
62 | - 'manager' => [ |
|
63 | - 'map' => [ |
|
64 | - ['name', 'filter_name'], |
|
65 | - ['code', 'type', 'image_file_id'], |
|
66 | - ['default_val', 'postfix'], |
|
67 | - ['view', 'searchable'], |
|
68 | - ['item'] |
|
69 | - ] |
|
70 | - ] |
|
71 | - ]; |
|
16 | + public static $objectName = 'Свойство'; |
|
17 | + public static $cols = [ |
|
18 | + //Основные параметры |
|
19 | + 'name' => ['type' => 'text'], |
|
20 | + 'filter_name' => ['type' => 'text'], |
|
21 | + 'image_file_id' => ['type' => 'image'], |
|
22 | + 'code' => ['type' => 'text'], |
|
23 | + 'type' => ['type' => 'text'], |
|
24 | + 'postfix' => ['type' => 'text'], |
|
25 | + 'default_val' => ['type' => 'text'], |
|
26 | + 'view' => ['type' => 'bool'], |
|
27 | + 'searchable' => ['type' => 'bool'], |
|
28 | + //Системные |
|
29 | + 'weight' => ['type' => 'number'], |
|
30 | + 'user_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'user'], |
|
31 | + 'advance' => ['type' => 'text'], |
|
32 | + 'date_create' => ['type' => 'dateTime'], |
|
33 | + //Менеджеры |
|
34 | + 'item' => ['type' => 'dataManager', 'relation' => 'items'], |
|
35 | + ]; |
|
36 | + public static $labels = [ |
|
37 | + 'name' => 'Название', |
|
38 | + 'filter_name' => 'Название в фильтре', |
|
39 | + 'image_file_id' => 'Иконка', |
|
40 | + 'code' => 'Код', |
|
41 | + 'type' => 'Тип', |
|
42 | + 'postfix' => 'Постфикс', |
|
43 | + 'default_val' => 'Значение по умолчанию', |
|
44 | + 'view' => 'Отображается', |
|
45 | + 'searchable' => 'Используется при поиске', |
|
46 | + 'weight' => 'Вес сортировки', |
|
47 | + 'advance' => 'Дополнительные параметры', |
|
48 | + 'user_id' => 'Создатель', |
|
49 | + 'date_create' => 'Дата создания', |
|
50 | + 'item' => 'Значения для списка' |
|
51 | + ]; |
|
52 | + public static $dataManagers = [ |
|
53 | + 'manager' => [ |
|
54 | + 'name' => 'Свойства товаров', |
|
55 | + 'cols' => [ |
|
56 | + 'name', 'code', 'type', 'item', 'view', 'searchable', 'user_id', 'date_create' |
|
57 | + ], |
|
58 | + 'sortMode' => true |
|
59 | + ] |
|
60 | + ]; |
|
61 | + public static $forms = [ |
|
62 | + 'manager' => [ |
|
63 | + 'map' => [ |
|
64 | + ['name', 'filter_name'], |
|
65 | + ['code', 'type', 'image_file_id'], |
|
66 | + ['default_val', 'postfix'], |
|
67 | + ['view', 'searchable'], |
|
68 | + ['item'] |
|
69 | + ] |
|
70 | + ] |
|
71 | + ]; |
|
72 | 72 | |
73 | - public static function relations() { |
|
73 | + public static function relations() { |
|
74 | 74 | return [ |
75 | 75 | 'user' => [ |
76 | 76 | 'model' => 'Users\User', |
@@ -86,15 +86,15 @@ discard block |
||
86 | 86 | 'col' => 'image_file_id' |
87 | 87 | ], |
88 | 88 | ]; |
89 | - } |
|
89 | + } |
|
90 | 90 | |
91 | - public function beforeSave() { |
|
91 | + public function beforeSave() { |
|
92 | 92 | if (!isset($this->id)) { |
93 | - $this->user_id = \Users\User::$cur->id; |
|
93 | + $this->user_id = \Users\User::$cur->id; |
|
94 | 94 | } |
95 | 95 | if ($this->advance && is_array($this->advance)) { |
96 | - $this->advance = json_encode($this->advance); |
|
96 | + $this->advance = json_encode($this->advance); |
|
97 | + } |
|
97 | 98 | } |
98 | - } |
|
99 | 99 | |
100 | 100 | } |
@@ -10,42 +10,42 @@ discard block |
||
10 | 10 | */ |
11 | 11 | class ecommerceController extends Controller { |
12 | 12 | |
13 | - public function buyCardAction() { |
|
13 | + public function buyCardAction() { |
|
14 | 14 | $this->view->setTitle('Покупка карты'); |
15 | 15 | $bread = []; |
16 | 16 | $bread[] = ['text' => 'Покупка карты']; |
17 | 17 | $user = Users\User::$cur; |
18 | 18 | if (!empty($_POST) && !empty($_POST['card_id'])) { |
19 | - $error = false; |
|
20 | - $card = \Ecommerce\Card::get((int) $_POST['card_id']); |
|
21 | - if (!$card) { |
|
19 | + $error = false; |
|
20 | + $card = \Ecommerce\Card::get((int) $_POST['card_id']); |
|
21 | + if (!$card) { |
|
22 | 22 | $error = true; |
23 | 23 | Msg::add('Такой карты не существует', 'danger'); |
24 | - } |
|
24 | + } |
|
25 | 25 | |
26 | - if (!Users\User::$cur->id) { |
|
26 | + if (!Users\User::$cur->id) { |
|
27 | 27 | $user_id = $this->Users->registration($_POST, true); |
28 | 28 | if (!$user_id) { |
29 | - $error = true; |
|
30 | - $user = null; |
|
29 | + $error = true; |
|
30 | + $user = null; |
|
31 | 31 | } else { |
32 | - $user = Users\User::get($user_id); |
|
32 | + $user = Users\User::get($user_id); |
|
33 | + } |
|
33 | 34 | } |
34 | - } |
|
35 | - $userCard = \Ecommerce\Card\Item::get([['card_id', $card->id], ['user_id', $user->id]]); |
|
36 | - if ($userCard) { |
|
35 | + $userCard = \Ecommerce\Card\Item::get([['card_id', $card->id], ['user_id', $user->id]]); |
|
36 | + if ($userCard) { |
|
37 | 37 | $error = true; |
38 | 38 | Msg::add('У вас уже есть такая карта', 'danger'); |
39 | - } |
|
39 | + } |
|
40 | 40 | |
41 | - $fields = \Ecommerce\UserAdds\Field::getList(); |
|
42 | - foreach ($fields as $field) { |
|
41 | + $fields = \Ecommerce\UserAdds\Field::getList(); |
|
42 | + foreach ($fields as $field) { |
|
43 | 43 | if (empty($_POST['userAdds']['fields'][$field->id]) && $field->required) { |
44 | - $error = 1; |
|
45 | - Msg::add('Вы не указали: ' . $field->name); |
|
44 | + $error = 1; |
|
45 | + Msg::add('Вы не указали: ' . $field->name); |
|
46 | + } |
|
46 | 47 | } |
47 | - } |
|
48 | - if (!$error) { |
|
48 | + if (!$error) { |
|
49 | 49 | $cardItem = new \Ecommerce\Card\Item(); |
50 | 50 | $cardItem->card_id = $card->id; |
51 | 51 | $cardItem->user_id = $user->id; |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | $cart->date_status = date('Y-m-d H:i:s'); |
59 | 59 | $cart->complete_data = date('Y-m-d H:i:s'); |
60 | 60 | if (!empty($_SESSION['cart']['cart_id'])) { |
61 | - $cart->card_item_id = $cardItem->id; |
|
61 | + $cart->card_item_id = $cardItem->id; |
|
62 | 62 | } |
63 | 63 | $cart->save(); |
64 | 64 | |
@@ -73,69 +73,69 @@ discard block |
||
73 | 73 | $extra->info = 'card:' . $card->id . '|cardItem:' . $cardItem->id; |
74 | 74 | $extra->save(); |
75 | 75 | Tools::redirect('/ecommerce/cart/success'); |
76 | - } |
|
76 | + } |
|
77 | 77 | } |
78 | 78 | $this->view->page(['data' => compact('bread')]); |
79 | - } |
|
79 | + } |
|
80 | 80 | |
81 | - public function autoCompleteAction() { |
|
81 | + public function autoCompleteAction() { |
|
82 | 82 | $return = Cache::get('itemsAutocomplete'); |
83 | 83 | if (!$return) { |
84 | - $items = $this->ecommerce->getItems(); |
|
85 | - $return = []; |
|
86 | - foreach ($items as $item) { |
|
84 | + $items = $this->ecommerce->getItems(); |
|
85 | + $return = []; |
|
86 | + foreach ($items as $item) { |
|
87 | 87 | $return[] = ['name' => $item->name(), 'search' => $item->search_index . ' ' . $item->name]; |
88 | - } |
|
89 | - $return = json_encode($return); |
|
90 | - Cache::set('itemsAutocomplete', [], $return); |
|
88 | + } |
|
89 | + $return = json_encode($return); |
|
90 | + Cache::set('itemsAutocomplete', [], $return); |
|
91 | 91 | } |
92 | 92 | echo $return; |
93 | - } |
|
93 | + } |
|
94 | 94 | |
95 | - public function indexAction() { |
|
95 | + public function indexAction() { |
|
96 | 96 | if (empty($this->module->config['catalogPresentPage'])) { |
97 | - Tools::redirect('/ecommerce/itemList'); |
|
97 | + Tools::redirect('/ecommerce/itemList'); |
|
98 | 98 | } |
99 | 99 | //$this->view->setTitle('Каталог'); |
100 | 100 | $this->view->page(); |
101 | - } |
|
101 | + } |
|
102 | 102 | |
103 | - public function itemListAction($category_id = 0) { |
|
103 | + public function itemListAction($category_id = 0) { |
|
104 | 104 | //search |
105 | 105 | if (!empty($_GET['search'])) { |
106 | - if (!empty($_GET['inCatalog'])) { |
|
106 | + if (!empty($_GET['inCatalog'])) { |
|
107 | 107 | $category_id = (int) $_GET['inCatalog']; |
108 | - } |
|
109 | - $search = $_GET['search']; |
|
108 | + } |
|
109 | + $search = $_GET['search']; |
|
110 | 110 | } else { |
111 | - $search = ''; |
|
111 | + $search = ''; |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | //sort |
115 | 115 | if (!empty($_GET['sort'])) { |
116 | - $sort = $_GET['sort']; |
|
116 | + $sort = $_GET['sort']; |
|
117 | 117 | } elseif (!empty($this->ecommerce->config['defaultSort'])) { |
118 | - $sort = $this->ecommerce->config['defaultSort']; |
|
118 | + $sort = $this->ecommerce->config['defaultSort']; |
|
119 | 119 | } else { |
120 | - $sort = ['name' => 'asc']; |
|
120 | + $sort = ['name' => 'asc']; |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | //category |
124 | 124 | $category = null; |
125 | 125 | if ($category_id) { |
126 | - if (is_numeric($category_id)) { |
|
126 | + if (is_numeric($category_id)) { |
|
127 | 127 | $category = \Ecommerce\Category::get($category_id); |
128 | - } |
|
129 | - if (!$category) { |
|
128 | + } |
|
129 | + if (!$category) { |
|
130 | 130 | $category = \Ecommerce\Category::get($category_id, 'alias'); |
131 | - } |
|
132 | - if ($category) { |
|
131 | + } |
|
132 | + if ($category) { |
|
133 | 133 | $category_id = $category->id; |
134 | - } else { |
|
134 | + } else { |
|
135 | 135 | $category_id = 0; |
136 | - } |
|
136 | + } |
|
137 | 137 | } else { |
138 | - $category_id = 0; |
|
138 | + $category_id = 0; |
|
139 | 139 | } |
140 | 140 | $active = $category_id; |
141 | 141 | |
@@ -151,17 +151,17 @@ discard block |
||
151 | 151 | //bread |
152 | 152 | $bread = []; |
153 | 153 | if (!$category || !$category->name) { |
154 | - $bread[] = array('text' => 'Каталог'); |
|
155 | - $this->view->setTitle('Каталог'); |
|
154 | + $bread[] = array('text' => 'Каталог'); |
|
155 | + $this->view->setTitle('Каталог'); |
|
156 | 156 | } else { |
157 | - $bread[] = array('text' => 'Каталог', 'href' => '/ecommerce'); |
|
158 | - $categoryIds = array_values(array_filter(explode('/', $category->tree_path))); |
|
159 | - foreach ($categoryIds as $id) { |
|
157 | + $bread[] = array('text' => 'Каталог', 'href' => '/ecommerce'); |
|
158 | + $categoryIds = array_values(array_filter(explode('/', $category->tree_path))); |
|
159 | + foreach ($categoryIds as $id) { |
|
160 | 160 | $cat = Ecommerce\Category::get($id); |
161 | 161 | $bread[] = array('text' => $cat->name, 'href' => '/ecommerce/itemList/' . $cat->id); |
162 | - } |
|
163 | - $bread[] = array('text' => $category->name); |
|
164 | - $this->view->setTitle($category->name); |
|
162 | + } |
|
163 | + $bread[] = array('text' => $category->name); |
|
164 | + $this->view->setTitle($category->name); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | //items |
@@ -176,30 +176,30 @@ discard block |
||
176 | 176 | |
177 | 177 | //params |
178 | 178 | if (empty(App::$cur->ecommerce->config['filtersInLast'])) { |
179 | - $options = \Ecommerce\Item\Option::getList(['where' => ['item_option_searchable', 1], 'order' => ['weight', 'asc']]); |
|
179 | + $options = \Ecommerce\Item\Option::getList(['where' => ['item_option_searchable', 1], 'order' => ['weight', 'asc']]); |
|
180 | 180 | } else { |
181 | - $params = $this->ecommerce->getItemsParams([ |
|
182 | - 'parent' => $category_id, |
|
183 | - 'search' => trim($search), |
|
184 | - 'filters' => !empty($_GET['filters']) ? $_GET['filters'] : [] |
|
185 | - ]); |
|
186 | - $ids = []; |
|
187 | - foreach ($params as $param) { |
|
181 | + $params = $this->ecommerce->getItemsParams([ |
|
182 | + 'parent' => $category_id, |
|
183 | + 'search' => trim($search), |
|
184 | + 'filters' => !empty($_GET['filters']) ? $_GET['filters'] : [] |
|
185 | + ]); |
|
186 | + $ids = []; |
|
187 | + foreach ($params as $param) { |
|
188 | 188 | $ids[] = $param->item_option_id; |
189 | - } |
|
190 | - if ($ids) { |
|
189 | + } |
|
190 | + if ($ids) { |
|
191 | 191 | $options = \Ecommerce\Item\Option::getList(['where' => ['id', $ids, 'IN'], 'order' => ['weight', 'asc']]); |
192 | - } else { |
|
192 | + } else { |
|
193 | 193 | $options = []; |
194 | - } |
|
194 | + } |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | |
198 | 198 | //child categorys |
199 | 199 | if ($category) { |
200 | - $categorys = $category->catalogs; |
|
200 | + $categorys = $category->catalogs; |
|
201 | 201 | } else { |
202 | - $categorys = \Ecommerce\Category::getList(['where' => ['parent_id', 0]]); |
|
202 | + $categorys = \Ecommerce\Category::getList(['where' => ['parent_id', 0]]); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | //view content |
@@ -207,12 +207,12 @@ discard block |
||
207 | 207 | 'page' => $category ? $category->resolveTemplate() : (!empty(App::$cur->ecommerce->config['defaultCategoryTemplate']) ? App::$cur->ecommerce->config['defaultCategoryTemplate'] : 'current'), |
208 | 208 | 'content' => $category ? $category->resolveViewer() : (!empty(App::$cur->ecommerce->config['defaultCategoryView']) ? App::$cur->ecommerce->config['defaultCategoryView'] : 'itemList'), |
209 | 209 | 'data' => compact('active', 'category', 'sort', 'search', 'pages', 'items', 'categorys', 'bread', 'options')]); |
210 | - } |
|
210 | + } |
|
211 | 211 | |
212 | - public function viewAction($id = '') { |
|
212 | + public function viewAction($id = '') { |
|
213 | 213 | $item = \Ecommerce\Item::get((int) $id); |
214 | 214 | if (!$item) { |
215 | - Tools::redirect('/ecommerce/', 'Такой товар не найден'); |
|
215 | + Tools::redirect('/ecommerce/', 'Такой товар не найден'); |
|
216 | 216 | } |
217 | 217 | $active = $item->category_id; |
218 | 218 | $catalog = $item->category; |
@@ -221,10 +221,10 @@ discard block |
||
221 | 221 | |
222 | 222 | $catalogIds = array_values(array_filter(explode('/', $item->tree_path))); |
223 | 223 | foreach ($catalogIds as $id) { |
224 | - $cat = Ecommerce\Category::get($id); |
|
225 | - if ($cat) { |
|
224 | + $cat = Ecommerce\Category::get($id); |
|
225 | + if ($cat) { |
|
226 | 226 | $bread[] = ['text' => $cat->name, 'href' => '/ecommerce/itemList/' . $cat->id]; |
227 | - } |
|
227 | + } |
|
228 | 228 | } |
229 | 229 | $bread[] = ['text' => $item->name()]; |
230 | 230 | $this->view->setTitle($item->name()); |
@@ -233,17 +233,17 @@ discard block |
||
233 | 233 | 'content' => $item->view ? $item->view : 'view' |
234 | 234 | ]; |
235 | 235 | if (isset($_GET['quickview'])) { |
236 | - $options['page'] = 'blank'; |
|
236 | + $options['page'] = 'blank'; |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | $this->view->addMetaTag(['property' => 'og:title', 'content' => $item->name]); |
240 | 240 | $this->view->addMetaTag(['property' => 'og:description', 'content' => $item->description]); |
241 | 241 | if ($item->image) { |
242 | - $this->view->addMetaTag(['property' => 'og:image', 'content' => 'http://' . INJI_DOMAIN_NAME . $item->image->path]); |
|
242 | + $this->view->addMetaTag(['property' => 'og:image', 'content' => 'http://' . INJI_DOMAIN_NAME . $item->image->path]); |
|
243 | 243 | } |
244 | 244 | $this->view->addMetaTag(['property' => 'og:url', 'content' => 'http://' . INJI_DOMAIN_NAME . '/view/' . $item->id]); |
245 | 245 | |
246 | 246 | $this->view->page($options); |
247 | - } |
|
247 | + } |
|
248 | 248 | |
249 | 249 | } |
@@ -15,22 +15,22 @@ |
||
15 | 15 | |
16 | 16 | class Change extends \Model { |
17 | 17 | |
18 | - static $logging = false; |
|
19 | - static $cols = [ |
|
20 | - 'activity_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'activity'], |
|
21 | - 'col' => ['type' => 'text'], |
|
22 | - 'old' => ['type' => 'textarea'], |
|
23 | - 'new' => ['type' => 'textarea'], |
|
24 | - 'date_create' => ['type' => 'dateTime'] |
|
25 | - ]; |
|
18 | + static $logging = false; |
|
19 | + static $cols = [ |
|
20 | + 'activity_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'activity'], |
|
21 | + 'col' => ['type' => 'text'], |
|
22 | + 'old' => ['type' => 'textarea'], |
|
23 | + 'new' => ['type' => 'textarea'], |
|
24 | + 'date_create' => ['type' => 'dateTime'] |
|
25 | + ]; |
|
26 | 26 | |
27 | - static function relations() { |
|
27 | + static function relations() { |
|
28 | 28 | return [ |
29 | 29 | 'activity' => [ |
30 | 30 | 'col' => 'activity_id', |
31 | 31 | 'model' => 'Dashboard\Activity' |
32 | 32 | ] |
33 | 33 | ]; |
34 | - } |
|
34 | + } |
|
35 | 35 | |
36 | 36 | } |
@@ -20,24 +20,24 @@ discard block |
||
20 | 20 | */ |
21 | 21 | class Activity extends \Model { |
22 | 22 | |
23 | - static $logging = false; |
|
24 | - static $cols = [ |
|
25 | - 'type' => ['type' => 'select', 'source' => 'array', |
|
26 | - 'sourceArray' => [ |
|
27 | - 'changes' => 'Изменение', |
|
28 | - 'new' => 'Создание', |
|
29 | - 'delete' => 'Удаление' |
|
30 | - ] |
|
31 | - ], |
|
32 | - 'item_id' => ['type' => 'number'], |
|
33 | - 'module' => ['type' => 'text'], |
|
34 | - 'model' => ['type' => 'text'], |
|
35 | - 'user_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'user'], |
|
36 | - 'changes_text' => ['type' => 'text'], |
|
37 | - 'date_create' => ['type' => 'dateTime'] |
|
38 | - ]; |
|
23 | + static $logging = false; |
|
24 | + static $cols = [ |
|
25 | + 'type' => ['type' => 'select', 'source' => 'array', |
|
26 | + 'sourceArray' => [ |
|
27 | + 'changes' => 'Изменение', |
|
28 | + 'new' => 'Создание', |
|
29 | + 'delete' => 'Удаление' |
|
30 | + ] |
|
31 | + ], |
|
32 | + 'item_id' => ['type' => 'number'], |
|
33 | + 'module' => ['type' => 'text'], |
|
34 | + 'model' => ['type' => 'text'], |
|
35 | + 'user_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'user'], |
|
36 | + 'changes_text' => ['type' => 'text'], |
|
37 | + 'date_create' => ['type' => 'dateTime'] |
|
38 | + ]; |
|
39 | 39 | |
40 | - static function relations() { |
|
40 | + static function relations() { |
|
41 | 41 | return [ |
42 | 42 | 'user' => [ |
43 | 43 | 'col' => 'user_id', |
@@ -49,6 +49,6 @@ discard block |
||
49 | 49 | 'model' => 'Dashboard\Activity\Change' |
50 | 50 | ] |
51 | 51 | ]; |
52 | - } |
|
52 | + } |
|
53 | 53 | |
54 | 54 | } |