Completed
Push — master ( 78c2e1...01635f )
by Andrii
19:30 queued 15:45
created

src/controllers/PreOrderController.php (1 issue)

1
<?php
2
/**
3
 * Server module for HiPanel
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-module-server
6
 * @package   hipanel-module-server
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\server\controllers;
12
13
use hipanel\actions\IndexAction;
14
use hipanel\actions\PrepareBulkAction;
15
use hipanel\actions\RedirectAction;
16
use hipanel\actions\SmartUpdateAction;
17
use hipanel\base\CrudController;
18
use hipanel\filters\EasyAccessControl;
19
use hipanel\modules\server\models\Change;
20
use Yii;
21
use yii\base\Event;
22
23
class PreOrderController extends CrudController
24
{
25
    public static function modelClassName()
26
    {
27
        return Change::class;
28
    }
29
30
    public function behaviors()
31
    {
32
        return array_merge(parent::behaviors(), [
33
            [
34
                'class' => EasyAccessControl::class,
35
                'actions' => [
36
                    '*' => 'resell',
37
                ],
38
            ],
39
        ]);
40
    }
41
42
    public function actions()
43
    {
44
        return [
45
            'index' => [
46
                'class' => IndexAction::class,
47
                'findOptions' => ['state' => 'new', 'class' => 'serverBuy'],
48
                'data' => function ($action) {
0 ignored issues
show
The parameter $action is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

48
                'data' => function (/** @scrutinizer ignore-unused */ $action) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
49
                    return [
50
                        'states' => Change::getStates(),
51
                    ];
52
                },
53
            ],
54
            'approve' => [
55
                'class' => SmartUpdateAction::class,
56
                'success' => Yii::t('hipanel:server', 'VDS were approved successfully'),
57
                'error' => Yii::t('hipanel:server', 'Error occurred during VDS approving'),
58
                'POST html' => [
59
                    'save'    => true,
60
                    'success' => [
61
                        'class' => RedirectAction::class,
62
                    ],
63
                ],
64
                'on beforeSave' => function (Event $event) {
65
                    /** @var \hipanel\actions\Action $action */
66
                    $action = $event->sender;
67
                    $comment = Yii::$app->request->post('comment');
68
                    foreach ($action->collection->models as $model) {
69
                        $model->setAttribute('comment', $comment);
70
                    }
71
                },
72
            ],
73
            'bulk-approve-modal' => [
74
                'class' => PrepareBulkAction::class,
75
                'view' => '_bulkApprove',
76
                'findOptions' => [
77
                    'state' => Change::STATE_NEW,
78
                ],
79
            ],
80
            'reject' => [
81
                'class' => SmartUpdateAction::class,
82
                'success' => Yii::t('hipanel:server', 'VDS were rejected successfully'),
83
                'error' => Yii::t('hipanel:server', 'Error occurred during VDS rejecting'),
84
                'POST html' => [
85
                    'save'    => true,
86
                    'success' => [
87
                        'class' => RedirectAction::class,
88
                    ],
89
                ],
90
                'on beforeSave' => function (Event $event) {
91
                    /** @var \hipanel\actions\Action $action */
92
                    $action = $event->sender;
93
                    $comment = Yii::$app->request->post('comment');
94
                    foreach ($action->collection->models as $model) {
95
                        $model->setAttribute('comment', $comment);
96
                    }
97
                },
98
            ],
99
            'bulk-reject-modal' => [
100
                'class' => PrepareBulkAction::class,
101
                'view' => '_bulkReject',
102
                'findOptions' => [
103
                    'state' => Change::STATE_NEW,
104
                ],
105
            ],
106
        ];
107
    }
108
}
109