-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOption.php
More file actions
90 lines (69 loc) · 1.98 KB
/
Option.php
File metadata and controls
90 lines (69 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
namespace Onimla\HTML;
/*
require_once 'Element.class.php';
require_once 'Select.class.php';
*/
class Option extends Element {
public function __construct($value = FALSE, $text = FALSE) {
parent::__construct('option');
$this->value($value);
$this->text($text);
}
public function enable() {
return $this->removeAttr('disabled');
}
public function enabled() {
return !$this->attr('disabled');
}
public function disable() {
return $this->attr('disabled', 'disabled');
}
public function disabled() {
return (bool) $this->attr('disabled');
}
public function label($text = FALSE) {
return $this->attr('label', $text, 'encode');
}
/**
* Set the attribute <code>selected</code> to <code>true</code>
* @return Option
*/
public function select() {
return $this->attr('selected', 'selected');
}
/**
* The value for the attribute <code>selected</code>
* @return bool
*/
public function selected() {
return $this->attr('selected');
}
/**
* Unset the attribute <code>selected</code> (set to <code>fale</code>)
* @return Option
*/
public function deselect() {
return $this->removeAttr('selected');
}
public function deselected() {
return (bool) !$this->attr('selected');
}
public function value($value = FALSE) {
if (strlen($value) < 1) {
return $this->attr(__FUNCTION__);
}
return $this->attr(__FUNCTION__, $value);
}
public static function create($array, $ignoreIndexes = TRUE) {
$result = new Node;
foreach ($array as $value => $text) {
$option = $text instanceof Element ? $text : new self(FALSE, $text);
if (!$ignoreIndexes) {
$option->setAttributeValue('value', $value);
}
$result->$value = $option;
}
return $result;
}
}