PlanDetailMenu   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 6
dl 0
loc 61
ccs 0
cts 51
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A items() 0 53 4
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\helpers\Url;
14
use hipanel\modules\finance\models\Plan;
15
use hipanel\widgets\SettingsModal;
16
use Yii;
17
18
class PlanDetailMenu extends \hipanel\menus\AbstractDetailMenu
19
{
20
    /**
21
     * @var Plan
22
     */
23
    public $model;
24
25
    public function items()
26
    {
27
        $actions = PlanActionsMenu::create(['model' => $this->model])->items();
28
        $items = array_merge($actions, [
29
            'copy' => [
30
                'label' => SettingsModal::widget([
31
                    'model' => $this->model,
32
                    'title' => Yii::t('hipanel', 'Copy'),
33
                    'icon' => 'fa-copy fa-fw',
34
                    'scenario' => 'copy',
35
                    'handleSubmit' => false,
36
                ]),
37
                'encode' => false,
38
//                'visible' => !$this->model->isDeleted() && Yii::$app->user->can('plan.create'),
39
                'visible' => false,
40
            ],
41
            'delete' => [
42
                'label' => Yii::t('hipanel', 'Delete'),
43
                'icon' => 'fa-trash',
44
                'url' => ['@plan/delete', 'id' => $this->model->id],
45
                'encode' => false,
46
                'linkOptions' => [
47
                    'data' => [
48
                        'confirm' => Yii::t('hipanel', 'Are you sure you want to delete this item?'),
49
                        'method' => 'POST',
50
                        'pjax' => '0',
51
                    ],
52
                ],
53
                'visible' => \count($this->model->sales) === 0 && !$this->model->isDeleted() && Yii::$app->user->can('plan.delete'),
54
            ],
55
            'restore' => [
56
                'label' => Yii::t('hipanel.finance.plan', 'Restore'),
57
                'icon' => 'fa-refresh',
58
                'url' => ['@plan/restore'],
59
                'linkOptions' => [
60
                    'data' => [
61
                        'method' => 'POST',
62
                        'pjax' => '0',
63
                        'params' => ['selection[]' => $this->model->id],
64
                    ],
65
                ],
66
                'visible' => $this->model->isDeleted() && Yii::$app->user->can('plan.update'),
67
            ],
68
            'bills' => [
69
                'label' => Yii::t('hipanel:finance', 'Bills'),
70
                'icon' => 'fa-money',
71
                'url' => Url::toSearch('bill', ['tariff_id' => $this->model->id]),
72
            ],
73
        ]);
74
        unset($items['view']);
75
76
        return $items;
77
    }
78
}
79