1: <?php
2: /**
3: * This file contains the QControlLabel class.
4: *
5: * @package Controls
6: */
7:
8: /**
9: * This class will render a 'label' HTML element
10: *
11: * @package Controls
12: * @property string $Text Text to be shown for the label
13: * @property string $ForControlId The control ID 'for' which the label is being created
14: * @property-write mixed $ForControl QControl instance which can be supplied to an instance of QControlLabel
15: * to set it as the target control for which the label will be created
16: */
17: class QControlLabel extends QControl {
18: ///////////////////////////
19: // Private Member Variables
20: ///////////////////////////
21:
22: // APPEARANCE
23: /** @var null|string The text for the label (which is going to be visible on screen) */
24: protected $strText = null;
25:
26: // BEHAVIOR
27: /** @var string The control ID of the control for which this label will be created */
28: protected $strForControlId;
29:
30: //////////
31: // Methods
32: //////////
33: public function ParsePostData() {
34: }
35:
36: /**
37: * Return the HTML for the control to be rendered
38: *
39: * @return string The HTML for the control
40: */
41: protected function GetControlHtml() {
42: $strStyle = $this->GetStyleAttributes();
43: if ($strStyle) {
44: $strStyle = sprintf('style="%s"', $strStyle);
45: }
46:
47: $strToReturn = sprintf('<label id="%s" for="%s" %s %s>%s</label>',
48: $this->strControlId,
49: $this->strForControlId,
50: $this->RenderHtmlAttributes(),
51: $strStyle,
52: $this->strText);
53:
54: return $strToReturn;
55: }
56:
57: /**
58: * Validates the control. For now, it only returns true
59: *
60: * @return bool
61: */
62: public function Validate() {
63: return true;
64: }
65:
66: /////////////////////////
67: // Public Properties: GET
68: /////////////////////////
69: /**
70: * PHP magic method to get the value of properties in the class
71: *
72: * @param string $strName Name of the property whose value we have to get
73: *
74: * @return mixed|null|string
75: * @throws Exception
76: * @throws QCallerException
77: */
78: public function __get($strName) {
79: switch ($strName) {
80: // APPEARANCE
81: case "Text":
82: return $this->strText;
83: case "ForControlId":
84: return $this->strForControlId;
85:
86: default:
87: try {
88: return parent::__get($strName);
89: } catch (QCallerException $objExc) {
90: $objExc->IncrementOffset();
91: throw $objExc;
92: }
93: }
94: }
95:
96: /////////////////////////
97: // Public Properties: SET
98: /////////////////////////
99: /**
100: * PHP magic methof to set value of properties in the class
101: *
102: * @param string $strName Name of the property
103: * @param string $mixValue Value of the property
104: *
105: * @return mixed|void
106: * @throws Exception
107: * @throws QCallerException
108: * @throws QInvalidCastException
109: */
110: public function __set($strName, $mixValue) {
111: $this->blnModified = true;
112:
113: switch ($strName) {
114: // APPEARANCE
115: case "Text":
116: try {
117: $this->strText = QType::Cast($mixValue, QType::String);
118: break;
119: } catch (QInvalidCastException $objExc) {
120: $objExc->IncrementOffset();
121: throw $objExc;
122: }
123:
124: case "ForControlId":
125: try {
126: $this->strForControlId = QType::Cast($mixValue, QType::String);
127: break;
128: } catch (QInvalidCastException $objExc) {
129: $objExc->IncrementOffset();
130: throw $objExc;
131: }
132:
133: case "ForControl":
134: try {
135: $objControl = QType::Cast($mixValue, 'QControl');
136: $this->strForControlId = QType::Cast($objControl->ControlId, QType::String);
137: break;
138: } catch (QInvalidCastException $objExc) {
139: $objExc->IncrementOffset();
140: throw $objExc;
141: }
142:
143: default:
144: try {
145: parent::__set($strName, $mixValue);
146: } catch (QCallerException $objExc) {
147: $objExc->IncrementOffset();
148: throw $objExc;
149: }
150: break;
151: }
152: }
153: }