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.

237 lines
9.2 KiB

13 years ago
  1. <?php
  2. if(!defined('QUASICMS') ) die("No quasi.");
  3. if (!defined("SHIPPINGMETHODVIEW.CLASS.PHP")){
  4. define("SHIPPINGMETHODVIEW.CLASS.PHP",1);
  5. /**
  6. * Class ShippingMethodView - provides checkbox display of a shipping method
  7. * This class shows a radiobutton that is a member of "ShippingMethods" group.
  8. * It will optionally also display the description, transit time and rate for the method.
  9. *
  10. * When the method is selected, it will issue a callback passing the id of the paymentmethod
  11. * as a parameter if the parent is a ShippingModule - Note that this requires the existance of
  12. * the method "SelectMethod($intId)" in the parent.
  13. *
  14. *@author Erik Winn <erikwinnmail@yahoo.com>
  15. *
  16. *
  17. * $Id: ShippingMethodView.class.php 286 2008-10-10 23:33:36Z erikwinn $
  18. *@version 0.1
  19. *
  20. *@copyright (C) 2008 by Erik Winn
  21. *@license GPL v.2
  22. This program is free software; you can redistribute it and/or modify
  23. it under the terms of the GNU General Public License as published by
  24. the Free Software Foundation; either version 2 of the License, or
  25. (at your option) any later version.
  26. This program is distributed in the hope that it will be useful,
  27. but WITHOUT ANY WARRANTY; without even the implied warranty of
  28. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  29. GNU General Public License for more details.
  30. You should have received a copy of the GNU General Public License
  31. along with this program; if not, write to the Free Software
  32. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
  33. *
  34. *@package Quasi
  35. * @subpackage View
  36. */
  37. class ShippingMethodView extends QPanel
  38. {
  39. /**
  40. * This is normally the ShippingModule
  41. * @var QPanel objControlBlock - the content block to which this module is assigned
  42. */
  43. protected $objControlBlock;
  44. /**
  45. * @var ShippingMethod objShippingMethod - local reference or instance of some relevant object ..
  46. */
  47. protected $objShippingMethod;
  48. /**
  49. * @var boolean blnShowDescription - if true, display method description
  50. */
  51. protected $blnShowDescription;
  52. /**
  53. * @var boolean blnShowTransitTime - if true, display method delivery time
  54. */
  55. protected $blnShowTransitTime;
  56. /**
  57. * @var boolean blnShowRate - if true, display method price
  58. */
  59. protected $blnShowRate;
  60. //Controls ..
  61. /**
  62. * @var QRadioButton ctlRadioButton - button for selecting this method
  63. */
  64. public $ctlRadioButton;
  65. /**
  66. * @var QLabel lblDescription - label to display the description of the method
  67. */
  68. public $lblDescription;
  69. /**
  70. * @var QLabel lblTransitTime - label to display estimated delivery time
  71. */
  72. public $lblTransitTime;
  73. /**
  74. * @var QLabel lblRate - label to display price for this method
  75. */
  76. public $lblRate;
  77. /**
  78. * Class constructor
  79. * NOTE: The ShippingMethod passed to this view is expected to have already been
  80. * initilized with an order and have the rate set
  81. *@param QPanel objControlBlock - parent controller object.
  82. *@param ShippingMethod objShippingMethod
  83. */
  84. public function __construct( QPanel $objControlBlock,
  85. ShippingMethod $objShippingMethod,
  86. $blnShowDescription = true,
  87. $blnShowTransitTime = true,
  88. $blnShowRate = true
  89. )
  90. {
  91. //Normally assumed to be the ShippingModule
  92. $this->objControlBlock =& $objControlBlock;
  93. $this->objShippingMethod =& $objShippingMethod;
  94. $this->blnShowDescription =& $blnShowDescription;
  95. $this->blnShowTransitTime =& $blnShowTransitTime;
  96. $this->blnShowRate =& $blnShowRate;
  97. try {
  98. parent::__construct($this->objControlBlock);
  99. } catch (QCallerException $objExc) {
  100. $objExc->IncrementOffset();
  101. throw $objExc;
  102. }
  103. $this->strTemplate = __QUASI_CORE_TEMPLATES__ . '/ShippingMethodView.tpl.php';
  104. $this->ctlRadioButton = new QRadioButton($this);
  105. $this->ctlRadioButton->AddCssClass('MethodRadioButton');
  106. $this->ctlRadioButton->GroupName = "ShippingMethods";
  107. if(IndexPage::$blnAjaxOk)
  108. $this->ctlRadioButton->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnSelectMethod_Click'));
  109. else
  110. $this->ctlRadioButton->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnSelectMethod_Click'));
  111. $this->ctlRadioButton->ActionParameter = $objShippingMethod->Id;
  112. if($this->blnShowDescription)
  113. {
  114. $this->lblDescription = new QLabel($this);
  115. $this->lblDescription->CssClass = 'MethodDescription';
  116. $this->lblDescription->HtmlEntities = false;
  117. $this->lblDescription->Text = $objShippingMethod->Description;
  118. }
  119. if($this->blnShowTransitTime)
  120. {
  121. $this->lblTransitTime = new QLabel($this);
  122. $this->lblTransitTime->CssClass = 'MethodTime';
  123. $this->lblTransitTime->HtmlEntities = false;
  124. $this->lblTransitTime->Text = $objShippingMethod->TransitTime;
  125. }
  126. if($this->blnShowRate)
  127. {
  128. $this->lblRate = new QLabel($this);
  129. $this->lblRate->CssClass = 'MethodPrice';
  130. $this->lblRate->HtmlEntities = false;
  131. $this->lblRate->Text = money_format('%n', $objShippingMethod->Rate);
  132. }
  133. }
  134. public function Validate() { return true; }
  135. /**
  136. * Called when this method is selected, only takes action if parent is ShippingModule
  137. */
  138. public function btnSelectMethod_Click($strFormId, $strControlId, $intMethodId)
  139. {
  140. if( $this->objControlBlock instanceof ShippingModule )
  141. $this->objControlBlock->SelectMethod($intMethodId);
  142. }
  143. public function __get($strName)
  144. {
  145. switch ($strName)
  146. {
  147. case 'ShippingMethod':
  148. return $this->objShippingMethod ;
  149. case 'Checked':
  150. case 'Selected':
  151. return $this->ctlRadioButton->Checked ;
  152. case 'ShowDescription':
  153. return $this->blnShowDescription;
  154. case 'ShowTransitTime':
  155. return $this->blnShowTransitTime;
  156. case 'ShowRate':
  157. return $this->blnShowRate;
  158. default:
  159. try {
  160. return parent::__get($strName);
  161. } catch (QCallerException $objExc) {
  162. $objExc->IncrementOffset();
  163. throw $objExc;
  164. }
  165. }
  166. }
  167. public function __set($strName, $mixValue)
  168. {
  169. switch ($strName)
  170. {
  171. case 'ShippingMethod':
  172. try {
  173. return ($this->objShippingMethod = QType::Cast($mixValue, 'ShippingMethod' ));
  174. } catch (QInvalidCastException $objExc) {
  175. $objExc->IncrementOffset();
  176. throw $objExc;
  177. }
  178. case 'Checked':
  179. case 'Selected':
  180. try {
  181. return ($this->ctlRadioButton->Checked = QType::Cast($mixValue, QType::Boolean ));
  182. } catch (QInvalidCastException $objExc) {
  183. $objExc->IncrementOffset();
  184. throw $objExc;
  185. }
  186. case 'ShowDescription':
  187. try {
  188. return ($this->blnShowDescription = QType::Cast($mixValue, QType::Boolean ));
  189. } catch (QInvalidCastException $objExc) {
  190. $objExc->IncrementOffset();
  191. throw $objExc;
  192. }
  193. case 'ShowTransitTime':
  194. try {
  195. return ($this->blnShowTransitTime = QType::Cast($mixValue, QType::Boolean ));
  196. } catch (QInvalidCastException $objExc) {
  197. $objExc->IncrementOffset();
  198. throw $objExc;
  199. }
  200. case 'ShowRate':
  201. try {
  202. return ($this->blnShowRate = QType::Cast($mixValue, QType::Boolean ));
  203. } catch (QInvalidCastException $objExc) {
  204. $objExc->IncrementOffset();
  205. throw $objExc;
  206. }
  207. default:
  208. try {
  209. return (parent::__set($strName, $mixValue));
  210. } catch (QCallerException $objExc) {
  211. $objExc->IncrementOffset();
  212. throw $objExc;
  213. }
  214. }
  215. }
  216. }//end class
  217. }//end define
  218. ?>