|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace hipanel\modules\server\controllers; |
|
4
|
|
|
|
|
5
|
|
|
use hipanel\actions\Action; |
|
6
|
|
|
use hipanel\actions\IndexAction; |
|
7
|
|
|
use hipanel\actions\PrepareBulkAction; |
|
8
|
|
|
use hipanel\actions\RedirectAction; |
|
9
|
|
|
use hipanel\actions\SmartUpdateAction; |
|
10
|
|
|
use hipanel\base\CrudController; |
|
11
|
|
|
use hipanel\modules\server\models\Change; |
|
12
|
|
|
use Yii; |
|
13
|
|
|
use yii\base\Event; |
|
14
|
|
|
|
|
15
|
|
|
class PreOrderController extends CrudController |
|
16
|
|
|
{ |
|
17
|
|
|
public static function modelClassName() |
|
18
|
|
|
{ |
|
19
|
|
|
return Change::class; |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function actions() |
|
23
|
|
|
{ |
|
24
|
|
|
return [ |
|
25
|
|
|
'index' => [ |
|
26
|
|
|
'class' => IndexAction::class, |
|
27
|
|
|
'findOptions' => ['state' => 'new', 'class' => 'serverBuy'], |
|
28
|
|
|
'data' => function ($action) { |
|
29
|
|
|
return [ |
|
30
|
|
|
'states' => $action->controller->getStates(), |
|
31
|
|
|
]; |
|
32
|
|
|
}, |
|
33
|
|
|
], |
|
34
|
|
|
'bulk-approve' => [ |
|
35
|
|
|
'class' => SmartUpdateAction::class, |
|
36
|
|
|
'scenario' => 'approve', |
|
37
|
|
|
'success' => Yii::t('hipanel/server', 'Hosting accounts were blocked successfully'), |
|
38
|
|
|
'error' => Yii::t('hipanel/server', 'Error during the hosting accounts blocking'), |
|
39
|
|
|
'POST html' => [ |
|
40
|
|
|
'save' => true, |
|
41
|
|
|
'success' => [ |
|
42
|
|
|
'class' => RedirectAction::class, |
|
43
|
|
|
], |
|
44
|
|
|
], |
|
45
|
|
View Code Duplication |
'on beforeSave' => function (Event $event) { |
|
|
|
|
|
|
46
|
|
|
/** @var \hipanel\actions\Action $action */ |
|
47
|
|
|
$action = $event->sender; |
|
48
|
|
|
$comment = Yii::$app->request->post('comment'); |
|
49
|
|
|
if (!empty($type)) { |
|
|
|
|
|
|
50
|
|
|
foreach ($action->collection->models as $model) { |
|
51
|
|
|
$model->setAttribute('comment', $comment); |
|
52
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
}, |
|
56
|
|
|
], |
|
57
|
|
|
'bulk-approve-modal' => [ |
|
58
|
|
|
'class' => PrepareBulkAction::class, |
|
59
|
|
|
'scenario' => 'approve', |
|
60
|
|
|
'view' => '_bulkApprove', |
|
61
|
|
|
], |
|
62
|
|
|
]; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function getStates() |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->getRefs('state,change', [], 'hipanel/server'); |
|
|
|
|
|
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
} |
|
71
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.