@@ -13,13 +13,13 @@ |
||
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 | } |
@@ -10,58 +10,58 @@ discard block |
||
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 |
||
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 |
||
132 | 132 | $fileObject->save(); |
133 | 133 | |
134 | 134 | return $fileObject->id; |
135 | - } |
|
135 | + } |
|
136 | 136 | |
137 | 137 | } |
@@ -13,30 +13,30 @@ discard block |
||
13 | 13 | |
14 | 14 | class Mysql extends \Object { |
15 | 15 | |
16 | - public $config = []; // настройки подключения выбраной базы |
|
17 | - public $connect = FALSE; // ярлык соединения с MySQL |
|
18 | - public $encoding = 'utf-8'; // установленная кодировка |
|
19 | - public $db_name = 'test'; // выбраная в данный момент база |
|
20 | - public $table_prefix = 'inji_'; // префикс названий таблиц |
|
21 | - public $pdo = NULL; |
|
22 | - public $lastQuery = ''; |
|
23 | - public $last_error = ''; |
|
24 | - public $noConnectAbort = false; |
|
25 | - public $dbInstance = null; |
|
16 | + public $config = []; // настройки подключения выбраной базы |
|
17 | + public $connect = FALSE; // ярлык соединения с MySQL |
|
18 | + public $encoding = 'utf-8'; // установленная кодировка |
|
19 | + public $db_name = 'test'; // выбраная в данный момент база |
|
20 | + public $table_prefix = 'inji_'; // префикс названий таблиц |
|
21 | + public $pdo = NULL; |
|
22 | + public $lastQuery = ''; |
|
23 | + public $last_error = ''; |
|
24 | + public $noConnectAbort = false; |
|
25 | + public $dbInstance = null; |
|
26 | 26 | |
27 | - /** |
|
28 | - * Подключение к MySQL |
|
29 | - */ |
|
30 | - public function init($connect_options) { |
|
27 | + /** |
|
28 | + * Подключение к MySQL |
|
29 | + */ |
|
30 | + public function init($connect_options) { |
|
31 | 31 | extract($connect_options); |
32 | 32 | if (isset($db_name)) |
33 | - $this->db_name = $db_name; |
|
33 | + $this->db_name = $db_name; |
|
34 | 34 | if (isset($encoding)) |
35 | - $this->encoding = $encoding; |
|
35 | + $this->encoding = $encoding; |
|
36 | 36 | if (isset($table_prefix)) |
37 | - $this->table_prefix = $table_prefix; |
|
37 | + $this->table_prefix = $table_prefix; |
|
38 | 38 | if (isset($noConnectAbort)) |
39 | - $this->noConnectAbort = $noConnectAbort; |
|
39 | + $this->noConnectAbort = $noConnectAbort; |
|
40 | 40 | |
41 | 41 | $dsn = "mysql:host=$host;port=$port;dbname=$db_name;charset=$encoding"; |
42 | 42 | $dt = new \DateTime(); |
@@ -50,21 +50,21 @@ discard block |
||
50 | 50 | $this->pdo = new \PDO($dsn, $user, $pass, $opt); |
51 | 51 | $error = $this->pdo->errorInfo(); |
52 | 52 | if ((int) $error[0]) { |
53 | - if ($this->noConnectAbort) { |
|
53 | + if ($this->noConnectAbort) { |
|
54 | 54 | return false; |
55 | - } else { |
|
55 | + } else { |
|
56 | 56 | INJI_SYSTEM_ERROR($error[2], true); |
57 | - } |
|
57 | + } |
|
58 | 58 | } else { |
59 | - $this->connect = true; |
|
60 | - $query = new Mysql\Query($this); |
|
61 | - $query->query("SET SQL_BIG_SELECTS=1"); |
|
62 | - $query->query("SET SESSION sql_mode = 'NO_ENGINE_SUBSTITUTION'"); |
|
63 | - return true; |
|
59 | + $this->connect = true; |
|
60 | + $query = new Mysql\Query($this); |
|
61 | + $query->query("SET SQL_BIG_SELECTS=1"); |
|
62 | + $query->query("SET SESSION sql_mode = 'NO_ENGINE_SUBSTITUTION'"); |
|
63 | + return true; |
|
64 | + } |
|
64 | 65 | } |
65 | - } |
|
66 | 66 | |
67 | - public function getTableCols($table_name) { |
|
67 | + public function getTableCols($table_name) { |
|
68 | 68 | $query = new Mysql\Query($this); |
69 | 69 | $old_db = $this->db_name; |
70 | 70 | $old_prefix = $this->table_prefix; |
@@ -77,35 +77,35 @@ discard block |
||
77 | 77 | $this->db_name = $old_db; |
78 | 78 | $this->table_prefix = $old_prefix; |
79 | 79 | return $result->getArray('COLUMN_NAME'); |
80 | - } |
|
80 | + } |
|
81 | 81 | |
82 | - public function tableExist($tableName) { |
|
82 | + public function tableExist($tableName) { |
|
83 | 83 | $query = new Mysql\Query($this); |
84 | 84 | return (bool) $query->query("SHOW TABLES FROM `{$this->db_name}` LIKE '{$this->table_prefix}{$tableName}'")->getArray(); |
85 | - } |
|
85 | + } |
|
86 | 86 | |
87 | - public function addCol($table = false, $name = false, $param = 'TEXT NOT NULL') { |
|
87 | + public function addCol($table = false, $name = false, $param = 'TEXT NOT NULL') { |
|
88 | 88 | if (!$table || !$name) { |
89 | - return false; |
|
89 | + return false; |
|
90 | 90 | } |
91 | 91 | if ($param == 'pk') { |
92 | - $param = "int(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`{$name}`)"; |
|
92 | + $param = "int(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`{$name}`)"; |
|
93 | 93 | } |
94 | 94 | $query = new Mysql\Query($this); |
95 | 95 | return $query->query("ALTER TABLE `{$this->db_name}`.`{$this->table_prefix}{$table}` ADD `{$name}` {$param}"); |
96 | - } |
|
96 | + } |
|
97 | 97 | |
98 | - public function delCol($table = false, $name = false) { |
|
98 | + public function delCol($table = false, $name = false) { |
|
99 | 99 | if (!$table || !$name) { |
100 | - return false; |
|
100 | + return false; |
|
101 | 101 | } |
102 | 102 | $query = new Mysql\Query($this); |
103 | 103 | return $query->query("ALTER TABLE `{$this->db_name}`.`{$this->table_prefix}{$table}` DROP `{$name}`"); |
104 | - } |
|
104 | + } |
|
105 | 105 | |
106 | - public function getTables() { |
|
106 | + public function getTables() { |
|
107 | 107 | $query = new Mysql\Query($this); |
108 | 108 | return $query->query("SHOW TABLES")->getArray(); |
109 | - } |
|
109 | + } |
|
110 | 110 | |
111 | 111 | } |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | ], '', true); |
11 | 11 | $buttons = $dataManager->getButtons($params, $model); |
12 | 12 | if ($buttons) { |
13 | - ?> |
|
13 | + ?> |
|
14 | 14 | <h3 class="dataManager-title"><?= $dataManager->name; ?> |
15 | 15 | <div class ='pull-right dataManager-managerButtons'> |
16 | 16 | <div class="btn-group"> |
@@ -26,13 +26,13 @@ discard block |
||
26 | 26 | 'style' => '' |
27 | 27 | ]; |
28 | 28 | if (!empty($dataManager->managerOptions['categorys'])) { |
29 | - $mainCol['style'].='margin-left:260px;'; |
|
30 | - echo '<div class ="pull-left dataManager-categorys" style = "width:250px;">'; |
|
31 | - $this->widget('Ui\DataManager/categorys', compact('dataManager')); |
|
32 | - echo '</div>'; |
|
29 | + $mainCol['style'].='margin-left:260px;'; |
|
30 | + echo '<div class ="pull-left dataManager-categorys" style = "width:250px;">'; |
|
31 | + $this->widget('Ui\DataManager/categorys', compact('dataManager')); |
|
32 | + echo '</div>'; |
|
33 | 33 | } |
34 | 34 | if (!empty($dataManager->managerOptions['filters'])) { |
35 | - ?> |
|
35 | + ?> |
|
36 | 36 | <div class="modal fade" id = "<?= $dataManager->managerId; ?>_filters" > |
37 | 37 | <div class="modal-dialog modal-lg"> |
38 | 38 | <div class="modal-content"> |
@@ -46,7 +46,7 @@ discard block |
||
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 |
||
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 |
@@ -13,99 +13,99 @@ discard block |
||
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 |
||
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 | } |
@@ -13,413 +13,413 @@ discard block |
||
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 |
||
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 | } |
@@ -9,16 +9,16 @@ |
||
9 | 9 | 'value' => !empty($options['value']) ? addcslashes($options['value'], "'") : (!empty($form->userDataTree[$name]) ? addcslashes($form->userDataTree[$name], "'") : '') |
10 | 10 | ]; |
11 | 11 | if (!empty($options['disabled'])) { |
12 | - $attributes['disabled'] = 'disabled'; |
|
12 | + $attributes['disabled'] = 'disabled'; |
|
13 | 13 | } |
14 | 14 | if (!empty($options['placeholder'])) { |
15 | - $attributes['placeholder'] = $options['placeholder']; |
|
15 | + $attributes['placeholder'] = $options['placeholder']; |
|
16 | 16 | } |
17 | 17 | if (!empty($options['checked'])) { |
18 | - $attributes['checked'] = 'checked'; |
|
18 | + $attributes['checked'] = 'checked'; |
|
19 | 19 | } |
20 | 20 | if (!empty($options['attributes'])) { |
21 | - $attributes = array_merge($attributes, $options['attributes']); |
|
21 | + $attributes = array_merge($attributes, $options['attributes']); |
|
22 | 22 | } |
23 | 23 | echo Html::el('input', $attributes, '', null); |
24 | 24 | echo!empty($options['helpText']) ? "<div class='help-block'>{$options['helpText']}</div>" : ''; |
@@ -6,10 +6,10 @@ discard block |
||
6 | 6 | <?= $label; ?> |
7 | 7 | </h3> |
8 | 8 | <?php |
9 | - if ($options['source'] == 'relation' && empty($options['modelPk'])) { |
|
9 | + if ($options['source'] == 'relation' && empty($options['modelPk'])) { |
|
10 | 10 | echo '<h4 class=" text-muted">Чтобы добавить связи, сначала создайте объект</h4>'; |
11 | 11 | echo '<p class=" text-muted">Просто заполните доступные поля и нажмите кнопку внизу формы. После этого дополнительные поля разблокируются</p>'; |
12 | - } else { |
|
12 | + } else { |
|
13 | 13 | ?> |
14 | 14 | <div class="table-responsive"> |
15 | 15 | <table class ='table table-striped'> |
@@ -17,18 +17,18 @@ discard block |
||
17 | 17 | <tr> |
18 | 18 | <?php |
19 | 19 | foreach ($options['cols'] as $colName => $col) { |
20 | - if (!empty($col['hidden'])) { |
|
20 | + if (!empty($col['hidden'])) { |
|
21 | 21 | continue; |
22 | - } |
|
23 | - echo "<th>"; |
|
24 | - echo $col['col']['label']; |
|
25 | - if (!empty($col['col']['model'])) { |
|
22 | + } |
|
23 | + echo "<th>"; |
|
24 | + echo $col['col']['label']; |
|
25 | + if (!empty($col['col']['model'])) { |
|
26 | 26 | $modelName = $col['col']['model']; |
27 | 27 | $onclick = 'inji.Ui.forms.popUp(\'' . addslashes($modelName) . '\',{},function(elem){' |
28 | 28 | . 'return function(data,modal){inji.Ui.forms.submitAjax($(elem).closest(\'form\')[0], {notSave: true});}}(this));return false;'; |
29 | 29 | echo ' (<a href="" onclick="' . $onclick . ';this.disabled=true;return false;">Создать</a>)'; |
30 | - } |
|
31 | - echo "</th>"; |
|
30 | + } |
|
31 | + echo "</th>"; |
|
32 | 32 | } |
33 | 33 | ?> |
34 | 34 | <td> </td> |
@@ -36,14 +36,14 @@ discard block |
||
36 | 36 | </thead> |
37 | 37 | <tbody class="listBody"> |
38 | 38 | <?php |
39 | - $i = 0; |
|
40 | - if (!empty($options['values'])) { |
|
39 | + $i = 0; |
|
40 | + if (!empty($options['values'])) { |
|
41 | 41 | foreach ($options['values'] as $row) { |
42 | - echo '<tr>'; |
|
43 | - foreach ($options['cols'] as $colName => $col) { |
|
42 | + echo '<tr>'; |
|
43 | + foreach ($options['cols'] as $colName => $col) { |
|
44 | 44 | $input = clone $col['input']; |
45 | 45 | if (empty($col['hidden'])) { |
46 | - echo '<td>'; |
|
46 | + echo '<td>'; |
|
47 | 47 | } |
48 | 48 | $input->options['noContainer'] = true; |
49 | 49 | $input->colParams['label'] = false; |
@@ -51,24 +51,24 @@ discard block |
||
51 | 51 | $input->colName .= '[' . $colName . '][' . ($i) . ']'; |
52 | 52 | $input->draw(); |
53 | 53 | if (empty($col['hidden'])) { |
54 | - echo '</td>'; |
|
54 | + echo '</td>'; |
|
55 | + } |
|
55 | 56 | } |
56 | - } |
|
57 | - $i++; |
|
58 | - echo '<td class="actionTd"><a class="btn btn-danger btn-xs" onclick="inji.Ui.forms.delRowFromList(this);"><i class="glyphicon glyphicon-remove"></i></a></td>'; |
|
59 | - echo '</tr>'; |
|
57 | + $i++; |
|
58 | + echo '<td class="actionTd"><a class="btn btn-danger btn-xs" onclick="inji.Ui.forms.delRowFromList(this);"><i class="glyphicon glyphicon-remove"></i></a></td>'; |
|
59 | + echo '</tr>'; |
|
60 | 60 | } |
61 | - } |
|
62 | - ?> |
|
61 | + } |
|
62 | + ?> |
|
63 | 63 | </tbody> |
64 | 64 | <tfoot> |
65 | 65 | <tr> |
66 | 66 | <?php |
67 | 67 | foreach ($options['cols'] as $colName => $col) { |
68 | - if (!empty($col['hidden'])) { |
|
68 | + if (!empty($col['hidden'])) { |
|
69 | 69 | continue; |
70 | - } |
|
71 | - echo "<th>{$col['col']['label']}</th>"; |
|
70 | + } |
|
71 | + echo "<th>{$col['col']['label']}</th>"; |
|
72 | 72 | } |
73 | 73 | ?> |
74 | 74 | <td> </td> |
@@ -81,26 +81,26 @@ discard block |
||
81 | 81 | <script>/* |
82 | 82 | <tr> |
83 | 83 | <?php |
84 | - foreach ($options['cols'] as $colName => $col) { |
|
84 | + foreach ($options['cols'] as $colName => $col) { |
|
85 | 85 | if (empty($col['hidden'])) { |
86 | - echo '<td>'; |
|
86 | + echo '<td>'; |
|
87 | 87 | } |
88 | 88 | $col['input']->options['noContainer'] = true; |
89 | 89 | $col['input']->colParams['label'] = false; |
90 | 90 | $col['input']->colName.="[{$colName}][]"; |
91 | 91 | $col['input']->draw(); |
92 | 92 | if (empty($col['hidden'])) { |
93 | - echo '</td>'; |
|
93 | + echo '</td>'; |
|
94 | + } |
|
94 | 95 | } |
95 | - } |
|
96 | - ?> |
|
96 | + ?> |
|
97 | 97 | <td class="actionTd"><a class="btn btn-danger btn-xs" onclick="inji.Ui.forms.delRowFromList(this);"><i class="glyphicon glyphicon-remove"></i></a></td> |
98 | 98 | </tr> |
99 | 99 | */</script> |
100 | 100 | </div> |
101 | 101 | <?php |
102 | - } |
|
103 | - ?> |
|
102 | + } |
|
103 | + ?> |
|
104 | 104 | </div> |
105 | 105 | <?php |
106 | 106 | //exit(); |