IpDetailMenu   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 5
dl 0
loc 55
ccs 0
cts 41
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 6 1
A run() 0 4 1
A items() 0 33 1
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\menus;
12
13
use hipanel\widgets\ModalButton;
14
use Yii;
15
use yii\helpers\Html;
16
17
class IpDetailMenu extends \hipanel\menus\AbstractDetailMenu
18
{
19
    public $model;
20
21
    /**
22
     * @var IpActionsMenu
23
     */
24
    private $ipActionsMenu;
25
26
    public function init()
27
    {
28
        $this->ipActionsMenu = IpActionsMenu::create(['model' => $this->model]);
29
30
        parent::init();
31
    }
32
33
    public function run($config = [])
34
    {
35
        return $this->ipActionsMenu->registerClientScript() . parent::run($config);
36
    }
37
38
    public function items()
39
    {
40
        $actions = $this->ipActionsMenu->items();
41
        $items = array_merge($actions, [
42
            [
43
                'label' => ModalButton::widget([
44
                    'model' => $this->model,
45
                    'scenario' => 'delete',
46
                    'button' => [
47
                        'label' => '<i class="fa fa-fw fa-trash-o"></i> ' . Yii::t('hipanel', 'Delete'),
48
                    ],
49
                    'modal' => [
50
                        'header' => Html::tag('h4', Yii::t('hipanel:hosting', 'Confirm IP address deleting')),
51
                        'headerOptions' => ['class' => 'label-danger'],
52
                        'footer' => [
53
                            'label' => Yii::t('hipanel:hosting', 'Delete IP address'),
54
                            'data-loading-text' => Yii::t('hipanel:hosting', 'Deleting IP address...'),
55
                            'class' => 'btn btn-danger',
56
                        ],
57
                    ],
58
                    'body' => Yii::t('hipanel:hosting',
59
                        'Are you sure, that you want to delete IP address {ip}? All related objects might be deleted too!',
60
                        ['ip' => Html::tag('b', $this->model->ip)]
61
                    ),
62
                ]),
63
                'encode' => false,
64
                'visible' => Yii::$app->user->can('admin'),
65
            ],
66
        ]);
67
        unset($items['view']);
68
69
        return $items;
70
    }
71
}
72