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 RefuseController 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 | '*' => 'manage', |
||
37 | ], |
||
38 | ], |
||
39 | ]); |
||
40 | } |
||
41 | |||
42 | public function actions() |
||
43 | { |
||
44 | return [ |
||
45 | 'index' => [ |
||
46 | 'class' => IndexAction::class, |
||
47 | 'findOptions' => ['state' => 'new', 'class' => 'server'], |
||
48 | 'data' => function ($action) { |
||
0 ignored issues
–
show
|
|||
49 | return [ |
||
50 | 'states' => Change::getStates(), |
||
51 | ]; |
||
52 | }, |
||
53 | ], |
||
54 | 'approve' => [ |
||
55 | 'class' => SmartUpdateAction::class, |
||
56 | 'success' => Yii::t('hipanel:server', 'Server refuse was approved successfully'), |
||
57 | 'error' => Yii::t('hipanel:server', 'Error occurred during server refuse 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', 'Server refuse was rejected successfully'), |
||
83 | 'error' => Yii::t('hipanel:server', 'Error occurred during server refuse 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 | 'data' => function ($action, $data) { |
||
106 | return [ |
||
107 | 'bulkOp' => array_merge($data, [ |
||
108 | 'scenario' => 'reject', |
||
109 | 'submitButton' => Yii::t('hipanel:finance:change', 'Reject'), |
||
110 | 'submitButtonOptions' => ['class' => 'btn btn-danger'], |
||
111 | ]), |
||
112 | ]; |
||
113 | }, |
||
114 | ], |
||
115 | ]; |
||
116 | } |
||
117 | } |
||
118 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.