@@ -13,75 +13,75 @@ |
||
13 | 13 | |
14 | 14 | class Options extends \Migrations\Parser { |
15 | 15 | |
16 | - static $options; |
|
16 | + static $options; |
|
17 | 17 | |
18 | - public function parse() { |
|
18 | + public function parse() { |
|
19 | 19 | if (!Options::$options) { |
20 | - Options::$options = \Ecommerce\Item\Option::getList(); |
|
20 | + Options::$options = \Ecommerce\Item\Option::getList(); |
|
21 | 21 | } |
22 | 22 | $options = []; |
23 | 23 | $modelName = 'Ecommerce\Item\Option'; |
24 | 24 | foreach ($this->data['ЗначенияСвойства'] as $opt) { |
25 | - $optionId = \App::$cur->migrations->ids['parseIds']['Ecommerce\Item\Option'][$opt['Ид']]->object_id; |
|
26 | - if ($optionId && !isset(Options::$options[$optionId])) { |
|
25 | + $optionId = \App::$cur->migrations->ids['parseIds']['Ecommerce\Item\Option'][$opt['Ид']]->object_id; |
|
26 | + if ($optionId && !isset(Options::$options[$optionId])) { |
|
27 | 27 | Options::$options = \Ecommerce\Item\Option::getList(); |
28 | - } |
|
29 | - if (isset(Options::$options[$optionId]) && Options::$options[$optionId]->type == 'select') { |
|
28 | + } |
|
29 | + if (isset(Options::$options[$optionId]) && Options::$options[$optionId]->type == 'select') { |
|
30 | 30 | if (empty($options[$optionId])) { |
31 | - $options[$optionId] = []; |
|
31 | + $options[$optionId] = []; |
|
32 | 32 | } else { |
33 | - if (!Options::$options[$optionId]->advance) { |
|
33 | + if (!Options::$options[$optionId]->advance) { |
|
34 | 34 | Options::$options[$optionId]->advance = ['multi' => true]; |
35 | 35 | Options::$options[$optionId]->save(); |
36 | - } |
|
36 | + } |
|
37 | 37 | } |
38 | 38 | if ($opt['Значение'] && isset(\App::$cur->migrations->ids['parseIds']['Ecommerce\Item\Option\Item'][$opt['Значение']])) { |
39 | - $options[$optionId][] = \App::$cur->migrations->ids['parseIds']['Ecommerce\Item\Option\Item'][$opt['Значение']]->object_id; |
|
39 | + $options[$optionId][] = \App::$cur->migrations->ids['parseIds']['Ecommerce\Item\Option\Item'][$opt['Значение']]->object_id; |
|
40 | 40 | } |
41 | - } else { |
|
41 | + } else { |
|
42 | 42 | $options[$optionId] = $opt['Значение']; |
43 | - } |
|
43 | + } |
|
44 | 44 | } |
45 | 45 | $itemParams = \Ecommerce\Item\Param::getList(['where' => ['item_id', $this->model->id]]); |
46 | 46 | foreach ($itemParams as $itemParam) { |
47 | - if ($itemParam->item_option_id && !isset(Options::$options[$itemParam->item_option_id])) { |
|
47 | + if ($itemParam->item_option_id && !isset(Options::$options[$itemParam->item_option_id])) { |
|
48 | 48 | Options::$options = \Ecommerce\Item\Option::getList(); |
49 | - } |
|
50 | - if (isset(Options::$options[$itemParam->item_option_id]) && Options::$options[$itemParam->item_option_id]->type == 'select') { |
|
49 | + } |
|
50 | + if (isset(Options::$options[$itemParam->item_option_id]) && Options::$options[$itemParam->item_option_id]->type == 'select') { |
|
51 | 51 | if (empty($options[$itemParam->item_option_id]) || !in_array($itemParam->value, $options[$itemParam->item_option_id])) { |
52 | - $itemParam->delete(); |
|
52 | + $itemParam->delete(); |
|
53 | 53 | } else { |
54 | - unset($options[$itemParam->item_option_id][array_search($itemParam->value, $options[$itemParam->item_option_id])]); |
|
54 | + unset($options[$itemParam->item_option_id][array_search($itemParam->value, $options[$itemParam->item_option_id])]); |
|
55 | 55 | } |
56 | - } else { |
|
56 | + } else { |
|
57 | 57 | if (empty($options[$itemParam->item_option_id])) { |
58 | - $itemParam->delete(); |
|
58 | + $itemParam->delete(); |
|
59 | 59 | } else { |
60 | - $itemParam->value = $options[$itemParam->item_option_id]; |
|
61 | - $itemParam->save(); |
|
62 | - unset($options[$itemParam->item_option_id]); |
|
60 | + $itemParam->value = $options[$itemParam->item_option_id]; |
|
61 | + $itemParam->save(); |
|
62 | + unset($options[$itemParam->item_option_id]); |
|
63 | + } |
|
63 | 64 | } |
64 | - } |
|
65 | 65 | } |
66 | 66 | foreach ($options as $optionId => $values) { |
67 | - if (is_array($values)) { |
|
67 | + if (is_array($values)) { |
|
68 | 68 | foreach ($values as $value) { |
69 | - $itemParam = new \Ecommerce\Item\Param([ |
|
70 | - 'item_option_id' => $optionId, |
|
71 | - 'item_id' => $this->model->id, |
|
72 | - 'value' => $value |
|
73 | - ]); |
|
74 | - $itemParam->save(); |
|
69 | + $itemParam = new \Ecommerce\Item\Param([ |
|
70 | + 'item_option_id' => $optionId, |
|
71 | + 'item_id' => $this->model->id, |
|
72 | + 'value' => $value |
|
73 | + ]); |
|
74 | + $itemParam->save(); |
|
75 | 75 | } |
76 | - } else { |
|
76 | + } else { |
|
77 | 77 | $itemParam = new \Ecommerce\Item\Param([ |
78 | 78 | 'item_option_id' => $optionId, |
79 | 79 | 'item_id' => $this->model->id, |
80 | 80 | 'value' => $values |
81 | 81 | ]); |
82 | 82 | $itemParam->save(); |
83 | - } |
|
83 | + } |
|
84 | + } |
|
84 | 85 | } |
85 | - } |
|
86 | 86 | |
87 | 87 | } |
@@ -13,11 +13,11 @@ 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_'; // префикс названий таблиц |
|
16 | + public $config = []; // настройки подключения выбраной базы |
|
17 | + public $connect = FALSE; // ярлык соединения с MySQL |
|
18 | + public $encoding = 'utf-8'; // установленная кодировка |
|
19 | + public $db_name = 'test'; // выбраная в данный момент база |
|
20 | + public $table_prefix = 'inji_'; // префикс названий таблиц |
|
21 | 21 | public $pdo = NULL; |
22 | 22 | public $lastQuery = ''; |
23 | 23 | public $last_error = ''; |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | $this->table_prefix = ''; |
72 | 72 | |
73 | 73 | $query->where('TABLE_SCHEMA', $old_db); |
74 | - $query->where('TABLE_NAME', $old_prefix . $table_name); |
|
74 | + $query->where('TABLE_NAME', $old_prefix.$table_name); |
|
75 | 75 | $result = $query->select('COLUMNS'); |
76 | 76 | $this->db_name = $old_db; |
77 | 77 | $this->table_prefix = $old_prefix; |
@@ -29,14 +29,18 @@ |
||
29 | 29 | */ |
30 | 30 | public function init($connect_options) { |
31 | 31 | extract($connect_options); |
32 | - if (isset($db_name)) |
|
33 | - $this->db_name = $db_name; |
|
34 | - if (isset($encoding)) |
|
35 | - $this->encoding = $encoding; |
|
36 | - if (isset($table_prefix)) |
|
37 | - $this->table_prefix = $table_prefix; |
|
38 | - if (isset($noConnectAbort)) |
|
39 | - $this->noConnectAbort = $noConnectAbort; |
|
32 | + if (isset($db_name)) { |
|
33 | + $this->db_name = $db_name; |
|
34 | + } |
|
35 | + if (isset($encoding)) { |
|
36 | + $this->encoding = $encoding; |
|
37 | + } |
|
38 | + if (isset($table_prefix)) { |
|
39 | + $this->table_prefix = $table_prefix; |
|
40 | + } |
|
41 | + if (isset($noConnectAbort)) { |
|
42 | + $this->noConnectAbort = $noConnectAbort; |
|
43 | + } |
|
40 | 44 | |
41 | 45 | $dsn = "mysql:host=$host;port=$port;dbname=$db_name;charset=$encoding"; |
42 | 46 | $dt = new \DateTime(); |
@@ -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 | } |
@@ -12,10 +12,10 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class Migrations extends \Module { |
14 | 14 | |
15 | - public $ids = []; |
|
16 | - public $migrationObjects = []; |
|
15 | + public $ids = []; |
|
16 | + public $migrationObjects = []; |
|
17 | 17 | |
18 | - public function startMigration($migrationId, $mapId, $filePath) { |
|
18 | + public function startMigration($migrationId, $mapId, $filePath) { |
|
19 | 19 | $log = new \Migrations\Log(); |
20 | 20 | $log->migration_id = $migrationId; |
21 | 21 | $log->migration_map_id = $mapId; |
@@ -24,11 +24,11 @@ discard block |
||
24 | 24 | |
25 | 25 | $reader = new Migrations\Reader\Xml(); |
26 | 26 | if (!$reader->loadData($filePath)) { |
27 | - $event = new Migrations\Log\Event(); |
|
28 | - $event->log_id = $log->id; |
|
29 | - $event->type = 'load_data_error'; |
|
30 | - $event->save(); |
|
31 | - return false; |
|
27 | + $event = new Migrations\Log\Event(); |
|
28 | + $event->log_id = $log->id; |
|
29 | + $event->type = 'load_data_error'; |
|
30 | + $event->save(); |
|
31 | + return false; |
|
32 | 32 | } |
33 | 33 | $walker = new \Migrations\Walker(); |
34 | 34 | $walker->migration = Migrations\Migration::get($migrationId); |
@@ -38,43 +38,43 @@ discard block |
||
38 | 38 | $walker->walk(); |
39 | 39 | $log->result = 'success'; |
40 | 40 | $log->save(); |
41 | - } |
|
41 | + } |
|
42 | 42 | |
43 | - public function loadParseIds($type) { |
|
43 | + public function loadParseIds($type) { |
|
44 | 44 | $this->ids['parseIds'][$type] = \Migrations\Id::getList(['where' => ['type', $type], 'key' => 'parse_id']); |
45 | - } |
|
45 | + } |
|
46 | 46 | |
47 | - public function loadObjectIds($type) { |
|
47 | + public function loadObjectIds($type) { |
|
48 | 48 | $this->ids['objectIds'][$type] = \Migrations\Id::getList(['where' => ['type', $type], 'key' => 'object_id']); |
49 | - } |
|
49 | + } |
|
50 | 50 | |
51 | - public function findObject($parseId, $type) { |
|
51 | + public function findObject($parseId, $type) { |
|
52 | 52 | if (empty($this->ids['parseIds'][$type])) { |
53 | - $this->loadParseIds($type); |
|
54 | - ksort($this->ids['parseIds'][$type]); |
|
53 | + $this->loadParseIds($type); |
|
54 | + ksort($this->ids['parseIds'][$type]); |
|
55 | 55 | } |
56 | 56 | if (!empty($this->ids['parseIds'][$type][$parseId])) { |
57 | - return $this->ids['parseIds'][$type][$parseId]; |
|
57 | + return $this->ids['parseIds'][$type][$parseId]; |
|
58 | + } |
|
58 | 59 | } |
59 | - } |
|
60 | 60 | |
61 | - public function findParse($objectId, $type) { |
|
61 | + public function findParse($objectId, $type) { |
|
62 | 62 | if (empty($this->ids['objectIds'][$type])) { |
63 | - $this->loadObjectIds($type); |
|
64 | - ksort($this->ids['objectIds'][$type]); |
|
63 | + $this->loadObjectIds($type); |
|
64 | + ksort($this->ids['objectIds'][$type]); |
|
65 | 65 | } |
66 | 66 | if (!empty($this->ids['objectIds'][$type][$objectId])) { |
67 | - return $this->ids['objectIds'][$type][$objectId]; |
|
67 | + return $this->ids['objectIds'][$type][$objectId]; |
|
68 | + } |
|
68 | 69 | } |
69 | - } |
|
70 | 70 | |
71 | - public function getMigrationObject($objectId) { |
|
71 | + public function getMigrationObject($objectId) { |
|
72 | 72 | if (empty($this->migrationObjects)) { |
73 | - $this->migrationObjects = \Migrations\Migration\Object::getList(); |
|
73 | + $this->migrationObjects = \Migrations\Migration\Object::getList(); |
|
74 | 74 | } |
75 | 75 | if (!empty($this->migrationObjects[$objectId])) { |
76 | - return $this->migrationObjects[$objectId]; |
|
76 | + return $this->migrationObjects[$objectId]; |
|
77 | + } |
|
77 | 78 | } |
78 | - } |
|
79 | 79 | |
80 | 80 | } |
@@ -396,6 +396,9 @@ |
||
396 | 396 | return $rows; |
397 | 397 | } |
398 | 398 | |
399 | + /** |
|
400 | + * @param DataManager $dataManager |
|
401 | + */ |
|
399 | 402 | public static function drawCol($item, $colName, $params = [], $dataManager = null, $originalCol = '', $originalItem = null) { |
400 | 403 | $modelName = get_class($item); |
401 | 404 | if (!class_exists($modelName)) { |
@@ -12,61 +12,61 @@ discard block |
||
12 | 12 | |
13 | 13 | class DataManager extends \Object { |
14 | 14 | |
15 | - public $modelName = ''; |
|
16 | - public $managerOptions = []; |
|
17 | - public $managerName = 'customManager'; |
|
18 | - public $name = 'Менеджер данных'; |
|
19 | - public $limit = 30; |
|
20 | - public $page = 1; |
|
21 | - public $table = null; |
|
22 | - public $joins = []; |
|
23 | - public $predraw = false; |
|
24 | - public $cols = []; |
|
25 | - public $managerId = ''; |
|
26 | - |
|
27 | - /** |
|
28 | - * Construct new data manager |
|
29 | - * |
|
30 | - * @param string|array $modelNameOrOptions |
|
31 | - * @param string $managerName |
|
32 | - * @throws Exception |
|
33 | - */ |
|
34 | - public function __construct($modelNameOrOptions, $managerName = 'manager') { |
|
15 | + public $modelName = ''; |
|
16 | + public $managerOptions = []; |
|
17 | + public $managerName = 'customManager'; |
|
18 | + public $name = 'Менеджер данных'; |
|
19 | + public $limit = 30; |
|
20 | + public $page = 1; |
|
21 | + public $table = null; |
|
22 | + public $joins = []; |
|
23 | + public $predraw = false; |
|
24 | + public $cols = []; |
|
25 | + public $managerId = ''; |
|
26 | + |
|
27 | + /** |
|
28 | + * Construct new data manager |
|
29 | + * |
|
30 | + * @param string|array $modelNameOrOptions |
|
31 | + * @param string $managerName |
|
32 | + * @throws Exception |
|
33 | + */ |
|
34 | + public function __construct($modelNameOrOptions, $managerName = 'manager') { |
|
35 | 35 | $this->managerName = $managerName; |
36 | 36 | |
37 | 37 | if (!is_array($modelNameOrOptions)) { |
38 | - if (!class_exists($modelNameOrOptions)) { |
|
38 | + if (!class_exists($modelNameOrOptions)) { |
|
39 | 39 | throw new \Exception("model {$modelNameOrOptions} not exists"); |
40 | - } |
|
41 | - $this->modelName = $modelNameOrOptions; |
|
42 | - $this->managerOptions = !empty($modelNameOrOptions::$dataManagers[$managerName]) ? $modelNameOrOptions::$dataManagers[$managerName] : []; |
|
43 | - if (isset($modelNameOrOptions::$objectName)) { |
|
40 | + } |
|
41 | + $this->modelName = $modelNameOrOptions; |
|
42 | + $this->managerOptions = !empty($modelNameOrOptions::$dataManagers[$managerName]) ? $modelNameOrOptions::$dataManagers[$managerName] : []; |
|
43 | + if (isset($modelNameOrOptions::$objectName)) { |
|
44 | 44 | $this->name = $modelNameOrOptions::$objectName; |
45 | - } else { |
|
45 | + } else { |
|
46 | 46 | $this->name = $modelNameOrOptions; |
47 | - } |
|
47 | + } |
|
48 | 48 | } else { |
49 | - $this->managerOptions = $modelNameOrOptions; |
|
49 | + $this->managerOptions = $modelNameOrOptions; |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | if (!$this->managerOptions || !is_array($this->managerOptions)) { |
53 | - throw new \Exception('empty DataManager'); |
|
53 | + throw new \Exception('empty DataManager'); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | if (!empty($this->managerOptions['name'])) { |
57 | - $this->name = $this->managerOptions['name']; |
|
57 | + $this->name = $this->managerOptions['name']; |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | $this->managerId = str_replace('\\', '_', 'dataManager_' . $this->modelName . '_' . $this->managerName . '_' . \Tools::randomString()); |
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Get buttons for manager |
|
65 | - * |
|
66 | - * @param string $params |
|
67 | - * @param object $model |
|
68 | - */ |
|
69 | - public function getButtons($params = [], $model = null) { |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Get buttons for manager |
|
65 | + * |
|
66 | + * @param string $params |
|
67 | + * @param object $model |
|
68 | + */ |
|
69 | + public function getButtons($params = [], $model = null) { |
|
70 | 70 | $modelName = $this->modelName; |
71 | 71 | |
72 | 72 | |
@@ -76,102 +76,102 @@ discard block |
||
76 | 76 | 'formName' => !empty($this->managerOptions['editForm']) ? $this->managerOptions['editForm'] : 'manager' |
77 | 77 | ]; |
78 | 78 | if ($model) { |
79 | - $formModelName = get_class($model); |
|
80 | - $relations = $formModelName::relations(); |
|
81 | - $type = !empty($relations[$params['relation']]['type']) ? $relations[$params['relation']]['type'] : 'to'; |
|
82 | - switch ($type) { |
|
79 | + $formModelName = get_class($model); |
|
80 | + $relations = $formModelName::relations(); |
|
81 | + $type = !empty($relations[$params['relation']]['type']) ? $relations[$params['relation']]['type'] : 'to'; |
|
82 | + switch ($type) { |
|
83 | 83 | case 'relModel': |
84 | 84 | $formParams['preset'] = [ |
85 | - $formModelName::index() => $model->pk() |
|
86 | - ]; |
|
87 | - break; |
|
85 | + $formModelName::index() => $model->pk() |
|
86 | + ]; |
|
87 | + break; |
|
88 | 88 | default: |
89 | 89 | $formParams['preset'] = [ |
90 | - $relations[$params['relation']]['col'] => $model->pk() |
|
91 | - ]; |
|
92 | - } |
|
90 | + $relations[$params['relation']]['col'] => $model->pk() |
|
91 | + ]; |
|
92 | + } |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | $buttons = []; |
96 | 96 | if (!empty($this->managerOptions['sortMode'])) { |
97 | - $buttons[] = [ |
|
98 | - 'class' => 'modeBtn', |
|
99 | - 'data-mode' => 'sort', |
|
100 | - 'text' => 'Сортировать', |
|
101 | - ]; |
|
97 | + $buttons[] = [ |
|
98 | + 'class' => 'modeBtn', |
|
99 | + 'data-mode' => 'sort', |
|
100 | + 'text' => 'Сортировать', |
|
101 | + ]; |
|
102 | 102 | } |
103 | 103 | if (!empty($this->managerOptions['filters'])) { |
104 | - $buttons[] = [ |
|
105 | - 'text' => 'Фильтры', |
|
106 | - 'onclick' => ' var modal = $("#' . $this->managerId . '_filters"); |
|
104 | + $buttons[] = [ |
|
105 | + 'text' => 'Фильтры', |
|
106 | + 'onclick' => ' var modal = $("#' . $this->managerId . '_filters"); |
|
107 | 107 | modal.modal("show");', |
108 | - ]; |
|
108 | + ]; |
|
109 | 109 | } |
110 | 110 | if (!empty($modelName::$forms['simpleItem'])) { |
111 | - $formParams['formName'] = 'simpleItem'; |
|
112 | - $buttons[] = [ |
|
113 | - 'text' => '<i class = "glyphicon glyphicon-send"></i> Быстрое создание', |
|
114 | - 'onclick' => 'inji.Ui.dataManagers.get(this).newItem("' . str_replace('\\', '\\\\', $modelName) . '",' . json_encode($formParams) . ');', |
|
115 | - ]; |
|
111 | + $formParams['formName'] = 'simpleItem'; |
|
112 | + $buttons[] = [ |
|
113 | + 'text' => '<i class = "glyphicon glyphicon-send"></i> Быстрое создание', |
|
114 | + 'onclick' => 'inji.Ui.dataManagers.get(this).newItem("' . str_replace('\\', '\\\\', $modelName) . '",' . json_encode($formParams) . ');', |
|
115 | + ]; |
|
116 | 116 | } |
117 | 117 | $formParams['formName'] = !empty($this->managerOptions['editForm']) ? $this->managerOptions['editForm'] : 'manager'; |
118 | 118 | $name = 'Элемент'; |
119 | 119 | if ($modelName::$objectName) { |
120 | - $name = $modelName::$objectName; |
|
120 | + $name = $modelName::$objectName; |
|
121 | 121 | } |
122 | 122 | if (!empty($modelName::$forms[$formParams['formName']])) { |
123 | - $aform = new ActiveForm(new $modelName, $formParams['formName']); |
|
124 | - if ($aform->checkAccess()) { |
|
123 | + $aform = new ActiveForm(new $modelName, $formParams['formName']); |
|
124 | + if ($aform->checkAccess()) { |
|
125 | 125 | $buttons[] = [ |
126 | 126 | 'text' => 'Создать ' . $name, |
127 | 127 | 'onclick' => 'inji.Ui.dataManagers.get(this).newItem("' . str_replace('\\', '\\\\', $modelName) . '",' . json_encode($formParams) . ');', |
128 | 128 | ]; |
129 | - } |
|
129 | + } |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | return $buttons; |
133 | - } |
|
133 | + } |
|
134 | 134 | |
135 | - function getActions($onlyGroupActions = false) { |
|
135 | + function getActions($onlyGroupActions = false) { |
|
136 | 136 | $actions = [ |
137 | 137 | 'Open' => ['className' => 'Open'], 'Edit' => ['className' => 'Edit'], 'Delete' => ['className' => 'Delete'] |
138 | 138 | ]; |
139 | 139 | if (isset($this->managerOptions['actions'])) { |
140 | - $actions = array_merge($actions, $this->managerOptions['actions']); |
|
140 | + $actions = array_merge($actions, $this->managerOptions['actions']); |
|
141 | 141 | } |
142 | 142 | $return = []; |
143 | 143 | foreach ($actions as $key => $action) { |
144 | - if ($action === false) { |
|
144 | + if ($action === false) { |
|
145 | 145 | continue; |
146 | - } |
|
147 | - if (is_array($action)) { |
|
146 | + } |
|
147 | + if (is_array($action)) { |
|
148 | 148 | if (!empty($action['access']['groups']) && !in_array(\Users\User::$cur->group_id, $action['access']['groups'])) { |
149 | - continue; |
|
149 | + continue; |
|
150 | 150 | } |
151 | 151 | if (empty($action['className'])) { |
152 | - $action['className'] = $key; |
|
152 | + $action['className'] = $key; |
|
153 | 153 | } |
154 | 154 | $return[$key] = $action; |
155 | - } else { |
|
155 | + } else { |
|
156 | 156 | $key = $action; |
157 | 157 | $return[$key] = [ |
158 | 158 | 'className' => $action |
159 | 159 | ]; |
160 | - } |
|
161 | - $return[$key]['className'] = strpos($return[$key]['className'], '\\') === false && class_exists('Ui\DataManager\Action\\' . $return[$key]['className']) ? 'Ui\DataManager\Action\\' . $return[$key]['className'] : $return[$key]['className']; |
|
162 | - if (!class_exists($return[$key]['className']) || ($onlyGroupActions && !$return[$key]['className']::$groupAction)) { |
|
160 | + } |
|
161 | + $return[$key]['className'] = strpos($return[$key]['className'], '\\') === false && class_exists('Ui\DataManager\Action\\' . $return[$key]['className']) ? 'Ui\DataManager\Action\\' . $return[$key]['className'] : $return[$key]['className']; |
|
162 | + if (!class_exists($return[$key]['className']) || ($onlyGroupActions && !$return[$key]['className']::$groupAction)) { |
|
163 | 163 | unset($return[$key]); |
164 | - } |
|
164 | + } |
|
165 | 165 | } |
166 | 166 | return $return; |
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * Get cols for manager |
|
171 | - * |
|
172 | - * @return string |
|
173 | - */ |
|
174 | - public function getCols() { |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * Get cols for manager |
|
171 | + * |
|
172 | + * @return string |
|
173 | + */ |
|
174 | + public function getCols() { |
|
175 | 175 | $actions = $this->getActions(); |
176 | 176 | ob_start(); |
177 | 177 | ?> |
@@ -187,12 +187,12 @@ discard block |
||
187 | 187 | <li><a href ='' onclick='inji.Ui.dataManagers.get(this).rowSelection("inverse");return false;'>Инвертировать</a></li> |
188 | 188 | <li role="separator" class="divider"></li> |
189 | 189 | <?php |
190 | - foreach ($actions as $action => $actionParams) { |
|
190 | + foreach ($actions as $action => $actionParams) { |
|
191 | 191 | if (class_exists($actionParams['className']) && $actionParams['className']::$groupAction) { |
192 | - echo "<li><a role='button' href ='#' onclick='inji.Ui.dataManagers.get(this).groupAction(\"" . str_replace('\\', '\\\\', $action) . "\");return false;'>{$actionParams['className']::$name}</a></li>"; |
|
192 | + echo "<li><a role='button' href ='#' onclick='inji.Ui.dataManagers.get(this).groupAction(\"" . str_replace('\\', '\\\\', $action) . "\");return false;'>{$actionParams['className']::$name}</a></li>"; |
|
193 | + } |
|
193 | 194 | } |
194 | - } |
|
195 | - ?> |
|
195 | + ?> |
|
196 | 196 | </ul> |
197 | 197 | </div> |
198 | 198 | <?php |
@@ -205,293 +205,293 @@ discard block |
||
205 | 205 | |
206 | 206 | $modelName = $this->modelName; |
207 | 207 | foreach ($this->managerOptions['cols'] as $key => $col) { |
208 | - if (is_array($col)) { |
|
208 | + if (is_array($col)) { |
|
209 | 209 | $colName = $key; |
210 | 210 | $colOptions = $col; |
211 | - } else { |
|
211 | + } else { |
|
212 | 212 | $colName = $col; |
213 | 213 | $colOptions = []; |
214 | - } |
|
215 | - $colInfo = []; |
|
216 | - if ($modelName) { |
|
214 | + } |
|
215 | + $colInfo = []; |
|
216 | + if ($modelName) { |
|
217 | 217 | $colInfo = $modelName::getColInfo($colName); |
218 | - } |
|
219 | - if (empty($colOptions['label']) && !empty($colInfo['label'])) { |
|
218 | + } |
|
219 | + if (empty($colOptions['label']) && !empty($colInfo['label'])) { |
|
220 | 220 | $colOptions['label'] = $colInfo['label']; |
221 | - } elseif (empty($colOptions['label'])) { |
|
221 | + } elseif (empty($colOptions['label'])) { |
|
222 | 222 | $colOptions['label'] = $colName; |
223 | - } |
|
224 | - $cols[$colName] = $colOptions; |
|
223 | + } |
|
224 | + $cols[$colName] = $colOptions; |
|
225 | 225 | } |
226 | 226 | return $cols; |
227 | - } |
|
228 | - |
|
229 | - /** |
|
230 | - * Get rows for manager |
|
231 | - * |
|
232 | - * @param array $params |
|
233 | - * @param object $model |
|
234 | - * @return type |
|
235 | - */ |
|
236 | - public function getRows($params = [], $model = null) { |
|
227 | + } |
|
228 | + |
|
229 | + /** |
|
230 | + * Get rows for manager |
|
231 | + * |
|
232 | + * @param array $params |
|
233 | + * @param object $model |
|
234 | + * @return type |
|
235 | + */ |
|
236 | + public function getRows($params = [], $model = null) { |
|
237 | 237 | $modelName = $this->modelName; |
238 | 238 | if (!class_exists($modelName)) { |
239 | - return []; |
|
239 | + return []; |
|
240 | 240 | } |
241 | 241 | if (!$this->checkAccess()) { |
242 | - $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->managerName . '"'); |
|
243 | - return []; |
|
242 | + $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->managerName . '"'); |
|
243 | + return []; |
|
244 | 244 | } |
245 | 245 | $modelName = $this->modelName; |
246 | 246 | $queryParams = []; |
247 | 247 | if (empty($params['all'])) { |
248 | - if (!empty($params['limit'])) { |
|
248 | + if (!empty($params['limit'])) { |
|
249 | 249 | $this->limit = (int) $params['limit']; |
250 | - } |
|
251 | - if (!empty($params['page'])) { |
|
250 | + } |
|
251 | + if (!empty($params['page'])) { |
|
252 | 252 | $this->page = (int) $params['page']; |
253 | - } |
|
254 | - $queryParams['limit'] = $this->limit; |
|
255 | - $queryParams['start'] = $this->page * $this->limit - $this->limit; |
|
253 | + } |
|
254 | + $queryParams['limit'] = $this->limit; |
|
255 | + $queryParams['start'] = $this->page * $this->limit - $this->limit; |
|
256 | 256 | } |
257 | 257 | if (!empty($params['categoryPath']) && $modelName::$categoryModel) { |
258 | - $queryParams['where'][] = ['tree_path', $params['categoryPath'] . '%', 'LIKE']; |
|
258 | + $queryParams['where'][] = ['tree_path', $params['categoryPath'] . '%', 'LIKE']; |
|
259 | 259 | } |
260 | 260 | if (!empty($params['appType'])) { |
261 | - $queryParams['appType'] = $params['appType']; |
|
261 | + $queryParams['appType'] = $params['appType']; |
|
262 | 262 | } |
263 | 263 | if ($this->joins) { |
264 | - $queryParams['joins'] = $this->joins; |
|
264 | + $queryParams['joins'] = $this->joins; |
|
265 | 265 | } |
266 | 266 | if (!empty($this->managerOptions['userGroupFilter'][\Users\User::$cur->group_id]['getRows'])) { |
267 | - foreach ($this->managerOptions['userGroupFilter'][\Users\User::$cur->group_id]['getRows'] as $colName => $colOptions) { |
|
267 | + foreach ($this->managerOptions['userGroupFilter'][\Users\User::$cur->group_id]['getRows'] as $colName => $colOptions) { |
|
268 | 268 | if (!empty($colOptions['userCol'])) { |
269 | - $queryParams['where'][] = [$colName, \Model::getColValue(\Users\User::$cur, $colOptions['userCol'])]; |
|
269 | + $queryParams['where'][] = [$colName, \Model::getColValue(\Users\User::$cur, $colOptions['userCol'])]; |
|
270 | 270 | } elseif (isset($colOptions['value'])) { |
271 | - if (is_array($colOptions['value'])) { |
|
271 | + if (is_array($colOptions['value'])) { |
|
272 | 272 | foreach ($colOptions['value'] as $key => $value) { |
273 | - if ($key === 'userCol') { |
|
273 | + if ($key === 'userCol') { |
|
274 | 274 | $colOptions['value'][$key] = \Model::getColValue(\Users\User::$cur, $value); |
275 | - } |
|
275 | + } |
|
276 | 276 | } |
277 | - } |
|
278 | - $queryParams['where'][] = [$colName, $colOptions['value'], is_array($colOptions['value']) ? 'IN' : '=']; |
|
277 | + } |
|
278 | + $queryParams['where'][] = [$colName, $colOptions['value'], is_array($colOptions['value']) ? 'IN' : '=']; |
|
279 | + } |
|
279 | 280 | } |
280 | - } |
|
281 | 281 | } |
282 | 282 | if (!empty($this->managerOptions['filters'])) { |
283 | - foreach ($this->managerOptions['filters'] as $col) { |
|
283 | + foreach ($this->managerOptions['filters'] as $col) { |
|
284 | 284 | $colInfo = $modelName::getColInfo($col); |
285 | 285 | switch ($colInfo['colParams']['type']) { |
286 | - case 'select': |
|
286 | + case 'select': |
|
287 | 287 | if (empty($params['filters'][$col]['value'])) { |
288 | - continue; |
|
288 | + continue; |
|
289 | 289 | } |
290 | 290 | if (is_array($params['filters'][$col]['value'])) { |
291 | - foreach ($params['filters'][$col]['value'] as $key => $value) { |
|
291 | + foreach ($params['filters'][$col]['value'] as $key => $value) { |
|
292 | 292 | if ($value === '') { |
293 | - unset($params['filters'][$col]['value'][$key]); |
|
293 | + unset($params['filters'][$col]['value'][$key]); |
|
294 | + } |
|
294 | 295 | } |
295 | - } |
|
296 | 296 | } |
297 | 297 | if (!$params['filters'][$col]['value']) { |
298 | - continue; |
|
298 | + continue; |
|
299 | 299 | } |
300 | 300 | $queryParams['where'][] = [$col, $params['filters'][$col]['value'], is_array($params['filters'][$col]['value']) ? 'IN' : '=']; |
301 | 301 | break; |
302 | - case 'bool': |
|
302 | + case 'bool': |
|
303 | 303 | |
304 | 304 | if (!isset($params['filters'][$col]['value']) || $params['filters'][$col]['value'] === '') { |
305 | - continue; |
|
305 | + continue; |
|
306 | 306 | } |
307 | 307 | $queryParams['where'][] = [$col, $params['filters'][$col]['value']]; |
308 | 308 | break; |
309 | - case 'dateTime': |
|
309 | + case 'dateTime': |
|
310 | 310 | case 'date': |
311 | 311 | if (empty($params['filters'][$col]['min']) && empty($params['filters'][$col]['max'])) { |
312 | - continue; |
|
312 | + continue; |
|
313 | 313 | } |
314 | 314 | if (!empty($params['filters'][$col]['min'])) { |
315 | - $queryParams['where'][] = [$col, $params['filters'][$col]['min'], '>=']; |
|
315 | + $queryParams['where'][] = [$col, $params['filters'][$col]['min'], '>=']; |
|
316 | 316 | } |
317 | 317 | if (!empty($params['filters'][$col]['max'])) { |
318 | - if ($colInfo['colParams']['type'] == 'dateTime' && !strpos($params['filters'][$col]['max'], ' ')) { |
|
318 | + if ($colInfo['colParams']['type'] == 'dateTime' && !strpos($params['filters'][$col]['max'], ' ')) { |
|
319 | 319 | |
320 | 320 | $date = $params['filters'][$col]['max'] . ' 23:59:59'; |
321 | - } else { |
|
321 | + } else { |
|
322 | 322 | $date = $params['filters'][$col]['max']; |
323 | - } |
|
324 | - $queryParams['where'][] = [$col, $date, '<=']; |
|
323 | + } |
|
324 | + $queryParams['where'][] = [$col, $date, '<=']; |
|
325 | 325 | } |
326 | 326 | break; |
327 | - case 'number': |
|
327 | + case 'number': |
|
328 | 328 | if (empty($params['filters'][$col]['min']) && empty($params['filters'][$col]['max'])) { |
329 | - continue; |
|
329 | + continue; |
|
330 | 330 | } |
331 | 331 | if (!empty($params['filters'][$col]['min'])) { |
332 | - $queryParams['where'][] = [$col, $params['filters'][$col]['min'], '>=']; |
|
332 | + $queryParams['where'][] = [$col, $params['filters'][$col]['min'], '>=']; |
|
333 | 333 | } |
334 | 334 | if (!empty($params['filters'][$col]['max'])) { |
335 | - $queryParams['where'][] = [$col, $params['filters'][$col]['max'], '<=']; |
|
335 | + $queryParams['where'][] = [$col, $params['filters'][$col]['max'], '<=']; |
|
336 | 336 | } |
337 | 337 | break; |
338 | - case 'email': |
|
338 | + case 'email': |
|
339 | 339 | case 'text': |
340 | 340 | case 'textarea': |
341 | 341 | case 'html': |
342 | 342 | if (empty($params['filters'][$col]['value'])) { |
343 | - continue; |
|
343 | + continue; |
|
344 | 344 | } |
345 | 345 | switch ($params['filters'][$col]['compareType']) { |
346 | - case 'contains': |
|
346 | + case 'contains': |
|
347 | 347 | $queryParams['where'][] = [$col, '%' . $params['filters'][$col]['value'] . '%', 'LIKE']; |
348 | 348 | break; |
349 | - case 'equals': |
|
349 | + case 'equals': |
|
350 | 350 | $queryParams['where'][] = [$col, $params['filters'][$col]['value']]; |
351 | 351 | break; |
352 | - case 'starts_with': |
|
352 | + case 'starts_with': |
|
353 | 353 | $queryParams['where'][] = [$col, $params['filters'][$col]['value'] . '%', 'LIKE']; |
354 | 354 | break; |
355 | - case 'ends_with': |
|
355 | + case 'ends_with': |
|
356 | 356 | $queryParams['where'][] = [$col, '%' . $params['filters'][$col]['value'], 'LIKE']; |
357 | 357 | break; |
358 | 358 | } |
359 | 359 | break; |
360 | 360 | } |
361 | - } |
|
361 | + } |
|
362 | 362 | } |
363 | 363 | if (!empty($params['mode']) && $params['mode'] == 'sort') { |
364 | - $queryParams['order'] = ['weight', 'asc']; |
|
364 | + $queryParams['order'] = ['weight', 'asc']; |
|
365 | 365 | } elseif (!empty($params['sortered']) && !empty($this->managerOptions['sortable'])) { |
366 | - foreach ($params['sortered'] as $key => $sortType) { |
|
366 | + foreach ($params['sortered'] as $key => $sortType) { |
|
367 | 367 | $keys = array_keys($this->managerOptions['cols']); |
368 | 368 | $colName = ''; |
369 | 369 | if (isset($keys[$key])) { |
370 | - if (is_array($this->managerOptions['cols'][$keys[$key]])) { |
|
370 | + if (is_array($this->managerOptions['cols'][$keys[$key]])) { |
|
371 | 371 | $colName = $keys[$key]; |
372 | - } else { |
|
372 | + } else { |
|
373 | 373 | $colName = $this->managerOptions['cols'][$keys[$key]]; |
374 | - } |
|
374 | + } |
|
375 | 375 | } |
376 | 376 | if ($colName && in_array($colName, $this->managerOptions['sortable'])) { |
377 | - $sortType = in_array($sortType, ['desc', 'asc']) ? $sortType : 'desc'; |
|
378 | - $queryParams['order'][] = [$colName, $sortType]; |
|
377 | + $sortType = in_array($sortType, ['desc', 'asc']) ? $sortType : 'desc'; |
|
378 | + $queryParams['order'][] = [$colName, $sortType]; |
|
379 | + } |
|
379 | 380 | } |
380 | - } |
|
381 | 381 | } |
382 | 382 | if ($model && !empty($params['relation'])) { |
383 | - $relation = $model::getRelation($params['relation']); |
|
384 | - $items = $model->$params['relation']($queryParams); |
|
383 | + $relation = $model::getRelation($params['relation']); |
|
384 | + $items = $model->$params['relation']($queryParams); |
|
385 | 385 | } else { |
386 | - $relation = false; |
|
387 | - $items = $modelName::getList($queryParams); |
|
386 | + $relation = false; |
|
387 | + $items = $modelName::getList($queryParams); |
|
388 | 388 | } |
389 | 389 | $rows = []; |
390 | 390 | foreach ($items as $item) { |
391 | - if ($relation && !empty($relation['relModel'])) { |
|
391 | + if ($relation && !empty($relation['relModel'])) { |
|
392 | 392 | $item = $relation['relModel']::get([[$item->index(), $item->id], [$model->index(), $model->id]]); |
393 | - } |
|
394 | - $row = []; |
|
395 | - $row[] = '<input type ="checkbox" name = "pk[]" value =' . $item->pk() . '>'; |
|
396 | - $redirectUrl = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/admin/' . str_replace('\\', '%5C', get_class($originalItem)); |
|
397 | - $row[] = "<a href ='/admin/" . $item->genViewLink() . "?redirectUrl={$redirectUrl}'>{$item->pk()}</a>"; |
|
398 | - foreach ($this->managerOptions['cols'] as $key => $colName) { |
|
393 | + } |
|
394 | + $row = []; |
|
395 | + $row[] = '<input type ="checkbox" name = "pk[]" value =' . $item->pk() . '>'; |
|
396 | + $redirectUrl = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/admin/' . str_replace('\\', '%5C', get_class($originalItem)); |
|
397 | + $row[] = "<a href ='/admin/" . $item->genViewLink() . "?redirectUrl={$redirectUrl}'>{$item->pk()}</a>"; |
|
398 | + foreach ($this->managerOptions['cols'] as $key => $colName) { |
|
399 | 399 | if (!empty($params['download'])) { |
400 | - $row[] = \Model::getColValue($item, is_array($colName) ? $key : $colName, true, false); |
|
400 | + $row[] = \Model::getColValue($item, is_array($colName) ? $key : $colName, true, false); |
|
401 | 401 | } else { |
402 | - $row[] = DataManager::drawCol($item, is_array($colName) ? $key : $colName, $params, $this); |
|
402 | + $row[] = DataManager::drawCol($item, is_array($colName) ? $key : $colName, $params, $this); |
|
403 | 403 | } |
404 | - } |
|
405 | - $row[] = $this->rowButtons($item, $params); |
|
406 | - $rows[] = $row; |
|
404 | + } |
|
405 | + $row[] = $this->rowButtons($item, $params); |
|
406 | + $rows[] = $row; |
|
407 | 407 | } |
408 | 408 | return $rows; |
409 | - } |
|
409 | + } |
|
410 | 410 | |
411 | - public static function drawCol($item, $colName, $params = [], $dataManager = null, $originalCol = '', $originalItem = null) { |
|
411 | + public static function drawCol($item, $colName, $params = [], $dataManager = null, $originalCol = '', $originalItem = null) { |
|
412 | 412 | $modelName = get_class($item); |
413 | 413 | if (!class_exists($modelName)) { |
414 | - return false; |
|
414 | + return false; |
|
415 | 415 | } |
416 | 416 | |
417 | 417 | if (!$originalCol) { |
418 | - $originalCol = $colName; |
|
418 | + $originalCol = $colName; |
|
419 | 419 | } |
420 | 420 | if (!$originalItem) { |
421 | - $originalItem = $item; |
|
421 | + $originalItem = $item; |
|
422 | 422 | } |
423 | 423 | |
424 | 424 | $relations = $modelName::relations(); |
425 | 425 | if (strpos($colName, ':') !== false && !empty($relations[substr($colName, 0, strpos($colName, ':'))])) { |
426 | - $rel = substr($colName, 0, strpos($colName, ':')); |
|
427 | - $col = substr($colName, strpos($colName, ':') + 1); |
|
428 | - if ($item->$rel) { |
|
426 | + $rel = substr($colName, 0, strpos($colName, ':')); |
|
427 | + $col = substr($colName, strpos($colName, ':') + 1); |
|
428 | + if ($item->$rel) { |
|
429 | 429 | return DataManager::drawCol($item->$rel, $col, $params, $dataManager, $originalCol, $originalItem); |
430 | - } else { |
|
430 | + } else { |
|
431 | 431 | return 'Не указано'; |
432 | - } |
|
432 | + } |
|
433 | 433 | } |
434 | 434 | if (!empty($modelName::$cols[$colName]['relation'])) { |
435 | - $type = !empty($relations[$modelName::$cols[$colName]['relation']]['type']) ? $relations[$modelName::$cols[$colName]['relation']]['type'] : 'to'; |
|
436 | - switch ($type) { |
|
435 | + $type = !empty($relations[$modelName::$cols[$colName]['relation']]['type']) ? $relations[$modelName::$cols[$colName]['relation']]['type'] : 'to'; |
|
436 | + switch ($type) { |
|
437 | 437 | case 'relModel': |
438 | 438 | $managerParams = ['relation' => $modelName::$cols[$colName]['relation']]; |
439 | - $count = $item->{$modelName::$cols[$colName]['relation']}(array_merge($params, ['count' => 1])); |
|
440 | - $count = $count ? $count : 'Нет'; |
|
441 | - return "<a class = 'btn btn-xs btn-primary' onclick = 'inji.Ui.dataManagers.popUp(\"" . str_replace('\\', '\\\\', $modelName) . ":" . $item->pk() . "\"," . json_encode(array_merge($params, $managerParams)) . ")'>{$count}</a>"; |
|
439 | + $count = $item->{$modelName::$cols[$colName]['relation']}(array_merge($params, ['count' => 1])); |
|
440 | + $count = $count ? $count : 'Нет'; |
|
441 | + return "<a class = 'btn btn-xs btn-primary' onclick = 'inji.Ui.dataManagers.popUp(\"" . str_replace('\\', '\\\\', $modelName) . ":" . $item->pk() . "\"," . json_encode(array_merge($params, $managerParams)) . ")'>{$count}</a>"; |
|
442 | 442 | case 'many': |
443 | 443 | $managerParams = ['relation' => $modelName::$cols[$colName]['relation']]; |
444 | - $count = $item->{$modelName::$cols[$colName]['relation']}(array_merge($params, ['count' => 1])); |
|
445 | - $count = $count ? $count : 'Нет'; |
|
446 | - return "<a class = 'btn btn-xs btn-primary' onclick = 'inji.Ui.dataManagers.popUp(\"" . str_replace('\\', '\\\\', $modelName) . ":" . $item->pk() . "\"," . json_encode(array_merge($params, $managerParams)) . ")'>{$count}</a>"; |
|
444 | + $count = $item->{$modelName::$cols[$colName]['relation']}(array_merge($params, ['count' => 1])); |
|
445 | + $count = $count ? $count : 'Нет'; |
|
446 | + return "<a class = 'btn btn-xs btn-primary' onclick = 'inji.Ui.dataManagers.popUp(\"" . str_replace('\\', '\\\\', $modelName) . ":" . $item->pk() . "\"," . json_encode(array_merge($params, $managerParams)) . ")'>{$count}</a>"; |
|
447 | 447 | default : |
448 | 448 | if ($item->{$modelName::$cols[$colName]['relation']}) { |
449 | 449 | if (\App::$cur->name == 'admin') { |
450 | - $href = "<a href ='/admin/" . $item->{$modelName::$cols[$colName]['relation']}->genViewLink() . "'>"; |
|
451 | - if (!empty($modelName::$cols[$colName]['showCol'])) { |
|
450 | + $href = "<a href ='/admin/" . $item->{$modelName::$cols[$colName]['relation']}->genViewLink() . "'>"; |
|
451 | + if (!empty($modelName::$cols[$colName]['showCol'])) { |
|
452 | 452 | $href .= $item->{$modelName::$cols[$colName]['relation']}->{$modelName::$cols[$colName]['showCol']}; |
453 | - } else { |
|
453 | + } else { |
|
454 | 454 | |
455 | 455 | $href .= $item->{$modelName::$cols[$colName]['relation']}->name(); |
456 | - } |
|
457 | - $href .= '</a>'; |
|
458 | - return $href; |
|
456 | + } |
|
457 | + $href .= '</a>'; |
|
458 | + return $href; |
|
459 | 459 | } else { |
460 | - return $item->{$modelName::$cols[$colName]['relation']}->name(); |
|
460 | + return $item->{$modelName::$cols[$colName]['relation']}->name(); |
|
461 | 461 | } |
462 | - } else { |
|
462 | + } else { |
|
463 | 463 | return $item->$colName; |
464 | - } |
|
465 | - } |
|
464 | + } |
|
465 | + } |
|
466 | 466 | } else { |
467 | - if (!empty($modelName::$cols[$colName]['view']['type'])) { |
|
467 | + if (!empty($modelName::$cols[$colName]['view']['type'])) { |
|
468 | 468 | switch ($modelName::$cols[$colName]['view']['type']) { |
469 | - case 'widget': |
|
469 | + case 'widget': |
|
470 | 470 | ob_start(); |
471 | 471 | \App::$cur->view->widget($modelName::$cols[$colName]['view']['widget'], ['item' => $item, 'colName' => $colName, 'colParams' => $modelName::$cols[$colName]]); |
472 | 472 | $content = ob_get_contents(); |
473 | 473 | ob_end_clean(); |
474 | 474 | return $content; |
475 | - case 'moduleMethod': |
|
475 | + case 'moduleMethod': |
|
476 | 476 | return \App::$cur->{$modelName::$cols[$colName]['view']['module']}->{$modelName::$cols[$colName]['view']['method']}($item, $colName, $modelName::$cols[$colName]); |
477 | - case 'many': |
|
477 | + case 'many': |
|
478 | 478 | $managerParams = ['relation' => $modelName::$cols[$colName]['relation']]; |
479 | 479 | $count = $item->{$modelName::$cols[$colName]['relation']}(array_merge($params, ['count' => 1])); |
480 | 480 | return "<a class = 'btn btn-xs btn-primary' onclick = 'inji.Ui.dataManagers.popUp(\"" . str_replace('\\', '\\\\', $modelName) . ":" . $item->pk() . "\"," . json_encode(array_merge($params, $managerParams)) . ")'>{$count} " . \Tools::getNumEnding($count, ['Элемент', 'Элемента', 'Элементов']) . "</a>"; |
481 | - default: |
|
481 | + default: |
|
482 | 482 | return $item->$colName; |
483 | 483 | } |
484 | - } elseif (!empty($modelName::$cols[$colName]['type'])) { |
|
484 | + } elseif (!empty($modelName::$cols[$colName]['type'])) { |
|
485 | 485 | if (\App::$cur->name == 'admin' && $originalCol == 'name' || ( $dataManager && !empty($dataManager->managerOptions['colToView']) && $dataManager->managerOptions['colToView'] == $originalCol)) { |
486 | - $formName = $dataManager && !empty($dataManager->managerOptions['editForm']) ? $dataManager->managerOptions['editForm'] : 'manager'; |
|
487 | - $redirectUrl = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/admin/' . str_replace('\\', '/', get_class($originalItem)); |
|
488 | - return "<a href ='/admin/{$originalItem->genViewLink()}?formName={$formName}&redirectUrl={$redirectUrl}'>{$item->$colName}</a>"; |
|
486 | + $formName = $dataManager && !empty($dataManager->managerOptions['editForm']) ? $dataManager->managerOptions['editForm'] : 'manager'; |
|
487 | + $redirectUrl = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/admin/' . str_replace('\\', '/', get_class($originalItem)); |
|
488 | + return "<a href ='/admin/{$originalItem->genViewLink()}?formName={$formName}&redirectUrl={$redirectUrl}'>{$item->$colName}</a>"; |
|
489 | 489 | } elseif (\App::$cur->name == 'admin' && $colName == 'name') { |
490 | - $redirectUrl = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/admin/' . str_replace('\\', '/', get_class($originalItem)); |
|
491 | - return "<a href ='/admin/{$item->genViewLink()}?redirectUrl={$redirectUrl}'>{$item->$colName}</a>"; |
|
490 | + $redirectUrl = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/admin/' . str_replace('\\', '/', get_class($originalItem)); |
|
491 | + return "<a href ='/admin/{$item->genViewLink()}?redirectUrl={$redirectUrl}'>{$item->$colName}</a>"; |
|
492 | 492 | } elseif ($modelName::$cols[$colName]['type'] == 'html') { |
493 | - $uid = \Tools::randomString(); |
|
494 | - $script = "<script>inji.onLoad(function(){ |
|
493 | + $uid = \Tools::randomString(); |
|
494 | + $script = "<script>inji.onLoad(function(){ |
|
495 | 495 | var el{$uid}=$('#{$uid}'); |
496 | 496 | var height{$uid} = el{$uid}.height(); |
497 | 497 | el{$uid}.css('maxHeight','none'); |
@@ -517,20 +517,20 @@ discard block |
||
517 | 517 | el{$uid}.after('<a href=\"#\" onclick=\"el{$uid}Toggle();return false;\">Развернуть</a>'); |
518 | 518 | } |
519 | 519 | })</script>"; |
520 | - return "<div id = '{$uid}' style='max-height:44px;overflow:hidden;'>{$item->$colName}</div>" . $script; |
|
520 | + return "<div id = '{$uid}' style='max-height:44px;overflow:hidden;'>{$item->$colName}</div>" . $script; |
|
521 | 521 | } else { |
522 | - return \Model::resloveTypeValue($item, $colName); |
|
522 | + return \Model::resloveTypeValue($item, $colName); |
|
523 | 523 | } |
524 | - } else { |
|
524 | + } else { |
|
525 | 525 | return $item->$colName; |
526 | - } |
|
526 | + } |
|
527 | + } |
|
527 | 528 | } |
528 | - } |
|
529 | 529 | |
530 | - public function rowButtons($item, $params) { |
|
530 | + public function rowButtons($item, $params) { |
|
531 | 531 | $modelName = $this->modelName; |
532 | 532 | if (!class_exists($modelName)) { |
533 | - return false; |
|
533 | + return false; |
|
534 | 534 | } |
535 | 535 | ob_start(); |
536 | 536 | $widgetName = !empty($this->managerOptions['rowButtonsWidget']) ? $this->managerOptions['rowButtonsWidget'] : 'Ui\DataManager/rowButtons'; |
@@ -542,132 +542,132 @@ discard block |
||
542 | 542 | $buttons = ob_get_contents(); |
543 | 543 | ob_end_clean(); |
544 | 544 | return $buttons; |
545 | - } |
|
545 | + } |
|
546 | 546 | |
547 | - public function getPages($params = [], $model = null) { |
|
547 | + public function getPages($params = [], $model = null) { |
|
548 | 548 | $modelName = $this->modelName; |
549 | 549 | if (!class_exists($modelName)) { |
550 | - return []; |
|
550 | + return []; |
|
551 | 551 | } |
552 | 552 | if (!$this->checkAccess()) { |
553 | - $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->managerName . '"'); |
|
554 | - return []; |
|
553 | + $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->managerName . '"'); |
|
554 | + return []; |
|
555 | 555 | } |
556 | 556 | if (!empty($params['limit'])) { |
557 | - $this->limit = (int) $params['limit']; |
|
557 | + $this->limit = (int) $params['limit']; |
|
558 | 558 | } |
559 | 559 | if (!empty($params['page'])) { |
560 | - $this->page = (int) $params['page']; |
|
560 | + $this->page = (int) $params['page']; |
|
561 | 561 | } |
562 | 562 | $queryParams = [ |
563 | 563 | 'count' => true |
564 | 564 | ]; |
565 | 565 | $modelName = $this->modelName; |
566 | 566 | if (!empty($params['categoryPath']) && $modelName::$categoryModel) { |
567 | - $queryParams['where'][] = ['tree_path', $params['categoryPath'] . '%', 'LIKE']; |
|
567 | + $queryParams['where'][] = ['tree_path', $params['categoryPath'] . '%', 'LIKE']; |
|
568 | 568 | } |
569 | 569 | if (!empty($this->managerOptions['userGroupFilter'][\Users\User::$cur->group_id]['getRows'])) { |
570 | - foreach ($this->managerOptions['userGroupFilter'][\Users\User::$cur->group_id]['getRows'] as $colName => $colOptions) { |
|
570 | + foreach ($this->managerOptions['userGroupFilter'][\Users\User::$cur->group_id]['getRows'] as $colName => $colOptions) { |
|
571 | 571 | if (!empty($colOptions['userCol'])) { |
572 | - $queryParams['where'][] = [$colName, \Model::getColValue(\Users\User::$cur, $colOptions['userCol'])]; |
|
572 | + $queryParams['where'][] = [$colName, \Model::getColValue(\Users\User::$cur, $colOptions['userCol'])]; |
|
573 | 573 | } elseif (isset($colOptions['value'])) { |
574 | - if (is_array($colOptions['value'])) { |
|
574 | + if (is_array($colOptions['value'])) { |
|
575 | 575 | foreach ($colOptions['value'] as $key => $value) { |
576 | - if ($key === 'userCol') { |
|
576 | + if ($key === 'userCol') { |
|
577 | 577 | $colOptions['value'][$key] = \Model::getColValue(\Users\User::$cur, $value); |
578 | - } |
|
578 | + } |
|
579 | + } |
|
579 | 580 | } |
580 | - } |
|
581 | - $queryParams['where'][] = [$colName, $colOptions['value'], is_array($colOptions['value']) ? 'IN' : '=']; |
|
581 | + $queryParams['where'][] = [$colName, $colOptions['value'], is_array($colOptions['value']) ? 'IN' : '=']; |
|
582 | + } |
|
582 | 583 | } |
583 | - } |
|
584 | 584 | } |
585 | 585 | $modelName = $this->modelName; |
586 | 586 | if (!empty($this->managerOptions['filters'])) { |
587 | - foreach ($this->managerOptions['filters'] as $col) { |
|
587 | + foreach ($this->managerOptions['filters'] as $col) { |
|
588 | 588 | $colInfo = $modelName::getColInfo($col); |
589 | 589 | switch ($colInfo['colParams']['type']) { |
590 | - case 'select': |
|
590 | + case 'select': |
|
591 | 591 | if (empty($params['filters'][$col]['value'])) { |
592 | - continue; |
|
592 | + continue; |
|
593 | 593 | } |
594 | 594 | if (is_array($params['filters'][$col]['value'])) { |
595 | - foreach ($params['filters'][$col]['value'] as $key => $value) { |
|
595 | + foreach ($params['filters'][$col]['value'] as $key => $value) { |
|
596 | 596 | if ($value === '') { |
597 | - unset($params['filters'][$col]['value'][$key]); |
|
597 | + unset($params['filters'][$col]['value'][$key]); |
|
598 | + } |
|
598 | 599 | } |
599 | - } |
|
600 | 600 | } |
601 | 601 | if (!$params['filters'][$col]['value']) { |
602 | - continue; |
|
602 | + continue; |
|
603 | 603 | } |
604 | 604 | $queryParams['where'][] = [$col, $params['filters'][$col]['value'], is_array($params['filters'][$col]['value']) ? 'IN' : '=']; |
605 | 605 | break; |
606 | - case 'bool': |
|
606 | + case 'bool': |
|
607 | 607 | |
608 | 608 | if (empty($params['filters'][$col]['value'])) { |
609 | - continue; |
|
609 | + continue; |
|
610 | 610 | } |
611 | 611 | $queryParams['where'][] = [$col, '1']; |
612 | 612 | break; |
613 | - case 'dateTime': |
|
613 | + case 'dateTime': |
|
614 | 614 | case 'date': |
615 | 615 | if (empty($params['filters'][$col]['min']) && empty($params['filters'][$col]['max'])) { |
616 | - continue; |
|
616 | + continue; |
|
617 | 617 | } |
618 | 618 | if (!empty($params['filters'][$col]['min'])) { |
619 | - $queryParams['where'][] = [$col, $params['filters'][$col]['min'], '>=']; |
|
619 | + $queryParams['where'][] = [$col, $params['filters'][$col]['min'], '>=']; |
|
620 | 620 | } |
621 | 621 | if (!empty($params['filters'][$col]['max'])) { |
622 | - if ($colInfo['colParams']['type'] == 'dateTime' && !strpos($params['filters'][$col]['max'], ' ')) { |
|
622 | + if ($colInfo['colParams']['type'] == 'dateTime' && !strpos($params['filters'][$col]['max'], ' ')) { |
|
623 | 623 | |
624 | 624 | $date = $params['filters'][$col]['max'] . ' 23:59:59'; |
625 | - } else { |
|
625 | + } else { |
|
626 | 626 | $date = $params['filters'][$col]['max']; |
627 | - } |
|
628 | - $queryParams['where'][] = [$col, $date, '<=']; |
|
627 | + } |
|
628 | + $queryParams['where'][] = [$col, $date, '<=']; |
|
629 | 629 | } |
630 | 630 | break; |
631 | - case 'number': |
|
631 | + case 'number': |
|
632 | 632 | if (empty($params['filters'][$col]['min']) && empty($params['filters'][$col]['max'])) { |
633 | - continue; |
|
633 | + continue; |
|
634 | 634 | } |
635 | 635 | if (!empty($params['filters'][$col]['min'])) { |
636 | - $queryParams['where'][] = [$col, $params['filters'][$col]['min'], '>=']; |
|
636 | + $queryParams['where'][] = [$col, $params['filters'][$col]['min'], '>=']; |
|
637 | 637 | } |
638 | 638 | if (!empty($params['filters'][$col]['max'])) { |
639 | - $queryParams['where'][] = [$col, $params['filters'][$col]['max'], '<=']; |
|
639 | + $queryParams['where'][] = [$col, $params['filters'][$col]['max'], '<=']; |
|
640 | 640 | } |
641 | 641 | break; |
642 | - case 'email': |
|
642 | + case 'email': |
|
643 | 643 | case 'text': |
644 | 644 | case 'textarea': |
645 | 645 | case 'html': |
646 | 646 | if (empty($params['filters'][$col]['value'])) { |
647 | - continue; |
|
647 | + continue; |
|
648 | 648 | } |
649 | 649 | switch ($params['filters'][$col]['compareType']) { |
650 | - case 'contains': |
|
650 | + case 'contains': |
|
651 | 651 | $queryParams['where'][] = [$col, '%' . $params['filters'][$col]['value'] . '%', 'LIKE']; |
652 | 652 | break; |
653 | - case 'equals': |
|
653 | + case 'equals': |
|
654 | 654 | $queryParams['where'][] = [$col, $params['filters'][$col]['value']]; |
655 | 655 | break; |
656 | - case 'starts_with': |
|
656 | + case 'starts_with': |
|
657 | 657 | $queryParams['where'][] = [$col, $params['filters'][$col]['value'] . '%', 'LIKE']; |
658 | 658 | break; |
659 | - case 'ends_with': |
|
659 | + case 'ends_with': |
|
660 | 660 | $queryParams['where'][] = [$col, '%' . $params['filters'][$col]['value'], 'LIKE']; |
661 | 661 | break; |
662 | 662 | } |
663 | 663 | break; |
664 | 664 | } |
665 | - } |
|
665 | + } |
|
666 | 666 | } |
667 | 667 | if ($model && !empty($params['relation'])) { |
668 | - $count = $model->$params['relation']($queryParams); |
|
668 | + $count = $model->$params['relation']($queryParams); |
|
669 | 669 | } else { |
670 | - $count = $modelName::getCount($queryParams); |
|
670 | + $count = $modelName::getCount($queryParams); |
|
671 | 671 | } |
672 | 672 | $pages = new Pages([ |
673 | 673 | 'limit' => $this->limit, |
@@ -677,9 +677,9 @@ discard block |
||
677 | 677 | 'dataManager' => $this |
678 | 678 | ]); |
679 | 679 | return $pages; |
680 | - } |
|
680 | + } |
|
681 | 681 | |
682 | - public function preDraw($params = [], $model = null) { |
|
682 | + public function preDraw($params = [], $model = null) { |
|
683 | 683 | $this->predraw = true; |
684 | 684 | |
685 | 685 | $cols = $this->getCols(); |
@@ -687,16 +687,16 @@ discard block |
||
687 | 687 | $this->table = new Table(); |
688 | 688 | $tableCols = []; |
689 | 689 | foreach ($cols as $colName => $colOptions) { |
690 | - $tableCols[] = !empty($colOptions['label']) ? $colOptions['label'] : $colName; |
|
690 | + $tableCols[] = !empty($colOptions['label']) ? $colOptions['label'] : $colName; |
|
691 | 691 | } |
692 | 692 | $tableCols[] = ''; |
693 | 693 | $this->table->class .=' datamanagertable'; |
694 | 694 | $this->table->setCols($tableCols); |
695 | - } |
|
695 | + } |
|
696 | 696 | |
697 | - public function draw($params = [], $model = null) { |
|
697 | + public function draw($params = [], $model = null) { |
|
698 | 698 | if (!$this->predraw) { |
699 | - $this->preDraw($params, $model); |
|
699 | + $this->preDraw($params, $model); |
|
700 | 700 | } |
701 | 701 | \App::$cur->view->widget('Ui\DataManager/DataManager', [ |
702 | 702 | 'dataManager' => $this, |
@@ -704,58 +704,58 @@ discard block |
||
704 | 704 | 'table' => $this->table, |
705 | 705 | 'params' => $params |
706 | 706 | ]); |
707 | - } |
|
707 | + } |
|
708 | 708 | |
709 | - public function drawCategorys() { |
|
709 | + public function drawCategorys() { |
|
710 | 710 | if (!class_exists($this->modelName)) { |
711 | - return false; |
|
711 | + return false; |
|
712 | 712 | } |
713 | 713 | if (!$this->checkAccess()) { |
714 | - $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->managerName . '"'); |
|
715 | - return []; |
|
714 | + $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->managerName . '"'); |
|
715 | + return []; |
|
716 | 716 | } |
717 | 717 | $tree = new Tree(); |
718 | 718 | $tree->ul($this->managerOptions['categorys']['model'], 0, function($category) { |
719 | - $path = $category->tree_path . ($category->pk() ? $category->pk() . "/" : ''); |
|
720 | - $cleanClassName = str_replace('\\', '\\\\', get_class($category)); |
|
721 | - return "<a href='#' onclick='inji.Ui.dataManagers.get(this).switchCategory(this);return false;' data-index='{$category->index()}' data-path ='{$path}' data-id='{$category->pk()}' data-model='{$this->managerOptions['categorys']['model']}'> {$category->name}</a> |
|
719 | + $path = $category->tree_path . ($category->pk() ? $category->pk() . "/" : ''); |
|
720 | + $cleanClassName = str_replace('\\', '\\\\', get_class($category)); |
|
721 | + return "<a href='#' onclick='inji.Ui.dataManagers.get(this).switchCategory(this);return false;' data-index='{$category->index()}' data-path ='{$path}' data-id='{$category->pk()}' data-model='{$this->managerOptions['categorys']['model']}'> {$category->name}</a> |
|
722 | 722 | |
723 | 723 | <a href = '#' class ='glyphicon glyphicon-edit' onclick = 'inji.Ui.forms.popUp(\"{$cleanClassName}:{$category->pk()}\")'></a> |
724 | 724 | <a href = '#' class ='glyphicon glyphicon-remove' onclick = 'inji.Ui.dataManagers.get(this).delCategory({$category->pk()});return false;'></a>"; |
725 | 725 | }); |
726 | 726 | ?> |
727 | 727 | <?php |
728 | - } |
|
729 | - |
|
730 | - /** |
|
731 | - * Draw error message |
|
732 | - * |
|
733 | - * @param string $errorText |
|
734 | - */ |
|
735 | - public function drawError($errorText) { |
|
728 | + } |
|
729 | + |
|
730 | + /** |
|
731 | + * Draw error message |
|
732 | + * |
|
733 | + * @param string $errorText |
|
734 | + */ |
|
735 | + public function drawError($errorText) { |
|
736 | 736 | echo $errorText; |
737 | - } |
|
738 | - |
|
739 | - /** |
|
740 | - * Check access cur user to manager with name in param |
|
741 | - * |
|
742 | - * @return boolean |
|
743 | - */ |
|
744 | - public function checkAccess() { |
|
737 | + } |
|
738 | + |
|
739 | + /** |
|
740 | + * Check access cur user to manager with name in param |
|
741 | + * |
|
742 | + * @return boolean |
|
743 | + */ |
|
744 | + public function checkAccess() { |
|
745 | 745 | if (\App::$cur->Access && !\App::$cur->Access->checkAccess($this)) { |
746 | - return false; |
|
746 | + return false; |
|
747 | 747 | } |
748 | 748 | |
749 | 749 | if (!empty($this->managerOptions['options']['access']['apps']) && !in_array(\App::$cur->name, $this->managerOptions['options']['access']['apps'])) { |
750 | - return false; |
|
750 | + return false; |
|
751 | 751 | } |
752 | 752 | if (!empty($this->managerOptions['options']['access']['groups']) && in_array(\Users\User::$cur->group_id, $this->managerOptions['options']['access']['groups'])) { |
753 | - return true; |
|
753 | + return true; |
|
754 | 754 | } |
755 | 755 | if ($this->managerName == 'manager' && !\Users\User::$cur->isAdmin()) { |
756 | - return false; |
|
756 | + return false; |
|
757 | 757 | } |
758 | 758 | return true; |
759 | - } |
|
759 | + } |
|
760 | 760 | |
761 | 761 | } |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | $this->name = $this->managerOptions['name']; |
58 | 58 | } |
59 | 59 | |
60 | - $this->managerId = str_replace('\\', '_', 'dataManager_' . $this->modelName . '_' . $this->managerName . '_' . \Tools::randomString()); |
|
60 | + $this->managerId = str_replace('\\', '_', 'dataManager_'.$this->modelName.'_'.$this->managerName.'_'.\Tools::randomString()); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | if (!empty($this->managerOptions['filters'])) { |
104 | 104 | $buttons[] = [ |
105 | 105 | 'text' => 'Фильтры', |
106 | - 'onclick' => ' var modal = $("#' . $this->managerId . '_filters"); |
|
106 | + 'onclick' => ' var modal = $("#'.$this->managerId.'_filters"); |
|
107 | 107 | modal.modal("show");', |
108 | 108 | ]; |
109 | 109 | } |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | $formParams['formName'] = 'simpleItem'; |
112 | 112 | $buttons[] = [ |
113 | 113 | 'text' => '<i class = "glyphicon glyphicon-send"></i> Быстрое создание', |
114 | - 'onclick' => 'inji.Ui.dataManagers.get(this).newItem("' . str_replace('\\', '\\\\', $modelName) . '",' . json_encode($formParams) . ');', |
|
114 | + 'onclick' => 'inji.Ui.dataManagers.get(this).newItem("'.str_replace('\\', '\\\\', $modelName).'",'.json_encode($formParams).');', |
|
115 | 115 | ]; |
116 | 116 | } |
117 | 117 | $formParams['formName'] = !empty($this->managerOptions['editForm']) ? $this->managerOptions['editForm'] : 'manager'; |
@@ -123,8 +123,8 @@ discard block |
||
123 | 123 | $aform = new ActiveForm(new $modelName, $formParams['formName']); |
124 | 124 | if ($aform->checkAccess()) { |
125 | 125 | $buttons[] = [ |
126 | - 'text' => 'Создать ' . $name, |
|
127 | - 'onclick' => 'inji.Ui.dataManagers.get(this).newItem("' . str_replace('\\', '\\\\', $modelName) . '",' . json_encode($formParams) . ');', |
|
126 | + 'text' => 'Создать '.$name, |
|
127 | + 'onclick' => 'inji.Ui.dataManagers.get(this).newItem("'.str_replace('\\', '\\\\', $modelName).'",'.json_encode($formParams).');', |
|
128 | 128 | ]; |
129 | 129 | } |
130 | 130 | } |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | 'className' => $action |
159 | 159 | ]; |
160 | 160 | } |
161 | - $return[$key]['className'] = strpos($return[$key]['className'], '\\') === false && class_exists('Ui\DataManager\Action\\' . $return[$key]['className']) ? 'Ui\DataManager\Action\\' . $return[$key]['className'] : $return[$key]['className']; |
|
161 | + $return[$key]['className'] = strpos($return[$key]['className'], '\\') === false && class_exists('Ui\DataManager\Action\\'.$return[$key]['className']) ? 'Ui\DataManager\Action\\'.$return[$key]['className'] : $return[$key]['className']; |
|
162 | 162 | if (!class_exists($return[$key]['className']) || ($onlyGroupActions && !$return[$key]['className']::$groupAction)) { |
163 | 163 | unset($return[$key]); |
164 | 164 | } |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | <?php |
190 | 190 | foreach ($actions as $action => $actionParams) { |
191 | 191 | if (class_exists($actionParams['className']) && $actionParams['className']::$groupAction) { |
192 | - echo "<li><a role='button' href ='#' onclick='inji.Ui.dataManagers.get(this).groupAction(\"" . str_replace('\\', '\\\\', $action) . "\");return false;'>{$actionParams['className']::$name}</a></li>"; |
|
192 | + echo "<li><a role='button' href ='#' onclick='inji.Ui.dataManagers.get(this).groupAction(\"".str_replace('\\', '\\\\', $action)."\");return false;'>{$actionParams['className']::$name}</a></li>"; |
|
193 | 193 | } |
194 | 194 | } |
195 | 195 | ?> |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | return []; |
240 | 240 | } |
241 | 241 | if (!$this->checkAccess()) { |
242 | - $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->managerName . '"'); |
|
242 | + $this->drawError('you not have access to "'.$this->modelName.'" manager with name: "'.$this->managerName.'"'); |
|
243 | 243 | return []; |
244 | 244 | } |
245 | 245 | $modelName = $this->modelName; |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | $queryParams['start'] = $this->page * $this->limit - $this->limit; |
256 | 256 | } |
257 | 257 | if (!empty($params['categoryPath']) && $modelName::$categoryModel) { |
258 | - $queryParams['where'][] = ['tree_path', $params['categoryPath'] . '%', 'LIKE']; |
|
258 | + $queryParams['where'][] = ['tree_path', $params['categoryPath'].'%', 'LIKE']; |
|
259 | 259 | } |
260 | 260 | if (!empty($params['appType'])) { |
261 | 261 | $queryParams['appType'] = $params['appType']; |
@@ -317,7 +317,7 @@ discard block |
||
317 | 317 | if (!empty($params['filters'][$col]['max'])) { |
318 | 318 | if ($colInfo['colParams']['type'] == 'dateTime' && !strpos($params['filters'][$col]['max'], ' ')) { |
319 | 319 | |
320 | - $date = $params['filters'][$col]['max'] . ' 23:59:59'; |
|
320 | + $date = $params['filters'][$col]['max'].' 23:59:59'; |
|
321 | 321 | } else { |
322 | 322 | $date = $params['filters'][$col]['max']; |
323 | 323 | } |
@@ -344,16 +344,16 @@ discard block |
||
344 | 344 | } |
345 | 345 | switch ($params['filters'][$col]['compareType']) { |
346 | 346 | case 'contains': |
347 | - $queryParams['where'][] = [$col, '%' . $params['filters'][$col]['value'] . '%', 'LIKE']; |
|
347 | + $queryParams['where'][] = [$col, '%'.$params['filters'][$col]['value'].'%', 'LIKE']; |
|
348 | 348 | break; |
349 | 349 | case 'equals': |
350 | 350 | $queryParams['where'][] = [$col, $params['filters'][$col]['value']]; |
351 | 351 | break; |
352 | 352 | case 'starts_with': |
353 | - $queryParams['where'][] = [$col, $params['filters'][$col]['value'] . '%', 'LIKE']; |
|
353 | + $queryParams['where'][] = [$col, $params['filters'][$col]['value'].'%', 'LIKE']; |
|
354 | 354 | break; |
355 | 355 | case 'ends_with': |
356 | - $queryParams['where'][] = [$col, '%' . $params['filters'][$col]['value'], 'LIKE']; |
|
356 | + $queryParams['where'][] = [$col, '%'.$params['filters'][$col]['value'], 'LIKE']; |
|
357 | 357 | break; |
358 | 358 | } |
359 | 359 | break; |
@@ -392,9 +392,9 @@ discard block |
||
392 | 392 | $item = $relation['relModel']::get([[$item->index(), $item->id], [$model->index(), $model->id]]); |
393 | 393 | } |
394 | 394 | $row = []; |
395 | - $row[] = '<input type ="checkbox" name = "pk[]" value =' . $item->pk() . '>'; |
|
396 | - $redirectUrl = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/admin/' . str_replace('\\', '%5C', get_class($originalItem)); |
|
397 | - $row[] = "<a href ='/admin/" . $item->genViewLink() . "?redirectUrl={$redirectUrl}'>{$item->pk()}</a>"; |
|
395 | + $row[] = '<input type ="checkbox" name = "pk[]" value ='.$item->pk().'>'; |
|
396 | + $redirectUrl = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/admin/'.str_replace('\\', '%5C', get_class($originalItem)); |
|
397 | + $row[] = "<a href ='/admin/".$item->genViewLink()."?redirectUrl={$redirectUrl}'>{$item->pk()}</a>"; |
|
398 | 398 | foreach ($this->managerOptions['cols'] as $key => $colName) { |
399 | 399 | if (!empty($params['download'])) { |
400 | 400 | $row[] = \Model::getColValue($item, is_array($colName) ? $key : $colName, true, false); |
@@ -438,16 +438,16 @@ discard block |
||
438 | 438 | $managerParams = ['relation' => $modelName::$cols[$colName]['relation']]; |
439 | 439 | $count = $item->{$modelName::$cols[$colName]['relation']}(array_merge($params, ['count' => 1])); |
440 | 440 | $count = $count ? $count : 'Нет'; |
441 | - return "<a class = 'btn btn-xs btn-primary' onclick = 'inji.Ui.dataManagers.popUp(\"" . str_replace('\\', '\\\\', $modelName) . ":" . $item->pk() . "\"," . json_encode(array_merge($params, $managerParams)) . ")'>{$count}</a>"; |
|
441 | + return "<a class = 'btn btn-xs btn-primary' onclick = 'inji.Ui.dataManagers.popUp(\"".str_replace('\\', '\\\\', $modelName).":".$item->pk()."\",".json_encode(array_merge($params, $managerParams)).")'>{$count}</a>"; |
|
442 | 442 | case 'many': |
443 | 443 | $managerParams = ['relation' => $modelName::$cols[$colName]['relation']]; |
444 | 444 | $count = $item->{$modelName::$cols[$colName]['relation']}(array_merge($params, ['count' => 1])); |
445 | 445 | $count = $count ? $count : 'Нет'; |
446 | - return "<a class = 'btn btn-xs btn-primary' onclick = 'inji.Ui.dataManagers.popUp(\"" . str_replace('\\', '\\\\', $modelName) . ":" . $item->pk() . "\"," . json_encode(array_merge($params, $managerParams)) . ")'>{$count}</a>"; |
|
446 | + return "<a class = 'btn btn-xs btn-primary' onclick = 'inji.Ui.dataManagers.popUp(\"".str_replace('\\', '\\\\', $modelName).":".$item->pk()."\",".json_encode(array_merge($params, $managerParams)).")'>{$count}</a>"; |
|
447 | 447 | default : |
448 | 448 | if ($item->{$modelName::$cols[$colName]['relation']}) { |
449 | 449 | if (\App::$cur->name == 'admin') { |
450 | - $href = "<a href ='/admin/" . $item->{$modelName::$cols[$colName]['relation']}->genViewLink() . "'>"; |
|
450 | + $href = "<a href ='/admin/".$item->{$modelName::$cols[$colName]['relation']}->genViewLink()."'>"; |
|
451 | 451 | if (!empty($modelName::$cols[$colName]['showCol'])) { |
452 | 452 | $href .= $item->{$modelName::$cols[$colName]['relation']}->{$modelName::$cols[$colName]['showCol']}; |
453 | 453 | } else { |
@@ -477,17 +477,17 @@ discard block |
||
477 | 477 | case 'many': |
478 | 478 | $managerParams = ['relation' => $modelName::$cols[$colName]['relation']]; |
479 | 479 | $count = $item->{$modelName::$cols[$colName]['relation']}(array_merge($params, ['count' => 1])); |
480 | - return "<a class = 'btn btn-xs btn-primary' onclick = 'inji.Ui.dataManagers.popUp(\"" . str_replace('\\', '\\\\', $modelName) . ":" . $item->pk() . "\"," . json_encode(array_merge($params, $managerParams)) . ")'>{$count} " . \Tools::getNumEnding($count, ['Элемент', 'Элемента', 'Элементов']) . "</a>"; |
|
480 | + return "<a class = 'btn btn-xs btn-primary' onclick = 'inji.Ui.dataManagers.popUp(\"".str_replace('\\', '\\\\', $modelName).":".$item->pk()."\",".json_encode(array_merge($params, $managerParams)).")'>{$count} ".\Tools::getNumEnding($count, ['Элемент', 'Элемента', 'Элементов'])."</a>"; |
|
481 | 481 | default: |
482 | 482 | return $item->$colName; |
483 | 483 | } |
484 | 484 | } elseif (!empty($modelName::$cols[$colName]['type'])) { |
485 | - if (\App::$cur->name == 'admin' && $originalCol == 'name' || ( $dataManager && !empty($dataManager->managerOptions['colToView']) && $dataManager->managerOptions['colToView'] == $originalCol)) { |
|
485 | + if (\App::$cur->name == 'admin' && $originalCol == 'name' || ($dataManager && !empty($dataManager->managerOptions['colToView']) && $dataManager->managerOptions['colToView'] == $originalCol)) { |
|
486 | 486 | $formName = $dataManager && !empty($dataManager->managerOptions['editForm']) ? $dataManager->managerOptions['editForm'] : 'manager'; |
487 | - $redirectUrl = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/admin/' . str_replace('\\', '/', get_class($originalItem)); |
|
487 | + $redirectUrl = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/admin/'.str_replace('\\', '/', get_class($originalItem)); |
|
488 | 488 | return "<a href ='/admin/{$originalItem->genViewLink()}?formName={$formName}&redirectUrl={$redirectUrl}'>{$item->$colName}</a>"; |
489 | 489 | } elseif (\App::$cur->name == 'admin' && $colName == 'name') { |
490 | - $redirectUrl = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/admin/' . str_replace('\\', '/', get_class($originalItem)); |
|
490 | + $redirectUrl = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/admin/'.str_replace('\\', '/', get_class($originalItem)); |
|
491 | 491 | return "<a href ='/admin/{$item->genViewLink()}?redirectUrl={$redirectUrl}'>{$item->$colName}</a>"; |
492 | 492 | } elseif ($modelName::$cols[$colName]['type'] == 'html') { |
493 | 493 | $uid = \Tools::randomString(); |
@@ -517,7 +517,7 @@ discard block |
||
517 | 517 | el{$uid}.after('<a href=\"#\" onclick=\"el{$uid}Toggle();return false;\">Развернуть</a>'); |
518 | 518 | } |
519 | 519 | })</script>"; |
520 | - return "<div id = '{$uid}' style='max-height:44px;overflow:hidden;'>{$item->$colName}</div>" . $script; |
|
520 | + return "<div id = '{$uid}' style='max-height:44px;overflow:hidden;'>{$item->$colName}</div>".$script; |
|
521 | 521 | } else { |
522 | 522 | return \Model::resloveTypeValue($item, $colName); |
523 | 523 | } |
@@ -550,7 +550,7 @@ discard block |
||
550 | 550 | return []; |
551 | 551 | } |
552 | 552 | if (!$this->checkAccess()) { |
553 | - $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->managerName . '"'); |
|
553 | + $this->drawError('you not have access to "'.$this->modelName.'" manager with name: "'.$this->managerName.'"'); |
|
554 | 554 | return []; |
555 | 555 | } |
556 | 556 | if (!empty($params['limit'])) { |
@@ -564,7 +564,7 @@ discard block |
||
564 | 564 | ]; |
565 | 565 | $modelName = $this->modelName; |
566 | 566 | if (!empty($params['categoryPath']) && $modelName::$categoryModel) { |
567 | - $queryParams['where'][] = ['tree_path', $params['categoryPath'] . '%', 'LIKE']; |
|
567 | + $queryParams['where'][] = ['tree_path', $params['categoryPath'].'%', 'LIKE']; |
|
568 | 568 | } |
569 | 569 | if (!empty($this->managerOptions['userGroupFilter'][\Users\User::$cur->group_id]['getRows'])) { |
570 | 570 | foreach ($this->managerOptions['userGroupFilter'][\Users\User::$cur->group_id]['getRows'] as $colName => $colOptions) { |
@@ -621,7 +621,7 @@ discard block |
||
621 | 621 | if (!empty($params['filters'][$col]['max'])) { |
622 | 622 | if ($colInfo['colParams']['type'] == 'dateTime' && !strpos($params['filters'][$col]['max'], ' ')) { |
623 | 623 | |
624 | - $date = $params['filters'][$col]['max'] . ' 23:59:59'; |
|
624 | + $date = $params['filters'][$col]['max'].' 23:59:59'; |
|
625 | 625 | } else { |
626 | 626 | $date = $params['filters'][$col]['max']; |
627 | 627 | } |
@@ -648,16 +648,16 @@ discard block |
||
648 | 648 | } |
649 | 649 | switch ($params['filters'][$col]['compareType']) { |
650 | 650 | case 'contains': |
651 | - $queryParams['where'][] = [$col, '%' . $params['filters'][$col]['value'] . '%', 'LIKE']; |
|
651 | + $queryParams['where'][] = [$col, '%'.$params['filters'][$col]['value'].'%', 'LIKE']; |
|
652 | 652 | break; |
653 | 653 | case 'equals': |
654 | 654 | $queryParams['where'][] = [$col, $params['filters'][$col]['value']]; |
655 | 655 | break; |
656 | 656 | case 'starts_with': |
657 | - $queryParams['where'][] = [$col, $params['filters'][$col]['value'] . '%', 'LIKE']; |
|
657 | + $queryParams['where'][] = [$col, $params['filters'][$col]['value'].'%', 'LIKE']; |
|
658 | 658 | break; |
659 | 659 | case 'ends_with': |
660 | - $queryParams['where'][] = [$col, '%' . $params['filters'][$col]['value'], 'LIKE']; |
|
660 | + $queryParams['where'][] = [$col, '%'.$params['filters'][$col]['value'], 'LIKE']; |
|
661 | 661 | break; |
662 | 662 | } |
663 | 663 | break; |
@@ -690,7 +690,7 @@ discard block |
||
690 | 690 | $tableCols[] = !empty($colOptions['label']) ? $colOptions['label'] : $colName; |
691 | 691 | } |
692 | 692 | $tableCols[] = ''; |
693 | - $this->table->class .=' datamanagertable'; |
|
693 | + $this->table->class .= ' datamanagertable'; |
|
694 | 694 | $this->table->setCols($tableCols); |
695 | 695 | } |
696 | 696 | |
@@ -711,12 +711,12 @@ discard block |
||
711 | 711 | return false; |
712 | 712 | } |
713 | 713 | if (!$this->checkAccess()) { |
714 | - $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->managerName . '"'); |
|
714 | + $this->drawError('you not have access to "'.$this->modelName.'" manager with name: "'.$this->managerName.'"'); |
|
715 | 715 | return []; |
716 | 716 | } |
717 | 717 | $tree = new Tree(); |
718 | 718 | $tree->ul($this->managerOptions['categorys']['model'], 0, function($category) { |
719 | - $path = $category->tree_path . ($category->pk() ? $category->pk() . "/" : ''); |
|
719 | + $path = $category->tree_path.($category->pk() ? $category->pk()."/" : ''); |
|
720 | 720 | $cleanClassName = str_replace('\\', '\\\\', get_class($category)); |
721 | 721 | return "<a href='#' onclick='inji.Ui.dataManagers.get(this).switchCategory(this);return false;' data-index='{$category->index()}' data-path ='{$path}' data-id='{$category->pk()}' data-model='{$this->managerOptions['categorys']['model']}'> {$category->name}</a> |
722 | 722 |
@@ -4,36 +4,36 @@ discard block |
||
4 | 4 | $optionsHtml = ''; |
5 | 5 | |
6 | 6 | foreach ($options['values'] as $key => $value) { |
7 | - $selected = ''; |
|
7 | + $selected = ''; |
|
8 | 8 | |
9 | - $primaryValue = isset($options['value']) ? $options['value'] : null; |
|
10 | - $primaryValue = is_array($primaryValue) && isset($primaryValue['primary']) ? $primaryValue['primary'] : $primaryValue; |
|
11 | - if (is_numeric($key) && !is_array($primaryValue) && $primaryValue !== '') { |
|
9 | + $primaryValue = isset($options['value']) ? $options['value'] : null; |
|
10 | + $primaryValue = is_array($primaryValue) && isset($primaryValue['primary']) ? $primaryValue['primary'] : $primaryValue; |
|
11 | + if (is_numeric($key) && !is_array($primaryValue) && $primaryValue !== '') { |
|
12 | 12 | $primaryValue = (int) $primaryValue; |
13 | - } |
|
14 | - if ( |
|
15 | - (!is_array($primaryValue) && ($key === $primaryValue || (isset($form->userDataTree[$name]) && $form->userDataTree[$name] === $key))) || |
|
13 | + } |
|
14 | + if ( |
|
15 | + (!is_array($primaryValue) && ($key === $primaryValue || (isset($form->userDataTree[$name]) && $form->userDataTree[$name] === $key))) || |
|
16 | 16 | (is_array($primaryValue) && (in_array($key, $primaryValue) || (isset($form->userDataTree[$name]) && in_array($key, $form->userDataTree[$name])))) |
17 | - ) { |
|
17 | + ) { |
|
18 | 18 | $selected = ' selected="selected"'; |
19 | - } |
|
20 | - if (is_array($value)) { |
|
19 | + } |
|
20 | + if (is_array($value)) { |
|
21 | 21 | $aditionalInputs[] = $value['input']; |
22 | 22 | if ($selected) { |
23 | - $showedInput = count($aditionalInputs) - 1; |
|
24 | - $aditionValue = !empty($options['aditionalValue']) ? $options['aditionalValue'] : ''; |
|
23 | + $showedInput = count($aditionalInputs) - 1; |
|
24 | + $aditionValue = !empty($options['aditionalValue']) ? $options['aditionalValue'] : ''; |
|
25 | 25 | } |
26 | 26 | $optionsHtml .= "<option data-aditionalInput='" . ( count($aditionalInputs) - 1) . "' value ='{$key}'{$selected}>{$value['text']}</option>"; |
27 | - } else { |
|
27 | + } else { |
|
28 | 28 | $optionsHtml .= "<option value ='{$key}'{$selected}>{$value}</option>"; |
29 | - } |
|
29 | + } |
|
30 | 30 | } |
31 | 31 | ?> |
32 | 32 | <?= empty($options['noContainer']) ? '<div class="form-group">' : ''; ?> |
33 | 33 | <?= $label !== false ? "<label>{$label}" : ''; ?> |
34 | 34 | <?php |
35 | 35 | if ($label !== false && !empty($options['createBtn'])) { |
36 | - echo ' (<a href="" onclick="' . $options['createBtn']['onclick'] . ';this.disabled=true;return false;">' . $options['createBtn']['text'] . '</a>)'; |
|
36 | + echo ' (<a href="" onclick="' . $options['createBtn']['onclick'] . ';this.disabled=true;return false;">' . $options['createBtn']['text'] . '</a>)'; |
|
37 | 37 | } |
38 | 38 | ?> |
39 | 39 | <?= $label !== false ? "</label>" : ''; ?> |
@@ -42,18 +42,18 @@ discard block |
||
42 | 42 | </select> |
43 | 43 | <?php |
44 | 44 | foreach ($aditionalInputs as $key => $input) { |
45 | - $input['options']['noContainer'] = true; |
|
45 | + $input['options']['noContainer'] = true; |
|
46 | 46 | |
47 | - if ($key !== $showedInput) { |
|
47 | + if ($key !== $showedInput) { |
|
48 | 48 | $input['options']['disabled'] = true; |
49 | 49 | $input['options']['class'] = !empty($input['options']['class']) ? $input['options']['class'] . ' hidden' : 'hidden'; |
50 | - } else { |
|
50 | + } else { |
|
51 | 51 | $input['options']['value'] = empty($input['options']['value']) ? $aditionValue : $input['options']['value']; |
52 | - } |
|
53 | - if ($input['type'] == 'select') { |
|
52 | + } |
|
53 | + if ($input['type'] == 'select') { |
|
54 | 54 | $input['options']['values'] = \Ui\ActiveForm::getOptionsList($input); |
55 | - } |
|
56 | - $form->input($input['type'], empty($input['name']) ? $name . '[aditional]' : $input['name'], false, $input['options']); |
|
55 | + } |
|
56 | + $form->input($input['type'], empty($input['name']) ? $name . '[aditional]' : $input['name'], false, $input['options']); |
|
57 | 57 | } |
58 | 58 | ?> |
59 | 59 | <?= empty($options['noContainer']) ? '</div>' : ''; ?> |
60 | 60 | \ No newline at end of file |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | $showedInput = count($aditionalInputs) - 1; |
24 | 24 | $aditionValue = !empty($options['aditionalValue']) ? $options['aditionalValue'] : ''; |
25 | 25 | } |
26 | - $optionsHtml .= "<option data-aditionalInput='" . ( count($aditionalInputs) - 1) . "' value ='{$key}'{$selected}>{$value['text']}</option>"; |
|
26 | + $optionsHtml .= "<option data-aditionalInput='".(count($aditionalInputs) - 1)."' value ='{$key}'{$selected}>{$value['text']}</option>"; |
|
27 | 27 | } else { |
28 | 28 | $optionsHtml .= "<option value ='{$key}'{$selected}>{$value}</option>"; |
29 | 29 | } |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | <?= $label !== false ? "<label>{$label}" : ''; ?> |
34 | 34 | <?php |
35 | 35 | if ($label !== false && !empty($options['createBtn'])) { |
36 | - echo ' (<a href="" onclick="' . $options['createBtn']['onclick'] . ';this.disabled=true;return false;">' . $options['createBtn']['text'] . '</a>)'; |
|
36 | + echo ' (<a href="" onclick="'.$options['createBtn']['onclick'].';this.disabled=true;return false;">'.$options['createBtn']['text'].'</a>)'; |
|
37 | 37 | } |
38 | 38 | ?> |
39 | 39 | <?= $label !== false ? "</label>" : ''; ?> |
@@ -46,14 +46,14 @@ discard block |
||
46 | 46 | |
47 | 47 | if ($key !== $showedInput) { |
48 | 48 | $input['options']['disabled'] = true; |
49 | - $input['options']['class'] = !empty($input['options']['class']) ? $input['options']['class'] . ' hidden' : 'hidden'; |
|
49 | + $input['options']['class'] = !empty($input['options']['class']) ? $input['options']['class'].' hidden' : 'hidden'; |
|
50 | 50 | } else { |
51 | 51 | $input['options']['value'] = empty($input['options']['value']) ? $aditionValue : $input['options']['value']; |
52 | 52 | } |
53 | 53 | if ($input['type'] == 'select') { |
54 | 54 | $input['options']['values'] = \Ui\ActiveForm::getOptionsList($input); |
55 | 55 | } |
56 | - $form->input($input['type'], empty($input['name']) ? $name . '[aditional]' : $input['name'], false, $input['options']); |
|
56 | + $form->input($input['type'], empty($input['name']) ? $name.'[aditional]' : $input['name'], false, $input['options']); |
|
57 | 57 | } |
58 | 58 | ?> |
59 | 59 | <?= empty($options['noContainer']) ? '</div>' : ''; ?> |
60 | 60 | \ No newline at end of file |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | $this->formName = $form; |
48 | 48 | $this->form = \App::$cur->ui->getModelForm($this->modelName, $form); |
49 | 49 | if (empty($this->form)) { |
50 | - throw new \Exception('empty form ' . $form); |
|
50 | + throw new \Exception('empty form '.$form); |
|
51 | 51 | } |
52 | 52 | $this->inputs = $this->getInputs(); |
53 | 53 | } |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | $this->model->_params[$modelName::index()] = 0; |
83 | 83 | } |
84 | 84 | $relOptions['model']::fixPrefix($relOptions['col']); |
85 | - $inputs[$col] = new ActiveForm(new $relOptions['model']([ $relOptions['col'] => &$this->model->_params[$modelName::index()]]), $colPath[2]); |
|
85 | + $inputs[$col] = new ActiveForm(new $relOptions['model']([$relOptions['col'] => &$this->model->_params[$modelName::index()]]), $colPath[2]); |
|
86 | 86 | } |
87 | 87 | $inputs[$col]->parent = $this; |
88 | 88 | } elseif (!empty($modelName::$cols[$col])) { |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | |
96 | 96 | public function checkRequest($params = [], $ajax = false) { |
97 | 97 | if (!$this->checkAccess()) { |
98 | - $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->formName . '"'); |
|
98 | + $this->drawError('you not have access to "'.$this->modelName.'" manager with name: "'.$this->formName.'"'); |
|
99 | 99 | return []; |
100 | 100 | } |
101 | 101 | $successId = 0; |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | if (!empty($this->form['userGroupReadonly'][\Users\User::$cur->group_id]) && in_array($col, $this->form['userGroupReadonly'][\Users\User::$cur->group_id])) { |
127 | 127 | continue; |
128 | 128 | } |
129 | - $inputClassName = '\Ui\ActiveForm\Input\\' . ucfirst($param['type']); |
|
129 | + $inputClassName = '\Ui\ActiveForm\Input\\'.ucfirst($param['type']); |
|
130 | 130 | $input = new $inputClassName(); |
131 | 131 | $input->activeForm = $this; |
132 | 132 | $input->activeFormParams = $params; |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | if ($ajax) { |
172 | 172 | \Msg::show(); |
173 | 173 | } elseif (!empty($_GET['redirectUrl'])) { |
174 | - \Tools::redirect($_GET['redirectUrl'] . (!empty($_GET['dataManagerHash']) ? '#' . $_GET['dataManagerHash'] : '')); |
|
174 | + \Tools::redirect($_GET['redirectUrl'].(!empty($_GET['dataManagerHash']) ? '#'.$_GET['dataManagerHash'] : '')); |
|
175 | 175 | } |
176 | 176 | $successId = $this->model->pk(); |
177 | 177 | } |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | |
187 | 187 | public function draw($params = [], $ajax = false) { |
188 | 188 | if (!$this->checkAccess()) { |
189 | - $this->drawError('you not have access to "' . $this->modelName . '" form with name: "' . $this->formName . '"'); |
|
189 | + $this->drawError('you not have access to "'.$this->modelName.'" form with name: "'.$this->formName.'"'); |
|
190 | 190 | return []; |
191 | 191 | } |
192 | 192 | $form = new Form(!empty($this->form['formOptions']) ? $this->form['formOptions'] : []); |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | if (is_object($options)) { |
198 | 198 | $options->draw(); |
199 | 199 | } else { |
200 | - $inputClassName = '\Ui\ActiveForm\Input\\' . ucfirst($options['type']); |
|
200 | + $inputClassName = '\Ui\ActiveForm\Input\\'.ucfirst($options['type']); |
|
201 | 201 | $input = new $inputClassName(); |
202 | 202 | $input->form = $form; |
203 | 203 | $input->activeForm = $this; |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | } |
274 | 274 | foreach ($values as $key => $value) { |
275 | 275 | if (is_array($value) && !empty($value['input']) && empty($value['input']['noprefix'])) { |
276 | - $values[$key]['input']['name'] = $aditionalInputNamePrefix . "[{$value['input']['name']}]"; |
|
276 | + $values[$key]['input']['name'] = $aditionalInputNamePrefix."[{$value['input']['name']}]"; |
|
277 | 277 | } |
278 | 278 | } |
279 | 279 | return $values; |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | */ |
296 | 296 | public function checkAccess() { |
297 | 297 | if (empty($this->form)) { |
298 | - $this->drawError('"' . $this->modelName . '" form with name: "' . $this->formName . '" not found'); |
|
298 | + $this->drawError('"'.$this->modelName.'" form with name: "'.$this->formName.'" not found'); |
|
299 | 299 | return false; |
300 | 300 | } |
301 | 301 | if (\App::$cur->Access && !\App::$cur->Access->checkAccess($this)) { |
@@ -13,118 +13,118 @@ discard block |
||
13 | 13 | |
14 | 14 | class ActiveForm extends \Object { |
15 | 15 | |
16 | - public $model = null; |
|
17 | - public $modelName = ''; |
|
18 | - public $header = ""; |
|
19 | - public $action = ""; |
|
20 | - public $form = []; |
|
21 | - public $inputs = []; |
|
22 | - public $formName = 'noNameForm'; |
|
23 | - public $requestFormName = ''; |
|
24 | - public $requestFullFormName = ''; |
|
25 | - public $parent = null; |
|
16 | + public $model = null; |
|
17 | + public $modelName = ''; |
|
18 | + public $header = ""; |
|
19 | + public $action = ""; |
|
20 | + public $form = []; |
|
21 | + public $inputs = []; |
|
22 | + public $formName = 'noNameForm'; |
|
23 | + public $requestFormName = ''; |
|
24 | + public $requestFullFormName = ''; |
|
25 | + public $parent = null; |
|
26 | 26 | |
27 | - /** |
|
28 | - * |
|
29 | - * @param array|\Model $model |
|
30 | - * @param array|string $form |
|
31 | - */ |
|
32 | - public function __construct($model, $form = '') { |
|
27 | + /** |
|
28 | + * |
|
29 | + * @param array|\Model $model |
|
30 | + * @param array|string $form |
|
31 | + */ |
|
32 | + public function __construct($model, $form = '') { |
|
33 | 33 | if (is_array($model)) { |
34 | - $this->form = $model; |
|
35 | - if (is_string($form)) { |
|
34 | + $this->form = $model; |
|
35 | + if (is_string($form)) { |
|
36 | 36 | $this->formName = $form; |
37 | - } |
|
37 | + } |
|
38 | 38 | } else { |
39 | - $this->model = $model; |
|
40 | - $this->modelName = get_class($model); |
|
41 | - if (is_array($form)) { |
|
39 | + $this->model = $model; |
|
40 | + $this->modelName = get_class($model); |
|
41 | + if (is_array($form)) { |
|
42 | 42 | if (empty($form)) { |
43 | - throw new \Exception('empty form'); |
|
43 | + throw new \Exception('empty form'); |
|
44 | 44 | } |
45 | 45 | $this->form = $form; |
46 | - } else { |
|
46 | + } else { |
|
47 | 47 | $this->formName = $form; |
48 | 48 | $this->form = \App::$cur->ui->getModelForm($this->modelName, $form); |
49 | 49 | if (empty($this->form)) { |
50 | - throw new \Exception('empty form ' . $form); |
|
50 | + throw new \Exception('empty form ' . $form); |
|
51 | 51 | } |
52 | 52 | $this->inputs = $this->getInputs(); |
53 | - } |
|
53 | + } |
|
54 | 54 | } |
55 | 55 | $this->requestFormName = "ActiveForm_{$this->formName}"; |
56 | 56 | $modeName = $this->modelName; |
57 | 57 | |
58 | 58 | if (!empty($this->form['name'])) { |
59 | - $this->header = $this->form['name']; |
|
59 | + $this->header = $this->form['name']; |
|
60 | 60 | } elseif (!empty($modeName::$objectName)) { |
61 | - $this->header = $modeName::$objectName; |
|
61 | + $this->header = $modeName::$objectName; |
|
62 | 62 | } else { |
63 | - $this->header = $this->modelName; |
|
63 | + $this->header = $this->modelName; |
|
64 | + } |
|
64 | 65 | } |
65 | - } |
|
66 | 66 | |
67 | - public function getInputs() { |
|
67 | + public function getInputs() { |
|
68 | 68 | $inputs = !empty($this->form['inputs']) ? $this->form['inputs'] : []; |
69 | 69 | $modelName = $this->modelName; |
70 | 70 | foreach ($this->form['map'] as $row) { |
71 | - foreach ($row as $col) { |
|
71 | + foreach ($row as $col) { |
|
72 | 72 | if (!$col || !empty($inputs[$col])) { |
73 | - continue; |
|
73 | + continue; |
|
74 | 74 | } |
75 | 75 | if (strpos($col, 'form:') === 0) { |
76 | - $colPath = explode(':', $col); |
|
77 | - if ($this->model->{$colPath[1]}) { |
|
76 | + $colPath = explode(':', $col); |
|
77 | + if ($this->model->{$colPath[1]}) { |
|
78 | 78 | $inputs[$col] = new ActiveForm($this->model->{$colPath[1]}, $colPath[2]); |
79 | - } else { |
|
79 | + } else { |
|
80 | 80 | $relOptions = $modelName::getRelation($colPath[1]); |
81 | 81 | if (!isset($this->model->_params[$modelName::index()])) { |
82 | - $this->model->_params[$modelName::index()] = 0; |
|
82 | + $this->model->_params[$modelName::index()] = 0; |
|
83 | 83 | } |
84 | 84 | $relOptions['model']::fixPrefix($relOptions['col']); |
85 | 85 | $inputs[$col] = new ActiveForm(new $relOptions['model']([ $relOptions['col'] => &$this->model->_params[$modelName::index()]]), $colPath[2]); |
86 | - } |
|
87 | - $inputs[$col]->parent = $this; |
|
86 | + } |
|
87 | + $inputs[$col]->parent = $this; |
|
88 | 88 | } elseif (!empty($modelName::$cols[$col])) { |
89 | - $inputs[$col] = $modelName::$cols[$col]; |
|
89 | + $inputs[$col] = $modelName::$cols[$col]; |
|
90 | + } |
|
90 | 91 | } |
91 | - } |
|
92 | 92 | } |
93 | 93 | return $inputs; |
94 | - } |
|
94 | + } |
|
95 | 95 | |
96 | - public function checkRequest($params = [], $ajax = false) { |
|
96 | + public function checkRequest($params = [], $ajax = false) { |
|
97 | 97 | if (!$this->checkAccess()) { |
98 | - $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->formName . '"'); |
|
99 | - return []; |
|
98 | + $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->formName . '"'); |
|
99 | + return []; |
|
100 | 100 | } |
101 | 101 | $successId = 0; |
102 | 102 | if (!empty($_POST[$this->requestFormName][$this->modelName])) { |
103 | - $request = $_POST[$this->requestFormName][$this->modelName]; |
|
104 | - if ($this->model) { |
|
103 | + $request = $_POST[$this->requestFormName][$this->modelName]; |
|
104 | + if ($this->model) { |
|
105 | 105 | if (!empty($this->form['handler'])) { |
106 | - $modelName = $this->model; |
|
107 | - $modelName::{$this->form['handler']}($request); |
|
108 | - $text = 'Новый элемент был успешно добавлен'; |
|
109 | - \Msg::add($text, 'success'); |
|
110 | - \Msg::show(); |
|
106 | + $modelName = $this->model; |
|
107 | + $modelName::{$this->form['handler']}($request); |
|
108 | + $text = 'Новый элемент был успешно добавлен'; |
|
109 | + \Msg::add($text, 'success'); |
|
110 | + \Msg::show(); |
|
111 | 111 | } else { |
112 | - $presets = !empty($this->form['preset']) ? $this->form['preset'] : []; |
|
113 | - if (!empty($this->form['userGroupPreset'][\Users\User::$cur->group_id])) { |
|
112 | + $presets = !empty($this->form['preset']) ? $this->form['preset'] : []; |
|
113 | + if (!empty($this->form['userGroupPreset'][\Users\User::$cur->group_id])) { |
|
114 | 114 | $presets = array_merge($presets, $this->form['userGroupPreset'][\Users\User::$cur->group_id]); |
115 | - } |
|
116 | - $afterSave = []; |
|
117 | - $error = false; |
|
118 | - foreach ($this->inputs as $col => $param) { |
|
115 | + } |
|
116 | + $afterSave = []; |
|
117 | + $error = false; |
|
118 | + foreach ($this->inputs as $col => $param) { |
|
119 | 119 | if (!empty($presets[$col])) { |
120 | - continue; |
|
120 | + continue; |
|
121 | 121 | } |
122 | 122 | if (is_object($param)) { |
123 | - $afterSave[] = $param; |
|
124 | - continue; |
|
123 | + $afterSave[] = $param; |
|
124 | + continue; |
|
125 | 125 | } |
126 | 126 | if (!empty($this->form['userGroupReadonly'][\Users\User::$cur->group_id]) && in_array($col, $this->form['userGroupReadonly'][\Users\User::$cur->group_id])) { |
127 | - continue; |
|
127 | + continue; |
|
128 | 128 | } |
129 | 129 | $inputClassName = '\Ui\ActiveForm\Input\\' . ucfirst($param['type']); |
130 | 130 | $input = new $inputClassName(); |
@@ -134,189 +134,189 @@ discard block |
||
134 | 134 | $input->colName = $col; |
135 | 135 | $input->colParams = $param; |
136 | 136 | try { |
137 | - $input->validate($request); |
|
138 | - $input->parseRequest($request); |
|
137 | + $input->validate($request); |
|
138 | + $input->parseRequest($request); |
|
139 | 139 | } catch (\Exception $exc) { |
140 | - \Msg::add($exc->getMessage(), 'danger'); |
|
141 | - $error = true; |
|
140 | + \Msg::add($exc->getMessage(), 'danger'); |
|
141 | + $error = true; |
|
142 | + } |
|
142 | 143 | } |
143 | - } |
|
144 | - if (!$error && empty($_GET['notSave'])) { |
|
144 | + if (!$error && empty($_GET['notSave'])) { |
|
145 | 145 | foreach ($presets as $col => $preset) { |
146 | - if (!empty($preset['value'])) { |
|
146 | + if (!empty($preset['value'])) { |
|
147 | 147 | $this->model->$col = $preset['value']; |
148 | - } elseif (!empty($preset['userCol'])) { |
|
148 | + } elseif (!empty($preset['userCol'])) { |
|
149 | 149 | if (strpos($preset['userCol'], ':')) { |
150 | - $rel = substr($preset['userCol'], 0, strpos($preset['userCol'], ':')); |
|
151 | - $param = substr($preset['userCol'], strpos($preset['userCol'], ':') + 1); |
|
152 | - $this->model->$col = \Users\User::$cur->$rel->$param; |
|
150 | + $rel = substr($preset['userCol'], 0, strpos($preset['userCol'], ':')); |
|
151 | + $param = substr($preset['userCol'], strpos($preset['userCol'], ':') + 1); |
|
152 | + $this->model->$col = \Users\User::$cur->$rel->$param; |
|
153 | 153 | } else { |
154 | - $this->model->$col = \Users\User::$cur->{$preset['userCol']}; |
|
154 | + $this->model->$col = \Users\User::$cur->{$preset['userCol']}; |
|
155 | + } |
|
155 | 156 | } |
156 | - } |
|
157 | 157 | } |
158 | 158 | if (!$this->parent) { |
159 | - if (!empty($this->form['successText'])) { |
|
159 | + if (!empty($this->form['successText'])) { |
|
160 | 160 | $text = $this->form['successText']; |
161 | - } else { |
|
161 | + } else { |
|
162 | 162 | $text = $this->model->pk() ? 'Изменения были успешно сохранены' : 'Новый элемент был успешно добавлен'; |
163 | - } |
|
164 | - \Msg::add($text, 'success'); |
|
163 | + } |
|
164 | + \Msg::add($text, 'success'); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | $this->model->save(!empty($params['dataManagerParams']) ? $params['dataManagerParams'] : []); |
168 | 168 | foreach ($afterSave as $form) { |
169 | - $form->checkRequest(); |
|
169 | + $form->checkRequest(); |
|
170 | 170 | } |
171 | 171 | if ($ajax) { |
172 | - \Msg::show(); |
|
172 | + \Msg::show(); |
|
173 | 173 | } elseif (!empty($_GET['redirectUrl'])) { |
174 | - \Tools::redirect($_GET['redirectUrl'] . (!empty($_GET['dataManagerHash']) ? '#' . $_GET['dataManagerHash'] : '')); |
|
174 | + \Tools::redirect($_GET['redirectUrl'] . (!empty($_GET['dataManagerHash']) ? '#' . $_GET['dataManagerHash'] : '')); |
|
175 | 175 | } |
176 | 176 | $successId = $this->model->pk(); |
177 | - } |
|
177 | + } |
|
178 | + } |
|
178 | 179 | } |
179 | - } |
|
180 | - if (!is_array($params) && is_callable($params)) { |
|
180 | + if (!is_array($params) && is_callable($params)) { |
|
181 | 181 | $params($request); |
182 | - } |
|
182 | + } |
|
183 | 183 | } |
184 | 184 | return $successId; |
185 | - } |
|
185 | + } |
|
186 | 186 | |
187 | - public function draw($params = [], $ajax = false) { |
|
187 | + public function draw($params = [], $ajax = false) { |
|
188 | 188 | if (!$this->checkAccess()) { |
189 | - $this->drawError('you not have access to "' . $this->modelName . '" form with name: "' . $this->formName . '"'); |
|
190 | - return []; |
|
189 | + $this->drawError('you not have access to "' . $this->modelName . '" form with name: "' . $this->formName . '"'); |
|
190 | + return []; |
|
191 | 191 | } |
192 | 192 | $form = new Form(!empty($this->form['formOptions']) ? $this->form['formOptions'] : []); |
193 | 193 | \App::$cur->view->widget('Ui\ActiveForm', ['form' => $form, 'activeForm' => $this, 'ajax' => $ajax, 'params' => $params]); |
194 | - } |
|
194 | + } |
|
195 | 195 | |
196 | - public function drawCol($colName, $options, $form, $params = []) { |
|
196 | + public function drawCol($colName, $options, $form, $params = []) { |
|
197 | 197 | if (is_object($options)) { |
198 | - $options->draw(); |
|
198 | + $options->draw(); |
|
199 | 199 | } else { |
200 | - $inputClassName = '\Ui\ActiveForm\Input\\' . ucfirst($options['type']); |
|
201 | - $input = new $inputClassName(); |
|
202 | - $input->form = $form; |
|
203 | - $input->activeForm = $this; |
|
204 | - $input->activeFormParams = $params; |
|
205 | - $input->modelName = $this->modelName; |
|
206 | - $input->colName = $colName; |
|
207 | - $input->colParams = $options; |
|
208 | - $input->options = !empty($options['options']) ? $options['options'] : []; |
|
209 | - $input->draw(); |
|
200 | + $inputClassName = '\Ui\ActiveForm\Input\\' . ucfirst($options['type']); |
|
201 | + $input = new $inputClassName(); |
|
202 | + $input->form = $form; |
|
203 | + $input->activeForm = $this; |
|
204 | + $input->activeFormParams = $params; |
|
205 | + $input->modelName = $this->modelName; |
|
206 | + $input->colName = $colName; |
|
207 | + $input->colParams = $options; |
|
208 | + $input->options = !empty($options['options']) ? $options['options'] : []; |
|
209 | + $input->draw(); |
|
210 | 210 | } |
211 | 211 | return true; |
212 | - } |
|
212 | + } |
|
213 | 213 | |
214 | - public static function getOptionsList($inputParams, $params = [], $modelName = '', $aditionalInputNamePrefix = 'aditional', $options = []) { |
|
214 | + public static function getOptionsList($inputParams, $params = [], $modelName = '', $aditionalInputNamePrefix = 'aditional', $options = []) { |
|
215 | 215 | $values = []; |
216 | 216 | switch ($inputParams['source']) { |
217 | - case 'model': |
|
217 | + case 'model': |
|
218 | 218 | $values = $inputParams['model']::getList(['forSelect' => true]); |
219 | 219 | break; |
220 | - case 'array': |
|
220 | + case 'array': |
|
221 | 221 | $values = $inputParams['sourceArray']; |
222 | 222 | break; |
223 | - case 'method': |
|
223 | + case 'method': |
|
224 | 224 | if (!empty($inputParams['params'])) { |
225 | - $values = call_user_func_array([\App::$cur->$inputParams['module'], $inputParams['method']], $inputParams['params']); |
|
225 | + $values = call_user_func_array([\App::$cur->$inputParams['module'], $inputParams['method']], $inputParams['params']); |
|
226 | 226 | } else { |
227 | - $values = \App::$cur->$inputParams['module']->$inputParams['method'](); |
|
227 | + $values = \App::$cur->$inputParams['module']->$inputParams['method'](); |
|
228 | 228 | } |
229 | 229 | break; |
230 | - case 'relation': |
|
230 | + case 'relation': |
|
231 | 231 | if (!$modelName) { |
232 | - return []; |
|
232 | + return []; |
|
233 | 233 | } |
234 | 234 | $relation = $modelName::getRelation($inputParams['relation']); |
235 | 235 | if (!empty($params['dataManagerParams']['appType'])) { |
236 | - $options['appType'] = $params['dataManagerParams']['appType']; |
|
236 | + $options['appType'] = $params['dataManagerParams']['appType']; |
|
237 | 237 | } |
238 | 238 | $items = []; |
239 | 239 | if (class_exists($relation['model'])) { |
240 | - $filters = $relation['model']::managerFilters(); |
|
241 | - if (!empty($filters['getRows']['where'])) { |
|
240 | + $filters = $relation['model']::managerFilters(); |
|
241 | + if (!empty($filters['getRows']['where'])) { |
|
242 | 242 | $options['where'][] = $filters['getRows']['where']; |
243 | - } |
|
244 | - if (!empty($relation['where'])) { |
|
243 | + } |
|
244 | + if (!empty($relation['where'])) { |
|
245 | 245 | $options['where'][] = $relation['where']; |
246 | - } |
|
247 | - if (!empty($relation['order'])) { |
|
246 | + } |
|
247 | + if (!empty($relation['order'])) { |
|
248 | 248 | $options['order'] = $relation['order']; |
249 | - } |
|
250 | - if (!empty($inputParams['itemName'])) { |
|
249 | + } |
|
250 | + if (!empty($inputParams['itemName'])) { |
|
251 | 251 | $options['itemName'] = $inputParams['itemName']; |
252 | - } |
|
253 | - $items = $relation['model']::getList($options); |
|
252 | + } |
|
253 | + $items = $relation['model']::getList($options); |
|
254 | 254 | } |
255 | 255 | if (!empty($params['noEmptyValue'])) { |
256 | - $values = []; |
|
256 | + $values = []; |
|
257 | 257 | } else { |
258 | - $values = [0 => 'Не задано']; |
|
258 | + $values = [0 => 'Не задано']; |
|
259 | 259 | } |
260 | 260 | foreach ($items as $key => $item) { |
261 | - if (!empty($inputParams['showCol'])) { |
|
261 | + if (!empty($inputParams['showCol'])) { |
|
262 | 262 | if (is_array($inputParams['showCol'])) { |
263 | - switch ($inputParams['showCol']['type']) { |
|
263 | + switch ($inputParams['showCol']['type']) { |
|
264 | 264 | case 'staticMethod': |
265 | 265 | $values[$key] = $inputParams['showCol']['class']::{$inputParams['showCol']['method']}($item); |
266 | - break; |
|
267 | - } |
|
266 | + break; |
|
267 | + } |
|
268 | 268 | } else { |
269 | - $values[$key] = $item->$inputParams['showCol']; |
|
269 | + $values[$key] = $item->$inputParams['showCol']; |
|
270 | 270 | } |
271 | - } else { |
|
271 | + } else { |
|
272 | 272 | $values[$key] = $item->name(); |
273 | - } |
|
273 | + } |
|
274 | 274 | } |
275 | 275 | break; |
276 | 276 | } |
277 | 277 | foreach ($values as $key => $value) { |
278 | - if (is_array($value) && !empty($value['input']) && empty($value['input']['noprefix'])) { |
|
278 | + if (is_array($value) && !empty($value['input']) && empty($value['input']['noprefix'])) { |
|
279 | 279 | $values[$key]['input']['name'] = $aditionalInputNamePrefix . "[{$value['input']['name']}]"; |
280 | - } |
|
280 | + } |
|
281 | 281 | } |
282 | 282 | return $values; |
283 | - } |
|
283 | + } |
|
284 | 284 | |
285 | - /** |
|
286 | - * Draw error message |
|
287 | - * |
|
288 | - * @param string $errorText |
|
289 | - */ |
|
290 | - public function drawError($errorText) { |
|
285 | + /** |
|
286 | + * Draw error message |
|
287 | + * |
|
288 | + * @param string $errorText |
|
289 | + */ |
|
290 | + public function drawError($errorText) { |
|
291 | 291 | echo $errorText; |
292 | - } |
|
292 | + } |
|
293 | 293 | |
294 | - /** |
|
295 | - * Check access cur user to form with name in param and $model |
|
296 | - * |
|
297 | - * @return boolean |
|
298 | - */ |
|
299 | - public function checkAccess() { |
|
294 | + /** |
|
295 | + * Check access cur user to form with name in param and $model |
|
296 | + * |
|
297 | + * @return boolean |
|
298 | + */ |
|
299 | + public function checkAccess() { |
|
300 | 300 | if (empty($this->form)) { |
301 | - $this->drawError('"' . $this->modelName . '" form with name: "' . $this->formName . '" not found'); |
|
302 | - return false; |
|
301 | + $this->drawError('"' . $this->modelName . '" form with name: "' . $this->formName . '" not found'); |
|
302 | + return false; |
|
303 | 303 | } |
304 | 304 | if (\App::$cur->Access && !\App::$cur->Access->checkAccess($this)) { |
305 | - return false; |
|
305 | + return false; |
|
306 | 306 | } |
307 | 307 | if (!empty($this->form['options']['access']['apps']) && !in_array(\App::$cur->name, $this->form['options']['access']['apps'])) { |
308 | - return false; |
|
308 | + return false; |
|
309 | 309 | } |
310 | 310 | if (!empty($this->form['options']['access']['groups']) && in_array(\Users\User::$cur->group_id, $this->form['options']['access']['groups'])) { |
311 | - return true; |
|
311 | + return true; |
|
312 | 312 | } |
313 | 313 | if ($this->model && !empty($this->form['options']['access']['self']) && \Users\User::$cur->id == $this->model->user_id) { |
314 | - return true; |
|
314 | + return true; |
|
315 | 315 | } |
316 | 316 | if ($this->formName == 'manager' && !\Users\User::$cur->isAdmin()) { |
317 | - return false; |
|
317 | + return false; |
|
318 | 318 | } |
319 | 319 | return true; |
320 | - } |
|
320 | + } |
|
321 | 321 | |
322 | 322 | } |
@@ -13,15 +13,15 @@ discard block |
||
13 | 13 | |
14 | 14 | class Input extends \Object { |
15 | 15 | |
16 | - public $form = null; |
|
17 | - public $activeForm = null; |
|
18 | - public $activeFormParams = []; |
|
19 | - public $modelName = ''; |
|
20 | - public $colName = ''; |
|
21 | - public $colParams = []; |
|
22 | - public $options = []; |
|
16 | + public $form = null; |
|
17 | + public $activeForm = null; |
|
18 | + public $activeFormParams = []; |
|
19 | + public $modelName = ''; |
|
20 | + public $colName = ''; |
|
21 | + public $colParams = []; |
|
22 | + public $options = []; |
|
23 | 23 | |
24 | - public function draw() { |
|
24 | + public function draw() { |
|
25 | 25 | $inputName = $this->colName(); |
26 | 26 | $inputLabel = $this->colLabel(); |
27 | 27 | |
@@ -31,78 +31,78 @@ discard block |
||
31 | 31 | |
32 | 32 | $preset = $this->preset(); |
33 | 33 | if ($preset !== null) { |
34 | - $inputOptions['disabled'] = true; |
|
35 | - $this->form->input('hidden', $inputName, '', $inputOptions); |
|
36 | - return true; |
|
34 | + $inputOptions['disabled'] = true; |
|
35 | + $this->form->input('hidden', $inputName, '', $inputOptions); |
|
36 | + return true; |
|
37 | 37 | } |
38 | 38 | $classPath = explode('\\', get_called_class()); |
39 | 39 | $inputType = lcfirst(array_pop($classPath)); |
40 | 40 | $this->form->input($inputType, $inputName, $inputLabel, $inputOptions); |
41 | 41 | return true; |
42 | - } |
|
42 | + } |
|
43 | 43 | |
44 | - public function parseRequest($request) { |
|
44 | + public function parseRequest($request) { |
|
45 | 45 | $colName = empty($this->colParams['col']) ? $this->colName : $this->colParams['col']; |
46 | 46 | if (isset($request[$this->colName])) { |
47 | - $this->activeForm->model->{$colName} = $request[$this->colName]; |
|
47 | + $this->activeForm->model->{$colName} = $request[$this->colName]; |
|
48 | 48 | } else { |
49 | - $this->activeForm->model->{$colName} = 0; |
|
50 | - $this->activeForm->model->{$colName} = ''; |
|
49 | + $this->activeForm->model->{$colName} = 0; |
|
50 | + $this->activeForm->model->{$colName} = ''; |
|
51 | + } |
|
51 | 52 | } |
52 | - } |
|
53 | 53 | |
54 | - public function value() { |
|
54 | + public function value() { |
|
55 | 55 | $value = isset($this->colParams['default']) ? $this->colParams['default'] : ''; |
56 | 56 | if ($this->activeForm) { |
57 | - $colName = empty($this->colParams['col']) ? $this->colName : $this->colParams['col']; |
|
58 | - $value = ($this->activeForm && $this->activeForm->model && isset($this->activeForm->model->{$colName})) ? $this->activeForm->model->{$colName} : $value; |
|
57 | + $colName = empty($this->colParams['col']) ? $this->colName : $this->colParams['col']; |
|
58 | + $value = ($this->activeForm && $this->activeForm->model && isset($this->activeForm->model->{$colName})) ? $this->activeForm->model->{$colName} : $value; |
|
59 | 59 | } |
60 | 60 | return $value; |
61 | - } |
|
61 | + } |
|
62 | 62 | |
63 | - public function preset() { |
|
63 | + public function preset() { |
|
64 | 64 | $preset = !empty($this->activeForm->form['preset'][$this->colName]) ? $this->activeForm->form['preset'][$this->colName] : []; |
65 | 65 | if (!empty($this->activeForm->form['userGroupPreset'][\Users\User::$cur->group_id][$this->colName])) { |
66 | - $preset = array_merge($preset, $this->activeForm->form['userGroupPreset'][\Users\User::$cur->group_id][$this->colName]); |
|
66 | + $preset = array_merge($preset, $this->activeForm->form['userGroupPreset'][\Users\User::$cur->group_id][$this->colName]); |
|
67 | 67 | } |
68 | 68 | if ($preset) { |
69 | - $value = ''; |
|
70 | - if (!empty($preset['value'])) { |
|
69 | + $value = ''; |
|
70 | + if (!empty($preset['value'])) { |
|
71 | 71 | $value = $preset['value']; |
72 | - } elseif (!empty($preset['userCol'])) { |
|
72 | + } elseif (!empty($preset['userCol'])) { |
|
73 | 73 | if (strpos($preset['userCol'], ':')) { |
74 | - $rel = substr($preset['userCol'], 0, strpos($preset['userCol'], ':')); |
|
75 | - $param = substr($preset['userCol'], strpos($preset['userCol'], ':') + 1); |
|
76 | - $value = \Users\User::$cur->$rel->$param; |
|
74 | + $rel = substr($preset['userCol'], 0, strpos($preset['userCol'], ':')); |
|
75 | + $param = substr($preset['userCol'], strpos($preset['userCol'], ':') + 1); |
|
76 | + $value = \Users\User::$cur->$rel->$param; |
|
77 | 77 | } |
78 | - } |
|
79 | - return $value; |
|
78 | + } |
|
79 | + return $value; |
|
80 | 80 | } |
81 | 81 | return null; |
82 | - } |
|
82 | + } |
|
83 | 83 | |
84 | - public function colName() { |
|
84 | + public function colName() { |
|
85 | 85 | return "{$this->activeForm->requestFormName}[{$this->activeForm->modelName}]".(stristr($this->colName, '[')?$this->colName:"[{$this->colName}]"); |
86 | - } |
|
86 | + } |
|
87 | 87 | |
88 | - public function colLabel() { |
|
88 | + public function colLabel() { |
|
89 | 89 | $modelName = $this->modelName; |
90 | 90 | return isset($this->colParams['label']) ? $this->colParams['label'] : (($this->activeForm->model && !empty($modelName::$labels[$this->colName])) ? $modelName::$labels[$this->colName] : $this->colName); |
91 | - } |
|
91 | + } |
|
92 | 92 | |
93 | - public function readOnly() { |
|
93 | + public function readOnly() { |
|
94 | 94 | return !empty($this->activeForm->form['userGroupReadonly'][\Users\User::$cur->group_id]) && in_array($this->colName, $this->activeForm->form['userGroupReadonly'][\Users\User::$cur->group_id]); |
95 | - } |
|
95 | + } |
|
96 | 96 | |
97 | - public function validate(&$request) { |
|
97 | + public function validate(&$request) { |
|
98 | 98 | if (empty($request[$this->colName]) && !empty($this->colParams['required'])) { |
99 | - throw new \Exception('Вы не заполнили: ' . $this->colLabel()); |
|
99 | + throw new \Exception('Вы не заполнили: ' . $this->colLabel()); |
|
100 | 100 | } |
101 | 101 | if (!empty($this->colParams['validator'])) { |
102 | - $modelName = $this->modelName; |
|
103 | - $validator = $modelName::validator($this->colParams['validator']); |
|
104 | - $validator($this->activeForm, $request); |
|
102 | + $modelName = $this->modelName; |
|
103 | + $validator = $modelName::validator($this->colParams['validator']); |
|
104 | + $validator($this->activeForm, $request); |
|
105 | + } |
|
105 | 106 | } |
106 | - } |
|
107 | 107 | |
108 | 108 | } |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | } |
84 | 84 | |
85 | 85 | public function colName() { |
86 | - return "{$this->activeForm->requestFormName}[{$this->activeForm->modelName}]" . (stristr($this->colName, '[') ? $this->colName : "[{$this->colName}]"); |
|
86 | + return "{$this->activeForm->requestFormName}[{$this->activeForm->modelName}]".(stristr($this->colName, '[') ? $this->colName : "[{$this->colName}]"); |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | public function colLabel() { |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | |
98 | 98 | public function validate(&$request) { |
99 | 99 | if (empty($request[$this->colName]) && !empty($this->colParams['required'])) { |
100 | - throw new \Exception('Вы не заполнили: ' . $this->colLabel()); |
|
100 | + throw new \Exception('Вы не заполнили: '.$this->colLabel()); |
|
101 | 101 | } |
102 | 102 | if (!empty($this->colParams['validator'])) { |
103 | 103 | $modelName = $this->modelName; |
@@ -10,28 +10,28 @@ discard block |
||
10 | 10 | */ |
11 | 11 | class EcommerceController extends adminController { |
12 | 12 | |
13 | - public function dashboardAction() { |
|
13 | + public function dashboardAction() { |
|
14 | 14 | $this->view->setTitle('Онлайн магазин'); |
15 | 15 | $forms = \Ecommerce\Item::$magicForms; |
16 | 16 | \Ecommerce\Item::$forms['simpleItem']['handler'](); |
17 | 17 | $this->view->page(); |
18 | - } |
|
18 | + } |
|
19 | 19 | |
20 | - public function configureAction() { |
|
20 | + public function configureAction() { |
|
21 | 21 | if (!empty($_POST['config'])) { |
22 | - $config = App::$cur->ecommerce->config; |
|
23 | - $config['view_empty_warehouse'] = empty($_POST['config']['view_empty_warehouse']) ? false : true; |
|
24 | - $config['view_empty_image'] = empty($_POST['config']['view_empty_image']) ? false : true; |
|
25 | - $config['sell_empty_warehouse'] = empty($_POST['config']['sell_empty_warehouse']) ? false : true; |
|
26 | - $config['sell_over_warehouse'] = empty($_POST['config']['sell_over_warehouse']) ? false : true; |
|
27 | - $config['notify_mail'] = $_POST['config']['notify_mail']; |
|
28 | - $config['defaultCategoryView'] = $_POST['config']['defaultCategoryView']; |
|
29 | - $config['defaultCurrency'] = $_POST['config']['defaultCurrency']; |
|
30 | - $config['orderPrefix'] = $_POST['config']['orderPrefix']; |
|
31 | - $config['show_zero_price'] = empty($_POST['config']['show_zero_price']) ? false : true; |
|
32 | - $config['show_without_price'] = empty($_POST['config']['show_without_price']) ? false : true; |
|
33 | - Config::save('module', $config, 'Ecommerce'); |
|
34 | - Tools::redirect('/admin/ecommerce/configure', 'Настройки были изменены', 'success'); |
|
22 | + $config = App::$cur->ecommerce->config; |
|
23 | + $config['view_empty_warehouse'] = empty($_POST['config']['view_empty_warehouse']) ? false : true; |
|
24 | + $config['view_empty_image'] = empty($_POST['config']['view_empty_image']) ? false : true; |
|
25 | + $config['sell_empty_warehouse'] = empty($_POST['config']['sell_empty_warehouse']) ? false : true; |
|
26 | + $config['sell_over_warehouse'] = empty($_POST['config']['sell_over_warehouse']) ? false : true; |
|
27 | + $config['notify_mail'] = $_POST['config']['notify_mail']; |
|
28 | + $config['defaultCategoryView'] = $_POST['config']['defaultCategoryView']; |
|
29 | + $config['defaultCurrency'] = $_POST['config']['defaultCurrency']; |
|
30 | + $config['orderPrefix'] = $_POST['config']['orderPrefix']; |
|
31 | + $config['show_zero_price'] = empty($_POST['config']['show_zero_price']) ? false : true; |
|
32 | + $config['show_without_price'] = empty($_POST['config']['show_without_price']) ? false : true; |
|
33 | + Config::save('module', $config, 'Ecommerce'); |
|
34 | + Tools::redirect('/admin/ecommerce/configure', 'Настройки были изменены', 'success'); |
|
35 | 35 | } |
36 | 36 | $managers = [ |
37 | 37 | 'Ecommerce\Delivery', |
@@ -51,51 +51,51 @@ discard block |
||
51 | 51 | ]; |
52 | 52 | $this->view->setTitle('Настройки магазина'); |
53 | 53 | $this->view->page(['data' => compact('managers')]); |
54 | - } |
|
54 | + } |
|
55 | 55 | |
56 | - public function reBlockIndexAction() { |
|
56 | + public function reBlockIndexAction() { |
|
57 | 57 | set_time_limit(0); |
58 | 58 | $carts = Cart::getList(); |
59 | 59 | foreach ($carts as $cart) { |
60 | - $cart->save(); |
|
60 | + $cart->save(); |
|
61 | 61 | } |
62 | 62 | Tools::redirect('/admin/ecommerce/configure', 'Данные о блокировках обновлены'); |
63 | - } |
|
63 | + } |
|
64 | 64 | |
65 | - public function reSearchIndexAction($i = 0) { |
|
65 | + public function reSearchIndexAction($i = 0) { |
|
66 | 66 | set_time_limit(0); |
67 | 67 | $count = 100; |
68 | 68 | $items = Ecommerce\Item::getList(['start' => $i * $count, 'limit' => $count]); |
69 | 69 | if (!$items) { |
70 | - Tools::redirect('/admin/ecommerce/configure', 'Поисковый индекс обновлен'); |
|
70 | + Tools::redirect('/admin/ecommerce/configure', 'Поисковый индекс обновлен'); |
|
71 | 71 | } else { |
72 | - $i++; |
|
73 | - foreach ($items as $key => $item) { |
|
72 | + $i++; |
|
73 | + foreach ($items as $key => $item) { |
|
74 | 74 | $item->save(); |
75 | 75 | unset($items[$key]); |
76 | 76 | unset($item); |
77 | - } |
|
78 | - echo 'Происходит процесс индексации: проиндексировано ' . $i * $count; |
|
79 | - Tools::redirect('/admin/ecommerce/reSearchIndex/' . $i); |
|
77 | + } |
|
78 | + echo 'Происходит процесс индексации: проиндексировано ' . $i * $count; |
|
79 | + Tools::redirect('/admin/ecommerce/reSearchIndex/' . $i); |
|
80 | + } |
|
80 | 81 | } |
81 | - } |
|
82 | 82 | |
83 | - public function newOrdersSubscribeAction() { |
|
83 | + public function newOrdersSubscribeAction() { |
|
84 | 84 | $this->Notifications->subscribe('Ecommerce-orders'); |
85 | - } |
|
85 | + } |
|
86 | 86 | |
87 | - public function closeCartAction($cartId = 0) { |
|
87 | + public function closeCartAction($cartId = 0) { |
|
88 | 88 | $cart = Ecommerce\Cart::get((int) $cartId); |
89 | 89 | $result = new Server\Result(); |
90 | 90 | if ($cart && $cart->cart_status_id != 5) { |
91 | - $cart->cart_status_id = 5; |
|
92 | - $cart->save(); |
|
93 | - $result->successMsg = 'Заказ был завершен'; |
|
94 | - $result->send(); |
|
91 | + $cart->cart_status_id = 5; |
|
92 | + $cart->save(); |
|
93 | + $result->successMsg = 'Заказ был завершен'; |
|
94 | + $result->send(); |
|
95 | 95 | } |
96 | 96 | $result->success = false; |
97 | 97 | $result->content = 'Такая корзина не найдена'; |
98 | 98 | $result->send(); |
99 | - } |
|
99 | + } |
|
100 | 100 | |
101 | 101 | } |
@@ -75,8 +75,8 @@ |
||
75 | 75 | unset($items[$key]); |
76 | 76 | unset($item); |
77 | 77 | } |
78 | - echo 'Происходит процесс индексации: проиндексировано ' . $i * $count; |
|
79 | - Tools::redirect('/admin/ecommerce/reSearchIndex/' . $i); |
|
78 | + echo 'Происходит процесс индексации: проиндексировано '.$i * $count; |
|
79 | + Tools::redirect('/admin/ecommerce/reSearchIndex/'.$i); |
|
80 | 80 | } |
81 | 81 | } |
82 | 82 |
@@ -13,57 +13,57 @@ discard block |
||
13 | 13 | |
14 | 14 | class Item extends \Model { |
15 | 15 | |
16 | - public static $categoryModel = 'Ecommerce\Category'; |
|
17 | - public static $objectName = 'Товар'; |
|
18 | - public static $labels = [ |
|
19 | - 'name' => 'Название', |
|
20 | - 'alias' => 'Алиас', |
|
21 | - 'category_id' => 'Раздел', |
|
22 | - 'description' => 'Описание', |
|
23 | - 'item_type_id' => 'Тип товара', |
|
24 | - 'image_file_id' => 'Изображение', |
|
25 | - 'best' => 'Лучшее предложение', |
|
26 | - 'options' => 'Параметры', |
|
27 | - 'offers' => 'Торговые предложения', |
|
28 | - 'widget' => 'Виджет для отображения в каталоге', |
|
29 | - 'view' => 'Шаблон для отображения полной информации', |
|
30 | - 'deleted' => 'Удален', |
|
31 | - 'imgs' => 'Фото' |
|
32 | - ]; |
|
33 | - public static $cols = [ |
|
34 | - //Основные параметры |
|
35 | - 'category_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'category'], |
|
36 | - 'image_file_id' => ['type' => 'image'], |
|
37 | - 'name' => ['type' => 'text'], |
|
38 | - 'alias' => ['type' => 'text'], |
|
39 | - 'description' => ['type' => 'html'], |
|
40 | - 'item_type_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'type'], |
|
41 | - 'best' => ['type' => 'bool'], |
|
42 | - 'deleted' => ['type' => 'bool'], |
|
43 | - //Системные |
|
44 | - 'user_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'user'], |
|
45 | - 'weight' => ['type' => 'number'], |
|
46 | - 'sales' => ['type' => 'number'], |
|
47 | - 'imported' => ['type' => 'text'], |
|
48 | - 'tree_path' => ['type' => 'text'], |
|
49 | - 'search_index' => ['type' => 'text'], |
|
50 | - 'date_create' => ['type' => 'dateTime'], |
|
51 | - 'widget' => ['type' => 'text'], |
|
52 | - 'view' => ['type' => 'text'], |
|
53 | - //Менеджеры |
|
54 | - 'options' => ['type' => 'dataManager', 'relation' => 'options'], |
|
55 | - 'offers' => ['type' => 'dataManager', 'relation' => 'offers'], |
|
56 | - 'imgs' => ['type' => 'dataManager', 'relation' => 'images'], |
|
57 | - ]; |
|
16 | + public static $categoryModel = 'Ecommerce\Category'; |
|
17 | + public static $objectName = 'Товар'; |
|
18 | + public static $labels = [ |
|
19 | + 'name' => 'Название', |
|
20 | + 'alias' => 'Алиас', |
|
21 | + 'category_id' => 'Раздел', |
|
22 | + 'description' => 'Описание', |
|
23 | + 'item_type_id' => 'Тип товара', |
|
24 | + 'image_file_id' => 'Изображение', |
|
25 | + 'best' => 'Лучшее предложение', |
|
26 | + 'options' => 'Параметры', |
|
27 | + 'offers' => 'Торговые предложения', |
|
28 | + 'widget' => 'Виджет для отображения в каталоге', |
|
29 | + 'view' => 'Шаблон для отображения полной информации', |
|
30 | + 'deleted' => 'Удален', |
|
31 | + 'imgs' => 'Фото' |
|
32 | + ]; |
|
33 | + public static $cols = [ |
|
34 | + //Основные параметры |
|
35 | + 'category_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'category'], |
|
36 | + 'image_file_id' => ['type' => 'image'], |
|
37 | + 'name' => ['type' => 'text'], |
|
38 | + 'alias' => ['type' => 'text'], |
|
39 | + 'description' => ['type' => 'html'], |
|
40 | + 'item_type_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'type'], |
|
41 | + 'best' => ['type' => 'bool'], |
|
42 | + 'deleted' => ['type' => 'bool'], |
|
43 | + //Системные |
|
44 | + 'user_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'user'], |
|
45 | + 'weight' => ['type' => 'number'], |
|
46 | + 'sales' => ['type' => 'number'], |
|
47 | + 'imported' => ['type' => 'text'], |
|
48 | + 'tree_path' => ['type' => 'text'], |
|
49 | + 'search_index' => ['type' => 'text'], |
|
50 | + 'date_create' => ['type' => 'dateTime'], |
|
51 | + 'widget' => ['type' => 'text'], |
|
52 | + 'view' => ['type' => 'text'], |
|
53 | + //Менеджеры |
|
54 | + 'options' => ['type' => 'dataManager', 'relation' => 'options'], |
|
55 | + 'offers' => ['type' => 'dataManager', 'relation' => 'offers'], |
|
56 | + 'imgs' => ['type' => 'dataManager', 'relation' => 'images'], |
|
57 | + ]; |
|
58 | 58 | |
59 | - public static function simpleItemHandler($request) { |
|
59 | + public static function simpleItemHandler($request) { |
|
60 | 60 | if ($request) { |
61 | - $item = new Item(); |
|
62 | - $item->name = $request['name']; |
|
63 | - $item->description = $request['description']; |
|
64 | - $item->category_id = $request['category']; |
|
65 | - $item->save(); |
|
66 | - if (!empty($_FILES['ActiveForm_simpleItem']['tmp_name']['Ecommerce\Item']['image'])) { |
|
61 | + $item = new Item(); |
|
62 | + $item->name = $request['name']; |
|
63 | + $item->description = $request['description']; |
|
64 | + $item->category_id = $request['category']; |
|
65 | + $item->save(); |
|
66 | + if (!empty($_FILES['ActiveForm_simpleItem']['tmp_name']['Ecommerce\Item']['image'])) { |
|
67 | 67 | $file_id = \App::$primary->files->upload([ |
68 | 68 | 'tmp_name' => $_FILES['ActiveForm_simpleItem']['tmp_name']['Ecommerce\Item']['image'], |
69 | 69 | 'name' => $_FILES['ActiveForm_simpleItem']['name']['Ecommerce\Item']['image'], |
@@ -75,131 +75,131 @@ discard block |
||
75 | 75 | 'accept_group' => 'image' |
76 | 76 | ]); |
77 | 77 | if ($file_id) { |
78 | - $item->image_file_id = $file_id; |
|
79 | - $item->save(); |
|
78 | + $item->image_file_id = $file_id; |
|
79 | + $item->save(); |
|
80 | + } |
|
80 | 81 | } |
81 | - } |
|
82 | - if (!empty($request['options']['option'])) { |
|
82 | + if (!empty($request['options']['option'])) { |
|
83 | 83 | foreach ($request['options']['option'] as $key => $option_id) { |
84 | - $param = new Item\Param(); |
|
85 | - $param->item_id = $item->id; |
|
86 | - $param->value = $request['options']['value'][$key]; |
|
87 | - $param->item_option_id = $option_id; |
|
88 | - $param->save(); |
|
84 | + $param = new Item\Param(); |
|
85 | + $param->item_id = $item->id; |
|
86 | + $param->value = $request['options']['value'][$key]; |
|
87 | + $param->item_option_id = $option_id; |
|
88 | + $param->save(); |
|
89 | 89 | } |
90 | - } |
|
91 | - $offer = new Item\Offer(); |
|
92 | - $offer->item_id = $item->id; |
|
93 | - $offer->save(); |
|
94 | - if (!empty($request['offerOptions']['option'])) { |
|
90 | + } |
|
91 | + $offer = new Item\Offer(); |
|
92 | + $offer->item_id = $item->id; |
|
93 | + $offer->save(); |
|
94 | + if (!empty($request['offerOptions']['option'])) { |
|
95 | 95 | foreach ($request['offerOptions']['option'] as $key => $option_id) { |
96 | - $param = new Item\Offer\Param(); |
|
97 | - $param->item_offer_id = $offer->id; |
|
98 | - $param->value = $request['offerOptions']['value'][$key]; |
|
99 | - $param->item_offer_option_id = $option_id; |
|
100 | - $param->save(); |
|
96 | + $param = new Item\Offer\Param(); |
|
97 | + $param->item_offer_id = $offer->id; |
|
98 | + $param->value = $request['offerOptions']['value'][$key]; |
|
99 | + $param->item_offer_option_id = $option_id; |
|
100 | + $param->save(); |
|
101 | + } |
|
101 | 102 | } |
102 | - } |
|
103 | - $price = new Item\Offer\Price(); |
|
104 | - $price->price = $request['price']; |
|
105 | - $price->item_offer_id = $offer->id; |
|
106 | - $price->currency_id = $request['currency']; |
|
107 | - $price->save(); |
|
103 | + $price = new Item\Offer\Price(); |
|
104 | + $price->price = $request['price']; |
|
105 | + $price->item_offer_id = $offer->id; |
|
106 | + $price->currency_id = $request['currency']; |
|
107 | + $price->save(); |
|
108 | + } |
|
108 | 109 | } |
109 | - } |
|
110 | 110 | |
111 | - public static $dataManagers = [ |
|
112 | - 'manager' => [ |
|
113 | - 'name' => 'Товары', |
|
114 | - 'cols' => [ |
|
115 | - 'name', |
|
116 | - 'imgs', |
|
117 | - 'category_id', |
|
118 | - 'item_type_id', |
|
119 | - 'best', |
|
120 | - 'deleted', |
|
121 | - 'options', |
|
122 | - 'offers', |
|
123 | - ], |
|
124 | - 'categorys' => [ |
|
125 | - 'model' => 'Ecommerce\Category', |
|
126 | - ], |
|
127 | - 'sortMode' => true |
|
128 | - ] |
|
129 | - ]; |
|
130 | - public static $forms = [ |
|
131 | - 'manager' => [ |
|
132 | - 'map' => [ |
|
133 | - ['name', 'alias'], |
|
134 | - ['category_id', 'item_type_id', 'deleted'], |
|
135 | - ['widget', 'view'], |
|
136 | - ['best', 'image_file_id'], |
|
137 | - ['description'], |
|
138 | - ['imgs'], |
|
139 | - ['options'], |
|
140 | - ['offers'], |
|
141 | - ] |
|
142 | - ], |
|
143 | - 'simpleItem' => [ |
|
144 | - 'options' => [ |
|
145 | - 'access' => [ |
|
146 | - 'groups' => [ |
|
147 | - 3 |
|
148 | - ] |
|
149 | - ], |
|
150 | - ], |
|
151 | - 'name' => 'Простой товар с ценой', |
|
152 | - 'inputs' => [ |
|
153 | - 'name' => ['type' => 'text'], |
|
154 | - 'description' => ['type' => 'html'], |
|
155 | - 'category' => ['type' => 'select', 'source' => 'model', 'model' => 'Ecommerce\Category', 'label' => 'Категория'], |
|
156 | - 'image' => ['type' => 'image', 'label' => 'Изображение'], |
|
157 | - 'price' => ['type' => 'text', 'label' => 'Цена'], |
|
158 | - 'currency' => ['type' => 'select', 'source' => 'model', 'model' => 'Money\Currency', 'label' => 'Валюта'], |
|
159 | - 'options' => ['type' => 'dynamicList', 'source' => 'options', 'options' => [ |
|
160 | - 'inputs' => [ |
|
161 | - 'option' => ['type' => 'select', 'source' => 'model', 'model' => 'Ecommerce\Item\Option', 'label' => 'Свойство'], |
|
162 | - 'value' => ['type' => 'dynamicType', 'typeSource' => 'selfMethod', 'selfMethod' => 'realType', 'label' => 'Значение'], |
|
163 | - ] |
|
164 | - ] |
|
165 | - ], |
|
166 | - 'offerOptions' => ['type' => 'dynamicList', 'source' => 'options', 'options' => [ |
|
167 | - 'inputs' => [ |
|
168 | - 'option' => ['type' => 'select', 'source' => 'model', 'model' => 'Ecommerce\Item\Offer\Option', 'label' => 'Свойство предложения'], |
|
169 | - 'value' => ['type' => 'dynamicType', 'typeSource' => 'selfMethod', 'selfMethod' => 'realType', 'label' => 'Значение'], |
|
170 | - ] |
|
171 | - ],'label'=>'Параметры предложения' |
|
172 | - ] |
|
173 | - ], |
|
174 | - 'map' => [ |
|
175 | - ['name', 'category'], |
|
176 | - ['description'], |
|
177 | - ['image'], |
|
178 | - ['price', 'currency'], |
|
179 | - ['options'], |
|
180 | - ['offerOptions'], |
|
181 | - ], |
|
182 | - 'handler' => 'simpleItemHandler' |
|
183 | - ] |
|
184 | - ]; |
|
111 | + public static $dataManagers = [ |
|
112 | + 'manager' => [ |
|
113 | + 'name' => 'Товары', |
|
114 | + 'cols' => [ |
|
115 | + 'name', |
|
116 | + 'imgs', |
|
117 | + 'category_id', |
|
118 | + 'item_type_id', |
|
119 | + 'best', |
|
120 | + 'deleted', |
|
121 | + 'options', |
|
122 | + 'offers', |
|
123 | + ], |
|
124 | + 'categorys' => [ |
|
125 | + 'model' => 'Ecommerce\Category', |
|
126 | + ], |
|
127 | + 'sortMode' => true |
|
128 | + ] |
|
129 | + ]; |
|
130 | + public static $forms = [ |
|
131 | + 'manager' => [ |
|
132 | + 'map' => [ |
|
133 | + ['name', 'alias'], |
|
134 | + ['category_id', 'item_type_id', 'deleted'], |
|
135 | + ['widget', 'view'], |
|
136 | + ['best', 'image_file_id'], |
|
137 | + ['description'], |
|
138 | + ['imgs'], |
|
139 | + ['options'], |
|
140 | + ['offers'], |
|
141 | + ] |
|
142 | + ], |
|
143 | + 'simpleItem' => [ |
|
144 | + 'options' => [ |
|
145 | + 'access' => [ |
|
146 | + 'groups' => [ |
|
147 | + 3 |
|
148 | + ] |
|
149 | + ], |
|
150 | + ], |
|
151 | + 'name' => 'Простой товар с ценой', |
|
152 | + 'inputs' => [ |
|
153 | + 'name' => ['type' => 'text'], |
|
154 | + 'description' => ['type' => 'html'], |
|
155 | + 'category' => ['type' => 'select', 'source' => 'model', 'model' => 'Ecommerce\Category', 'label' => 'Категория'], |
|
156 | + 'image' => ['type' => 'image', 'label' => 'Изображение'], |
|
157 | + 'price' => ['type' => 'text', 'label' => 'Цена'], |
|
158 | + 'currency' => ['type' => 'select', 'source' => 'model', 'model' => 'Money\Currency', 'label' => 'Валюта'], |
|
159 | + 'options' => ['type' => 'dynamicList', 'source' => 'options', 'options' => [ |
|
160 | + 'inputs' => [ |
|
161 | + 'option' => ['type' => 'select', 'source' => 'model', 'model' => 'Ecommerce\Item\Option', 'label' => 'Свойство'], |
|
162 | + 'value' => ['type' => 'dynamicType', 'typeSource' => 'selfMethod', 'selfMethod' => 'realType', 'label' => 'Значение'], |
|
163 | + ] |
|
164 | + ] |
|
165 | + ], |
|
166 | + 'offerOptions' => ['type' => 'dynamicList', 'source' => 'options', 'options' => [ |
|
167 | + 'inputs' => [ |
|
168 | + 'option' => ['type' => 'select', 'source' => 'model', 'model' => 'Ecommerce\Item\Offer\Option', 'label' => 'Свойство предложения'], |
|
169 | + 'value' => ['type' => 'dynamicType', 'typeSource' => 'selfMethod', 'selfMethod' => 'realType', 'label' => 'Значение'], |
|
170 | + ] |
|
171 | + ],'label'=>'Параметры предложения' |
|
172 | + ] |
|
173 | + ], |
|
174 | + 'map' => [ |
|
175 | + ['name', 'category'], |
|
176 | + ['description'], |
|
177 | + ['image'], |
|
178 | + ['price', 'currency'], |
|
179 | + ['options'], |
|
180 | + ['offerOptions'], |
|
181 | + ], |
|
182 | + 'handler' => 'simpleItemHandler' |
|
183 | + ] |
|
184 | + ]; |
|
185 | 185 | |
186 | - public function realType() { |
|
186 | + public function realType() { |
|
187 | 187 | if ($this->option && $this->option->type) { |
188 | - $type = $this->option->type; |
|
188 | + $type = $this->option->type; |
|
189 | 189 | |
190 | - if ($type == 'select') { |
|
190 | + if ($type == 'select') { |
|
191 | 191 | return [ |
192 | 192 | 'type' => 'select', |
193 | 193 | 'source' => 'relation', |
194 | 194 | 'relation' => 'option:items', |
195 | 195 | ]; |
196 | - } |
|
197 | - return $type; |
|
196 | + } |
|
197 | + return $type; |
|
198 | 198 | } |
199 | 199 | return 'text'; |
200 | - } |
|
200 | + } |
|
201 | 201 | |
202 | - public static function indexes() { |
|
202 | + public static function indexes() { |
|
203 | 203 | return [ |
204 | 204 | 'ecommerce_item_item_category_id' => [ |
205 | 205 | 'type' => 'INDEX', |
@@ -220,45 +220,45 @@ discard block |
||
220 | 220 | ] |
221 | 221 | ], |
222 | 222 | ]; |
223 | - } |
|
223 | + } |
|
224 | 224 | |
225 | - public function beforeSave() { |
|
225 | + public function beforeSave() { |
|
226 | 226 | |
227 | 227 | if ($this->id) { |
228 | - $this->search_index = $this->name . ' '; |
|
229 | - if ($this->category) { |
|
228 | + $this->search_index = $this->name . ' '; |
|
229 | + if ($this->category) { |
|
230 | 230 | $this->search_index .= $this->category->name . ' '; |
231 | - } |
|
232 | - if ($this->options) { |
|
231 | + } |
|
232 | + if ($this->options) { |
|
233 | 233 | foreach ($this->options as $option) { |
234 | - if ($option->item_option_searchable && $option->value) { |
|
234 | + if ($option->item_option_searchable && $option->value) { |
|
235 | 235 | if ($option->item_option_type != 'select') { |
236 | - $this->search_index .= $option->value . ' '; |
|
236 | + $this->search_index .= $option->value . ' '; |
|
237 | 237 | } elseif (!empty($option->option->items[$option->value])) { |
238 | - $option->option->items[$option->value]->value . ' '; |
|
238 | + $option->option->items[$option->value]->value . ' '; |
|
239 | 239 | } |
240 | - } |
|
240 | + } |
|
241 | + } |
|
241 | 242 | } |
242 | - } |
|
243 | - if ($this->offers) { |
|
243 | + if ($this->offers) { |
|
244 | 244 | foreach ($this->offers as $offer) { |
245 | - if ($offer->options) { |
|
245 | + if ($offer->options) { |
|
246 | 246 | foreach ($offer->options as $option) { |
247 | - if ($option->item_offer_option_searchable && $option->value) { |
|
247 | + if ($option->item_offer_option_searchable && $option->value) { |
|
248 | 248 | if ($option->item_offer_option_type != 'select') { |
249 | - $this->search_index .= $option->value . ' '; |
|
249 | + $this->search_index .= $option->value . ' '; |
|
250 | 250 | } elseif (!empty($option->option->items[$option->value])) { |
251 | - $option->option->items[$option->value]->value . ' '; |
|
251 | + $option->option->items[$option->value]->value . ' '; |
|
252 | 252 | } |
253 | - } |
|
253 | + } |
|
254 | + } |
|
254 | 255 | } |
255 | - } |
|
256 | 256 | } |
257 | - } |
|
257 | + } |
|
258 | + } |
|
258 | 259 | } |
259 | - } |
|
260 | 260 | |
261 | - public static function relations() { |
|
261 | + public static function relations() { |
|
262 | 262 | |
263 | 263 | return [ |
264 | 264 | 'category' => [ |
@@ -296,55 +296,55 @@ discard block |
||
296 | 296 | 'col' => 'user_id' |
297 | 297 | ] |
298 | 298 | ]; |
299 | - } |
|
299 | + } |
|
300 | 300 | |
301 | - public function getPrice() { |
|
301 | + public function getPrice() { |
|
302 | 302 | $offers = $this->offers(['key' => false]); |
303 | 303 | $curPrice = null; |
304 | 304 | |
305 | 305 | foreach ($offers[0]->prices as $price) { |
306 | - if (!$price->type) { |
|
306 | + if (!$price->type) { |
|
307 | 307 | $curPrice = $price; |
308 | - } elseif ( |
|
309 | - (!$price->type->roles && !$curPrice) || |
|
308 | + } elseif ( |
|
309 | + (!$price->type->roles && !$curPrice) || |
|
310 | 310 | ($price->type->roles && !$curPrice && strpos($price->type->roles, "|" . \Users\User::$cur->role_id . "|") !== false) |
311 | - ) { |
|
311 | + ) { |
|
312 | 312 | $curPrice = $price; |
313 | - } |
|
313 | + } |
|
314 | 314 | } |
315 | 315 | return $curPrice; |
316 | - } |
|
316 | + } |
|
317 | 317 | |
318 | - public function name() { |
|
318 | + public function name() { |
|
319 | 319 | if (!empty(\App::$primary->ecommerce->config['item_option_as_name'])) { |
320 | - $param = Item\Param::get([['item_id', $this->id], ['item_option_id', \App::$primary->ecommerce->config['item_option_as_name']]]); |
|
321 | - if ($param && $param->value) { |
|
320 | + $param = Item\Param::get([['item_id', $this->id], ['item_option_id', \App::$primary->ecommerce->config['item_option_as_name']]]); |
|
321 | + if ($param && $param->value) { |
|
322 | 322 | return $param->value; |
323 | - } |
|
323 | + } |
|
324 | 324 | } |
325 | 325 | return $this->name; |
326 | - } |
|
326 | + } |
|
327 | 327 | |
328 | - public function beforeDelete() { |
|
328 | + public function beforeDelete() { |
|
329 | 329 | if ($this->id) { |
330 | - if ($this->options) { |
|
330 | + if ($this->options) { |
|
331 | 331 | foreach ($this->options as $option) { |
332 | - $option->delete(); |
|
332 | + $option->delete(); |
|
333 | + } |
|
333 | 334 | } |
334 | - } |
|
335 | - if ($this->offers) { |
|
335 | + if ($this->offers) { |
|
336 | 336 | foreach ($this->offers as $offer) { |
337 | - $offer->delete(); |
|
337 | + $offer->delete(); |
|
338 | 338 | } |
339 | - } |
|
340 | - if ($this->image) { |
|
339 | + } |
|
340 | + if ($this->image) { |
|
341 | 341 | $this->image->delete(); |
342 | - } |
|
342 | + } |
|
343 | + } |
|
343 | 344 | } |
344 | - } |
|
345 | 345 | |
346 | - public function getHref() { |
|
346 | + public function getHref() { |
|
347 | 347 | return "/ecommerce/view/{$this->pk()}"; |
348 | - } |
|
348 | + } |
|
349 | 349 | |
350 | 350 | } |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | 'size' => $_FILES['ActiveForm_simpleItem']['size']['Ecommerce\Item']['image'], |
72 | 72 | 'error' => $_FILES['ActiveForm_simpleItem']['error']['Ecommerce\Item']['image'], |
73 | 73 | ], [ |
74 | - 'upload_code' => 'activeForm:' . 'Ecommerce\Item' . ':' . $item->pk(), |
|
74 | + 'upload_code' => 'activeForm:'.'Ecommerce\Item'.':'.$item->pk(), |
|
75 | 75 | 'accept_group' => 'image' |
76 | 76 | ]); |
77 | 77 | if ($file_id) { |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | 'option' => ['type' => 'select', 'source' => 'model', 'model' => 'Ecommerce\Item\Offer\Option', 'label' => 'Свойство предложения'], |
169 | 169 | 'value' => ['type' => 'dynamicType', 'typeSource' => 'selfMethod', 'selfMethod' => 'realType', 'label' => 'Значение'], |
170 | 170 | ] |
171 | - ],'label'=>'Параметры предложения' |
|
171 | + ], 'label'=>'Параметры предложения' |
|
172 | 172 | ] |
173 | 173 | ], |
174 | 174 | 'map' => [ |
@@ -225,17 +225,17 @@ discard block |
||
225 | 225 | public function beforeSave() { |
226 | 226 | |
227 | 227 | if ($this->id) { |
228 | - $this->search_index = $this->name . ' '; |
|
228 | + $this->search_index = $this->name.' '; |
|
229 | 229 | if ($this->category) { |
230 | - $this->search_index .= $this->category->name . ' '; |
|
230 | + $this->search_index .= $this->category->name.' '; |
|
231 | 231 | } |
232 | 232 | if ($this->options) { |
233 | 233 | foreach ($this->options as $option) { |
234 | 234 | if ($option->item_option_searchable && $option->value) { |
235 | 235 | if ($option->item_option_type != 'select') { |
236 | - $this->search_index .= $option->value . ' '; |
|
236 | + $this->search_index .= $option->value.' '; |
|
237 | 237 | } elseif (!empty($option->option->items[$option->value])) { |
238 | - $option->option->items[$option->value]->value . ' '; |
|
238 | + $option->option->items[$option->value]->value.' '; |
|
239 | 239 | } |
240 | 240 | } |
241 | 241 | } |
@@ -246,9 +246,9 @@ discard block |
||
246 | 246 | foreach ($offer->options as $option) { |
247 | 247 | if ($option->item_offer_option_searchable && $option->value) { |
248 | 248 | if ($option->item_offer_option_type != 'select') { |
249 | - $this->search_index .= $option->value . ' '; |
|
249 | + $this->search_index .= $option->value.' '; |
|
250 | 250 | } elseif (!empty($option->option->items[$option->value])) { |
251 | - $option->option->items[$option->value]->value . ' '; |
|
251 | + $option->option->items[$option->value]->value.' '; |
|
252 | 252 | } |
253 | 253 | } |
254 | 254 | } |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | 'col' => 'item_id', |
272 | 272 | //'resultKey' => 'code', |
273 | 273 | 'resultKey' => 'item_option_id', |
274 | - 'join' => [Item\Option::table(), Item\Option::index() . ' = ' . Item\Param::colPrefix() . Item\Option::index()] |
|
274 | + 'join' => [Item\Option::table(), Item\Option::index().' = '.Item\Param::colPrefix().Item\Option::index()] |
|
275 | 275 | ], |
276 | 276 | 'offers' => [ |
277 | 277 | 'type' => 'many', |
@@ -307,7 +307,7 @@ discard block |
||
307 | 307 | $curPrice = $price; |
308 | 308 | } elseif ( |
309 | 309 | (!$price->type->roles && !$curPrice) || |
310 | - ($price->type->roles && !$curPrice && strpos($price->type->roles, "|" . \Users\User::$cur->role_id . "|") !== false) |
|
310 | + ($price->type->roles && !$curPrice && strpos($price->type->roles, "|".\Users\User::$cur->role_id."|") !== false) |
|
311 | 311 | ) { |
312 | 312 | $curPrice = $price; |
313 | 313 | } |