Index: trunk/extensions/EducationProgram/EducationProgram.php |
— | — | @@ -113,6 +113,7 @@ |
114 | 114 | $wgAutoloadClasses['SpecialStudent'] = dirname( __FILE__ ) . '/specials/SpecialStudent.php'; |
115 | 115 | $wgAutoloadClasses['SpecialStudents'] = dirname( __FILE__ ) . '/specials/SpecialStudents.php'; |
116 | 116 | $wgAutoloadClasses['SpecialEnroll'] = dirname( __FILE__ ) . '/specials/SpecialEnroll.php'; |
| 117 | +$wgAutoloadClasses['SpecialDisenroll'] = dirname( __FILE__ ) . '/specials/SpecialDisenroll.php'; |
117 | 118 | $wgAutoloadClasses['SpecialCAs'] = dirname( __FILE__ ) . '/specials/SpecialCAs.php'; |
118 | 119 | $wgAutoloadClasses['SpecialOAs'] = dirname( __FILE__ ) . '/specials/SpecialOAs.php'; |
119 | 120 | //$wgAutoloadClasses['SpecialCA'] = dirname( __FILE__ ) . '/specials/SpecialCA.php'; |
— | — | @@ -129,6 +130,7 @@ |
130 | 131 | $wgSpecialPages['Courses'] = 'SpecialCourses'; |
131 | 132 | $wgSpecialPages['EducationProgram'] = 'SpecialEducationProgram'; |
132 | 133 | $wgSpecialPages['Enroll'] = 'SpecialEnroll'; |
| 134 | +$wgSpecialPages['Disenroll'] = 'SpecialDisenroll'; |
133 | 135 | $wgSpecialPages['CampusAmbassadors'] = 'SpecialCAs'; |
134 | 136 | $wgSpecialPages['OnlineAmbassadors'] = 'SpecialOAs'; |
135 | 137 | //$wgSpecialPages['CampusAmbassador'] = 'SpecialCA'; |
— | — | @@ -148,6 +150,8 @@ |
149 | 151 | //$wgSpecialPageGroups['OnlineAmbassador'] = 'education'; |
150 | 152 | $wgSpecialPageGroups['CampusAmbassadorProfile'] = 'education'; |
151 | 153 | $wgSpecialPageGroups['OnlineAmbassadorProfile'] = 'education'; |
| 154 | +$wgSpecialPageGroups['Enroll'] = 'education'; |
| 155 | +$wgSpecialPageGroups['Disenroll'] = 'education'; |
152 | 156 | |
153 | 157 | define( 'EP_STUDENT', 0 ); |
154 | 158 | define( 'EP_INSTRUCTOR', 1 ); |
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.alias.php |
— | — | @@ -23,6 +23,7 @@ |
24 | 24 | 'Courses' => array( 'Courses' ), |
25 | 25 | 'EducationProgram' => array( 'EducationProgram' ), |
26 | 26 | 'Enroll' => array( 'Enroll' ), |
| 27 | + 'Disenroll' => array( 'Disenroll' ), |
27 | 28 | 'CampusAmbassadors' => array( 'CampusAmbassadors' ), |
28 | 29 | 'OnlineAmbassadors' => array( 'OnlineAmbassadors' ), |
29 | 30 | // 'CampusAmbassador' => array( 'CampusAmbassador' ), |
Index: trunk/extensions/EducationProgram/specials/SpecialDisenroll.php |
— | — | @@ -0,0 +1,105 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Disenrollment page for students. |
| 6 | + * |
| 7 | + * @since 0.1 |
| 8 | + * |
| 9 | + * @file SpecialDisenroll.php |
| 10 | + * @ingroup EducationProgram |
| 11 | + * |
| 12 | + * @licence GNU GPL v3 or later |
| 13 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 14 | + */ |
| 15 | +class SpecialDisenroll extends SpecialEPPage { |
| 16 | + |
| 17 | + /** |
| 18 | + * @since 0.1 |
| 19 | + * @var EPCourse |
| 20 | + */ |
| 21 | + protected $course; |
| 22 | + |
| 23 | + /** |
| 24 | + * @since 0.1 |
| 25 | + * @var string|false |
| 26 | + */ |
| 27 | + protected $token = false; |
| 28 | + |
| 29 | + /** |
| 30 | + * Constructor. |
| 31 | + * |
| 32 | + * @since 0.1 |
| 33 | + */ |
| 34 | + public function __construct() { |
| 35 | + parent::__construct( 'Disenroll', '', false ); |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * Main method. |
| 40 | + * |
| 41 | + * @since 0.1 |
| 42 | + * |
| 43 | + * @param string $subPage |
| 44 | + */ |
| 45 | + public function execute( $subPage ) { |
| 46 | + parent::execute( $subPage ); |
| 47 | + |
| 48 | + $args = explode( '/', $this->subPage, 2 ); |
| 49 | + |
| 50 | + if ( $args[0] === '' ) { |
| 51 | + $this->showWarning( wfMessage( 'ep-disenroll-no-name' ) ); |
| 52 | + } |
| 53 | + else { |
| 54 | + $course = EPCourse::get( $args[0] ); |
| 55 | + |
| 56 | + if ( $course === false ) { |
| 57 | + $this->showWarning( wfMessage( 'ep-disenroll-invalid-name' ) ); |
| 58 | + } |
| 59 | + else { |
| 60 | + if ( EPStudent::newFromUser( $this->getUser() )->hasCourse( array( 'id' => $course->getId() ) ) ) { |
| 61 | + if ( $course->getStatus() === 'current' ) { |
| 62 | + if ( $this->getUser()->isLoggedIn() ) { |
| 63 | + $req = $this->getRequest(); |
| 64 | + |
| 65 | + if ( $req->wasPosted() && $this->getUser()->matchEditToken( $req->getText( 'disenrollEditToken' ) ) ) { |
| 66 | + $this->doDisenroll( $course ); |
| 67 | + } |
| 68 | + else { |
| 69 | + $this->showDisenrollForm( $course ); |
| 70 | + } |
| 71 | + } |
| 72 | + else { |
| 73 | + $this->showLoginLink(); |
| 74 | + } |
| 75 | + } |
| 76 | + else { |
| 77 | + $this->showWarning( wfMessage( 'ep-disenroll-course-passed' ) ); |
| 78 | + } |
| 79 | + } |
| 80 | + else { |
| 81 | + $this->showWarning( wfMessage( 'ep-disenroll-not-enrolled' ) ); |
| 82 | + } |
| 83 | + } |
| 84 | + } |
| 85 | + } |
| 86 | + |
| 87 | + protected function showLoginLink() { |
| 88 | + $this->getOutput()->addHTML( Linker::linkKnown( |
| 89 | + SpecialPage::getTitleFor( 'Userlogin' ), |
| 90 | + wfMsgHtml( 'ep-enroll-login-and-enroll' ), |
| 91 | + array(), |
| 92 | + array( |
| 93 | + 'returnto' => $this->getTitle( $this->subPage )->getFullText() |
| 94 | + ) |
| 95 | + ) ); |
| 96 | + } |
| 97 | + |
| 98 | + protected function showDisenrollForm( EPCourse $course ) { |
| 99 | + // TODO |
| 100 | + } |
| 101 | + |
| 102 | + protected function doDisenroll( EPCourse $course ) { |
| 103 | + // TODO |
| 104 | + } |
| 105 | + |
| 106 | +} |
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php |
— | — | @@ -34,6 +34,7 @@ |
35 | 35 | 'ep-tab-create' => 'Create', |
36 | 36 | 'ep-tab-history' => 'View history', |
37 | 37 | 'ep-tab-enroll' => 'Enroll', |
| 38 | + 'ep-tab-disenroll' => 'Disenroll', |
38 | 39 | |
39 | 40 | // Tooltips |
40 | 41 | 'tooltip-ep-form-save' => 'Save', |
— | — | @@ -167,6 +168,7 @@ |
168 | 169 | 'special-campusambassadors' => 'Campus ambassadors', |
169 | 170 | 'special-onlineambassador' => 'Online ambassador', |
170 | 171 | 'special-campusambassador' => 'Campus ambassador', |
| 172 | + 'special-disenroll' => 'Disenroll', |
171 | 173 | |
172 | 174 | // Course statuses |
173 | 175 | 'ep-course-status-passed' => 'Passed', |
Index: trunk/extensions/EducationProgram/api/ApiEnlist.php |
— | — | @@ -33,7 +33,7 @@ |
34 | 34 | $this->dieUsage( wfMsg( 'ep-enlist-invalid-user' ), 'invalid-user' ); |
35 | 35 | } |
36 | 36 | |
37 | | - if ( !$this->userIsAllowed( $userId, $params['role'] ) ) { |
| 37 | + if ( !$this->userIsAllowed( $userId, $params['role'], $params['subaction'] ) ) { |
38 | 38 | $this->dieUsageMsg( array( 'badaccess-groups' ) ); |
39 | 39 | } |
40 | 40 | |
— | — | @@ -77,13 +77,19 @@ |
78 | 78 | * |
79 | 79 | * @param integer $userId User id of the mentor affected |
80 | 80 | * @param string $role |
| 81 | + * @param string $subAction |
81 | 82 | * |
82 | 83 | * @return boolean |
83 | 84 | */ |
84 | | - protected function userIsAllowed( $userId, $role ) { |
| 85 | + protected function userIsAllowed( $userId, $role, $subAction ) { |
85 | 86 | $user = $this->getUser(); |
86 | 87 | $isSelf = $user->getId() === $userId; |
| 88 | + $isRemove = $subAction === 'remove'; |
87 | 89 | |
| 90 | + if ( $isSelf && $isRemove ) { |
| 91 | + return true; |
| 92 | + } |
| 93 | + |
88 | 94 | switch ( $role ) { |
89 | 95 | case 'student': |
90 | 96 | return $user->isAllowed( 'ep-enroll' ) && $isSelf; |
Index: trunk/extensions/EducationProgram/EducationProgram.hooks.php |
— | — | @@ -193,7 +193,9 @@ |
194 | 194 | public static function onSpecialPageTabs( SkinTemplate &$sktemplate, array &$links ) { |
195 | 195 | $textParts = SpecialPageFactory::resolveAlias( $sktemplate->getTitle()->getText() ); |
196 | 196 | |
197 | | - if ( $textParts[0] === 'Enroll' && !is_null( $textParts[1] ) && trim( $textParts[1] ) !== '' ) { |
| 197 | + if ( in_array( $textParts[0], array( 'Enroll', 'Disenroll' ) ) |
| 198 | + && !is_null( $textParts[1] ) && trim( $textParts[1] ) !== '' ) { |
| 199 | + |
198 | 200 | // Remove the token from the title if needed. |
199 | 201 | if ( !$sktemplate->getRequest()->getCheck( 'wptoken' ) ) { |
200 | 202 | $textParts[1] = explode( '/', $textParts[1] ); |
— | — | @@ -264,12 +266,13 @@ |
265 | 267 | 'text' => wfMsg( 'ep-tab-history' ), |
266 | 268 | 'href' => $title->getLocalUrl( array( 'action' => 'history' ) ) |
267 | 269 | ); |
268 | | - |
| 270 | + |
269 | 271 | if ( $title->getNamespace() === EP_NS_COURSE ) { |
| 272 | + $student = EPStudent::newFromUser( $user ); |
| 273 | + $hasCourse = $student !== false && $student->hasCourse( array( 'name' => $title->getText() ) ); |
| 274 | + |
270 | 275 | if ( $user->isAllowed( 'ep-enroll' ) ) { |
271 | | - $student = EPStudent::newFromUser( $user ); |
272 | | - |
273 | | - if ( $student === false || !$student->hasCourse( array( 'name' => $title->getText() ) ) ) { |
| 276 | + if ( !$hasCourse ) { |
274 | 277 | $links['views']['enroll'] = array( |
275 | 278 | 'class' => $isSpecial ? 'selected' : false, |
276 | 279 | 'text' => wfMsg( 'ep-tab-enroll' ), |
— | — | @@ -277,6 +280,14 @@ |
278 | 281 | ); |
279 | 282 | } |
280 | 283 | } |
| 284 | + |
| 285 | + if ( $hasCourse ) { |
| 286 | + $links[$isSpecial ? 'views' : 'actions']['disenroll'] = array( |
| 287 | + 'class' => $isSpecial ? 'selected' : false, |
| 288 | + 'text' => wfMsg( 'ep-tab-disenroll' ), |
| 289 | + 'href' => SpecialPage::getTitleFor( 'Disenroll', $title->getText() )->getLocalURL() |
| 290 | + ); |
| 291 | + } |
281 | 292 | } |
282 | 293 | } |
283 | 294 | } |