r100951 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100950‎ | r100951 | r100952 >
Date:06:22, 27 October 2011
Author:jpostlethwaite
Status:ok
Tags:fundraising 
Comment:
Added helper methods to GateForm for form id, name, payment_method, payment_submethod. Added an init() method called in __construct(). This makes it so you do not have to override parent::__construct(). Made it optional for $showCardsOnCurrencyChange.
Modified paths:
  • /trunk/extensions/DonationInterface/gateway_forms/Form.php (modified) (history)

Diff [purge]

Index: trunk/extensions/DonationInterface/gateway_forms/Form.php
@@ -21,6 +21,24 @@
2222 public $form_data;
2323
2424 /**
 25+ * The id of the form.
 26+ *
 27+ * This should also be the name of the form
 28+ *
 29+ * @var string
 30+ */
 31+ public $form_id = 'payment';
 32+
 33+ /**
 34+ * The name of the form.
 35+ *
 36+ * This should also be the id of the form
 37+ *
 38+ * @var string
 39+ */
 40+ public $form_name = 'payment';
 41+
 42+ /**
2543 * An array of form errors, passed from the payflow pro object
2644 * @var array
2745 */
@@ -39,6 +57,18 @@
4058 protected $captcha_html;
4159
4260 /**
 61+ * The payment method
 62+ * @var string
 63+ */
 64+ protected $payment_method = '';
 65+
 66+ /**
 67+ * The payment submethod
 68+ * @var string
 69+ */
 70+ protected $payment_submethod = '';
 71+
 72+ /**
4373 * Required method for returning the full HTML for a form.
4474 *
4575 * Code invoking forms will expect this method to be set. Requiring only
@@ -82,9 +112,19 @@
83113 }
84114
85115 $this->loadLogoLinkOverride();
 116+
 117+ // This method should be overridden in the child class
 118+ $this->init();
86119 }
87120
88121 /**
 122+ * Initialize the form
 123+ *
 124+ */
 125+ protected function init() {
 126+ }
 127+
 128+ /**
89129 * Override the link in the logo to redirec to a particular form
90130 * rather than the main page
91131 */
@@ -313,7 +353,12 @@
314354 * @fixme It would be great to default the currency to a locale's currency
315355 * @return string The entire HTML select for the currency dropdown
316356 */
317 - public function generateCurrencyDropdown() {
 357+ public function generateCurrencyDropdown( $options = array() ) {
 358+
 359+ extract( $options );
 360+
 361+ $showCardsOnCurrencyChange = isset( $showCardsOnCurrencyChange ) ? (boolean) $showCardsOnCurrencyChange : true;
 362+
318363 $available_currencies = array(
319364 'USD' => 'USD: U.S. Dollar',
320365 'GBP' => 'GBP: British Pound',
@@ -336,7 +381,7 @@
337382 array(
338383 'name' => 'currency_code',
339384 'id' => 'input_currency_code',
340 - 'onchange' => 'showCards()'
 385+ 'onchange' => $showCardsOnCurrencyChange ? 'showCards()' : '',
341386 ) );
342387 $currency_menu .= $currency_opts;
343388 $currency_menu .= Xml::closeElement( 'select' );
@@ -736,4 +781,84 @@
737782 return wfAppendQuery( $wgTitle->getLocalURL(), $query_array );
738783 }
739784
 785+ /**
 786+ * Get the form id
 787+ *
 788+ * @return string
 789+ */
 790+ protected function getFormId() {
 791+
 792+ return $this->form_id;
 793+ }
 794+
 795+ /**
 796+ * Set the form id
 797+ *
 798+ * @param string $value The form_id value
 799+ */
 800+ protected function setFormId( $value = '' ) {
 801+
 802+ $this->form_id = (string) $value;
 803+ }
 804+
 805+ /**
 806+ * Get the form name
 807+ *
 808+ * @return string
 809+ */
 810+ protected function getFormName() {
 811+
 812+ return $this->form_name;
 813+ }
 814+
 815+ /**
 816+ * Set the form name
 817+ *
 818+ * @param string $value The form_name value
 819+ */
 820+ protected function setFormName( $value = '' ) {
 821+
 822+ $this->form_name = (string) $value;
 823+ }
 824+
 825+ /**
 826+ * Get the payment method
 827+ *
 828+ * @return string
 829+ */
 830+ protected function getPaymentMethod() {
 831+
 832+ return $this->payment_method;
 833+ }
 834+
 835+ /**
 836+ * Set the payment method
 837+ *
 838+ * @param string $value The payment method value
 839+ */
 840+ protected function setPaymentMethod( $value = '' ) {
 841+
 842+ $this->payment_method = (string) $value;
 843+ }
 844+
 845+ /**
 846+ * Get the payment submethod
 847+ *
 848+ * @return string
 849+ */
 850+ protected function getPaymentSubmethod() {
 851+
 852+ return $this->payment_submethod;
 853+ }
 854+
 855+ /**
 856+ * Set the payment submethod
 857+ *
 858+ * @param string $value The payment submethod value
 859+ */
 860+ protected function setPaymentSubmethod( $value = '' ) {
 861+
 862+ $this->payment_submethod = (string) $value;
 863+ }
 864+
740865 }

Status & tagging log