@@ -10,38 +10,38 @@ |
||
10 | 10 | */ |
11 | 11 | class DashboardController extends adminController { |
12 | 12 | |
13 | - public function indexAction() { |
|
13 | + public function indexAction() { |
|
14 | 14 | $sections = $this->module->getSnippets('adminDashboardWidget'); |
15 | 15 | $this->view->setTitle('Панель управления'); |
16 | 16 | $this->view->page(['data' => compact('sections')]); |
17 | - } |
|
17 | + } |
|
18 | 18 | |
19 | - public function siteConfigAction() { |
|
19 | + public function siteConfigAction() { |
|
20 | 20 | if (isset($_POST['site_name'])) { |
21 | - $config = \App::$primary->config; |
|
22 | - $config['site']['name'] = $_POST['site_name']; |
|
23 | - $config['site']['company_name'] = $_POST['company_name']; |
|
24 | - $config['site']['email'] = $_POST['site_email']; |
|
25 | - $config['site']['keywords'] = $_POST['site_keywords']; |
|
26 | - $config['site']['description'] = $_POST['site_description']; |
|
27 | - $config['site']['domain'] = $_POST['site_domain']; |
|
28 | - if (isset($_POST['metatags'])) { |
|
21 | + $config = \App::$primary->config; |
|
22 | + $config['site']['name'] = $_POST['site_name']; |
|
23 | + $config['site']['company_name'] = $_POST['company_name']; |
|
24 | + $config['site']['email'] = $_POST['site_email']; |
|
25 | + $config['site']['keywords'] = $_POST['site_keywords']; |
|
26 | + $config['site']['description'] = $_POST['site_description']; |
|
27 | + $config['site']['domain'] = $_POST['site_domain']; |
|
28 | + if (isset($_POST['metatags'])) { |
|
29 | 29 | $config['site']['metatags'] = $_POST['metatags']; |
30 | - } |
|
31 | - if (!empty($_FILES['site_logo']['tmp_name'])) { |
|
30 | + } |
|
31 | + if (!empty($_FILES['site_logo']['tmp_name'])) { |
|
32 | 32 | $fileId = $this->Files->upload($_FILES['site_logo'], array('file_code' => 'site_logo')); |
33 | 33 | $config['site']['site_logo'] = Files\File::get($fileId)->path; |
34 | - } |
|
35 | - Config::save('app', $config); |
|
36 | - Tools::redirect('/admin/dashboard/siteConfig', 'Изменения сохранены', 'success'); |
|
34 | + } |
|
35 | + Config::save('app', $config); |
|
36 | + Tools::redirect('/admin/dashboard/siteConfig', 'Изменения сохранены', 'success'); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | $this->view->setTitle('Общие настройки сайта'); |
40 | 40 | $this->view->page(); |
41 | - } |
|
41 | + } |
|
42 | 42 | |
43 | - public function phpInfoAction() { |
|
43 | + public function phpInfoAction() { |
|
44 | 44 | $this->view->page(); |
45 | - } |
|
45 | + } |
|
46 | 46 | |
47 | 47 | } |
@@ -32,7 +32,7 @@ |
||
32 | 32 | $walker->migration = $this->migration; |
33 | 33 | $walker->map = $this->map; |
34 | 34 | $walker->data = &$this->data[$path->item]; |
35 | - $walker->curPath = $this->curPath . $path->item . '/'; |
|
35 | + $walker->curPath = $this->curPath.$path->item.'/'; |
|
36 | 36 | $walker->mapPath = $path; |
37 | 37 | $walker->mapPathParent = $this->mapPath; |
38 | 38 | $walker->migtarionLog = $this->migtarionLog; |
@@ -13,61 +13,61 @@ discard block |
||
13 | 13 | |
14 | 14 | class Walker { |
15 | 15 | |
16 | - public $migration = null; |
|
17 | - public $map = null; |
|
18 | - public $data = null; |
|
19 | - public $mapPath = null; |
|
20 | - public $mapPathParent = null; |
|
21 | - public $curPath = '/'; |
|
22 | - public $migtarionLog = null; |
|
16 | + public $migration = null; |
|
17 | + public $map = null; |
|
18 | + public $data = null; |
|
19 | + public $mapPath = null; |
|
20 | + public $mapPathParent = null; |
|
21 | + public $curPath = '/'; |
|
22 | + public $migtarionLog = null; |
|
23 | 23 | |
24 | - //walk map pathes on cur path |
|
25 | - public function walk() { |
|
24 | + //walk map pathes on cur path |
|
25 | + public function walk() { |
|
26 | 26 | $walked = []; |
27 | 27 | //walk know pathes |
28 | 28 | foreach ($this->map->paths(['where' => ['path', $this->curPath]]) as $path) { |
29 | - if (isset($this->data[$path->item])) { |
|
29 | + if (isset($this->data[$path->item])) { |
|
30 | 30 | if ($path->type == 'container') { //create walker for container |
31 | - $walker = new Walker(); |
|
32 | - $walker->migration = $this->migration; |
|
33 | - $walker->map = $this->map; |
|
34 | - $walker->data = &$this->data[$path->item]; |
|
35 | - $walker->curPath = $this->curPath . $path->item . '/'; |
|
36 | - $walker->mapPath = $path; |
|
37 | - $walker->mapPathParent = $this->mapPath; |
|
38 | - $walker->migtarionLog = $this->migtarionLog; |
|
39 | - $walker->walk(); |
|
31 | + $walker = new Walker(); |
|
32 | + $walker->migration = $this->migration; |
|
33 | + $walker->map = $this->map; |
|
34 | + $walker->data = &$this->data[$path->item]; |
|
35 | + $walker->curPath = $this->curPath . $path->item . '/'; |
|
36 | + $walker->mapPath = $path; |
|
37 | + $walker->mapPathParent = $this->mapPath; |
|
38 | + $walker->migtarionLog = $this->migtarionLog; |
|
39 | + $walker->walk(); |
|
40 | 40 | } elseif ($path->type == 'object') { //start parse path data |
41 | - $this->startObjectParse($path->object_id, $this->data[$path->item]); |
|
41 | + $this->startObjectParse($path->object_id, $this->data[$path->item]); |
|
42 | 42 | } |
43 | - } |
|
44 | - $walked[$path->item] = true; |
|
43 | + } |
|
44 | + $walked[$path->item] = true; |
|
45 | 45 | } |
46 | 46 | //check unparsed paths |
47 | 47 | foreach ($this->data as $key => &$data) { |
48 | - //skip parsed and attribtes |
|
49 | - if ($key == '@attributes' || !empty($walked[$key])) { |
|
48 | + //skip parsed and attribtes |
|
49 | + if ($key == '@attributes' || !empty($walked[$key])) { |
|
50 | 50 | continue; |
51 | - } |
|
52 | - //search object for parse |
|
53 | - $object = Migration\Object::get([ |
|
54 | - ['code', $key], |
|
55 | - ['migration_id', $this->migration->id] |
|
56 | - ]); |
|
57 | - if ($object) { //parse as object |
|
51 | + } |
|
52 | + //search object for parse |
|
53 | + $object = Migration\Object::get([ |
|
54 | + ['code', $key], |
|
55 | + ['migration_id', $this->migration->id] |
|
56 | + ]); |
|
57 | + if ($object) { //parse as object |
|
58 | 58 | $this->startObjectParse($object, $data); |
59 | - } else { //create new map path for configure unknown path |
|
59 | + } else { //create new map path for configure unknown path |
|
60 | 60 | $this->mapPath = new Migration\Map\Path(); |
61 | 61 | $this->mapPath->parent_id = $this->mapPathParent ? $this->mapPathParent->id : 0; |
62 | 62 | $this->mapPath->path = $this->curPath; |
63 | 63 | $this->mapPath->item = $key; |
64 | 64 | $this->mapPath->migration_map_id = $this->map->id; |
65 | 65 | $this->mapPath->save(); |
66 | - } |
|
66 | + } |
|
67 | + } |
|
67 | 68 | } |
68 | - } |
|
69 | 69 | |
70 | - private function startObjectParse($object_id, &$data) { |
|
70 | + private function startObjectParse($object_id, &$data) { |
|
71 | 71 | $objectParser = new Parser\Object(); |
72 | 72 | $objectParser->object = is_object($object_id) ? $object_id : \App::$cur->migrations->getMigrationObject($object_id); |
73 | 73 | $objectParser->data = $data; |
@@ -76,33 +76,33 @@ discard block |
||
76 | 76 | |
77 | 77 | if ($objectParser->object->clear && json_decode($objectParser->object->clear, true)) { |
78 | 78 | |
79 | - $where = json_decode($objectParser->object->clear, true); |
|
80 | - if (!$where) { |
|
79 | + $where = json_decode($objectParser->object->clear, true); |
|
80 | + if (!$where) { |
|
81 | 81 | $where = []; |
82 | - } else { |
|
82 | + } else { |
|
83 | 83 | $where = [[$where]]; |
84 | - } |
|
85 | - if ($ids) { |
|
84 | + } |
|
85 | + if ($ids) { |
|
86 | 86 | $where[] = ['id', implode(',', $ids), 'NOT IN']; |
87 | - } |
|
88 | - if (empty(\App::$cur->migrations->ids['objectIds'])) { |
|
87 | + } |
|
88 | + if (empty(\App::$cur->migrations->ids['objectIds'])) { |
|
89 | 89 | \App::$cur->migrations->loadObjectIds($objectParser->object->model); |
90 | - } |
|
91 | - if (!empty(\App::$cur->migrations->ids['objectIds'][$objectParser->object->model])) { |
|
90 | + } |
|
91 | + if (!empty(\App::$cur->migrations->ids['objectIds'][$objectParser->object->model])) { |
|
92 | 92 | $where[] = ['id', implode(',', array_keys(\App::$cur->migrations->ids['objectIds'][$objectParser->object->model])), 'IN']; |
93 | - } |
|
94 | - $modelName = $objectParser->object->model; |
|
95 | - $objects = $modelName::getList(['where' => $where]); |
|
96 | - foreach ($objects as $object) { |
|
93 | + } |
|
94 | + $modelName = $objectParser->object->model; |
|
95 | + $objects = $modelName::getList(['where' => $where]); |
|
96 | + foreach ($objects as $object) { |
|
97 | 97 | $objectId = \App::$cur->migrations->findParse($object->id, $objectParser->object->model); |
98 | 98 | if ($objectId) { |
99 | - $objectId->delete(); |
|
100 | - unset(\App::$cur->migrations->ids['objectIds'][$objectParser->object->model][$object->id]); |
|
101 | - unset(\App::$cur->migrations->ids['parseIds'][$objectParser->object->model][$objectId->parse_id]); |
|
99 | + $objectId->delete(); |
|
100 | + unset(\App::$cur->migrations->ids['objectIds'][$objectParser->object->model][$object->id]); |
|
101 | + unset(\App::$cur->migrations->ids['parseIds'][$objectParser->object->model][$objectId->parse_id]); |
|
102 | 102 | } |
103 | 103 | $object->delete(); |
104 | - } |
|
104 | + } |
|
105 | + } |
|
105 | 106 | } |
106 | - } |
|
107 | 107 | |
108 | 108 | } |
@@ -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,96 +76,96 @@ 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 | - $buttons[] = [ |
|
124 | - 'text' => 'Создать ' . $name, |
|
125 | - 'onclick' => 'inji.Ui.dataManagers.get(this).newItem("' . str_replace('\\', '\\\\', $modelName) . '",' . json_encode($formParams) . ');', |
|
126 | - ]; |
|
123 | + $buttons[] = [ |
|
124 | + 'text' => 'Создать ' . $name, |
|
125 | + 'onclick' => 'inji.Ui.dataManagers.get(this).newItem("' . str_replace('\\', '\\\\', $modelName) . '",' . json_encode($formParams) . ');', |
|
126 | + ]; |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | return $buttons; |
130 | - } |
|
130 | + } |
|
131 | 131 | |
132 | - function getActions($onlyGroupActions = false) { |
|
132 | + function getActions($onlyGroupActions = false) { |
|
133 | 133 | $actions = [ |
134 | 134 | 'Open' => ['className' => 'Open'], 'Edit' => ['className' => 'Edit'], 'Delete' => ['className' => 'Delete'] |
135 | 135 | ]; |
136 | 136 | if (isset($this->managerOptions['actions'])) { |
137 | - $actions = array_merge($actions, $this->managerOptions['actions']); |
|
137 | + $actions = array_merge($actions, $this->managerOptions['actions']); |
|
138 | 138 | } |
139 | 139 | $return = []; |
140 | 140 | foreach ($actions as $key => $action) { |
141 | - if ($action === false) { |
|
141 | + if ($action === false) { |
|
142 | 142 | continue; |
143 | - } |
|
144 | - if (is_array($action)) { |
|
143 | + } |
|
144 | + if (is_array($action)) { |
|
145 | 145 | if (!empty($action['access']['groups']) && !in_array(\Users\User::$cur->group_id, $action['access']['groups'])) { |
146 | - continue; |
|
146 | + continue; |
|
147 | 147 | } |
148 | 148 | $return[$key] = $action; |
149 | - } else { |
|
149 | + } else { |
|
150 | 150 | $key = $action; |
151 | 151 | $return[$key] = [ |
152 | 152 | 'className' => $action |
153 | 153 | ]; |
154 | - } |
|
155 | - $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']; |
|
156 | - if (!class_exists($return[$key]['className']) || ($onlyGroupActions && !$return[$key]['className']::$groupAction)) { |
|
154 | + } |
|
155 | + $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']; |
|
156 | + if (!class_exists($return[$key]['className']) || ($onlyGroupActions && !$return[$key]['className']::$groupAction)) { |
|
157 | 157 | unset($return[$key]); |
158 | - } |
|
158 | + } |
|
159 | 159 | } |
160 | 160 | return $return; |
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * Get cols for manager |
|
165 | - * |
|
166 | - * @return string |
|
167 | - */ |
|
168 | - public function getCols() { |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * Get cols for manager |
|
165 | + * |
|
166 | + * @return string |
|
167 | + */ |
|
168 | + public function getCols() { |
|
169 | 169 | $actions = $this->getActions(); |
170 | 170 | ob_start(); |
171 | 171 | ?> |
@@ -181,12 +181,12 @@ discard block |
||
181 | 181 | <li><a href ='' onclick='inji.Ui.dataManagers.get(this).rowSelection("inverse");return false;'>Инвертировать</a></li> |
182 | 182 | <li role="separator" class="divider"></li> |
183 | 183 | <?php |
184 | - foreach ($actions as $action => $actionParams) { |
|
184 | + foreach ($actions as $action => $actionParams) { |
|
185 | 185 | if (class_exists($actionParams['className']) && $actionParams['className']::$groupAction) { |
186 | - echo "<li><a role='button' href ='#' onclick='inji.Ui.dataManagers.get(this).groupAction(\"" . str_replace('\\', '\\\\', $action) . "\");return false;'>{$actionParams['className']::$name}</a></li>"; |
|
186 | + echo "<li><a role='button' href ='#' onclick='inji.Ui.dataManagers.get(this).groupAction(\"" . str_replace('\\', '\\\\', $action) . "\");return false;'>{$actionParams['className']::$name}</a></li>"; |
|
187 | + } |
|
187 | 188 | } |
188 | - } |
|
189 | - ?> |
|
189 | + ?> |
|
190 | 190 | </ul> |
191 | 191 | </div> |
192 | 192 | <?php |
@@ -199,299 +199,299 @@ discard block |
||
199 | 199 | |
200 | 200 | $modelName = $this->modelName; |
201 | 201 | foreach ($this->managerOptions['cols'] as $key => $col) { |
202 | - if (is_array($col)) { |
|
202 | + if (is_array($col)) { |
|
203 | 203 | $colName = $key; |
204 | 204 | $colOptions = $col; |
205 | - } else { |
|
205 | + } else { |
|
206 | 206 | $colName = $col; |
207 | 207 | $colOptions = []; |
208 | - } |
|
209 | - $colInfo = []; |
|
210 | - if ($modelName) { |
|
208 | + } |
|
209 | + $colInfo = []; |
|
210 | + if ($modelName) { |
|
211 | 211 | $colInfo = $modelName::getColInfo($colName); |
212 | - } |
|
213 | - if (empty($colOptions['label']) && !empty($colInfo['label'])) { |
|
212 | + } |
|
213 | + if (empty($colOptions['label']) && !empty($colInfo['label'])) { |
|
214 | 214 | $colOptions['label'] = $colInfo['label']; |
215 | - } elseif (empty($colOptions['label'])) { |
|
215 | + } elseif (empty($colOptions['label'])) { |
|
216 | 216 | $colOptions['label'] = $colName; |
217 | - } |
|
218 | - $cols[$colName] = $colOptions; |
|
217 | + } |
|
218 | + $cols[$colName] = $colOptions; |
|
219 | 219 | } |
220 | 220 | return $cols; |
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * Get rows for manager |
|
225 | - * |
|
226 | - * @param array $params |
|
227 | - * @param object $model |
|
228 | - * @return type |
|
229 | - */ |
|
230 | - public function getRows($params = [], $model = null) { |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * Get rows for manager |
|
225 | + * |
|
226 | + * @param array $params |
|
227 | + * @param object $model |
|
228 | + * @return type |
|
229 | + */ |
|
230 | + public function getRows($params = [], $model = null) { |
|
231 | 231 | $modelName = $this->modelName; |
232 | 232 | if (!class_exists($modelName)) { |
233 | - return []; |
|
233 | + return []; |
|
234 | 234 | } |
235 | 235 | if (!$this->checkAccess()) { |
236 | - $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->managerName . '"'); |
|
237 | - return []; |
|
236 | + $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->managerName . '"'); |
|
237 | + return []; |
|
238 | 238 | } |
239 | 239 | $modelName = $this->modelName; |
240 | 240 | $queryParams = []; |
241 | 241 | if (empty($params['all'])) { |
242 | - if (!empty($params['limit'])) { |
|
242 | + if (!empty($params['limit'])) { |
|
243 | 243 | $this->limit = (int) $params['limit']; |
244 | - } |
|
245 | - if (!empty($params['page'])) { |
|
244 | + } |
|
245 | + if (!empty($params['page'])) { |
|
246 | 246 | $this->page = (int) $params['page']; |
247 | - } |
|
248 | - $queryParams['limit'] = $this->limit; |
|
249 | - $queryParams['start'] = $this->page * $this->limit - $this->limit; |
|
247 | + } |
|
248 | + $queryParams['limit'] = $this->limit; |
|
249 | + $queryParams['start'] = $this->page * $this->limit - $this->limit; |
|
250 | 250 | } |
251 | 251 | if (!empty($params['categoryPath']) && $modelName::$categoryModel) { |
252 | - $queryParams['where'][] = ['tree_path', $params['categoryPath'] . '%', 'LIKE']; |
|
252 | + $queryParams['where'][] = ['tree_path', $params['categoryPath'] . '%', 'LIKE']; |
|
253 | 253 | } |
254 | 254 | if (!empty($params['appType'])) { |
255 | - $queryParams['appType'] = $params['appType']; |
|
255 | + $queryParams['appType'] = $params['appType']; |
|
256 | 256 | } |
257 | 257 | if ($this->joins) { |
258 | - $queryParams['joins'] = $this->joins; |
|
258 | + $queryParams['joins'] = $this->joins; |
|
259 | 259 | } |
260 | 260 | if (!empty($this->managerOptions['userGroupFilter'][\Users\User::$cur->group_id]['getRows'])) { |
261 | - foreach ($this->managerOptions['userGroupFilter'][\Users\User::$cur->group_id]['getRows'] as $colName => $colOptions) { |
|
261 | + foreach ($this->managerOptions['userGroupFilter'][\Users\User::$cur->group_id]['getRows'] as $colName => $colOptions) { |
|
262 | 262 | if (!empty($colOptions['userCol'])) { |
263 | - if (strpos($colOptions['userCol'], ':')) { |
|
263 | + if (strpos($colOptions['userCol'], ':')) { |
|
264 | 264 | $rel = substr($colOptions['userCol'], 0, strpos($colOptions['userCol'], ':')); |
265 | 265 | $param = substr($colOptions['userCol'], strpos($colOptions['userCol'], ':') + 1); |
266 | 266 | $queryParams['where'][] = [$colName, \Users\User::$cur->$rel->$param]; |
267 | - } |
|
267 | + } |
|
268 | 268 | } elseif (isset($colOptions['value'])) { |
269 | - $queryParams['where'][] = [$colName, $colOptions['value'], is_array($colOptions['value']) ? 'IN' : '=']; |
|
269 | + $queryParams['where'][] = [$colName, $colOptions['value'], is_array($colOptions['value']) ? 'IN' : '=']; |
|
270 | + } |
|
270 | 271 | } |
271 | - } |
|
272 | 272 | } |
273 | 273 | if (!empty($this->managerOptions['filters'])) { |
274 | - foreach ($this->managerOptions['filters'] as $col) { |
|
274 | + foreach ($this->managerOptions['filters'] as $col) { |
|
275 | 275 | $colInfo = $modelName::getColInfo($col); |
276 | 276 | switch ($colInfo['colParams']['type']) { |
277 | - case 'select': |
|
277 | + case 'select': |
|
278 | 278 | if (empty($params['filters'][$col]['value'])) { |
279 | - continue; |
|
279 | + continue; |
|
280 | 280 | } |
281 | 281 | if (is_array($params['filters'][$col]['value'])) { |
282 | - foreach ($params['filters'][$col]['value'] as $key => $value) { |
|
282 | + foreach ($params['filters'][$col]['value'] as $key => $value) { |
|
283 | 283 | if ($value === '') { |
284 | - unset($params['filters'][$col]['value'][$key]); |
|
284 | + unset($params['filters'][$col]['value'][$key]); |
|
285 | + } |
|
285 | 286 | } |
286 | - } |
|
287 | 287 | } |
288 | 288 | if (!$params['filters'][$col]['value']) { |
289 | - continue; |
|
289 | + continue; |
|
290 | 290 | } |
291 | 291 | $queryParams['where'][] = [$col, $params['filters'][$col]['value'], is_array($params['filters'][$col]['value']) ? 'IN' : '=']; |
292 | 292 | break; |
293 | - case 'bool': |
|
293 | + case 'bool': |
|
294 | 294 | |
295 | 295 | if (!isset($params['filters'][$col]['value']) || $params['filters'][$col]['value'] === '') { |
296 | - continue; |
|
296 | + continue; |
|
297 | 297 | } |
298 | 298 | $queryParams['where'][] = [$col, $params['filters'][$col]['value']]; |
299 | 299 | break; |
300 | - case 'dateTime': |
|
300 | + case 'dateTime': |
|
301 | 301 | case 'date': |
302 | 302 | if (empty($params['filters'][$col]['min']) && empty($params['filters'][$col]['max'])) { |
303 | - continue; |
|
303 | + continue; |
|
304 | 304 | } |
305 | 305 | if (!empty($params['filters'][$col]['min'])) { |
306 | - $queryParams['where'][] = [$col, $params['filters'][$col]['min'], '>=']; |
|
306 | + $queryParams['where'][] = [$col, $params['filters'][$col]['min'], '>=']; |
|
307 | 307 | } |
308 | 308 | if (!empty($params['filters'][$col]['max'])) { |
309 | - if ($colInfo['colParams']['type'] == 'dateTime' && !strpos($params['filters'][$col]['max'], ' ')) { |
|
309 | + if ($colInfo['colParams']['type'] == 'dateTime' && !strpos($params['filters'][$col]['max'], ' ')) { |
|
310 | 310 | |
311 | 311 | $date = $params['filters'][$col]['max'] . ' 23:59:59'; |
312 | - } else { |
|
312 | + } else { |
|
313 | 313 | $date = $params['filters'][$col]['max']; |
314 | - } |
|
315 | - $queryParams['where'][] = [$col, $date, '<=']; |
|
314 | + } |
|
315 | + $queryParams['where'][] = [$col, $date, '<=']; |
|
316 | 316 | } |
317 | 317 | break; |
318 | - case 'number': |
|
318 | + case 'number': |
|
319 | 319 | if (empty($params['filters'][$col]['min']) && empty($params['filters'][$col]['max'])) { |
320 | - continue; |
|
320 | + continue; |
|
321 | 321 | } |
322 | 322 | if (!empty($params['filters'][$col]['min'])) { |
323 | - $queryParams['where'][] = [$col, $params['filters'][$col]['min'], '>=']; |
|
323 | + $queryParams['where'][] = [$col, $params['filters'][$col]['min'], '>=']; |
|
324 | 324 | } |
325 | 325 | if (!empty($params['filters'][$col]['max'])) { |
326 | - $queryParams['where'][] = [$col, $params['filters'][$col]['max'], '<=']; |
|
326 | + $queryParams['where'][] = [$col, $params['filters'][$col]['max'], '<=']; |
|
327 | 327 | } |
328 | 328 | break; |
329 | - case 'email': |
|
329 | + case 'email': |
|
330 | 330 | case 'text': |
331 | 331 | case 'textarea': |
332 | 332 | case 'html': |
333 | 333 | if (empty($params['filters'][$col]['value'])) { |
334 | - continue; |
|
334 | + continue; |
|
335 | 335 | } |
336 | 336 | switch ($params['filters'][$col]['compareType']) { |
337 | - case 'contains': |
|
337 | + case 'contains': |
|
338 | 338 | $queryParams['where'][] = [$col, '%' . $params['filters'][$col]['value'] . '%', 'LIKE']; |
339 | 339 | break; |
340 | - case 'equals': |
|
340 | + case 'equals': |
|
341 | 341 | $queryParams['where'][] = [$col, $params['filters'][$col]['value']]; |
342 | 342 | break; |
343 | - case 'starts_with': |
|
343 | + case 'starts_with': |
|
344 | 344 | $queryParams['where'][] = [$col, $params['filters'][$col]['value'] . '%', 'LIKE']; |
345 | 345 | break; |
346 | - case 'ends_with': |
|
346 | + case 'ends_with': |
|
347 | 347 | $queryParams['where'][] = [$col, '%' . $params['filters'][$col]['value'], 'LIKE']; |
348 | 348 | break; |
349 | 349 | } |
350 | 350 | break; |
351 | 351 | } |
352 | - } |
|
352 | + } |
|
353 | 353 | } |
354 | 354 | if (!empty($params['mode']) && $params['mode'] == 'sort') { |
355 | - $queryParams['order'] = ['weight', 'asc']; |
|
355 | + $queryParams['order'] = ['weight', 'asc']; |
|
356 | 356 | } elseif (!empty($params['sortered']) && !empty($this->managerOptions['sortable'])) { |
357 | - foreach ($params['sortered'] as $key => $sortType) { |
|
357 | + foreach ($params['sortered'] as $key => $sortType) { |
|
358 | 358 | $keys = array_keys($this->managerOptions['cols']); |
359 | 359 | $colName = ''; |
360 | 360 | if (isset($keys[$key])) { |
361 | - if (is_array($this->managerOptions['cols'][$keys[$key]])) { |
|
361 | + if (is_array($this->managerOptions['cols'][$keys[$key]])) { |
|
362 | 362 | $colName = $keys[$key]; |
363 | - } else { |
|
363 | + } else { |
|
364 | 364 | $colName = $this->managerOptions['cols'][$keys[$key]]; |
365 | - } |
|
365 | + } |
|
366 | 366 | } |
367 | 367 | if ($colName && in_array($colName, $this->managerOptions['sortable'])) { |
368 | - $sortType = in_array($sortType, ['desc', 'asc']) ? $sortType : 'desc'; |
|
369 | - $queryParams['order'][] = [$colName, $sortType]; |
|
368 | + $sortType = in_array($sortType, ['desc', 'asc']) ? $sortType : 'desc'; |
|
369 | + $queryParams['order'][] = [$colName, $sortType]; |
|
370 | + } |
|
370 | 371 | } |
371 | - } |
|
372 | 372 | } |
373 | 373 | if ($model && !empty($params['relation'])) { |
374 | - $relation = $model::getRelation($params['relation']); |
|
375 | - $items = $model->$params['relation']($queryParams); |
|
374 | + $relation = $model::getRelation($params['relation']); |
|
375 | + $items = $model->$params['relation']($queryParams); |
|
376 | 376 | } else { |
377 | - $relation = false; |
|
378 | - $items = $modelName::getList($queryParams); |
|
377 | + $relation = false; |
|
378 | + $items = $modelName::getList($queryParams); |
|
379 | 379 | } |
380 | 380 | $rows = []; |
381 | 381 | foreach ($items as $item) { |
382 | - if ($relation && !empty($relation['relModel'])) { |
|
382 | + if ($relation && !empty($relation['relModel'])) { |
|
383 | 383 | $item = $relation['relModel']::get([[$item->index(), $item->id], [$model->index(), $model->id]]); |
384 | - } |
|
385 | - $row = []; |
|
386 | - $row[] = '<input type ="checkbox" name = "pk[]" value =' . $item->pk() . '>'; |
|
387 | - $row[] = $item->pk(); |
|
388 | - foreach ($this->managerOptions['cols'] as $key => $colName) { |
|
384 | + } |
|
385 | + $row = []; |
|
386 | + $row[] = '<input type ="checkbox" name = "pk[]" value =' . $item->pk() . '>'; |
|
387 | + $row[] = $item->pk(); |
|
388 | + foreach ($this->managerOptions['cols'] as $key => $colName) { |
|
389 | 389 | if (!empty($params['download'])) { |
390 | - $row[] = \Model::getColValue($item, is_array($colName) ? $key : $colName, true, false); |
|
390 | + $row[] = \Model::getColValue($item, is_array($colName) ? $key : $colName, true, false); |
|
391 | 391 | } else { |
392 | - $row[] = DataManager::drawCol($item, is_array($colName) ? $key : $colName, $params, $this); |
|
392 | + $row[] = DataManager::drawCol($item, is_array($colName) ? $key : $colName, $params, $this); |
|
393 | + } |
|
393 | 394 | } |
394 | - } |
|
395 | - $row[] = $this->rowButtons($item, $params); |
|
396 | - $rows[] = $row; |
|
395 | + $row[] = $this->rowButtons($item, $params); |
|
396 | + $rows[] = $row; |
|
397 | 397 | } |
398 | 398 | return $rows; |
399 | - } |
|
399 | + } |
|
400 | 400 | |
401 | - public static function drawCol($item, $colName, $params = [], $dataManager = null, $originalCol = '', $originalItem = null) { |
|
401 | + public static function drawCol($item, $colName, $params = [], $dataManager = null, $originalCol = '', $originalItem = null) { |
|
402 | 402 | $modelName = get_class($item); |
403 | 403 | if (!class_exists($modelName)) { |
404 | - return false; |
|
404 | + return false; |
|
405 | 405 | } |
406 | 406 | |
407 | 407 | if (!$originalCol) { |
408 | - $originalCol = $colName; |
|
408 | + $originalCol = $colName; |
|
409 | 409 | } |
410 | 410 | if (!$originalItem) { |
411 | - $originalItem = $item; |
|
411 | + $originalItem = $item; |
|
412 | 412 | } |
413 | 413 | |
414 | 414 | $relations = $modelName::relations(); |
415 | 415 | if (strpos($colName, ':') !== false && !empty($relations[substr($colName, 0, strpos($colName, ':'))])) { |
416 | - $rel = substr($colName, 0, strpos($colName, ':')); |
|
417 | - $col = substr($colName, strpos($colName, ':') + 1); |
|
418 | - if ($item->$rel) { |
|
416 | + $rel = substr($colName, 0, strpos($colName, ':')); |
|
417 | + $col = substr($colName, strpos($colName, ':') + 1); |
|
418 | + if ($item->$rel) { |
|
419 | 419 | return DataManager::drawCol($item->$rel, $col, $params, $dataManager, $originalCol, $originalItem); |
420 | - } else { |
|
420 | + } else { |
|
421 | 421 | return 'Не указано'; |
422 | - } |
|
422 | + } |
|
423 | 423 | } |
424 | 424 | if (!empty($modelName::$cols[$colName]['relation'])) { |
425 | - $type = !empty($relations[$modelName::$cols[$colName]['relation']]['type']) ? $relations[$modelName::$cols[$colName]['relation']]['type'] : 'to'; |
|
426 | - switch ($type) { |
|
425 | + $type = !empty($relations[$modelName::$cols[$colName]['relation']]['type']) ? $relations[$modelName::$cols[$colName]['relation']]['type'] : 'to'; |
|
426 | + switch ($type) { |
|
427 | 427 | case 'relModel': |
428 | 428 | $managerParams = ['relation' => $modelName::$cols[$colName]['relation']]; |
429 | - $count = $item->{$modelName::$cols[$colName]['relation']}(array_merge($params, ['count' => 1])); |
|
430 | - $count = $count ? $count : 'Нет'; |
|
431 | - 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>"; |
|
429 | + $count = $item->{$modelName::$cols[$colName]['relation']}(array_merge($params, ['count' => 1])); |
|
430 | + $count = $count ? $count : 'Нет'; |
|
431 | + return "<a class = 'btn btn-xs btn-primary' onclick = 'inji.Ui.dataManagers.popUp(\"" . str_replace('\\', '\\\\', $modelName) . ":" . $item->pk() . "\"," . json_encode(array_merge($params, $managerParams)) . ")'>{$count}</a>"; |
|
432 | 432 | case 'many': |
433 | 433 | $managerParams = ['relation' => $modelName::$cols[$colName]['relation']]; |
434 | - $count = $item->{$modelName::$cols[$colName]['relation']}(array_merge($params, ['count' => 1])); |
|
435 | - $count = $count ? $count : 'Нет'; |
|
436 | - 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>"; |
|
434 | + $count = $item->{$modelName::$cols[$colName]['relation']}(array_merge($params, ['count' => 1])); |
|
435 | + $count = $count ? $count : 'Нет'; |
|
436 | + return "<a class = 'btn btn-xs btn-primary' onclick = 'inji.Ui.dataManagers.popUp(\"" . str_replace('\\', '\\\\', $modelName) . ":" . $item->pk() . "\"," . json_encode(array_merge($params, $managerParams)) . ")'>{$count}</a>"; |
|
437 | 437 | default : |
438 | 438 | if ($item->{$modelName::$cols[$colName]['relation']}) { |
439 | 439 | if (\App::$cur->name == 'admin') { |
440 | - $href = "<a href ='/admin/" . str_replace('\\', '/view/', $relations[$modelName::$cols[$colName]['relation']]['model']) . "/" . $item->{$modelName::$cols[$colName]['relation']}->pk() . "'>"; |
|
441 | - if (!empty($modelName::$cols[$colName]['showCol'])) { |
|
440 | + $href = "<a href ='/admin/" . str_replace('\\', '/view/', $relations[$modelName::$cols[$colName]['relation']]['model']) . "/" . $item->{$modelName::$cols[$colName]['relation']}->pk() . "'>"; |
|
441 | + if (!empty($modelName::$cols[$colName]['showCol'])) { |
|
442 | 442 | $href .= $item->{$modelName::$cols[$colName]['relation']}->{$modelName::$cols[$colName]['showCol']}; |
443 | - } else { |
|
443 | + } else { |
|
444 | 444 | |
445 | 445 | $href .= $item->{$modelName::$cols[$colName]['relation']}->name(); |
446 | - } |
|
447 | - $href .= '</a>'; |
|
448 | - return $href; |
|
446 | + } |
|
447 | + $href .= '</a>'; |
|
448 | + return $href; |
|
449 | 449 | } else { |
450 | - return $item->{$modelName::$cols[$colName]['relation']}->name(); |
|
450 | + return $item->{$modelName::$cols[$colName]['relation']}->name(); |
|
451 | 451 | } |
452 | - } else { |
|
452 | + } else { |
|
453 | 453 | return $item->$colName; |
454 | - } |
|
455 | - } |
|
454 | + } |
|
455 | + } |
|
456 | 456 | } else { |
457 | - if (!empty($modelName::$cols[$colName]['view']['type'])) { |
|
457 | + if (!empty($modelName::$cols[$colName]['view']['type'])) { |
|
458 | 458 | switch ($modelName::$cols[$colName]['view']['type']) { |
459 | - case 'widget': |
|
459 | + case 'widget': |
|
460 | 460 | ob_start(); |
461 | 461 | \App::$cur->view->widget($modelName::$cols[$colName]['view']['widget'], ['item' => $item, 'colName' => $colName, 'colParams' => $modelName::$cols[$colName]]); |
462 | 462 | $content = ob_get_contents(); |
463 | 463 | ob_end_clean(); |
464 | 464 | return $content; |
465 | - case 'moduleMethod': |
|
465 | + case 'moduleMethod': |
|
466 | 466 | return \App::$cur->{$modelName::$cols[$colName]['view']['module']}->{$modelName::$cols[$colName]['view']['method']}($item, $colName, $modelName::$cols[$colName]); |
467 | - case 'many': |
|
467 | + case 'many': |
|
468 | 468 | $managerParams = ['relation' => $modelName::$cols[$colName]['relation']]; |
469 | 469 | $count = $item->{$modelName::$cols[$colName]['relation']}(array_merge($params, ['count' => 1])); |
470 | 470 | return "<a class = 'btn btn-xs btn-primary' onclick = 'inji.Ui.dataManagers.popUp(\"" . str_replace('\\', '\\\\', $modelName) . ":" . $item->pk() . "\"," . json_encode(array_merge($params, $managerParams)) . ")'>{$count} " . \Tools::getNumEnding($count, ['Элемент', 'Элемента', 'Элементов']) . "</a>"; |
471 | - default: |
|
471 | + default: |
|
472 | 472 | return $item->$colName; |
473 | 473 | } |
474 | - } elseif (!empty($modelName::$cols[$colName]['type'])) { |
|
474 | + } elseif (!empty($modelName::$cols[$colName]['type'])) { |
|
475 | 475 | if (\App::$cur->name == 'admin' && $originalCol == 'name' || ( $dataManager && !empty($dataManager->managerOptions['colToView']) && $dataManager->managerOptions['colToView'] == $originalCol)) { |
476 | - $formName = $dataManager && !empty($dataManager->managerOptions['editForm']) ? $dataManager->managerOptions['editForm'] : 'manager'; |
|
477 | - $redirectUrl = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/admin/' . str_replace('\\', '/', get_class($originalItem)); |
|
478 | - return "<a href ='/admin/" . str_replace('\\', '/view/', get_class($originalItem)) . "/{$originalItem->id}?formName={$formName}&redirectUrl={$redirectUrl}'>{$item->$colName}</a>"; |
|
476 | + $formName = $dataManager && !empty($dataManager->managerOptions['editForm']) ? $dataManager->managerOptions['editForm'] : 'manager'; |
|
477 | + $redirectUrl = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/admin/' . str_replace('\\', '/', get_class($originalItem)); |
|
478 | + return "<a href ='/admin/" . str_replace('\\', '/view/', get_class($originalItem)) . "/{$originalItem->id}?formName={$formName}&redirectUrl={$redirectUrl}'>{$item->$colName}</a>"; |
|
479 | 479 | } elseif (\App::$cur->name == 'admin' && $colName == 'name') { |
480 | - $redirectUrl = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/admin/' . str_replace('\\', '/', get_class($originalItem)); |
|
481 | - return "<a href ='/admin/" . str_replace('\\', '/view/', get_class($item)) . "/{$item->id}?redirectUrl={$redirectUrl}'>{$item->$colName}</a>"; |
|
480 | + $redirectUrl = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/admin/' . str_replace('\\', '/', get_class($originalItem)); |
|
481 | + return "<a href ='/admin/" . str_replace('\\', '/view/', get_class($item)) . "/{$item->id}?redirectUrl={$redirectUrl}'>{$item->$colName}</a>"; |
|
482 | 482 | } else { |
483 | - return \Model::resloveTypeValue($item, $colName); |
|
483 | + return \Model::resloveTypeValue($item, $colName); |
|
484 | 484 | } |
485 | - } else { |
|
485 | + } else { |
|
486 | 486 | return $item->$colName; |
487 | - } |
|
487 | + } |
|
488 | + } |
|
488 | 489 | } |
489 | - } |
|
490 | 490 | |
491 | - public function rowButtons($item, $params) { |
|
491 | + public function rowButtons($item, $params) { |
|
492 | 492 | $modelName = $this->modelName; |
493 | 493 | if (!class_exists($modelName)) { |
494 | - return false; |
|
494 | + return false; |
|
495 | 495 | } |
496 | 496 | ob_start(); |
497 | 497 | $widgetName = !empty($this->managerOptions['rowButtonsWidget']) ? $this->managerOptions['rowButtonsWidget'] : 'Ui\DataManager/rowButtons'; |
@@ -503,129 +503,129 @@ discard block |
||
503 | 503 | $buttons = ob_get_contents(); |
504 | 504 | ob_end_clean(); |
505 | 505 | return $buttons; |
506 | - } |
|
506 | + } |
|
507 | 507 | |
508 | - public function getPages($params = [], $model = null) { |
|
508 | + public function getPages($params = [], $model = null) { |
|
509 | 509 | $modelName = $this->modelName; |
510 | 510 | if (!class_exists($modelName)) { |
511 | - return []; |
|
511 | + return []; |
|
512 | 512 | } |
513 | 513 | if (!$this->checkAccess()) { |
514 | - $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->managerName . '"'); |
|
515 | - return []; |
|
514 | + $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->managerName . '"'); |
|
515 | + return []; |
|
516 | 516 | } |
517 | 517 | if (!empty($params['limit'])) { |
518 | - $this->limit = (int) $params['limit']; |
|
518 | + $this->limit = (int) $params['limit']; |
|
519 | 519 | } |
520 | 520 | if (!empty($params['page'])) { |
521 | - $this->page = (int) $params['page']; |
|
521 | + $this->page = (int) $params['page']; |
|
522 | 522 | } |
523 | 523 | $queryParams = [ |
524 | 524 | 'count' => true |
525 | 525 | ]; |
526 | 526 | $modelName = $this->modelName; |
527 | 527 | if (!empty($params['categoryPath']) && $modelName::$categoryModel) { |
528 | - $queryParams['where'][] = ['tree_path', $params['categoryPath'] . '%', 'LIKE']; |
|
528 | + $queryParams['where'][] = ['tree_path', $params['categoryPath'] . '%', 'LIKE']; |
|
529 | 529 | } |
530 | 530 | if (!empty($this->managerOptions['userGroupFilter'][\Users\User::$cur->group_id]['getRows'])) { |
531 | - foreach ($this->managerOptions['userGroupFilter'][\Users\User::$cur->group_id]['getRows'] as $colName => $colOptions) { |
|
531 | + foreach ($this->managerOptions['userGroupFilter'][\Users\User::$cur->group_id]['getRows'] as $colName => $colOptions) { |
|
532 | 532 | if (!empty($colOptions['userCol'])) { |
533 | - if (strpos($colOptions['userCol'], ':')) { |
|
533 | + if (strpos($colOptions['userCol'], ':')) { |
|
534 | 534 | $rel = substr($colOptions['userCol'], 0, strpos($colOptions['userCol'], ':')); |
535 | 535 | $param = substr($colOptions['userCol'], strpos($colOptions['userCol'], ':') + 1); |
536 | 536 | $queryParams['where'][] = [$colName, \Users\User::$cur->$rel->$param]; |
537 | - } |
|
537 | + } |
|
538 | 538 | } elseif (isset($colOptions['value'])) { |
539 | - $queryParams['where'][] = [$colName, $colOptions['value'], is_array($colOptions['value']) ? 'IN' : '=']; |
|
539 | + $queryParams['where'][] = [$colName, $colOptions['value'], is_array($colOptions['value']) ? 'IN' : '=']; |
|
540 | + } |
|
540 | 541 | } |
541 | - } |
|
542 | 542 | } |
543 | 543 | $modelName = $this->modelName; |
544 | 544 | if (!empty($this->managerOptions['filters'])) { |
545 | - foreach ($this->managerOptions['filters'] as $col) { |
|
545 | + foreach ($this->managerOptions['filters'] as $col) { |
|
546 | 546 | $colInfo = $modelName::getColInfo($col); |
547 | 547 | switch ($colInfo['colParams']['type']) { |
548 | - case 'select': |
|
548 | + case 'select': |
|
549 | 549 | if (empty($params['filters'][$col]['value'])) { |
550 | - continue; |
|
550 | + continue; |
|
551 | 551 | } |
552 | 552 | if (is_array($params['filters'][$col]['value'])) { |
553 | - foreach ($params['filters'][$col]['value'] as $key => $value) { |
|
553 | + foreach ($params['filters'][$col]['value'] as $key => $value) { |
|
554 | 554 | if ($value === '') { |
555 | - unset($params['filters'][$col]['value'][$key]); |
|
555 | + unset($params['filters'][$col]['value'][$key]); |
|
556 | + } |
|
556 | 557 | } |
557 | - } |
|
558 | 558 | } |
559 | 559 | if (!$params['filters'][$col]['value']) { |
560 | - continue; |
|
560 | + continue; |
|
561 | 561 | } |
562 | 562 | $queryParams['where'][] = [$col, $params['filters'][$col]['value'], is_array($params['filters'][$col]['value']) ? 'IN' : '=']; |
563 | 563 | break; |
564 | - case 'bool': |
|
564 | + case 'bool': |
|
565 | 565 | |
566 | 566 | if (empty($params['filters'][$col]['value'])) { |
567 | - continue; |
|
567 | + continue; |
|
568 | 568 | } |
569 | 569 | $queryParams['where'][] = [$col, '1']; |
570 | 570 | break; |
571 | - case 'dateTime': |
|
571 | + case 'dateTime': |
|
572 | 572 | case 'date': |
573 | 573 | if (empty($params['filters'][$col]['min']) && empty($params['filters'][$col]['max'])) { |
574 | - continue; |
|
574 | + continue; |
|
575 | 575 | } |
576 | 576 | if (!empty($params['filters'][$col]['min'])) { |
577 | - $queryParams['where'][] = [$col, $params['filters'][$col]['min'], '>=']; |
|
577 | + $queryParams['where'][] = [$col, $params['filters'][$col]['min'], '>=']; |
|
578 | 578 | } |
579 | 579 | if (!empty($params['filters'][$col]['max'])) { |
580 | - if ($colInfo['colParams']['type'] == 'dateTime' && !strpos($params['filters'][$col]['max'], ' ')) { |
|
580 | + if ($colInfo['colParams']['type'] == 'dateTime' && !strpos($params['filters'][$col]['max'], ' ')) { |
|
581 | 581 | |
582 | 582 | $date = $params['filters'][$col]['max'] . ' 23:59:59'; |
583 | - } else { |
|
583 | + } else { |
|
584 | 584 | $date = $params['filters'][$col]['max']; |
585 | - } |
|
586 | - $queryParams['where'][] = [$col, $date, '<=']; |
|
585 | + } |
|
586 | + $queryParams['where'][] = [$col, $date, '<=']; |
|
587 | 587 | } |
588 | 588 | break; |
589 | - case 'number': |
|
589 | + case 'number': |
|
590 | 590 | if (empty($params['filters'][$col]['min']) && empty($params['filters'][$col]['max'])) { |
591 | - continue; |
|
591 | + continue; |
|
592 | 592 | } |
593 | 593 | if (!empty($params['filters'][$col]['min'])) { |
594 | - $queryParams['where'][] = [$col, $params['filters'][$col]['min'], '>=']; |
|
594 | + $queryParams['where'][] = [$col, $params['filters'][$col]['min'], '>=']; |
|
595 | 595 | } |
596 | 596 | if (!empty($params['filters'][$col]['max'])) { |
597 | - $queryParams['where'][] = [$col, $params['filters'][$col]['max'], '<=']; |
|
597 | + $queryParams['where'][] = [$col, $params['filters'][$col]['max'], '<=']; |
|
598 | 598 | } |
599 | 599 | break; |
600 | - case 'email': |
|
600 | + case 'email': |
|
601 | 601 | case 'text': |
602 | 602 | case 'textarea': |
603 | 603 | case 'html': |
604 | 604 | if (empty($params['filters'][$col]['value'])) { |
605 | - continue; |
|
605 | + continue; |
|
606 | 606 | } |
607 | 607 | switch ($params['filters'][$col]['compareType']) { |
608 | - case 'contains': |
|
608 | + case 'contains': |
|
609 | 609 | $queryParams['where'][] = [$col, '%' . $params['filters'][$col]['value'] . '%', 'LIKE']; |
610 | 610 | break; |
611 | - case 'equals': |
|
611 | + case 'equals': |
|
612 | 612 | $queryParams['where'][] = [$col, $params['filters'][$col]['value']]; |
613 | 613 | break; |
614 | - case 'starts_with': |
|
614 | + case 'starts_with': |
|
615 | 615 | $queryParams['where'][] = [$col, $params['filters'][$col]['value'] . '%', 'LIKE']; |
616 | 616 | break; |
617 | - case 'ends_with': |
|
617 | + case 'ends_with': |
|
618 | 618 | $queryParams['where'][] = [$col, '%' . $params['filters'][$col]['value'], 'LIKE']; |
619 | 619 | break; |
620 | 620 | } |
621 | 621 | break; |
622 | 622 | } |
623 | - } |
|
623 | + } |
|
624 | 624 | } |
625 | 625 | if ($model && !empty($params['relation'])) { |
626 | - $count = $model->$params['relation']($queryParams); |
|
626 | + $count = $model->$params['relation']($queryParams); |
|
627 | 627 | } else { |
628 | - $count = $modelName::getCount($queryParams); |
|
628 | + $count = $modelName::getCount($queryParams); |
|
629 | 629 | } |
630 | 630 | $pages = new Pages([ |
631 | 631 | 'limit' => $this->limit, |
@@ -635,9 +635,9 @@ discard block |
||
635 | 635 | 'dataManager' => $this |
636 | 636 | ]); |
637 | 637 | return $pages; |
638 | - } |
|
638 | + } |
|
639 | 639 | |
640 | - public function preDraw($params = [], $model = null) { |
|
640 | + public function preDraw($params = [], $model = null) { |
|
641 | 641 | $this->predraw = true; |
642 | 642 | |
643 | 643 | $cols = $this->getCols(); |
@@ -645,16 +645,16 @@ discard block |
||
645 | 645 | $this->table = new Table(); |
646 | 646 | $tableCols = []; |
647 | 647 | foreach ($cols as $colName => $colOptions) { |
648 | - $tableCols[] = !empty($colOptions['label']) ? $colOptions['label'] : $colName; |
|
648 | + $tableCols[] = !empty($colOptions['label']) ? $colOptions['label'] : $colName; |
|
649 | 649 | } |
650 | 650 | $tableCols[] = ''; |
651 | 651 | $this->table->class .=' datamanagertable'; |
652 | 652 | $this->table->setCols($tableCols); |
653 | - } |
|
653 | + } |
|
654 | 654 | |
655 | - public function draw($params = [], $model = null) { |
|
655 | + public function draw($params = [], $model = null) { |
|
656 | 656 | if (!$this->predraw) { |
657 | - $this->preDraw($params, $model); |
|
657 | + $this->preDraw($params, $model); |
|
658 | 658 | } |
659 | 659 | \App::$cur->view->widget('Ui\DataManager/DataManager', [ |
660 | 660 | 'dataManager' => $this, |
@@ -662,58 +662,58 @@ discard block |
||
662 | 662 | 'table' => $this->table, |
663 | 663 | 'params' => $params |
664 | 664 | ]); |
665 | - } |
|
665 | + } |
|
666 | 666 | |
667 | - public function drawCategorys() { |
|
667 | + public function drawCategorys() { |
|
668 | 668 | if (!class_exists($this->modelName)) { |
669 | - return false; |
|
669 | + return false; |
|
670 | 670 | } |
671 | 671 | if (!$this->checkAccess()) { |
672 | - $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->managerName . '"'); |
|
673 | - return []; |
|
672 | + $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->managerName . '"'); |
|
673 | + return []; |
|
674 | 674 | } |
675 | 675 | $tree = new Tree(); |
676 | 676 | $tree->ul($this->managerOptions['categorys']['model'], 0, function($category) { |
677 | - $path = $category->tree_path . ($category->pk() ? $category->pk() . "/" : ''); |
|
678 | - $cleanClassName = str_replace('\\', '\\\\', get_class($category)); |
|
679 | - 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> |
|
677 | + $path = $category->tree_path . ($category->pk() ? $category->pk() . "/" : ''); |
|
678 | + $cleanClassName = str_replace('\\', '\\\\', get_class($category)); |
|
679 | + 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> |
|
680 | 680 | |
681 | 681 | <a href = '#' class ='glyphicon glyphicon-edit' onclick = 'inji.Ui.forms.popUp(\"{$cleanClassName}:{$category->pk()}\")'></a> |
682 | 682 | <a href = '#' class ='glyphicon glyphicon-remove' onclick = 'inji.Ui.dataManagers.get(this).delCategory({$category->pk()});return false;'></a>"; |
683 | 683 | }); |
684 | 684 | ?> |
685 | 685 | <?php |
686 | - } |
|
687 | - |
|
688 | - /** |
|
689 | - * Draw error message |
|
690 | - * |
|
691 | - * @param string $errorText |
|
692 | - */ |
|
693 | - public function drawError($errorText) { |
|
686 | + } |
|
687 | + |
|
688 | + /** |
|
689 | + * Draw error message |
|
690 | + * |
|
691 | + * @param string $errorText |
|
692 | + */ |
|
693 | + public function drawError($errorText) { |
|
694 | 694 | echo $errorText; |
695 | - } |
|
696 | - |
|
697 | - /** |
|
698 | - * Check access cur user to manager with name in param |
|
699 | - * |
|
700 | - * @return boolean |
|
701 | - */ |
|
702 | - public function checkAccess() { |
|
695 | + } |
|
696 | + |
|
697 | + /** |
|
698 | + * Check access cur user to manager with name in param |
|
699 | + * |
|
700 | + * @return boolean |
|
701 | + */ |
|
702 | + public function checkAccess() { |
|
703 | 703 | if (\App::$cur->Access && !\App::$cur->Access->checkAccess($this)) { |
704 | - return false; |
|
704 | + return false; |
|
705 | 705 | } |
706 | 706 | |
707 | 707 | if (!empty($this->managerOptions['options']['access']['apps']) && !in_array(\App::$cur->name, $this->managerOptions['options']['access']['apps'])) { |
708 | - return false; |
|
708 | + return false; |
|
709 | 709 | } |
710 | 710 | if (!empty($this->managerOptions['options']['access']['groups']) && in_array(\Users\User::$cur->group_id, $this->managerOptions['options']['access']['groups'])) { |
711 | - return true; |
|
711 | + return true; |
|
712 | 712 | } |
713 | 713 | if ($this->managerName == 'manager' && !\Users\User::$cur->isAdmin()) { |
714 | - return false; |
|
714 | + return false; |
|
715 | 715 | } |
716 | 716 | return true; |
717 | - } |
|
717 | + } |
|
718 | 718 | |
719 | 719 | } |
@@ -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'; |
@@ -121,8 +121,8 @@ discard block |
||
121 | 121 | } |
122 | 122 | if (!empty($modelName::$forms[$formParams['formName']])) { |
123 | 123 | $buttons[] = [ |
124 | - 'text' => 'Создать ' . $name, |
|
125 | - 'onclick' => 'inji.Ui.dataManagers.get(this).newItem("' . str_replace('\\', '\\\\', $modelName) . '",' . json_encode($formParams) . ');', |
|
124 | + 'text' => 'Создать '.$name, |
|
125 | + 'onclick' => 'inji.Ui.dataManagers.get(this).newItem("'.str_replace('\\', '\\\\', $modelName).'",'.json_encode($formParams).');', |
|
126 | 126 | ]; |
127 | 127 | } |
128 | 128 | |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | 'className' => $action |
153 | 153 | ]; |
154 | 154 | } |
155 | - $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']; |
|
155 | + $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']; |
|
156 | 156 | if (!class_exists($return[$key]['className']) || ($onlyGroupActions && !$return[$key]['className']::$groupAction)) { |
157 | 157 | unset($return[$key]); |
158 | 158 | } |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | <?php |
184 | 184 | foreach ($actions as $action => $actionParams) { |
185 | 185 | if (class_exists($actionParams['className']) && $actionParams['className']::$groupAction) { |
186 | - echo "<li><a role='button' href ='#' onclick='inji.Ui.dataManagers.get(this).groupAction(\"" . str_replace('\\', '\\\\', $action) . "\");return false;'>{$actionParams['className']::$name}</a></li>"; |
|
186 | + echo "<li><a role='button' href ='#' onclick='inji.Ui.dataManagers.get(this).groupAction(\"".str_replace('\\', '\\\\', $action)."\");return false;'>{$actionParams['className']::$name}</a></li>"; |
|
187 | 187 | } |
188 | 188 | } |
189 | 189 | ?> |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | return []; |
234 | 234 | } |
235 | 235 | if (!$this->checkAccess()) { |
236 | - $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->managerName . '"'); |
|
236 | + $this->drawError('you not have access to "'.$this->modelName.'" manager with name: "'.$this->managerName.'"'); |
|
237 | 237 | return []; |
238 | 238 | } |
239 | 239 | $modelName = $this->modelName; |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | $queryParams['start'] = $this->page * $this->limit - $this->limit; |
250 | 250 | } |
251 | 251 | if (!empty($params['categoryPath']) && $modelName::$categoryModel) { |
252 | - $queryParams['where'][] = ['tree_path', $params['categoryPath'] . '%', 'LIKE']; |
|
252 | + $queryParams['where'][] = ['tree_path', $params['categoryPath'].'%', 'LIKE']; |
|
253 | 253 | } |
254 | 254 | if (!empty($params['appType'])) { |
255 | 255 | $queryParams['appType'] = $params['appType']; |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | if (!empty($params['filters'][$col]['max'])) { |
309 | 309 | if ($colInfo['colParams']['type'] == 'dateTime' && !strpos($params['filters'][$col]['max'], ' ')) { |
310 | 310 | |
311 | - $date = $params['filters'][$col]['max'] . ' 23:59:59'; |
|
311 | + $date = $params['filters'][$col]['max'].' 23:59:59'; |
|
312 | 312 | } else { |
313 | 313 | $date = $params['filters'][$col]['max']; |
314 | 314 | } |
@@ -335,16 +335,16 @@ discard block |
||
335 | 335 | } |
336 | 336 | switch ($params['filters'][$col]['compareType']) { |
337 | 337 | case 'contains': |
338 | - $queryParams['where'][] = [$col, '%' . $params['filters'][$col]['value'] . '%', 'LIKE']; |
|
338 | + $queryParams['where'][] = [$col, '%'.$params['filters'][$col]['value'].'%', 'LIKE']; |
|
339 | 339 | break; |
340 | 340 | case 'equals': |
341 | 341 | $queryParams['where'][] = [$col, $params['filters'][$col]['value']]; |
342 | 342 | break; |
343 | 343 | case 'starts_with': |
344 | - $queryParams['where'][] = [$col, $params['filters'][$col]['value'] . '%', 'LIKE']; |
|
344 | + $queryParams['where'][] = [$col, $params['filters'][$col]['value'].'%', 'LIKE']; |
|
345 | 345 | break; |
346 | 346 | case 'ends_with': |
347 | - $queryParams['where'][] = [$col, '%' . $params['filters'][$col]['value'], 'LIKE']; |
|
347 | + $queryParams['where'][] = [$col, '%'.$params['filters'][$col]['value'], 'LIKE']; |
|
348 | 348 | break; |
349 | 349 | } |
350 | 350 | break; |
@@ -383,7 +383,7 @@ discard block |
||
383 | 383 | $item = $relation['relModel']::get([[$item->index(), $item->id], [$model->index(), $model->id]]); |
384 | 384 | } |
385 | 385 | $row = []; |
386 | - $row[] = '<input type ="checkbox" name = "pk[]" value =' . $item->pk() . '>'; |
|
386 | + $row[] = '<input type ="checkbox" name = "pk[]" value ='.$item->pk().'>'; |
|
387 | 387 | $row[] = $item->pk(); |
388 | 388 | foreach ($this->managerOptions['cols'] as $key => $colName) { |
389 | 389 | if (!empty($params['download'])) { |
@@ -428,16 +428,16 @@ discard block |
||
428 | 428 | $managerParams = ['relation' => $modelName::$cols[$colName]['relation']]; |
429 | 429 | $count = $item->{$modelName::$cols[$colName]['relation']}(array_merge($params, ['count' => 1])); |
430 | 430 | $count = $count ? $count : 'Нет'; |
431 | - 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>"; |
|
431 | + return "<a class = 'btn btn-xs btn-primary' onclick = 'inji.Ui.dataManagers.popUp(\"".str_replace('\\', '\\\\', $modelName).":".$item->pk()."\",".json_encode(array_merge($params, $managerParams)).")'>{$count}</a>"; |
|
432 | 432 | case 'many': |
433 | 433 | $managerParams = ['relation' => $modelName::$cols[$colName]['relation']]; |
434 | 434 | $count = $item->{$modelName::$cols[$colName]['relation']}(array_merge($params, ['count' => 1])); |
435 | 435 | $count = $count ? $count : 'Нет'; |
436 | - 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>"; |
|
436 | + return "<a class = 'btn btn-xs btn-primary' onclick = 'inji.Ui.dataManagers.popUp(\"".str_replace('\\', '\\\\', $modelName).":".$item->pk()."\",".json_encode(array_merge($params, $managerParams)).")'>{$count}</a>"; |
|
437 | 437 | default : |
438 | 438 | if ($item->{$modelName::$cols[$colName]['relation']}) { |
439 | 439 | if (\App::$cur->name == 'admin') { |
440 | - $href = "<a href ='/admin/" . str_replace('\\', '/view/', $relations[$modelName::$cols[$colName]['relation']]['model']) . "/" . $item->{$modelName::$cols[$colName]['relation']}->pk() . "'>"; |
|
440 | + $href = "<a href ='/admin/".str_replace('\\', '/view/', $relations[$modelName::$cols[$colName]['relation']]['model'])."/".$item->{$modelName::$cols[$colName]['relation']}->pk()."'>"; |
|
441 | 441 | if (!empty($modelName::$cols[$colName]['showCol'])) { |
442 | 442 | $href .= $item->{$modelName::$cols[$colName]['relation']}->{$modelName::$cols[$colName]['showCol']}; |
443 | 443 | } else { |
@@ -467,18 +467,18 @@ discard block |
||
467 | 467 | case 'many': |
468 | 468 | $managerParams = ['relation' => $modelName::$cols[$colName]['relation']]; |
469 | 469 | $count = $item->{$modelName::$cols[$colName]['relation']}(array_merge($params, ['count' => 1])); |
470 | - 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>"; |
|
470 | + return "<a class = 'btn btn-xs btn-primary' onclick = 'inji.Ui.dataManagers.popUp(\"".str_replace('\\', '\\\\', $modelName).":".$item->pk()."\",".json_encode(array_merge($params, $managerParams)).")'>{$count} ".\Tools::getNumEnding($count, ['Элемент', 'Элемента', 'Элементов'])."</a>"; |
|
471 | 471 | default: |
472 | 472 | return $item->$colName; |
473 | 473 | } |
474 | 474 | } elseif (!empty($modelName::$cols[$colName]['type'])) { |
475 | - if (\App::$cur->name == 'admin' && $originalCol == 'name' || ( $dataManager && !empty($dataManager->managerOptions['colToView']) && $dataManager->managerOptions['colToView'] == $originalCol)) { |
|
475 | + if (\App::$cur->name == 'admin' && $originalCol == 'name' || ($dataManager && !empty($dataManager->managerOptions['colToView']) && $dataManager->managerOptions['colToView'] == $originalCol)) { |
|
476 | 476 | $formName = $dataManager && !empty($dataManager->managerOptions['editForm']) ? $dataManager->managerOptions['editForm'] : 'manager'; |
477 | - $redirectUrl = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/admin/' . str_replace('\\', '/', get_class($originalItem)); |
|
478 | - return "<a href ='/admin/" . str_replace('\\', '/view/', get_class($originalItem)) . "/{$originalItem->id}?formName={$formName}&redirectUrl={$redirectUrl}'>{$item->$colName}</a>"; |
|
477 | + $redirectUrl = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/admin/'.str_replace('\\', '/', get_class($originalItem)); |
|
478 | + return "<a href ='/admin/".str_replace('\\', '/view/', get_class($originalItem))."/{$originalItem->id}?formName={$formName}&redirectUrl={$redirectUrl}'>{$item->$colName}</a>"; |
|
479 | 479 | } elseif (\App::$cur->name == 'admin' && $colName == 'name') { |
480 | - $redirectUrl = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/admin/' . str_replace('\\', '/', get_class($originalItem)); |
|
481 | - return "<a href ='/admin/" . str_replace('\\', '/view/', get_class($item)) . "/{$item->id}?redirectUrl={$redirectUrl}'>{$item->$colName}</a>"; |
|
480 | + $redirectUrl = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/admin/'.str_replace('\\', '/', get_class($originalItem)); |
|
481 | + return "<a href ='/admin/".str_replace('\\', '/view/', get_class($item))."/{$item->id}?redirectUrl={$redirectUrl}'>{$item->$colName}</a>"; |
|
482 | 482 | } else { |
483 | 483 | return \Model::resloveTypeValue($item, $colName); |
484 | 484 | } |
@@ -511,7 +511,7 @@ discard block |
||
511 | 511 | return []; |
512 | 512 | } |
513 | 513 | if (!$this->checkAccess()) { |
514 | - $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->managerName . '"'); |
|
514 | + $this->drawError('you not have access to "'.$this->modelName.'" manager with name: "'.$this->managerName.'"'); |
|
515 | 515 | return []; |
516 | 516 | } |
517 | 517 | if (!empty($params['limit'])) { |
@@ -525,7 +525,7 @@ discard block |
||
525 | 525 | ]; |
526 | 526 | $modelName = $this->modelName; |
527 | 527 | if (!empty($params['categoryPath']) && $modelName::$categoryModel) { |
528 | - $queryParams['where'][] = ['tree_path', $params['categoryPath'] . '%', 'LIKE']; |
|
528 | + $queryParams['where'][] = ['tree_path', $params['categoryPath'].'%', 'LIKE']; |
|
529 | 529 | } |
530 | 530 | if (!empty($this->managerOptions['userGroupFilter'][\Users\User::$cur->group_id]['getRows'])) { |
531 | 531 | foreach ($this->managerOptions['userGroupFilter'][\Users\User::$cur->group_id]['getRows'] as $colName => $colOptions) { |
@@ -579,7 +579,7 @@ discard block |
||
579 | 579 | if (!empty($params['filters'][$col]['max'])) { |
580 | 580 | if ($colInfo['colParams']['type'] == 'dateTime' && !strpos($params['filters'][$col]['max'], ' ')) { |
581 | 581 | |
582 | - $date = $params['filters'][$col]['max'] . ' 23:59:59'; |
|
582 | + $date = $params['filters'][$col]['max'].' 23:59:59'; |
|
583 | 583 | } else { |
584 | 584 | $date = $params['filters'][$col]['max']; |
585 | 585 | } |
@@ -606,16 +606,16 @@ discard block |
||
606 | 606 | } |
607 | 607 | switch ($params['filters'][$col]['compareType']) { |
608 | 608 | case 'contains': |
609 | - $queryParams['where'][] = [$col, '%' . $params['filters'][$col]['value'] . '%', 'LIKE']; |
|
609 | + $queryParams['where'][] = [$col, '%'.$params['filters'][$col]['value'].'%', 'LIKE']; |
|
610 | 610 | break; |
611 | 611 | case 'equals': |
612 | 612 | $queryParams['where'][] = [$col, $params['filters'][$col]['value']]; |
613 | 613 | break; |
614 | 614 | case 'starts_with': |
615 | - $queryParams['where'][] = [$col, $params['filters'][$col]['value'] . '%', 'LIKE']; |
|
615 | + $queryParams['where'][] = [$col, $params['filters'][$col]['value'].'%', 'LIKE']; |
|
616 | 616 | break; |
617 | 617 | case 'ends_with': |
618 | - $queryParams['where'][] = [$col, '%' . $params['filters'][$col]['value'], 'LIKE']; |
|
618 | + $queryParams['where'][] = [$col, '%'.$params['filters'][$col]['value'], 'LIKE']; |
|
619 | 619 | break; |
620 | 620 | } |
621 | 621 | break; |
@@ -648,7 +648,7 @@ discard block |
||
648 | 648 | $tableCols[] = !empty($colOptions['label']) ? $colOptions['label'] : $colName; |
649 | 649 | } |
650 | 650 | $tableCols[] = ''; |
651 | - $this->table->class .=' datamanagertable'; |
|
651 | + $this->table->class .= ' datamanagertable'; |
|
652 | 652 | $this->table->setCols($tableCols); |
653 | 653 | } |
654 | 654 | |
@@ -669,12 +669,12 @@ discard block |
||
669 | 669 | return false; |
670 | 670 | } |
671 | 671 | if (!$this->checkAccess()) { |
672 | - $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->managerName . '"'); |
|
672 | + $this->drawError('you not have access to "'.$this->modelName.'" manager with name: "'.$this->managerName.'"'); |
|
673 | 673 | return []; |
674 | 674 | } |
675 | 675 | $tree = new Tree(); |
676 | 676 | $tree->ul($this->managerOptions['categorys']['model'], 0, function($category) { |
677 | - $path = $category->tree_path . ($category->pk() ? $category->pk() . "/" : ''); |
|
677 | + $path = $category->tree_path.($category->pk() ? $category->pk()."/" : ''); |
|
678 | 678 | $cleanClassName = str_replace('\\', '\\\\', get_class($category)); |
679 | 679 | 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> |
680 | 680 |
@@ -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 |
@@ -6,10 +6,10 @@ discard block |
||
6 | 6 | <?= $label; ?> |
7 | 7 | </h3> |
8 | 8 | <?php |
9 | - if ($options['source'] == 'relation' && empty($options['modelPk'])) { |
|
9 | + if ($options['source'] == 'relation' && empty($options['modelPk'])) { |
|
10 | 10 | echo '<h4 class=" text-muted">Чтобы добавить связи, сначала создайте объект</h4>'; |
11 | 11 | echo '<p class=" text-muted">Просто заполните доступные поля и нажмите кнопку внизу формы. После этого дополнительные поля разблокируются</p>'; |
12 | - } else { |
|
12 | + } else { |
|
13 | 13 | ?> |
14 | 14 | <div class="table-responsive"> |
15 | 15 | <table class ='table table-striped'> |
@@ -17,15 +17,15 @@ discard block |
||
17 | 17 | <tr> |
18 | 18 | <?php |
19 | 19 | foreach ($options['cols'] as $colName => $col) { |
20 | - echo "<th>"; |
|
21 | - echo $col['col']['label']; |
|
22 | - if (!empty($col['col']['model'])) { |
|
20 | + echo "<th>"; |
|
21 | + echo $col['col']['label']; |
|
22 | + if (!empty($col['col']['model'])) { |
|
23 | 23 | $modelName = $col['col']['model']; |
24 | 24 | $onclick = 'inji.Ui.forms.popUp(\'' . addslashes($modelName) . '\',{},function(elem){' |
25 | 25 | . 'return function(data,modal){inji.Ui.forms.submitAjax($(elem).closest(\'form\')[0], {notSave: true});}}(this));return false;'; |
26 | 26 | echo ' (<a href="" onclick="' . $onclick . ';this.disabled=true;return false;">Создать</a>)'; |
27 | - } |
|
28 | - echo "</th>"; |
|
27 | + } |
|
28 | + echo "</th>"; |
|
29 | 29 | } |
30 | 30 | ?> |
31 | 31 | <td> </td> |
@@ -33,29 +33,29 @@ discard block |
||
33 | 33 | </thead> |
34 | 34 | <tbody class="listBody"> |
35 | 35 | <?php |
36 | - $i = 0; |
|
37 | - if (!empty($options['values'])) { |
|
36 | + $i = 0; |
|
37 | + if (!empty($options['values'])) { |
|
38 | 38 | foreach ($options['values'] as $row) { |
39 | - $i++; |
|
40 | - echo '<tr>'; |
|
41 | - foreach ($options['cols'] as $colName => $col) { |
|
39 | + $i++; |
|
40 | + echo '<tr>'; |
|
41 | + foreach ($options['cols'] as $colName => $col) { |
|
42 | 42 | echo '<td>'; |
43 | 43 | $col['options']['noContainer'] = true; |
44 | 44 | $col['options']['value'] = $row[$colName]; |
45 | 45 | $form->input($col['type'], $name . '[' . ($i) . '][' . $colName . ']', false, $col['options']); |
46 | 46 | echo '</td>'; |
47 | - } |
|
48 | - echo '<td class="actionTd"><a class="btn btn-danger btn-xs" onclick="inji.Ui.forms.delRowFromList(this);"><i class="glyphicon glyphicon-remove"></i></a></td>'; |
|
49 | - echo '</tr>'; |
|
47 | + } |
|
48 | + echo '<td class="actionTd"><a class="btn btn-danger btn-xs" onclick="inji.Ui.forms.delRowFromList(this);"><i class="glyphicon glyphicon-remove"></i></a></td>'; |
|
49 | + echo '</tr>'; |
|
50 | 50 | } |
51 | - } |
|
52 | - ?> |
|
51 | + } |
|
52 | + ?> |
|
53 | 53 | </tbody> |
54 | 54 | <tfoot> |
55 | 55 | <tr> |
56 | 56 | <?php |
57 | 57 | foreach ($options['cols'] as $colName => $col) { |
58 | - echo "<th>{$col['col']['label']}</th>"; |
|
58 | + echo "<th>{$col['col']['label']}</th>"; |
|
59 | 59 | } |
60 | 60 | ?> |
61 | 61 | <td> </td> |
@@ -68,21 +68,21 @@ discard block |
||
68 | 68 | <script>/* |
69 | 69 | <tr> |
70 | 70 | <?php |
71 | - foreach ($options['cols'] as $colName => $col) { |
|
71 | + foreach ($options['cols'] as $colName => $col) { |
|
72 | 72 | echo '<td>'; |
73 | 73 | $col['input']->options['noContainer'] = true; |
74 | 74 | $col['input']->colParams['label'] = false; |
75 | 75 | $col['input']->draw(); |
76 | 76 | echo '</td>'; |
77 | - } |
|
78 | - ?> |
|
77 | + } |
|
78 | + ?> |
|
79 | 79 | <td class="actionTd"><a class="btn btn-danger btn-xs" onclick="inji.Ui.forms.delRowFromList(this);"><i class="glyphicon glyphicon-remove"></i></a></td> |
80 | 80 | </tr> |
81 | 81 | */</script> |
82 | 82 | </div> |
83 | 83 | <?php |
84 | - } |
|
85 | - ?> |
|
84 | + } |
|
85 | + ?> |
|
86 | 86 | </div> |
87 | 87 | <?php |
88 | 88 | //exit(); |
@@ -21,9 +21,9 @@ discard block |
||
21 | 21 | echo $col['col']['label']; |
22 | 22 | if (!empty($col['col']['model'])) { |
23 | 23 | $modelName = $col['col']['model']; |
24 | - $onclick = 'inji.Ui.forms.popUp(\'' . addslashes($modelName) . '\',{},function(elem){' |
|
24 | + $onclick = 'inji.Ui.forms.popUp(\''.addslashes($modelName).'\',{},function(elem){' |
|
25 | 25 | . 'return function(data,modal){inji.Ui.forms.submitAjax($(elem).closest(\'form\')[0], {notSave: true});}}(this));return false;'; |
26 | - echo ' (<a href="" onclick="' . $onclick . ';this.disabled=true;return false;">Создать</a>)'; |
|
26 | + echo ' (<a href="" onclick="'.$onclick.';this.disabled=true;return false;">Создать</a>)'; |
|
27 | 27 | } |
28 | 28 | echo "</th>"; |
29 | 29 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | echo '<td>'; |
43 | 43 | $col['options']['noContainer'] = true; |
44 | 44 | $col['options']['value'] = $row[$colName]; |
45 | - $form->input($col['type'], $name . '[' . ($i) . '][' . $colName . ']', false, $col['options']); |
|
45 | + $form->input($col['type'], $name.'['.($i).']['.$colName.']', false, $col['options']); |
|
46 | 46 | echo '</td>'; |
47 | 47 | } |
48 | 48 | echo '<td class="actionTd"><a class="btn btn-danger btn-xs" onclick="inji.Ui.forms.delRowFromList(this);"><i class="glyphicon glyphicon-remove"></i></a></td>'; |
@@ -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 ($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,186 +134,186 @@ 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['order'])) { |
|
243 | + } |
|
244 | + if (!empty($relation['order'])) { |
|
245 | 245 | $options['order'] = $relation['order']; |
246 | - } |
|
247 | - if (!empty($inputParams['itemName'])) { |
|
246 | + } |
|
247 | + if (!empty($inputParams['itemName'])) { |
|
248 | 248 | $options['itemName'] = $inputParams['itemName']; |
249 | - } |
|
250 | - $items = $relation['model']::getList($options); |
|
249 | + } |
|
250 | + $items = $relation['model']::getList($options); |
|
251 | 251 | } |
252 | 252 | if (!empty($params['noEmptyValue'])) { |
253 | - $values = []; |
|
253 | + $values = []; |
|
254 | 254 | } else { |
255 | - $values = [0 => 'Не задано']; |
|
255 | + $values = [0 => 'Не задано']; |
|
256 | 256 | } |
257 | 257 | foreach ($items as $key => $item) { |
258 | - if (!empty($inputParams['showCol'])) { |
|
258 | + if (!empty($inputParams['showCol'])) { |
|
259 | 259 | if (is_array($inputParams['showCol'])) { |
260 | - switch ($inputParams['showCol']['type']) { |
|
260 | + switch ($inputParams['showCol']['type']) { |
|
261 | 261 | case 'staticMethod': |
262 | 262 | $values[$key] = $inputParams['showCol']['class']::{$inputParams['showCol']['method']}($item); |
263 | - break; |
|
264 | - } |
|
263 | + break; |
|
264 | + } |
|
265 | 265 | } else { |
266 | - $values[$key] = $item->$inputParams['showCol']; |
|
266 | + $values[$key] = $item->$inputParams['showCol']; |
|
267 | 267 | } |
268 | - } else { |
|
268 | + } else { |
|
269 | 269 | $values[$key] = $item->name(); |
270 | - } |
|
270 | + } |
|
271 | 271 | } |
272 | 272 | break; |
273 | 273 | } |
274 | 274 | foreach ($values as $key => $value) { |
275 | - if (is_array($value) && !empty($value['input']) && empty($value['input']['noprefix'])) { |
|
275 | + if (is_array($value) && !empty($value['input']) && empty($value['input']['noprefix'])) { |
|
276 | 276 | $values[$key]['input']['name'] = $aditionalInputNamePrefix . "[{$value['input']['name']}]"; |
277 | - } |
|
277 | + } |
|
278 | 278 | } |
279 | 279 | return $values; |
280 | - } |
|
280 | + } |
|
281 | 281 | |
282 | - /** |
|
283 | - * Draw error message |
|
284 | - * |
|
285 | - * @param string $errorText |
|
286 | - */ |
|
287 | - public function drawError($errorText) { |
|
282 | + /** |
|
283 | + * Draw error message |
|
284 | + * |
|
285 | + * @param string $errorText |
|
286 | + */ |
|
287 | + public function drawError($errorText) { |
|
288 | 288 | echo $errorText; |
289 | - } |
|
289 | + } |
|
290 | 290 | |
291 | - /** |
|
292 | - * Check access cur user to form with name in param and $model |
|
293 | - * |
|
294 | - * @return boolean |
|
295 | - */ |
|
296 | - public function checkAccess() { |
|
291 | + /** |
|
292 | + * Check access cur user to form with name in param and $model |
|
293 | + * |
|
294 | + * @return boolean |
|
295 | + */ |
|
296 | + public function checkAccess() { |
|
297 | 297 | if (empty($this->form)) { |
298 | - $this->drawError('"' . $this->modelName . '" form with name: "' . $this->formName . '" not found'); |
|
299 | - return false; |
|
298 | + $this->drawError('"' . $this->modelName . '" form with name: "' . $this->formName . '" not found'); |
|
299 | + return false; |
|
300 | 300 | } |
301 | 301 | if (\App::$cur->Access && !\App::$cur->Access->checkAccess($this)) { |
302 | - return false; |
|
302 | + return false; |
|
303 | 303 | } |
304 | 304 | if (!empty($this->form['options']['access']['apps']) && !in_array(\App::$cur->name, $this->form['options']['access']['apps'])) { |
305 | - return false; |
|
305 | + return false; |
|
306 | 306 | } |
307 | 307 | if (!empty($this->form['options']['access']['groups']) && in_array(\Users\User::$cur->group_id, $this->form['options']['access']['groups'])) { |
308 | - return true; |
|
308 | + return true; |
|
309 | 309 | } |
310 | 310 | if ($this->model && !empty($this->form['options']['access']['self']) && \Users\User::$cur->id == $this->model->user_id) { |
311 | - return true; |
|
311 | + return true; |
|
312 | 312 | } |
313 | 313 | if ($this->formName == 'manager' && !\Users\User::$cur->isAdmin()) { |
314 | - return false; |
|
314 | + return false; |
|
315 | 315 | } |
316 | 316 | return true; |
317 | - } |
|
317 | + } |
|
318 | 318 | |
319 | 319 | } |
@@ -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)) { |