http://www.mediawiki.org/wiki/Special:Code/MediaWiki/100287

Revision: 100287
Author:   jeroendedauw
Date:     2011-10-19 22:27:37 +0000 (Wed, 19 Oct 2011)
Log Message:
-----------
let users modify the challenge they want to tackle

Modified Paths:
--------------
    trunk/extensions/Contest/specials/SpecialMyContests.php

Modified: trunk/extensions/Contest/specials/SpecialMyContests.php
===================================================================
--- trunk/extensions/Contest/specials/SpecialMyContests.php     2011-10-19 
22:25:26 UTC (rev 100286)
+++ trunk/extensions/Contest/specials/SpecialMyContests.php     2011-10-19 
22:27:37 UTC (rev 100287)
@@ -343,6 +343,7 @@
 
                $contestant = new ContestContestant( array(
                        'id' => $data['contestant-id'],
+                       'challenge_id' => $data['contestant-challengeid'],
 
                        'full_name' => $data['contestant-realname'],
                        'email' => $data['contestant-email'],
@@ -426,6 +427,15 @@
                        'options' => ContestContestant::getCountriesForInput()
                );
 
+               $fields['contestant-challengeid'] = array(
+                       'type' => 'radio',
+                       'label-message' => 'contest-signup-challenge',
+                       'options' => $this->getChallengesList( $contestant ),
+                       'default' => $contestant->getField( 'challenge_id' ),
+                       'required' => true,
+                       'validation-callback' => array( __CLASS__, 
'validateChallengeField' )
+               );
+               
                $fields['contestant-volunteer'] = array(
                        'type' => 'check',
                        'default' => $contestant->getField( 'volunteer' ),
@@ -449,7 +459,33 @@
 
                return $fields;
        }
+       
+       /**
+        * Gets a list of contests that can be fed directly to the options 
field of
+        * an HTMLForm radio input.
+        * challenge title => challenge id
+        *
+        * @since 0.1
+        *
+        * @param ContestContestant $contestant
+        *
+        * @return array
+        */
+       protected function getChallengesList( ContestContestant $contestant ) {
+               $list = array();
 
+               $challenges = ContestChallenge::s()->select(
+                       array( 'id', 'title' ),
+                       array( 'contest_id' => $contestant->getField( 
'contest_id' ) )
+               );
+               
+               foreach ( $challenges as /* ContestChallenge */ $challenge ) {
+                       $list[$challenge->getField( 'title' )] = 
$challenge->getId();
+               }
+
+               return $list;
+       }
+
        /**
         * HTMLForm field validation-callback for name field.
         *
@@ -539,7 +575,25 @@
 
                return wfMsg( 'contest-submission-invalid-url' );
        }
+       
+       /**
+        * HTMLForm field validation-callback for challenge field.
+        *
+        * @since 0.1
+        *
+        * @param $value String
+        * @param $alldata Array
+        *
+        * @return true|string
+        */
+       public static function validateChallengeField( $value, $alldata = null 
) {
+               if ( is_null( $value ) ) {
+                       return wfMsg( 'contest-signup-require-challenge' );
+               }
 
+               return true;
+       }
+
 }
 
 class ContestSubmissionField extends HTMLFormField {


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to