Completed
Push — master ( 148954...101852 )
by Andrii
06:05 queued 01:50
created

PlanDetailMenu   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

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

1 Method

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