Passed
Push — v5 ( e348bf...8a8f01 )
by Alexey
06:35
created

UiController   A

Complexity

Total Complexity 24

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 70
rs 10
c 0
b 0
f 0
wmc 24

3 Methods

Rating   Name   Duplication   Size   Complexity  
F formPopUpAction() 0 48 18
A autocompleteAction() 0 9 3
A fastEditAction() 0 5 3
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 {
0 ignored issues
show
Bug introduced by
The type Controller was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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
        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
            $this->view->widget('msgList');
46
            $form->action = (App::$cur->system ? '/' . App::$cur->name : '') . '/ui/formPopUp/?' . http_build_query($get);
47
            $form->draw($params, true);
48
            $return->content = ob_get_contents();
49
            ob_end_clean();
50
            $return->send();
51
        } else {
52
            $form->checkRequest($params);
53
            $_GET['item'] = get_class($form->model) . ($model->pk() ? ':' . $model->pk() : '');
54
            $get = $_GET;
55
            if (isset($get['notSave'])) {
56
                unset($get['notSave']);
57
            }
58
            $form->action = (App::$cur->system ? '/' . App::$cur->name : '') . '/ui/formPopUp/?' . http_build_query($get);
59
            $this->view->setTitle(($model && $model->pk() ? 'Изменить ' : 'Создать ') . $form->header);
60
            $this->view->page(['content' => 'form', 'data' => compact('form', 'params')]);
61
        }
62
    }
63
64
    public function fastEditAction() {
65
        $model = $_POST['model']::get($_POST['key']);
66
        if ($model && $model->checkAccess()) {
67
            $model->{$_POST['col']} = $_POST['data'];
68
            $model->save();
69
        }
70
    }
71
72
    public function autocompleteAction() {
73
        $snippets = $this->module->getSnippets('autocomplete');
74
        if (!is_string($_GET['snippet']) || !isset($snippets[$_GET['snippet']])) {
75
            exit();
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
76
        }
77
        $snippet = $snippets[$_GET['snippet']];
78
        $result = new \Server\Result();
79
        $result->content = $snippet['find']($_GET['search'], $_GET['snippetParams']);
80
        $result->send();
81
    }
82
}
83