1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19:
20:
21:
22: class QHListControl extends QControl {
23:
24: use QListItemManager, QDataBinder;
25:
26:
27: protected $strTag = 'ul';
28:
29: protected $strItemTag = 'li';
30:
31: protected $objItemStyle = null;
32:
33: protected $objCrypt = null;
34:
35: protected $blnEncryptValues = true;
36:
37: 38: 39: 40: 41: 42: 43:
44: public function AddItem($mixListItemOrName, $strValue = null, $strAnchor = null) {
45: if (gettype($mixListItemOrName) == QType::Object) {
46: $objListItem = QType::Cast($mixListItemOrName, "QHListItem");
47: }
48: else {
49: $objListItem = new QHListItem($mixListItemOrName, $strValue, $strAnchor);
50: }
51:
52: $this->AddListItem ($objListItem);
53: }
54:
55: 56: 57: 58:
59: public function AddItems($objItemArray) {
60: if (!$objItemArray) return;
61:
62: if (!is_object(reset($objItemArray))) {
63: foreach ($objItemArray as $key=>$val) {
64: $this->AddItem ($key, $val);
65: }
66: } else {
67: $this->AddListItems ($objItemArray);
68: }
69: }
70:
71: 72: 73:
74: public function ParsePostData() {}
75:
76: 77: 78: 79:
80: public function Validate() {return true;}
81:
82: 83: 84: 85:
86: public function GetId() {
87: return $this->strControlId;
88: }
89:
90: 91: 92: 93: 94:
95: public function GetControlHtml() {
96: $strHtml = '';
97: if ($this->HasDataBinder()) {
98: $this->CallDataBinder();
99: }
100: if ($this->GetItemCount()) {
101: $strHtml = '';
102: foreach ($this->GetAllItems() as $objItem) {
103: $strHtml .= $this->GetItemHtml($objItem);
104: }
105:
106: $strHtml = $this->RenderTag($this->strTag, null, null, $strHtml);
107: }
108: if ($this->HasDataBinder()) {
109: $this->RemoveAllItems();
110: }
111:
112: return $strHtml;
113: }
114:
115: 116: 117: 118: 119: 120:
121: protected function GetItemHtml ($objItem) {
122: $strHtml = $this->GetItemText($objItem);
123: $strHtml .= "\n";
124: if ($objItem->GetItemCount()) {
125: $strSubHtml = '';
126: foreach ($objItem->GetAllItems() as $objSubItem) {
127: $strSubHtml .= $this->GetItemHtml($objSubItem);
128: }
129: $strTag = $objItem->Tag;
130: if (!$strTag) {
131: $strTag = $this->strTag;
132: }
133: $strHtml .= QHtml::RenderTag($strTag, $this->GetSubTagAttributes($objItem), $strSubHtml);
134: }
135: $objStyler = $this->GetItemStyler($objItem);
136: $strHtml = QHtml::RenderTag($this->strItemTag, $objStyler->RenderHtmlAttributes(), $strHtml);
137:
138: return $strHtml;
139: }
140:
141: 142: 143: 144: 145: 146:
147: protected function GetItemText ($objItem) {
148: $strHtml = QApplication::HtmlEntities($objItem->Text);
149:
150: if ($strAnchor = $objItem->Anchor) {
151: $strHtml = QHtml::RenderTag('a', ['href' => $strAnchor], $strHtml, false, true);
152: }
153: return $strHtml;
154: }
155:
156: 157: 158: 159: 160: 161: 162:
163: protected function GetItemStyler ($objItem) {
164: if ($this->objItemStyle) {
165: $objStyler = clone $this->objItemStyle;
166: }
167: else {
168: $objStyler = new QListItemStyle();
169: }
170: $objStyler->SetHtmlAttribute('id', $objItem->Id);
171:
172:
173: if ($objItem->Value) {
174: if ($this->blnEncryptValues) {
175: $strValue = $this->EncryptValue($objItem->Value);
176: } else {
177: $strValue = $objItem->Value;
178: }
179: $objStyler->SetDataAttribute('value', $strValue);
180: }
181: if ($objStyle = $objItem->ItemStyle) {
182: $objStyler->Override($objStyle);
183: }
184: return $objStyler;
185: }
186:
187: 188: 189: 190: 191: 192:
193: protected function EncryptValue($value) {
194: if (!$this->objCrypt) {
195: $this->objCrypt = new QCryptography(null, true);
196: }
197: return $this->objCrypt->Encrypt($value);
198: }
199:
200: 201: 202: 203: 204: 205:
206: public function DecryptValue ($strEncryptedValue) {
207: if (!$this->objCrypt) {
208: $this->objCrypt = new QCryptography(null, true);
209: }
210: return $this->objCrypt->Decrypt($strEncryptedValue);
211: }
212:
213: 214: 215: 216: 217:
218: protected function GetSubTagAttributes($objItem) {
219: return $objItem->GetSubTagStyler()->RenderHtmlAttributes();
220: }
221:
222:
223:
224:
225:
226: 227: 228: 229: 230: 231: 232:
233: public function __get($strName) {
234: switch ($strName) {
235:
236: case "Tag": return $this->strTag;
237: case "ItemTag": return $this->strItemTag;
238: case "EncryptValues": return $this->blnEncryptValues;
239: default:
240: try {
241: return parent::__get($strName);
242: } catch (QCallerException $objExc) {
243: $objExc->IncrementOffset();
244: throw $objExc;
245: }
246: }
247: }
248:
249:
250:
251:
252: 253: 254: 255: 256: 257: 258: 259:
260: public function __set($strName, $mixValue) {
261: switch ($strName) {
262:
263: case "Tag":
264: try {
265: $this->strTag = QType::Cast($mixValue, QType::String);
266: break;
267: } catch (QInvalidCastException $objExc) {
268: $objExc->IncrementOffset();
269: throw $objExc;
270: }
271: case "ItemTag":
272: try {
273: $this->strItemTag = QType::Cast($mixValue, QType::String);
274: break;
275: } catch (QInvalidCastException $objExc) {
276: $objExc->IncrementOffset();
277: throw $objExc;
278: }
279:
280: case "EncryptValues":
281: try {
282: $this->blnEncryptValues = QType::Cast($mixValue, QType::Boolean);
283: break;
284: } catch (QInvalidCastException $objExc) {
285: $objExc->IncrementOffset();
286: throw $objExc;
287: }
288:
289:
290: default:
291: try {
292: parent::__set($strName, $mixValue);
293: } catch (QCallerException $objExc) {
294: $objExc->IncrementOffset();
295: throw $objExc;
296: }
297: break;
298: }
299: }
300:
301: }
302:
303: