Completed
Push — master ( 6e0e1d...0afdc4 )
by Alexey
04:12
created
system/modules/Ui/objects/ActiveForm.php 2 patches
Indentation   +154 added lines, -154 removed lines patch added patch discarded remove patch
@@ -13,118 +13,118 @@  discard block
 block discarded – undo
13 13
 
14 14
 class ActiveForm extends \Object {
15 15
 
16
-  public $model = null;
17
-  public $modelName = '';
18
-  public $header = "";
19
-  public $action = "";
20
-  public $form = [];
21
-  public $inputs = [];
22
-  public $formName = 'noNameForm';
23
-  public $requestFormName = '';
24
-  public $requestFullFormName = '';
25
-  public $parent = null;
16
+    public $model = null;
17
+    public $modelName = '';
18
+    public $header = "";
19
+    public $action = "";
20
+    public $form = [];
21
+    public $inputs = [];
22
+    public $formName = 'noNameForm';
23
+    public $requestFormName = '';
24
+    public $requestFullFormName = '';
25
+    public $parent = null;
26 26
 
27
-  /**
28
-   * 
29
-   * @param array|\Model $model
30
-   * @param array|string $form
31
-   */
32
-  public function __construct($model, $form = '') {
27
+    /**
28
+     * 
29
+     * @param array|\Model $model
30
+     * @param array|string $form
31
+     */
32
+    public function __construct($model, $form = '') {
33 33
     if (is_array($model)) {
34
-      $this->form = $model;
35
-      if (is_string($form)) {
34
+        $this->form = $model;
35
+        if (is_string($form)) {
36 36
         $this->formName = $form;
37
-      }
37
+        }
38 38
     } else {
39
-      $this->model = $model;
40
-      $this->modelName = get_class($model);
41
-      if (is_array($form)) {
39
+        $this->model = $model;
40
+        $this->modelName = get_class($model);
41
+        if (is_array($form)) {
42 42
         if (empty($form)) {
43
-          throw new \Exception('empty form');
43
+            throw new \Exception('empty form');
44 44
         }
45 45
         $this->form = $form;
46
-      } else {
46
+        } else {
47 47
         $this->formName = $form;
48 48
         $this->form = \App::$cur->ui->getModelForm($this->modelName, $form);
49 49
         if (empty($this->form)) {
50
-          throw new \Exception('empty form ' . $form);
50
+            throw new \Exception('empty form ' . $form);
51 51
         }
52 52
         $this->inputs = $this->getInputs();
53
-      }
53
+        }
54 54
     }
55 55
     $this->requestFormName = "ActiveForm_{$this->formName}";
56 56
     $modeName = $this->modelName;
57 57
 
58 58
     if (!empty($this->form['name'])) {
59
-      $this->header = $this->form['name'];
59
+        $this->header = $this->form['name'];
60 60
     } elseif (!empty($modeName::$objectName)) {
61
-      $this->header = $modeName::$objectName;
61
+        $this->header = $modeName::$objectName;
62 62
     } else {
63
-      $this->header = $this->modelName;
63
+        $this->header = $this->modelName;
64
+    }
64 65
     }
65
-  }
66 66
 
67
-  public function getInputs() {
67
+    public function getInputs() {
68 68
     $inputs = !empty($this->form['inputs']) ? $this->form['inputs'] : [];
69 69
     $modelName = $this->modelName;
70 70
     foreach ($this->form['map'] as $row) {
71
-      foreach ($row as $col) {
71
+        foreach ($row as $col) {
72 72
         if (!$col || !empty($inputs[$col])) {
73
-          continue;
73
+            continue;
74 74
         }
75 75
         if (strpos($col, 'form:') === 0) {
76
-          $colPath = explode(':', $col);
77
-          if ($this->model->{$colPath[1]}) {
76
+            $colPath = explode(':', $col);
77
+            if ($this->model->{$colPath[1]}) {
78 78
             $inputs[$col] = new ActiveForm($this->model->{$colPath[1]}, $colPath[2]);
79
-          } else {
79
+            } else {
80 80
             $relOptions = $modelName::getRelation($colPath[1]);
81 81
             if (!isset($this->model->_params[$modelName::index()])) {
82
-              $this->model->_params[$modelName::index()] = 0;
82
+                $this->model->_params[$modelName::index()] = 0;
83 83
             }
84 84
             $relOptions['model']::fixPrefix($relOptions['col']);
85 85
             $inputs[$col] = new ActiveForm(new $relOptions['model']([ $relOptions['col'] => &$this->model->_params[$modelName::index()]]), $colPath[2]);
86
-          }
87
-          $inputs[$col]->parent = $this;
86
+            }
87
+            $inputs[$col]->parent = $this;
88 88
         } elseif (!empty($modelName::$cols[$col])) {
89
-          $inputs[$col] = $modelName::$cols[$col];
89
+            $inputs[$col] = $modelName::$cols[$col];
90
+        }
90 91
         }
91
-      }
92 92
     }
93 93
     return $inputs;
94
-  }
94
+    }
95 95
 
96
-  public function checkRequest($params = [], $ajax = false) {
96
+    public function checkRequest($params = [], $ajax = false) {
97 97
     if (!$this->checkAccess()) {
98
-      $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->formName . '"');
99
-      return [];
98
+        $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->formName . '"');
99
+        return [];
100 100
     }
101 101
     $successId = 0;
102 102
     if (!empty($_POST[$this->requestFormName][$this->modelName])) {
103
-      $request = $_POST[$this->requestFormName][$this->modelName];
104
-      if ($this->model) {
103
+        $request = $_POST[$this->requestFormName][$this->modelName];
104
+        if ($this->model) {
105 105
         if ($this->form['handler']) {
106
-          $modelName = $this->model;
107
-          $modelName::{$this->form['handler']}($request);
108
-          $text = 'Новый элемент был успешно добавлен';
109
-          \Msg::add($text, 'success');
110
-          \Msg::show();
106
+            $modelName = $this->model;
107
+            $modelName::{$this->form['handler']}($request);
108
+            $text = 'Новый элемент был успешно добавлен';
109
+            \Msg::add($text, 'success');
110
+            \Msg::show();
111 111
         } else {
112
-          $presets = !empty($this->form['preset']) ? $this->form['preset'] : [];
113
-          if (!empty($this->form['userGroupPreset'][\Users\User::$cur->group_id])) {
112
+            $presets = !empty($this->form['preset']) ? $this->form['preset'] : [];
113
+            if (!empty($this->form['userGroupPreset'][\Users\User::$cur->group_id])) {
114 114
             $presets = array_merge($presets, $this->form['userGroupPreset'][\Users\User::$cur->group_id]);
115
-          }
116
-          $afterSave = [];
117
-          $error = false;
118
-          foreach ($this->inputs as $col => $param) {
115
+            }
116
+            $afterSave = [];
117
+            $error = false;
118
+            foreach ($this->inputs as $col => $param) {
119 119
             if (!empty($presets[$col])) {
120
-              continue;
120
+                continue;
121 121
             }
122 122
             if (is_object($param)) {
123
-              $afterSave[] = $param;
124
-              continue;
123
+                $afterSave[] = $param;
124
+                continue;
125 125
             }
126 126
             if (!empty($this->form['userGroupReadonly'][\Users\User::$cur->group_id]) && in_array($col, $this->form['userGroupReadonly'][\Users\User::$cur->group_id])) {
127
-              continue;
127
+                continue;
128 128
             }
129 129
             $inputClassName = '\Ui\ActiveForm\Input\\' . ucfirst($param['type']);
130 130
             $input = new $inputClassName();
@@ -134,186 +134,186 @@  discard block
 block discarded – undo
134 134
             $input->colName = $col;
135 135
             $input->colParams = $param;
136 136
             try {
137
-              $input->validate($request);
138
-              $input->parseRequest($request);
137
+                $input->validate($request);
138
+                $input->parseRequest($request);
139 139
             } catch (\Exception $exc) {
140
-              \Msg::add($exc->getMessage(), 'danger');
141
-              $error = true;
140
+                \Msg::add($exc->getMessage(), 'danger');
141
+                $error = true;
142
+            }
142 143
             }
143
-          }
144
-          if (!$error && empty($_GET['notSave'])) {
144
+            if (!$error && empty($_GET['notSave'])) {
145 145
             foreach ($presets as $col => $preset) {
146
-              if (!empty($preset['value'])) {
146
+                if (!empty($preset['value'])) {
147 147
                 $this->model->$col = $preset['value'];
148
-              } elseif (!empty($preset['userCol'])) {
148
+                } elseif (!empty($preset['userCol'])) {
149 149
                 if (strpos($preset['userCol'], ':')) {
150
-                  $rel = substr($preset['userCol'], 0, strpos($preset['userCol'], ':'));
151
-                  $param = substr($preset['userCol'], strpos($preset['userCol'], ':') + 1);
152
-                  $this->model->$col = \Users\User::$cur->$rel->$param;
150
+                    $rel = substr($preset['userCol'], 0, strpos($preset['userCol'], ':'));
151
+                    $param = substr($preset['userCol'], strpos($preset['userCol'], ':') + 1);
152
+                    $this->model->$col = \Users\User::$cur->$rel->$param;
153 153
                 } else {
154
-                  $this->model->$col = \Users\User::$cur->{$preset['userCol']};
154
+                    $this->model->$col = \Users\User::$cur->{$preset['userCol']};
155
+                }
155 156
                 }
156
-              }
157 157
             }
158 158
             if (!$this->parent) {
159
-              if (!empty($this->form['successText'])) {
159
+                if (!empty($this->form['successText'])) {
160 160
                 $text = $this->form['successText'];
161
-              } else {
161
+                } else {
162 162
                 $text = $this->model->pk() ? 'Изменения были успешно сохранены' : 'Новый элемент был успешно добавлен';
163
-              }
164
-              \Msg::add($text, 'success');
163
+                }
164
+                \Msg::add($text, 'success');
165 165
             }
166 166
 
167 167
             $this->model->save(!empty($params['dataManagerParams']) ? $params['dataManagerParams'] : []);
168 168
             foreach ($afterSave as $form) {
169
-              $form->checkRequest();
169
+                $form->checkRequest();
170 170
             }
171 171
             if ($ajax) {
172
-              \Msg::show();
172
+                \Msg::show();
173 173
             } elseif (!empty($_GET['redirectUrl'])) {
174
-              \Tools::redirect($_GET['redirectUrl'] . (!empty($_GET['dataManagerHash']) ? '#' . $_GET['dataManagerHash'] : ''));
174
+                \Tools::redirect($_GET['redirectUrl'] . (!empty($_GET['dataManagerHash']) ? '#' . $_GET['dataManagerHash'] : ''));
175 175
             }
176 176
             $successId = $this->model->pk();
177
-          }
177
+            }
178
+        }
178 179
         }
179
-      }
180
-      if (!is_array($params) && is_callable($params)) {
180
+        if (!is_array($params) && is_callable($params)) {
181 181
         $params($request);
182
-      }
182
+        }
183 183
     }
184 184
     return $successId;
185
-  }
185
+    }
186 186
 
187
-  public function draw($params = [], $ajax = false) {
187
+    public function draw($params = [], $ajax = false) {
188 188
     if (!$this->checkAccess()) {
189
-      $this->drawError('you not have access to "' . $this->modelName . '" form with name: "' . $this->formName . '"');
190
-      return [];
189
+        $this->drawError('you not have access to "' . $this->modelName . '" form with name: "' . $this->formName . '"');
190
+        return [];
191 191
     }
192 192
     $form = new Form(!empty($this->form['formOptions']) ? $this->form['formOptions'] : []);
193 193
     \App::$cur->view->widget('Ui\ActiveForm', ['form' => $form, 'activeForm' => $this, 'ajax' => $ajax, 'params' => $params]);
194
-  }
194
+    }
195 195
 
196
-  public function drawCol($colName, $options, $form, $params = []) {
196
+    public function drawCol($colName, $options, $form, $params = []) {
197 197
     if (is_object($options)) {
198
-      $options->draw();
198
+        $options->draw();
199 199
     } else {
200
-      $inputClassName = '\Ui\ActiveForm\Input\\' . ucfirst($options['type']);
201
-      $input = new $inputClassName();
202
-      $input->form = $form;
203
-      $input->activeForm = $this;
204
-      $input->activeFormParams = $params;
205
-      $input->modelName = $this->modelName;
206
-      $input->colName = $colName;
207
-      $input->colParams = $options;
208
-      $input->options = !empty($options['options']) ? $options['options'] : [];
209
-      $input->draw();
200
+        $inputClassName = '\Ui\ActiveForm\Input\\' . ucfirst($options['type']);
201
+        $input = new $inputClassName();
202
+        $input->form = $form;
203
+        $input->activeForm = $this;
204
+        $input->activeFormParams = $params;
205
+        $input->modelName = $this->modelName;
206
+        $input->colName = $colName;
207
+        $input->colParams = $options;
208
+        $input->options = !empty($options['options']) ? $options['options'] : [];
209
+        $input->draw();
210 210
     }
211 211
     return true;
212
-  }
212
+    }
213 213
 
214
-  public static function getOptionsList($inputParams, $params = [], $modelName = '', $aditionalInputNamePrefix = 'aditional', $options = []) {
214
+    public static function getOptionsList($inputParams, $params = [], $modelName = '', $aditionalInputNamePrefix = 'aditional', $options = []) {
215 215
     $values = [];
216 216
     switch ($inputParams['source']) {
217
-      case 'model':
217
+        case 'model':
218 218
         $values = $inputParams['model']::getList(['forSelect' => true]);
219 219
         break;
220
-      case 'array':
220
+        case 'array':
221 221
         $values = $inputParams['sourceArray'];
222 222
         break;
223
-      case 'method':
223
+        case 'method':
224 224
         if (!empty($inputParams['params'])) {
225
-          $values = call_user_func_array([\App::$cur->$inputParams['module'], $inputParams['method']], $inputParams['params']);
225
+            $values = call_user_func_array([\App::$cur->$inputParams['module'], $inputParams['method']], $inputParams['params']);
226 226
         } else {
227
-          $values = \App::$cur->$inputParams['module']->$inputParams['method']();
227
+            $values = \App::$cur->$inputParams['module']->$inputParams['method']();
228 228
         }
229 229
         break;
230
-      case 'relation':
230
+        case 'relation':
231 231
         if (!$modelName) {
232
-          return [];
232
+            return [];
233 233
         }
234 234
         $relation = $modelName::getRelation($inputParams['relation']);
235 235
         if (!empty($params['dataManagerParams']['appType'])) {
236
-          $options['appType'] = $params['dataManagerParams']['appType'];
236
+            $options['appType'] = $params['dataManagerParams']['appType'];
237 237
         }
238 238
         $items = [];
239 239
         if (class_exists($relation['model'])) {
240
-          $filters = $relation['model']::managerFilters();
241
-          if (!empty($filters['getRows']['where'])) {
240
+            $filters = $relation['model']::managerFilters();
241
+            if (!empty($filters['getRows']['where'])) {
242 242
             $options['where'][] = $filters['getRows']['where'];
243
-          }
244
-          if (!empty($relation['order'])) {
243
+            }
244
+            if (!empty($relation['order'])) {
245 245
             $options['order'] = $relation['order'];
246
-          }
247
-          if (!empty($inputParams['itemName'])) {
246
+            }
247
+            if (!empty($inputParams['itemName'])) {
248 248
             $options['itemName'] = $inputParams['itemName'];
249
-          }
250
-          $items = $relation['model']::getList($options);
249
+            }
250
+            $items = $relation['model']::getList($options);
251 251
         }
252 252
         if (!empty($params['noEmptyValue'])) {
253
-          $values = [];
253
+            $values = [];
254 254
         } else {
255
-          $values = [0 => 'Не задано'];
255
+            $values = [0 => 'Не задано'];
256 256
         }
257 257
         foreach ($items as $key => $item) {
258
-          if (!empty($inputParams['showCol'])) {
258
+            if (!empty($inputParams['showCol'])) {
259 259
             if (is_array($inputParams['showCol'])) {
260
-              switch ($inputParams['showCol']['type']) {
260
+                switch ($inputParams['showCol']['type']) {
261 261
                 case 'staticMethod':
262 262
                   $values[$key] = $inputParams['showCol']['class']::{$inputParams['showCol']['method']}($item);
263
-                  break;
264
-              }
263
+                    break;
264
+                }
265 265
             } else {
266
-              $values[$key] = $item->$inputParams['showCol'];
266
+                $values[$key] = $item->$inputParams['showCol'];
267 267
             }
268
-          } else {
268
+            } else {
269 269
             $values[$key] = $item->name();
270
-          }
270
+            }
271 271
         }
272 272
         break;
273 273
     }
274 274
     foreach ($values as $key => $value) {
275
-      if (is_array($value) && !empty($value['input']) && empty($value['input']['noprefix'])) {
275
+        if (is_array($value) && !empty($value['input']) && empty($value['input']['noprefix'])) {
276 276
         $values[$key]['input']['name'] = $aditionalInputNamePrefix . "[{$value['input']['name']}]";
277
-      }
277
+        }
278 278
     }
279 279
     return $values;
280
-  }
280
+    }
281 281
 
282
-  /**
283
-   * Draw error message
284
-   * 
285
-   * @param string $errorText
286
-   */
287
-  public function drawError($errorText) {
282
+    /**
283
+     * Draw error message
284
+     * 
285
+     * @param string $errorText
286
+     */
287
+    public function drawError($errorText) {
288 288
     echo $errorText;
289
-  }
289
+    }
290 290
 
291
-  /**
292
-   * Check access cur user to form with name in param and $model
293
-   * 
294
-   * @return boolean
295
-   */
296
-  public function checkAccess() {
291
+    /**
292
+     * Check access cur user to form with name in param and $model
293
+     * 
294
+     * @return boolean
295
+     */
296
+    public function checkAccess() {
297 297
     if (empty($this->form)) {
298
-      $this->drawError('"' . $this->modelName . '" form with name: "' . $this->formName . '" not found');
299
-      return false;
298
+        $this->drawError('"' . $this->modelName . '" form with name: "' . $this->formName . '" not found');
299
+        return false;
300 300
     }
301 301
     if (\App::$cur->Access && !\App::$cur->Access->checkAccess($this)) {
302
-      return false;
302
+        return false;
303 303
     }
304 304
     if (!empty($this->form['options']['access']['apps']) && !in_array(\App::$cur->name, $this->form['options']['access']['apps'])) {
305
-      return false;
305
+        return false;
306 306
     }
307 307
     if (!empty($this->form['options']['access']['groups']) && in_array(\Users\User::$cur->group_id, $this->form['options']['access']['groups'])) {
308
-      return true;
308
+        return true;
309 309
     }
310 310
     if ($this->model && !empty($this->form['options']['access']['self']) && \Users\User::$cur->id == $this->model->user_id) {
311
-      return true;
311
+        return true;
312 312
     }
313 313
     if ($this->formName == 'manager' && !\Users\User::$cur->isAdmin()) {
314
-      return false;
314
+        return false;
315 315
     }
316 316
     return true;
317
-  }
317
+    }
318 318
 
319 319
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
         $this->formName = $form;
48 48
         $this->form = \App::$cur->ui->getModelForm($this->modelName, $form);
49 49
         if (empty($this->form)) {
50
-          throw new \Exception('empty form ' . $form);
50
+          throw new \Exception('empty form '.$form);
51 51
         }
52 52
         $this->inputs = $this->getInputs();
53 53
       }
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
               $this->model->_params[$modelName::index()] = 0;
83 83
             }
84 84
             $relOptions['model']::fixPrefix($relOptions['col']);
85
-            $inputs[$col] = new ActiveForm(new $relOptions['model']([ $relOptions['col'] => &$this->model->_params[$modelName::index()]]), $colPath[2]);
85
+            $inputs[$col] = new ActiveForm(new $relOptions['model']([$relOptions['col'] => &$this->model->_params[$modelName::index()]]), $colPath[2]);
86 86
           }
87 87
           $inputs[$col]->parent = $this;
88 88
         } elseif (!empty($modelName::$cols[$col])) {
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
 
96 96
   public function checkRequest($params = [], $ajax = false) {
97 97
     if (!$this->checkAccess()) {
98
-      $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->formName . '"');
98
+      $this->drawError('you not have access to "'.$this->modelName.'" manager with name: "'.$this->formName.'"');
99 99
       return [];
100 100
     }
101 101
     $successId = 0;
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
             if (!empty($this->form['userGroupReadonly'][\Users\User::$cur->group_id]) && in_array($col, $this->form['userGroupReadonly'][\Users\User::$cur->group_id])) {
127 127
               continue;
128 128
             }
129
-            $inputClassName = '\Ui\ActiveForm\Input\\' . ucfirst($param['type']);
129
+            $inputClassName = '\Ui\ActiveForm\Input\\'.ucfirst($param['type']);
130 130
             $input = new $inputClassName();
131 131
             $input->activeForm = $this;
132 132
             $input->activeFormParams = $params;
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
             if ($ajax) {
172 172
               \Msg::show();
173 173
             } elseif (!empty($_GET['redirectUrl'])) {
174
-              \Tools::redirect($_GET['redirectUrl'] . (!empty($_GET['dataManagerHash']) ? '#' . $_GET['dataManagerHash'] : ''));
174
+              \Tools::redirect($_GET['redirectUrl'].(!empty($_GET['dataManagerHash']) ? '#'.$_GET['dataManagerHash'] : ''));
175 175
             }
176 176
             $successId = $this->model->pk();
177 177
           }
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
 
187 187
   public function draw($params = [], $ajax = false) {
188 188
     if (!$this->checkAccess()) {
189
-      $this->drawError('you not have access to "' . $this->modelName . '" form with name: "' . $this->formName . '"');
189
+      $this->drawError('you not have access to "'.$this->modelName.'" form with name: "'.$this->formName.'"');
190 190
       return [];
191 191
     }
192 192
     $form = new Form(!empty($this->form['formOptions']) ? $this->form['formOptions'] : []);
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
     if (is_object($options)) {
198 198
       $options->draw();
199 199
     } else {
200
-      $inputClassName = '\Ui\ActiveForm\Input\\' . ucfirst($options['type']);
200
+      $inputClassName = '\Ui\ActiveForm\Input\\'.ucfirst($options['type']);
201 201
       $input = new $inputClassName();
202 202
       $input->form = $form;
203 203
       $input->activeForm = $this;
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
     }
274 274
     foreach ($values as $key => $value) {
275 275
       if (is_array($value) && !empty($value['input']) && empty($value['input']['noprefix'])) {
276
-        $values[$key]['input']['name'] = $aditionalInputNamePrefix . "[{$value['input']['name']}]";
276
+        $values[$key]['input']['name'] = $aditionalInputNamePrefix."[{$value['input']['name']}]";
277 277
       }
278 278
     }
279 279
     return $values;
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
    */
296 296
   public function checkAccess() {
297 297
     if (empty($this->form)) {
298
-      $this->drawError('"' . $this->modelName . '" form with name: "' . $this->formName . '" not found');
298
+      $this->drawError('"'.$this->modelName.'" form with name: "'.$this->formName.'" not found');
299 299
       return false;
300 300
     }
301 301
     if (\App::$cur->Access && !\App::$cur->Access->checkAccess($this)) {
Please login to merge, or discard this patch.
system/modules/Ui/objects/ActiveForm/Input.php 2 patches
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -13,15 +13,15 @@  discard block
 block discarded – undo
13 13
 
14 14
 class Input extends \Object {
15 15
 
16
-  public $form = null;
17
-  public $activeForm = null;
18
-  public $activeFormParams = [];
19
-  public $modelName = '';
20
-  public $colName = '';
21
-  public $colParams = [];
22
-  public $options = [];
16
+    public $form = null;
17
+    public $activeForm = null;
18
+    public $activeFormParams = [];
19
+    public $modelName = '';
20
+    public $colName = '';
21
+    public $colParams = [];
22
+    public $options = [];
23 23
 
24
-  public function draw() {
24
+    public function draw() {
25 25
     $inputName = $this->colName();
26 26
     $inputLabel = $this->colLabel();
27 27
 
@@ -31,78 +31,78 @@  discard block
 block discarded – undo
31 31
 
32 32
     $preset = $this->preset();
33 33
     if ($preset !== null) {
34
-      $inputOptions['disabled'] = true;
35
-      $this->form->input('hidden', $inputName, '', $inputOptions);
36
-      return true;
34
+        $inputOptions['disabled'] = true;
35
+        $this->form->input('hidden', $inputName, '', $inputOptions);
36
+        return true;
37 37
     }
38 38
     $classPath = explode('\\', get_called_class());
39 39
     $inputType = lcfirst(array_pop($classPath));
40 40
     $this->form->input($inputType, $inputName, $inputLabel, $inputOptions);
41 41
     return true;
42
-  }
42
+    }
43 43
 
44
-  public function parseRequest($request) {
44
+    public function parseRequest($request) {
45 45
     $colName = empty($this->colParams['col']) ? $this->colName : $this->colParams['col'];
46 46
     if (isset($request[$this->colName])) {
47
-      $this->activeForm->model->{$colName} = $request[$this->colName];
47
+        $this->activeForm->model->{$colName} = $request[$this->colName];
48 48
     } else {
49
-      $this->activeForm->model->{$colName} = 0;
50
-      $this->activeForm->model->{$colName} = '';
49
+        $this->activeForm->model->{$colName} = 0;
50
+        $this->activeForm->model->{$colName} = '';
51
+    }
51 52
     }
52
-  }
53 53
 
54
-  public function value() {
54
+    public function value() {
55 55
     $value = isset($this->colParams['default']) ? $this->colParams['default'] : '';
56 56
     if ($this->activeForm) {
57
-      $colName = empty($this->colParams['col']) ? $this->colName : $this->colParams['col'];
58
-      $value = ($this->activeForm && $this->activeForm->model && isset($this->activeForm->model->{$colName})) ? $this->activeForm->model->{$colName} : $value;
57
+        $colName = empty($this->colParams['col']) ? $this->colName : $this->colParams['col'];
58
+        $value = ($this->activeForm && $this->activeForm->model && isset($this->activeForm->model->{$colName})) ? $this->activeForm->model->{$colName} : $value;
59 59
     }
60 60
     return $value;
61
-  }
61
+    }
62 62
 
63
-  public function preset() {
63
+    public function preset() {
64 64
     $preset = !empty($this->activeForm->form['preset'][$this->colName]) ? $this->activeForm->form['preset'][$this->colName] : [];
65 65
     if (!empty($this->activeForm->form['userGroupPreset'][\Users\User::$cur->group_id][$this->colName])) {
66
-      $preset = array_merge($preset, $this->activeForm->form['userGroupPreset'][\Users\User::$cur->group_id][$this->colName]);
66
+        $preset = array_merge($preset, $this->activeForm->form['userGroupPreset'][\Users\User::$cur->group_id][$this->colName]);
67 67
     }
68 68
     if ($preset) {
69
-      $value = '';
70
-      if (!empty($preset['value'])) {
69
+        $value = '';
70
+        if (!empty($preset['value'])) {
71 71
         $value = $preset['value'];
72
-      } elseif (!empty($preset['userCol'])) {
72
+        } elseif (!empty($preset['userCol'])) {
73 73
         if (strpos($preset['userCol'], ':')) {
74
-          $rel = substr($preset['userCol'], 0, strpos($preset['userCol'], ':'));
75
-          $param = substr($preset['userCol'], strpos($preset['userCol'], ':') + 1);
76
-          $value = \Users\User::$cur->$rel->$param;
74
+            $rel = substr($preset['userCol'], 0, strpos($preset['userCol'], ':'));
75
+            $param = substr($preset['userCol'], strpos($preset['userCol'], ':') + 1);
76
+            $value = \Users\User::$cur->$rel->$param;
77 77
         }
78
-      }
79
-      return $value;
78
+        }
79
+        return $value;
80 80
     }
81 81
     return null;
82
-  }
82
+    }
83 83
 
84
-  public function colName() {
84
+    public function colName() {
85 85
     return "{$this->activeForm->requestFormName}[{$this->activeForm->modelName}]".(stristr($this->colName, '[')?$this->colName:"[{$this->colName}]");
86
-  }
86
+    }
87 87
 
88
-  public function colLabel() {
88
+    public function colLabel() {
89 89
     $modelName = $this->modelName;
90 90
     return isset($this->colParams['label']) ? $this->colParams['label'] : (($this->activeForm->model && !empty($modelName::$labels[$this->colName])) ? $modelName::$labels[$this->colName] : $this->colName);
91
-  }
91
+    }
92 92
 
93
-  public function readOnly() {
93
+    public function readOnly() {
94 94
     return !empty($this->activeForm->form['userGroupReadonly'][\Users\User::$cur->group_id]) && in_array($this->colName, $this->activeForm->form['userGroupReadonly'][\Users\User::$cur->group_id]);
95
-  }
95
+    }
96 96
 
97
-  public function validate(&$request) {
97
+    public function validate(&$request) {
98 98
     if (empty($request[$this->colName]) && !empty($this->colParams['required'])) {
99
-      throw new \Exception('Вы не заполнили: ' . $this->colLabel());
99
+        throw new \Exception('Вы не заполнили: ' . $this->colLabel());
100 100
     }
101 101
     if (!empty($this->colParams['validator'])) {
102
-      $modelName = $this->modelName;
103
-      $validator = $modelName::validator($this->colParams['validator']);
104
-      $validator($this->activeForm, $request);
102
+        $modelName = $this->modelName;
103
+        $validator = $modelName::validator($this->colParams['validator']);
104
+        $validator($this->activeForm, $request);
105
+    }
105 106
     }
106
-  }
107 107
 
108 108
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
   }
84 84
 
85 85
   public function colName() {
86
-    return "{$this->activeForm->requestFormName}[{$this->activeForm->modelName}]" . (stristr($this->colName, '[') ? $this->colName : "[{$this->colName}]");
86
+    return "{$this->activeForm->requestFormName}[{$this->activeForm->modelName}]".(stristr($this->colName, '[') ? $this->colName : "[{$this->colName}]");
87 87
   }
88 88
 
89 89
   public function colLabel() {
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 
98 98
   public function validate(&$request) {
99 99
     if (empty($request[$this->colName]) && !empty($this->colParams['required'])) {
100
-      throw new \Exception('Вы не заполнили: ' . $this->colLabel());
100
+      throw new \Exception('Вы не заполнили: '.$this->colLabel());
101 101
     }
102 102
     if (!empty($this->colParams['validator'])) {
103 103
       $modelName = $this->modelName;
Please login to merge, or discard this patch.
system/modules/Ecommerce/appAdminControllers/EcommerceController.php 2 patches
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -10,28 +10,28 @@  discard block
 block discarded – undo
10 10
  */
11 11
 class EcommerceController extends adminController {
12 12
 
13
-  public function dashboardAction() {
13
+    public function dashboardAction() {
14 14
     $this->view->setTitle('Онлайн магазин');
15 15
     $forms = \Ecommerce\Item::$magicForms;
16 16
     \Ecommerce\Item::$forms['simpleItem']['handler']();
17 17
     $this->view->page();
18
-  }
18
+    }
19 19
 
20
-  public function configureAction() {
20
+    public function configureAction() {
21 21
     if (!empty($_POST['config'])) {
22
-      $config = App::$cur->ecommerce->config;
23
-      $config['view_empty_warehouse'] = empty($_POST['config']['view_empty_warehouse']) ? false : true;
24
-      $config['view_empty_image'] = empty($_POST['config']['view_empty_image']) ? false : true;
25
-      $config['sell_empty_warehouse'] = empty($_POST['config']['sell_empty_warehouse']) ? false : true;
26
-      $config['sell_over_warehouse'] = empty($_POST['config']['sell_over_warehouse']) ? false : true;
27
-      $config['notify_mail'] = $_POST['config']['notify_mail'];
28
-      $config['defaultCategoryView'] = $_POST['config']['defaultCategoryView'];
29
-      $config['defaultCurrency'] = $_POST['config']['defaultCurrency'];
30
-      $config['orderPrefix'] = $_POST['config']['orderPrefix'];
31
-      $config['show_zero_price'] = empty($_POST['config']['show_zero_price']) ? false : true;
32
-      $config['show_without_price'] = empty($_POST['config']['show_without_price']) ? false : true;
33
-      Config::save('module', $config, 'Ecommerce');
34
-      Tools::redirect('/admin/ecommerce/configure', 'Настройки были изменены', 'success');
22
+        $config = App::$cur->ecommerce->config;
23
+        $config['view_empty_warehouse'] = empty($_POST['config']['view_empty_warehouse']) ? false : true;
24
+        $config['view_empty_image'] = empty($_POST['config']['view_empty_image']) ? false : true;
25
+        $config['sell_empty_warehouse'] = empty($_POST['config']['sell_empty_warehouse']) ? false : true;
26
+        $config['sell_over_warehouse'] = empty($_POST['config']['sell_over_warehouse']) ? false : true;
27
+        $config['notify_mail'] = $_POST['config']['notify_mail'];
28
+        $config['defaultCategoryView'] = $_POST['config']['defaultCategoryView'];
29
+        $config['defaultCurrency'] = $_POST['config']['defaultCurrency'];
30
+        $config['orderPrefix'] = $_POST['config']['orderPrefix'];
31
+        $config['show_zero_price'] = empty($_POST['config']['show_zero_price']) ? false : true;
32
+        $config['show_without_price'] = empty($_POST['config']['show_without_price']) ? false : true;
33
+        Config::save('module', $config, 'Ecommerce');
34
+        Tools::redirect('/admin/ecommerce/configure', 'Настройки были изменены', 'success');
35 35
     }
36 36
     $managers = [
37 37
         'Ecommerce\Delivery',
@@ -51,51 +51,51 @@  discard block
 block discarded – undo
51 51
     ];
52 52
     $this->view->setTitle('Настройки магазина');
53 53
     $this->view->page(['data' => compact('managers')]);
54
-  }
54
+    }
55 55
 
56
-  public function reBlockIndexAction() {
56
+    public function reBlockIndexAction() {
57 57
     set_time_limit(0);
58 58
     $carts = Cart::getList();
59 59
     foreach ($carts as $cart) {
60
-      $cart->save();
60
+        $cart->save();
61 61
     }
62 62
     Tools::redirect('/admin/ecommerce/configure', 'Данные о блокировках обновлены');
63
-  }
63
+    }
64 64
 
65
-  public function reSearchIndexAction($i = 0) {
65
+    public function reSearchIndexAction($i = 0) {
66 66
     set_time_limit(0);
67 67
     $count = 100;
68 68
     $items = Ecommerce\Item::getList(['start' => $i * $count, 'limit' => $count]);
69 69
     if (!$items) {
70
-      Tools::redirect('/admin/ecommerce/configure', 'Поисковый индекс обновлен');
70
+        Tools::redirect('/admin/ecommerce/configure', 'Поисковый индекс обновлен');
71 71
     } else {
72
-      $i++;
73
-      foreach ($items as $key => $item) {
72
+        $i++;
73
+        foreach ($items as $key => $item) {
74 74
         $item->save();
75 75
         unset($items[$key]);
76 76
         unset($item);
77
-      }
78
-      echo 'Происходит процесс индексации: проиндексировано ' . $i * $count;
79
-      Tools::redirect('/admin/ecommerce/reSearchIndex/' . $i);
77
+        }
78
+        echo 'Происходит процесс индексации: проиндексировано ' . $i * $count;
79
+        Tools::redirect('/admin/ecommerce/reSearchIndex/' . $i);
80
+    }
80 81
     }
81
-  }
82 82
 
83
-  public function newOrdersSubscribeAction() {
83
+    public function newOrdersSubscribeAction() {
84 84
     $this->Notifications->subscribe('Ecommerce-orders');
85
-  }
85
+    }
86 86
 
87
-  public function closeCartAction($cartId = 0) {
87
+    public function closeCartAction($cartId = 0) {
88 88
     $cart = Ecommerce\Cart::get((int) $cartId);
89 89
     $result = new Server\Result();
90 90
     if ($cart && $cart->cart_status_id != 5) {
91
-      $cart->cart_status_id = 5;
92
-      $cart->save();
93
-      $result->successMsg = 'Заказ был завершен';
94
-      $result->send();
91
+        $cart->cart_status_id = 5;
92
+        $cart->save();
93
+        $result->successMsg = 'Заказ был завершен';
94
+        $result->send();
95 95
     }
96 96
     $result->success = false;
97 97
     $result->content = 'Такая корзина не найдена';
98 98
     $result->send();
99
-  }
99
+    }
100 100
 
101 101
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -75,8 +75,8 @@
 block discarded – undo
75 75
         unset($items[$key]);
76 76
         unset($item);
77 77
       }
78
-      echo 'Происходит процесс индексации: проиндексировано ' . $i * $count;
79
-      Tools::redirect('/admin/ecommerce/reSearchIndex/' . $i);
78
+      echo 'Происходит процесс индексации: проиндексировано '.$i * $count;
79
+      Tools::redirect('/admin/ecommerce/reSearchIndex/'.$i);
80 80
     }
81 81
   }
82 82
 
Please login to merge, or discard this patch.
system/modules/Ecommerce/models/Item.php 2 patches
Indentation   +202 added lines, -202 removed lines patch added patch discarded remove patch
@@ -13,57 +13,57 @@  discard block
 block discarded – undo
13 13
 
14 14
 class Item extends \Model {
15 15
 
16
-  public static $categoryModel = 'Ecommerce\Category';
17
-  public static $objectName = 'Товар';
18
-  public static $labels = [
19
-      'name' => 'Название',
20
-      'alias' => 'Алиас',
21
-      'category_id' => 'Раздел',
22
-      'description' => 'Описание',
23
-      'item_type_id' => 'Тип товара',
24
-      'image_file_id' => 'Изображение',
25
-      'best' => 'Лучшее предложение',
26
-      'options' => 'Параметры',
27
-      'offers' => 'Торговые предложения',
28
-      'widget' => 'Виджет для отображения в каталоге',
29
-      'view' => 'Шаблон для отображения полной информации',
30
-      'deleted' => 'Удален',
31
-      'imgs' => 'Фото'
32
-  ];
33
-  public static $cols = [
34
-      //Основные параметры
35
-      'category_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'category'],
36
-      'image_file_id' => ['type' => 'image'],
37
-      'name' => ['type' => 'text'],
38
-      'alias' => ['type' => 'text'],
39
-      'description' => ['type' => 'html'],
40
-      'item_type_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'type'],
41
-      'best' => ['type' => 'bool'],
42
-      'deleted' => ['type' => 'bool'],
43
-      //Системные
44
-      'user_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'user'],
45
-      'weight' => ['type' => 'number'],
46
-      'sales' => ['type' => 'number'],
47
-      'imported' => ['type' => 'text'],
48
-      'tree_path' => ['type' => 'text'],
49
-      'search_index' => ['type' => 'text'],
50
-      'date_create' => ['type' => 'dateTime'],
51
-      'widget' => ['type' => 'text'],
52
-      'view' => ['type' => 'text'],
53
-      //Менеджеры
54
-      'options' => ['type' => 'dataManager', 'relation' => 'options'],
55
-      'offers' => ['type' => 'dataManager', 'relation' => 'offers'],
56
-      'imgs' => ['type' => 'dataManager', 'relation' => 'images'],
57
-  ];
16
+    public static $categoryModel = 'Ecommerce\Category';
17
+    public static $objectName = 'Товар';
18
+    public static $labels = [
19
+        'name' => 'Название',
20
+        'alias' => 'Алиас',
21
+        'category_id' => 'Раздел',
22
+        'description' => 'Описание',
23
+        'item_type_id' => 'Тип товара',
24
+        'image_file_id' => 'Изображение',
25
+        'best' => 'Лучшее предложение',
26
+        'options' => 'Параметры',
27
+        'offers' => 'Торговые предложения',
28
+        'widget' => 'Виджет для отображения в каталоге',
29
+        'view' => 'Шаблон для отображения полной информации',
30
+        'deleted' => 'Удален',
31
+        'imgs' => 'Фото'
32
+    ];
33
+    public static $cols = [
34
+        //Основные параметры
35
+        'category_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'category'],
36
+        'image_file_id' => ['type' => 'image'],
37
+        'name' => ['type' => 'text'],
38
+        'alias' => ['type' => 'text'],
39
+        'description' => ['type' => 'html'],
40
+        'item_type_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'type'],
41
+        'best' => ['type' => 'bool'],
42
+        'deleted' => ['type' => 'bool'],
43
+        //Системные
44
+        'user_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'user'],
45
+        'weight' => ['type' => 'number'],
46
+        'sales' => ['type' => 'number'],
47
+        'imported' => ['type' => 'text'],
48
+        'tree_path' => ['type' => 'text'],
49
+        'search_index' => ['type' => 'text'],
50
+        'date_create' => ['type' => 'dateTime'],
51
+        'widget' => ['type' => 'text'],
52
+        'view' => ['type' => 'text'],
53
+        //Менеджеры
54
+        'options' => ['type' => 'dataManager', 'relation' => 'options'],
55
+        'offers' => ['type' => 'dataManager', 'relation' => 'offers'],
56
+        'imgs' => ['type' => 'dataManager', 'relation' => 'images'],
57
+    ];
58 58
 
59
-  public static function simpleItemHandler($request) {
59
+    public static function simpleItemHandler($request) {
60 60
     if ($request) {
61
-      $item = new Item();
62
-      $item->name = $request['name'];
63
-      $item->description = $request['description'];
64
-      $item->category_id = $request['category'];
65
-      $item->save();
66
-      if (!empty($_FILES['ActiveForm_simpleItem']['tmp_name']['Ecommerce\Item']['image'])) {
61
+        $item = new Item();
62
+        $item->name = $request['name'];
63
+        $item->description = $request['description'];
64
+        $item->category_id = $request['category'];
65
+        $item->save();
66
+        if (!empty($_FILES['ActiveForm_simpleItem']['tmp_name']['Ecommerce\Item']['image'])) {
67 67
         $file_id = \App::$primary->files->upload([
68 68
             'tmp_name' => $_FILES['ActiveForm_simpleItem']['tmp_name']['Ecommerce\Item']['image'],
69 69
             'name' => $_FILES['ActiveForm_simpleItem']['name']['Ecommerce\Item']['image'],
@@ -75,131 +75,131 @@  discard block
 block discarded – undo
75 75
             'accept_group' => 'image'
76 76
         ]);
77 77
         if ($file_id) {
78
-          $item->image_file_id = $file_id;
79
-          $item->save();
78
+            $item->image_file_id = $file_id;
79
+            $item->save();
80
+        }
80 81
         }
81
-      }
82
-      if (!empty($request['options']['option'])) {
82
+        if (!empty($request['options']['option'])) {
83 83
         foreach ($request['options']['option'] as $key => $option_id) {
84
-          $param = new Item\Param();
85
-          $param->item_id = $item->id;
86
-          $param->value = $request['options']['value'][$key];
87
-          $param->item_option_id = $option_id;
88
-          $param->save();
84
+            $param = new Item\Param();
85
+            $param->item_id = $item->id;
86
+            $param->value = $request['options']['value'][$key];
87
+            $param->item_option_id = $option_id;
88
+            $param->save();
89 89
         }
90
-      }
91
-      $offer = new Item\Offer();
92
-      $offer->item_id = $item->id;
93
-      $offer->save();
94
-      if (!empty($request['offerOptions']['option'])) {
90
+        }
91
+        $offer = new Item\Offer();
92
+        $offer->item_id = $item->id;
93
+        $offer->save();
94
+        if (!empty($request['offerOptions']['option'])) {
95 95
         foreach ($request['offerOptions']['option'] as $key => $option_id) {
96
-          $param = new Item\Offer\Param();
97
-          $param->item_offer_id = $offer->id;
98
-          $param->value = $request['offerOptions']['value'][$key];
99
-          $param->item_offer_option_id = $option_id;
100
-          $param->save();
96
+            $param = new Item\Offer\Param();
97
+            $param->item_offer_id = $offer->id;
98
+            $param->value = $request['offerOptions']['value'][$key];
99
+            $param->item_offer_option_id = $option_id;
100
+            $param->save();
101
+        }
101 102
         }
102
-      }
103
-      $price = new Item\Offer\Price();
104
-      $price->price = $request['price'];
105
-      $price->item_offer_id = $offer->id;
106
-      $price->currency_id = $request['currency'];
107
-      $price->save();
103
+        $price = new Item\Offer\Price();
104
+        $price->price = $request['price'];
105
+        $price->item_offer_id = $offer->id;
106
+        $price->currency_id = $request['currency'];
107
+        $price->save();
108
+    }
108 109
     }
109
-  }
110 110
 
111
-  public static $dataManagers = [
112
-      'manager' => [
113
-          'name' => 'Товары',
114
-          'cols' => [
115
-              'name',
116
-              'imgs',
117
-              'category_id',
118
-              'item_type_id',
119
-              'best',
120
-              'deleted',
121
-              'options',
122
-              'offers',
123
-          ],
124
-          'categorys' => [
125
-              'model' => 'Ecommerce\Category',
126
-          ],
127
-          'sortMode' => true
128
-      ]
129
-  ];
130
-  public static $forms = [
131
-      'manager' => [
132
-          'map' => [
133
-              ['name', 'alias'],
134
-              ['category_id', 'item_type_id', 'deleted'],
135
-              ['widget', 'view'],
136
-              ['best', 'image_file_id'],
137
-              ['description'],
138
-              ['imgs'],
139
-              ['options'],
140
-              ['offers'],
141
-          ]
142
-      ],
143
-      'simpleItem' => [
144
-          'options' => [
145
-              'access' => [
146
-                  'groups' => [
147
-                      3
148
-                  ]
149
-              ],
150
-          ],
151
-          'name' => 'Простой товар с ценой',
152
-          'inputs' => [
153
-              'name' => ['type' => 'text'],
154
-              'description' => ['type' => 'html'],
155
-              'category' => ['type' => 'select', 'source' => 'model', 'model' => 'Ecommerce\Category', 'label' => 'Категория'],
156
-              'image' => ['type' => 'image', 'label' => 'Изображение'],
157
-              'price' => ['type' => 'text', 'label' => 'Цена'],
158
-              'currency' => ['type' => 'select', 'source' => 'model', 'model' => 'Money\Currency', 'label' => 'Валюта'],
159
-              'options' => ['type' => 'dynamicList', 'source' => 'options', 'options' => [
160
-                      'inputs' => [
161
-                          'option' => ['type' => 'select', 'source' => 'model', 'model' => 'Ecommerce\Item\Option', 'label' => 'Свойство'],
162
-                          'value' => ['type' => 'dynamicType', 'typeSource' => 'selfMethod', 'selfMethod' => 'realType', 'label' => 'Значение'],
163
-                      ]
164
-                  ]
165
-              ],
166
-              'offerOptions' => ['type' => 'dynamicList', 'source' => 'options', 'options' => [
167
-                      'inputs' => [
168
-                          'option' => ['type' => 'select', 'source' => 'model', 'model' => 'Ecommerce\Item\Offer\Option', 'label' => 'Свойство предложения'],
169
-                          'value' => ['type' => 'dynamicType', 'typeSource' => 'selfMethod', 'selfMethod' => 'realType', 'label' => 'Значение'],
170
-                      ]
171
-                  ],'label'=>'Параметры предложения'
172
-              ]
173
-          ],
174
-          'map' => [
175
-              ['name', 'category'],
176
-              ['description'],
177
-              ['image'],
178
-              ['price', 'currency'],
179
-              ['options'],
180
-              ['offerOptions'],
181
-          ],
182
-          'handler' => 'simpleItemHandler'
183
-      ]
184
-  ];
111
+    public static $dataManagers = [
112
+        'manager' => [
113
+            'name' => 'Товары',
114
+            'cols' => [
115
+                'name',
116
+                'imgs',
117
+                'category_id',
118
+                'item_type_id',
119
+                'best',
120
+                'deleted',
121
+                'options',
122
+                'offers',
123
+            ],
124
+            'categorys' => [
125
+                'model' => 'Ecommerce\Category',
126
+            ],
127
+            'sortMode' => true
128
+        ]
129
+    ];
130
+    public static $forms = [
131
+        'manager' => [
132
+            'map' => [
133
+                ['name', 'alias'],
134
+                ['category_id', 'item_type_id', 'deleted'],
135
+                ['widget', 'view'],
136
+                ['best', 'image_file_id'],
137
+                ['description'],
138
+                ['imgs'],
139
+                ['options'],
140
+                ['offers'],
141
+            ]
142
+        ],
143
+        'simpleItem' => [
144
+            'options' => [
145
+                'access' => [
146
+                    'groups' => [
147
+                        3
148
+                    ]
149
+                ],
150
+            ],
151
+            'name' => 'Простой товар с ценой',
152
+            'inputs' => [
153
+                'name' => ['type' => 'text'],
154
+                'description' => ['type' => 'html'],
155
+                'category' => ['type' => 'select', 'source' => 'model', 'model' => 'Ecommerce\Category', 'label' => 'Категория'],
156
+                'image' => ['type' => 'image', 'label' => 'Изображение'],
157
+                'price' => ['type' => 'text', 'label' => 'Цена'],
158
+                'currency' => ['type' => 'select', 'source' => 'model', 'model' => 'Money\Currency', 'label' => 'Валюта'],
159
+                'options' => ['type' => 'dynamicList', 'source' => 'options', 'options' => [
160
+                        'inputs' => [
161
+                            'option' => ['type' => 'select', 'source' => 'model', 'model' => 'Ecommerce\Item\Option', 'label' => 'Свойство'],
162
+                            'value' => ['type' => 'dynamicType', 'typeSource' => 'selfMethod', 'selfMethod' => 'realType', 'label' => 'Значение'],
163
+                        ]
164
+                    ]
165
+                ],
166
+                'offerOptions' => ['type' => 'dynamicList', 'source' => 'options', 'options' => [
167
+                        'inputs' => [
168
+                            'option' => ['type' => 'select', 'source' => 'model', 'model' => 'Ecommerce\Item\Offer\Option', 'label' => 'Свойство предложения'],
169
+                            'value' => ['type' => 'dynamicType', 'typeSource' => 'selfMethod', 'selfMethod' => 'realType', 'label' => 'Значение'],
170
+                        ]
171
+                    ],'label'=>'Параметры предложения'
172
+                ]
173
+            ],
174
+            'map' => [
175
+                ['name', 'category'],
176
+                ['description'],
177
+                ['image'],
178
+                ['price', 'currency'],
179
+                ['options'],
180
+                ['offerOptions'],
181
+            ],
182
+            'handler' => 'simpleItemHandler'
183
+        ]
184
+    ];
185 185
 
186
-  public function realType() {
186
+    public function realType() {
187 187
     if ($this->option && $this->option->type) {
188
-      $type = $this->option->type;
188
+        $type = $this->option->type;
189 189
 
190
-      if ($type == 'select') {
190
+        if ($type == 'select') {
191 191
         return [
192 192
             'type' => 'select',
193 193
             'source' => 'relation',
194 194
             'relation' => 'option:items',
195 195
         ];
196
-      }
197
-      return $type;
196
+        }
197
+        return $type;
198 198
     }
199 199
     return 'text';
200
-  }
200
+    }
201 201
 
202
-  public static function indexes() {
202
+    public static function indexes() {
203 203
     return [
204 204
         'ecommerce_item_item_category_id' => [
205 205
             'type' => 'INDEX',
@@ -220,45 +220,45 @@  discard block
 block discarded – undo
220 220
             ]
221 221
         ],
222 222
     ];
223
-  }
223
+    }
224 224
 
225
-  public function beforeSave() {
225
+    public function beforeSave() {
226 226
 
227 227
     if ($this->id) {
228
-      $this->search_index = $this->name . ' ';
229
-      if ($this->category) {
228
+        $this->search_index = $this->name . ' ';
229
+        if ($this->category) {
230 230
         $this->search_index .= $this->category->name . ' ';
231
-      }
232
-      if ($this->options) {
231
+        }
232
+        if ($this->options) {
233 233
         foreach ($this->options as $option) {
234
-          if ($option->item_option_searchable && $option->value) {
234
+            if ($option->item_option_searchable && $option->value) {
235 235
             if ($option->item_option_type != 'select') {
236
-              $this->search_index .= $option->value . ' ';
236
+                $this->search_index .= $option->value . ' ';
237 237
             } elseif (!empty($option->option->items[$option->value])) {
238
-              $option->option->items[$option->value]->value . ' ';
238
+                $option->option->items[$option->value]->value . ' ';
239 239
             }
240
-          }
240
+            }
241
+        }
241 242
         }
242
-      }
243
-      if ($this->offers) {
243
+        if ($this->offers) {
244 244
         foreach ($this->offers as $offer) {
245
-          if ($offer->options) {
245
+            if ($offer->options) {
246 246
             foreach ($offer->options as $option) {
247
-              if ($option->item_offer_option_searchable && $option->value) {
247
+                if ($option->item_offer_option_searchable && $option->value) {
248 248
                 if ($option->item_offer_option_type != 'select') {
249
-                  $this->search_index .= $option->value . ' ';
249
+                    $this->search_index .= $option->value . ' ';
250 250
                 } elseif (!empty($option->option->items[$option->value])) {
251
-                  $option->option->items[$option->value]->value . ' ';
251
+                    $option->option->items[$option->value]->value . ' ';
252 252
                 }
253
-              }
253
+                }
254
+            }
254 255
             }
255
-          }
256 256
         }
257
-      }
257
+        }
258
+    }
258 259
     }
259
-  }
260 260
 
261
-  public static function relations() {
261
+    public static function relations() {
262 262
 
263 263
     return [
264 264
         'category' => [
@@ -296,55 +296,55 @@  discard block
 block discarded – undo
296 296
             'col' => 'user_id'
297 297
         ]
298 298
     ];
299
-  }
299
+    }
300 300
 
301
-  public function getPrice() {
301
+    public function getPrice() {
302 302
     $offers = $this->offers(['key' => false]);
303 303
     $curPrice = null;
304 304
 
305 305
     foreach ($offers[0]->prices as $price) {
306
-      if (!$price->type) {
306
+        if (!$price->type) {
307 307
         $curPrice = $price;
308
-      } elseif (
309
-              (!$price->type->roles && !$curPrice) ||
308
+        } elseif (
309
+                (!$price->type->roles && !$curPrice) ||
310 310
               ($price->type->roles && !$curPrice && strpos($price->type->roles, "|" . \Users\User::$cur->role_id . "|") !== false)
311
-      ) {
311
+        ) {
312 312
         $curPrice = $price;
313
-      }
313
+        }
314 314
     }
315 315
     return $curPrice;
316
-  }
316
+    }
317 317
 
318
-  public function name() {
318
+    public function name() {
319 319
     if (!empty(\App::$primary->ecommerce->config['item_option_as_name'])) {
320
-      $param = Item\Param::get([['item_id', $this->id], ['item_option_id', \App::$primary->ecommerce->config['item_option_as_name']]]);
321
-      if ($param && $param->value) {
320
+        $param = Item\Param::get([['item_id', $this->id], ['item_option_id', \App::$primary->ecommerce->config['item_option_as_name']]]);
321
+        if ($param && $param->value) {
322 322
         return $param->value;
323
-      }
323
+        }
324 324
     }
325 325
     return $this->name;
326
-  }
326
+    }
327 327
 
328
-  public function beforeDelete() {
328
+    public function beforeDelete() {
329 329
     if ($this->id) {
330
-      if ($this->options) {
330
+        if ($this->options) {
331 331
         foreach ($this->options as $option) {
332
-          $option->delete();
332
+            $option->delete();
333
+        }
333 334
         }
334
-      }
335
-      if ($this->offers) {
335
+        if ($this->offers) {
336 336
         foreach ($this->offers as $offer) {
337
-          $offer->delete();
337
+            $offer->delete();
338 338
         }
339
-      }
340
-      if ($this->image) {
339
+        }
340
+        if ($this->image) {
341 341
         $this->image->delete();
342
-      }
342
+        }
343
+    }
343 344
     }
344
-  }
345 345
 
346
-  public function getHref() {
346
+    public function getHref() {
347 347
     return "/ecommerce/view/{$this->pk()}";
348
-  }
348
+    }
349 349
 
350 350
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
             'size' => $_FILES['ActiveForm_simpleItem']['size']['Ecommerce\Item']['image'],
72 72
             'error' => $_FILES['ActiveForm_simpleItem']['error']['Ecommerce\Item']['image'],
73 73
                 ], [
74
-            'upload_code' => 'activeForm:' . 'Ecommerce\Item' . ':' . $item->pk(),
74
+            'upload_code' => 'activeForm:'.'Ecommerce\Item'.':'.$item->pk(),
75 75
             'accept_group' => 'image'
76 76
         ]);
77 77
         if ($file_id) {
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
                           'option' => ['type' => 'select', 'source' => 'model', 'model' => 'Ecommerce\Item\Offer\Option', 'label' => 'Свойство предложения'],
169 169
                           'value' => ['type' => 'dynamicType', 'typeSource' => 'selfMethod', 'selfMethod' => 'realType', 'label' => 'Значение'],
170 170
                       ]
171
-                  ],'label'=>'Параметры предложения'
171
+                  ], 'label'=>'Параметры предложения'
172 172
               ]
173 173
           ],
174 174
           'map' => [
@@ -225,17 +225,17 @@  discard block
 block discarded – undo
225 225
   public function beforeSave() {
226 226
 
227 227
     if ($this->id) {
228
-      $this->search_index = $this->name . ' ';
228
+      $this->search_index = $this->name.' ';
229 229
       if ($this->category) {
230
-        $this->search_index .= $this->category->name . ' ';
230
+        $this->search_index .= $this->category->name.' ';
231 231
       }
232 232
       if ($this->options) {
233 233
         foreach ($this->options as $option) {
234 234
           if ($option->item_option_searchable && $option->value) {
235 235
             if ($option->item_option_type != 'select') {
236
-              $this->search_index .= $option->value . ' ';
236
+              $this->search_index .= $option->value.' ';
237 237
             } elseif (!empty($option->option->items[$option->value])) {
238
-              $option->option->items[$option->value]->value . ' ';
238
+              $option->option->items[$option->value]->value.' ';
239 239
             }
240 240
           }
241 241
         }
@@ -246,9 +246,9 @@  discard block
 block discarded – undo
246 246
             foreach ($offer->options as $option) {
247 247
               if ($option->item_offer_option_searchable && $option->value) {
248 248
                 if ($option->item_offer_option_type != 'select') {
249
-                  $this->search_index .= $option->value . ' ';
249
+                  $this->search_index .= $option->value.' ';
250 250
                 } elseif (!empty($option->option->items[$option->value])) {
251
-                  $option->option->items[$option->value]->value . ' ';
251
+                  $option->option->items[$option->value]->value.' ';
252 252
                 }
253 253
               }
254 254
             }
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
             'col' => 'item_id',
272 272
             //'resultKey' => 'code',
273 273
             'resultKey' => 'item_option_id',
274
-            'join' => [Item\Option::table(), Item\Option::index() . ' = ' . Item\Param::colPrefix() . Item\Option::index()]
274
+            'join' => [Item\Option::table(), Item\Option::index().' = '.Item\Param::colPrefix().Item\Option::index()]
275 275
         ],
276 276
         'offers' => [
277 277
             'type' => 'many',
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
         $curPrice = $price;
308 308
       } elseif (
309 309
               (!$price->type->roles && !$curPrice) ||
310
-              ($price->type->roles && !$curPrice && strpos($price->type->roles, "|" . \Users\User::$cur->role_id . "|") !== false)
310
+              ($price->type->roles && !$curPrice && strpos($price->type->roles, "|".\Users\User::$cur->role_id."|") !== false)
311 311
       ) {
312 312
         $curPrice = $price;
313 313
       }
Please login to merge, or discard this patch.
system/Inji/Tools.php 4 patches
Doc Comments   +1 added lines patch added patch discarded remove patch
@@ -218,6 +218,7 @@
 block discarded – undo
218 218
    * @param  $number Integer Число на основе которого нужно сформировать окончание
219 219
    * @param  $endingsArray  Array Массив слов или окончаний для чисел (1, 4, 5),
220 220
    *         например array('яблоко', 'яблока', 'яблок')
221
+   * @param string[] $endingArray
221 222
    * @return String
222 223
    */
223 224
   public static function getNumEnding($number, $endingArray) {
Please login to merge, or discard this patch.
Indentation   +227 added lines, -227 removed lines patch added patch discarded remove patch
@@ -12,84 +12,84 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class Tools extends Model {
14 14
 
15
-  /**
16
-   * Return random string
17
-   * 
18
-   * @param int $length
19
-   * @param string $characters
20
-   * @return string
21
-   */
22
-  public static function randomString($length = 20, $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') {
15
+    /**
16
+     * Return random string
17
+     * 
18
+     * @param int $length
19
+     * @param string $characters
20
+     * @return string
21
+     */
22
+    public static function randomString($length = 20, $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') {
23 23
     $charactersLength = strlen($characters);
24 24
     $randomString = '';
25 25
     for ($i = 0; $i < $length; $i++) {
26
-      $randomString .= $characters[rand(0, $charactersLength - 1)];
26
+        $randomString .= $characters[rand(0, $charactersLength - 1)];
27 27
     }
28 28
     return $randomString;
29
-  }
29
+    }
30 30
 
31
-  /**
32
-   * Clean and return user query params
33
-   * 
34
-   * @param string $uri
35
-   * @return array
36
-   */
37
-  public static function uriParse($uri) {
31
+    /**
32
+     * Clean and return user query params
33
+     * 
34
+     * @param string $uri
35
+     * @return array
36
+     */
37
+    public static function uriParse($uri) {
38 38
     $answerPos = strpos($uri, '?');
39 39
     $params = array_slice(explode('/', substr($uri, 0, $answerPos ? $answerPos : strlen($uri) )), 1);
40 40
 
41 41
     foreach ($params as $key => $param) {
42
-      if ($param != '') {
42
+        if ($param != '') {
43 43
         $params[$key] = urldecode($param);
44
-      } else {
44
+        } else {
45 45
         unset($params[$key]);
46
-      }
46
+        }
47 47
     }
48 48
     return $params;
49
-  }
49
+    }
50 50
 
51
-  /**
52
-   * Recursive create dir
53
-   * 
54
-   * @param string $path
55
-   * @return boolean
56
-   */
57
-  public static function createDir($path) {
51
+    /**
52
+     * Recursive create dir
53
+     * 
54
+     * @param string $path
55
+     * @return boolean
56
+     */
57
+    public static function createDir($path) {
58 58
     if (file_exists($path))
59
-      return true;
59
+        return true;
60 60
 
61 61
     $path = explode('/', $path);
62 62
     $cur = '';
63 63
     foreach ($path as $item) {
64
-      $cur .= $item . '/';
65
-      if (!file_exists($cur)) {
64
+        $cur .= $item . '/';
65
+        if (!file_exists($cur)) {
66 66
         mkdir($cur);
67
-      }
67
+        }
68 68
     }
69 69
     return true;
70
-  }
70
+    }
71 71
 
72
-  /**
73
-   * Resize image in path
74
-   * 
75
-   * @param string $img_path
76
-   * @param int $max_width
77
-   * @param int $max_height
78
-   * @param string|false $crop
79
-   * @param string $pos
80
-   * @return string
81
-   */
82
-  public static function resizeImage($img_path, $max_width = 1000, $max_height = 1000, $crop = false, $pos = 'center') {
72
+    /**
73
+     * Resize image in path
74
+     * 
75
+     * @param string $img_path
76
+     * @param int $max_width
77
+     * @param int $max_height
78
+     * @param string|false $crop
79
+     * @param string $pos
80
+     * @return string
81
+     */
82
+    public static function resizeImage($img_path, $max_width = 1000, $max_height = 1000, $crop = false, $pos = 'center') {
83 83
     ini_set("gd.jpeg_ignore_warning", 1);
84 84
     list( $img_width, $img_height, $img_type, $img_tag ) = getimagesize($img_path);
85 85
     switch ($img_type) {
86
-      case 1:
86
+        case 1:
87 87
         $img_type = 'gif';
88 88
         break;
89
-      case 3:
89
+        case 3:
90 90
         $img_type = 'png';
91 91
         break;
92
-      case 2:
92
+        case 2:
93 93
       default:
94 94
         $img_type = 'jpeg';
95 95
         break;
@@ -97,55 +97,55 @@  discard block
 block discarded – undo
97 97
     $imagecreatefromX = "imagecreatefrom{$img_type}";
98 98
     $src_res = $imagecreatefromX($img_path);
99 99
     if (!$src_res) {
100
-      return false;
100
+        return false;
101 101
     }
102 102
 
103 103
     if ($img_width / $max_width > $img_height / $max_height)
104
-      $separator = $img_width / $max_width;
104
+        $separator = $img_width / $max_width;
105 105
     else
106
-      $separator = $img_height / $max_height;
106
+        $separator = $img_height / $max_height;
107 107
 
108 108
     if ($crop === true || $crop == 'q') {
109
-      if ($img_width > $img_height) {
109
+        if ($img_width > $img_height) {
110 110
         $imgX = floor(( $img_width - $img_height ) / 2);
111 111
         $imgY = 0;
112 112
         $img_width = $img_height;
113 113
         $new_width = $max_width;
114 114
         $new_height = $max_height;
115
-      } else {
115
+        } else {
116 116
         $imgX = 0;
117 117
         $imgY = floor(( $img_height - $img_width ) / 2);
118 118
         $img_height = $img_width;
119 119
         $new_width = $max_width;
120 120
         $new_height = $max_height;
121
-      }
122
-      if ($pos == 'top') {
121
+        }
122
+        if ($pos == 'top') {
123 123
         $imgY = 0;
124
-      }
124
+        }
125 125
     } elseif ($crop == 'c') {
126 126
 //Вычисляем некий коэффициент масштабирования
127
-      $k1 = $img_width / $max_width;
128
-      $k2 = $img_height / $max_height;
129
-      $k = $k1 > $k2 ? $k2 : $k1;
130
-      $ow = $img_width;
131
-      $oh = $img_height;
127
+        $k1 = $img_width / $max_width;
128
+        $k2 = $img_height / $max_height;
129
+        $k = $k1 > $k2 ? $k2 : $k1;
130
+        $ow = $img_width;
131
+        $oh = $img_height;
132 132
 //Вычисляем размеры области для нового изображения
133
-      $img_width = intval($max_width * $k);
134
-      $img_height = intval($max_height * $k);
135
-      $new_width = $max_width;
136
-      $new_height = $max_height;
133
+        $img_width = intval($max_width * $k);
134
+        $img_height = intval($max_height * $k);
135
+        $new_width = $max_width;
136
+        $new_height = $max_height;
137 137
 //Находим начальные координаты (центрируем новое изображение)
138
-      $imgX = (int) (($ow / 2) - ($img_width / 2) );
139
-      if ($pos == 'center') {
138
+        $imgX = (int) (($ow / 2) - ($img_width / 2) );
139
+        if ($pos == 'center') {
140 140
         $imgY = (int) (($oh / 2) - ($img_height / 2));
141
-      } else {
141
+        } else {
142 142
         $imgY = 0;
143
-      }
143
+        }
144 144
     } else {
145
-      $imgX = 0;
146
-      $imgY = 0;
147
-      $new_width = floor($img_width / $separator);
148
-      $new_height = floor($img_height / $separator);
145
+        $imgX = 0;
146
+        $imgY = 0;
147
+        $new_width = floor($img_width / $separator);
148
+        $new_height = floor($img_height / $separator);
149 149
     }
150 150
 
151 151
     $new_res = imagecreatetruecolor($new_width, $new_height);
@@ -154,128 +154,128 @@  discard block
 block discarded – undo
154 154
     imagecopyresampled($new_res, $src_res, 0, 0, $imgX, $imgY, $new_width, $new_height, $img_width, $img_height);
155 155
 
156 156
     if ($img_type == 'jpeg') {
157
-      imageinterlace($new_res, 1); // чересстрочное формирование изображение
158
-      imagejpeg($new_res, $img_path, 85);
157
+        imageinterlace($new_res, 1); // чересстрочное формирование изображение
158
+        imagejpeg($new_res, $img_path, 85);
159 159
     } else {
160
-      $imageX = "image{$img_type}";
161
-      $imageX($new_res, $img_path);
160
+        $imageX = "image{$img_type}";
161
+        $imageX($new_res, $img_path);
162 162
     }
163 163
 
164 164
     imagedestroy($new_res);
165 165
     imagedestroy($src_res);
166 166
     return $img_type;
167
-  }
167
+    }
168 168
 
169
-  /**
170
-   * Send mail
171
-   * 
172
-   * @param string $from
173
-   * @param string $to
174
-   * @param string $subject
175
-   * @param string $text
176
-   * @param string $charset
177
-   * @param string $ctype
178
-   * @return boolean
179
-   */
180
-  public static function sendMail($from, $to, $subject, $text, $charset = 'utf-8', $ctype = 'text/html') {
169
+    /**
170
+     * Send mail
171
+     * 
172
+     * @param string $from
173
+     * @param string $to
174
+     * @param string $subject
175
+     * @param string $text
176
+     * @param string $charset
177
+     * @param string $ctype
178
+     * @return boolean
179
+     */
180
+    public static function sendMail($from, $to, $subject, $text, $charset = 'utf-8', $ctype = 'text/html') {
181 181
     $msg = compact('from', 'to', 'subject', 'text', 'charset', 'ctype');
182 182
     $msg = Inji::$inst->event('sendMail', $msg);
183 183
     if (is_array($msg)) {
184
-      $headers = "From: {$msg['from']}\r\n";
185
-      $headers .= "Content-type: {$msg['ctype']}; charset={$msg['charset']}\r\n";
186
-      $headers .= "Mime-Version: 1.0\r\n";
187
-      return mail($msg['to'], $msg['subject'], $msg['text'], $headers);
184
+        $headers = "From: {$msg['from']}\r\n";
185
+        $headers .= "Content-type: {$msg['ctype']}; charset={$msg['charset']}\r\n";
186
+        $headers .= "Mime-Version: 1.0\r\n";
187
+        return mail($msg['to'], $msg['subject'], $msg['text'], $headers);
188 188
     }
189 189
     return $msg;
190
-  }
190
+    }
191 191
 
192
-  /**
193
-   * Redirect user from any place of code
194
-   * 
195
-   * Also add message to message query for view
196
-   * 
197
-   * @param string $href
198
-   * @param string $text
199
-   * @param string $status
200
-   */
201
-  public static function redirect($href = null, $text = false, $status = 'info') {
192
+    /**
193
+     * Redirect user from any place of code
194
+     * 
195
+     * Also add message to message query for view
196
+     * 
197
+     * @param string $href
198
+     * @param string $text
199
+     * @param string $status
200
+     */
201
+    public static function redirect($href = null, $text = false, $status = 'info') {
202 202
     if ($href === null) {
203
-      $href = $_SERVER['REQUEST_URI'];
203
+        $href = $_SERVER['REQUEST_URI'];
204 204
     }
205 205
     if ($text !== false) {
206
-      Msg::add($text, $status);
206
+        Msg::add($text, $status);
207 207
     }
208 208
     if (!headers_sent()) {
209
-      header("Location: {$href}");
209
+        header("Location: {$href}");
210 210
     } else {
211
-      echo '\'"><script>window.location="' . $href . '";</script>';
211
+        echo '\'"><script>window.location="' . $href . '";</script>';
212 212
     }
213 213
     exit("Перенаправление на: <a href = '{$href}'>{$href}</a>");
214
-  }
214
+    }
215 215
 
216
-  /**
217
-   * Функция возвращает окончание для множественного числа слова на основании числа и массива окончаний
218
-   * @param  $number Integer Число на основе которого нужно сформировать окончание
219
-   * @param  $endingsArray  Array Массив слов или окончаний для чисел (1, 4, 5),
220
-   *         например array('яблоко', 'яблока', 'яблок')
221
-   * @return String
222
-   */
223
-  public static function getNumEnding($number, $endingArray) {
216
+    /**
217
+     * Функция возвращает окончание для множественного числа слова на основании числа и массива окончаний
218
+     * @param  $number Integer Число на основе которого нужно сформировать окончание
219
+     * @param  $endingsArray  Array Массив слов или окончаний для чисел (1, 4, 5),
220
+     *         например array('яблоко', 'яблока', 'яблок')
221
+     * @return String
222
+     */
223
+    public static function getNumEnding($number, $endingArray) {
224 224
     $number = $number % 100;
225 225
     if ($number >= 11 && $number <= 19) {
226
-      $ending = $endingArray[2];
226
+        $ending = $endingArray[2];
227 227
     } else {
228
-      $i = $number % 10;
229
-      switch ($i) {
228
+        $i = $number % 10;
229
+        switch ($i) {
230 230
         case (1): $ending = $endingArray[0];
231
-          break;
231
+            break;
232 232
         case (2):
233 233
         case (3):
234 234
         case (4): $ending = $endingArray[1];
235
-          break;
235
+            break;
236 236
         default: $ending = $endingArray[2];
237
-      }
237
+        }
238 238
     }
239 239
     return $ending;
240
-  }
240
+    }
241 241
 
242
-  /**
243
-   * Clean request path
244
-   * 
245
-   * @param string $path
246
-   * @return string
247
-   */
248
-  public static function parsePath($path) {
242
+    /**
243
+     * Clean request path
244
+     * 
245
+     * @param string $path
246
+     * @return string
247
+     */
248
+    public static function parsePath($path) {
249 249
     $path = str_replace('\\', '/', $path);
250 250
     $pathArray = explode('/', $path);
251 251
     $cleanPathArray = [];
252 252
     do {
253
-      $changes = 0;
254
-      foreach ($pathArray as $pathItem) {
253
+        $changes = 0;
254
+        foreach ($pathArray as $pathItem) {
255 255
         if (trim($pathItem) === '' || $pathItem == '.') {
256
-          $changes++;
257
-          continue;
256
+            $changes++;
257
+            continue;
258 258
         }
259 259
         if ($pathItem == '..') {
260
-          array_pop($cleanPathArray);
261
-          $changes++;
262
-          continue;
260
+            array_pop($cleanPathArray);
261
+            $changes++;
262
+            continue;
263 263
         }
264 264
         $cleanPathArray[] = $pathItem;
265
-      }
266
-      $pathArray = $cleanPathArray;
267
-      $cleanPathArray = [];
265
+        }
266
+        $pathArray = $cleanPathArray;
267
+        $cleanPathArray = [];
268 268
     } while ($changes);
269 269
     return (strpos($path, '/') === 0 ? '/' : '') . implode('/', $pathArray);
270
-  }
270
+    }
271 271
 
272
-  /**
273
-   * Show date in rus
274
-   * 
275
-   * @param string $date
276
-   * @return string
277
-   */
278
-  public static function toRusDate($date) {
272
+    /**
273
+     * Show date in rus
274
+     * 
275
+     * @param string $date
276
+     * @return string
277
+     */
278
+    public static function toRusDate($date) {
279 279
     $yy = (int) substr($date, 0, 4);
280 280
     $mm = (int) substr($date, 5, 2);
281 281
     $dd = (int) substr($date, 8, 2);
@@ -284,114 +284,114 @@  discard block
 block discarded – undo
284 284
 
285 285
     $month = array('января', 'февраля', 'марта', 'апреля', 'мая', 'июня', 'июля', 'августа', 'сентября', 'октября', 'ноября', 'декабря');
286 286
     if (empty($month[$mm - 1])) {
287
-      return 'Не указано';
287
+        return 'Не указано';
288 288
     }
289 289
     return ($dd > 0 ? $dd . " " : '') . $month[$mm - 1] . " " . $yy . " " . $hours;
290
-  }
290
+    }
291 291
 
292
-  /**
293
-   * Set header
294
-   * 
295
-   * @param string $code
296
-   * @param boolean $exit
297
-   */
298
-  public static function header($code, $exit = false) {
292
+    /**
293
+     * Set header
294
+     * 
295
+     * @param string $code
296
+     * @param boolean $exit
297
+     */
298
+    public static function header($code, $exit = false) {
299 299
     if (!headers_sent()) {
300
-      switch ($code) {
300
+        switch ($code) {
301 301
         case '404':
302 302
           header('HTTP/1.1 404 Not Found');
303
-          break;
303
+            break;
304 304
         default :
305 305
           header($code);
306
-      }
306
+        }
307 307
     }
308 308
     if ($exit) {
309
-      exit;
309
+        exit;
310
+    }
310 311
     }
311
-  }
312 312
 
313
-  /**
314
-   * Return exist path from array
315
-   * 
316
-   * If no exist path in array - return default
317
-   * 
318
-   * @param array $paths
319
-   * @param string|false $default
320
-   * @return string|false
321
-   */
322
-  public static function pathsResolve($paths = [], $default = false) {
313
+    /**
314
+     * Return exist path from array
315
+     * 
316
+     * If no exist path in array - return default
317
+     * 
318
+     * @param array $paths
319
+     * @param string|false $default
320
+     * @return string|false
321
+     */
322
+    public static function pathsResolve($paths = [], $default = false) {
323 323
     foreach ($paths as $path) {
324
-      if (file_exists($path)) {
324
+        if (file_exists($path)) {
325 325
         return $path;
326
-      }
326
+        }
327 327
     }
328 328
     return $default;
329
-  }
329
+    }
330 330
 
331
-  /**
332
-   * Convert acronyms to bites
333
-   * 
334
-   * @param string $val
335
-   * @return int
336
-   */
337
-  public static function toBytes($val) {
331
+    /**
332
+     * Convert acronyms to bites
333
+     * 
334
+     * @param string $val
335
+     * @return int
336
+     */
337
+    public static function toBytes($val) {
338 338
     $val = trim($val);
339 339
     $last = strtolower($val[strlen($val) - 1]);
340 340
     switch ($last) {
341
-      case 'g':
341
+        case 'g':
342 342
         $val *= 1024;
343
-      case 'm':
343
+        case 'm':
344 344
         $val *= 1024;
345
-      case 'k':
345
+        case 'k':
346 346
         $val *= 1024;
347 347
     }
348 348
 
349 349
     return $val;
350
-  }
350
+    }
351 351
 
352
-  /**
353
-   * Recursive copy directories and files
354
-   * 
355
-   * @param string $from
356
-   * @param string $to
357
-   */
358
-  public static function copyFiles($from, $to) {
352
+    /**
353
+     * Recursive copy directories and files
354
+     * 
355
+     * @param string $from
356
+     * @param string $to
357
+     */
358
+    public static function copyFiles($from, $to) {
359 359
     $from = rtrim($from, '/');
360 360
     $to = rtrim($to, '/');
361 361
     self::createDir($to);
362 362
     $files = scandir($from);
363 363
     foreach ($files as $file) {
364
-      if (in_array($file, ['.', '..'])) {
364
+        if (in_array($file, ['.', '..'])) {
365 365
         continue;
366
-      }
367
-      if (is_dir($from . '/' . $file)) {
366
+        }
367
+        if (is_dir($from . '/' . $file)) {
368 368
         self::copyFiles($from . '/' . $file, $to . '/' . $file);
369
-      } else {
369
+        } else {
370 370
         copy($from . '/' . $file, $to . '/' . $file);
371
-      }
371
+        }
372
+    }
372 373
     }
373
-  }
374 374
 
375
-  /**
376
-   * Translit function
377
-   * 
378
-   * @param string $str
379
-   * @return string
380
-   */
381
-  public static function translit($str) {
375
+    /**
376
+     * Translit function
377
+     * 
378
+     * @param string $str
379
+     * @return string
380
+     */
381
+    public static function translit($str) {
382 382
     $rus = array('А', 'Б', 'В', 'Г', 'Д', 'Е', 'Ё', 'Ж', 'З', 'И', 'Й', 'К', 'Л', 'М', 'Н', 'О', 'П', 'Р', 'С', 'Т', 'У', 'Ф', 'Х', 'Ц', 'Ч', 'Ш', 'Щ', 'Ъ', 'Ы', 'Ь', 'Э', 'Ю', 'Я', 'а', 'б', 'в', 'г', 'д', 'е', 'ё', 'ж', 'з', 'и', 'й', 'к', 'л', 'м', 'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч', 'ш', 'щ', 'ъ', 'ы', 'ь', 'э', 'ю', 'я');
383 383
     $lat = array('A', 'B', 'V', 'G', 'D', 'E', 'E', 'Gh', 'Z', 'I', 'Y', 'K', 'L', 'M', 'N', 'O', 'P', 'R', 'S', 'T', 'U', 'F', 'H', 'C', 'Ch', 'Sh', 'Sch', 'Y', 'Y', 'Y', 'E', 'Yu', 'Ya', 'a', 'b', 'v', 'g', 'd', 'e', 'e', 'gh', 'z', 'i', 'y', 'k', 'l', 'm', 'n', 'o', 'p', 'r', 's', 't', 'u', 'f', 'h', 'c', 'ch', 'sh', 'sch', 'y', 'y', 'y', 'e', 'yu', 'ya');
384 384
     return str_replace($rus, $lat, $str);
385
-  }
385
+    }
386 386
 
387
-  /**
388
-   * get youtube video ID from URL
389
-   *
390
-   * @author http://stackoverflow.com/a/6556662
391
-   * @param string $url
392
-   * @return string Youtube video id or FALSE if none found. 
393
-   */
394
-  public static function youtubeIdFromUrl($url) {
387
+    /**
388
+     * get youtube video ID from URL
389
+     *
390
+     * @author http://stackoverflow.com/a/6556662
391
+     * @param string $url
392
+     * @return string Youtube video id or FALSE if none found. 
393
+     */
394
+    public static function youtubeIdFromUrl($url) {
395 395
     $pattern = '%^# Match any youtube URL
396 396
         (?:https?://)?  # Optional scheme. Either http or https
397 397
         (?:www\.)?      # Optional www subdomain
@@ -409,20 +409,20 @@  discard block
 block discarded – undo
409 409
     ;
410 410
     $result = preg_match($pattern, $url, $matches);
411 411
     if (false !== $result) {
412
-      return $matches[1];
412
+        return $matches[1];
413 413
     }
414 414
     return false;
415
-  }
415
+    }
416 416
 
417
-  /**
418
-   * check array is associative
419
-   *
420
-   * @author http://stackoverflow.com/a/173479
421
-   * @param array $arr
422
-   * @return boolean
423
-   */
424
-  public static function isAssoc(&$arr) {
417
+    /**
418
+     * check array is associative
419
+     *
420
+     * @author http://stackoverflow.com/a/173479
421
+     * @param array $arr
422
+     * @return boolean
423
+     */
424
+    public static function isAssoc(&$arr) {
425 425
     return array_keys($arr) !== range(0, count($arr) - 1);
426
-  }
426
+    }
427 427
 
428 428
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
    */
37 37
   public static function uriParse($uri) {
38 38
     $answerPos = strpos($uri, '?');
39
-    $params = array_slice(explode('/', substr($uri, 0, $answerPos ? $answerPos : strlen($uri) )), 1);
39
+    $params = array_slice(explode('/', substr($uri, 0, $answerPos ? $answerPos : strlen($uri))), 1);
40 40
 
41 41
     foreach ($params as $key => $param) {
42 42
       if ($param != '') {
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
     $path = explode('/', $path);
62 62
     $cur = '';
63 63
     foreach ($path as $item) {
64
-      $cur .= $item . '/';
64
+      $cur .= $item.'/';
65 65
       if (!file_exists($cur)) {
66 66
         mkdir($cur);
67 67
       }
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
    */
82 82
   public static function resizeImage($img_path, $max_width = 1000, $max_height = 1000, $crop = false, $pos = 'center') {
83 83
     ini_set("gd.jpeg_ignore_warning", 1);
84
-    list( $img_width, $img_height, $img_type, $img_tag ) = getimagesize($img_path);
84
+    list($img_width, $img_height, $img_type, $img_tag) = getimagesize($img_path);
85 85
     switch ($img_type) {
86 86
       case 1:
87 87
         $img_type = 'gif';
@@ -107,14 +107,14 @@  discard block
 block discarded – undo
107 107
 
108 108
     if ($crop === true || $crop == 'q') {
109 109
       if ($img_width > $img_height) {
110
-        $imgX = floor(( $img_width - $img_height ) / 2);
110
+        $imgX = floor(($img_width - $img_height) / 2);
111 111
         $imgY = 0;
112 112
         $img_width = $img_height;
113 113
         $new_width = $max_width;
114 114
         $new_height = $max_height;
115 115
       } else {
116 116
         $imgX = 0;
117
-        $imgY = floor(( $img_height - $img_width ) / 2);
117
+        $imgY = floor(($img_height - $img_width) / 2);
118 118
         $img_height = $img_width;
119 119
         $new_width = $max_width;
120 120
         $new_height = $max_height;
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
       $new_width = $max_width;
136 136
       $new_height = $max_height;
137 137
 //Находим начальные координаты (центрируем новое изображение)
138
-      $imgX = (int) (($ow / 2) - ($img_width / 2) );
138
+      $imgX = (int) (($ow / 2) - ($img_width / 2));
139 139
       if ($pos == 'center') {
140 140
         $imgY = (int) (($oh / 2) - ($img_height / 2));
141 141
       } else {
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
     if (!headers_sent()) {
209 209
       header("Location: {$href}");
210 210
     } else {
211
-      echo '\'"><script>window.location="' . $href . '";</script>';
211
+      echo '\'"><script>window.location="'.$href.'";</script>';
212 212
     }
213 213
     exit("Перенаправление на: <a href = '{$href}'>{$href}</a>");
214 214
   }
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
       $pathArray = $cleanPathArray;
267 267
       $cleanPathArray = [];
268 268
     } while ($changes);
269
-    return (strpos($path, '/') === 0 ? '/' : '') . implode('/', $pathArray);
269
+    return (strpos($path, '/') === 0 ? '/' : '').implode('/', $pathArray);
270 270
   }
271 271
 
272 272
   /**
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
     if (empty($month[$mm - 1])) {
287 287
       return 'Не указано';
288 288
     }
289
-    return ($dd > 0 ? $dd . " " : '') . $month[$mm - 1] . " " . $yy . " " . $hours;
289
+    return ($dd > 0 ? $dd." " : '').$month[$mm - 1]." ".$yy." ".$hours;
290 290
   }
291 291
 
292 292
   /**
@@ -364,10 +364,10 @@  discard block
 block discarded – undo
364 364
       if (in_array($file, ['.', '..'])) {
365 365
         continue;
366 366
       }
367
-      if (is_dir($from . '/' . $file)) {
368
-        self::copyFiles($from . '/' . $file, $to . '/' . $file);
367
+      if (is_dir($from.'/'.$file)) {
368
+        self::copyFiles($from.'/'.$file, $to.'/'.$file);
369 369
       } else {
370
-        copy($from . '/' . $file, $to . '/' . $file);
370
+        copy($from.'/'.$file, $to.'/'.$file);
371 371
       }
372 372
     }
373 373
   }
Please login to merge, or discard this patch.
Braces   +8 added lines, -6 removed lines patch added patch discarded remove patch
@@ -55,8 +55,9 @@  discard block
 block discarded – undo
55 55
    * @return boolean
56 56
    */
57 57
   public static function createDir($path) {
58
-    if (file_exists($path))
59
-      return true;
58
+    if (file_exists($path)) {
59
+          return true;
60
+    }
60 61
 
61 62
     $path = explode('/', $path);
62 63
     $cur = '';
@@ -100,10 +101,11 @@  discard block
 block discarded – undo
100 101
       return false;
101 102
     }
102 103
 
103
-    if ($img_width / $max_width > $img_height / $max_height)
104
-      $separator = $img_width / $max_width;
105
-    else
106
-      $separator = $img_height / $max_height;
104
+    if ($img_width / $max_width > $img_height / $max_height) {
105
+          $separator = $img_width / $max_width;
106
+    } else {
107
+          $separator = $img_height / $max_height;
108
+    }
107 109
 
108 110
     if ($crop === true || $crop == 'q') {
109 111
       if ($img_width > $img_height) {
Please login to merge, or discard this patch.
system/modules/Sliders/models/Slide.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -13,52 +13,52 @@  discard block
 block discarded – undo
13 13
 
14 14
 class Slide extends \Model {
15 15
 
16
-  public static $objectName = "Слайд";
17
-  public static $cols = [
18
-      'name' => ['type' => 'text'],
19
-      'link' => ['type' => 'text'],
20
-      'description' => ['type' => 'html'],
21
-      'image_file_id' => ['type' => 'image'],
22
-      'preview_image_file_id' => ['type' => 'image'],
23
-      'slider_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'slider'],
24
-      'user_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'user'],
25
-      'weight' => ['type' => 'number'],
26
-      'date_create' => ['type' => 'dateTime'],
27
-  ];
28
-  public static $labels = [
29
-      'name' => 'Имя',
30
-      'link' => 'Ссылка',
31
-      'description' => 'Описание',
32
-      'date_create' => 'Дата создания',
33
-      'slider_id' => 'Слайдер',
34
-      'user_id' => 'Создатель',
35
-      'weight' => 'Вес',
36
-      'image_file_id' => 'Изображение',
37
-      'preview_image_file_id' => 'Превью Изображения',
38
-  ];
39
-  public static $dataManagers = [
40
-      'manager' => [
41
-          'name' => 'Слайды',
42
-          'cols' => [
43
-              'image_file_id', 'name', 'link', 'date_create'
44
-          ],
45
-          'filters' => [
46
-              'slider_id', 'name', 'link', 'description', 'date_create'
47
-          ],
48
-          'sortMode' => true
49
-      ],
50
-  ];
51
-  public static $forms = [
52
-      'manager' => [
53
-          'map' => [
54
-              ['name', 'link'],
55
-              ['preview_image_file_id', 'image_file_id'],
56
-              ['description'],
57
-          ],
58
-      ],
59
-  ];
16
+    public static $objectName = "Слайд";
17
+    public static $cols = [
18
+        'name' => ['type' => 'text'],
19
+        'link' => ['type' => 'text'],
20
+        'description' => ['type' => 'html'],
21
+        'image_file_id' => ['type' => 'image'],
22
+        'preview_image_file_id' => ['type' => 'image'],
23
+        'slider_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'slider'],
24
+        'user_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'user'],
25
+        'weight' => ['type' => 'number'],
26
+        'date_create' => ['type' => 'dateTime'],
27
+    ];
28
+    public static $labels = [
29
+        'name' => 'Имя',
30
+        'link' => 'Ссылка',
31
+        'description' => 'Описание',
32
+        'date_create' => 'Дата создания',
33
+        'slider_id' => 'Слайдер',
34
+        'user_id' => 'Создатель',
35
+        'weight' => 'Вес',
36
+        'image_file_id' => 'Изображение',
37
+        'preview_image_file_id' => 'Превью Изображения',
38
+    ];
39
+    public static $dataManagers = [
40
+        'manager' => [
41
+            'name' => 'Слайды',
42
+            'cols' => [
43
+                'image_file_id', 'name', 'link', 'date_create'
44
+            ],
45
+            'filters' => [
46
+                'slider_id', 'name', 'link', 'description', 'date_create'
47
+            ],
48
+            'sortMode' => true
49
+        ],
50
+    ];
51
+    public static $forms = [
52
+        'manager' => [
53
+            'map' => [
54
+                ['name', 'link'],
55
+                ['preview_image_file_id', 'image_file_id'],
56
+                ['description'],
57
+            ],
58
+        ],
59
+    ];
60 60
 
61
-  public static function relations() {
61
+    public static function relations() {
62 62
     return [
63 63
         'slider' => [
64 64
             'model' => 'Sliders\Slider',
@@ -77,6 +77,6 @@  discard block
 block discarded – undo
77 77
             'col' => 'user_id'
78 78
         ]
79 79
     ];
80
-  }
80
+    }
81 81
 
82 82
 }
Please login to merge, or discard this patch.
system/modules/Files/models/Type.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -13,13 +13,13 @@
 block discarded – undo
13 13
 
14 14
 class Type extends \Model {
15 15
 
16
-  public static $cols = [
17
-      'dir' => ['type' => 'text'],
18
-      'ext' => ['type' => 'text'],
19
-      'group' => ['type' => 'text'],
20
-      'allow_resize' => ['type' => 'bool'],
21
-      'options' => ['type' => 'textarea'],
22
-      'date_create' => ['type' => 'dateTime'],
23
-  ];
16
+    public static $cols = [
17
+        'dir' => ['type' => 'text'],
18
+        'ext' => ['type' => 'text'],
19
+        'group' => ['type' => 'text'],
20
+        'allow_resize' => ['type' => 'bool'],
21
+        'options' => ['type' => 'textarea'],
22
+        'date_create' => ['type' => 'dateTime'],
23
+    ];
24 24
 
25 25
 }
Please login to merge, or discard this patch.
system/modules/Files/install_script.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -1,39 +1,39 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 return function($step = NULL, $params = []) {
4
-  $options = ['max_height' => 1200, 'max_width' => 1200];
5
-  $types = [
6
-      [
7
-          'dir' => '/static/mediafiles/images/',
8
-          'ext' => 'png',
9
-          'group' => 'image',
10
-          'allow_resize' => 1,
11
-          'options' => json_encode($options)
12
-      ],
13
-      [
14
-          'dir' => '/static/mediafiles/images/',
15
-          'ext' => 'jpeg',
16
-          'group' => 'image',
17
-          'allow_resize' => 1,
18
-          'options' => json_encode($options)
19
-      ],
20
-      [
21
-          'dir' => '/static/mediafiles/images/',
22
-          'ext' => 'jpg',
23
-          'group' => 'image',
24
-          'allow_resize' => 1,
25
-          'options' => json_encode($options)
26
-      ],
27
-      [
28
-          'dir' => '/static/mediafiles/images/',
29
-          'ext' => 'gif',
30
-          'group' => 'image',
31
-          'allow_resize' => 1,
32
-          'options' => json_encode($options)
33
-      ],
34
-  ];
35
-  foreach ($types as $type) {
4
+    $options = ['max_height' => 1200, 'max_width' => 1200];
5
+    $types = [
6
+        [
7
+            'dir' => '/static/mediafiles/images/',
8
+            'ext' => 'png',
9
+            'group' => 'image',
10
+            'allow_resize' => 1,
11
+            'options' => json_encode($options)
12
+        ],
13
+        [
14
+            'dir' => '/static/mediafiles/images/',
15
+            'ext' => 'jpeg',
16
+            'group' => 'image',
17
+            'allow_resize' => 1,
18
+            'options' => json_encode($options)
19
+        ],
20
+        [
21
+            'dir' => '/static/mediafiles/images/',
22
+            'ext' => 'jpg',
23
+            'group' => 'image',
24
+            'allow_resize' => 1,
25
+            'options' => json_encode($options)
26
+        ],
27
+        [
28
+            'dir' => '/static/mediafiles/images/',
29
+            'ext' => 'gif',
30
+            'group' => 'image',
31
+            'allow_resize' => 1,
32
+            'options' => json_encode($options)
33
+        ],
34
+    ];
35
+    foreach ($types as $type) {
36 36
     $typeObject = new \Files\Type($type);
37 37
     $typeObject->save();
38
-  }
38
+    }
39 39
 };
Please login to merge, or discard this patch.
system/modules/Files/Files.php 3 patches
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -10,58 +10,58 @@  discard block
 block discarded – undo
10 10
  */
11 11
 class Files extends Module {
12 12
 
13
-  /**
14
-   * Загрузка файлов
15
-   * 
16
-   * $file - масив из переменной $_FILES[{input name}]
17
-   * $options - массив из опций заливки 
18
-   * --	[file_code]: уникальный код для системы медиаданых
19
-   * --	[allow_types]: досупные для заливки типы файлов. Например image (тип форматов из таблицы типов файлов file_type_ext)
20
-   */
21
-  public function upload($file, $options = []) {
13
+    /**
14
+     * Загрузка файлов
15
+     * 
16
+     * $file - масив из переменной $_FILES[{input name}]
17
+     * $options - массив из опций заливки 
18
+     * --	[file_code]: уникальный код для системы медиаданых
19
+     * --	[allow_types]: досупные для заливки типы файлов. Например image (тип форматов из таблицы типов файлов file_type_ext)
20
+     */
21
+    public function upload($file, $options = []) {
22 22
 
23 23
     $sitePath = App::$primary->path;
24 24
 
25 25
     if (!is_uploaded_file($file['tmp_name']))
26
-      return 0;
26
+        return 0;
27 27
 
28 28
     $fileinfo = pathinfo($file['name']);
29 29
     if (empty($fileinfo['extension']))
30
-      return 0;
30
+        return 0;
31 31
 
32 32
     $type = Files\Type::get($fileinfo['extension'], 'ext');
33 33
     if (!$type)
34
-      return 0;
34
+        return 0;
35 35
 
36 36
     if (!empty($options['accept_group']) && $options['accept_group'] != $type->group) {
37
-      return 0;
37
+        return 0;
38 38
     }
39 39
 
40 40
     $fileObject = new Files\File();
41 41
     if (!empty($options['file_code'])) {
42
-      $fileObject = Files\File::get($options['file_code'], 'code');
43
-      if (!$fileObject) {
42
+        $fileObject = Files\File::get($options['file_code'], 'code');
43
+        if (!$fileObject) {
44 44
         $fileObject = new Files\File();
45 45
         $fileObject->code = $options['file_code'];
46
-      }
46
+        }
47 47
     }
48 48
     $fileObject->name = $fileinfo['filename'];
49 49
     $fileObject->path = $type->type_dir . date('Y-m-d') . '/' . microtime(true) . '.' . $fileinfo['extension'];
50 50
     if ($fileObject->id && file_exists($sitePath . $fileObject->path))
51
-      unlink($sitePath . $fileObject->path);
51
+        unlink($sitePath . $fileObject->path);
52 52
 
53 53
     Tools::createDir($sitePath . $type->type_dir . date('Y-m-d') . '/');
54 54
 
55 55
     if (!move_uploaded_file($file['tmp_name'], $sitePath . $fileObject->path)) {
56
-      return false;
56
+        return false;
57 57
     }
58 58
 
59 59
     if ($type->allow_resize && $type->options && json_decode($type->options, true)) {
60
-      $typeOptions = json_decode($type->options, true);
61
-      list( $img_width, $img_height, $img_type, $img_tag ) = getimagesize($sitePath . $fileObject->path);
62
-      if ($img_height > $typeOptions['max_height'] || $img_width > $typeOptions['max_width']) {
60
+        $typeOptions = json_decode($type->options, true);
61
+        list( $img_width, $img_height, $img_type, $img_tag ) = getimagesize($sitePath . $fileObject->path);
62
+        if ($img_height > $typeOptions['max_height'] || $img_width > $typeOptions['max_width']) {
63 63
         Tools::resizeImage($sitePath . $fileObject->path, $typeOptions['max_width'], $typeOptions['max_height']);
64
-      }
64
+        }
65 65
     }
66 66
 
67 67
     $fileObject->type_id = $type->pk();
@@ -70,60 +70,60 @@  discard block
 block discarded – undo
70 70
     $fileObject->save();
71 71
 
72 72
     return $fileObject->id;
73
-  }
74
-
75
-  /**
76
-   * Загрузка файлов по урл
77
-   * 
78
-   * $url - адрес файла
79
-   * $options - массив из опций заливки 
80
-   * --	[file_code]: уникальный код для системы медиаданых
81
-   * --	[allow_types]: досупные для заливки типы файлов. Например image (тип форматов из таблицы типов файлов file_type_ext)
82
-   */
83
-  public function uploadFromUrl($url, $options = []) {
73
+    }
74
+
75
+    /**
76
+     * Загрузка файлов по урл
77
+     * 
78
+     * $url - адрес файла
79
+     * $options - массив из опций заливки 
80
+     * --	[file_code]: уникальный код для системы медиаданых
81
+     * --	[allow_types]: досупные для заливки типы файлов. Например image (тип форматов из таблицы типов файлов file_type_ext)
82
+     */
83
+    public function uploadFromUrl($url, $options = []) {
84 84
     $sitePath = App::$primary->path;
85 85
 
86 86
     $fileinfo = pathinfo($url);
87 87
     if (empty($fileinfo['extension']))
88
-      return 0;
88
+        return 0;
89 89
 
90 90
     $type = Files\Type::get($fileinfo['extension'], 'ext');
91 91
     if (!$type)
92
-      return 0;
92
+        return 0;
93 93
 
94 94
     if (!empty($options['accept_group']) && $options['accept_group'] != $type->group) {
95
-      return 0;
95
+        return 0;
96 96
     }
97 97
 
98 98
     $fileObject = new Files\File();
99 99
     if (!empty($options['file_code'])) {
100
-      $fileObject = Files\File::get($options['file_code'], 'code');
101
-      if (!$fileObject) {
100
+        $fileObject = Files\File::get($options['file_code'], 'code');
101
+        if (!$fileObject) {
102 102
         $fileObject = new Files\File();
103 103
         $fileObject->code = $options['file_code'];
104
-      }
104
+        }
105 105
     }
106 106
     $fileObject->name = $fileinfo['filename'];
107 107
     $fileObject->path = $type->type_dir . date('Y-m-d') . '/' . microtime(true) . '.' . $fileinfo['extension'];
108 108
     if ($fileObject->id && file_exists($sitePath . $fileObject->path))
109
-      unlink($sitePath . $fileObject->path);
109
+        unlink($sitePath . $fileObject->path);
110 110
 
111 111
     Tools::createDir($sitePath . $type->type_dir . date('Y-m-d') . '/');
112 112
 
113 113
     $file = @file_get_contents($url);
114 114
     if ($file === false) {
115
-      return 0;
115
+        return 0;
116 116
     }
117 117
     if (!file_put_contents($sitePath . $fileObject->path, $file)) {
118
-      return 0;
118
+        return 0;
119 119
     }
120 120
 
121 121
     if ($type->allow_resize && $type->options && json_decode($type->options, true)) {
122
-      $typeOptions = json_decode($type->options, true);
123
-      list( $img_width, $img_height, $img_type, $img_tag ) = getimagesize($sitePath . $fileObject->path);
124
-      if ($img_height > $typeOptions['max_height'] || $img_width > $typeOptions['max_width']) {
122
+        $typeOptions = json_decode($type->options, true);
123
+        list( $img_width, $img_height, $img_type, $img_tag ) = getimagesize($sitePath . $fileObject->path);
124
+        if ($img_height > $typeOptions['max_height'] || $img_width > $typeOptions['max_width']) {
125 125
         Tools::resizeImage($sitePath . $fileObject->path, $typeOptions['max_width'], $typeOptions['max_height']);
126
-      }
126
+        }
127 127
     }
128 128
 
129 129
     $fileObject->type_id = $type->pk();
@@ -132,6 +132,6 @@  discard block
 block discarded – undo
132 132
     $fileObject->save();
133 133
 
134 134
     return $fileObject->id;
135
-  }
135
+    }
136 136
 
137 137
 }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -46,21 +46,21 @@  discard block
 block discarded – undo
46 46
       }
47 47
     }
48 48
     $fileObject->name = $fileinfo['filename'];
49
-    $fileObject->path = $type->type_dir . date('Y-m-d') . '/' . microtime(true) . '.' . $fileinfo['extension'];
50
-    if ($fileObject->id && file_exists($sitePath . $fileObject->path))
51
-      unlink($sitePath . $fileObject->path);
49
+    $fileObject->path = $type->type_dir.date('Y-m-d').'/'.microtime(true).'.'.$fileinfo['extension'];
50
+    if ($fileObject->id && file_exists($sitePath.$fileObject->path))
51
+      unlink($sitePath.$fileObject->path);
52 52
 
53
-    Tools::createDir($sitePath . $type->type_dir . date('Y-m-d') . '/');
53
+    Tools::createDir($sitePath.$type->type_dir.date('Y-m-d').'/');
54 54
 
55
-    if (!move_uploaded_file($file['tmp_name'], $sitePath . $fileObject->path)) {
55
+    if (!move_uploaded_file($file['tmp_name'], $sitePath.$fileObject->path)) {
56 56
       return false;
57 57
     }
58 58
 
59 59
     if ($type->allow_resize && $type->options && json_decode($type->options, true)) {
60 60
       $typeOptions = json_decode($type->options, true);
61
-      list( $img_width, $img_height, $img_type, $img_tag ) = getimagesize($sitePath . $fileObject->path);
61
+      list($img_width, $img_height, $img_type, $img_tag) = getimagesize($sitePath.$fileObject->path);
62 62
       if ($img_height > $typeOptions['max_height'] || $img_width > $typeOptions['max_width']) {
63
-        Tools::resizeImage($sitePath . $fileObject->path, $typeOptions['max_width'], $typeOptions['max_height']);
63
+        Tools::resizeImage($sitePath.$fileObject->path, $typeOptions['max_width'], $typeOptions['max_height']);
64 64
       }
65 65
     }
66 66
 
@@ -104,25 +104,25 @@  discard block
 block discarded – undo
104 104
       }
105 105
     }
106 106
     $fileObject->name = $fileinfo['filename'];
107
-    $fileObject->path = $type->type_dir . date('Y-m-d') . '/' . microtime(true) . '.' . $fileinfo['extension'];
108
-    if ($fileObject->id && file_exists($sitePath . $fileObject->path))
109
-      unlink($sitePath . $fileObject->path);
107
+    $fileObject->path = $type->type_dir.date('Y-m-d').'/'.microtime(true).'.'.$fileinfo['extension'];
108
+    if ($fileObject->id && file_exists($sitePath.$fileObject->path))
109
+      unlink($sitePath.$fileObject->path);
110 110
 
111
-    Tools::createDir($sitePath . $type->type_dir . date('Y-m-d') . '/');
111
+    Tools::createDir($sitePath.$type->type_dir.date('Y-m-d').'/');
112 112
 
113 113
     $file = @file_get_contents($url);
114 114
     if ($file === false) {
115 115
       return 0;
116 116
     }
117
-    if (!file_put_contents($sitePath . $fileObject->path, $file)) {
117
+    if (!file_put_contents($sitePath.$fileObject->path, $file)) {
118 118
       return 0;
119 119
     }
120 120
 
121 121
     if ($type->allow_resize && $type->options && json_decode($type->options, true)) {
122 122
       $typeOptions = json_decode($type->options, true);
123
-      list( $img_width, $img_height, $img_type, $img_tag ) = getimagesize($sitePath . $fileObject->path);
123
+      list($img_width, $img_height, $img_type, $img_tag) = getimagesize($sitePath.$fileObject->path);
124 124
       if ($img_height > $typeOptions['max_height'] || $img_width > $typeOptions['max_width']) {
125
-        Tools::resizeImage($sitePath . $fileObject->path, $typeOptions['max_width'], $typeOptions['max_height']);
125
+        Tools::resizeImage($sitePath.$fileObject->path, $typeOptions['max_width'], $typeOptions['max_height']);
126 126
       }
127 127
     }
128 128
 
Please login to merge, or discard this patch.
Braces   +21 added lines, -14 removed lines patch added patch discarded remove patch
@@ -22,16 +22,19 @@  discard block
 block discarded – undo
22 22
 
23 23
     $sitePath = App::$primary->path;
24 24
 
25
-    if (!is_uploaded_file($file['tmp_name']))
26
-      return 0;
25
+    if (!is_uploaded_file($file['tmp_name'])) {
26
+          return 0;
27
+    }
27 28
 
28 29
     $fileinfo = pathinfo($file['name']);
29
-    if (empty($fileinfo['extension']))
30
-      return 0;
30
+    if (empty($fileinfo['extension'])) {
31
+          return 0;
32
+    }
31 33
 
32 34
     $type = Files\Type::get($fileinfo['extension'], 'ext');
33
-    if (!$type)
34
-      return 0;
35
+    if (!$type) {
36
+          return 0;
37
+    }
35 38
 
36 39
     if (!empty($options['accept_group']) && $options['accept_group'] != $type->group) {
37 40
       return 0;
@@ -47,8 +50,9 @@  discard block
 block discarded – undo
47 50
     }
48 51
     $fileObject->name = $fileinfo['filename'];
49 52
     $fileObject->path = $type->type_dir . date('Y-m-d') . '/' . microtime(true) . '.' . $fileinfo['extension'];
50
-    if ($fileObject->id && file_exists($sitePath . $fileObject->path))
51
-      unlink($sitePath . $fileObject->path);
53
+    if ($fileObject->id && file_exists($sitePath . $fileObject->path)) {
54
+          unlink($sitePath . $fileObject->path);
55
+    }
52 56
 
53 57
     Tools::createDir($sitePath . $type->type_dir . date('Y-m-d') . '/');
54 58
 
@@ -84,12 +88,14 @@  discard block
 block discarded – undo
84 88
     $sitePath = App::$primary->path;
85 89
 
86 90
     $fileinfo = pathinfo($url);
87
-    if (empty($fileinfo['extension']))
88
-      return 0;
91
+    if (empty($fileinfo['extension'])) {
92
+          return 0;
93
+    }
89 94
 
90 95
     $type = Files\Type::get($fileinfo['extension'], 'ext');
91
-    if (!$type)
92
-      return 0;
96
+    if (!$type) {
97
+          return 0;
98
+    }
93 99
 
94 100
     if (!empty($options['accept_group']) && $options['accept_group'] != $type->group) {
95 101
       return 0;
@@ -105,8 +111,9 @@  discard block
 block discarded – undo
105 111
     }
106 112
     $fileObject->name = $fileinfo['filename'];
107 113
     $fileObject->path = $type->type_dir . date('Y-m-d') . '/' . microtime(true) . '.' . $fileinfo['extension'];
108
-    if ($fileObject->id && file_exists($sitePath . $fileObject->path))
109
-      unlink($sitePath . $fileObject->path);
114
+    if ($fileObject->id && file_exists($sitePath . $fileObject->path)) {
115
+          unlink($sitePath . $fileObject->path);
116
+    }
110 117
 
111 118
     Tools::createDir($sitePath . $type->type_dir . date('Y-m-d') . '/');
112 119
 
Please login to merge, or discard this patch.