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

src/widgets/PrepaidAmountWidget.php (1 issue)

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\inputs\OptionsInput;
14
use hipanel\modules\finance\models\ServerResource;
15
use yii\base\Widget;
16
use yii\helpers\Html;
17
use yii\widgets\ActiveField;
18
19
final class PrepaidAmountWidget extends Widget
20
{
21
    public $model;
22
    public $attribute;
23
24
    /**
25
     * @var ActiveField
26
     */
27
    public $activeField;
28
29
    /** @var ServerResource */
30
    public $resource;
31
32
    public function init()
33
    {
34
        Html::addCssClass($this->activeField->options, 'form-group-sm');
35
    }
36
37
    public function run()
38
    {
39
        $type = $this->resource->decorator()->prepaidAmountType();
40
41
        if ($type instanceof OptionsInput) {
42
            echo $this->renderDropdownInput($type);
43
        } else {
44
            echo $this->renderTextInput($type);
45
        }
46
    }
47
48
    private function renderTextInput($type)
0 ignored issues
show
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
49
    {
50
        $this->activeField->template = "{label}\n<div class=\"input-group\">{input}</div>\n{hint}\n{error}";
51
52
        return $this->activeField->input('number', [
53
            'class' => 'form-control price-input',
54
            'autocomplete' => false,
55
            'step' => 'any',
56
            'data' => [
57
                'min-price' => $this->resource->getMinimumQuantity(),
58
            ],
59
            'value' => $this->resource->decorator()->getPrepaidQuantity(),
60
        ]);
61
    }
62
63
    private function renderDropdownInput(OptionsInput $boolean)
64
    {
65
        return $this->activeField->dropDownList($boolean->getOptions(), [
66
            'class' => 'form-control',
67
            'value' => $this->resource->decorator()->getPrepaidQuantity(),
68
        ]);
69
    }
70
}
71