r100287 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100286‎ | r100287 | r100288 >
Date:22:27, 19 October 2011
Author:jeroendedauw
Status:ok
Tags:
Comment:
let users modify the challenge they want to tackle
Modified paths:
  • /trunk/extensions/Contest/specials/SpecialMyContests.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Contest/specials/SpecialMyContests.php
@@ -343,6 +343,7 @@
344344
345345 $contestant = new ContestContestant( array(
346346 'id' => $data['contestant-id'],
 347+ 'challenge_id' => $data['contestant-challengeid'],
347348
348349 'full_name' => $data['contestant-realname'],
349350 'email' => $data['contestant-email'],
@@ -426,6 +427,15 @@
427428 'options' => ContestContestant::getCountriesForInput()
428429 );
429430
 431+ $fields['contestant-challengeid'] = array(
 432+ 'type' => 'radio',
 433+ 'label-message' => 'contest-signup-challenge',
 434+ 'options' => $this->getChallengesList( $contestant ),
 435+ 'default' => $contestant->getField( 'challenge_id' ),
 436+ 'required' => true,
 437+ 'validation-callback' => array( __CLASS__, 'validateChallengeField' )
 438+ );
 439+
430440 $fields['contestant-volunteer'] = array(
431441 'type' => 'check',
432442 'default' => $contestant->getField( 'volunteer' ),
@@ -449,7 +459,33 @@
450460
451461 return $fields;
452462 }
 463+
 464+ /**
 465+ * Gets a list of contests that can be fed directly to the options field of
 466+ * an HTMLForm radio input.
 467+ * challenge title => challenge id
 468+ *
 469+ * @since 0.1
 470+ *
 471+ * @param ContestContestant $contestant
 472+ *
 473+ * @return array
 474+ */
 475+ protected function getChallengesList( ContestContestant $contestant ) {
 476+ $list = array();
453477
 478+ $challenges = ContestChallenge::s()->select(
 479+ array( 'id', 'title' ),
 480+ array( 'contest_id' => $contestant->getField( 'contest_id' ) )
 481+ );
 482+
 483+ foreach ( $challenges as /* ContestChallenge */ $challenge ) {
 484+ $list[$challenge->getField( 'title' )] = $challenge->getId();
 485+ }
 486+
 487+ return $list;
 488+ }
 489+
454490 /**
455491 * HTMLForm field validation-callback for name field.
456492 *
@@ -539,7 +575,25 @@
540576
541577 return wfMsg( 'contest-submission-invalid-url' );
542578 }
 579+
 580+ /**
 581+ * HTMLForm field validation-callback for challenge field.
 582+ *
 583+ * @since 0.1
 584+ *
 585+ * @param $value String
 586+ * @param $alldata Array
 587+ *
 588+ * @return true|string
 589+ */
 590+ public static function validateChallengeField( $value, $alldata = null ) {
 591+ if ( is_null( $value ) ) {
 592+ return wfMsg( 'contest-signup-require-challenge' );
 593+ }
543594
 595+ return true;
 596+ }
 597+
544598 }
545599
546600 class ContestSubmissionField extends HTMLFormField {

Follow-up revisions

RevisionCommit summaryAuthorDate
r1002961.18wmf1 MFT r100292, r100287reedy23:40, 19 October 2011

Status & tagging log