1: <?php
2: 3: 4: 5: 6:
7:
8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26: class QCalendar extends QDateTimeTextBox {
27: protected $strJavaScripts = __JQUERY_EFFECTS__;
28: protected $strStyleSheets = __JQUERY_CSS__;
29: protected $datMinDate = null;
30: protected $datMaxDate = null;
31: protected $datDefaultDate = null;
32: protected $intFirstDay = null;
33: protected $mixNumberOfMonths = null;
34: protected $blnAutoSize = false;
35: protected $blnGotoCurrent = false;
36: protected $blnIsRTL = false;
37: protected $blnModified = false;
38: protected $strJqDateFormat = 'M d yy';
39: protected $blnShowButtonPanel = true;
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55: static private $mapQC2JQ = array(
56: 'MMMM' => 'MM',
57: 'MMM' => 'M',
58: 'MM' => 'mm',
59: 'M' => 'm',
60: 'DDDD' => 'DD',
61: 'DDD' => 'D',
62: 'DD' => 'dd',
63: 'D' => 'd',
64: 'YYYY' => 'yy',
65: 'YY' => 'y',
66: );
67: static private $mapJQ2QC = null;
68:
69: static public function qcFrmt($jqFrmt) {
70: if (!QCalendar::$mapJQ2QC) {
71: QCalendar::$mapJQ2QC = array_flip(QCalendar::$mapQC2JQ);
72: }
73:
74: return strtr($jqFrmt, QCalendar::$mapJQ2QC);
75: }
76:
77: static public function jqFrmt($qcFrmt) {
78: return strtr($qcFrmt, QCalendar::$mapQC2JQ);
79: }
80:
81: 82: 83:
84: static public function jsDate(QDateTime $dt) {
85: return JavaScriptHelper::toJsObject($dt);
86: }
87:
88: 89: 90: 91: 92:
93: public function Validate() {
94: return true;
95: }
96:
97: protected function makeJsProperty($strProp, $strKey) {
98: $objValue = $this->$strProp;
99: if (null === $objValue) {
100: return '';
101: }
102:
103: return $strKey . ': ' . JavaScriptHelper::toJsObject($objValue) . ', ';
104: }
105:
106: 107: 108: 109: 110:
111: public function GetControlHtml() {
112: $strToReturn = parent::GetControlHtml();
113:
114: $strJqOptions = '';
115: $strJqOptions .= $this->makeJsProperty('ShowButtonPanel', 'showButtonPanel');
116: $strJqOptions .= $this->makeJsProperty('JqDateFormat', 'dateFormat');
117: $strJqOptions .= $this->makeJsProperty('AutoSize', 'autoSize');
118: $strJqOptions .= $this->makeJsProperty('MaxDate', 'maxDate');
119: $strJqOptions .= $this->makeJsProperty('MinDate', 'minDate');
120: $strJqOptions .= $this->makeJsProperty('DefaultDate', 'defaultDate');
121: $strJqOptions .= $this->makeJsProperty('FirstDay', 'firstDay');
122: $strJqOptions .= $this->makeJsProperty('GotoCurrent', 'gotoCurrent');
123: $strJqOptions .= $this->makeJsProperty('IsRTL', 'isRTL');
124: $strJqOptions .= $this->makeJsProperty('NumberOfMonths', 'numberOfMonths');
125: if ($strJqOptions) {
126: $strJqOptions = substr($strJqOptions, 0, -2);
127: }
128:
129: QApplication::ExecuteJavaScript(
130: sprintf('jQuery("#%s").datepicker({%s})', $this->strControlId, $strJqOptions));
131:
132: return $strToReturn;
133: }
134:
135:
136:
137:
138: 139: 140: 141: 142: 143: 144: 145:
146: public function __get($strName) {
147: switch ($strName) {
148: case "MinDate" :
149: return $this->datMinDate;
150: case "MaxDate" :
151: return $this->datMaxDate;
152: case "DefaultDate" :
153: return $this->datDefaultDate;
154: case "FirstDay" :
155: return $this->intFirstDay;
156: case "GotoCurrent" :
157: return $this->blnGotoCurrent;
158: case "IsRTL" :
159: return $this->blnIsRTL;
160: case "NumberOfMonths" :
161: return $this->mixNumberOfMonths;
162: case "AutoSize" :
163: return $this->blnAutoSize;
164: case "DateFormat" :
165: return $this->strDateTimeFormat;
166: case "JqDateFormat" :
167: return $this->strJqDateFormat;
168: case "ShowButtonPanel" :
169: return $this->blnShowButtonPanel;
170: default :
171: try {
172: return parent::__get($strName);
173: } catch (QCallerException $objExc) {
174: $objExc->IncrementOffset();
175: throw $objExc;
176: }
177: }
178: }
179:
180:
181:
182:
183: 184: 185: 186: 187: 188: 189: 190: 191:
192: public function __set($strName, $mixValue) {
193: $this->blnModified = true;
194: switch ($strName) {
195: case "MinDate" :
196: try {
197: $this->datMinDate = QType::Cast($mixValue, QType::DateTime);
198: break;
199: } catch (QInvalidCastException $objExc) {
200: $objExc->IncrementOffset();
201: throw $objExc;
202: }
203: case "MaxDate" :
204: $blnMaxDate = true;
205: try {
206: $this->datMaxDate = QType::Cast($mixValue, QType::DateTime);
207: break;
208: } catch (QInvalidCastException $objExc) {
209: $objExc->IncrementOffset();
210: throw $objExc;
211: }
212: case "DefaultDate" :
213: $blnDefaultDate = true;
214: try {
215: $this->datDefaultDate = QType::Cast($mixValue, QType::DateTime);
216: break;
217: } catch (QInvalidCastException $objExc) {
218: $objExc->IncrementOffset();
219: throw $objExc;
220: }
221: case "FirstDay" :
222: $blnFirstDay = true;
223: try {
224: $this->intFirstDay = QType::Cast($mixValue, QType::Integer);
225: break;
226: } catch (QInvalidCastException $objExc) {
227: $objExc->IncrementOffset();
228: throw $objExc;
229: }
230: case "GotoCurrent" :
231: try {
232: $this->blnGotoCurrent = QType::Cast($mixValue, QType::Boolean);
233: break;
234: } catch (QInvalidCastException $objExc) {
235: $objExc->IncrementOffset();
236: throw $objExc;
237: }
238: case "IsRTL" :
239: try {
240: $this->blnIsRTL = QType::Cast($mixValue, QType::Boolean);
241: break;
242: } catch (QInvalidCastException $objExc) {
243: $objExc->IncrementOffset();
244: throw $objExc;
245: }
246: case "NumberOfMonths" :
247: $blnNumberOfMonths = true;
248: if (!is_array($mixValue) && !is_numeric($mixValue)) {
249: throw new exception('NumberOfMonths must be an integer or an array');
250: }
251: $this->mixNumberOfMonths = $mixValue;
252: break;
253: case "AutoSize" :
254: try {
255: $this->blnAutoSize = QType::Cast($mixValue, QType::Boolean);
256: break;
257: } catch (QInvalidCastException $objExc) {
258: $objExc->IncrementOffset();
259: throw $objExc;
260: }
261: case "JqDateFormat":
262: try {
263: $this->strJqDateFormat = QType::Cast($mixValue, QType::String);
264: parent::__set('DateTimeFormat', QCalendar::qcFrmt($this->strJqDateFormat));
265: break;
266: } catch (QInvalidCastException $objExc) {
267: $objExc->IncrementOffset();
268: throw $objExc;
269: }
270: case "DateTimeFormat":
271: case "DateFormat":
272: parent::__set('DateTimeFormat', $mixValue);
273: $this->strJqDateFormat = QCalendar::jqFrmt($this->strDateTimeFormat);
274: break;
275: case "ShowButtonPanel" :
276: try {
277: $this->blnShowButtonPanel = QType::Cast($mixValue, QType::Boolean);
278: break;
279: } catch (QInvalidCastException $objExc) {
280: $objExc->IncrementOffset();
281: throw $objExc;
282: }
283:
284: default :
285: try {
286: parent::__set($strName, $mixValue);
287: } catch (QCallerException $objExc) {
288: $objExc->IncrementOffset();
289: throw $objExc;
290: }
291: break;
292: }
293: }
294:
295: 296: 297: 298: 299: 300: 301: 302: 303:
304: public function AddAction($objEvent, $objAction) {
305: if ($objEvent instanceof QClickEvent) {
306: throw new QCallerException('QCalendar does not support click events');
307: }
308: parent::AddAction($objEvent, $objAction);
309: }
310: }