Index: trunk/extensions/Contest/specials/SpecialMyContests.php |
— | — | @@ -343,6 +343,7 @@ |
344 | 344 | |
345 | 345 | $contestant = new ContestContestant( array( |
346 | 346 | 'id' => $data['contestant-id'], |
| 347 | + 'challenge_id' => $data['contestant-challengeid'], |
347 | 348 | |
348 | 349 | 'full_name' => $data['contestant-realname'], |
349 | 350 | 'email' => $data['contestant-email'], |
— | — | @@ -426,6 +427,15 @@ |
427 | 428 | 'options' => ContestContestant::getCountriesForInput() |
428 | 429 | ); |
429 | 430 | |
| 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 | + |
430 | 440 | $fields['contestant-volunteer'] = array( |
431 | 441 | 'type' => 'check', |
432 | 442 | 'default' => $contestant->getField( 'volunteer' ), |
— | — | @@ -449,7 +459,33 @@ |
450 | 460 | |
451 | 461 | return $fields; |
452 | 462 | } |
| 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(); |
453 | 477 | |
| 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 | + |
454 | 490 | /** |
455 | 491 | * HTMLForm field validation-callback for name field. |
456 | 492 | * |
— | — | @@ -539,7 +575,25 @@ |
540 | 576 | |
541 | 577 | return wfMsg( 'contest-submission-invalid-url' ); |
542 | 578 | } |
| 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 | + } |
543 | 594 | |
| 595 | + return true; |
| 596 | + } |
| 597 | + |
544 | 598 | } |
545 | 599 | |
546 | 600 | class ContestSubmissionField extends HTMLFormField { |