Completed
Push — master ( 4964bd...7a50d9 )
by Dmitry
05:40
created

SalePricesActionsMenu::getGenerationButtons()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
rs 9.4285
cc 2
eloc 9
nc 2
nop 0
1
<?php
2
3
namespace hipanel\modules\finance\menus;
4
5
use hipanel\modules\finance\models\Sale;
6
use Yii;
7
8
/**
9
 * Class TariffActionsMenu
10
 *
11
 * @author Dmytro Naumenko <[email protected]>
12
 */
13
class SalePricesActionsMenu extends \hiqdev\yii2\menus\Menu
14
{
15
    /**
16
     * @var \hipanel\modules\finance\models\Sale
17
     */
18
    public $model;
19
20
    public function items()
21
    {
22
        return $this->getGenerationButtons();
23
    }
24
25
    protected function getGenerationButtons()
26
    {
27
        $buttons = [];
28
29
        foreach ($this->suggestionTypesByObject() as $config) {
30
            $buttons[] = [
31
                'label' => $config['label'],
32
                'icon' => $config['icon'],
33
                'url' => $this->suggestionLink($config['type']),
34
                'visible' => Yii::$app->user->can('plan.update'),
35
            ];
36
        }
37
38
        return $buttons;
39
    }
40
41
    protected function suggestionLink($type)
42
    {
43
        return ['@price/suggest', 'plan_id' => $this->model->tariff_id, 'object_id' => $this->model->object_id, 'type' => $type];
44
    }
45
46
    protected function suggestionTypesByObject()
47
    {
48
        switch ($this->model->tariff_type) {
49
            case Sale::SALE_TYPE_SERVER:
50
                return [
51
                    [
52
                        'type' => 'default',
53
                        'label' => Yii::t('hipanel.finance.price', 'Main prices'),
54
                        'icon' => 'fa-plus',
55
                    ],
56
                    [
57
                        'type' => 'parts',
58
                        'label' => Yii::t('hipanel.finance.price', 'Part prices'),
59
                        'icon' => 'fa-hdd-o',
60
                    ]
61
                ];
62
        }
63
64
        return [];
65
    }
66
}
67