|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Ui controller |
|
5
|
|
|
* |
|
6
|
|
|
* @author Alexey Krupskiy <[email protected]> |
|
7
|
|
|
* @link http://inji.ru/ |
|
8
|
|
|
* @copyright 2015 Alexey Krupskiy |
|
9
|
|
|
* @license https://github.com/injitools/cms-Inji/blob/master/LICENSE |
|
10
|
|
|
*/ |
|
11
|
|
|
class UiController extends Controller { |
|
12
|
|
|
|
|
13
|
|
|
public function formPopUpAction() { |
|
14
|
|
|
if (strpos($_GET['item'], ':')) { |
|
15
|
|
|
$raw = explode(':', $_GET['item']); |
|
16
|
|
|
$modelName = $raw[0]; |
|
17
|
|
|
$id = $raw[1]; |
|
18
|
|
|
$model = $modelName::get($id, $modelName::index(), !empty($_GET['params']['dataManagerParams']) ? $_GET['params']['dataManagerParams'] : []); |
|
19
|
|
|
} else { |
|
20
|
|
|
$modelName = $_GET['item']; |
|
21
|
|
|
$model = new $modelName(); |
|
22
|
|
|
} |
|
23
|
|
|
$params = []; |
|
24
|
|
|
if (!empty($_GET['params'])) { |
|
25
|
|
|
$params = $_GET['params']; |
|
26
|
|
|
if (!empty($params['preset'])) { |
|
27
|
|
|
$model->setParams($params['preset']); |
|
28
|
|
|
} |
|
29
|
|
|
} |
|
30
|
|
View Code Duplication |
if (!empty($_GET['params']['dataManagerParams']['appType'])) { |
|
|
|
|
|
|
31
|
|
|
$params['appType'] = $_GET['params']['dataManagerParams']['appType']; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
$formName = !empty($_GET['formName']) ? $_GET['formName'] : (!empty($_GET['params']['formName']) ? $_GET['params']['formName'] : 'manager'); |
|
35
|
|
|
$form = new Ui\ActiveForm($model, $formName); |
|
36
|
|
|
if (!empty($_GET['_']) || !empty($_POST['_'])) { |
|
37
|
|
|
$return = new Server\Result(); |
|
38
|
|
|
ob_start(); |
|
39
|
|
|
$form->checkRequest($params, true); |
|
40
|
|
|
$_GET['item'] = get_class($form->model) . ($model->pk() ? ':' . $model->pk() : ''); |
|
41
|
|
|
$get = $_GET; |
|
42
|
|
|
if (isset($get['notSave'])) { |
|
43
|
|
|
unset($get['notSave']); |
|
44
|
|
|
} |
|
45
|
|
|
$form->action = (App::$cur->system ? '/' . App::$cur->name : '') . '/ui/formPopUp/?' . http_build_query($get); |
|
46
|
|
|
$form->draw($params, true); |
|
47
|
|
|
$return->content = ob_get_contents(); |
|
48
|
|
|
ob_end_clean(); |
|
49
|
|
|
$return->send(); |
|
50
|
|
|
} else { |
|
51
|
|
|
$form->checkRequest($params); |
|
52
|
|
|
$_GET['item'] = get_class($form->model) . ($model->pk() ? ':' . $model->pk() : ''); |
|
53
|
|
|
$get = $_GET; |
|
54
|
|
|
if (isset($get['notSave'])) { |
|
55
|
|
|
unset($get['notSave']); |
|
56
|
|
|
} |
|
57
|
|
|
$form->action = (App::$cur->system ? '/' . App::$cur->name : '') . '/ui/formPopUp/?' . http_build_query($get); |
|
58
|
|
|
$this->view->setTitle(($model && $model->pk() ? 'Изменить ' : 'Создать ') . $form->header); |
|
59
|
|
|
$this->view->page(['content' => 'form', 'data' => compact('form', 'params')]); |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function fastEditAction() { |
|
64
|
|
|
$model = $_POST['model']::get($_POST['key']); |
|
65
|
|
|
if ($model && $model->checkAccess()) { |
|
66
|
|
|
$model->$_POST['col'] = $_POST['data']; |
|
67
|
|
|
$model->save(); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function autocompleteAction() { |
|
72
|
|
|
$snippets = $this->module->getSnippets('autocomplete'); |
|
73
|
|
|
if (!is_string($_GET['snippet']) || !isset($snippets[$_GET['snippet']])) { |
|
74
|
|
|
exit(); |
|
|
|
|
|
|
75
|
|
|
} |
|
76
|
|
|
$snippet = $snippets[$_GET['snippet']]; |
|
77
|
|
|
$result = new \Server\Result(); |
|
78
|
|
|
$result->content = $snippet['find']($_GET['search'], $_GET['snippetParams']); |
|
79
|
|
|
$result->send(); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.