Index: trunk/extensions/EducationProgram/specials/SpecialEnroll.php |
— | — | @@ -64,13 +64,14 @@ |
65 | 65 | if ( $this->getUser()->isLoggedIn() ) { |
66 | 66 | if ( $this->getUser()->isAllowed( 'epstudent' ) ) { |
67 | 67 | $user = $this->getUser(); |
68 | | - $hasFields = trim( $user->getRealName() ) !== '' || $user->getOption( 'gender' ) !== 'unknown'; |
| 68 | + $hasFields = trim( $user->getRealName() ) !== '' && $user->getOption( 'gender' ) !== 'unknown'; |
69 | 69 | |
70 | 70 | if ( $hasFields ) { |
71 | | - $this->showEnrollmentForm( $term ); |
| 71 | + $this->doEnroll( $term ); |
| 72 | + $this->onSuccess(); |
72 | 73 | } |
73 | 74 | else { |
74 | | - |
| 75 | + $this->showEnrollmentForm( $term ); |
75 | 76 | } |
76 | 77 | } |
77 | 78 | else { |
— | — | @@ -137,16 +138,41 @@ |
138 | 139 | } |
139 | 140 | |
140 | 141 | /** |
141 | | - * Just enroll the user in the term. This is useful when |
142 | | - * there are no things for the user to fill out in the |
143 | | - * enrollment form, making that step not needed. |
| 142 | + * Just enroll the user in the term. |
144 | 143 | * |
145 | 144 | * @since 0.1 |
146 | 145 | * |
147 | 146 | * @param EPTerm $term |
| 147 | + * |
| 148 | + * @return boolean Success indicator |
148 | 149 | */ |
149 | | - protected function autoEnroll( EPTerm $term ) { |
150 | | - // TODO |
| 150 | + protected function doEnroll( EPTerm $term ) { |
| 151 | + $student = EPStudent::newFromUser( $this->getUser(), array( 'id' ) ); |
| 152 | + $hadStudent = $student !== false; |
| 153 | + |
| 154 | + $fields = array( |
| 155 | + 'active_enroll' => 1 |
| 156 | + ); |
| 157 | + |
| 158 | + if ( !$hadStudent ) { |
| 159 | + $student = new EPStudent( array( 'user_id' => $this->getUser()->getId() ), true ); |
| 160 | + $fields['first_enroll'] = wfTimestamp( TS_MW ); |
| 161 | + } |
| 162 | + |
| 163 | + $student->setFields( $fields ); |
| 164 | + |
| 165 | + $success = $student->writeToDB(); |
| 166 | + |
| 167 | + if ( $success ) { |
| 168 | + $success = $student->associateWithTerms( array( $term ) ) && $success; |
| 169 | + |
| 170 | + if ( !$hadStudent ) { |
| 171 | + $this->getUser()->setOption( 'ep_showtoplink', true ); |
| 172 | + $this->getUser()->saveSettings(); |
| 173 | + } |
| 174 | + } |
| 175 | + |
| 176 | + return $success; |
151 | 177 | } |
152 | 178 | |
153 | 179 | /** |
— | — | @@ -205,7 +231,7 @@ |
206 | 232 | 'default' => 'unknown', |
207 | 233 | 'label-message' => 'ep-enroll-gender', |
208 | 234 | 'validation-callback' => function( $value, array $alldata = null ) { |
209 | | - return strlen( $value ) < 2 ? wfMsg( 'ep-enroll-invalid-gender' ) : true; |
| 235 | + return in_array( $value, array( 'male', 'female', 'unknown' ) ) ? true : wfMsg( 'ep-enroll-invalid-gender' ); |
210 | 236 | }, |
211 | 237 | 'options' => array( |
212 | 238 | wfMsg( 'gender-male' ) => 'male', |
— | — | @@ -227,25 +253,17 @@ |
228 | 254 | * @return Bool|Array |
229 | 255 | */ |
230 | 256 | public function handleSubmission( array $data ) { |
231 | | - $student = EPStudent::newFromUser( $this->getUser(), array( 'id' ) ); |
| 257 | + if ( array_key_exists( 'realname', $data ) ) { |
| 258 | + $this->getUser()->setRealName( $data['realname'] ); |
| 259 | + } |
232 | 260 | |
233 | | - if ( $student === false ) { |
234 | | - $student = new EPStudent( array( 'user_id' => $this->getUser()->getId() ), true ); |
| 261 | + if ( array_key_exists( 'gender', $data ) ) { |
| 262 | + $this->getUser()->setOption( 'gender', $data['gender'] ); |
235 | 263 | } |
236 | 264 | |
237 | | - $fields = array(); // TODO |
| 265 | + $this->getUser()->saveSettings(); |
238 | 266 | |
239 | | - $student->setFields( $fields ); |
240 | | - |
241 | | - $success = $student->writeToDB(); |
242 | | - |
243 | | - if ( $success ) { |
244 | | - $success = $student->associateWithTerms( array( $this->term ) ) && $success; |
245 | | - $this->getUser()->setOption( 'ep_showtoplink', true ); |
246 | | - $this->getUser()->saveSettings(); // TODO: can't we just save this single option instead of everything? |
247 | | - } |
248 | | - |
249 | | - if ( $success ) { |
| 267 | + if ( $this->doEnroll( $this->term ) ) { |
250 | 268 | return true; |
251 | 269 | } |
252 | 270 | else { |
Index: trunk/extensions/EducationProgram/includes/EPStudent.php |
— | — | @@ -82,6 +82,11 @@ |
83 | 83 | |
84 | 84 | $dbw->commit(); |
85 | 85 | |
| 86 | + foreach ( $terms as /* EPTerm */ $term ) { |
| 87 | + EPCourse::updateSummaryFields( 'students', array( 'id' => $term->getField( 'course_id' ) ) ); |
| 88 | + EPOrg::updateSummaryFields( 'students', array( 'id' => $term->getField( 'org_id' ) ) ); |
| 89 | + } |
| 90 | + |
86 | 91 | return $success; |
87 | 92 | } |
88 | 93 | |
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php |
— | — | @@ -268,6 +268,10 @@ |
269 | 269 | 'ep-enroll-invalid-token' => 'The token you provided is invalid.', |
270 | 270 | 'ep-enroll-legend' => 'Enroll', |
271 | 271 | 'ep-enroll-header' => 'In order to enroll for this course, all you need to do is fill out this form and click the submission button. After that you will be enrolled.', |
| 272 | + 'ep-enroll-gender' => 'Gender (optional)', |
| 273 | + 'ep-enroll-realname' => 'Real name (required)', |
| 274 | + 'ep-enroll-invalid-name' => 'The name needs to be at least contain $1 {{PLURAL:$1|character|characters}}.', |
| 275 | + 'ep-enroll-invalid-gender' => 'Please select one of these genders', |
272 | 276 | |
273 | 277 | // Special:MyCourses |
274 | 278 | 'ep-mycourses-enrolled' => 'You have successfully enrolled for $1 at $2.', |