AggregateController::actions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 43

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 43
rs 9.232
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * Hosting Plugin for HiPanel
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-module-hosting
6
 * @package   hipanel-module-hosting
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\hosting\controllers;
12
13
use hipanel\actions\IndexAction;
14
use hipanel\actions\SmartCreateAction;
15
use hipanel\actions\SmartDeleteAction;
16
use hipanel\actions\SmartUpdateAction;
17
use hipanel\actions\ValidateFormAction;
18
use hipanel\actions\ViewAction;
19
use hipanel\base\CrudController;
20
use hipanel\filters\EasyAccessControl;
21
use hipanel\modules\hosting\models\PrefixSearch;
22
use yii\helpers\ArrayHelper;
23
use Yii;
24
25
class AggregateController extends CrudController
26
{
27 View Code Duplication
    public function behaviors(): array
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
28
    {
29
        return ArrayHelper::merge(parent::behaviors(), [
30
            [
31
                'class' => EasyAccessControl::class,
32
                'actions' => [
33
                    'create' => 'admin',
34
                    'update' => 'admin',
35
                    'delete' => 'admin',
36
                    '*' => 'ip.read',
37
                ],
38
            ],
39
        ]);
40
    }
41
42
    public function actions()
43
    {
44
        return array_merge(parent::actions(), [
45
            'index' => [
46
                'class' => IndexAction::class,
47
            ],
48
            'view' => [
49
                'class' => ViewAction::class,
50
                'data' => static function ($action) {
51
                    $prefixSearch = new PrefixSearch();
52
                    $childPrefixesDataProvider = $prefixSearch->search([
53
                        $prefixSearch->formName() => [
54
                            'ip_cnts_eql' => $action->getCollection()->first->ip,
55
                        ],
56
                    ]);
57
58
                    return ['childPrefixesDataProvider' => $childPrefixesDataProvider];
59
                },
60
            ],
61
            'create' => [
62
                'class' => SmartCreateAction::class,
63
                'success' => Yii::t('hipanel.hosting.ipam', 'Aggregate was created successfully'),
64
                'error' => Yii::t('hipanel.hosting.ipam', 'An error occurred when trying to add an aggregate'),
65
            ],
66
            'update' => [
67
                'class' => SmartUpdateAction::class,
68
                'success' => Yii::t('hipanel.hosting.ipam', 'IP address was updated successfully'),
69
                'error' => Yii::t('hipanel.hosting.ipam', 'An error occurred when trying to update an aggregate'),
70
            ],
71
            'delete' => [
72
                'class' => SmartDeleteAction::class,
73
                'success' => Yii::t('hipanel.hosting.ipam', 'Aggregate was deleted successfully'),
74
            ],
75
            'validate-form' => [
76
                'class' => ValidateFormAction::class,
77
            ],
78
            'set-note' => [
79
                'class' => SmartUpdateAction::class,
80
                'success' => Yii::t('hipanel.hosting.ipam', 'Description was changed'),
81
                'error' => Yii::t('hipanel.hosting.ipam', 'Failed to change description'),
82
            ],
83
        ]);
84
    }
85
}
86