r101560 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101559‎ | r101560 | r101561 >
Date:00:09, 2 November 2011
Author:jpostlethwaite
Status:ok
Tags:fundraising 
Comment:
Added helper to generate radio buttons for donation amounts.
Modified paths:
  • /trunk/extensions/DonationInterface/gateway_forms/Form.php (modified) (history)

Diff [purge]

Index: trunk/extensions/DonationInterface/gateway_forms/Form.php
@@ -348,6 +348,11 @@
349349 /**
350350 * Generates the dropdown list for available currencies
351351 *
 352+ * @param array $options
 353+ *
 354+ * $options:
 355+ * - showCardsOnCurrencyChange: Allow javascript onchange="showCards();" to be executed.
 356+ *
352357 * @fixme The list of available currencies should NOT be defined here but rather
353358 * be customizable
354359 * @fixme It would be great to default the currency to a locale's currency
@@ -365,7 +370,7 @@
366371 'EUR' => 'EUR: Euro',
367372 'AUD' => 'AUD: Australian Dollar',
368373 'CAD' => 'CAD: Canadian Dollar',
369 - 'JPY' => 'JPY: Japanese Yen'
 374+ 'JPY' => 'JPY: Japanese Yen',
370375 );
371376
372377 $currency_opts = '';
@@ -390,6 +395,71 @@
391396 }
392397
393398 /**
 399+ * Generates the radio buttons for selecting a donation amount
 400+ *
 401+ * @param array $options
 402+ *
 403+ * $options:
 404+ * - displayCurrencyDropdown: Display the currency dropdown selector
 405+ * - showCardsOnCurrencyChange: Passed to @see Gateway_Form::generateStateDropdown()
 406+ *
 407+ * @todo
 408+ * - Use Xml object to generate form elements.
 409+ *
 410+ * @return string Returns an html table of radio buttons for the amount.
 411+ */
 412+ public function generateAmountByRadio( $options = array() ) {
 413+
 414+ extract( $options );
 415+
 416+ $options['showCardsOnCurrencyChange'] = isset( $showCardsOnCurrencyChange ) ? (boolean) $showCardsOnCurrencyChange : true;
 417+ $displayCurrencyDropdown = isset( $displayCurrencyDropdown ) ? (boolean) $displayCurrencyDropdown : true;
 418+ $setCurrency = isset( $setCurrency ) ? (string) $setCurrency : '';
 419+ $displayCurrencyDropdown = empty( $setCurrency ) ? $displayCurrencyDropdown : false;
 420+
 421+ // The text to return
 422+ $return = '';
 423+
 424+ $return .= '<table id="amount-radio">';
 425+ $return .= ' <tr>';
 426+ $return .= ' <td><label><input type="radio" name="amountRadio" value="5" /> 5</label></td>';
 427+ $return .= ' <td><label><input type="radio" name="amountRadio" value="10" /> 10</label></td>';
 428+ $return .= ' <td><label><input type="radio" name="amountRadio" value="20" /> 20</label></td>';
 429+ $return .= ' <td><label><input type="radio" name="amountRadio" value="35" /> 35</label></td>';
 430+ $return .= ' </tr>';
 431+ $return .= ' <tr>';
 432+ $return .= ' <td><label><input type="radio" name="amountRadio" value="50" /> 50</label></td>';
 433+ $return .= ' <td><label><input type="radio" name="amountRadio" value="100" /> 100</label></td>';
 434+ $return .= ' <td><label><input type="radio" name="amountRadio" value="250" /> 250</label></td>';
 435+ $return .= ' <td>';
 436+ $return .= ' <input type="radio" name="amountRadio" id="input_amount_other" value="other" />';
 437+ $return .= ' <label><input type="text" class="txt-sm hint" name="amountGiven" size="4" id="other-amount" title="Other..." onfocus=""/></label>';
 438+
 439+ // Add hidden amount field for validation
 440+ $return .= Html::hidden( 'amount', 0 );
 441+
 442+ // Set currency
 443+ if ( !empty( $setCurrency ) ) {
 444+ $return .= Html::hidden( 'currency_code', $setCurrency );
 445+ }
 446+
 447+ $return .= ' </td>';
 448+ $return .= ' </tr>';
 449+
 450+ if ( $displayCurrencyDropdown ) {
 451+ $return .= ' <tr>';
 452+ $return .= ' <td colspan="4" >';
 453+ $return .= $this->generateCurrencyDropdown( $options );
 454+ $return .= ' </td>';
 455+ $return .= ' </tr>';
 456+ }
 457+
 458+ $return .= '</table>';
 459+
 460+ return $return;
 461+ }
 462+
 463+ /**
394464 * Set the hidden field array
395465 *
396466 * If you pass nothing in, we'll set the fields for you.

Status & tagging log