@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | |
14 | 14 | class File extends \Exchange1c\Mode { |
15 | 15 | |
16 | - public function process() { |
|
16 | + public function process() { |
|
17 | 17 | $dir = $this->exchange->path; |
18 | 18 | \Tools::createDir($dir); |
19 | 19 | $file = new \Exchange1c\Exchange\File(); |
@@ -24,26 +24,26 @@ discard block |
||
24 | 24 | |
25 | 25 | $filename = \Tools::parsePath($_GET['filename']); |
26 | 26 | if (strpos($filename, '/') !== false) { |
27 | - $subDir = substr($filename, 0, strrpos($filename, "/") + 1); |
|
28 | - \Tools::createDir($dir . '/' . $subDir); |
|
27 | + $subDir = substr($filename, 0, strrpos($filename, "/") + 1); |
|
28 | + \Tools::createDir($dir . '/' . $subDir); |
|
29 | 29 | } |
30 | 30 | $text = ''; |
31 | 31 | if (false === file_put_contents($dir . '/' . $filename, file_get_contents("php://input"))) { |
32 | - $text = 'Fail on save file: ' . $filename; |
|
33 | - $file->status = 'failure'; |
|
32 | + $text = 'Fail on save file: ' . $filename; |
|
33 | + $file->status = 'failure'; |
|
34 | 34 | } else { |
35 | - $file->size = ceil(filesize($dir . '/' . $filename)); |
|
36 | - $file->name = $filename; |
|
37 | - $file->status = 'success'; |
|
35 | + $file->size = ceil(filesize($dir . '/' . $filename)); |
|
36 | + $file->name = $filename; |
|
37 | + $file->status = 'success'; |
|
38 | 38 | } |
39 | 39 | $file->save(); |
40 | 40 | if (strpos($filename, '1cbitrix') !== false) { |
41 | - $data = new \SimpleXMLElement(file_get_contents($dir . '/' . $filename)); |
|
42 | - $orders = new \Exchange1c\Parser\Orders($data); |
|
43 | - $orders->process(); |
|
41 | + $data = new \SimpleXMLElement(file_get_contents($dir . '/' . $filename)); |
|
42 | + $orders = new \Exchange1c\Parser\Orders($data); |
|
43 | + $orders->process(); |
|
44 | 44 | } |
45 | 45 | \App::$cur->exchange1c->response($file->status, $text, false); |
46 | 46 | $this->end($file->status); |
47 | - } |
|
47 | + } |
|
48 | 48 | |
49 | 49 | } |
@@ -25,20 +25,20 @@ |
||
25 | 25 | $filename = \Tools::parsePath($_GET['filename']); |
26 | 26 | if (strpos($filename, '/') !== false) { |
27 | 27 | $subDir = substr($filename, 0, strrpos($filename, "/") + 1); |
28 | - \Tools::createDir($dir . '/' . $subDir); |
|
28 | + \Tools::createDir($dir.'/'.$subDir); |
|
29 | 29 | } |
30 | 30 | $text = ''; |
31 | - if (false === file_put_contents($dir . '/' . $filename, file_get_contents("php://input"))) { |
|
32 | - $text = 'Fail on save file: ' . $filename; |
|
31 | + if (false === file_put_contents($dir.'/'.$filename, file_get_contents("php://input"))) { |
|
32 | + $text = 'Fail on save file: '.$filename; |
|
33 | 33 | $file->status = 'failure'; |
34 | 34 | } else { |
35 | - $file->size = ceil(filesize($dir . '/' . $filename)); |
|
35 | + $file->size = ceil(filesize($dir.'/'.$filename)); |
|
36 | 36 | $file->name = $filename; |
37 | 37 | $file->status = 'success'; |
38 | 38 | } |
39 | 39 | $file->save(); |
40 | 40 | if (strpos($filename, '1cbitrix') !== false) { |
41 | - $data = new \SimpleXMLElement(file_get_contents($dir . '/' . $filename)); |
|
41 | + $data = new \SimpleXMLElement(file_get_contents($dir.'/'.$filename)); |
|
42 | 42 | $orders = new \Exchange1c\Parser\Orders($data); |
43 | 43 | $orders->process(); |
44 | 44 | } |
@@ -13,37 +13,37 @@ |
||
13 | 13 | |
14 | 14 | class File extends \Model { |
15 | 15 | |
16 | - public static $cols = [ |
|
17 | - 'name' => ['type' => 'text'], |
|
18 | - 'exchange_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'exchange'], |
|
19 | - 'size' => ['type' => 'number'], |
|
20 | - 'status' => ['type' => 'text'], |
|
21 | - 'deleted' => ['type' => 'bool'], |
|
22 | - 'date_create' => ['type' => 'dateTime'], |
|
23 | - ]; |
|
24 | - public static $dataManagers = [ |
|
25 | - 'manager' => [ |
|
26 | - 'cols' => [ |
|
27 | - 'name', 'size', 'status', 'deleted', 'date_create' |
|
28 | - ], |
|
29 | - ] |
|
30 | - ]; |
|
16 | + public static $cols = [ |
|
17 | + 'name' => ['type' => 'text'], |
|
18 | + 'exchange_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'exchange'], |
|
19 | + 'size' => ['type' => 'number'], |
|
20 | + 'status' => ['type' => 'text'], |
|
21 | + 'deleted' => ['type' => 'bool'], |
|
22 | + 'date_create' => ['type' => 'dateTime'], |
|
23 | + ]; |
|
24 | + public static $dataManagers = [ |
|
25 | + 'manager' => [ |
|
26 | + 'cols' => [ |
|
27 | + 'name', 'size', 'status', 'deleted', 'date_create' |
|
28 | + ], |
|
29 | + ] |
|
30 | + ]; |
|
31 | 31 | |
32 | - public function deleteFile() { |
|
32 | + public function deleteFile() { |
|
33 | 33 | if ($this->exchange && file_exists($this->exchange->path . '/' . $this->name)) { |
34 | - unlink($this->exchange->path . '/' . $this->name); |
|
34 | + unlink($this->exchange->path . '/' . $this->name); |
|
35 | 35 | } |
36 | 36 | $this->deleted = 1; |
37 | 37 | $this->save(); |
38 | - } |
|
38 | + } |
|
39 | 39 | |
40 | - public static function relations() { |
|
40 | + public static function relations() { |
|
41 | 41 | return [ |
42 | 42 | 'exchange' => [ |
43 | 43 | 'model' => 'Exchange1c\Exchange', |
44 | 44 | 'col' => 'exchange_id' |
45 | 45 | ] |
46 | 46 | ]; |
47 | - } |
|
47 | + } |
|
48 | 48 | |
49 | 49 | } |
@@ -30,8 +30,8 @@ |
||
30 | 30 | ]; |
31 | 31 | |
32 | 32 | public function deleteFile() { |
33 | - if ($this->exchange && file_exists($this->exchange->path . '/' . $this->name)) { |
|
34 | - unlink($this->exchange->path . '/' . $this->name); |
|
33 | + if ($this->exchange && file_exists($this->exchange->path.'/'.$this->name)) { |
|
34 | + unlink($this->exchange->path.'/'.$this->name); |
|
35 | 35 | } |
36 | 36 | $this->deleted = 1; |
37 | 37 | $this->save(); |
@@ -13,65 +13,65 @@ discard block |
||
13 | 13 | |
14 | 14 | class Delivery extends \Model { |
15 | 15 | |
16 | - public static $objectName = 'Доставка'; |
|
17 | - public static $cols = [ |
|
18 | - //Основные параметры |
|
19 | - 'name' => ['type' => 'text'], |
|
20 | - 'price' => ['type' => 'decimal'], |
|
21 | - 'currency_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'currency'], |
|
22 | - 'price_text' => ['type' => 'textarea'], |
|
23 | - 'max_cart_price' => ['type' => 'decimal'], |
|
24 | - 'icon_file_id' => ['type' => 'image'], |
|
25 | - 'info' => ['type' => 'html'], |
|
26 | - 'disabled' => ['type' => 'bool'], |
|
27 | - //Системные |
|
28 | - 'weight' => ['type' => 'number'], |
|
29 | - 'date_create' => ['type' => 'dateTime'], |
|
30 | - //Менеджеры |
|
31 | - 'field' => ['type' => 'dataManager', 'relation' => 'fields'], |
|
32 | - 'priceChanger' => ['type' => 'dataManager', 'relation' => 'prices'] |
|
33 | - ]; |
|
34 | - public static $labels = [ |
|
35 | - 'name' => 'Название', |
|
36 | - 'price' => 'Стоимость', |
|
37 | - 'price_text' => 'Текстовое описание стоимости (отображается вместо цены)', |
|
38 | - 'max_cart_price' => 'Басплатно при', |
|
39 | - 'icon_file_id' => 'Иконка', |
|
40 | - 'currency_id' => 'Валюта', |
|
41 | - 'info' => 'Дополнительная информация', |
|
42 | - 'priceChanger' => 'Градация стоимости', |
|
43 | - 'field' => 'Поля', |
|
44 | - 'disabled' => 'Отключено', |
|
45 | - ]; |
|
46 | - public static $dataManagers = [ |
|
47 | - 'manager' => [ |
|
48 | - 'name' => 'Варианты доставки', |
|
49 | - 'cols' => [ |
|
50 | - 'name', |
|
51 | - 'price', |
|
52 | - 'currency_id', |
|
53 | - 'max_cart_price', |
|
54 | - 'disabled', |
|
55 | - 'field', |
|
56 | - 'priceChanger', |
|
57 | - ], |
|
58 | - 'sortMode' => true |
|
59 | - ], |
|
60 | - ]; |
|
61 | - public static $forms = [ |
|
62 | - 'manager' => [ |
|
63 | - 'map' => [ |
|
64 | - ['name', 'disabled'], |
|
65 | - ['max_cart_price', 'icon_file_id'], |
|
66 | - ['price', 'currency_id'], |
|
67 | - ['price_text'], |
|
68 | - ['info'], |
|
69 | - ['priceChanger'], |
|
70 | - ['field'] |
|
71 | - ] |
|
72 | - ]]; |
|
16 | + public static $objectName = 'Доставка'; |
|
17 | + public static $cols = [ |
|
18 | + //Основные параметры |
|
19 | + 'name' => ['type' => 'text'], |
|
20 | + 'price' => ['type' => 'decimal'], |
|
21 | + 'currency_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'currency'], |
|
22 | + 'price_text' => ['type' => 'textarea'], |
|
23 | + 'max_cart_price' => ['type' => 'decimal'], |
|
24 | + 'icon_file_id' => ['type' => 'image'], |
|
25 | + 'info' => ['type' => 'html'], |
|
26 | + 'disabled' => ['type' => 'bool'], |
|
27 | + //Системные |
|
28 | + 'weight' => ['type' => 'number'], |
|
29 | + 'date_create' => ['type' => 'dateTime'], |
|
30 | + //Менеджеры |
|
31 | + 'field' => ['type' => 'dataManager', 'relation' => 'fields'], |
|
32 | + 'priceChanger' => ['type' => 'dataManager', 'relation' => 'prices'] |
|
33 | + ]; |
|
34 | + public static $labels = [ |
|
35 | + 'name' => 'Название', |
|
36 | + 'price' => 'Стоимость', |
|
37 | + 'price_text' => 'Текстовое описание стоимости (отображается вместо цены)', |
|
38 | + 'max_cart_price' => 'Басплатно при', |
|
39 | + 'icon_file_id' => 'Иконка', |
|
40 | + 'currency_id' => 'Валюта', |
|
41 | + 'info' => 'Дополнительная информация', |
|
42 | + 'priceChanger' => 'Градация стоимости', |
|
43 | + 'field' => 'Поля', |
|
44 | + 'disabled' => 'Отключено', |
|
45 | + ]; |
|
46 | + public static $dataManagers = [ |
|
47 | + 'manager' => [ |
|
48 | + 'name' => 'Варианты доставки', |
|
49 | + 'cols' => [ |
|
50 | + 'name', |
|
51 | + 'price', |
|
52 | + 'currency_id', |
|
53 | + 'max_cart_price', |
|
54 | + 'disabled', |
|
55 | + 'field', |
|
56 | + 'priceChanger', |
|
57 | + ], |
|
58 | + 'sortMode' => true |
|
59 | + ], |
|
60 | + ]; |
|
61 | + public static $forms = [ |
|
62 | + 'manager' => [ |
|
63 | + 'map' => [ |
|
64 | + ['name', 'disabled'], |
|
65 | + ['max_cart_price', 'icon_file_id'], |
|
66 | + ['price', 'currency_id'], |
|
67 | + ['price_text'], |
|
68 | + ['info'], |
|
69 | + ['priceChanger'], |
|
70 | + ['field'] |
|
71 | + ] |
|
72 | + ]]; |
|
73 | 73 | |
74 | - public static function relations() { |
|
74 | + public static function relations() { |
|
75 | 75 | return [ |
76 | 76 | 'icon' => [ |
77 | 77 | 'model' => 'Files\File', |
@@ -92,6 +92,6 @@ discard block |
||
92 | 92 | 'col' => 'delivery_id' |
93 | 93 | ] |
94 | 94 | ]; |
95 | - } |
|
95 | + } |
|
96 | 96 | |
97 | 97 | } |
@@ -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 |