Completed
Push — master ( 5a0a6c...47e90b )
by Andrii
05:24
created

ClassValuesAction::run()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 23
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 14
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 23
ccs 0
cts 18
cp 0
crap 12
rs 9.0856
1
<?php
2
3
/*
4
 * HiPanel core package
5
 *
6
 * @link      https://hipanel.com/
7
 * @package   hipanel-core
8
 * @license   BSD-3-Clause
9
 * @copyright Copyright (c) 2014-2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hipanel\actions;
13
14
use hiqdev\hiart\Collection;
15
use Closure;
16
use Yii;
17
18
/**
19
 * Class ClassValuesAction.
20
 */
21
class ClassValuesAction extends Action
22
{
23
    public $valuesClass;
24
25
    public $view;
26
27
    public $model;
28
29
    public function run($id)
30
    {
31
        $this->model = $this->controller->findModel($id);
32
        $this->model->scenario = $this->scenario;
0 ignored issues
show
Bug introduced by
The property scenario does not seem to exist. Did you mean _scenario?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
33
        $request = Yii::$app->request;
34
35
        if ($request->isAjax && Yii::$app->request->isPost) {
36
37
            /// to be redone with native Action collection
38
            $this->model = (new Collection(['model' => $this->model]))->load()->first;
39
40
            $this->beforePerform();
41
            $this->model->perform('SetClassValues', [
42
                'id'     => $id,
43
                'class'  => $this->valuesClass,
44
                'values' => $this->model->dirtyAttributes,
45
            ]);
46
            Yii::$app->end();
47
        }
48
        $this->model->setAttributes($this->model->perform('GetClassValues', ['id' => $id, 'class' => $this->valuesClass]));
49
50
        return $this->controller->renderAjax($this->view, ['model' => $this->model]);
51
    }
52
}
53