]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/framework/Web/UI/WebControls/TListItem.php
0118a9178cb482468797b69a5dea9a4eca0c91ef
[bacula/bacula] / gui / baculum / framework / Web / UI / WebControls / TListItem.php
1 <?php
2 /**
3  * TListItem class file
4  *
5  * @author Qiang Xue <qiang.xue@gmail.com>
6  * @link https://github.com/pradosoft/prado
7  * @copyright Copyright &copy; 2005-2016 The PRADO Group
8  * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT
9  * @package System.Web.UI.WebControls
10  */
11
12 /**
13  * TListItem class.
14  *
15  * TListItem represents an item in a list control. Each item has a {@link setText Text}
16  * property and a {@link setValue Value} property. If either one of them is not set,
17  * it will take the value of the other property.
18  * An item can be {@link setSelected Selected} or {@link setEnabled Enabled},
19  * and it can have additional {@link getAttributes Attributes} which may be rendered
20  * if the list control supports so.
21  *
22  * @author Qiang Xue <qiang.xue@gmail.com>
23  * @package System.Web.UI.WebControls
24  * @since 3.0
25  */
26 class TListItem extends TComponent
27 {
28         /**
29          * @var TMap list of custom attributes
30          */
31         private $_attributes=null;
32         /**
33          * @var string text of the item
34          */
35         private $_text='';
36         /**
37          * @var string value of the item
38          */
39         private $_value='';
40         /**
41          * @var boolean whether the item is enabled
42          */
43         private $_enabled=true;
44         /**
45          * @var boolean whether the item is selected
46          */
47         private $_selected=false;
48
49         /**
50          * Constructor.
51          * @param string text of the item
52          * @param string value of the item
53          * @param boolean whether the item is enabled
54          * @param boolean whether the item is selected
55          */
56         public function __construct($text='',$value='',$enabled=true,$selected=false)
57         {
58                 $this->setText($text);
59                 $this->setValue($value);
60                 $this->setEnabled($enabled);
61                 $this->setSelected($selected);
62         }
63
64         /**
65          * Returns an array with the names of all variables of this object that should NOT be serialized
66          * because their value is the default one or useless to be cached for the next page loads.
67          * Reimplement in derived classes to add new variables, but remember to  also to call the parent
68          * implementation first.
69          */
70         protected function _getZappableSleepProps(&$exprops)
71         {
72                 parent::_getZappableSleepProps($exprops);
73                 if ($this->_attributes===null)
74                         $exprops[] = "\0TListItem\0_attributes";
75                 if($this->_text==='')
76                         $exprops[] = "\0TListItem\0_text";
77                 if($this->_value==='')
78                         $exprops[] = "\0TListItem\0_value";
79                 if ($this->_enabled===true)
80                         $exprops[] = "\0TListItem\0_enabled";
81                 if ($this->_selected===false)
82                         $exprops[] = "\0TListItem\0_selected";
83         }
84
85         /**
86          * @return boolean whether the item is enabled
87          */
88         public function getEnabled()
89         {
90                 return $this->_enabled;
91         }
92
93         /**
94          * @param boolean whether the item is enabled
95          */
96         public function setEnabled($value)
97         {
98                 $this->_enabled=TPropertyValue::ensureBoolean($value);
99         }
100
101         /**
102          * @return boolean whether the item is selected
103          */
104         public function getSelected()
105         {
106                 return $this->_selected;
107         }
108
109         /**
110          * @param boolean whether the item is selected
111          */
112         public function setSelected($value)
113         {
114                 $this->_selected=TPropertyValue::ensureBoolean($value);
115         }
116
117         /**
118          * @return string text of the item
119          */
120         public function getText()
121         {
122                 return $this->_text===''?$this->_value:$this->_text;
123         }
124
125         /**
126          * @param string text of the item
127          */
128         public function setText($value)
129         {
130                 $this->_text=TPropertyValue::ensureString($value);
131         }
132
133         /**
134          * @return string value of the item
135          */
136         public function getValue()
137         {
138                 return $this->_value===''?$this->_text:$this->_value;
139         }
140
141         /**
142          * @param string value of the item
143          */
144         public function setValue($value)
145         {
146                 $this->_value=TPropertyValue::ensureString($value);
147         }
148
149         /**
150          * @return TAttributeCollection custom attributes
151          */
152         public function getAttributes()
153         {
154                 if(!$this->_attributes)
155                         $this->_attributes=new TAttributeCollection;
156                 return $this->_attributes;
157         }
158
159         /**
160          * @return boolean whether the item has any custom attribute
161          */
162         public function getHasAttributes()
163         {
164                 return $this->_attributes && $this->_attributes->getCount()>0;
165         }
166
167         /**
168          * @param string name of the attribute
169          * @return boolean whether the named attribute exists
170          */
171         public function hasAttribute($name)
172         {
173                 return $this->_attributes?$this->_attributes->contains($name):false;
174         }
175
176         /**
177          * @return string the named attribute value, null if attribute does not exist
178          */
179         public function getAttribute($name)
180         {
181                 return $this->_attributes?$this->_attributes->itemAt($name):null;
182         }
183
184         /**
185          * @param string attribute name
186          * @param string value of the attribute
187          */
188         public function setAttribute($name,$value)
189         {
190                 $this->getAttributes()->add($name,$value);
191         }
192
193         /**
194          * Removes the named attribute.
195          * @param string the name of the attribute to be removed.
196          * @return string attribute value removed, empty string if attribute does not exist.
197          */
198         public function removeAttribute($name)
199         {
200                 return $this->_attributes?$this->_attributes->remove($name):null;
201         }
202 }
203