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

src/views/plan/modals/suggestPrices.php (3 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
use hipanel\modules\finance\models\Plan;
4
use hipanel\modules\finance\models\PriceSuggestionRequestForm;
5
use hipanel\modules\finance\widgets\combo\TemplatePlanCombo;
6
use hipanel\modules\server\widgets\combo\HubCombo;
7
use hipanel\modules\server\widgets\combo\ServerCombo;
8
use hiqdev\combo\StaticCombo;
9
use yii\bootstrap\ActiveForm;
10
use yii\helpers\Html;
11
12
/**
13
 * @var \yii\web\View $this
14
 * @var Plan $plan
15
 * @var PriceSuggestionRequestForm $model
16
 */
17
?>
18
19
<?php $form = ActiveForm::begin(['id' => 'create-prices', 'action' => ['@price/suggest'], 'method' => 'GET']) ?>
20
21
<?= $form->field($model, 'plan_id')->hiddenInput()->label(false) ?>
22
23
<?php
24
// TODO: think about splitting to multiple files, if files becomes monstrous.
25
// $this->render("../{$model->type}/suggestPricesModal", compact('form', 'model', 'plan'));
26
?>
27
28
<?php if ($plan->type === Plan::TYPE_SERVER): ?>
29 View Code Duplication
    <?php if ($model->isObjectPredefined()) : ?>
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...
30
        <?= $form->field($model, 'object_id')->hiddenInput()->label(false) ?>
31
    <?php else : ?>
32
        <?= $form->field($model, 'object_id')->widget(ServerCombo::class, ['primaryFilter' => 'name_like']) ?>
33
    <?php endif; ?>
34
    <?= $form->field($model, 'template_plan_id')->widget(TemplatePlanCombo::class, [
35
        'plan_id' => $plan->id,
36
        'object_input_type' => $model->isObjectPredefined() ? null : 'server/server',
37
    ]) ?>
38
    <?= $form->field($model, 'type')->widget(StaticCombo::class, [
39
        'data' => [
40
            'default' => Yii::t('hipanel.finance.suggestionTypes', 'default'),
41
            'services' => Yii::t('hipanel.finance.suggestionTypes', 'services'),
42
            'parts' => Yii::t('hipanel.finance.suggestionTypes', 'parts'),
43
        ],
44
    ]) ?>
45
<?php elseif ($plan->type === Plan::TYPE_SWITCH): ?>
46 View Code Duplication
    <?php if ($model->isObjectPredefined()) : ?>
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...
47
        <?= $form->field($model, 'object_id')->hiddenInput()->label(false) ?>
48
    <?php else : ?>
49
        <?= $form->field($model, 'object_id')->widget(HubCombo::class) ?>
50
    <?php endif; ?>
51
    <?= $form->field($model, 'template_plan_id')->widget(TemplatePlanCombo::class, [
52
        'plan_id' => $plan->id,
53
        'object_input_type' => $model->isObjectPredefined() ? null : 'server/hub',
54
    ]) ?>
55
    <?= $form->field($model, 'type')->widget(StaticCombo::class, [
56
        'data' => [
57
            'default' => Yii::t('hipanel.finance.suggestionTypes', 'default'),
58
            'services' => Yii::t('hipanel.finance.suggestionTypes', 'services'),
59
            'parts' => Yii::t('hipanel.finance.suggestionTypes', 'parts'),
60
        ],
61
    ]) ?>
62
<?php elseif ($plan->type === Plan::TYPE_TEMPLATE): ?>
63
    <?= $form->field($model, 'object_id')->hiddenInput(['value' => $model->plan_id])->label(false) ?>
64
    <?= $form->field($model, 'type')->widget(StaticCombo::class, [
65
        'data' => [
66
            'model_groups' => Yii::t('hipanel.finance.suggestionTypes', 'model_groups'),
67
            'dedicated_server' => Yii::t('hipanel.finance.suggestionTypes', 'dedicated_server'),
68
            'switch' => Yii::t('hipanel.finance.suggestionTypes', 'switch'),
69
            'v_cdn' => Yii::t('hipanel.finance.suggestionTypes', 'v_cdn'),
70
            'p_cdn' => Yii::t('hipanel.finance.suggestionTypes', 'p_cdn'),
71
        ],
72
    ]) ?>
73
<?php elseif (in_array($plan->type, [Plan::TYPE_VCDN, Plan::TYPE_PCDN], true)): ?>
74 View Code Duplication
    <?php if ($model->isObjectPredefined()) : ?>
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...
75
        <?= $form->field($model, 'object_id')->hiddenInput()->label(false) ?>
76
    <?php else : ?>
77
        <?= $form->field($model, 'object_id')->widget(ServerCombo::class, [
78
            'primaryFilter' => 'name_like',
79
            /// XXX Looks like managers need CDN tariffs to be applicable to any servers
80
            /// 'filter' => ['type' => ['format' => $plan->type === Plan::TYPE_PCDN ? 'cdnpix' : 'cdn']],
81
        ]) ?>
82
    <?php endif; ?>
83
    <?= $form->field($model, 'template_plan_id')->widget(TemplatePlanCombo::class, [
84
        'plan_id' => $plan->id,
85
        'object_input_type' => $model->isObjectPredefined() ? null : 'server/server',
86
    ]) ?>
87
    <?= $form->field($model, 'type')->widget(StaticCombo::class, [
88
        'data' => [
89
            'default' => Yii::t('hipanel.finance.suggestionTypes', 'default'),
90
        ],
91
    ]) ?>
92
<?php elseif (in_array($plan->type, [Plan::TYPE_CERTIFICATE, Plan::TYPE_DOMAIN], true)): ?>
93
    <?= $form->field($model, 'template_plan_id')->widget(TemplatePlanCombo::class, [
94
        'plan_id' => $plan->id,
95
    ]) ?>
96
    <?php $form->action = ['@plan/create-prices', 'id' => $plan->id]; ?>
97
<?php else: ?>
98
    <p class="text-center bg-warning"
99
       style="padding: 1rem;"><?= Yii::t('hipanel.finance.plan', 'This plan doesn\'t support detailed prices') ?></p>
100
<?php endif ?>
101
102
<?= Html::submitButton(Yii::t('hipanel.finance.price', 'Proceed to creation'), [
103
    'class' => 'btn btn-block btn-success',
104
]) ?>
105
106
<?php ActiveForm::end(); ?>
107