Completed
Push — master ( 92156c...43c17e )
by Andrii
25:32 queued 10:20
created

AggregateController::behaviors()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
dl 14
loc 14
rs 9.7998
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 View Code Duplication
class AggregateController extends CrudController
0 ignored issues
show
Duplication introduced by
This class 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...
26
{
27
    public function behaviors(): array
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
                    $dataProvider = $prefixSearch->search([
53
                        $prefixSearch->formName() => [
54
                            'aggregate' => $action->getCollection()->first->ip,
55
                        ],
56
                    ]);
57
//                    $dataProvider->query->withSuggestions();
58
59
                    return ['childPrefixesDataProvider' => $dataProvider];
60
                },
61
            ],
62
            'create' => [
63
                'class' => SmartCreateAction::class,
64
                'success' => Yii::t('hipanel.hosting.ipam', 'Aggregate was created successfully'),
65
                'error' => Yii::t('hipanel.hosting.ipam', 'An error occurred when trying to add an aggregate'),
66
            ],
67
            'update' => [
68
                'class' => SmartUpdateAction::class,
69
                'success' => Yii::t('hipanel.hosting.ipam', 'IP address was updated successfully'),
70
                'error' => Yii::t('hipanel.hosting.ipam', 'An error occurred when trying to update an aggregate'),
71
            ],
72
            'delete' => [
73
                'class' => SmartDeleteAction::class,
74
                'success' => Yii::t('hipanel.hosting.ipam', 'Aggregate was deleted successfully'),
75
            ],
76
            'validate-form' => [
77
                'class' => ValidateFormAction::class,
78
            ],
79
            'set-note' => [
80
                'class' => SmartUpdateAction::class,
81
                'success' => Yii::t('hipanel.hosting.ipam', 'Description was changed'),
82
                'error' => Yii::t('hipanel.hosting.ipam', 'Failed to change description'),
83
            ],
84
        ]);
85
    }
86
}
87