A QCodo powered CMS
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.

208 lines
6.5 KiB

  1. <?php
  2. if(!defined('QUINTACMS') ) die("No quinta.");
  3. if (!defined("SHIPPINGMETHODCONTROLLER.CLASS.PHP")){
  4. define("SHIPPINGMETHODCONTROLLER.CLASS.PHP",1);
  5. /**
  6. * Class ShippingMethodController - 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 <sidewalksoftware@gmail.com>
  15. *
  16. *@version 0.3
  17. *
  18. *@package Quinta
  19. * @subpackage View
  20. */
  21. class ShippingMethodController extends QPanel{
  22. /**
  23. * This is normally the ShippingModule
  24. * @var QPanel objControlBlock - the content block to which this module is assigned
  25. */
  26. protected $objControlBlock;
  27. /**
  28. * @var ShippingMethod objShippingMethod - local reference or instance of some relevant object ..
  29. */
  30. protected $objShippingMethod;
  31. /**
  32. * @var boolean blnShowDescription - if true, display method description
  33. */
  34. protected $blnShowDescription;
  35. /**
  36. * @var boolean blnShowTransitTime - if true, display method delivery time
  37. */
  38. protected $blnShowTransitTime;
  39. /**
  40. * @var boolean blnShowRate - if true, display method price
  41. */
  42. protected $blnShowRate;
  43. //Controls ..
  44. /**
  45. * @var QRadioButton ctlRadioButton - button for selecting this method
  46. */
  47. public $ctlRadioButton;
  48. /**
  49. * @var QLabel lblDescription - label to display the description of the method
  50. */
  51. public $lblDescription;
  52. /**
  53. * @var QLabel lblTransitTime - label to display estimated delivery time
  54. */
  55. public $lblTransitTime;
  56. /**
  57. * @var QLabel lblRate - label to display price for this method
  58. */
  59. public $lblRate;
  60. /**
  61. * Class constructor
  62. * NOTE: The ShippingMethod passed to this view is expected to have already been
  63. * initilized with an order and have the rate set
  64. *@param QPanel objControlBlock - parent controller object.
  65. *@param ShippingMethod objShippingMethod
  66. */
  67. public function __construct( QPanel $objControlBlock,
  68. ShippingMethod $objShippingMethod,
  69. $blnShowDescription = true,
  70. $blnShowTransitTime = true,
  71. $blnShowRate = true
  72. )
  73. {
  74. //Normally assumed to be the ShippingModule
  75. $this->objControlBlock =& $objControlBlock;
  76. $this->objShippingMethod =& $objShippingMethod;
  77. $this->blnShowDescription =& $blnShowDescription;
  78. $this->blnShowTransitTime =& $blnShowTransitTime;
  79. $this->blnShowRate =& $blnShowRate;
  80. try {
  81. parent::__construct($this->objControlBlock);
  82. } catch (QCallerException $objExc) {
  83. $objExc->IncrementOffset();
  84. throw $objExc;
  85. }
  86. $this->strTemplate = __QUINTA_CORE_VIEWS__ . '/ShippingMethodView.tpl.php';
  87. $this->ctlRadioButton = new QRadioButton($this);
  88. $this->ctlRadioButton->AddCssClass('MethodRadioButton');
  89. $this->ctlRadioButton->GroupName = "ShippingMethods";
  90. if(IndexPage::$blnAjaxOk)
  91. $this->ctlRadioButton->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnSelectMethod_Click'));
  92. else
  93. $this->ctlRadioButton->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnSelectMethod_Click'));
  94. $this->ctlRadioButton->ActionParameter = $objShippingMethod->Id;
  95. if($this->blnShowDescription)
  96. {
  97. $this->lblDescription = new QLabel($this);
  98. $this->lblDescription->CssClass = 'MethodDescription';
  99. $this->lblDescription->HtmlEntities = false;
  100. $this->lblDescription->Text = $objShippingMethod->Description;
  101. }
  102. if($this->blnShowTransitTime)
  103. {
  104. $this->lblTransitTime = new QLabel($this);
  105. $this->lblTransitTime->CssClass = 'MethodTime';
  106. $this->lblTransitTime->HtmlEntities = false;
  107. $this->lblTransitTime->Text = $objShippingMethod->TransitTime;
  108. }
  109. if($this->blnShowRate)
  110. {
  111. $this->lblRate = new QLabel($this);
  112. $this->lblRate->CssClass = 'MethodPrice';
  113. $this->lblRate->HtmlEntities = false;
  114. $this->lblRate->Text = money_format('%n', $objShippingMethod->Rate);
  115. }
  116. }
  117. public function Validate() { return true; }
  118. /**
  119. * Called when this method is selected, only takes action if parent is ShippingModule
  120. */
  121. public function btnSelectMethod_Click($strFormId, $strControlId, $intMethodId){
  122. if( $this->objControlBlock instanceof ShippingModule )
  123. $this->objControlBlock->SelectMethod($intMethodId);
  124. }
  125. public function __get($strName){
  126. switch ($strName){
  127. case 'ShippingMethod':
  128. return $this->objShippingMethod ;
  129. case 'Checked':
  130. case 'Selected':
  131. return $this->ctlRadioButton->Checked ;
  132. case 'ShowDescription':
  133. return $this->blnShowDescription;
  134. case 'ShowTransitTime':
  135. return $this->blnShowTransitTime;
  136. case 'ShowRate':
  137. return $this->blnShowRate;
  138. default:
  139. try {
  140. return parent::__get($strName);
  141. } catch (QCallerException $objExc) {
  142. $objExc->IncrementOffset();
  143. throw $objExc;
  144. }
  145. }
  146. }
  147. public function __set($strName, $mixValue){
  148. switch ($strName){
  149. case 'ShippingMethod':
  150. try {
  151. return ($this->objShippingMethod = QType::Cast($mixValue, 'ShippingMethod' ));
  152. } catch (QInvalidCastException $objExc) {
  153. $objExc->IncrementOffset();
  154. throw $objExc;
  155. }
  156. case 'Checked':
  157. case 'Selected':
  158. try {
  159. return ($this->ctlRadioButton->Checked = QType::Cast($mixValue, QType::Boolean ));
  160. } catch (QInvalidCastException $objExc) {
  161. $objExc->IncrementOffset();
  162. throw $objExc;
  163. }
  164. case 'ShowDescription':
  165. try {
  166. return ($this->blnShowDescription = QType::Cast($mixValue, QType::Boolean ));
  167. } catch (QInvalidCastException $objExc) {
  168. $objExc->IncrementOffset();
  169. throw $objExc;
  170. }
  171. case 'ShowTransitTime':
  172. try {
  173. return ($this->blnShowTransitTime = QType::Cast($mixValue, QType::Boolean ));
  174. } catch (QInvalidCastException $objExc) {
  175. $objExc->IncrementOffset();
  176. throw $objExc;
  177. }
  178. case 'ShowRate':
  179. try {
  180. return ($this->blnShowRate = QType::Cast($mixValue, QType::Boolean ));
  181. } catch (QInvalidCastException $objExc) {
  182. $objExc->IncrementOffset();
  183. throw $objExc;
  184. }
  185. default:
  186. try {
  187. return (parent::__set($strName, $mixValue));
  188. } catch (QCallerException $objExc) {
  189. $objExc->IncrementOffset();
  190. throw $objExc;
  191. }
  192. }
  193. }
  194. }//end class
  195. }//end define
  196. ?>