Completed
Push — master ( 3bd96a...d26825 )
by Klochok
12:58
created

AddressController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 4
dl 0
loc 61
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A behaviors() 0 14 1
A actions() 0 43 1
1
<?php
2
3
namespace hipanel\modules\hosting\controllers;
4
5
use hipanel\actions\IndexAction;
6
use hipanel\actions\SmartCreateAction;
7
use hipanel\actions\SmartDeleteAction;
8
use hipanel\actions\SmartUpdateAction;
9
use hipanel\actions\ValidateFormAction;
10
use hipanel\actions\ViewAction;
11
use hipanel\base\CrudController;
12
use hipanel\filters\EasyAccessControl;
13
use hipanel\modules\hosting\models\PrefixSearch;
14
use yii\helpers\ArrayHelper;
15
use Yii;
16
17
class AddressController extends CrudController
18
{
19
    public function behaviors(): array
20
    {
21
        return ArrayHelper::merge(parent::behaviors(), [
22
            [
23
                'class' => EasyAccessControl::class,
24
                'actions' => [
25
                    'create' => 'admin',
26
                    'update' => 'admin',
27
                    'delete' => 'admin',
28
                    '*' => 'ip.read',
29
                ],
30
            ],
31
        ]);
32
    }
33
34
    public function actions()
35
    {
36
        return array_merge(parent::actions(), [
37
            'index' => [
38
                'class' => IndexAction::class,
39
            ],
40
            'view' => [
41
                'class' => ViewAction::class,
42
                'data' => static function ($action) {
43
                    $prefixSearch = new PrefixSearch();
44
                    $dataProvider = $prefixSearch->search([
45
                        $prefixSearch->formName() => [
46
                            'prefix' => $action->getCollection()->first->ip,
47
                        ],
48
                    ]);
49
50
                    return ['childPrefixesDataProvider' => $dataProvider];
51
                },
52
            ],
53
            'create' => [
54
                'class' => SmartCreateAction::class,
55
                'success' => Yii::t('hipanel.hosting.ipam', 'IP Address was created successfully'),
56
                'error' => Yii::t('hipanel.hosting.ipam', 'An error occurred when trying to add a prefix'),
57
            ],
58
            'update' => [
59
                'class' => SmartUpdateAction::class,
60
                'success' => Yii::t('hipanel.hosting.ipam', 'IP Address was updated successfully'),
61
                'error' => Yii::t('hipanel.hosting.ipam', 'An error occurred when trying to update a prefix'),
62
            ],
63
            'delete' => [
64
                'class' => SmartDeleteAction::class,
65
                'success' => Yii::t('hipanel.hosting.ipam', 'IP Address was deleted successfully'),
66
            ],
67
            'validate-form' => [
68
                'class' => ValidateFormAction::class,
69
            ],
70
            'set-note' => [
71
                'class' => SmartUpdateAction::class,
72
                'success' => Yii::t('hipanel.hosting.ipam', 'Description was changed'),
73
                'error' => Yii::t('hipanel.hosting.ipam', 'Failed to change description'),
74
            ],
75
        ]);
76
    }
77
}
78