1: <?php
2: /**
3: * QListItemBase.class.php contains the QListItemBase class
4: * @package Controls
5: */
6:
7: /**
8: * This base class represents an item in some kind of html item list. There are many types of possible lists, including
9: * checklists and hierarchical lists. This is the core functionality common to all of them.
10: *
11: * @package Controls
12: * @property string $Name Usually what gets displayed. Can be overridden by the Label attribute in certain situations.
13: * @property string $Value is any text that represents the value of the item (e.g. maybe a DB Id)
14: * @property-read boolean $Empty true when both $Name and $Value are null, in which case this item will be rendered with an empty value in the list control
15: * @property QListItemStyle $ItemStyle Custom HTML attributes for this particular item.
16: * @property string $Text synonym of Name. Used to store longer text with the item.
17: * @property string $Id A place to save an id for the item. It is up to the corresponding list class to use this in the object.
18: */
19: class QListItemBase extends QBaseClass {
20: ///////////////////////////
21: // Private Member Variables
22: ///////////////////////////
23: /** @var null|string Name of the Item */
24: protected $strName = null;
25: /** @var null|string Value of the Item */
26: protected $strValue = null;
27: /** @var QListItemStyle Custom attributes of the list item */
28: protected $objItemStyle;
29: /** @var string the internal id */
30: protected $strId;
31:
32:
33: /////////////////////////
34: // Methods
35: /////////////////////////
36: /**
37: * Creates a QListItem
38: *
39: * @param string $strName is the displayed Name or Text of the Item
40: * @param string|null $strValue is any text that represents the value of the ListItem (e.g. maybe a DB Id)
41: * @param null|QListItemStyle $objItemStyle is the item style. If provided here, it is referenced and shared with other items.
42: *
43: * @throws Exception|QCallerException
44: */
45: public function __construct($strName, $strValue = null, $objItemStyle = null) {
46: $this->strName = $strName;
47: $this->strValue = $strValue;
48: $this->objItemStyle = $objItemStyle;
49: }
50:
51: public function GetStyle() {
52: if (!$this->objItemStyle) {
53: $this->objItemStyle = new QListItemStyle();
54: }
55: return $this->objItemStyle;
56: }
57:
58: /**
59: * Returns the css style of the list item
60: * @deprecated
61: *
62: * @return string
63: */
64: public function GetAttributes() {
65: $strToReturn = $this->GetStyle()->GetAttributes();
66: return $strToReturn;
67: }
68:
69: /**
70: * Stub functions required for QListItemManager trait support
71: */
72: public function MarkAsModified() {}
73: public function Reindex() {}
74: public function FindItem($strId) {return null;}
75:
76: /**
77: * Return the id. Used by trait.
78: * @return string
79: */
80: public function GetId() {
81: return $this->strId;
82: }
83:
84: /**
85: * Set the Id. Used by trait.
86: * @param $strId
87: */
88: public function SetId($strId) {
89: $this->strId = $strId;
90: }
91:
92: /////////////////////////
93: // Public Properties: GET
94: /////////////////////////
95: /**
96: * PHP magic method
97: * @param string $strName
98: *
99: * @return mixed
100: * @throws Exception|QCallerException
101: */
102: public function __get($strName) {
103: switch ($strName) {
104: case "Text":
105: case "Name": return $this->strName;
106: case "Value": return $this->strValue;
107: case "ItemStyle": return $this->objItemStyle;
108: case "Empty": return $this->strValue == null && $this->strName == null;
109: case "Id": return $this->strId;
110:
111: default:
112: try {
113: return parent::__get($strName);
114: } catch (QCallerException $objExc) {
115: $objExc->IncrementOffset();
116: throw $objExc;
117: }
118: }
119: }
120:
121: /////////////////////////
122: // Public Properties: SET
123: /////////////////////////
124: /**
125: * PHP magic method
126: * @param string $strName
127: * @param string $mixValue
128: *
129: * @return mixed
130: * @throws Exception|QCallerException|QInvalidCastException
131: */
132: public function __set($strName, $mixValue) {
133: switch ($strName) {
134: case "Text":
135: case "Name":
136: try {
137: $this->strName = QType::Cast($mixValue, QType::String);
138: break;
139: } catch (QInvalidCastException $objExc) {
140: $objExc->IncrementOffset();
141: throw $objExc;
142: }
143: case "Value":
144: try {
145: $this->strValue = QType::Cast($mixValue, QType::String);
146: break;
147: } catch (QInvalidCastException $objExc) {
148: $objExc->IncrementOffset();
149: throw $objExc;
150: }
151: case "ItemStyle":
152: try {
153: $this->objItemStyle = QType::Cast($mixValue, "QListItemStyle");
154: break;
155: } catch (QInvalidCastException $objExc) {
156: $objExc->IncrementOffset();
157: throw $objExc;
158: }
159: case "Id":
160: try {
161: $this->strId = QType::Cast($mixValue, QType::String);
162: break;
163: } catch (QInvalidCastException $objExc) {
164: $objExc->IncrementOffset();
165: throw $objExc;
166: }
167: default:
168: try {
169: parent::__set($strName, $mixValue);
170: } catch (QCallerException $objExc) {
171: $objExc->IncrementOffset();
172: throw $objExc;
173: }
174: break;
175: }
176: }
177: }
178: