Completed
Push — master ( 4f1415...383c20 )
by Dmitry
05:05
created

FormulaInput::getAttributeValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace hipanel\modules\finance\widgets;
4
5
use hipanel\modules\finance\models\Price;
6
use hiqdev\assets\autosize\AutosizeAsset;
7
use Yii;
8
use yii\helpers\BaseHtml;
9
use yii\web\NotAcceptableHttpException;
10
use yii\web\View;
11
use yii\widgets\InputWidget;
12
13
/**
14
 * Class FormulaInput
15
 *
16
 * @author Dmytro Naumenko <[email protected]>
17
 */
18
class FormulaInput extends InputWidget
19
{
20
    /** @var Price */
21
    public $model;
22
23
    /**
24
     * @var string
25
     */
26
    private $helpModalSelector;
27
28
    public function registerClientScript()
29
    {
30
        $this->registerHelpModal();
31
        AutosizeAsset::register($this->view);
32
        $this->view->registerJs("autosize($('.formula-input'));");
33
    }
34
35
    public function run()
36
    {
37
        $this->registerClientScript();
38
39
        return $this->render('formulaInput');
40
    }
41
42
    private function registerHelpModal(): void
43
    {
44
        $help = Yii::createObject(FormulaHelpModal::class);
45
        $this->helpModalSelector = '#' . $help->run();
46
    }
47
48
    public function formulaLinesCount()
49
    {
50
        return count($this->model->formulaLines());
51
    }
52
53
    /**
54
     * @return string
55
     */
56
    public function getHelpModalSelector(): string
57
    {
58
        return $this->helpModalSelector;
59
    }
60
}
61