AdminController   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
eloc 22
c 3
b 1
f 0
dl 0
loc 79
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A behaviors() 0 17 1
A beforeAction() 0 6 1
A init() 0 5 1
A getView() 0 7 2
1
<?php
2
3
namespace Itstructure\AdminModule\controllers;
4
5
use Yii;
6
use yii\web\Controller;
7
use Itstructure\AdminModule\Module;
8
use yii\filters\{VerbFilter, AccessControl};
9
10
/**
11
 * Class AdminController
12
 * Default controller for the `admin` module.
13
 *
14
 * @property Module $module
15
 * @property string $urlPrefix Url prefix for redirect and view links.
16
 * @property string $urlPrefixNeighbor Url prefix for redirect and view links of neighbor entity.
17
 *
18
 * @package Itstructure\AdminModule\controllers
19
 *
20
 * @author Andrey Girnik <[email protected]>
21
 */
22
class AdminController extends Controller
23
{
24
    /**
25
     * Url prefix for redirect and view links.
26
     *
27
     * @var string
28
     */
29
    protected $urlPrefix = '';
30
31
    /**
32
     * Url prefix for redirect and view links of neighbor entity.
33
     *
34
     * @var string
35
     */
36
    protected $urlPrefixNeighbor = '';
37
38
    /**
39
     * Initialize.
40
     *
41
     * @return void
42
     */
43
    public function init()
44
    {
45
        parent::init();
46
47
        $this->view->params['user'] = Yii::$app->user->identity;
48
    }
49
50
    /**
51
     * @param \yii\base\Action $action
52
     *
53
     * @return bool
54
     */
55
    public function beforeAction($action)
56
    {
57
        $this->view->params['urlPrefix']         = $this->urlPrefix;
58
        $this->view->params['urlPrefixNeighbor'] = $this->urlPrefixNeighbor;
59
60
        return parent::beforeAction($action);
61
    }
62
63
    /**
64
     * @inheritdoc
65
     */
66
    public function behaviors()
67
    {
68
        return [
69
            'access' => [
70
                'class' => AccessControl::class,
71
                'rules' => [
72
                    [
73
                        'allow' => true,
74
                        'roles' => $this->module->accessRoles,
75
                    ],
76
                ],
77
            ],
78
            'verbs' => [
79
                'class' => VerbFilter::class,
80
                'actions' => [
81
                    'delete' => [
82
                        'POST',
83
                    ],
84
                ],
85
            ],
86
        ];
87
    }
88
89
    /**
90
     * Give ability of configure view to the module class.
91
     *
92
     * @return \yii\base\View|\yii\web\View
93
     */
94
    public function getView()
95
    {
96
        if (method_exists($this->module, 'getView')) {
97
            return $this->module->getView();
98
        }
99
100
        return parent::getView();
101
    }
102
}
103