ProfileActionsMenu::items()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 37

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 37
ccs 0
cts 37
cp 0
rs 9.328
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 6
1
<?php
2
/**
3
 * Finance module for HiPanel
4
 *
5
 * @link      https://github.com/hiqdev/hipanel-module-finance
6
 * @package   hipanel-module-finance
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\finance\menus;
12
13
use hipanel\widgets\ModalButton;
14
use Yii;
15
use yii\helpers\Html;
16
17
class ProfileActionsMenu extends \hiqdev\yii2\menus\Menu
18
{
19
    public $model;
20
21
    public function items()
22
    {
23
        return [
24
            [
25
                'label' => Yii::t('hipanel', 'Update'),
26
                'icon' => 'fa-pencil',
27
                'url' => ['@tariffprofile/update', 'id' => $this->model->id],
28
                'visible' => Yii::$app->user->can('plan.update'),
29
            ],
30
            [
31
                'label' => ModalButton::widget([
32
                    'model' => $this->model,
33
                    'scenario' => 'delete',
34
                    'button' => ['label' => '<i class="fa fa-fw fa-trash-o"></i>' . Yii::t('hipanel', 'Delete')],
35
                    'body' => Yii::t('hipanel.finance.tariffprofile', 'Tariff must be unlinked form all objects before. Are you sure you want to delete tariffprofile {name}?', ['name' => $model->name]),
0 ignored issues
show
Bug introduced by
The variable $model does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
36
                    'modal' => [
37
                        'header' => Html::tag('h4', Yii::t('hipanel:finance:tariff', 'Confirm tariff profile deleting')),
38
                        'headerOptions' => ['class' => 'label-danger'],
39
                        'footer' => [
40
                            'label' => Yii::t('hipanel.finance.tariffprofile', 'Delete tariff profile'),
41
                            'data-loading-text' => Yii::t('hipanel.finance.tariffprofile', 'Deleting tariff profile...'),
42
                            'class' => 'btn btn-danger',
43
                        ],
44
                    ],
45
                ]),
46
                'visible' => Yii::$app->user->can('plan.delete') && !$this->model->isDefault(),
47
                'encode' => false,
48
            ],
49
            'view' => [
50
                'label' => Yii::t('hipanel', 'View'),
51
                'icon' => 'fa-info',
52
                'url' => ['@tariffprofile/view', 'id' => $this->model->id],
53
                'encode' => false,
54
                'visible' => Yii::$app->user->can('plan.read'),
55
            ],
56
        ];
57
    }
58
}
59