Index: trunk/extensions/Contest/Contest.i18n.php |
— | — | @@ -103,6 +103,7 @@ |
104 | 104 | 'contest-signup-volunteer' => 'I am interested in volunteer opportunities', |
105 | 105 | 'contest-signup-wmf' => 'I am interested in working for the Wikimedia Foundation', |
106 | 106 | 'contest-signup-readrules' => 'I confirm that I have read, and agree to, [[$1|the contest rules]]', |
| 107 | + 'contest-signup-challange' => 'What challange do you want to take on?', |
107 | 108 | |
108 | 109 | // Special:Contest |
109 | 110 | 'contest-contest-title' => 'Contest: $1', |
Index: trunk/extensions/Contest/specials/SpecialContestSignup.php |
— | — | @@ -37,7 +37,7 @@ |
38 | 38 | } |
39 | 39 | |
40 | 40 | if ( $this->getRequest()->wasPosted() && $this->getUser()->matchEditToken( $this->getRequest()->getVal( 'wpEditToken' ) ) ) { |
41 | | - $this->handleSubmission(); |
| 41 | + $this->showSignupForm( Contest::s()->selectRow( null, array( 'id' => $this->getRequest()->getInt( 'wpcontest-id' ) ) ) ); |
42 | 42 | } |
43 | 43 | else { |
44 | 44 | $this->showPage( $subPage ); |
— | — | @@ -48,11 +48,25 @@ |
49 | 49 | * Handle form submission. |
50 | 50 | * |
51 | 51 | * @since 0.1 |
| 52 | + * |
| 53 | + * @return true|array |
52 | 54 | */ |
53 | | - protected function handleSubmission() { |
54 | | - $request = $this->getRequest(); |
| 55 | + public static function handleSubmission( array $data ) { |
| 56 | + $user = $GLOBALS['wgUser']; //$this->getUser(); |
55 | 57 | |
| 58 | + $user->setEmail( $data['contestant-email'] ); |
| 59 | + $user->setRealName( $data['contestant-realname'] ); |
56 | 60 | |
| 61 | + $contestant = new ContestContestant( array( |
| 62 | + 'contest_id' => $data['contest-id'], |
| 63 | + 'user_id' => $user->getId(), |
| 64 | + 'challange_id' => $data['contestant-challangeid'], |
| 65 | + |
| 66 | + 'volunteer' => $data['contestant-volunteer'], |
| 67 | + 'wmf' => $data['contestant-wmf'], |
| 68 | + ) ); |
| 69 | + |
| 70 | + return $contestant->writeToDB(); |
57 | 71 | } |
58 | 72 | |
59 | 73 | /** |
— | — | @@ -89,14 +103,30 @@ |
90 | 104 | * @param Contest $contest |
91 | 105 | */ |
92 | 106 | protected function showSignupForm( Contest $contest ) { |
93 | | - $out = $this->getOutput(); |
94 | 107 | $form = new HTMLForm( $this->getFormFields( $contest ), $this->getContext() ); |
95 | 108 | |
| 109 | + $form->setSubmitCallback( array( __CLASS__, 'handleSubmission' ) ); |
96 | 110 | $form->setSubmitText( wfMsg( 'contest-signup-submit' ) ); |
97 | | - $form->show(); |
| 111 | + |
| 112 | + if( $form->show() ){ |
| 113 | + $this->showSucess( $contest ); |
| 114 | + } |
98 | 115 | } |
99 | 116 | |
100 | 117 | /** |
| 118 | + * Display a success message and helpfull links for further contest participation. |
| 119 | + * |
| 120 | + * @since 0.1 |
| 121 | + * |
| 122 | + * @param Contest $contest |
| 123 | + */ |
| 124 | + protected function showSucess( Contest $contest ) { |
| 125 | + $out = $this->getOutput(); |
| 126 | + |
| 127 | + // TODO |
| 128 | + } |
| 129 | + |
| 130 | + /** |
101 | 131 | * Gets the field definitions for the form. |
102 | 132 | * |
103 | 133 | * @since 0.1 |
— | — | @@ -108,49 +138,88 @@ |
109 | 139 | |
110 | 140 | $user = $this->getUser(); |
111 | 141 | |
112 | | - $fields[] = array( |
| 142 | + $fields['contest-id'] = array( |
113 | 143 | 'type' => 'hidden', |
114 | 144 | 'default' => $contest->getId(), |
115 | | - 'name' => 'contest-id', |
116 | 145 | 'id' => 'contest-id', |
117 | 146 | ); |
118 | 147 | |
119 | | - $fields[] = array( |
| 148 | + $fields['contestant-realname'] = array( |
120 | 149 | 'type' => 'text', |
121 | 150 | 'default' => $user->getRealName(), |
122 | 151 | 'label-message' => 'contest-signup-realname', |
123 | | - 'name' => 'contestant-realname', |
| 152 | + 'required' => true, |
| 153 | + 'validation-callback' => array( __CLASS__, 'validateNameField' ) |
124 | 154 | ); |
125 | 155 | |
126 | | - $fields[] = array( |
| 156 | + $fields['contestant-email'] = array( |
127 | 157 | 'type' => 'text', |
128 | 158 | 'default' => $user->getEmail(), |
129 | 159 | 'label-message' => 'contest-signup-email', |
130 | | - 'name' => 'contestant-email', |
| 160 | + 'required' => true, |
131 | 161 | ); |
132 | 162 | |
133 | | - $fields[] = array( |
| 163 | + $fields['contestant-challangeid'] = array( |
| 164 | + 'type' => 'radio', |
| 165 | + 'label-message' => 'contest-signup-challange', |
| 166 | + 'options' => $this->getChallangesList( $contest ), |
| 167 | + 'required' => true, |
| 168 | + ); |
| 169 | + |
| 170 | + $fields['contestant-volunteer'] = array( |
134 | 171 | 'type' => 'check', |
135 | 172 | 'default' => '0', |
136 | 173 | 'label-message' => 'contest-signup-volunteer', |
137 | | - 'name' => 'contestant-volunteer', |
138 | 174 | ); |
139 | 175 | |
140 | | - $fields[] = array( |
| 176 | + $fields['contestant-wmf'] = array( |
141 | 177 | 'type' => 'check', |
142 | 178 | 'default' => '0', |
143 | 179 | 'label-message' => 'contest-signup-wmf', |
144 | | - 'name' => 'contestant-wmf', |
145 | 180 | ); |
146 | 181 | |
147 | | - $fields[] = array( |
| 182 | + $fields['contestant-readrules'] = array( |
148 | 183 | 'type' => 'check', |
149 | 184 | 'default' => '0', |
150 | 185 | 'label-message' => array( 'contest-signup-readrules', $contest->getField( 'rules_page' ) ), |
151 | | - 'name' => 'contestant-readrules', |
152 | 186 | ); |
153 | 187 | |
154 | 188 | return $fields; |
155 | 189 | } |
156 | 190 | |
| 191 | + /** |
| 192 | + * Gets a list of contests that can be fed directly to the options field of |
| 193 | + * an HTMLForm radio input. |
| 194 | + * challange title => challange id |
| 195 | + * |
| 196 | + * @since 0.1 |
| 197 | + * |
| 198 | + * @param Contest $contest |
| 199 | + * |
| 200 | + * @return array |
| 201 | + */ |
| 202 | + protected function getChallangesList( Contest $contest ) { |
| 203 | + $list = array(); |
| 204 | + |
| 205 | + foreach ( $contest->getChallanges() as /* ContestChallange */ $challange ) { |
| 206 | + $list[$challange->getField( 'title' )] = $challange->getId(); |
| 207 | + } |
| 208 | + |
| 209 | + return $list; |
| 210 | + } |
| 211 | + |
| 212 | + /** |
| 213 | + * HTMLForm field validation-callback for Target field. |
| 214 | + * |
| 215 | + * @since 1.18 |
| 216 | + * |
| 217 | + * @param $value String |
| 218 | + * @param $alldata Array |
| 219 | + * |
| 220 | + * @return true|string |
| 221 | + */ |
| 222 | + public static function validateNameField( $value, $alldata = null ) { |
| 223 | + return strlen( $value ) > 1; |
| 224 | + } |
| 225 | + |
157 | 226 | } |
Index: trunk/extensions/Contest/specials/SpecialEditContest.php |
— | — | @@ -159,7 +159,7 @@ |
160 | 160 | $fields['name'] = array ( |
161 | 161 | 'type' => 'text', |
162 | 162 | 'label-message' => 'contest-edit-name', |
163 | | - 'id' => 'contest-name-field' |
| 163 | + 'id' => 'contest-name-field', |
164 | 164 | ); |
165 | 165 | |
166 | 166 | $fields['status'] = array ( |