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