Passed
Push — master ( 3b1e15...43df0a )
by Dmytro
04:55
created

UIListOption::__construct()   B

Complexity

Conditions 4
Paths 6

Size

Total Lines 33
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 4
eloc 20
c 1
b 1
f 0
nc 6
nop 4
dl 0
loc 33
rs 8.5806
1
<?php
2
3
namespace Asymptix\ui\components;
4
5
/**
6
 * DropDown List UI component class.
7
 *
8
 * @category Asymptix PHP Framework
9
 * @author Dmytro Zarezenko <[email protected]>
10
 * @copyright (c) 2009 - 2016, Dmytro Zarezenko
11
 *
12
 * @git https://github.com/Asymptix/Framework
13
 * @license http://opensource.org/licenses/MIT
14
 */
15
class UIListOption extends \Asymptix\ui\UIComponent {
16
    /**
17
     * Default drop-down list HTML template.
18
     */
19
    const DEFAULT_TEMPLATE = "core/ui/templates/components/ui_listoption.tpl.php";
20
21
    /**
22
     * Specifies that the option should be disabled when it first loads
23
     *           (empty or 'disabled', optional).
24
     *
25
     * @var string
26
     */
27
    public $disabled = "";
28
29
    /**
30
     * Defines a label to use when using <optgroup>.
31
     *
32
     * @var string
33
     */
34
    public $label = "";
35
36
    /**
37
     * Defines the value of the option to be sent to the server.
38
     *
39
     * @var string,integer
40
     */
41
    protected $value = "";
42
43
    /**
44
     * Generate HTML of the list <option> element.
45
     *
46
     * @param string,integer $optionValue Value of the option.
0 ignored issues
show
Documentation introduced by
The doc-type string,integer could not be parsed: Expected "|" or "end of type", but got "," at position 6. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
47
     * @param mixed $option Option object, pair array or single title value.
48
     * @param string,integer $currentValue Current selected list option value (optional).
0 ignored issues
show
Documentation introduced by
The doc-type string,integer could not be parsed: Expected "|" or "end of type", but got "," at position 6. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
49
     * @param string $template HTML template of this component (optional).
50
     */
51
    public function __construct($optionValue, $option, $currentValue, $template = "") {
52
        if (empty($template)) {
53
            $template = self::DEFAULT_TEMPLATE;
54
        }
55
        if (isObject($option)) {
56
            parent::__construct(
57
                [
58
                    'value' => $option->id,
59
                    'title' => $option->title
60
                ],
61
                $template,
62
                [],
63
                $currentValue
64
            );
65
        } elseif (is_array($option)) {
66
            parent::__construct(
67
                $option,
68
                $template,
69
                [],
70
                $currentValue
71
            );
72
        } else {
73
            parent::__construct(
74
                [
75
                    'value' => $optionValue,
76
                    'title' => $option
77
                ],
78
                $template,
79
                [],
80
                $currentValue
81
            );
82
        }
83
    }
84
}
85