5 * @author Qiang Xue <qiang.xue@gmail.com>
6 * @link https://github.com/pradosoft/prado
7 * @copyright Copyright © 2005-2016 The PRADO Group
8 * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT
9 * @package System.Web.UI.WebControls
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.
22 * @author Qiang Xue <qiang.xue@gmail.com>
23 * @package System.Web.UI.WebControls
26 class TListItem extends TComponent
29 * @var TMap list of custom attributes
31 private $_attributes=null;
33 * @var string text of the item
37 * @var string value of the item
41 * @var boolean whether the item is enabled
43 private $_enabled=true;
45 * @var boolean whether the item is selected
47 private $_selected=false;
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
56 public function __construct($text='',$value='',$enabled=true,$selected=false)
58 $this->setText($text);
59 $this->setValue($value);
60 $this->setEnabled($enabled);
61 $this->setSelected($selected);
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.
70 protected function _getZappableSleepProps(&$exprops)
72 parent::_getZappableSleepProps($exprops);
73 if ($this->_attributes===null)
74 $exprops[] = "\0TListItem\0_attributes";
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";
86 * @return boolean whether the item is enabled
88 public function getEnabled()
90 return $this->_enabled;
94 * @param boolean whether the item is enabled
96 public function setEnabled($value)
98 $this->_enabled=TPropertyValue::ensureBoolean($value);
102 * @return boolean whether the item is selected
104 public function getSelected()
106 return $this->_selected;
110 * @param boolean whether the item is selected
112 public function setSelected($value)
114 $this->_selected=TPropertyValue::ensureBoolean($value);
118 * @return string text of the item
120 public function getText()
122 return $this->_text===''?$this->_value:$this->_text;
126 * @param string text of the item
128 public function setText($value)
130 $this->_text=TPropertyValue::ensureString($value);
134 * @return string value of the item
136 public function getValue()
138 return $this->_value===''?$this->_text:$this->_value;
142 * @param string value of the item
144 public function setValue($value)
146 $this->_value=TPropertyValue::ensureString($value);
150 * @return TAttributeCollection custom attributes
152 public function getAttributes()
154 if(!$this->_attributes)
155 $this->_attributes=new TAttributeCollection;
156 return $this->_attributes;
160 * @return boolean whether the item has any custom attribute
162 public function getHasAttributes()
164 return $this->_attributes && $this->_attributes->getCount()>0;
168 * @param string name of the attribute
169 * @return boolean whether the named attribute exists
171 public function hasAttribute($name)
173 return $this->_attributes?$this->_attributes->contains($name):false;
177 * @return string the named attribute value, null if attribute does not exist
179 public function getAttribute($name)
181 return $this->_attributes?$this->_attributes->itemAt($name):null;
185 * @param string attribute name
186 * @param string value of the attribute
188 public function setAttribute($name,$value)
190 $this->getAttributes()->add($name,$value);
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.
198 public function removeAttribute($name)
200 return $this->_attributes?$this->_attributes->remove($name):null;