PageRenderTime 40ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/sgl/includes/qcubed/_core/base_controls/QRadioButton.class.php

http://logisticsouth.googlecode.com/
PHP | 281 lines | 205 code | 38 blank | 38 comment | 28 complexity | 4630bd57eec6f04179661379d46c54e7 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0
  1. <?php
  2. /**
  3. * This file contains the QRadioButton class.
  4. *
  5. * @package Controls
  6. */
  7. /**
  8. * This class will render an HTML Radio button.
  9. *
  10. * @package Controls
  11. *
  12. * @property string $Text is used to display text that is displayed next to the radio. The text is rendered as an html "Label For" the radio
  13. * @property string $TextAlign specifies if "Text" should be displayed to the left or to the right of the radio.
  14. * @property string $GroupName assigns the radio button into a radio button group (optional) so that no more than one radio in that group may be selected at a time.
  15. * @property boolean $HtmlEntities
  16. * @property boolean $Checked specifices whether or not the radio is selected
  17. */
  18. class QRadioButton extends QControl {
  19. ///////////////////////////
  20. // Private Member Variables
  21. ///////////////////////////
  22. // APPEARANCE
  23. protected $strText = null;
  24. protected $strTextAlign = QTextAlign::Right;
  25. // BEHAVIOR
  26. protected $strGroupName = null;
  27. protected $blnHtmlEntities = true;
  28. // MISC
  29. protected $blnChecked = false;
  30. //////////
  31. // Methods
  32. //////////
  33. public function ParsePostData() {
  34. if ($this->objForm->IsCheckableControlRendered($this->strControlId)) {
  35. if (QApplication::$RequestMode == QRequestMode::Ajax) {
  36. if ((array_key_exists($this->strControlId, $_POST)) && ($_POST[$this->strControlId]))
  37. $this->blnChecked = true;
  38. else
  39. $this->blnChecked = false;
  40. } else {
  41. if ($this->strGroupName)
  42. $strName = $this->strGroupName;
  43. else
  44. $strName = $this->strControlId;
  45. if (array_key_exists($strName, $_POST)) {
  46. if ($_POST[$strName] == $this->strControlId)
  47. $this->blnChecked = true;
  48. else
  49. $this->blnChecked = false;
  50. } else {
  51. $this->blnChecked = false;
  52. }
  53. }
  54. }
  55. }
  56. public function GetJavaScriptAction() {
  57. return "onclick";
  58. }
  59. protected function GetControlHtml() {
  60. if (!$this->blnEnabled)
  61. $strDisabled = 'disabled="disabled" ';
  62. else
  63. $strDisabled = "";
  64. if ($this->intTabIndex)
  65. $strTabIndex = sprintf('tabindex="%s" ', $this->intTabIndex);
  66. else
  67. $strTabIndex = "";
  68. if ($this->strToolTip)
  69. $strToolTip = sprintf('title="%s" ', $this->strToolTip);
  70. else
  71. $strToolTip = "";
  72. if ($this->strCssClass)
  73. $strCssClass = sprintf('class="%s" ', $this->strCssClass);
  74. else
  75. $strCssClass = "";
  76. if ($this->strAccessKey)
  77. $strAccessKey = sprintf('accesskey="%s" ', $this->strAccessKey);
  78. else
  79. $strAccessKey = "";
  80. if ($this->blnChecked)
  81. $strChecked = 'checked="checked"';
  82. else
  83. $strChecked = "";
  84. if ($this->strGroupName)
  85. $strGroupName = $this->strGroupName;
  86. else
  87. $strGroupName = $this->strControlId;
  88. $strStyle = $this->GetStyleAttributes();
  89. if (strlen($strStyle) > 0)
  90. $strStyle = sprintf('style="%s" ', $strStyle);
  91. $strCustomAttributes = $this->GetCustomAttributes();
  92. $strActions = $this->GetActionAttributes();
  93. if (strlen($this->strText)) {
  94. $this->blnIsBlockElement = true;
  95. if ($this->strTextAlign == QTextAlign::Left) {
  96. $strToReturn = sprintf('<span %s%s%s%s%s><label for="%s">%s</label><input type="radio" id="%s" name="%s" value="%s" %s%s%s%s%s /></span>',
  97. $strCssClass,
  98. $strToolTip,
  99. $strStyle,
  100. $strCustomAttributes,
  101. $strDisabled,
  102. $this->strControlId,
  103. ($this->blnHtmlEntities) ? QApplication::HtmlEntities($this->strText) : $this->strText,
  104. $this->strControlId,
  105. $strGroupName,
  106. $this->strControlId,
  107. $strDisabled,
  108. $strChecked,
  109. $strActions,
  110. $strAccessKey,
  111. $strTabIndex
  112. );
  113. } else {
  114. $strToReturn = sprintf('<span %s%s%s%s%s><input type="radio" id="%s" name="%s" value="%s" %s%s%s%s%s /><label for="%s">%s</label></span>',
  115. $strCssClass,
  116. $strToolTip,
  117. $strStyle,
  118. $strCustomAttributes,
  119. $strDisabled,
  120. $this->strControlId,
  121. $strGroupName,
  122. $this->strControlId,
  123. $strDisabled,
  124. $strChecked,
  125. $strActions,
  126. $strAccessKey,
  127. $strTabIndex,
  128. $this->strControlId,
  129. ($this->blnHtmlEntities) ? QApplication::HtmlEntities($this->strText) : $this->strText
  130. );
  131. }
  132. } else {
  133. $this->blnIsBlockElement = false;
  134. $strToReturn = sprintf('<input type="radio" id="%s" name="%s" value="%s" %s%s%s%s%s%s%s%s%s />',
  135. $this->strControlId,
  136. $strGroupName,
  137. $this->strControlId,
  138. $strCssClass,
  139. $strDisabled,
  140. $strChecked,
  141. $strActions,
  142. $strAccessKey,
  143. $strToolTip,
  144. $strTabIndex,
  145. $strCustomAttributes,
  146. $strStyle);
  147. }
  148. return $strToReturn;
  149. }
  150. public function Validate() {
  151. if ($this->blnRequired) {
  152. if (!$this->blnChecked) {
  153. $this->strValidationError = sprintf(QApplication::Translate('%s is required'), $this->strName);
  154. return false;
  155. }
  156. }
  157. $this->strValidationError = null;
  158. return true;
  159. }
  160. /////////////////////////
  161. // Public Properties: GET
  162. /////////////////////////
  163. public function __get($strName) {
  164. switch ($strName) {
  165. // APPEARANCE
  166. case "Text": return $this->strText;
  167. case "TextAlign": return $this->strTextAlign;
  168. // APPEARANCE
  169. case "GroupName": return $this->strGroupName;
  170. // BEHAVIOR
  171. case "HtmlEntities": return $this->blnHtmlEntities;
  172. // MISC
  173. case "Checked": return $this->blnChecked;
  174. default:
  175. try {
  176. return parent::__get($strName);
  177. } catch (QCallerException $objExc) {
  178. $objExc->IncrementOffset();
  179. throw $objExc;
  180. }
  181. }
  182. }
  183. /////////////////////////
  184. // Public Properties: SET
  185. /////////////////////////
  186. public function __set($strName, $mixValue) {
  187. $this->blnModified = true;
  188. switch ($strName) {
  189. // APPEARANCE
  190. case "Text":
  191. try {
  192. $this->strText = QType::Cast($mixValue, QType::String);
  193. break;
  194. } catch (QInvalidCastException $objExc) {
  195. $objExc->IncrementOffset();
  196. throw $objExc;
  197. }
  198. case "TextAlign":
  199. try {
  200. $this->strTextAlign = QType::Cast($mixValue, QType::String);
  201. break;
  202. } catch (QInvalidCastException $objExc) {
  203. $objExc->IncrementOffset();
  204. throw $objExc;
  205. }
  206. // BEHAVIOR
  207. case "HtmlEntities":
  208. try {
  209. $this->blnHtmlEntities = QType::Cast($mixValue, QType::Boolean);
  210. break;
  211. } catch (QInvalidCastException $objExc) {
  212. $objExc->IncrementOffset();
  213. throw $objExc;
  214. }
  215. case "GroupName":
  216. try {
  217. $this->strGroupName = QType::Cast($mixValue, QType::String);
  218. break;
  219. } catch (QInvalidCastException $objExc) {
  220. $objExc->IncrementOffset();
  221. throw $objExc;
  222. }
  223. // MISC
  224. case "Checked":
  225. try {
  226. $this->blnChecked = QType::Cast($mixValue, QType::Boolean);
  227. break;
  228. } catch (QInvalidCastException $objExc) {
  229. $objExc->IncrementOffset();
  230. throw $objExc;
  231. }
  232. default:
  233. try {
  234. parent::__set($strName, $mixValue);
  235. } catch (QCallerException $objExc) {
  236. $objExc->IncrementOffset();
  237. throw $objExc;
  238. }
  239. break;
  240. }
  241. }
  242. }
  243. ?>