1: <?php
2: /**
3: * This file contains the QButtonBase class.
4: *
5: * @package Controls
6: */
7:
8: /**
9: * This class will render an HTML Button.
10: *
11: * @package Controls
12: *
13: * @property string $Text is used to display the button's text
14: * @property boolean $PrimaryButton is a boolean to specify whether or not the button is 'primary' (e.g. makes this button a "Submit" form element rather than a "Button" form element)
15: * @property boolean $HtmlEntities
16: */
17: abstract class QButtonBase extends QActionControl {
18: ///////////////////////////
19: // Private Member Variables
20: ///////////////////////////
21:
22: // APPEARANCE
23: /** @var string Text on the button */
24: protected $strText = null;
25: /** @var bool Whether or not to use Htmlentities for the control */
26: protected $blnHtmlEntities = true;
27:
28: // BEHAVIOR
29: /** @var bool Is the button a primary button (causes form submission)? */
30: protected $blnPrimaryButton = false;
31:
32: // SETTINGS
33: /**
34: * @var bool Prevent any more actions from happening once action has been taken on this control
35: * causes "event.preventDefault()" to be called on the client side
36: */
37: protected $blnActionsMustTerminate = true;
38:
39: //////////
40: // Methods
41: //////////
42: /**
43: * Return the HTML string for the control
44: * @return string The HTML string of the control
45: */
46: protected function GetControlHtml() {
47: if ($this->blnPrimaryButton) {
48: $attrOverride['type'] = "submit";
49: }
50: else {
51: $attrOverride['type'] = "button";
52: }
53: $attrOverride['name'] = $this->strControlId;
54: $strInnerHtml = $this->GetInnerHtml();
55:
56: return $this->RenderTag('button', $attrOverride, null, $strInnerHtml);
57: }
58:
59: /**
60: * Returns the html to appear between the button tags.
61: * @return string
62: */
63: protected function GetInnerHtml() {
64: return ($this->blnHtmlEntities) ? QApplication::HtmlEntities($this->strText) : $this->strText;
65: }
66:
67:
68:
69: /////////////////////////
70: // Public Properties: GET
71: /////////////////////////
72: /**
73: * PHP Magic __get method implementation
74: * @param string $strName Name of the property to be fetched
75: *
76: * @return array|bool|int|mixed|null|QControl|QForm|string
77: * @throws Exception|QCallerException
78: */
79: public function __get($strName) {
80: switch ($strName) {
81: // APPEARANCE
82: case "Text": return $this->strText;
83: case "HtmlEntities": return $this->blnHtmlEntities;
84:
85: // BEHAVIOR
86: case "PrimaryButton": return $this->blnPrimaryButton;
87:
88: default:
89: try {
90: return parent::__get($strName);
91: } catch (QCallerException $objExc) {
92: $objExc->IncrementOffset();
93: throw $objExc;
94: }
95: }
96: }
97:
98: /////////////////////////
99: // Public Properties: SET
100: /////////////////////////
101: /**
102: * PHP Magic method __set implementation for this class (QButtonBase)
103: * @param string $strName Name of the property
104: * @param string $mixValue Value of the property
105: *
106: * @return mixed
107: * @throws Exception|QCallerException
108: * @throws Exception|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 "HtmlEntities":
125: try {
126: $this->blnHtmlEntities = QType::Cast($mixValue, QType::Boolean);
127: break;
128: } catch (QInvalidCastException $objExc) {
129: $objExc->IncrementOffset();
130: throw $objExc;
131: }
132:
133: // BEHAVIOR
134: case "PrimaryButton":
135: try {
136: $this->blnPrimaryButton = QType::Cast($mixValue, QType::Boolean);
137: break;
138: } catch (QInvalidCastException $objExc) {
139: $objExc->IncrementOffset();
140: throw $objExc;
141: }
142:
143: default:
144: try {
145: parent::__set($strName, $mixValue);
146: break;
147: } catch (QCallerException $objExc) {
148: $objExc->IncrementOffset();
149: throw $objExc;
150: }
151: }
152: }
153: }