Completed
Push — master ( e41cc1...feed29 )
by Andrey
08:18
created

ArticleController::actionView()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 10
loc 10
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
namespace app\controllers\admin;
4
5
use app\models\{Page, Article, ArticleSearch};
6
use app\traits\{AdminBeforeActionTrait, AccessTrait, AdditionFieldsTrait};
7
use Itstructure\MFUploader\interfaces\UploadModelInterface;
8
use Itstructure\AdminModule\controllers\CommonAdminController;
9
10
/**
11
 * Class ArticleController
12
 * ArticleController implements the CRUD actions for Article model.
13
 *
14
 * @package app\controllers\admin
15
 */
16 View Code Duplication
class ArticleController extends CommonAdminController
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

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.

Loading history...
17
{
18
    use AdminBeforeActionTrait, AccessTrait, AdditionFieldsTrait;
19
20
    /**
21
     * @var bool
22
     */
23
    protected $setEditingScenarios = 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
        $this->additionFields['images'] = $this->getMediaFiles(Article::tableName(), (int)$id, UploadModelInterface::FILE_TYPE_IMAGE);
49
50
        return parent::actionView($id);
51
    }
52
53
    /**
54
     * @return mixed|string|\yii\web\Response
55
     */
56
    public function actionCreate()
57
    {
58
        if (!$this->checkAccessToCreate()) {
59
            return $this->accessError();
60
        }
61
62
        $this->additionFields['pages'] = Page::getMenu();
63
        $this->additionFields['albums'] = $this->getAlbums();
64
65
        return parent::actionCreate();
66
    }
67
68
    /**
69
     * @param int|string $id
70
     *
71
     * @return string|\yii\web\Response
72
     */
73
    public function actionUpdate($id)
74
    {
75
        if (!$this->checkAccessToUpdate()) {
76
            return $this->accessError();
77
        }
78
79
        $this->additionFields['pages'] = Page::getMenu();
80
        $this->additionFields['albums'] = $this->getAlbums();
81
        $this->additionFields['images'] = $this->getMediaFiles(Article::tableName(), (int)$id, UploadModelInterface::FILE_TYPE_IMAGE);
82
83
        return parent::actionUpdate($id);
84
    }
85
86
    /**
87
     * @param int|string $id
88
     *
89
     * @return mixed|\yii\web\Response
90
     */
91
    public function actionDelete($id)
92
    {
93
        if (!$this->checkAccessToDelete()) {
94
            return $this->accessError();
95
        }
96
97
        return parent::actionDelete($id);
98
    }
99
100
    /**
101
     * Returns Product model name.
102
     *
103
     * @return string
104
     */
105
    protected function getModelName():string
106
    {
107
        return Article::class;
108
    }
109
110
    /**
111
     * Returns ProductSearch model name.
112
     *
113
     * @return string
114
     */
115
    protected function getSearchModelName():string
116
    {
117
        return ArticleSearch::class;
118
    }
119
}
120