Index: trunk/extensions/EducationProgram/specials/SpecialDisenroll.php |
— | — | @@ -49,7 +49,12 @@ |
50 | 50 | if ( $this->getUser()->isLoggedIn() ) { |
51 | 51 | $req = $this->getRequest(); |
52 | 52 | |
53 | | - if ( $req->wasPosted() && $this->getUser()->matchEditToken( $req->getText( 'disenrollEditToken' ) ) ) { |
| 53 | + $editTokenMatches = $this->getUser()->matchEditToken( |
| 54 | + $req->getText( 'disenrollToken' ), |
| 55 | + $this->getTitle( $this->subPage )->getLocalURL() |
| 56 | + ); |
| 57 | + |
| 58 | + if ( $req->wasPosted() && $editTokenMatches ) { |
54 | 59 | $this->doDisenroll( $course ); |
55 | 60 | } |
56 | 61 | else { |
— | — | @@ -127,24 +132,24 @@ |
128 | 133 | |
129 | 134 | $out->addHTML( '<br />' ); |
130 | 135 | |
131 | | - $out->addElement( |
132 | | - 'button', |
133 | | - array( |
134 | | - 'class' => 'ep-disenroll-cancel', |
135 | | - ), |
136 | | - wfMsg( 'ep-disenroll-cancel' ) |
137 | | - ); |
138 | | - |
139 | 136 | $out->addHTML( Html::input( |
140 | 137 | 'disenroll', |
141 | 138 | wfMsg( 'ep-disenroll-button' ), |
142 | 139 | 'submit', |
143 | 140 | array( |
144 | 141 | 'class' => 'ep-disenroll', |
145 | | - 'target-url' => '', // TODO |
146 | 142 | ) |
147 | 143 | ) ); |
148 | 144 | |
| 145 | + $out->addElement( |
| 146 | + 'button', |
| 147 | + array( |
| 148 | + 'class' => 'ep-disenroll-cancel', |
| 149 | + 'target-url' => $course->getTitle()->getLocalURL(), |
| 150 | + ), |
| 151 | + wfMsg( 'ep-disenroll-cancel' ) |
| 152 | + ); |
| 153 | + |
149 | 154 | $out->addHTML( Html::hidden( 'disenrollToken', $this->getUser()->getEditToken( $target ) ) ); |
150 | 155 | |
151 | 156 | $out->addHTML( '</form>' ); |
— | — | @@ -158,7 +163,20 @@ |
159 | 164 | * @param EPCourse $course |
160 | 165 | */ |
161 | 166 | protected function doDisenroll( EPCourse $course ) { |
162 | | - // TODO |
| 167 | + $success = $course->unenlistUsers( |
| 168 | + $this->getUser()->getId(), |
| 169 | + 'student', |
| 170 | + $this->getRequest()->getText( 'summary' ) |
| 171 | + ); |
| 172 | + |
| 173 | + if ( $success ) { |
| 174 | + $this->showSuccess( wfMessage( 'ep-disenroll-success' ) ); |
| 175 | + } |
| 176 | + else { |
| 177 | + $this->showError( wfMessage( 'ep-disenroll-fail' ) ); |
| 178 | + } |
| 179 | + |
| 180 | + $this->getOutput()->addWikiMsg( 'ep-disenroll-returnto', $course->getField( 'name' ) ); |
163 | 181 | } |
164 | 182 | |
165 | 183 | } |
Index: trunk/extensions/EducationProgram/includes/EPPageObject.php |
— | — | @@ -17,6 +17,13 @@ |
18 | 18 | return $this->getField( $this->table->getIdentifierField() ); |
19 | 19 | } |
20 | 20 | |
| 21 | + /** |
| 22 | + * |
| 23 | + * |
| 24 | + * @since 0.1 |
| 25 | + * |
| 26 | + * @return Title |
| 27 | + */ |
21 | 28 | public function getTitle() { |
22 | 29 | return $this->table->getTitleFor( $this->getIdentifier() ); |
23 | 30 | } |
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php |
— | — | @@ -451,6 +451,9 @@ |
452 | 452 | 'ep-disenroll-button' => 'Disenroll', |
453 | 453 | 'ep-disenroll-summary' => 'Why are you disenrolling?', |
454 | 454 | 'ep-disenroll-cancel' => 'Cancel', |
| 455 | + 'ep-disenroll-fail' => 'Something went wrong - could not disenroll you from this course.', |
| 456 | + 'ep-disenroll-success' => 'You have been successfully disenrolled from this course!', |
| 457 | + 'ep-disenroll-returnto' => 'Return to [[Course:$1|course $1]].', |
455 | 458 | |
456 | 459 | // Special:MyCourses |
457 | 460 | 'ep-mycourses-enrolled' => 'You have successfully enrolled for $1 at $2.', |