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