Completed
Push — master ( 358339...80c3f8 )
by Dmitry
39:13 queued 24:12
created

PlanDetailMenu   A

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