@@ -10,31 +10,31 @@ discard block |
||
10 | 10 | */ |
11 | 11 | class DataManagerController extends Controller { |
12 | 12 | |
13 | - public function parseRequest() { |
|
13 | + public function parseRequest() { |
|
14 | 14 | $return = []; |
15 | 15 | $return['params'] = UserRequest::get('params', 'array', []); |
16 | 16 | |
17 | 17 | $item = UserRequest::get('modelName', 'string', ''); |
18 | 18 | if (!$item) { |
19 | - $item = UserRequest::get('item', 'string', ''); |
|
19 | + $item = UserRequest::get('item', 'string', ''); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | if (strpos($item, ':')) { |
23 | - $raw = explode(':', $item); |
|
24 | - $return['modelName'] = $raw[0]; |
|
25 | - $return['model'] = $return['modelName']::get($raw[1], $return['modelName']::index(), $return['params']); |
|
23 | + $raw = explode(':', $item); |
|
24 | + $return['modelName'] = $raw[0]; |
|
25 | + $return['model'] = $return['modelName']::get($raw[1], $return['modelName']::index(), $return['params']); |
|
26 | 26 | } else { |
27 | - $return['modelName'] = $item; |
|
28 | - $return['model'] = null; |
|
27 | + $return['modelName'] = $item; |
|
28 | + $return['model'] = null; |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | if (!empty($return['params']['relation'])) { |
32 | - $relation = $return['modelName']::getRelation($return['params']['relation']); |
|
33 | - if (!empty($relation['type']) && $relation['type'] == 'relModel') { |
|
32 | + $relation = $return['modelName']::getRelation($return['params']['relation']); |
|
33 | + if (!empty($relation['type']) && $relation['type'] == 'relModel') { |
|
34 | 34 | $return['modelName'] = $relation['relModel']; |
35 | - } else { |
|
35 | + } else { |
|
36 | 36 | $return['modelName'] = $relation['model']; |
37 | - } |
|
37 | + } |
|
38 | 38 | } |
39 | 39 | $return['params']['filters'] = UserRequest::get('filters', 'array', []); |
40 | 40 | $return['params']['sortered'] = UserRequest::get('sortered', 'array', []); |
@@ -54,13 +54,13 @@ discard block |
||
54 | 54 | |
55 | 55 | $return['managerName'] = UserRequest::get('managerName', 'string', 'manager'); |
56 | 56 | if (!$return['managerName']) { |
57 | - $return['managerName'] = 'manager'; |
|
57 | + $return['managerName'] = 'manager'; |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | return $return; |
61 | - } |
|
61 | + } |
|
62 | 62 | |
63 | - public function indexAction() { |
|
63 | + public function indexAction() { |
|
64 | 64 | $result = new Server\Result(); |
65 | 65 | |
66 | 66 | ob_start(); |
@@ -75,9 +75,9 @@ discard block |
||
75 | 75 | ob_end_clean(); |
76 | 76 | |
77 | 77 | $result->send(); |
78 | - } |
|
78 | + } |
|
79 | 79 | |
80 | - public function loadRowsAction() { |
|
80 | + public function loadRowsAction() { |
|
81 | 81 | $result = new Server\Result(); |
82 | 82 | $result->content = []; |
83 | 83 | |
@@ -88,55 +88,55 @@ discard block |
||
88 | 88 | $dataManager = new Ui\DataManager($request['modelName'], $request['managerName']); |
89 | 89 | if ($request['download']) { |
90 | 90 | |
91 | - ini_set('memory_limit', '2000M'); |
|
92 | - set_time_limit(0); |
|
91 | + ini_set('memory_limit', '2000M'); |
|
92 | + set_time_limit(0); |
|
93 | 93 | |
94 | - $request['params']['all'] = true; |
|
95 | - $request['params']['download'] = true; |
|
96 | - ob_end_clean(); |
|
97 | - header('Content-Encoding: UTF-8'); |
|
98 | - header("Content-Type: text/csv"); |
|
99 | - header("Content-Disposition: attachment; filename=" . $request['modelName']::$objectName . '.csv'); |
|
100 | - echo "\xEF\xBB\xBF"; // UTF-8 BOM |
|
94 | + $request['params']['all'] = true; |
|
95 | + $request['params']['download'] = true; |
|
96 | + ob_end_clean(); |
|
97 | + header('Content-Encoding: UTF-8'); |
|
98 | + header("Content-Type: text/csv"); |
|
99 | + header("Content-Disposition: attachment; filename=" . $request['modelName']::$objectName . '.csv'); |
|
100 | + echo "\xEF\xBB\xBF"; // UTF-8 BOM |
|
101 | 101 | |
102 | 102 | |
103 | - $cols = $dataManager->getCols(); |
|
104 | - $cols = array_slice($cols, 1); |
|
105 | - $endRow = true; |
|
106 | - foreach ($cols as $colName => $options) { |
|
103 | + $cols = $dataManager->getCols(); |
|
104 | + $cols = array_slice($cols, 1); |
|
105 | + $endRow = true; |
|
106 | + foreach ($cols as $colName => $options) { |
|
107 | 107 | if (!$endRow) { |
108 | - echo ";"; |
|
108 | + echo ";"; |
|
109 | 109 | } |
110 | 110 | $endRow = false; |
111 | 111 | echo '"' . $options['label'] . '"'; |
112 | - } |
|
113 | - echo "\n"; |
|
114 | - $endRow = true; |
|
112 | + } |
|
113 | + echo "\n"; |
|
114 | + $endRow = true; |
|
115 | 115 | } |
116 | 116 | if (!$request['params']['all']) { |
117 | - $pages = $dataManager->getPages($request['params'], $request['model']); |
|
118 | - $request['params']['page'] = !empty($pages->params['page']) ? $pages->params['page'] : $dataManager->page; |
|
119 | - $request['params']['limit'] = !empty($pages->params['limit']) ? $pages->params['limit'] : $dataManager->limit; |
|
117 | + $pages = $dataManager->getPages($request['params'], $request['model']); |
|
118 | + $request['params']['page'] = !empty($pages->params['page']) ? $pages->params['page'] : $dataManager->page; |
|
119 | + $request['params']['limit'] = !empty($pages->params['limit']) ? $pages->params['limit'] : $dataManager->limit; |
|
120 | 120 | } |
121 | 121 | $rows = $dataManager->getRows($request['params'], $request['model']); |
122 | 122 | foreach ($rows as $row) { |
123 | - if ($request['download']) { |
|
123 | + if ($request['download']) { |
|
124 | 124 | $row = array_slice($row, 1, -1); |
125 | 125 | foreach ($row as $col) { |
126 | - if (!$endRow) { |
|
126 | + if (!$endRow) { |
|
127 | 127 | echo ";"; |
128 | - } |
|
129 | - $endRow = false; |
|
130 | - echo '"' . str_replace(["\n", '"'], ['“'], $col) . '"'; |
|
128 | + } |
|
129 | + $endRow = false; |
|
130 | + echo '"' . str_replace(["\n", '"'], ['“'], $col) . '"'; |
|
131 | 131 | } |
132 | 132 | echo "\n"; |
133 | 133 | $endRow = true; |
134 | - } else { |
|
134 | + } else { |
|
135 | 135 | Ui\Table::drawRow($row); |
136 | - } |
|
136 | + } |
|
137 | 137 | } |
138 | 138 | if ($request['download']) { |
139 | - exit(); |
|
139 | + exit(); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | $result->content['rows'] = ob_get_contents(); |
@@ -145,17 +145,17 @@ discard block |
||
145 | 145 | $result->content['pages'] = ''; |
146 | 146 | |
147 | 147 | if (isset($pages) && $pages) { |
148 | - if ($pages) { |
|
148 | + if ($pages) { |
|
149 | 149 | $pages->draw(); |
150 | 150 | echo '<div style="background:#fff;">записей: <b>' . $pages->options['count'] . '</b>. страница <b>' . $pages->params['page'] . '</b> из <b>' . $pages->params['pages'] . '</b></div>'; |
151 | - } |
|
152 | - $result->content['pages'] = ob_get_contents(); |
|
153 | - ob_end_clean(); |
|
151 | + } |
|
152 | + $result->content['pages'] = ob_get_contents(); |
|
153 | + ob_end_clean(); |
|
154 | 154 | } |
155 | 155 | $result->send(); |
156 | - } |
|
156 | + } |
|
157 | 157 | |
158 | - public function loadCategorysAction() { |
|
158 | + public function loadCategorysAction() { |
|
159 | 159 | $result = new Server\Result(); |
160 | 160 | |
161 | 161 | ob_start(); |
@@ -169,88 +169,88 @@ discard block |
||
169 | 169 | ob_end_clean(); |
170 | 170 | |
171 | 171 | $result->send(); |
172 | - } |
|
172 | + } |
|
173 | 173 | |
174 | - public function delRowAction() { |
|
174 | + public function delRowAction() { |
|
175 | 175 | |
176 | 176 | $request = $this->parseRequest(); |
177 | 177 | |
178 | 178 | $dataManager = new Ui\DataManager($request['modelName'], $request['managerName']); |
179 | 179 | |
180 | 180 | if ($dataManager->checkAccess()) { |
181 | - $model = $request['modelName']::get($request['key'], $request['modelName']::index(), $request['params']); |
|
182 | - if ($model) { |
|
181 | + $model = $request['modelName']::get($request['key'], $request['modelName']::index(), $request['params']); |
|
182 | + if ($model) { |
|
183 | 183 | $model->delete($request['params']); |
184 | - } |
|
184 | + } |
|
185 | 185 | } |
186 | 186 | $result = new Server\Result(); |
187 | 187 | $result->successMsg = empty($request['silence']) ? 'Запись удалена' : ''; |
188 | 188 | $result->send(); |
189 | - } |
|
189 | + } |
|
190 | 190 | |
191 | - public function updateRowAction() { |
|
191 | + public function updateRowAction() { |
|
192 | 192 | |
193 | 193 | $request = $this->parseRequest(); |
194 | 194 | |
195 | 195 | $dataManager = new Ui\DataManager($request['modelName'], $request['managerName']); |
196 | 196 | |
197 | 197 | if ($dataManager->checkAccess()) { |
198 | - $model = $request['modelName']::get($request['key'], $request['modelName']::index(), $request['params']); |
|
199 | - if ($model) { |
|
198 | + $model = $request['modelName']::get($request['key'], $request['modelName']::index(), $request['params']); |
|
199 | + if ($model) { |
|
200 | 200 | $model->{$request['col']} = $request['col_value']; |
201 | 201 | $model->save($request['params']); |
202 | - } |
|
202 | + } |
|
203 | 203 | } |
204 | 204 | $result = new Server\Result(); |
205 | 205 | $result->successMsg = empty($request['silence']) ? 'Запись Обновлена' : ''; |
206 | 206 | $result->send(); |
207 | - } |
|
207 | + } |
|
208 | 208 | |
209 | - public function groupActionAction() { |
|
209 | + public function groupActionAction() { |
|
210 | 210 | $request = $this->parseRequest(); |
211 | 211 | $dataManager = new Ui\DataManager($request['modelName'], $request['managerName']); |
212 | 212 | $result = new Server\Result(); |
213 | 213 | $result->success = false; |
214 | 214 | $result->content = 'Не удалось выполнить операцию'; |
215 | 215 | if ($dataManager->checkAccess()) { |
216 | - $ids = trim($request['ids'], ' ,'); |
|
217 | - if ($request['action'] && $ids) { |
|
216 | + $ids = trim($request['ids'], ' ,'); |
|
217 | + if ($request['action'] && $ids) { |
|
218 | 218 | $actions = $dataManager->getActions(); |
219 | 219 | if (!empty($actions[$request['action']])) { |
220 | - $actionParams = $actions[$request['action']]; |
|
221 | - if (!empty($actionParams['access']['groups']) && !in_array(\Users\User::$cur->group_id, $actionParams['access']['groups'])) { |
|
220 | + $actionParams = $actions[$request['action']]; |
|
221 | + if (!empty($actionParams['access']['groups']) && !in_array(\Users\User::$cur->group_id, $actionParams['access']['groups'])) { |
|
222 | 222 | $result->content = 'У вас нет прав доступа к операции ' . (!isset($actionParams['name']) ? $actionParams['className']::$name : $actionParams['name']); |
223 | - } else { |
|
223 | + } else { |
|
224 | 224 | try { |
225 | - $result->successMsg = $actionParams['className']::groupAction($dataManager, $ids, $actionParams, !empty($_GET['adInfo']) ? $_GET['adInfo'] : []); |
|
226 | - $result->success = true; |
|
225 | + $result->successMsg = $actionParams['className']::groupAction($dataManager, $ids, $actionParams, !empty($_GET['adInfo']) ? $_GET['adInfo'] : []); |
|
226 | + $result->success = true; |
|
227 | 227 | } catch (\Exception $e) { |
228 | - $result->content = $e->getMessage(); |
|
228 | + $result->content = $e->getMessage(); |
|
229 | 229 | } |
230 | - } |
|
230 | + } |
|
231 | + } |
|
231 | 232 | } |
232 | - } |
|
233 | 233 | } else { |
234 | - $result->content = 'У вас нет прав доступа к менеджеру ' . $request['managerName'] . ' модели ' . $request['modelName']; |
|
234 | + $result->content = 'У вас нет прав доступа к менеджеру ' . $request['managerName'] . ' модели ' . $request['modelName']; |
|
235 | 235 | } |
236 | 236 | $result->send(); |
237 | - } |
|
237 | + } |
|
238 | 238 | |
239 | - public function delCategoryAction() { |
|
239 | + public function delCategoryAction() { |
|
240 | 240 | |
241 | 241 | $request = $this->parseRequest(); |
242 | 242 | |
243 | 243 | $dataManager = new Ui\DataManager($request['modelName'], $request['managerName']); |
244 | 244 | |
245 | 245 | if ($dataManager->checkAccess() && !empty($dataManager->managerOptions['categorys'])) { |
246 | - $categoryModel = $dataManager->managerOptions['categorys']['model']; |
|
247 | - $model = $categoryModel::get($request['key'], $categoryModel::index(), $request['params']); |
|
248 | - if ($model) { |
|
246 | + $categoryModel = $dataManager->managerOptions['categorys']['model']; |
|
247 | + $model = $categoryModel::get($request['key'], $categoryModel::index(), $request['params']); |
|
248 | + if ($model) { |
|
249 | 249 | $model->delete($request['params']); |
250 | - } |
|
250 | + } |
|
251 | 251 | } |
252 | 252 | $result = new Server\Result(); |
253 | 253 | $result->send(); |
254 | - } |
|
254 | + } |
|
255 | 255 | |
256 | 256 | } |
@@ -9,16 +9,16 @@ |
||
9 | 9 | 'value' => !empty($options['value']) ? addcslashes($options['value'], "'") : (!empty($form->userDataTree[$name]) ? addcslashes($form->userDataTree[$name], "'") : '') |
10 | 10 | ]; |
11 | 11 | if (!empty($options['disabled'])) { |
12 | - $attributes['disabled'] = 'disabled'; |
|
12 | + $attributes['disabled'] = 'disabled'; |
|
13 | 13 | } |
14 | 14 | if (!empty($options['placeholder'])) { |
15 | - $attributes['placeholder'] = $options['placeholder']; |
|
15 | + $attributes['placeholder'] = $options['placeholder']; |
|
16 | 16 | } |
17 | 17 | if (!empty($options['checked'])) { |
18 | - $attributes['checked'] = 'checked'; |
|
18 | + $attributes['checked'] = 'checked'; |
|
19 | 19 | } |
20 | 20 | if (!empty($options['attributes'])) { |
21 | - $attributes = array_merge($attributes, $options['attributes']); |
|
21 | + $attributes = array_merge($attributes, $options['attributes']); |
|
22 | 22 | } |
23 | 23 | echo Html::el('input', $attributes, '', null); |
24 | 24 | echo!empty($options['helpText']) ? "<div class='help-block'>{$options['helpText']}</div>" : ''; |
@@ -7,8 +7,8 @@ discard block |
||
7 | 7 | </li> |
8 | 8 | <?php |
9 | 9 | if (class_exists('Users\User')) { |
10 | - App::$cur->ui; |
|
11 | - ?> |
|
10 | + App::$cur->ui; |
|
11 | + ?> |
|
12 | 12 | <hr /> |
13 | 13 | <div class="row userWidget"> |
14 | 14 | <div class="col-xs-4"> |
@@ -29,23 +29,23 @@ discard block |
||
29 | 29 | <a href = "/admin">Панель управления</a> |
30 | 30 | </li> |
31 | 31 | <?php |
32 | - $where[] = ['group_id', Users\User::$cur->group_id]; |
|
33 | - if (Users\User::$cur->group_id == 3) { |
|
32 | + $where[] = ['group_id', Users\User::$cur->group_id]; |
|
33 | + if (Users\User::$cur->group_id == 3) { |
|
34 | 34 | $where[] = ['group_id', 0, '=', 'OR']; |
35 | - } |
|
36 | - $menu = Menu\Menu::get([['code', 'sidebarMenu'], $where]); |
|
37 | - foreach ($menu->items(['where' => ['parent_id', 0], 'order' => ['weight', 'asc']]) as $item) { |
|
35 | + } |
|
36 | + $menu = Menu\Menu::get([['code', 'sidebarMenu'], $where]); |
|
37 | + foreach ($menu->items(['where' => ['parent_id', 0], 'order' => ['weight', 'asc']]) as $item) { |
|
38 | 38 | echo "<li><a href = '{$item->href}'>{$item->name}</a>"; |
39 | 39 | $childItems = Menu\Item::getList(['where' => ['parent_id', $item->id]]); |
40 | 40 | if ($childItems) { |
41 | - echo "<ul>"; |
|
42 | - foreach ($childItems as $item) { |
|
41 | + echo "<ul>"; |
|
42 | + foreach ($childItems as $item) { |
|
43 | 43 | echo "<li><a href = '{$item->href}'>{$item->name}</a>"; |
44 | - } |
|
45 | - echo "</ul>"; |
|
44 | + } |
|
45 | + echo "</ul>"; |
|
46 | 46 | } |
47 | 47 | echo "</li>"; |
48 | - } |
|
48 | + } |
|
49 | 49 | } |
50 | 50 | ?> |
51 | 51 | <li> |
@@ -10,55 +10,55 @@ |
||
10 | 10 | */ |
11 | 11 | class adminController extends Controller { |
12 | 12 | |
13 | - public function indexAction() { |
|
13 | + public function indexAction() { |
|
14 | 14 | $args = func_get_args(); |
15 | 15 | call_user_func_array([$this, 'dataManagerAction'], $args); |
16 | - } |
|
16 | + } |
|
17 | 17 | |
18 | - public function dataManagerAction($model = '', $dataManager = 'manager') { |
|
18 | + public function dataManagerAction($model = '', $dataManager = 'manager') { |
|
19 | 19 | if (!$model) { |
20 | - $modulePath = Module::getModulePath($this->module->moduleName); |
|
21 | - $path = $modulePath . '/models'; |
|
22 | - if (file_exists($path)) { |
|
20 | + $modulePath = Module::getModulePath($this->module->moduleName); |
|
21 | + $path = $modulePath . '/models'; |
|
22 | + if (file_exists($path)) { |
|
23 | 23 | $files = array_slice(scandir($path), 2); |
24 | 24 | foreach ($files as $file) { |
25 | - if (is_dir($path . '/' . $file)) { |
|
25 | + if (is_dir($path . '/' . $file)) { |
|
26 | 26 | continue; |
27 | - } |
|
28 | - $model = pathinfo($file, PATHINFO_FILENAME); |
|
29 | - break; |
|
27 | + } |
|
28 | + $model = pathinfo($file, PATHINFO_FILENAME); |
|
29 | + break; |
|
30 | + } |
|
30 | 31 | } |
31 | - } |
|
32 | 32 | } |
33 | 33 | $fullModelName = $this->module->moduleName . '\\' . ucfirst($model); |
34 | 34 | $dataManager = new Ui\DataManager($fullModelName, $dataManager); |
35 | 35 | $title = !empty($dataManager->managerOptions['name']) ? $dataManager->managerOptions['name'] : $fullModelName::objectName(); |
36 | 36 | $this->view->setTitle($title); |
37 | 37 | $this->view->page(['module' => 'Ui', 'content' => 'dataManager/manager', 'data' => compact('dataManager')]); |
38 | - } |
|
38 | + } |
|
39 | 39 | |
40 | - public function viewAction($model, $pk) { |
|
40 | + public function viewAction($model, $pk) { |
|
41 | 41 | $fullModelName = $this->module->moduleName . '\\' . ucfirst($model); |
42 | 42 | if (Users\User::$cur->group_id != 3 && (empty($fullModelName::$views['manager']['access']) || !in_array(Users\User::$cur->group_id, $fullModelName::$views['manager']['access']['groups']))) { |
43 | - Tools::redirect('/admin', 'У вас нет прав доступа для просмотра этого объекта', 'danger'); |
|
43 | + Tools::redirect('/admin', 'У вас нет прав доступа для просмотра этого объекта', 'danger'); |
|
44 | 44 | } |
45 | 45 | $item = $fullModelName::get($pk); |
46 | 46 | $this->view->setTitle(($fullModelName::$objectName ? $fullModelName::$objectName : $fullModelName) . ($item ? ( ' - ' . $item->name()) : '')); |
47 | 47 | if (!empty($_POST['comment'])) { |
48 | - $comment = new Dashboard\Comment(); |
|
49 | - $comment->text = $_POST['comment']; |
|
50 | - $comment->user_id = \Users\User::$cur->id; |
|
51 | - $comment->model = $fullModelName; |
|
52 | - $comment->item_id = $item->pk(); |
|
53 | - $comment->save(); |
|
54 | - Tools::redirect($_SERVER['REQUEST_URI']); |
|
48 | + $comment = new Dashboard\Comment(); |
|
49 | + $comment->text = $_POST['comment']; |
|
50 | + $comment->user_id = \Users\User::$cur->id; |
|
51 | + $comment->model = $fullModelName; |
|
52 | + $comment->item_id = $item->pk(); |
|
53 | + $comment->save(); |
|
54 | + Tools::redirect($_SERVER['REQUEST_URI']); |
|
55 | 55 | } |
56 | 56 | $moduleName = $this->module->moduleName; |
57 | 57 | $pageParam = ['module' => 'Ui', 'content' => 'dataManager/view', 'data' => compact('item', 'moduleName')]; |
58 | 58 | if (isset($_GET['print'])) { |
59 | - $pageParam['page'] = 'print'; |
|
59 | + $pageParam['page'] = 'print'; |
|
60 | 60 | } |
61 | 61 | $this->view->page($pageParam); |
62 | - } |
|
62 | + } |
|
63 | 63 | |
64 | 64 | } |
@@ -13,39 +13,39 @@ discard block |
||
13 | 13 | |
14 | 14 | class File extends \Model { |
15 | 15 | |
16 | - public static $cols = [ |
|
17 | - 'code' => ['type' => 'text'], |
|
18 | - 'type_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'type'], |
|
19 | - 'folder_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'foler'], |
|
20 | - 'upload_code' => ['type' => 'text'], |
|
21 | - 'path' => ['type' => 'textarea'], |
|
22 | - 'name' => ['type' => 'text'], |
|
23 | - 'about' => ['type' => 'html'], |
|
24 | - 'original_name' => ['type' => 'text'], |
|
25 | - 'md5' => ['type' => 'text'], |
|
26 | - 'date_create' => ['type' => 'dateTime'], |
|
27 | - ]; |
|
28 | - |
|
29 | - public function beforeSave() { |
|
16 | + public static $cols = [ |
|
17 | + 'code' => ['type' => 'text'], |
|
18 | + 'type_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'type'], |
|
19 | + 'folder_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'foler'], |
|
20 | + 'upload_code' => ['type' => 'text'], |
|
21 | + 'path' => ['type' => 'textarea'], |
|
22 | + 'name' => ['type' => 'text'], |
|
23 | + 'about' => ['type' => 'html'], |
|
24 | + 'original_name' => ['type' => 'text'], |
|
25 | + 'md5' => ['type' => 'text'], |
|
26 | + 'date_create' => ['type' => 'dateTime'], |
|
27 | + ]; |
|
28 | + |
|
29 | + public function beforeSave() { |
|
30 | 30 | $path = $this->getRealPath(); |
31 | 31 | if (!$this->md5 && $this->path && file_exists($path)) { |
32 | - $this->md5 = md5_file($path); |
|
32 | + $this->md5 = md5_file($path); |
|
33 | + } |
|
33 | 34 | } |
34 | - } |
|
35 | 35 | |
36 | - public function beforeDelete() { |
|
36 | + public function beforeDelete() { |
|
37 | 37 | $path = $this->getRealPath(); |
38 | 38 | if (file_exists($path)) { |
39 | - unlink($path); |
|
39 | + unlink($path); |
|
40 | + } |
|
40 | 41 | } |
41 | - } |
|
42 | 42 | |
43 | - public function getRealPath() { |
|
43 | + public function getRealPath() { |
|
44 | 44 | $sitePath = \App::$primary->path; |
45 | 45 | return "{$sitePath}{$this->path}"; |
46 | - } |
|
46 | + } |
|
47 | 47 | |
48 | - public static function relations() { |
|
48 | + public static function relations() { |
|
49 | 49 | return [ |
50 | 50 | 'type' => [ |
51 | 51 | 'model' => 'Files\Type', |
@@ -56,6 +56,6 @@ discard block |
||
56 | 56 | 'col' => 'folder_id' |
57 | 57 | ], |
58 | 58 | ]; |
59 | - } |
|
59 | + } |
|
60 | 60 | |
61 | 61 | } |
@@ -1,67 +1,67 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | return function($step = NULL, $params = []) { |
4 | - $options = ['max_height' => 1200, 'max_width' => 1200]; |
|
5 | - $types = [ |
|
6 | - [ |
|
7 | - 'dir' => '/static/mediafiles/images/', |
|
8 | - 'ext' => 'png', |
|
9 | - 'group' => 'image', |
|
10 | - 'allow_resize' => 1, |
|
11 | - 'options' => json_encode($options) |
|
12 | - ], |
|
13 | - [ |
|
14 | - 'dir' => '/static/mediafiles/images/', |
|
15 | - 'ext' => 'jpeg', |
|
16 | - 'group' => 'image', |
|
17 | - 'allow_resize' => 1, |
|
18 | - 'options' => json_encode($options) |
|
19 | - ], |
|
20 | - [ |
|
21 | - 'dir' => '/static/mediafiles/images/', |
|
22 | - 'ext' => 'jpg', |
|
23 | - 'group' => 'image', |
|
24 | - 'allow_resize' => 1, |
|
25 | - 'options' => json_encode($options) |
|
26 | - ], |
|
27 | - [ |
|
28 | - 'dir' => '/static/mediafiles/images/', |
|
29 | - 'ext' => 'gif', |
|
30 | - 'group' => 'image', |
|
31 | - 'allow_resize' => 1, |
|
32 | - 'options' => json_encode($options) |
|
33 | - ], |
|
34 | - [ |
|
35 | - 'dir' => '/static/mediafiles/docs/', |
|
36 | - 'ext' => 'xls', |
|
37 | - 'group' => 'doc', |
|
38 | - 'allow_resize' => 0, |
|
39 | - 'options' => '' |
|
40 | - ], |
|
41 | - [ |
|
42 | - 'dir' => '/static/mediafiles/docs/', |
|
43 | - 'ext' => 'pdf', |
|
44 | - 'group' => 'doc', |
|
45 | - 'allow_resize' => 0, |
|
46 | - 'options' => '' |
|
47 | - ], |
|
48 | - [ |
|
49 | - 'dir' => '/static/mediafiles/docs/', |
|
50 | - 'ext' => 'docx', |
|
51 | - 'group' => 'doc', |
|
52 | - 'allow_resize' => 0, |
|
53 | - 'options' => '' |
|
54 | - ], |
|
55 | - [ |
|
56 | - 'dir' => '/static/mediafiles/docs/', |
|
57 | - 'ext' => 'xlsx', |
|
58 | - 'group' => 'doc', |
|
59 | - 'allow_resize' => 0, |
|
60 | - 'options' => '' |
|
61 | - ], |
|
62 | - ]; |
|
63 | - foreach ($types as $type) { |
|
4 | + $options = ['max_height' => 1200, 'max_width' => 1200]; |
|
5 | + $types = [ |
|
6 | + [ |
|
7 | + 'dir' => '/static/mediafiles/images/', |
|
8 | + 'ext' => 'png', |
|
9 | + 'group' => 'image', |
|
10 | + 'allow_resize' => 1, |
|
11 | + 'options' => json_encode($options) |
|
12 | + ], |
|
13 | + [ |
|
14 | + 'dir' => '/static/mediafiles/images/', |
|
15 | + 'ext' => 'jpeg', |
|
16 | + 'group' => 'image', |
|
17 | + 'allow_resize' => 1, |
|
18 | + 'options' => json_encode($options) |
|
19 | + ], |
|
20 | + [ |
|
21 | + 'dir' => '/static/mediafiles/images/', |
|
22 | + 'ext' => 'jpg', |
|
23 | + 'group' => 'image', |
|
24 | + 'allow_resize' => 1, |
|
25 | + 'options' => json_encode($options) |
|
26 | + ], |
|
27 | + [ |
|
28 | + 'dir' => '/static/mediafiles/images/', |
|
29 | + 'ext' => 'gif', |
|
30 | + 'group' => 'image', |
|
31 | + 'allow_resize' => 1, |
|
32 | + 'options' => json_encode($options) |
|
33 | + ], |
|
34 | + [ |
|
35 | + 'dir' => '/static/mediafiles/docs/', |
|
36 | + 'ext' => 'xls', |
|
37 | + 'group' => 'doc', |
|
38 | + 'allow_resize' => 0, |
|
39 | + 'options' => '' |
|
40 | + ], |
|
41 | + [ |
|
42 | + 'dir' => '/static/mediafiles/docs/', |
|
43 | + 'ext' => 'pdf', |
|
44 | + 'group' => 'doc', |
|
45 | + 'allow_resize' => 0, |
|
46 | + 'options' => '' |
|
47 | + ], |
|
48 | + [ |
|
49 | + 'dir' => '/static/mediafiles/docs/', |
|
50 | + 'ext' => 'docx', |
|
51 | + 'group' => 'doc', |
|
52 | + 'allow_resize' => 0, |
|
53 | + 'options' => '' |
|
54 | + ], |
|
55 | + [ |
|
56 | + 'dir' => '/static/mediafiles/docs/', |
|
57 | + 'ext' => 'xlsx', |
|
58 | + 'group' => 'doc', |
|
59 | + 'allow_resize' => 0, |
|
60 | + 'options' => '' |
|
61 | + ], |
|
62 | + ]; |
|
63 | + foreach ($types as $type) { |
|
64 | 64 | $typeObject = new \Files\Type($type); |
65 | 65 | $typeObject->save(); |
66 | - } |
|
66 | + } |
|
67 | 67 | }; |
@@ -13,22 +13,22 @@ |
||
13 | 13 | |
14 | 14 | class File extends \Ui\ActiveForm\Input { |
15 | 15 | |
16 | - public function parseRequest($request) { |
|
16 | + public function parseRequest($request) { |
|
17 | 17 | if (!empty($_FILES[$this->activeForm->requestFormName]['tmp_name'][$this->modelName][$this->colName])) { |
18 | - $file_id = \App::$primary->files->upload([ |
|
19 | - 'tmp_name' => $_FILES[$this->activeForm->requestFormName]['tmp_name'][$this->modelName][$this->colName], |
|
20 | - 'name' => $_FILES[$this->activeForm->requestFormName]['name'][$this->modelName][$this->colName], |
|
21 | - 'type' => $_FILES[$this->activeForm->requestFormName]['type'][$this->modelName][$this->colName], |
|
22 | - 'size' => $_FILES[$this->activeForm->requestFormName]['size'][$this->modelName][$this->colName], |
|
23 | - 'error' => $_FILES[$this->activeForm->requestFormName]['error'][$this->modelName][$this->colName], |
|
24 | - ], [ |
|
25 | - 'upload_code' => 'activeForm:' . $this->activeForm->modelName . ':' . $this->activeForm->model->pk() |
|
26 | - ]); |
|
18 | + $file_id = \App::$primary->files->upload([ |
|
19 | + 'tmp_name' => $_FILES[$this->activeForm->requestFormName]['tmp_name'][$this->modelName][$this->colName], |
|
20 | + 'name' => $_FILES[$this->activeForm->requestFormName]['name'][$this->modelName][$this->colName], |
|
21 | + 'type' => $_FILES[$this->activeForm->requestFormName]['type'][$this->modelName][$this->colName], |
|
22 | + 'size' => $_FILES[$this->activeForm->requestFormName]['size'][$this->modelName][$this->colName], |
|
23 | + 'error' => $_FILES[$this->activeForm->requestFormName]['error'][$this->modelName][$this->colName], |
|
24 | + ], [ |
|
25 | + 'upload_code' => 'activeForm:' . $this->activeForm->modelName . ':' . $this->activeForm->model->pk() |
|
26 | + ]); |
|
27 | 27 | |
28 | - if ($file_id) { |
|
28 | + if ($file_id) { |
|
29 | 29 | $this->activeForm->model->{$this->colName} = $file_id; |
30 | - } |
|
30 | + } |
|
31 | + } |
|
31 | 32 | } |
32 | - } |
|
33 | 33 | |
34 | 34 | } |
@@ -13,118 +13,118 @@ discard block |
||
13 | 13 | |
14 | 14 | class ActiveForm extends \Object { |
15 | 15 | |
16 | - public $model = null; |
|
17 | - public $modelName = ''; |
|
18 | - public $header = ""; |
|
19 | - public $action = ""; |
|
20 | - public $form = []; |
|
21 | - public $inputs = []; |
|
22 | - public $formName = 'noNameForm'; |
|
23 | - public $requestFormName = ''; |
|
24 | - public $requestFullFormName = ''; |
|
25 | - public $parent = null; |
|
16 | + public $model = null; |
|
17 | + public $modelName = ''; |
|
18 | + public $header = ""; |
|
19 | + public $action = ""; |
|
20 | + public $form = []; |
|
21 | + public $inputs = []; |
|
22 | + public $formName = 'noNameForm'; |
|
23 | + public $requestFormName = ''; |
|
24 | + public $requestFullFormName = ''; |
|
25 | + public $parent = null; |
|
26 | 26 | |
27 | - /** |
|
28 | - * |
|
29 | - * @param array|\Model $model |
|
30 | - * @param array|string $form |
|
31 | - */ |
|
32 | - public function __construct($model, $form = '') { |
|
27 | + /** |
|
28 | + * |
|
29 | + * @param array|\Model $model |
|
30 | + * @param array|string $form |
|
31 | + */ |
|
32 | + public function __construct($model, $form = '') { |
|
33 | 33 | if (is_array($model)) { |
34 | - $this->form = $model; |
|
35 | - if (is_string($form)) { |
|
34 | + $this->form = $model; |
|
35 | + if (is_string($form)) { |
|
36 | 36 | $this->formName = $form; |
37 | - } |
|
37 | + } |
|
38 | 38 | } else { |
39 | - $this->model = $model; |
|
40 | - $this->modelName = get_class($model); |
|
41 | - if (is_array($form)) { |
|
39 | + $this->model = $model; |
|
40 | + $this->modelName = get_class($model); |
|
41 | + if (is_array($form)) { |
|
42 | 42 | if (empty($form)) { |
43 | - throw new \Exception('empty form'); |
|
43 | + throw new \Exception('empty form'); |
|
44 | 44 | } |
45 | 45 | $this->form = $form; |
46 | - } else { |
|
46 | + } else { |
|
47 | 47 | $this->formName = $form; |
48 | 48 | $this->form = \App::$cur->ui->getModelForm($this->modelName, $form); |
49 | 49 | if (empty($this->form)) { |
50 | - throw new \Exception('empty form ' . $form); |
|
50 | + throw new \Exception('empty form ' . $form); |
|
51 | 51 | } |
52 | 52 | $this->inputs = $this->getInputs(); |
53 | - } |
|
53 | + } |
|
54 | 54 | } |
55 | 55 | $this->requestFormName = "ActiveForm_{$this->formName}"; |
56 | 56 | $modeName = $this->modelName; |
57 | 57 | |
58 | 58 | if (!empty($this->form['name'])) { |
59 | - $this->header = $this->form['name']; |
|
59 | + $this->header = $this->form['name']; |
|
60 | 60 | } elseif (!empty($modeName::$objectName)) { |
61 | - $this->header = $modeName::$objectName; |
|
61 | + $this->header = $modeName::$objectName; |
|
62 | 62 | } else { |
63 | - $this->header = $this->modelName; |
|
63 | + $this->header = $this->modelName; |
|
64 | + } |
|
64 | 65 | } |
65 | - } |
|
66 | 66 | |
67 | - public function getInputs() { |
|
67 | + public function getInputs() { |
|
68 | 68 | $inputs = !empty($this->form['inputs']) ? $this->form['inputs'] : []; |
69 | 69 | $modelName = $this->modelName; |
70 | 70 | foreach ($this->form['map'] as $row) { |
71 | - foreach ($row as $col) { |
|
71 | + foreach ($row as $col) { |
|
72 | 72 | if (!$col || !empty($inputs[$col])) { |
73 | - continue; |
|
73 | + continue; |
|
74 | 74 | } |
75 | 75 | if (strpos($col, 'form:') === 0) { |
76 | - $colPath = explode(':', $col); |
|
77 | - if ($this->model->{$colPath[1]}) { |
|
76 | + $colPath = explode(':', $col); |
|
77 | + if ($this->model->{$colPath[1]}) { |
|
78 | 78 | $inputs[$col] = new ActiveForm($this->model->{$colPath[1]}, $colPath[2]); |
79 | - } else { |
|
79 | + } else { |
|
80 | 80 | $relOptions = $modelName::getRelation($colPath[1]); |
81 | 81 | if (!isset($this->model->_params[$modelName::index()])) { |
82 | - $this->model->_params[$modelName::index()] = 0; |
|
82 | + $this->model->_params[$modelName::index()] = 0; |
|
83 | 83 | } |
84 | 84 | $relOptions['model']::fixPrefix($relOptions['col']); |
85 | 85 | $inputs[$col] = new ActiveForm(new $relOptions['model']([ $relOptions['col'] => &$this->model->_params[$modelName::index()]]), $colPath[2]); |
86 | - } |
|
87 | - $inputs[$col]->parent = $this; |
|
86 | + } |
|
87 | + $inputs[$col]->parent = $this; |
|
88 | 88 | } elseif (!empty($modelName::$cols[$col])) { |
89 | - $inputs[$col] = $modelName::$cols[$col]; |
|
89 | + $inputs[$col] = $modelName::$cols[$col]; |
|
90 | + } |
|
90 | 91 | } |
91 | - } |
|
92 | 92 | } |
93 | 93 | return $inputs; |
94 | - } |
|
94 | + } |
|
95 | 95 | |
96 | - public function checkRequest($params = [], $ajax = false) { |
|
96 | + public function checkRequest($params = [], $ajax = false) { |
|
97 | 97 | if (!$this->checkAccess()) { |
98 | - $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->formName . '"'); |
|
99 | - return []; |
|
98 | + $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->formName . '"'); |
|
99 | + return []; |
|
100 | 100 | } |
101 | 101 | $successId = 0; |
102 | 102 | if (!empty($_POST[$this->requestFormName][$this->modelName]) || !empty($_FILES[$this->requestFormName]['tmp_name'][$this->modelName])) { |
103 | - $request = !empty($_POST[$this->requestFormName][$this->modelName])?$_POST[$this->requestFormName][$this->modelName]:[]; |
|
104 | - if ($this->model) { |
|
103 | + $request = !empty($_POST[$this->requestFormName][$this->modelName])?$_POST[$this->requestFormName][$this->modelName]:[]; |
|
104 | + if ($this->model) { |
|
105 | 105 | if (!empty($this->form['handler'])) { |
106 | - $modelName = $this->model; |
|
107 | - $modelName::{$this->form['handler']}($request); |
|
108 | - $text = 'Новый элемент был успешно добавлен'; |
|
109 | - \Msg::add($text, 'success'); |
|
110 | - \Msg::show(); |
|
106 | + $modelName = $this->model; |
|
107 | + $modelName::{$this->form['handler']}($request); |
|
108 | + $text = 'Новый элемент был успешно добавлен'; |
|
109 | + \Msg::add($text, 'success'); |
|
110 | + \Msg::show(); |
|
111 | 111 | } else { |
112 | - $presets = !empty($this->form['preset']) ? $this->form['preset'] : []; |
|
113 | - if (!empty($this->form['userGroupPreset'][\Users\User::$cur->group_id])) { |
|
112 | + $presets = !empty($this->form['preset']) ? $this->form['preset'] : []; |
|
113 | + if (!empty($this->form['userGroupPreset'][\Users\User::$cur->group_id])) { |
|
114 | 114 | $presets = array_merge($presets, $this->form['userGroupPreset'][\Users\User::$cur->group_id]); |
115 | - } |
|
116 | - $afterSave = []; |
|
117 | - $error = false; |
|
118 | - foreach ($this->inputs as $col => $param) { |
|
115 | + } |
|
116 | + $afterSave = []; |
|
117 | + $error = false; |
|
118 | + foreach ($this->inputs as $col => $param) { |
|
119 | 119 | if (!empty($presets[$col])) { |
120 | - continue; |
|
120 | + continue; |
|
121 | 121 | } |
122 | 122 | if (is_object($param)) { |
123 | - $afterSave[] = $param; |
|
124 | - continue; |
|
123 | + $afterSave[] = $param; |
|
124 | + continue; |
|
125 | 125 | } |
126 | 126 | if (!empty($this->form['userGroupReadonly'][\Users\User::$cur->group_id]) && in_array($col, $this->form['userGroupReadonly'][\Users\User::$cur->group_id])) { |
127 | - continue; |
|
127 | + continue; |
|
128 | 128 | } |
129 | 129 | $inputClassName = '\Ui\ActiveForm\Input\\' . ucfirst($param['type']); |
130 | 130 | $input = new $inputClassName(); |
@@ -134,189 +134,189 @@ discard block |
||
134 | 134 | $input->colName = $col; |
135 | 135 | $input->colParams = $param; |
136 | 136 | try { |
137 | - $input->validate($request); |
|
138 | - $input->parseRequest($request); |
|
137 | + $input->validate($request); |
|
138 | + $input->parseRequest($request); |
|
139 | 139 | } catch (\Exception $exc) { |
140 | - \Msg::add($exc->getMessage(), 'danger'); |
|
141 | - $error = true; |
|
140 | + \Msg::add($exc->getMessage(), 'danger'); |
|
141 | + $error = true; |
|
142 | + } |
|
142 | 143 | } |
143 | - } |
|
144 | - if (!$error && empty($_GET['notSave'])) { |
|
144 | + if (!$error && empty($_GET['notSave'])) { |
|
145 | 145 | foreach ($presets as $col => $preset) { |
146 | - if (!empty($preset['value'])) { |
|
146 | + if (!empty($preset['value'])) { |
|
147 | 147 | $this->model->$col = $preset['value']; |
148 | - } elseif (!empty($preset['userCol'])) { |
|
148 | + } elseif (!empty($preset['userCol'])) { |
|
149 | 149 | if (strpos($preset['userCol'], ':')) { |
150 | - $rel = substr($preset['userCol'], 0, strpos($preset['userCol'], ':')); |
|
151 | - $param = substr($preset['userCol'], strpos($preset['userCol'], ':') + 1); |
|
152 | - $this->model->$col = \Users\User::$cur->$rel->$param; |
|
150 | + $rel = substr($preset['userCol'], 0, strpos($preset['userCol'], ':')); |
|
151 | + $param = substr($preset['userCol'], strpos($preset['userCol'], ':') + 1); |
|
152 | + $this->model->$col = \Users\User::$cur->$rel->$param; |
|
153 | 153 | } else { |
154 | - $this->model->$col = \Users\User::$cur->{$preset['userCol']}; |
|
154 | + $this->model->$col = \Users\User::$cur->{$preset['userCol']}; |
|
155 | + } |
|
155 | 156 | } |
156 | - } |
|
157 | 157 | } |
158 | 158 | if (!$this->parent) { |
159 | - if (!empty($this->form['successText'])) { |
|
159 | + if (!empty($this->form['successText'])) { |
|
160 | 160 | $text = $this->form['successText']; |
161 | - } else { |
|
161 | + } else { |
|
162 | 162 | $text = $this->model->pk() ? 'Изменения были успешно сохранены' : 'Новый элемент был успешно добавлен'; |
163 | - } |
|
164 | - \Msg::add($text, 'success'); |
|
163 | + } |
|
164 | + \Msg::add($text, 'success'); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | $this->model->save(!empty($params['dataManagerParams']) ? $params['dataManagerParams'] : []); |
168 | 168 | foreach ($afterSave as $form) { |
169 | - $form->checkRequest(); |
|
169 | + $form->checkRequest(); |
|
170 | 170 | } |
171 | 171 | if ($ajax) { |
172 | - \Msg::show(); |
|
172 | + \Msg::show(); |
|
173 | 173 | } elseif (!empty($_GET['redirectUrl'])) { |
174 | - \Tools::redirect($_GET['redirectUrl'] . (!empty($_GET['dataManagerHash']) ? '#' . $_GET['dataManagerHash'] : '')); |
|
174 | + \Tools::redirect($_GET['redirectUrl'] . (!empty($_GET['dataManagerHash']) ? '#' . $_GET['dataManagerHash'] : '')); |
|
175 | 175 | } |
176 | 176 | $successId = $this->model->pk(); |
177 | - } |
|
177 | + } |
|
178 | + } |
|
178 | 179 | } |
179 | - } |
|
180 | - if (!is_array($params) && is_callable($params)) { |
|
180 | + if (!is_array($params) && is_callable($params)) { |
|
181 | 181 | $params($request); |
182 | - } |
|
182 | + } |
|
183 | 183 | } |
184 | 184 | return $successId; |
185 | - } |
|
185 | + } |
|
186 | 186 | |
187 | - public function draw($params = [], $ajax = false) { |
|
187 | + public function draw($params = [], $ajax = false) { |
|
188 | 188 | if (!$this->checkAccess()) { |
189 | - $this->drawError('you not have access to "' . $this->modelName . '" form with name: "' . $this->formName . '"'); |
|
190 | - return []; |
|
189 | + $this->drawError('you not have access to "' . $this->modelName . '" form with name: "' . $this->formName . '"'); |
|
190 | + return []; |
|
191 | 191 | } |
192 | 192 | $form = new Form(!empty($this->form['formOptions']) ? $this->form['formOptions'] : []); |
193 | 193 | \App::$cur->view->widget('Ui\ActiveForm', ['form' => $form, 'activeForm' => $this, 'ajax' => $ajax, 'params' => $params]); |
194 | - } |
|
194 | + } |
|
195 | 195 | |
196 | - public function drawCol($colName, $options, $form, $params = []) { |
|
196 | + public function drawCol($colName, $options, $form, $params = []) { |
|
197 | 197 | if (is_object($options)) { |
198 | - $options->draw(); |
|
198 | + $options->draw(); |
|
199 | 199 | } else { |
200 | - $inputClassName = '\Ui\ActiveForm\Input\\' . ucfirst($options['type']); |
|
201 | - $input = new $inputClassName(); |
|
202 | - $input->form = $form; |
|
203 | - $input->activeForm = $this; |
|
204 | - $input->activeFormParams = $params; |
|
205 | - $input->modelName = $this->modelName; |
|
206 | - $input->colName = $colName; |
|
207 | - $input->colParams = $options; |
|
208 | - $input->options = !empty($options['options']) ? $options['options'] : []; |
|
209 | - $input->draw(); |
|
200 | + $inputClassName = '\Ui\ActiveForm\Input\\' . ucfirst($options['type']); |
|
201 | + $input = new $inputClassName(); |
|
202 | + $input->form = $form; |
|
203 | + $input->activeForm = $this; |
|
204 | + $input->activeFormParams = $params; |
|
205 | + $input->modelName = $this->modelName; |
|
206 | + $input->colName = $colName; |
|
207 | + $input->colParams = $options; |
|
208 | + $input->options = !empty($options['options']) ? $options['options'] : []; |
|
209 | + $input->draw(); |
|
210 | 210 | } |
211 | 211 | return true; |
212 | - } |
|
212 | + } |
|
213 | 213 | |
214 | - public static function getOptionsList($inputParams, $params = [], $modelName = '', $aditionalInputNamePrefix = 'aditional', $options = []) { |
|
214 | + public static function getOptionsList($inputParams, $params = [], $modelName = '', $aditionalInputNamePrefix = 'aditional', $options = []) { |
|
215 | 215 | $values = []; |
216 | 216 | switch ($inputParams['source']) { |
217 | - case 'model': |
|
217 | + case 'model': |
|
218 | 218 | $values = $inputParams['model']::getList(['forSelect' => true]); |
219 | 219 | break; |
220 | - case 'array': |
|
220 | + case 'array': |
|
221 | 221 | $values = $inputParams['sourceArray']; |
222 | 222 | break; |
223 | - case 'method': |
|
223 | + case 'method': |
|
224 | 224 | if (!empty($inputParams['params'])) { |
225 | - $values = call_user_func_array([\App::$cur->$inputParams['module'], $inputParams['method']], $inputParams['params']); |
|
225 | + $values = call_user_func_array([\App::$cur->$inputParams['module'], $inputParams['method']], $inputParams['params']); |
|
226 | 226 | } else { |
227 | - $values = \App::$cur->$inputParams['module']->$inputParams['method'](); |
|
227 | + $values = \App::$cur->$inputParams['module']->$inputParams['method'](); |
|
228 | 228 | } |
229 | 229 | break; |
230 | - case 'relation': |
|
230 | + case 'relation': |
|
231 | 231 | if (!$modelName) { |
232 | - return []; |
|
232 | + return []; |
|
233 | 233 | } |
234 | 234 | $relation = $modelName::getRelation($inputParams['relation']); |
235 | 235 | if (!empty($params['dataManagerParams']['appType'])) { |
236 | - $options['appType'] = $params['dataManagerParams']['appType']; |
|
236 | + $options['appType'] = $params['dataManagerParams']['appType']; |
|
237 | 237 | } |
238 | 238 | $items = []; |
239 | 239 | if (class_exists($relation['model'])) { |
240 | - $filters = $relation['model']::managerFilters(); |
|
241 | - if (!empty($filters['getRows']['where'])) { |
|
240 | + $filters = $relation['model']::managerFilters(); |
|
241 | + if (!empty($filters['getRows']['where'])) { |
|
242 | 242 | $options['where'][] = $filters['getRows']['where']; |
243 | - } |
|
244 | - if (!empty($relation['where'])) { |
|
243 | + } |
|
244 | + if (!empty($relation['where'])) { |
|
245 | 245 | $options['where'][] = $relation['where']; |
246 | - } |
|
247 | - if (!empty($relation['order'])) { |
|
246 | + } |
|
247 | + if (!empty($relation['order'])) { |
|
248 | 248 | $options['order'] = $relation['order']; |
249 | - } |
|
250 | - if (!empty($inputParams['itemName'])) { |
|
249 | + } |
|
250 | + if (!empty($inputParams['itemName'])) { |
|
251 | 251 | $options['itemName'] = $inputParams['itemName']; |
252 | - } |
|
253 | - $items = $relation['model']::getList($options); |
|
252 | + } |
|
253 | + $items = $relation['model']::getList($options); |
|
254 | 254 | } |
255 | 255 | if (!empty($params['noEmptyValue'])) { |
256 | - $values = []; |
|
256 | + $values = []; |
|
257 | 257 | } else { |
258 | - $values = [0 => 'Не задано']; |
|
258 | + $values = [0 => 'Не задано']; |
|
259 | 259 | } |
260 | 260 | foreach ($items as $key => $item) { |
261 | - if (!empty($inputParams['showCol'])) { |
|
261 | + if (!empty($inputParams['showCol'])) { |
|
262 | 262 | if (is_array($inputParams['showCol'])) { |
263 | - switch ($inputParams['showCol']['type']) { |
|
263 | + switch ($inputParams['showCol']['type']) { |
|
264 | 264 | case 'staticMethod': |
265 | 265 | $values[$key] = $inputParams['showCol']['class']::{$inputParams['showCol']['method']}($item); |
266 | - break; |
|
267 | - } |
|
266 | + break; |
|
267 | + } |
|
268 | 268 | } else { |
269 | - $values[$key] = $item->$inputParams['showCol']; |
|
269 | + $values[$key] = $item->$inputParams['showCol']; |
|
270 | 270 | } |
271 | - } else { |
|
271 | + } else { |
|
272 | 272 | $values[$key] = $item->name(); |
273 | - } |
|
273 | + } |
|
274 | 274 | } |
275 | 275 | break; |
276 | 276 | } |
277 | 277 | foreach ($values as $key => $value) { |
278 | - if (is_array($value) && !empty($value['input']) && empty($value['input']['noprefix'])) { |
|
278 | + if (is_array($value) && !empty($value['input']) && empty($value['input']['noprefix'])) { |
|
279 | 279 | $values[$key]['input']['name'] = $aditionalInputNamePrefix . "[{$value['input']['name']}]"; |
280 | - } |
|
280 | + } |
|
281 | 281 | } |
282 | 282 | return $values; |
283 | - } |
|
283 | + } |
|
284 | 284 | |
285 | - /** |
|
286 | - * Draw error message |
|
287 | - * |
|
288 | - * @param string $errorText |
|
289 | - */ |
|
290 | - public function drawError($errorText) { |
|
285 | + /** |
|
286 | + * Draw error message |
|
287 | + * |
|
288 | + * @param string $errorText |
|
289 | + */ |
|
290 | + public function drawError($errorText) { |
|
291 | 291 | echo $errorText; |
292 | - } |
|
292 | + } |
|
293 | 293 | |
294 | - /** |
|
295 | - * Check access cur user to form with name in param and $model |
|
296 | - * |
|
297 | - * @return boolean |
|
298 | - */ |
|
299 | - public function checkAccess() { |
|
294 | + /** |
|
295 | + * Check access cur user to form with name in param and $model |
|
296 | + * |
|
297 | + * @return boolean |
|
298 | + */ |
|
299 | + public function checkAccess() { |
|
300 | 300 | if (empty($this->form)) { |
301 | - $this->drawError('"' . $this->modelName . '" form with name: "' . $this->formName . '" not found'); |
|
302 | - return false; |
|
301 | + $this->drawError('"' . $this->modelName . '" form with name: "' . $this->formName . '" not found'); |
|
302 | + return false; |
|
303 | 303 | } |
304 | 304 | if (\App::$cur->Access && !\App::$cur->Access->checkAccess($this)) { |
305 | - return false; |
|
305 | + return false; |
|
306 | 306 | } |
307 | 307 | if (!empty($this->form['options']['access']['apps']) && !in_array(\App::$cur->name, $this->form['options']['access']['apps'])) { |
308 | - return false; |
|
308 | + return false; |
|
309 | 309 | } |
310 | 310 | if (!empty($this->form['options']['access']['groups']) && in_array(\Users\User::$cur->group_id, $this->form['options']['access']['groups'])) { |
311 | - return true; |
|
311 | + return true; |
|
312 | 312 | } |
313 | 313 | if ($this->model && !empty($this->form['options']['access']['self']) && \Users\User::$cur->id == $this->model->user_id) { |
314 | - return true; |
|
314 | + return true; |
|
315 | 315 | } |
316 | 316 | if ($this->formName == 'manager' && !\Users\User::$cur->isAdmin()) { |
317 | - return false; |
|
317 | + return false; |
|
318 | 318 | } |
319 | 319 | return true; |
320 | - } |
|
320 | + } |
|
321 | 321 | |
322 | 322 | } |
@@ -12,61 +12,61 @@ discard block |
||
12 | 12 | |
13 | 13 | class DataManager extends \Object { |
14 | 14 | |
15 | - public $modelName = ''; |
|
16 | - public $managerOptions = []; |
|
17 | - public $managerName = 'customManager'; |
|
18 | - public $name = 'Менеджер данных'; |
|
19 | - public $limit = 30; |
|
20 | - public $page = 1; |
|
21 | - public $table = null; |
|
22 | - public $joins = []; |
|
23 | - public $predraw = false; |
|
24 | - public $cols = []; |
|
25 | - public $managerId = ''; |
|
26 | - |
|
27 | - /** |
|
28 | - * Construct new data manager |
|
29 | - * |
|
30 | - * @param string|array $modelNameOrOptions |
|
31 | - * @param string $managerName |
|
32 | - * @throws Exception |
|
33 | - */ |
|
34 | - public function __construct($modelNameOrOptions, $managerName = 'manager') { |
|
15 | + public $modelName = ''; |
|
16 | + public $managerOptions = []; |
|
17 | + public $managerName = 'customManager'; |
|
18 | + public $name = 'Менеджер данных'; |
|
19 | + public $limit = 30; |
|
20 | + public $page = 1; |
|
21 | + public $table = null; |
|
22 | + public $joins = []; |
|
23 | + public $predraw = false; |
|
24 | + public $cols = []; |
|
25 | + public $managerId = ''; |
|
26 | + |
|
27 | + /** |
|
28 | + * Construct new data manager |
|
29 | + * |
|
30 | + * @param string|array $modelNameOrOptions |
|
31 | + * @param string $managerName |
|
32 | + * @throws Exception |
|
33 | + */ |
|
34 | + public function __construct($modelNameOrOptions, $managerName = 'manager') { |
|
35 | 35 | $this->managerName = $managerName; |
36 | 36 | |
37 | 37 | if (!is_array($modelNameOrOptions)) { |
38 | - if (!class_exists($modelNameOrOptions)) { |
|
38 | + if (!class_exists($modelNameOrOptions)) { |
|
39 | 39 | throw new \Exception("model {$modelNameOrOptions} not exists"); |
40 | - } |
|
41 | - $this->modelName = $modelNameOrOptions; |
|
42 | - $this->managerOptions = !empty($modelNameOrOptions::$dataManagers[$managerName]) ? $modelNameOrOptions::$dataManagers[$managerName] : []; |
|
43 | - if (isset($modelNameOrOptions::$objectName)) { |
|
40 | + } |
|
41 | + $this->modelName = $modelNameOrOptions; |
|
42 | + $this->managerOptions = !empty($modelNameOrOptions::$dataManagers[$managerName]) ? $modelNameOrOptions::$dataManagers[$managerName] : []; |
|
43 | + if (isset($modelNameOrOptions::$objectName)) { |
|
44 | 44 | $this->name = $modelNameOrOptions::$objectName; |
45 | - } else { |
|
45 | + } else { |
|
46 | 46 | $this->name = $modelNameOrOptions; |
47 | - } |
|
47 | + } |
|
48 | 48 | } else { |
49 | - $this->managerOptions = $modelNameOrOptions; |
|
49 | + $this->managerOptions = $modelNameOrOptions; |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | if (!$this->managerOptions || !is_array($this->managerOptions)) { |
53 | - throw new \Exception('empty DataManager'); |
|
53 | + throw new \Exception('empty DataManager'); |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | if (!empty($this->managerOptions['name'])) { |
57 | - $this->name = $this->managerOptions['name']; |
|
57 | + $this->name = $this->managerOptions['name']; |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | $this->managerId = str_replace('\\', '_', 'dataManager_' . $this->modelName . '_' . $this->managerName . '_' . \Tools::randomString()); |
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Get buttons for manager |
|
65 | - * |
|
66 | - * @param string $params |
|
67 | - * @param object $model |
|
68 | - */ |
|
69 | - public function getButtons($params = [], $model = null) { |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Get buttons for manager |
|
65 | + * |
|
66 | + * @param string $params |
|
67 | + * @param object $model |
|
68 | + */ |
|
69 | + public function getButtons($params = [], $model = null) { |
|
70 | 70 | $modelName = $this->modelName; |
71 | 71 | |
72 | 72 | |
@@ -76,102 +76,102 @@ discard block |
||
76 | 76 | 'formName' => !empty($this->managerOptions['editForm']) ? $this->managerOptions['editForm'] : 'manager' |
77 | 77 | ]; |
78 | 78 | if ($model) { |
79 | - $formModelName = get_class($model); |
|
80 | - $relations = $formModelName::relations(); |
|
81 | - $type = !empty($relations[$params['relation']]['type']) ? $relations[$params['relation']]['type'] : 'to'; |
|
82 | - switch ($type) { |
|
79 | + $formModelName = get_class($model); |
|
80 | + $relations = $formModelName::relations(); |
|
81 | + $type = !empty($relations[$params['relation']]['type']) ? $relations[$params['relation']]['type'] : 'to'; |
|
82 | + switch ($type) { |
|
83 | 83 | case 'relModel': |
84 | 84 | $formParams['preset'] = [ |
85 | - $formModelName::index() => $model->pk() |
|
86 | - ]; |
|
87 | - break; |
|
85 | + $formModelName::index() => $model->pk() |
|
86 | + ]; |
|
87 | + break; |
|
88 | 88 | default: |
89 | 89 | $formParams['preset'] = [ |
90 | - $relations[$params['relation']]['col'] => $model->pk() |
|
91 | - ]; |
|
92 | - } |
|
90 | + $relations[$params['relation']]['col'] => $model->pk() |
|
91 | + ]; |
|
92 | + } |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | $buttons = []; |
96 | 96 | if (!empty($this->managerOptions['sortMode'])) { |
97 | - $buttons[] = [ |
|
98 | - 'class' => 'modeBtn', |
|
99 | - 'data-mode' => 'sort', |
|
100 | - 'text' => 'Сортировать', |
|
101 | - ]; |
|
97 | + $buttons[] = [ |
|
98 | + 'class' => 'modeBtn', |
|
99 | + 'data-mode' => 'sort', |
|
100 | + 'text' => 'Сортировать', |
|
101 | + ]; |
|
102 | 102 | } |
103 | 103 | if (!empty($this->managerOptions['filters'])) { |
104 | - $buttons[] = [ |
|
105 | - 'text' => 'Фильтры', |
|
106 | - 'onclick' => ' var modal = $("#' . $this->managerId . '_filters"); |
|
104 | + $buttons[] = [ |
|
105 | + 'text' => 'Фильтры', |
|
106 | + 'onclick' => ' var modal = $("#' . $this->managerId . '_filters"); |
|
107 | 107 | modal.modal("show");', |
108 | - ]; |
|
108 | + ]; |
|
109 | 109 | } |
110 | 110 | if (!empty($modelName::$forms['simpleItem'])) { |
111 | - $formParams['formName'] = 'simpleItem'; |
|
112 | - $buttons[] = [ |
|
113 | - 'text' => '<i class = "glyphicon glyphicon-send"></i> Быстрое создание', |
|
114 | - 'onclick' => 'inji.Ui.dataManagers.get(this).newItem("' . str_replace('\\', '\\\\', $modelName) . '",' . json_encode($formParams) . ');', |
|
115 | - ]; |
|
111 | + $formParams['formName'] = 'simpleItem'; |
|
112 | + $buttons[] = [ |
|
113 | + 'text' => '<i class = "glyphicon glyphicon-send"></i> Быстрое создание', |
|
114 | + 'onclick' => 'inji.Ui.dataManagers.get(this).newItem("' . str_replace('\\', '\\\\', $modelName) . '",' . json_encode($formParams) . ');', |
|
115 | + ]; |
|
116 | 116 | } |
117 | 117 | $formParams['formName'] = !empty($this->managerOptions['editForm']) ? $this->managerOptions['editForm'] : 'manager'; |
118 | 118 | $name = 'Элемент'; |
119 | 119 | if ($modelName::$objectName) { |
120 | - $name = $modelName::$objectName; |
|
120 | + $name = $modelName::$objectName; |
|
121 | 121 | } |
122 | 122 | if (!empty($modelName::$forms[$formParams['formName']])) { |
123 | - $aform = new ActiveForm(new $modelName, $formParams['formName']); |
|
124 | - if ($aform->checkAccess()) { |
|
123 | + $aform = new ActiveForm(new $modelName, $formParams['formName']); |
|
124 | + if ($aform->checkAccess()) { |
|
125 | 125 | $buttons[] = [ |
126 | 126 | 'text' => 'Создать ' . $name, |
127 | 127 | 'onclick' => 'inji.Ui.dataManagers.get(this).newItem("' . str_replace('\\', '\\\\', $modelName) . '",' . json_encode($formParams) . ');', |
128 | 128 | ]; |
129 | - } |
|
129 | + } |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | return $buttons; |
133 | - } |
|
133 | + } |
|
134 | 134 | |
135 | - function getActions($onlyGroupActions = false) { |
|
135 | + function getActions($onlyGroupActions = false) { |
|
136 | 136 | $actions = [ |
137 | 137 | 'Open' => ['className' => 'Open'], 'Edit' => ['className' => 'Edit'], 'Delete' => ['className' => 'Delete'] |
138 | 138 | ]; |
139 | 139 | if (isset($this->managerOptions['actions'])) { |
140 | - $actions = array_merge($actions, $this->managerOptions['actions']); |
|
140 | + $actions = array_merge($actions, $this->managerOptions['actions']); |
|
141 | 141 | } |
142 | 142 | $return = []; |
143 | 143 | foreach ($actions as $key => $action) { |
144 | - if ($action === false) { |
|
144 | + if ($action === false) { |
|
145 | 145 | continue; |
146 | - } |
|
147 | - if (is_array($action)) { |
|
146 | + } |
|
147 | + if (is_array($action)) { |
|
148 | 148 | if (!empty($action['access']['groups']) && !in_array(\Users\User::$cur->group_id, $action['access']['groups'])) { |
149 | - continue; |
|
149 | + continue; |
|
150 | 150 | } |
151 | 151 | if (empty($action['className'])) { |
152 | - $action['className'] = $key; |
|
152 | + $action['className'] = $key; |
|
153 | 153 | } |
154 | 154 | $return[$key] = $action; |
155 | - } else { |
|
155 | + } else { |
|
156 | 156 | $key = $action; |
157 | 157 | $return[$key] = [ |
158 | 158 | 'className' => $action |
159 | 159 | ]; |
160 | - } |
|
161 | - $return[$key]['className'] = strpos($return[$key]['className'], '\\') === false && class_exists('Ui\DataManager\Action\\' . $return[$key]['className']) ? 'Ui\DataManager\Action\\' . $return[$key]['className'] : $return[$key]['className']; |
|
162 | - if (!class_exists($return[$key]['className']) || ($onlyGroupActions && !$return[$key]['className']::$groupAction)) { |
|
160 | + } |
|
161 | + $return[$key]['className'] = strpos($return[$key]['className'], '\\') === false && class_exists('Ui\DataManager\Action\\' . $return[$key]['className']) ? 'Ui\DataManager\Action\\' . $return[$key]['className'] : $return[$key]['className']; |
|
162 | + if (!class_exists($return[$key]['className']) || ($onlyGroupActions && !$return[$key]['className']::$groupAction)) { |
|
163 | 163 | unset($return[$key]); |
164 | - } |
|
164 | + } |
|
165 | 165 | } |
166 | 166 | return $return; |
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * Get cols for manager |
|
171 | - * |
|
172 | - * @return string |
|
173 | - */ |
|
174 | - public function getCols() { |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * Get cols for manager |
|
171 | + * |
|
172 | + * @return string |
|
173 | + */ |
|
174 | + public function getCols() { |
|
175 | 175 | $actions = $this->getActions(); |
176 | 176 | ob_start(); |
177 | 177 | ?> |
@@ -187,12 +187,12 @@ discard block |
||
187 | 187 | <li><a href ='' onclick='inji.Ui.dataManagers.get(this).rowSelection("inverse");return false;'>Инвертировать</a></li> |
188 | 188 | <li role="separator" class="divider"></li> |
189 | 189 | <?php |
190 | - foreach ($actions as $action => $actionParams) { |
|
190 | + foreach ($actions as $action => $actionParams) { |
|
191 | 191 | if (class_exists($actionParams['className']) && $actionParams['className']::$groupAction) { |
192 | - echo "<li><a role='button' href ='#' onclick='inji.Ui.dataManagers.get(this).groupAction(\"" . str_replace('\\', '\\\\', $action) . "\");return false;'>{$actionParams['className']::$name}</a></li>"; |
|
192 | + echo "<li><a role='button' href ='#' onclick='inji.Ui.dataManagers.get(this).groupAction(\"" . str_replace('\\', '\\\\', $action) . "\");return false;'>{$actionParams['className']::$name}</a></li>"; |
|
193 | + } |
|
193 | 194 | } |
194 | - } |
|
195 | - ?> |
|
195 | + ?> |
|
196 | 196 | </ul> |
197 | 197 | </div> |
198 | 198 | <?php |
@@ -205,284 +205,284 @@ discard block |
||
205 | 205 | |
206 | 206 | $modelName = $this->modelName; |
207 | 207 | foreach ($this->managerOptions['cols'] as $key => $col) { |
208 | - if (is_array($col)) { |
|
208 | + if (is_array($col)) { |
|
209 | 209 | $colName = $key; |
210 | 210 | $colOptions = $col; |
211 | - } else { |
|
211 | + } else { |
|
212 | 212 | $colName = $col; |
213 | 213 | $colOptions = []; |
214 | - } |
|
215 | - $colInfo = []; |
|
216 | - if ($modelName) { |
|
214 | + } |
|
215 | + $colInfo = []; |
|
216 | + if ($modelName) { |
|
217 | 217 | $colInfo = $modelName::getColInfo($colName); |
218 | - } |
|
219 | - if (empty($colOptions['label']) && !empty($colInfo['label'])) { |
|
218 | + } |
|
219 | + if (empty($colOptions['label']) && !empty($colInfo['label'])) { |
|
220 | 220 | $colOptions['label'] = $colInfo['label']; |
221 | - } elseif (empty($colOptions['label'])) { |
|
221 | + } elseif (empty($colOptions['label'])) { |
|
222 | 222 | $colOptions['label'] = $colName; |
223 | - } |
|
224 | - $cols[$colName] = $colOptions; |
|
223 | + } |
|
224 | + $cols[$colName] = $colOptions; |
|
225 | 225 | } |
226 | 226 | return $cols; |
227 | - } |
|
228 | - |
|
229 | - /** |
|
230 | - * Get rows for manager |
|
231 | - * |
|
232 | - * @param array $params |
|
233 | - * @param object $model |
|
234 | - * @return type |
|
235 | - */ |
|
236 | - public function getRows($params = [], $model = null) { |
|
227 | + } |
|
228 | + |
|
229 | + /** |
|
230 | + * Get rows for manager |
|
231 | + * |
|
232 | + * @param array $params |
|
233 | + * @param object $model |
|
234 | + * @return type |
|
235 | + */ |
|
236 | + public function getRows($params = [], $model = null) { |
|
237 | 237 | $modelName = $this->modelName; |
238 | 238 | if (!class_exists($modelName)) { |
239 | - return []; |
|
239 | + return []; |
|
240 | 240 | } |
241 | 241 | if (!$this->checkAccess()) { |
242 | - $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->managerName . '"'); |
|
243 | - return []; |
|
242 | + $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->managerName . '"'); |
|
243 | + return []; |
|
244 | 244 | } |
245 | 245 | $modelName = $this->modelName; |
246 | 246 | $queryParams = []; |
247 | 247 | if (empty($params['all'])) { |
248 | - if (!empty($params['limit'])) { |
|
248 | + if (!empty($params['limit'])) { |
|
249 | 249 | $this->limit = (int) $params['limit']; |
250 | - } |
|
251 | - if (!empty($params['page'])) { |
|
250 | + } |
|
251 | + if (!empty($params['page'])) { |
|
252 | 252 | $this->page = (int) $params['page']; |
253 | - } |
|
254 | - $queryParams['limit'] = $this->limit; |
|
255 | - $queryParams['start'] = $this->page * $this->limit - $this->limit; |
|
253 | + } |
|
254 | + $queryParams['limit'] = $this->limit; |
|
255 | + $queryParams['start'] = $this->page * $this->limit - $this->limit; |
|
256 | 256 | } |
257 | 257 | if (!empty($params['categoryPath']) && $modelName::$categoryModel) { |
258 | - $queryParams['where'][] = ['tree_path', $params['categoryPath'] . '%', 'LIKE']; |
|
258 | + $queryParams['where'][] = ['tree_path', $params['categoryPath'] . '%', 'LIKE']; |
|
259 | 259 | } |
260 | 260 | if (!empty($params['appType'])) { |
261 | - $queryParams['appType'] = $params['appType']; |
|
261 | + $queryParams['appType'] = $params['appType']; |
|
262 | 262 | } |
263 | 263 | if ($this->joins) { |
264 | - $queryParams['joins'] = $this->joins; |
|
264 | + $queryParams['joins'] = $this->joins; |
|
265 | 265 | } |
266 | 266 | if (!empty($this->managerOptions['userGroupFilter'][\Users\User::$cur->group_id]['getRows'])) { |
267 | - foreach ($this->managerOptions['userGroupFilter'][\Users\User::$cur->group_id]['getRows'] as $colName => $colOptions) { |
|
267 | + foreach ($this->managerOptions['userGroupFilter'][\Users\User::$cur->group_id]['getRows'] as $colName => $colOptions) { |
|
268 | 268 | if (!empty($colOptions['userCol'])) { |
269 | - $queryParams['where'][] = [$colName, \Model::getColValue(\Users\User::$cur, $colOptions['userCol'])]; |
|
269 | + $queryParams['where'][] = [$colName, \Model::getColValue(\Users\User::$cur, $colOptions['userCol'])]; |
|
270 | 270 | } elseif (isset($colOptions['value'])) { |
271 | - if (is_array($colOptions['value'])) { |
|
271 | + if (is_array($colOptions['value'])) { |
|
272 | 272 | foreach ($colOptions['value'] as $key => $value) { |
273 | - if ($key === 'userCol') { |
|
273 | + if ($key === 'userCol') { |
|
274 | 274 | $colOptions['value'][$key] = \Model::getColValue(\Users\User::$cur, $value); |
275 | - } |
|
275 | + } |
|
276 | + } |
|
276 | 277 | } |
277 | - } |
|
278 | - $queryParams['where'][] = [$colName, $colOptions['value'], is_array($colOptions['value']) ? 'IN' : '=']; |
|
278 | + $queryParams['where'][] = [$colName, $colOptions['value'], is_array($colOptions['value']) ? 'IN' : '=']; |
|
279 | + } |
|
279 | 280 | } |
280 | - } |
|
281 | 281 | } |
282 | 282 | if (!empty($this->managerOptions['filters'])) { |
283 | - foreach ($this->managerOptions['filters'] as $col) { |
|
283 | + foreach ($this->managerOptions['filters'] as $col) { |
|
284 | 284 | $colInfo = $modelName::getColInfo($col); |
285 | 285 | switch ($colInfo['colParams']['type']) { |
286 | - case 'select': |
|
286 | + case 'select': |
|
287 | 287 | if (empty($params['filters'][$col]['value'])) { |
288 | - continue; |
|
288 | + continue; |
|
289 | 289 | } |
290 | 290 | if (is_array($params['filters'][$col]['value'])) { |
291 | - foreach ($params['filters'][$col]['value'] as $key => $value) { |
|
291 | + foreach ($params['filters'][$col]['value'] as $key => $value) { |
|
292 | 292 | if ($value === '') { |
293 | - unset($params['filters'][$col]['value'][$key]); |
|
293 | + unset($params['filters'][$col]['value'][$key]); |
|
294 | + } |
|
294 | 295 | } |
295 | - } |
|
296 | 296 | } |
297 | 297 | if (!$params['filters'][$col]['value']) { |
298 | - continue; |
|
298 | + continue; |
|
299 | 299 | } |
300 | 300 | $queryParams['where'][] = [$col, $params['filters'][$col]['value'], is_array($params['filters'][$col]['value']) ? 'IN' : '=']; |
301 | 301 | break; |
302 | - case 'bool': |
|
302 | + case 'bool': |
|
303 | 303 | |
304 | 304 | if (!isset($params['filters'][$col]['value']) || $params['filters'][$col]['value'] === '') { |
305 | - continue; |
|
305 | + continue; |
|
306 | 306 | } |
307 | 307 | $queryParams['where'][] = [$col, $params['filters'][$col]['value']]; |
308 | 308 | break; |
309 | - case 'dateTime': |
|
309 | + case 'dateTime': |
|
310 | 310 | case 'date': |
311 | 311 | if (empty($params['filters'][$col]['min']) && empty($params['filters'][$col]['max'])) { |
312 | - continue; |
|
312 | + continue; |
|
313 | 313 | } |
314 | 314 | if (!empty($params['filters'][$col]['min'])) { |
315 | - $queryParams['where'][] = [$col, $params['filters'][$col]['min'], '>=']; |
|
315 | + $queryParams['where'][] = [$col, $params['filters'][$col]['min'], '>=']; |
|
316 | 316 | } |
317 | 317 | if (!empty($params['filters'][$col]['max'])) { |
318 | - if ($colInfo['colParams']['type'] == 'dateTime' && !strpos($params['filters'][$col]['max'], ' ')) { |
|
318 | + if ($colInfo['colParams']['type'] == 'dateTime' && !strpos($params['filters'][$col]['max'], ' ')) { |
|
319 | 319 | |
320 | 320 | $date = $params['filters'][$col]['max'] . ' 23:59:59'; |
321 | - } else { |
|
321 | + } else { |
|
322 | 322 | $date = $params['filters'][$col]['max']; |
323 | - } |
|
324 | - $queryParams['where'][] = [$col, $date, '<=']; |
|
323 | + } |
|
324 | + $queryParams['where'][] = [$col, $date, '<=']; |
|
325 | 325 | } |
326 | 326 | break; |
327 | - case 'number': |
|
327 | + case 'number': |
|
328 | 328 | if (empty($params['filters'][$col]['min']) && empty($params['filters'][$col]['max'])) { |
329 | - continue; |
|
329 | + continue; |
|
330 | 330 | } |
331 | 331 | if (!empty($params['filters'][$col]['min'])) { |
332 | - $queryParams['where'][] = [$col, $params['filters'][$col]['min'], '>=']; |
|
332 | + $queryParams['where'][] = [$col, $params['filters'][$col]['min'], '>=']; |
|
333 | 333 | } |
334 | 334 | if (!empty($params['filters'][$col]['max'])) { |
335 | - $queryParams['where'][] = [$col, $params['filters'][$col]['max'], '<=']; |
|
335 | + $queryParams['where'][] = [$col, $params['filters'][$col]['max'], '<=']; |
|
336 | 336 | } |
337 | 337 | break; |
338 | - case 'email': |
|
338 | + case 'email': |
|
339 | 339 | case 'text': |
340 | 340 | case 'textarea': |
341 | 341 | case 'html': |
342 | 342 | if (empty($params['filters'][$col]['value'])) { |
343 | - continue; |
|
343 | + continue; |
|
344 | 344 | } |
345 | 345 | switch ($params['filters'][$col]['compareType']) { |
346 | - case 'contains': |
|
346 | + case 'contains': |
|
347 | 347 | $queryParams['where'][] = [$col, '%' . $params['filters'][$col]['value'] . '%', 'LIKE']; |
348 | 348 | break; |
349 | - case 'equals': |
|
349 | + case 'equals': |
|
350 | 350 | $queryParams['where'][] = [$col, $params['filters'][$col]['value']]; |
351 | 351 | break; |
352 | - case 'starts_with': |
|
352 | + case 'starts_with': |
|
353 | 353 | $queryParams['where'][] = [$col, $params['filters'][$col]['value'] . '%', 'LIKE']; |
354 | 354 | break; |
355 | - case 'ends_with': |
|
355 | + case 'ends_with': |
|
356 | 356 | $queryParams['where'][] = [$col, '%' . $params['filters'][$col]['value'], 'LIKE']; |
357 | 357 | break; |
358 | 358 | } |
359 | 359 | break; |
360 | 360 | } |
361 | - } |
|
361 | + } |
|
362 | 362 | } |
363 | 363 | if (!empty($params['mode']) && $params['mode'] == 'sort') { |
364 | - $queryParams['order'] = ['weight', 'asc']; |
|
364 | + $queryParams['order'] = ['weight', 'asc']; |
|
365 | 365 | } elseif (!empty($params['sortered']) && !empty($this->managerOptions['sortable'])) { |
366 | - foreach ($params['sortered'] as $colName => $sortType) { |
|
366 | + foreach ($params['sortered'] as $colName => $sortType) { |
|
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 | - $redirectUrl = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/admin/' . str_replace('\\', '%5C', get_class($originalItem)); |
|
388 | - $row[] = "<a href ='/admin/" . $item->genViewLink() . "?redirectUrl={$redirectUrl}'>{$item->pk()}</a>"; |
|
389 | - foreach ($this->managerOptions['cols'] as $key => $colName) { |
|
384 | + } |
|
385 | + $row = []; |
|
386 | + $row[] = '<input type ="checkbox" name = "pk[]" value =' . $item->pk() . '>'; |
|
387 | + $redirectUrl = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/admin/' . str_replace('\\', '%5C', get_class($originalItem)); |
|
388 | + $row[] = "<a href ='/admin/" . $item->genViewLink() . "?redirectUrl={$redirectUrl}'>{$item->pk()}</a>"; |
|
389 | + foreach ($this->managerOptions['cols'] as $key => $colName) { |
|
390 | 390 | if (!empty($params['download'])) { |
391 | - $row[] = \Model::getColValue($item, is_array($colName) ? $key : $colName, true, false); |
|
391 | + $row[] = \Model::getColValue($item, is_array($colName) ? $key : $colName, true, false); |
|
392 | 392 | } else { |
393 | - $row[] = DataManager::drawCol($item, is_array($colName) ? $key : $colName, $params, $this); |
|
393 | + $row[] = DataManager::drawCol($item, is_array($colName) ? $key : $colName, $params, $this); |
|
394 | + } |
|
394 | 395 | } |
395 | - } |
|
396 | - $row[] = $this->rowButtons($item, $params); |
|
397 | - $rows[] = $row; |
|
396 | + $row[] = $this->rowButtons($item, $params); |
|
397 | + $rows[] = $row; |
|
398 | 398 | } |
399 | 399 | return $rows; |
400 | - } |
|
400 | + } |
|
401 | 401 | |
402 | - public static function drawCol($item, $colName, $params = [], $dataManager = null, $originalCol = '', $originalItem = null) { |
|
402 | + public static function drawCol($item, $colName, $params = [], $dataManager = null, $originalCol = '', $originalItem = null) { |
|
403 | 403 | $modelName = get_class($item); |
404 | 404 | if (!class_exists($modelName)) { |
405 | - return false; |
|
405 | + return false; |
|
406 | 406 | } |
407 | 407 | |
408 | 408 | if (!$originalCol) { |
409 | - $originalCol = $colName; |
|
409 | + $originalCol = $colName; |
|
410 | 410 | } |
411 | 411 | if (!$originalItem) { |
412 | - $originalItem = $item; |
|
412 | + $originalItem = $item; |
|
413 | 413 | } |
414 | 414 | |
415 | 415 | $relations = $modelName::relations(); |
416 | 416 | if (strpos($colName, ':') !== false && !empty($relations[substr($colName, 0, strpos($colName, ':'))])) { |
417 | - $rel = substr($colName, 0, strpos($colName, ':')); |
|
418 | - $col = substr($colName, strpos($colName, ':') + 1); |
|
419 | - if ($item->$rel) { |
|
417 | + $rel = substr($colName, 0, strpos($colName, ':')); |
|
418 | + $col = substr($colName, strpos($colName, ':') + 1); |
|
419 | + if ($item->$rel) { |
|
420 | 420 | return DataManager::drawCol($item->$rel, $col, $params, $dataManager, $originalCol, $originalItem); |
421 | - } else { |
|
421 | + } else { |
|
422 | 422 | return 'Не указано'; |
423 | - } |
|
423 | + } |
|
424 | 424 | } |
425 | 425 | if (!empty($modelName::$cols[$colName]['relation'])) { |
426 | - $type = !empty($relations[$modelName::$cols[$colName]['relation']]['type']) ? $relations[$modelName::$cols[$colName]['relation']]['type'] : 'to'; |
|
427 | - switch ($type) { |
|
426 | + $type = !empty($relations[$modelName::$cols[$colName]['relation']]['type']) ? $relations[$modelName::$cols[$colName]['relation']]['type'] : 'to'; |
|
427 | + switch ($type) { |
|
428 | 428 | case 'relModel': |
429 | 429 | $managerParams = ['relation' => $modelName::$cols[$colName]['relation']]; |
430 | - $count = $item->{$modelName::$cols[$colName]['relation']}(array_merge($params, ['count' => 1])); |
|
431 | - $count = $count ? $count : 'Нет'; |
|
432 | - 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>"; |
|
430 | + $count = $item->{$modelName::$cols[$colName]['relation']}(array_merge($params, ['count' => 1])); |
|
431 | + $count = $count ? $count : 'Нет'; |
|
432 | + 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>"; |
|
433 | 433 | case 'many': |
434 | 434 | $managerParams = ['relation' => $modelName::$cols[$colName]['relation']]; |
435 | - $count = $item->{$modelName::$cols[$colName]['relation']}(array_merge($params, ['count' => 1])); |
|
436 | - $count = $count ? $count : 'Нет'; |
|
437 | - 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>"; |
|
435 | + $count = $item->{$modelName::$cols[$colName]['relation']}(array_merge($params, ['count' => 1])); |
|
436 | + $count = $count ? $count : 'Нет'; |
|
437 | + 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>"; |
|
438 | 438 | default : |
439 | 439 | if ($item->{$modelName::$cols[$colName]['relation']}) { |
440 | 440 | if (\App::$cur->name == 'admin') { |
441 | - $href = "<a href ='/admin/" . $item->{$modelName::$cols[$colName]['relation']}->genViewLink() . "'>"; |
|
442 | - if (!empty($modelName::$cols[$colName]['showCol'])) { |
|
441 | + $href = "<a href ='/admin/" . $item->{$modelName::$cols[$colName]['relation']}->genViewLink() . "'>"; |
|
442 | + if (!empty($modelName::$cols[$colName]['showCol'])) { |
|
443 | 443 | $href .= $item->{$modelName::$cols[$colName]['relation']}->{$modelName::$cols[$colName]['showCol']}; |
444 | - } else { |
|
444 | + } else { |
|
445 | 445 | |
446 | 446 | $href .= $item->{$modelName::$cols[$colName]['relation']}->name(); |
447 | - } |
|
448 | - $href .= '</a>'; |
|
449 | - return $href; |
|
447 | + } |
|
448 | + $href .= '</a>'; |
|
449 | + return $href; |
|
450 | 450 | } else { |
451 | - return $item->{$modelName::$cols[$colName]['relation']}->name(); |
|
451 | + return $item->{$modelName::$cols[$colName]['relation']}->name(); |
|
452 | 452 | } |
453 | - } else { |
|
453 | + } else { |
|
454 | 454 | return $item->$colName; |
455 | - } |
|
456 | - } |
|
455 | + } |
|
456 | + } |
|
457 | 457 | } else { |
458 | - if (!empty($modelName::$cols[$colName]['view']['type'])) { |
|
458 | + if (!empty($modelName::$cols[$colName]['view']['type'])) { |
|
459 | 459 | switch ($modelName::$cols[$colName]['view']['type']) { |
460 | - case 'widget': |
|
460 | + case 'widget': |
|
461 | 461 | ob_start(); |
462 | 462 | \App::$cur->view->widget($modelName::$cols[$colName]['view']['widget'], ['item' => $item, 'colName' => $colName, 'colParams' => $modelName::$cols[$colName]]); |
463 | 463 | $content = ob_get_contents(); |
464 | 464 | ob_end_clean(); |
465 | 465 | return $content; |
466 | - case 'moduleMethod': |
|
466 | + case 'moduleMethod': |
|
467 | 467 | return \App::$cur->{$modelName::$cols[$colName]['view']['module']}->{$modelName::$cols[$colName]['view']['method']}($item, $colName, $modelName::$cols[$colName]); |
468 | - case 'many': |
|
468 | + case 'many': |
|
469 | 469 | $managerParams = ['relation' => $modelName::$cols[$colName]['relation']]; |
470 | 470 | $count = $item->{$modelName::$cols[$colName]['relation']}(array_merge($params, ['count' => 1])); |
471 | 471 | 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>"; |
472 | - default: |
|
472 | + default: |
|
473 | 473 | return $item->$colName; |
474 | 474 | } |
475 | - } elseif (!empty($modelName::$cols[$colName]['type'])) { |
|
475 | + } elseif (!empty($modelName::$cols[$colName]['type'])) { |
|
476 | 476 | if (\App::$cur->name == 'admin' && $originalCol == 'name' || ( $dataManager && !empty($dataManager->managerOptions['colToView']) && $dataManager->managerOptions['colToView'] == $originalCol)) { |
477 | - $formName = $dataManager && !empty($dataManager->managerOptions['editForm']) ? $dataManager->managerOptions['editForm'] : 'manager'; |
|
478 | - $redirectUrl = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/admin/' . str_replace('\\', '/', get_class($originalItem)); |
|
479 | - return "<a href ='/admin/{$originalItem->genViewLink()}?formName={$formName}&redirectUrl={$redirectUrl}'>{$item->$colName}</a>"; |
|
477 | + $formName = $dataManager && !empty($dataManager->managerOptions['editForm']) ? $dataManager->managerOptions['editForm'] : 'manager'; |
|
478 | + $redirectUrl = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/admin/' . str_replace('\\', '/', get_class($originalItem)); |
|
479 | + return "<a href ='/admin/{$originalItem->genViewLink()}?formName={$formName}&redirectUrl={$redirectUrl}'>{$item->$colName}</a>"; |
|
480 | 480 | } elseif (\App::$cur->name == 'admin' && $colName == 'name') { |
481 | - $redirectUrl = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/admin/' . str_replace('\\', '/', get_class($originalItem)); |
|
482 | - return "<a href ='/admin/{$item->genViewLink()}?redirectUrl={$redirectUrl}'>{$item->$colName}</a>"; |
|
481 | + $redirectUrl = !empty($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/admin/' . str_replace('\\', '/', get_class($originalItem)); |
|
482 | + return "<a href ='/admin/{$item->genViewLink()}?redirectUrl={$redirectUrl}'>{$item->$colName}</a>"; |
|
483 | 483 | } elseif ($modelName::$cols[$colName]['type'] == 'html') { |
484 | - $uid = \Tools::randomString(); |
|
485 | - $script = "<script>inji.onLoad(function(){ |
|
484 | + $uid = \Tools::randomString(); |
|
485 | + $script = "<script>inji.onLoad(function(){ |
|
486 | 486 | var el{$uid}=$('#{$uid}'); |
487 | 487 | var height{$uid} = el{$uid}.height(); |
488 | 488 | el{$uid}.css('maxHeight','none'); |
@@ -508,20 +508,20 @@ discard block |
||
508 | 508 | el{$uid}.after('<a href=\"#\" onclick=\"el{$uid}Toggle();return false;\">Развернуть</a>'); |
509 | 509 | } |
510 | 510 | })</script>"; |
511 | - return "<div id = '{$uid}' style='max-height:44px;overflow:hidden;'>{$item->$colName}</div>" . $script; |
|
511 | + return "<div id = '{$uid}' style='max-height:44px;overflow:hidden;'>{$item->$colName}</div>" . $script; |
|
512 | 512 | } else { |
513 | - return \Model::resloveTypeValue($item, $colName); |
|
513 | + return \Model::resloveTypeValue($item, $colName); |
|
514 | 514 | } |
515 | - } else { |
|
515 | + } else { |
|
516 | 516 | return $item->$colName; |
517 | - } |
|
517 | + } |
|
518 | + } |
|
518 | 519 | } |
519 | - } |
|
520 | 520 | |
521 | - public function rowButtons($item, $params) { |
|
521 | + public function rowButtons($item, $params) { |
|
522 | 522 | $modelName = $this->modelName; |
523 | 523 | if (!class_exists($modelName)) { |
524 | - return false; |
|
524 | + return false; |
|
525 | 525 | } |
526 | 526 | ob_start(); |
527 | 527 | $widgetName = !empty($this->managerOptions['rowButtonsWidget']) ? $this->managerOptions['rowButtonsWidget'] : 'Ui\DataManager/rowButtons'; |
@@ -533,132 +533,132 @@ discard block |
||
533 | 533 | $buttons = ob_get_contents(); |
534 | 534 | ob_end_clean(); |
535 | 535 | return $buttons; |
536 | - } |
|
536 | + } |
|
537 | 537 | |
538 | - public function getPages($params = [], $model = null) { |
|
538 | + public function getPages($params = [], $model = null) { |
|
539 | 539 | $modelName = $this->modelName; |
540 | 540 | if (!class_exists($modelName)) { |
541 | - return []; |
|
541 | + return []; |
|
542 | 542 | } |
543 | 543 | if (!$this->checkAccess()) { |
544 | - $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->managerName . '"'); |
|
545 | - return []; |
|
544 | + $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->managerName . '"'); |
|
545 | + return []; |
|
546 | 546 | } |
547 | 547 | if (!empty($params['limit'])) { |
548 | - $this->limit = (int) $params['limit']; |
|
548 | + $this->limit = (int) $params['limit']; |
|
549 | 549 | } |
550 | 550 | if (!empty($params['page'])) { |
551 | - $this->page = (int) $params['page']; |
|
551 | + $this->page = (int) $params['page']; |
|
552 | 552 | } |
553 | 553 | $queryParams = [ |
554 | 554 | 'count' => true |
555 | 555 | ]; |
556 | 556 | $modelName = $this->modelName; |
557 | 557 | if (!empty($params['categoryPath']) && $modelName::$categoryModel) { |
558 | - $queryParams['where'][] = ['tree_path', $params['categoryPath'] . '%', 'LIKE']; |
|
558 | + $queryParams['where'][] = ['tree_path', $params['categoryPath'] . '%', 'LIKE']; |
|
559 | 559 | } |
560 | 560 | if (!empty($this->managerOptions['userGroupFilter'][\Users\User::$cur->group_id]['getRows'])) { |
561 | - foreach ($this->managerOptions['userGroupFilter'][\Users\User::$cur->group_id]['getRows'] as $colName => $colOptions) { |
|
561 | + foreach ($this->managerOptions['userGroupFilter'][\Users\User::$cur->group_id]['getRows'] as $colName => $colOptions) { |
|
562 | 562 | if (!empty($colOptions['userCol'])) { |
563 | - $queryParams['where'][] = [$colName, \Model::getColValue(\Users\User::$cur, $colOptions['userCol'])]; |
|
563 | + $queryParams['where'][] = [$colName, \Model::getColValue(\Users\User::$cur, $colOptions['userCol'])]; |
|
564 | 564 | } elseif (isset($colOptions['value'])) { |
565 | - if (is_array($colOptions['value'])) { |
|
565 | + if (is_array($colOptions['value'])) { |
|
566 | 566 | foreach ($colOptions['value'] as $key => $value) { |
567 | - if ($key === 'userCol') { |
|
567 | + if ($key === 'userCol') { |
|
568 | 568 | $colOptions['value'][$key] = \Model::getColValue(\Users\User::$cur, $value); |
569 | - } |
|
569 | + } |
|
570 | 570 | } |
571 | - } |
|
572 | - $queryParams['where'][] = [$colName, $colOptions['value'], is_array($colOptions['value']) ? 'IN' : '=']; |
|
571 | + } |
|
572 | + $queryParams['where'][] = [$colName, $colOptions['value'], is_array($colOptions['value']) ? 'IN' : '=']; |
|
573 | + } |
|
573 | 574 | } |
574 | - } |
|
575 | 575 | } |
576 | 576 | $modelName = $this->modelName; |
577 | 577 | if (!empty($this->managerOptions['filters'])) { |
578 | - foreach ($this->managerOptions['filters'] as $col) { |
|
578 | + foreach ($this->managerOptions['filters'] as $col) { |
|
579 | 579 | $colInfo = $modelName::getColInfo($col); |
580 | 580 | switch ($colInfo['colParams']['type']) { |
581 | - case 'select': |
|
581 | + case 'select': |
|
582 | 582 | if (empty($params['filters'][$col]['value'])) { |
583 | - continue; |
|
583 | + continue; |
|
584 | 584 | } |
585 | 585 | if (is_array($params['filters'][$col]['value'])) { |
586 | - foreach ($params['filters'][$col]['value'] as $key => $value) { |
|
586 | + foreach ($params['filters'][$col]['value'] as $key => $value) { |
|
587 | 587 | if ($value === '') { |
588 | - unset($params['filters'][$col]['value'][$key]); |
|
588 | + unset($params['filters'][$col]['value'][$key]); |
|
589 | + } |
|
589 | 590 | } |
590 | - } |
|
591 | 591 | } |
592 | 592 | if (!$params['filters'][$col]['value']) { |
593 | - continue; |
|
593 | + continue; |
|
594 | 594 | } |
595 | 595 | $queryParams['where'][] = [$col, $params['filters'][$col]['value'], is_array($params['filters'][$col]['value']) ? 'IN' : '=']; |
596 | 596 | break; |
597 | - case 'bool': |
|
597 | + case 'bool': |
|
598 | 598 | |
599 | 599 | if (empty($params['filters'][$col]['value'])) { |
600 | - continue; |
|
600 | + continue; |
|
601 | 601 | } |
602 | 602 | $queryParams['where'][] = [$col, '1']; |
603 | 603 | break; |
604 | - case 'dateTime': |
|
604 | + case 'dateTime': |
|
605 | 605 | case 'date': |
606 | 606 | if (empty($params['filters'][$col]['min']) && empty($params['filters'][$col]['max'])) { |
607 | - continue; |
|
607 | + continue; |
|
608 | 608 | } |
609 | 609 | if (!empty($params['filters'][$col]['min'])) { |
610 | - $queryParams['where'][] = [$col, $params['filters'][$col]['min'], '>=']; |
|
610 | + $queryParams['where'][] = [$col, $params['filters'][$col]['min'], '>=']; |
|
611 | 611 | } |
612 | 612 | if (!empty($params['filters'][$col]['max'])) { |
613 | - if ($colInfo['colParams']['type'] == 'dateTime' && !strpos($params['filters'][$col]['max'], ' ')) { |
|
613 | + if ($colInfo['colParams']['type'] == 'dateTime' && !strpos($params['filters'][$col]['max'], ' ')) { |
|
614 | 614 | |
615 | 615 | $date = $params['filters'][$col]['max'] . ' 23:59:59'; |
616 | - } else { |
|
616 | + } else { |
|
617 | 617 | $date = $params['filters'][$col]['max']; |
618 | - } |
|
619 | - $queryParams['where'][] = [$col, $date, '<=']; |
|
618 | + } |
|
619 | + $queryParams['where'][] = [$col, $date, '<=']; |
|
620 | 620 | } |
621 | 621 | break; |
622 | - case 'number': |
|
622 | + case 'number': |
|
623 | 623 | if (empty($params['filters'][$col]['min']) && empty($params['filters'][$col]['max'])) { |
624 | - continue; |
|
624 | + continue; |
|
625 | 625 | } |
626 | 626 | if (!empty($params['filters'][$col]['min'])) { |
627 | - $queryParams['where'][] = [$col, $params['filters'][$col]['min'], '>=']; |
|
627 | + $queryParams['where'][] = [$col, $params['filters'][$col]['min'], '>=']; |
|
628 | 628 | } |
629 | 629 | if (!empty($params['filters'][$col]['max'])) { |
630 | - $queryParams['where'][] = [$col, $params['filters'][$col]['max'], '<=']; |
|
630 | + $queryParams['where'][] = [$col, $params['filters'][$col]['max'], '<=']; |
|
631 | 631 | } |
632 | 632 | break; |
633 | - case 'email': |
|
633 | + case 'email': |
|
634 | 634 | case 'text': |
635 | 635 | case 'textarea': |
636 | 636 | case 'html': |
637 | 637 | if (empty($params['filters'][$col]['value'])) { |
638 | - continue; |
|
638 | + continue; |
|
639 | 639 | } |
640 | 640 | switch ($params['filters'][$col]['compareType']) { |
641 | - case 'contains': |
|
641 | + case 'contains': |
|
642 | 642 | $queryParams['where'][] = [$col, '%' . $params['filters'][$col]['value'] . '%', 'LIKE']; |
643 | 643 | break; |
644 | - case 'equals': |
|
644 | + case 'equals': |
|
645 | 645 | $queryParams['where'][] = [$col, $params['filters'][$col]['value']]; |
646 | 646 | break; |
647 | - case 'starts_with': |
|
647 | + case 'starts_with': |
|
648 | 648 | $queryParams['where'][] = [$col, $params['filters'][$col]['value'] . '%', 'LIKE']; |
649 | 649 | break; |
650 | - case 'ends_with': |
|
650 | + case 'ends_with': |
|
651 | 651 | $queryParams['where'][] = [$col, '%' . $params['filters'][$col]['value'], 'LIKE']; |
652 | 652 | break; |
653 | 653 | } |
654 | 654 | break; |
655 | 655 | } |
656 | - } |
|
656 | + } |
|
657 | 657 | } |
658 | 658 | if ($model && !empty($params['relation'])) { |
659 | - $count = $model->$params['relation']($queryParams); |
|
659 | + $count = $model->$params['relation']($queryParams); |
|
660 | 660 | } else { |
661 | - $count = $modelName::getCount($queryParams); |
|
661 | + $count = $modelName::getCount($queryParams); |
|
662 | 662 | } |
663 | 663 | $pages = new Pages([ |
664 | 664 | 'limit' => $this->limit, |
@@ -668,9 +668,9 @@ discard block |
||
668 | 668 | 'dataManager' => $this |
669 | 669 | ]); |
670 | 670 | return $pages; |
671 | - } |
|
671 | + } |
|
672 | 672 | |
673 | - public function preDraw($params = [], $model = null) { |
|
673 | + public function preDraw($params = [], $model = null) { |
|
674 | 674 | $this->predraw = true; |
675 | 675 | |
676 | 676 | $cols = $this->getCols(); |
@@ -678,19 +678,19 @@ discard block |
||
678 | 678 | $this->table = new Table(); |
679 | 679 | $tableCols = []; |
680 | 680 | foreach ($cols as $colName => $colOptions) { |
681 | - $tableCols[] = [ |
|
682 | - 'attributes' => ['class' => $this->managerId . '_colname_' . $colName, 'data-colname' => $colName], |
|
683 | - 'text' => !empty($colOptions['label']) ? $colOptions['label'] : $colName |
|
684 | - ]; |
|
681 | + $tableCols[] = [ |
|
682 | + 'attributes' => ['class' => $this->managerId . '_colname_' . $colName, 'data-colname' => $colName], |
|
683 | + 'text' => !empty($colOptions['label']) ? $colOptions['label'] : $colName |
|
684 | + ]; |
|
685 | 685 | } |
686 | 686 | $tableCols[] = ''; |
687 | 687 | $this->table->class .=' datamanagertable'; |
688 | 688 | $this->table->setCols($tableCols); |
689 | - } |
|
689 | + } |
|
690 | 690 | |
691 | - public function draw($params = [], $model = null) { |
|
691 | + public function draw($params = [], $model = null) { |
|
692 | 692 | if (!$this->predraw) { |
693 | - $this->preDraw($params, $model); |
|
693 | + $this->preDraw($params, $model); |
|
694 | 694 | } |
695 | 695 | \App::$cur->view->widget('Ui\DataManager/DataManager', [ |
696 | 696 | 'dataManager' => $this, |
@@ -698,58 +698,58 @@ discard block |
||
698 | 698 | 'table' => $this->table, |
699 | 699 | 'params' => $params |
700 | 700 | ]); |
701 | - } |
|
701 | + } |
|
702 | 702 | |
703 | - public function drawCategorys() { |
|
703 | + public function drawCategorys() { |
|
704 | 704 | if (!class_exists($this->modelName)) { |
705 | - return false; |
|
705 | + return false; |
|
706 | 706 | } |
707 | 707 | if (!$this->checkAccess()) { |
708 | - $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->managerName . '"'); |
|
709 | - return []; |
|
708 | + $this->drawError('you not have access to "' . $this->modelName . '" manager with name: "' . $this->managerName . '"'); |
|
709 | + return []; |
|
710 | 710 | } |
711 | 711 | $tree = new Tree(); |
712 | 712 | $tree->ul($this->managerOptions['categorys']['model'], 0, function($category) { |
713 | - $path = $category->tree_path . ($category->pk() ? $category->pk() . "/" : ''); |
|
714 | - $cleanClassName = str_replace('\\', '\\\\', get_class($category)); |
|
715 | - 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> |
|
713 | + $path = $category->tree_path . ($category->pk() ? $category->pk() . "/" : ''); |
|
714 | + $cleanClassName = str_replace('\\', '\\\\', get_class($category)); |
|
715 | + 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> |
|
716 | 716 | |
717 | 717 | <a href = '#' class ='glyphicon glyphicon-edit' onclick = 'inji.Ui.forms.popUp(\"{$cleanClassName}:{$category->pk()}\")'></a> |
718 | 718 | <a href = '#' class ='glyphicon glyphicon-remove' onclick = 'inji.Ui.dataManagers.get(this).delCategory({$category->pk()});return false;'></a>"; |
719 | 719 | }); |
720 | 720 | ?> |
721 | 721 | <?php |
722 | - } |
|
723 | - |
|
724 | - /** |
|
725 | - * Draw error message |
|
726 | - * |
|
727 | - * @param string $errorText |
|
728 | - */ |
|
729 | - public function drawError($errorText) { |
|
722 | + } |
|
723 | + |
|
724 | + /** |
|
725 | + * Draw error message |
|
726 | + * |
|
727 | + * @param string $errorText |
|
728 | + */ |
|
729 | + public function drawError($errorText) { |
|
730 | 730 | echo $errorText; |
731 | - } |
|
732 | - |
|
733 | - /** |
|
734 | - * Check access cur user to manager with name in param |
|
735 | - * |
|
736 | - * @return boolean |
|
737 | - */ |
|
738 | - public function checkAccess() { |
|
731 | + } |
|
732 | + |
|
733 | + /** |
|
734 | + * Check access cur user to manager with name in param |
|
735 | + * |
|
736 | + * @return boolean |
|
737 | + */ |
|
738 | + public function checkAccess() { |
|
739 | 739 | if (\App::$cur->Access && !\App::$cur->Access->checkAccess($this)) { |
740 | - return false; |
|
740 | + return false; |
|
741 | 741 | } |
742 | 742 | |
743 | 743 | if (!empty($this->managerOptions['options']['access']['apps']) && !in_array(\App::$cur->name, $this->managerOptions['options']['access']['apps'])) { |
744 | - return false; |
|
744 | + return false; |
|
745 | 745 | } |
746 | 746 | if (!empty($this->managerOptions['options']['access']['groups']) && in_array(\Users\User::$cur->group_id, $this->managerOptions['options']['access']['groups'])) { |
747 | - return true; |
|
747 | + return true; |
|
748 | 748 | } |
749 | 749 | if ($this->managerName == 'manager' && !\Users\User::$cur->isAdmin()) { |
750 | - return false; |
|
750 | + return false; |
|
751 | 751 | } |
752 | 752 | return true; |
753 | - } |
|
753 | + } |
|
754 | 754 | |
755 | 755 | } |