1: <?php
2: /**
3: * This is a SAMPLE of a custom QControl that you could write. Think of this as a "starting point".
4: * Remember: EVERYTHING here is meant to be customized! To use, simply make a copy of this file,
5: * rename the file, and edit the renamed file. Remember to specify a control Class name which matches the
6: * name of your file. And then implement your own logic for GetControlHtml().
7: *
8: * Additionally, you can add customizable logic for any or all of the following, as well:
9: * - __construct()
10: * - ParsePostData()
11: * - Validate()
12: * - GetEndScript()
13: * - GetEndHtml()
14: *
15: * @package Controls
16: */
17: class QSampleControl extends QControl {
18: protected $intExample;
19: protected $strFoo;
20:
21: /**
22: * If this control needs to update itself from the $_POST data, the logic to do so
23: * will be performed in this method.
24: */
25: public function ParsePostData() {}
26:
27: /**
28: * If this control has validation rules, the logic to do so
29: * will be performed in this method.
30: * @return boolean
31: */
32: public function Validate() {return true;}
33:
34: /**
35: * Get the HTML for this Control.
36: * @return string
37: */
38: public function GetControlHtml() {
39: // Pull any Attributes
40: $strAttributes = $this->GetAttributes();
41:
42: // Pull any styles
43: if ($strStyle = $this->GetStyleAttributes())
44: $strStyle = 'style="' . $strStyle . '"';
45:
46: // Return the HTML.
47: return sprintf('<span id="%s" %s%s>Sample Control: %s - %s</span>',
48: $this->strControlId, $strAttributes, $strStyle, $this->intExample, $this->strFoo);
49: }
50:
51: /**
52: * Constructor for this control
53: * @param mixed $objParentObject Parent QForm or QControl that is responsible for rendering this control
54: * @param string $strControlId optional control ID
55: */
56: public function __construct($objParentObject, $strControlId = null) {
57: try {
58: parent::__construct($objParentObject, $strControlId);
59: } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; }
60:
61: // Setup Control-specific CSS and JS files to be loaded
62: // Paths are relative to the __CSS_ASSETS__ and __JS_ASSETS__ directories
63: // Multiple files can be specified, as well, by separating with a comma
64: // $this->strJavaScripts = 'custom.js, ../path/to/prototype.js, etc.js';
65: // $this->strStyleSheets = 'custom.css';
66:
67: // Additional Setup Performed here
68: $this->intExample = 28;
69: $this->strFoo = 'Hello!';
70: }
71:
72: // For any JavaScript calls that need to be made whenever this control is rendered or re-rendered
73: // public function GetEndScript() {
74: // $strToReturn = parent::GetEndScript();
75: // return $strToReturn;
76: // }
77:
78: // For any HTML code that needs to be rendered at the END of the QForm when this control is INITIALLY rendered.
79: // public function GetEndHtml() {
80: // $strToReturn = parent::GetEndHtml();
81: // return $strToReturn;
82: // }
83:
84: /////////////////////////
85: // Public Properties: GET
86: /////////////////////////
87: public function __get($strName) {
88: switch ($strName) {
89: case 'Example': return $this->intExample;
90: case 'Foo': return $this->strFoo;
91:
92: default:
93: try {
94: return parent::__get($strName);
95: } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; }
96: }
97: }
98:
99: /////////////////////////
100: // Public Properties: SET
101: /////////////////////////
102: public function __set($strName, $mixValue) {
103: $this->blnModified = true;
104:
105: switch ($strName) {
106:
107: case 'Example':
108: try {
109: return ($this->intExample = QType::Cast($mixValue, QType::Integer));
110: } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; }
111: case 'Foo':
112: try {
113: return ($this->strFoo = QType::Cast($mixValue, QType::String));
114: } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; }
115:
116: default:
117: try {
118: return (parent::__set($strName, $mixValue));
119: } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; }
120: }
121: }
122: }