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.

250 lines
10 KiB

13 years ago
  1. <?php
  2. if(!defined('QUASICMS') ) die("No quasi.");
  3. if (!defined("PAYMENTMETHODVIEW.CLASS.PHP")){
  4. define("PAYMENTMETHODVIEW.CLASS.PHP",1);
  5. /**
  6. * Class PaymentMethodView - provides checkbox display of a payment method
  7. * This class shows a radiobutton that is a member of "PaymentMethods" group.
  8. * It will optionally also display the description, instructions and an image 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 PaymentModule - 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: PaymentMethodView.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 PaymentMethodView 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 PaymentMethod objPaymentMethod - local reference or instance of some relevant object ..
  46. */
  47. protected $objPaymentMethod;
  48. /**
  49. * @var boolean blnShowDescription - if true, display method description
  50. */
  51. protected $blnShowDescription;
  52. /**
  53. * @var boolean blnShowImage - if true, display method delivery time
  54. */
  55. protected $blnShowImage;
  56. //Controls ..
  57. /**
  58. * @var QRadioButton ctlRadioButton - button for selecting this method
  59. */
  60. public $ctlRadioButton;
  61. /**
  62. * @var QLabel lblDescription - label to display the description of the method
  63. */
  64. public $lblDescription;
  65. /**
  66. * @var QLabel lblTitle - label to display the Title of the method
  67. */
  68. public $lblTitle;
  69. /**
  70. * @var QPanel pnlImage - label to display an image for the payment provider
  71. */
  72. public $pnlImage;
  73. /**
  74. * Class constructor
  75. * NOTE: The PaymentMethod passed to this view is expected to have already been
  76. * initilized with an order and have the rate set
  77. *@param QPanel objControlBlock - parent controller object.
  78. *@param PaymentMethod objPaymentMethod
  79. *@param boolean blnShowDescription - whether to display the description
  80. *@param boolean blnShowImage - whether to display the image
  81. */
  82. public function __construct( QPanel $objControlBlock,
  83. PaymentMethod $objPaymentMethod,
  84. $blnShowDescription = true,
  85. $blnShowImage = true
  86. )
  87. {
  88. //Normally assumed to be the PaymentModule
  89. $this->objControlBlock =& $objControlBlock;
  90. $this->objPaymentMethod =& $objPaymentMethod;
  91. $this->blnShowDescription =& $blnShowDescription;
  92. $this->blnShowImage =& $blnShowImage;
  93. try {
  94. parent::__construct($this->objControlBlock);
  95. } catch (QCallerException $objExc) {
  96. $objExc->IncrementOffset();
  97. throw $objExc;
  98. }
  99. $this->strTemplate = __QUASI_CORE_TEMPLATES__ . '/PaymentMethodView.tpl.php';
  100. $this->ctlRadioButton = new QRadioButton($this);
  101. $this->ctlRadioButton->AddCssClass('MethodRadioButton');
  102. $this->ctlRadioButton->GroupName = "PaymentMethods";
  103. if(IndexPage::$blnAjaxOk)
  104. $this->ctlRadioButton->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnSelectMethod_Click'));
  105. else
  106. $this->ctlRadioButton->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnSelectMethod_Click'));
  107. $this->ctlRadioButton->ActionParameter = $objPaymentMethod->Id;
  108. $this->lblTitle = new QLabel($this);
  109. $this->lblTitle->Text = $objPaymentMethod->Title;
  110. if($this->blnShowDescription)
  111. {
  112. $this->lblDescription = new QLabel($this);
  113. $this->lblDescription->CssClass = 'MethodDescription';
  114. $this->lblDescription->HtmlEntities = false;
  115. $this->lblDescription->Text = $objPaymentMethod->Description;
  116. }
  117. if($this->blnShowImage)
  118. {
  119. $this->pnlImage = new QPanel($this);
  120. $this->pnlImage->CssClass = 'MethodImage';
  121. $this->pnlImage->HtmlEntities = false;
  122. if( '' != $objPaymentMethod->ImageUri )
  123. {
  124. if( false !== strpos( $objPaymentMethod->ImageUri, 'http' ) )
  125. $this->pnlImage->Text = sprintf('<img src="%s">', $objPaymentMethod->ImageUri);
  126. else
  127. {
  128. foreach( array( __QUASI_LOCAL__ . '/assets/images/',
  129. __QUASI_CONTRIB__ . '/assets/images/',
  130. __QUASI_CORE__ . '/assets/images/') as $strBase )
  131. {
  132. $strUri = $strBase . $objPaymentMethod->ImageUri;
  133. if( file_exists($strUri) )
  134. {
  135. if(false !== strpos( $strBase, 'local/' ))
  136. $strRelativeBase = __QUASI_LOCAL_IMAGES__ . '/';
  137. elseif(false !== strpos( $strBase, 'contrib/' ))
  138. $strRelativeBase = __QUASI_CONTRIB_IMAGES__ . '/';
  139. elseif(false !== strpos( $strBase, 'core/' ))
  140. $strRelativeBase = __QUASI_CORE_IMAGES__ . '/';
  141. else//fall back to QCodo images ..
  142. $strRelativeBase = __IMAGE_ASSETS__ . '/';
  143. $strUri = $strRelativeBase . $objPaymentMethod->ImageUri;
  144. $this->pnlImage->Text = sprintf('<img src="%s">', $strUri);
  145. break;
  146. }
  147. }
  148. }
  149. }
  150. }
  151. }
  152. public function Validate() { return true; }
  153. /**
  154. * Called when this method is selected, only takes action if parent is PaymentModule
  155. */
  156. public function btnSelectMethod_Click($strFormId, $strControlId, $intMethodId)
  157. {
  158. if( $this->objControlBlock instanceof PaymentModule )
  159. $this->objControlBlock->SelectMethod($intMethodId);
  160. }
  161. public function __get($strName)
  162. {
  163. switch ($strName)
  164. {
  165. case 'PaymentMethod':
  166. return $this->objPaymentMethod ;
  167. case 'Checked':
  168. case 'Selected':
  169. return $this->ctlRadioButton->Checked ;
  170. case 'ShowDescription':
  171. return $this->blnShowDescription;
  172. case 'ShowImage':
  173. return $this->blnShowImage;
  174. case 'ShowRate':
  175. return $this->blnShowRate;
  176. default:
  177. try {
  178. return parent::__get($strName);
  179. } catch (QCallerException $objExc) {
  180. $objExc->IncrementOffset();
  181. throw $objExc;
  182. }
  183. }
  184. }
  185. public function __set($strName, $mixValue)
  186. {
  187. switch ($strName)
  188. {
  189. case 'PaymentMethod':
  190. try {
  191. return ($this->objPaymentMethod = QType::Cast($mixValue, 'PaymentMethod' ));
  192. } catch (QInvalidCastException $objExc) {
  193. $objExc->IncrementOffset();
  194. throw $objExc;
  195. }
  196. case 'Checked':
  197. case 'Selected':
  198. try {
  199. return ($this->ctlRadioButton->Checked = QType::Cast($mixValue, QType::Boolean ));
  200. } catch (QInvalidCastException $objExc) {
  201. $objExc->IncrementOffset();
  202. throw $objExc;
  203. }
  204. case 'ShowDescription':
  205. try {
  206. return ($this->blnShowDescription = QType::Cast($mixValue, QType::Boolean ));
  207. } catch (QInvalidCastException $objExc) {
  208. $objExc->IncrementOffset();
  209. throw $objExc;
  210. }
  211. case 'ShowImage':
  212. try {
  213. return ($this->blnShowImage = QType::Cast($mixValue, QType::Boolean ));
  214. } catch (QInvalidCastException $objExc) {
  215. $objExc->IncrementOffset();
  216. throw $objExc;
  217. }
  218. default:
  219. try {
  220. return (parent::__set($strName, $mixValue));
  221. } catch (QCallerException $objExc) {
  222. $objExc->IncrementOffset();
  223. throw $objExc;
  224. }
  225. }
  226. }
  227. }//end class
  228. }//end define
  229. ?>