1 | <?php |
||
2 | |||
3 | namespace Itstructure\AdminModule\controllers; |
||
4 | |||
5 | use yii\web\NotFoundHttpException; |
||
6 | use Itstructure\AdminModule\models\{Language, LanguageSearch}; |
||
7 | |||
8 | /** |
||
9 | * Class LanguageController |
||
10 | * LanguageController implements the CRUD actions for Language model. |
||
11 | * |
||
12 | * @package Itstructure\AdminModule\controllers |
||
13 | * |
||
14 | * @author Andrey Girnik <[email protected]> |
||
15 | */ |
||
16 | class LanguageController extends CommonAdminController |
||
17 | { |
||
18 | /** |
||
19 | * Initialize. |
||
20 | */ |
||
21 | public function init() |
||
22 | { |
||
23 | $this->viewPath = '@admin/views/language'; |
||
24 | |||
25 | $this->setEditingScenarios = true; |
||
26 | |||
27 | parent::init(); |
||
28 | } |
||
29 | |||
30 | /** |
||
31 | * Set language as default. |
||
32 | * |
||
33 | * @param $languageId |
||
34 | * |
||
35 | * @return \yii\web\Response |
||
36 | * |
||
37 | * @throws NotFoundHttpException |
||
38 | */ |
||
39 | public function actionSetDefault($languageId) |
||
40 | { |
||
41 | $language = Language::findOne($languageId); |
||
42 | if (null === $language) { |
||
43 | throw new NotFoundHttpException('Language with id ' . $languageId . ' does not exist'); |
||
44 | } |
||
45 | |||
46 | $language->default = $language->default == 0 ? 1 : 0; |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
47 | $language->save(); |
||
48 | |||
49 | return $this->redirect('index'); |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * Returns Language model name. |
||
54 | * |
||
55 | * @return string |
||
56 | */ |
||
57 | protected function getModelName():string |
||
58 | { |
||
59 | return Language::class; |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * Returns LanguageSearch model name. |
||
64 | * |
||
65 | * @return string |
||
66 | */ |
||
67 | protected function getSearchModelName():string |
||
68 | { |
||
69 | return LanguageSearch::class; |
||
70 | } |
||
71 | } |
||
72 |