Passed
Push — master ( fe7b3f...22651e )
by Andrey
08:30
created

PageController   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 111
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 27
c 0
b 0
f 0
dl 0
loc 111
rs 10
wmc 15

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getAdditionFields() 0 12 3
A actionDelete() 0 7 2
A actionView() 0 7 2
A actionUpdate() 0 7 2
A getSearchModelName() 0 3 1
A actionCreate() 0 7 2
A getModelName() 0 3 1
A actionIndex() 0 7 2
1
<?php
2
3
namespace app\controllers\admin;
4
5
use app\models\{Page, PageSearch};
6
use app\traits\{LanguageTrait, AdminBeforeActionTrait, AccessTrait};
7
use Itstructure\MFUploader\models\album\Album;
8
use Itstructure\AdminModule\controllers\CommonAdminController;
9
10
/**
11
 * Class PageController
12
 * PageController implements the CRUD actions for Page model.
13
 *
14
 * @package app\controllers\admin
15
 */
16
class PageController extends CommonAdminController
17
{
18
    use LanguageTrait, AdminBeforeActionTrait, AccessTrait;
0 ignored issues
show
Bug introduced by
The trait app\traits\LanguageTrait requires the property $request which is not provided by app\controllers\admin\PageController.
Loading history...
introduced by
The trait app\traits\AdminBeforeActionTrait requires some properties which are not provided by app\controllers\admin\PageController: $request, $controller
Loading history...
Bug introduced by
The trait app\traits\AccessTrait requires the property $user which is not provided by app\controllers\admin\PageController.
Loading history...
19
20
    /**
21
     * @var bool
22
     */
23
    protected $isMultilanguage = true;
24
25
    /**
26
     * @return mixed|string
27
     */
28
    public function actionIndex()
29
    {
30
        if (!$this->checkAccessToIndex()) {
31
            return $this->accessError();
32
        }
33
34
        return parent::actionIndex();
35
    }
36
37
    /**
38
     * @param int|string $id
39
     *
40
     * @return mixed
41
     */
42
    public function actionView($id)
43
    {
44
        if (!$this->checkAccessToView()) {
45
            return $this->accessError();
46
        }
47
48
        return parent::actionView($id);
49
    }
50
51
    /**
52
     * @return mixed|string|\yii\web\Response
53
     */
54
    public function actionCreate()
55
    {
56
        if (!$this->checkAccessToCreate()) {
57
            return $this->accessError();
58
        }
59
60
        return parent::actionCreate();
61
    }
62
63
    /**
64
     * @param int|string $id
65
     *
66
     * @return string|\yii\web\Response
67
     */
68
    public function actionUpdate($id)
69
    {
70
        if (!$this->checkAccessToUpdate()) {
71
            return $this->accessError();
72
        }
73
74
        return parent::actionUpdate($id);
75
    }
76
77
    /**
78
     * @param int|string $id
79
     *
80
     * @return mixed|\yii\web\Response
81
     */
82
    public function actionDelete($id)
83
    {
84
        if (!$this->checkAccessToDelete()) {
85
            return $this->accessError();
86
        }
87
88
        return parent::actionDelete($id);
89
    }
90
91
    /**
92
     * Get addition fields for the view template.
93
     * @return array
94
     */
95
    protected function getAdditionFields(): array
96
    {
97
        if ($this->action->id == 'create' || $this->action->id == 'update') {
98
            return [
99
                'pages' => Page::getMenu(),
100
                'albums' => Album::find()->select([
101
                    'id', 'title'
102
                ])->all()
103
            ];
104
        }
105
106
        return $this->additionFields;
107
    }
108
109
    /**
110
     * Returns Page model name.
111
     *
112
     * @return string
113
     */
114
    protected function getModelName():string
115
    {
116
        return Page::class;
117
    }
118
119
    /**
120
     * Returns PageSearch model name.
121
     *
122
     * @return string
123
     */
124
    protected function getSearchModelName():string
125
    {
126
        return PageSearch::class;
127
    }
128
}
129