itstructure /
yii2-template-multilanguage
| 1 | <?php |
||
| 2 | |||
| 3 | namespace app\controllers\admin; |
||
| 4 | |||
| 5 | use app\models\{Page, Article, ArticleSearch}; |
||
| 6 | use app\traits\{LanguageTrait, 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 | class ArticleController extends CommonAdminController |
||
| 17 | { |
||
| 18 | use LanguageTrait, AdminBeforeActionTrait, AccessTrait, AdditionFieldsTrait; |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 19 | |||
| 20 | /** |
||
| 21 | * @var bool |
||
| 22 | */ |
||
| 23 | protected $isMultilanguage = true; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var bool |
||
| 27 | */ |
||
| 28 | protected $setEditingScenarios = true; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @return mixed|string |
||
| 32 | */ |
||
| 33 | public function actionIndex() |
||
| 34 | { |
||
| 35 | if (!$this->checkAccessToIndex()) { |
||
| 36 | return $this->accessError(); |
||
| 37 | } |
||
| 38 | |||
| 39 | return parent::actionIndex(); |
||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @param int|string $id |
||
| 44 | * |
||
| 45 | * @return mixed |
||
| 46 | */ |
||
| 47 | public function actionView($id) |
||
| 48 | { |
||
| 49 | if (!$this->checkAccessToView()) { |
||
| 50 | return $this->accessError(); |
||
| 51 | } |
||
| 52 | |||
| 53 | $this->additionFields['images'] = $this->getMediaFiles(Article::tableName(), (int)$id, UploadModelInterface::FILE_TYPE_IMAGE); |
||
| 54 | |||
| 55 | return parent::actionView($id); |
||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @return mixed|string|\yii\web\Response |
||
| 60 | */ |
||
| 61 | public function actionCreate() |
||
| 62 | { |
||
| 63 | if (!$this->checkAccessToCreate()) { |
||
| 64 | return $this->accessError(); |
||
| 65 | } |
||
| 66 | |||
| 67 | $this->additionFields['pages'] = Page::getMenu(); |
||
| 68 | $this->additionFields['albums'] = $this->getAlbums(); |
||
| 69 | |||
| 70 | return parent::actionCreate(); |
||
| 71 | } |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @param int|string $id |
||
| 75 | * |
||
| 76 | * @return string|\yii\web\Response |
||
| 77 | */ |
||
| 78 | public function actionUpdate($id) |
||
| 79 | { |
||
| 80 | if (!$this->checkAccessToUpdate()) { |
||
| 81 | return $this->accessError(); |
||
| 82 | } |
||
| 83 | |||
| 84 | $this->additionFields['pages'] = Page::getMenu(); |
||
| 85 | $this->additionFields['albums'] = $this->getAlbums(); |
||
| 86 | $this->additionFields['images'] = $this->getMediaFiles(Article::tableName(), (int)$id, UploadModelInterface::FILE_TYPE_IMAGE); |
||
| 87 | |||
| 88 | return parent::actionUpdate($id); |
||
| 89 | } |
||
| 90 | |||
| 91 | /** |
||
| 92 | * @param int|string $id |
||
| 93 | * |
||
| 94 | * @return mixed|\yii\web\Response |
||
| 95 | */ |
||
| 96 | public function actionDelete($id) |
||
| 97 | { |
||
| 98 | if (!$this->checkAccessToDelete()) { |
||
| 99 | return $this->accessError(); |
||
| 100 | } |
||
| 101 | |||
| 102 | return parent::actionDelete($id); |
||
| 103 | } |
||
| 104 | |||
| 105 | /** |
||
| 106 | * Returns Article model name. |
||
| 107 | * |
||
| 108 | * @return string |
||
| 109 | */ |
||
| 110 | protected function getModelName():string |
||
| 111 | { |
||
| 112 | return Article::class; |
||
| 113 | } |
||
| 114 | |||
| 115 | /** |
||
| 116 | * Returns ArticleSearch model name. |
||
| 117 | * |
||
| 118 | * @return string |
||
| 119 | */ |
||
| 120 | protected function getSearchModelName():string |
||
| 121 | { |
||
| 122 | return ArticleSearch::class; |
||
| 123 | } |
||
| 124 | } |
||
| 125 |