1: <?php
2: 3: 4: 5: 6:
7: class SampleComposite extends QControl {
8:
9:
10: protected $lblMessage;
11: protected $btnIncrement;
12: protected $btnDecrement;
13:
14: protected $intValue = 0;
15: protected $blnUseAjax = false;
16: protected $strPadding = '10px';
17:
18: protected $strWidth = '100px';
19: protected $strFontSize = '36px';
20: protected $blnFontBold = true;
21: protected $strBackColor = '#cccccc';
22:
23:
24:
25: protected $blnIsBlockElement = true;
26:
27:
28: public function __construct($objParentObject, $strControlId = null) {
29:
30: try {
31: parent::__construct($objParentObject, $strControlId);
32: } catch (QCallerException $objExc) {
33: $objExc->IncrementOffset();
34: throw $objExc;
35: }
36:
37:
38:
39: $this->lblMessage = new QLabel($this);
40: $this->btnIncrement = new QButton($this);
41: $this->btnDecrement = new QButton($this);
42:
43:
44: $this->btnIncrement->Text = '>>';
45: $this->btnDecrement->Text = '<<';
46:
47:
48: $this->SetupButtonActions();
49: }
50:
51: protected function SetupButtonActions() {
52:
53: $this->btnIncrement->RemoveAllActions(QClickEvent::EventName);
54: $this->btnDecrement->RemoveAllActions(QClickEvent::EventName);
55:
56:
57:
58:
59:
60: if ($this->blnUseAjax) {
61: $this->btnIncrement->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnIncrement_Click'));
62: $this->btnDecrement->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnDecrement_Click'));
63: } else {
64: $this->btnIncrement->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnIncrement_Click'));
65: $this->btnDecrement->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnDecrement_Click'));
66: }
67: }
68:
69:
70:
71:
72: public function ParsePostData() {
73:
74: }
75:
76:
77:
78: public function Validate() {
79: return true;
80: }
81:
82:
83: protected function GetControlHtml() {
84:
85: $strStyle = $this->GetStyleAttributes();
86: if ($this->strPadding){
87: $strStyle .= sprintf('padding:%s;', $this->strPadding);
88: }
89: $strStyle = sprintf('style="%s;text-align:center;"', $strStyle);
90:
91: $strAttributes = $this->GetAttributes();
92:
93:
94: $this->lblMessage->Text = $this->intValue;
95:
96:
97: $strMessage = $this->lblMessage->Render(false);
98: $strIncrement = $this->btnIncrement->Render(false);
99: $strDecrement = $this->btnDecrement->Render(false);
100:
101:
102: return sprintf('<div id="%s" %s%s><div>%s</div><div>%s%s</div></div>', $this->strControlId, $strStyle, $strAttributes, $strMessage, $strDecrement, $strIncrement);
103: }
104:
105:
106:
107: public function btnIncrement_Click($strFormId, $strControlId, $strParameter) {
108: $this->intValue++;
109:
110:
111: $this->blnModified = true;
112: }
113:
114: public function btnDecrement_Click($strFormId, $strControlId, $strParameter) {
115: $this->intValue--;
116:
117:
118: $this->blnModified = true;
119: }
120:
121:
122: public function __get($strName) {
123: switch ($strName) {
124: case 'Value': return $this->intValue;
125: case 'Padding': return $this->strPadding;
126: case 'UseAjax': return $this->blnUseAjax;
127: default:
128: try {
129: return parent::__get($strName);
130: } catch (QCallerException $objExc) {
131: $objExc->IncrementOffset();
132: throw $objExc;
133: }
134: }
135: }
136:
137: public function __set($strName, $mixValue) {
138:
139: $this->blnModified = true;
140:
141: try {
142: switch ($strName) {
143: case 'Value': return ($this->intValue = QType::Cast($mixValue, QType::Integer));
144: case 'Padding': return ($this->strPadding = QType::Cast($mixValue, QType::String));
145: case 'UseAjax':
146: $blnToReturn = ($this->blnUseAjax = QType::Cast($mixValue, QType::Boolean));
147:
148:
149:
150: $this->SetupButtonActions();
151:
152: return $blnToReturn;
153:
154: default:
155: return (parent::__set($strName, $mixValue));
156: }
157: } catch (QCallerException $objExc) {
158: $objExc->IncrementOffset();
159: throw $objExc;
160: }
161: }
162: }
163: ?>