1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Active form input select |
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
|
|
|
class Select extends \Ui\ActiveForm\Input { |
15
|
|
|
|
16
|
|
|
public function draw() { |
17
|
|
|
$inputName = $this->colName(); |
18
|
|
|
$inputLabel = $this->colLabel(); |
19
|
|
|
$inputParams = $this->colParams; |
20
|
|
|
|
21
|
|
|
$inputOptions = [ |
22
|
|
|
'value' => $this->value(), |
23
|
|
|
'disabled' => $this->readOnly(), |
24
|
|
|
'values' => \Ui\ActiveForm::getOptionsList($this->colParams, $this->activeFormParams, $this->activeForm->modelName, $inputName) |
25
|
|
|
]; |
26
|
|
|
$modelName = ''; |
27
|
|
|
switch ($inputParams['source']) { |
28
|
|
|
case 'model': |
29
|
|
|
$modelName = $inputParams['model']; |
30
|
|
|
break; |
31
|
|
|
case 'relation': |
32
|
|
|
if ($this->activeForm->modelName) { |
33
|
|
|
$itemModelName = $this->activeForm->modelName; |
34
|
|
|
$relation = $itemModelName::getRelation($inputParams['relation']); |
35
|
|
|
if ($relation['model'] && class_exists($relation['model'])) { |
36
|
|
|
$modelName = $relation['model']; |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
if (!empty($modelName)) { |
41
|
|
|
$inputOptions['createBtn'] = [ |
42
|
|
|
'text' => 'Создать элемент', |
43
|
|
|
'onclick' => 'inji.Ui.forms.popUp(\'' . addslashes($modelName) . '\',{},function(elem){' |
44
|
|
|
. 'return function(data,modal){inji.Ui.forms.submitAjax($(elem).closest(\'form\')[0], {notSave: true});}}(this))' |
45
|
|
|
]; |
46
|
|
|
} |
47
|
|
View Code Duplication |
if (!empty($inputOptions['values'][$this->activeForm->model->{$this->colName}]) && |
|
|
|
|
48
|
|
|
is_array($inputOptions['values'][$this->activeForm->model->{$this->colName}]) && |
49
|
|
|
!empty($inputOptions['values'][$this->activeForm->model->{$this->colName}]['input'])) { |
50
|
|
|
$aditionalCol = $inputOptions['values'][$this->activeForm->model->{$this->colName}]['input']['name']; |
51
|
|
|
$inputOptions['aditionalValue'] = $this->activeForm->model->$aditionalCol; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
$preset = $this->preset(); |
55
|
|
|
|
56
|
|
|
if ($preset !== null) { |
57
|
|
|
$inputOptions['disabled'] = true; |
58
|
|
|
$this->form->input('hidden', $inputName, '', $inputOptions); |
59
|
|
|
return true; |
60
|
|
|
} |
61
|
|
|
$this->form->input('select', $inputName, $inputLabel, $inputOptions); |
62
|
|
|
return true; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
} |
66
|
|
|
|
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.