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