A Qcodo based CMS/ecommerce framework
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
3.9 KiB

13 years ago
  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. class QSampleControl extends QControl {
  16. protected $intExample;
  17. protected $strFoo;
  18. /**
  19. * If this control needs to update itself from the $_POST data, the logic to do so
  20. * will be performed in this method.
  21. */
  22. public function ParsePostData() {}
  23. /**
  24. * If this control has validation rules, the logic to do so
  25. * will be performed in this method.
  26. * @return boolean
  27. */
  28. public function Validate() {return true;}
  29. /**
  30. * Get the HTML for this Control.
  31. * @return string
  32. */
  33. public function GetControlHtml() {
  34. // Pull any Attributes
  35. $strAttributes = $this->GetAttributes();
  36. // Pull any styles
  37. if ($strStyle = $this->GetStyleAttributes())
  38. $strStyle = 'style="' . $strStyle . '"';
  39. // Return the HTML.
  40. return sprintf('<span id="%s" %s%s>Sample Control: %s - %s</span>',
  41. $this->strControlId, $strAttributes, $strStyle, $this->intExample, $this->strFoo);
  42. }
  43. /**
  44. * Constructor for this control
  45. * @param mixed $objParentObject Parent QForm or QControl that is responsible for rendering this control
  46. * @param string $strControlId optional control ID
  47. */
  48. public function __construct($objParentObject, $strControlId = null) {
  49. try {
  50. parent::__construct($objParentObject, $strControlId);
  51. } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; }
  52. // Setup Control-specific CSS and JS files to be loaded
  53. // Paths are relative to the __CSS_ASSETS__ and __JS_ASSETS__ directories
  54. // Multiple files can be specified, as well, by separating with a comma
  55. // $this->strJavaScripts = 'custom.js, ../path/to/prototype.js, etc.js';
  56. // $this->strStyleSheets = 'custom.css';
  57. // Additional Setup Performed here
  58. $this->intExample = 28;
  59. $this->strFoo = 'Hello!';
  60. }
  61. // For any JavaScript calls that need to be made whenever this control is rendered or re-rendered
  62. // public function GetEndScript() {
  63. // $strToReturn = parent::GetEndScript();
  64. // return $strToReturn;
  65. // }
  66. // For any HTML code that needs to be rendered at the END of the QForm when this control is INITIALLY rendered.
  67. // public function GetEndHtml() {
  68. // $strToReturn = parent::GetEndHtml();
  69. // return $strToReturn;
  70. // }
  71. /////////////////////////
  72. // Public Properties: GET
  73. /////////////////////////
  74. public function __get($strName) {
  75. switch ($strName) {
  76. case 'Example': return $this->intExample;
  77. case 'Foo': return $this->strFoo;
  78. default:
  79. try {
  80. return parent::__get($strName);
  81. } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; }
  82. }
  83. }
  84. /////////////////////////
  85. // Public Properties: SET
  86. /////////////////////////
  87. public function __set($strName, $mixValue) {
  88. $this->blnModified = true;
  89. switch ($strName) {
  90. case 'Example':
  91. try {
  92. return ($this->intExample = QType::Cast($mixValue, QType::Integer));
  93. } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; }
  94. case 'Foo':
  95. try {
  96. return ($this->strFoo = QType::Cast($mixValue, QType::String));
  97. } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; }
  98. default:
  99. try {
  100. return (parent::__set($strName, $mixValue));
  101. } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; }
  102. }
  103. }
  104. }
  105. ?>