Completed
Push — master ( ff2b0b...f369f8 )
by Alexey
05:58
created

IndexAction::init()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 3
c 1
b 0
f 1
dl 0
loc 6
rs 10
cc 2
nc 2
nop 0
1
<?php
2
3
4
namespace common\components\maintenance\actions\backend;
5
6
use Yii;
7
use yii\base\Action;
8
use common\components\maintenance\models\FileStateForm;
9
use yii\data\ArrayDataProvider;
10
11
/**
12
 * Class IndexAction
13
 * @package common\components\maintenance\actions
14
 *
15
 * @property array $viewRenderParams
16
 */
17
class IndexAction extends Action
18
{
19
    /** @var string */
20
    public $defaultName;
21
22
    /** @var string */
23
    public $layout;
24
25
    /** @var string */
26
    public $view;
27
28
    /** @var array */
29
    public $params = [];
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function init()
35
    {
36
        parent::init();
37
38
        if ($this->defaultName === null) {
39
            $this->defaultName = Yii::t('app', 'Mode site');
40
        }
41
    }
42
43
    /**
44
     * @return string
45
     * @throws \Exception
46
     */
47
    public function run()
48
    {
49
        if ($this->layout !== null) {
50
            $this->controller->layout = $this->layout;
51
        }
52
        $model = new FileStateForm();
53
        if (($post = Yii::$app->request->post()) && $model->load($post) && $model->validate() && $model->save()) {
54
            return $this->controller->refresh();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->controller->refresh() also could return the type yii\web\Response which is incompatible with the documented return type string.
Loading history...
55
        }
56
        return $this->controller->render($this->view ?: $this->id, $this->getViewRenderParams($model));
57
    }
58
59
    /**
60
     * @param $model FileStateForm
61
     * @return array
62
     */
63
    protected function getViewRenderParams($model)
64
    {
65
        $listDataProvider = new ArrayDataProvider([
66
            'allModels' => $model->followers,
67
            'pagination' => [
68
                'pageSize' => 18
69
            ],
70
        ]);
71
72
        return [
73
            'name' => $this->defaultName,
74
            'model' => $model,
75
            'isEnable' => $model->isEnabled(),
76
            'listDataProvider' => $listDataProvider
77
        ];
78
    }
79
}
80