1: <?php
2: /**
3: * This file contains the QLinkButton class.
4: *
5: * @package Controls
6: */
7:
8: /**
9: * This class will render an HTML link <a href>, but will act like a Button or ImageButton.
10: * (it is a subclass of actioncontrol)
11: * Therefore, you cannot define a "URL/HREF" destination for this LinkButton. It simply links
12: * to "#". And then if a ClientAction is defined, it will execute that when clicked. If a ServerAction
13: * is defined, it will execute PostBack and execute that when clicked.
14: *
15: * @package Controls
16: *
17: * @property string $Text is the text of the Link
18: * @property string $HtmlEntities
19: */
20: class QLinkButton extends QActionControl {
21: ///////////////////////////
22: // Private Member Variables
23: ///////////////////////////
24:
25: // APPEARANCE
26: /** @var string|null The text on the button */
27: protected $strText = null;
28: /** @var bool Should htmlentities be used on this control? */
29: protected $blnHtmlEntities = true;
30:
31: //////////
32: // Methods
33: //////////
34: /**
35: * Function to return the formatted HTML for the control
36: * @return string The control's HTML
37: */
38: protected function GetControlHtml() {
39: $strStyle = $this->GetStyleAttributes();
40: if ($strStyle)
41: $strStyle = sprintf('style="%s"', $strStyle);
42:
43: $strToReturn = sprintf('<a href="#" id="%s" %s%s>%s</a>',
44: $this->strControlId,
45: $this->GetAttributes(),
46: $strStyle,
47: ($this->blnHtmlEntities) ?
48: QApplication::HtmlEntities($this->strText) :
49: $this->strText);
50:
51: return $strToReturn;
52: }
53:
54: /////////////////////////
55: // Public Properties: GET
56: /////////////////////////
57: /**
58: * The PHP __get magic method
59: * @param string $strName Name of the property
60: *
61: * @return array|bool|int|mixed|null|QControl|QForm|string
62: * @throws Exception|QCallerException
63: */
64: public function __get($strName) {
65: switch ($strName) {
66: // APPEARANCE
67: case "Text": return $this->strText;
68: case "HtmlEntities": return $this->blnHtmlEntities;
69: default:
70: try {
71: return parent::__get($strName);
72: } catch (QCallerException $objExc) {
73: $objExc->IncrementOffset();
74: throw $objExc;
75: }
76: }
77: }
78:
79: /////////////////////////
80: // Public Properties: SET
81: /////////////////////////
82: /**
83: * The PHP __set megic method implementation
84: * @param string $strName Name of the property
85: * @param string $mixValue Value of the property
86: *
87: * @throws Exception|QCallerException
88: * @throws Exception|QInvalidCastException
89: */
90: public function __set($strName, $mixValue) {
91: $this->blnModified = true;
92:
93: switch ($strName) {
94: // APPEARANCE
95: case "Text":
96: try {
97: $this->strText = QType::Cast($mixValue, QType::String);
98: break;
99: } catch (QInvalidCastException $objExc) {
100: $objExc->IncrementOffset();
101: throw $objExc;
102: }
103:
104: case "HtmlEntities":
105: try {
106: $this->blnHtmlEntities = QType::Cast($mixValue, QType::Boolean);
107: break;
108: } catch (QInvalidCastException $objExc) {
109: $objExc->IncrementOffset();
110: throw $objExc;
111: }
112:
113: default:
114: try {
115: parent::__set($strName, $mixValue);
116: } catch (QCallerException $objExc) {
117: $objExc->IncrementOffset();
118: throw $objExc;
119: }
120: break;
121: }
122: }
123: }