Test Failed
Push — master ( e9a009...455e4b )
by Alexey
04:25
created

Autocomplete::draw()   C

Complexity

Conditions 8
Paths 8

Size

Total Lines 33
Code Lines 24

Duplication

Lines 33
Ratio 100 %

Importance

Changes 0
Metric Value
cc 8
eloc 24
nc 8
nop 0
dl 33
loc 33
rs 5.3846
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Active form input search
5
 *
6
 * @author Alexey Krupskiy <[email protected]>
7
 * @link http://inji.ru/
8
 * @copyright 2015 Alexey Krupskiy
9
 * @license https://github.com/injitools/cms-Inji/blob/master/LICENSE
10
 */
11
12
namespace Ui\ActiveForm\Input;
13
14 View Code Duplication
class Autocomplete extends \Ui\ActiveForm\Input {
15
16
    public function draw() {
17
        $inputName = $this->colName();
18
        $inputLabel = $this->colLabel();
19
        $modelName = $this->activeForm->modelName;
20
21
        $inputOptions = [
22
            'value' => $this->value(),
23
            'disabled' => $this->readOnly(),
24
            'values' => []
25
        ];
26
        $relation = $modelName::getRelation($this->colParams['relation']);
27
        if ($relation && class_exists($relation['model']) && $inputOptions['value']) {
28
            $inputOptions['values'][$this->value()] = $relation['model']::get($inputOptions['value']);
29
        }
30
31
        if (!empty($inputOptions['values'][$this->activeForm->model->{$this->colName}]) &&
32
                is_array($inputOptions['values'][$this->activeForm->model->{$this->colName}]) &&
33
                !empty($inputOptions['values'][$this->activeForm->model->{$this->colName}]['input'])) {
34
            $aditionalCol = $inputOptions['values'][$this->activeForm->model->{$this->colName}]['input']['name'];
35
            $inputOptions['aditionalValue'] = $this->activeForm->model->$aditionalCol;
36
        }
37
38
        $preset = $this->preset();
39
40
        if ($preset !== null) {
41
            $inputOptions['disabled'] = true;
42
            $this->form->input('hidden', $inputName, '', $inputOptions);
43
            return true;
44
        }
45
        $inputOptions['inputObject'] = $this;
46
        $this->form->input('search', $inputName, $inputLabel, $inputOptions);
47
        return true;
48
    }
49
50
}
51