Completed
Push — master ( c2bc12...ef5bc2 )
by Dmitry
04:55
created

src/widgets/CreatePricesButton.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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\widgets;
12
13
use hipanel\modules\finance\models\Plan;
14
use hipanel\widgets\AjaxModal;
15
use Yii;
16
use yii\base\Widget;
17
use yii\bootstrap\Dropdown;
18
use yii\bootstrap\Html;
19
use yii\bootstrap\Modal;
20
use yii\web\View;
21
22
class CreatePricesButton extends Widget
23
{
24
    /**
25
     * @var Plan
26
     */
27
    public $model;
28
29
    public function init()
30
    {
31
        $this->view->on(View::EVENT_END_BODY, function () {
32
            echo AjaxModal::widget([
33
                'id' => 'create-prices-modal',
34
                'header' => Html::tag('h4', Yii::t('hipanel.finance.price', 'Create prices'), ['class' => 'modal-title']),
35
                'scenario' => 'create-prices',
36
                'actionUrl' => ['@plan/suggest-prices-modal', 'id' => $this->model->id],
37
                'size' => Modal::SIZE_SMALL,
38
                'toggleButton' => false,
39
            ]);
40 View Code Duplication
            if ($this->model->supportsSharedPrices()) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
41
                echo AjaxModal::widget([
42
                    'id' => 'create-shared-prices-modal',
43
                    'header' => Html::tag('h4', Yii::t('hipanel.finance.price', 'Create shared prices'),
44
                        ['class' => 'modal-title']),
45
                    'scenario' => 'create-prices',
46
                    'actionUrl' => ['@plan/suggest-shared-prices-modal', 'id' => $this->model->id],
47
                    'size' => Modal::SIZE_SMALL,
48
                    'toggleButton' => false,
49
                ]);
50
            }
51 View Code Duplication
            if ($this->model->is_grouping) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
52
                echo AjaxModal::widget([
53
                    'id' => 'create-grouping-prices-modal',
54
                    'header' => Html::tag('h4', Yii::t('hipanel.finance.price', 'Create grouping prices'), ['class' => 'modal-title']),
55
                    'scenario' => 'create-prices',
56
                    'actionUrl' => ['@plan/suggest-grouping-prices-modal', 'id' => $this->model->id],
57
                    'size' => Modal::SIZE_SMALL,
58
                    'toggleButton' => false,
59
                ]);
60
            }
61
        });
62
    }
63
64
    public function run()
65
    {
66
        return Html::tag('div', Html::a(Yii::t('hipanel.finance.price', 'Create prices') .
67
                '&nbsp;&nbsp;' .
68
                Html::tag('span', null, ['class' => 'caret']), '#', [
69
                'data-toggle' => 'dropdown', 'class' => 'dropdown-toggle btn btn-success btn-sm',
70
            ]) . Dropdown::widget([
71
                'options' => ['class' => 'pull-right'],
72
                'items' => array_filter([
73
                    [
74
                        'encode' => false,
75
                        'url' => '#',
76
                        'label' => Yii::t('hipanel.finance.price', 'Create prices'),
77
                        'linkOptions' => [
78
                            'data' => [
79
                                'toggle' => 'modal',
80
                                'target' => '#create-prices-modal',
81
                            ],
82
                        ],
83
                    ],
84
                    $this->model->supportsSharedPrices() ? [
85
                        'encode' => false,
86
                        'url' => '#',
87
                        'label' => Yii::t('hipanel.finance.price', 'Create shared prices'),
88
                        'linkOptions' => [
89
                            'data' => [
90
                                'toggle' => 'modal',
91
                                'target' => '#create-shared-prices-modal',
92
                            ],
93
                        ],
94
                    ] : null,
95
                    $this->model->is_grouping ? [
96
                        'encode' => false,
97
                        'url' => '#',
98
                        'label' => Yii::t('hipanel.finance.price', 'Create grouping prices'),
99
                        'linkOptions' => [
100
                            'data' => [
101
                                'toggle' => 'modal',
102
                                'target' => '#create-grouping-prices-modal',
103
                            ],
104
                        ],
105
                    ] : null,
106
                ]),
107
            ]), ['class' => 'dropdown']);
108
    }
109
}
110