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.

218 lines
7.0 KiB

  1. <?php
  2. if(!defined('QUINTACMS') ) die("No quinta.");
  3. if (!defined("PAYMENTMETHODCONTROLLER.CLASS.PHP")){
  4. define("PAYMENTMETHODCONTROLLER.CLASS.PHP",1);
  5. /**
  6. * Class PaymentMethodController - 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 <sidewalksoftware@gmail.com>
  15. *
  16. *@version 0.3
  17. *
  18. *@package Quinta
  19. * @subpackage View
  20. */
  21. class PaymentMethodController 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 PaymentMethod objPaymentMethod - local reference or instance of some relevant object ..
  29. */
  30. protected $objPaymentMethod;
  31. /**
  32. * @var boolean blnShowDescription - if true, display method description
  33. */
  34. protected $blnShowDescription;
  35. /**
  36. * @var boolean blnShowImage - if true, display method delivery time
  37. */
  38. protected $blnShowImage;
  39. //Controls ..
  40. /**
  41. * @var QRadioButton ctlRadioButton - button for selecting this method
  42. */
  43. public $ctlRadioButton;
  44. /**
  45. * @var QLabel lblDescription - label to display the description of the method
  46. */
  47. public $lblDescription;
  48. /**
  49. * @var QLabel lblTitle - label to display the Title of the method
  50. */
  51. public $lblTitle;
  52. /**
  53. * @var QPanel pnlImage - label to display an image for the payment provider
  54. */
  55. public $pnlImage;
  56. /**
  57. * Class constructor
  58. * NOTE: The PaymentMethod passed to this view is expected to have already been
  59. * initilized with an order and have the rate set
  60. *@param QPanel objControlBlock - parent controller object.
  61. *@param PaymentMethod objPaymentMethod
  62. *@param boolean blnShowDescription - whether to display the description
  63. *@param boolean blnShowImage - whether to display the image
  64. */
  65. public function __construct( QPanel $objControlBlock,
  66. PaymentMethod $objPaymentMethod,
  67. $blnShowDescription = true,
  68. $blnShowImage = true
  69. )
  70. {
  71. //Normally assumed to be the PaymentModule
  72. $this->objControlBlock =& $objControlBlock;
  73. $this->objPaymentMethod =& $objPaymentMethod;
  74. $this->blnShowDescription =& $blnShowDescription;
  75. $this->blnShowImage =& $blnShowImage;
  76. try {
  77. parent::__construct($this->objControlBlock);
  78. } catch (QCallerException $objExc) {
  79. $objExc->IncrementOffset();
  80. throw $objExc;
  81. }
  82. $this->strTemplate = __QUINTA_CORE_VIEWS__ . '/PaymentMethodView.tpl.php';
  83. $this->ctlRadioButton = new QRadioButton($this);
  84. $this->ctlRadioButton->AddCssClass('MethodRadioButton');
  85. $this->ctlRadioButton->GroupName = "PaymentMethods";
  86. if(IndexPage::$blnAjaxOk)
  87. $this->ctlRadioButton->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnSelectMethod_Click'));
  88. else
  89. $this->ctlRadioButton->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnSelectMethod_Click'));
  90. $this->ctlRadioButton->ActionParameter = $objPaymentMethod->Id;
  91. $this->lblTitle = new QLabel($this);
  92. $this->lblTitle->Text = $objPaymentMethod->Title;
  93. if($this->blnShowDescription){
  94. $this->lblDescription = new QLabel($this);
  95. $this->lblDescription->CssClass = 'MethodDescription';
  96. $this->lblDescription->HtmlEntities = false;
  97. $this->lblDescription->Text = $objPaymentMethod->Description;
  98. }
  99. if($this->blnShowImage){
  100. $this->pnlImage = new QPanel($this);
  101. $this->pnlImage->CssClass = 'MethodImage';
  102. $this->pnlImage->HtmlEntities = false;
  103. if( '' != $objPaymentMethod->ImageUri ){
  104. if( false !== strpos( $objPaymentMethod->ImageUri, 'http' ) )
  105. $this->pnlImage->Text = sprintf('<img src="%s">', $objPaymentMethod->ImageUri);
  106. else{
  107. foreach( array( __QUINTA_LOCAL__ . '/assets/images/',
  108. __QUINTA_CONTRIB__ . '/assets/images/',
  109. __QUINTA_CORE__ . '/assets/images/') as $strBase )
  110. {
  111. $strUri = $strBase . $objPaymentMethod->ImageUri;
  112. if( file_exists($strUri) ){
  113. if(false !== strpos( $strBase, 'local/' ))
  114. $strRelativeBase = __QUINTA_LOCAL_IMAGES__ . '/';
  115. elseif(false !== strpos( $strBase, 'contrib/' ))
  116. $strRelativeBase = __QUINTA_CONTRIB_IMAGES__ . '/';
  117. elseif(false !== strpos( $strBase, 'core/' ))
  118. $strRelativeBase = __QUINTA_CORE_IMAGES__ . '/';
  119. else//fall back to QCodo images ..
  120. $strRelativeBase = __IMAGE_ASSETS__ . '/';
  121. $strUri = $strRelativeBase . $objPaymentMethod->ImageUri;
  122. $this->pnlImage->Text = sprintf('<img src="%s">', $strUri);
  123. break;
  124. }
  125. }
  126. }
  127. }
  128. }
  129. }
  130. public function Validate() { return true; }
  131. /**
  132. * Called when this method is selected, only takes action if parent is PaymentModule
  133. */
  134. public function btnSelectMethod_Click($strFormId, $strControlId, $intMethodId){
  135. if( $this->objControlBlock instanceof PaymentModule )
  136. $this->objControlBlock->SelectMethod($intMethodId);
  137. }
  138. public function __get($strName){
  139. switch ($strName){
  140. case 'PaymentMethod':
  141. return $this->objPaymentMethod ;
  142. case 'Checked':
  143. case 'Selected':
  144. return $this->ctlRadioButton->Checked ;
  145. case 'ShowDescription':
  146. return $this->blnShowDescription;
  147. case 'ShowImage':
  148. return $this->blnShowImage;
  149. case 'ShowRate':
  150. return $this->blnShowRate;
  151. default:
  152. try {
  153. return parent::__get($strName);
  154. } catch (QCallerException $objExc) {
  155. $objExc->IncrementOffset();
  156. throw $objExc;
  157. }
  158. }
  159. }
  160. public function __set($strName, $mixValue){
  161. switch ($strName){
  162. case 'PaymentMethod':
  163. try {
  164. return ($this->objPaymentMethod = QType::Cast($mixValue, 'PaymentMethod' ));
  165. } catch (QInvalidCastException $objExc) {
  166. $objExc->IncrementOffset();
  167. throw $objExc;
  168. }
  169. case 'Checked':
  170. case 'Selected':
  171. try {
  172. return ($this->ctlRadioButton->Checked = QType::Cast($mixValue, QType::Boolean ));
  173. } catch (QInvalidCastException $objExc) {
  174. $objExc->IncrementOffset();
  175. throw $objExc;
  176. }
  177. case 'ShowDescription':
  178. try {
  179. return ($this->blnShowDescription = QType::Cast($mixValue, QType::Boolean ));
  180. } catch (QInvalidCastException $objExc) {
  181. $objExc->IncrementOffset();
  182. throw $objExc;
  183. }
  184. case 'ShowImage':
  185. try {
  186. return ($this->blnShowImage = QType::Cast($mixValue, QType::Boolean ));
  187. } catch (QInvalidCastException $objExc) {
  188. $objExc->IncrementOffset();
  189. throw $objExc;
  190. }
  191. default:
  192. try {
  193. return (parent::__set($strName, $mixValue));
  194. } catch (QCallerException $objExc) {
  195. $objExc->IncrementOffset();
  196. throw $objExc;
  197. }
  198. }
  199. }
  200. }//end class
  201. }//end define
  202. ?>