Index: trunk/extensions/EducationProgram/specials/SpecialMyCourses.php |
— | — | @@ -1,8 +1,8 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | /** |
5 | | - * Special page listing the courses that have at least one term in which the current user |
6 | | - * is or has been enrolled. When a subpage param is provided, and it's a valid course |
| 5 | + * Special page listing the courses in which the current user is enrolled. |
| 6 | + * When a subpage param is provided, and it's a valid course |
7 | 7 | * name, info for that course is shown. |
8 | 8 | * |
9 | 9 | * @since 0.1 |
— | — | @@ -21,7 +21,7 @@ |
22 | 22 | * @since 0.1 |
23 | 23 | */ |
24 | 24 | public function __construct() { |
25 | | - parent::__construct( 'MyCourses', 'ep-enroll' ); |
| 25 | + parent::__construct( 'MyCourses' ); |
26 | 26 | } |
27 | 27 | |
28 | 28 | /** |
— | — | @@ -67,7 +67,7 @@ |
68 | 68 | protected function displayCourses( EPStudent $student ) { |
69 | 69 | $out = $this->getOutput(); |
70 | 70 | |
71 | | - if ( $student->hasTerm() ) { |
| 71 | + if ( $student->hasCourse() ) { |
72 | 72 | if ( $this->getRequest()->getCheck( 'enrolled' ) ) { |
73 | 73 | $course = EPCourse::selectRow( null, array( 'id' => $this->getRequest()->getInt( 'enrolled' ) ) ); |
74 | 74 | |
— | — | @@ -80,8 +80,8 @@ |
81 | 81 | } |
82 | 82 | } |
83 | 83 | |
84 | | - $currentCourses = $student->getCurrentMasterCourses(); |
85 | | - $passedCourses = $student->getPassedMasterCourses(); |
| 84 | + $currentCourses = $student->getCoursesWithState( 'current' ); |
| 85 | + $passedCourses = $student->getCoursesWithState( 'passed' ); |
86 | 86 | |
87 | 87 | if ( count( $currentCourses ) > 0 ) { |
88 | 88 | $out->addHTML( Html::element( 'h2', array(), wfMsg( 'ep-mycourses-current' ) ) ); |
— | — | @@ -105,7 +105,7 @@ |
106 | 106 | * |
107 | 107 | * @param array $courses |
108 | 108 | */ |
109 | | - protected function displayCoursesList( array /* of EPMC */ $courses ) { |
| 109 | + protected function displayCoursesList( array /* of EPCourse */ $courses ) { |
110 | 110 | $out = $this->getOutput(); |
111 | 111 | |
112 | 112 | $out->addHTML( Xml::openElement( |
— | — | @@ -122,12 +122,12 @@ |
123 | 123 | |
124 | 124 | $out->addHTML( '<tbody>' ); |
125 | 125 | |
126 | | - foreach ( $courses as /* EPMC */ $course ) { |
| 126 | + foreach ( $courses as /* EPCourse */ $course ) { |
127 | 127 | $fields = array(); |
128 | 128 | |
129 | 129 | $fields[] = Linker::link( |
130 | | - $this->getTitle( $course->getField( 'name' ) ), |
131 | | - '<b>' . htmlspecialchars( $course->getField( 'name' ) ) . '</b>' |
| 130 | + $this->getTitle( $course->getMasterCourse()->getField( 'name' ) ), |
| 131 | + '<b>' . htmlspecialchars( $course->getMasterCourse()->getField( 'name' ) ) . '</b>' |
132 | 132 | ); |
133 | 133 | |
134 | 134 | $fields[] = Linker::link( |
— | — | @@ -158,7 +158,7 @@ |
159 | 159 | $out = $this->getOutput(); |
160 | 160 | |
161 | 161 | $course = EPCourse::selectRow( null, array( 'name' => $courseName ) ); |
162 | | - $terms = $student->getTerms( null, array( 'course_id' => $course->getId() ) ); |
| 162 | + $terms = $student->getCourses( null, array( 'course_id' => $course->getId() ) ); |
163 | 163 | |
164 | 164 | if ( $course !== false && count( $terms ) > 0 ) { |
165 | 165 | $out->addWikiMsg( 'ep-mycourses-show-all' ); |
Index: trunk/extensions/EducationProgram/specials/SpecialEnroll.php |
— | — | @@ -69,7 +69,7 @@ |
70 | 70 | $this->showEnrollmentView( $course ); |
71 | 71 | } |
72 | 72 | else { |
73 | | - if ( $token !== '' ) { |
| 73 | + if ( $token !== '' ) {q($token); |
74 | 74 | $this->showWarning( wfMessage( 'ep-enroll-invalid-token' ) ); |
75 | 75 | } |
76 | 76 | |
— | — | @@ -84,7 +84,7 @@ |
85 | 85 | |
86 | 86 | /** |
87 | 87 | * Shows the actual enrollment view. |
88 | | - * Should only be called after everything checks out, ie the user can enroll in the term. |
| 88 | + * Should only be called after everything checks out, ie the user can enroll in the course. |
89 | 89 | * |
90 | 90 | * @since 0.1 |
91 | 91 | * |
— | — | @@ -203,7 +203,7 @@ |
204 | 204 | } |
205 | 205 | |
206 | 206 | /** |
207 | | - * Just enroll the user in the term. |
| 207 | + * Just enroll the user in the course. |
208 | 208 | * |
209 | 209 | * @since 0.1 |
210 | 210 | * |
— | — | @@ -335,7 +335,7 @@ |
336 | 336 | |
337 | 337 | $this->getUser()->saveSettings(); |
338 | 338 | |
339 | | - if ( $this->doEnroll( $this->term ) ) { |
| 339 | + if ( $this->doEnroll( $this->course ) ) { |
340 | 340 | return true; |
341 | 341 | } |
342 | 342 | else { |
— | — | @@ -351,7 +351,7 @@ |
352 | 352 | public function onSuccess() { |
353 | 353 | $this->getOutput()->redirect( |
354 | 354 | SpecialPage::getTitleFor( 'MyCourses' )->getLocalURL( array( |
355 | | - 'enrolled' => $this->term->getId() |
| 355 | + 'enrolled' => $this->course->getId() |
356 | 356 | ) ) |
357 | 357 | ); |
358 | 358 | } |
Index: trunk/extensions/EducationProgram/specials/SpecialEPFormPage.php |
— | — | @@ -341,7 +341,7 @@ |
342 | 342 | $title = SpecialPage::getTitleFor( $parts[0], count( $parts ) === 2 ? $parts[1] : false )->getLocalURL(); |
343 | 343 | } |
344 | 344 | else { |
345 | | - $title = SpecialPage::getTitleFor( $this->itemPage )->getLocalURL(); |
| 345 | + $title = SpecialPage::getTitleFor( $this->itemPage, $this->subPage )->getLocalURL(); |
346 | 346 | } |
347 | 347 | |
348 | 348 | $this->getOutput()->redirect( $title ); |
Index: trunk/extensions/EducationProgram/includes/EPStudentPager.php |
— | — | @@ -85,7 +85,7 @@ |
86 | 86 | function( EPCourse $course ) { |
87 | 87 | return $course->getLink(); |
88 | 88 | }, |
89 | | - $this->currentObject->getCurrentCourses( 'name' ) |
| 89 | + $this->currentObject->getCoursesWithState( 'current', 'id' ) |
90 | 90 | ) ); |
91 | 91 | break; |
92 | 92 | } |
Index: trunk/extensions/EducationProgram/includes/EPStudent.php |
— | — | @@ -83,7 +83,7 @@ |
84 | 84 | 'ep_students_per_course', |
85 | 85 | array( |
86 | 86 | 'spc_student_id' => $this->getId(), |
87 | | - 'spc_term_id' => $course->getId(), |
| 87 | + 'spc_course_id' => $course->getId(), |
88 | 88 | ) |
89 | 89 | ) && $success; |
90 | 90 | } |
— | — | @@ -130,6 +130,37 @@ |
131 | 131 | } |
132 | 132 | |
133 | 133 | /** |
| 134 | + * Get the courses with a certain state. |
| 135 | + * States can be 'current', 'passed' and 'planned' |
| 136 | + * |
| 137 | + * @since 0.1 |
| 138 | + * |
| 139 | + * @param string $state |
| 140 | + * @param array|null $fields |
| 141 | + * @param array $conditions |
| 142 | + * |
| 143 | + * @return array of EPCourse |
| 144 | + */ |
| 145 | + public function getCoursesWithState( $state, $fields = null, array $conditions = array() ) { |
| 146 | + $now = wfGetDB( DB_SLAVE )->addQuotes( wfTimestampNow() ); |
| 147 | + |
| 148 | + switch ( $state ) { |
| 149 | + case 'passed': |
| 150 | + $conditions[] = 'end < ' . $now; |
| 151 | + break; |
| 152 | + case 'planned': |
| 153 | + $conditions[] = 'start > ' . $now; |
| 154 | + break; |
| 155 | + case 'current': |
| 156 | + $conditions[] = 'end >= ' . $now; |
| 157 | + $conditions[] = 'start <= ' . $now; |
| 158 | + break; |
| 159 | + } |
| 160 | + |
| 161 | + return $this->getCourses( $fields, $conditions ); |
| 162 | + } |
| 163 | + |
| 164 | + /** |
134 | 165 | * Returns the master courses this student is linked to (via courses). |
135 | 166 | * |
136 | 167 | * @since 0.1 |
Index: trunk/extensions/EducationProgram/includes/EPCourse.php |
— | — | @@ -240,7 +240,7 @@ |
241 | 241 | } |
242 | 242 | |
243 | 243 | if ( $success ) { |
244 | | - $success = wfGetDB( DB_MASTER )->delete( 'ep_students_per_course', array( 'spc_term_id' => $id ) ) && $success; |
| 244 | + $success = wfGetDB( DB_MASTER )->delete( 'ep_students_per_course', array( 'spc_course_id' => $id ) ) && $success; |
245 | 245 | } |
246 | 246 | |
247 | 247 | return $success; |
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php |
— | — | @@ -24,6 +24,12 @@ |
25 | 25 | 'ep-item-summary' => 'Summary', |
26 | 26 | 'ep-toplink' => 'My courses', |
27 | 27 | |
| 28 | + // Tabs |
| 29 | + 'ep-tab-view' => 'View', |
| 30 | + 'ep-tab-edit' => 'Edit', |
| 31 | + 'ep-tab-history' => 'history', |
| 32 | + 'ep-tab-enroll' => 'Enroll', |
| 33 | + |
28 | 34 | // Tooltips |
29 | 35 | 'tooltip-ep-form-save' => 'Save', |
30 | 36 | 'tooltip-ep-edit-institution' => 'Edit this institution', |
Index: trunk/extensions/EducationProgram/EducationProgram.hooks.php |
— | — | @@ -151,8 +151,6 @@ |
152 | 152 | public static function onSpecialPageTabs( SkinTemplate &$sktemplate, array &$links ) { |
153 | 153 | $viewLinks = $links['views']; |
154 | 154 | |
155 | | - $title = $sktemplate->getTitle(); |
156 | | - |
157 | 155 | // The Title getBaseText and getSubpageText methods only do what we want when |
158 | 156 | // the special pages NS is in teh list of NS with subpages. |
159 | 157 | $textParts = SpecialPageFactory::resolveAlias( $sktemplate->getTitle()->getText() ); |
— | — | @@ -196,7 +194,7 @@ |
197 | 195 | |
198 | 196 | // TODO: messages |
199 | 197 | if ( $specialSet !== false ) { |
200 | | - $editRight = $editRights[$specialSet['edit']]; |
| 198 | + $canonicalSet = $specialSet; |
201 | 199 | |
202 | 200 | foreach ( $specialSet as &$special ) { |
203 | 201 | $special = SpecialPageFactory::getLocalNameFor( $special ); |
— | — | @@ -204,24 +202,40 @@ |
205 | 203 | |
206 | 204 | $viewLinks['view'] = array( |
207 | 205 | 'class' => $type === 'view' ? 'selected' : false, |
208 | | - 'text' => wfMsg( 'vector-view-view' ), |
| 206 | + 'text' => wfMsg( 'ep-tab-view' ), |
209 | 207 | 'href' => SpecialPage::getTitleFor( $specialSet['view'], $textParts[1] )->getLocalUrl() |
210 | 208 | ); |
211 | 209 | |
212 | | - if ( $sktemplate->getUser()->isAllowed( $editRight ) ) { |
| 210 | + if ( $sktemplate->getUser()->isAllowed( $editRights[$canonicalSet['edit']] ) ) { |
213 | 211 | $viewLinks['edit'] = array( |
214 | 212 | 'class' => $type === 'edit' ? 'selected' : false, |
215 | | - 'text' => wfMsg( 'vector-view-edit' ), |
| 213 | + 'text' => wfMsg( 'ep-tab-edit' ), |
216 | 214 | 'href' => SpecialPage::getTitleFor( $specialSet['edit'], $textParts[1] )->getLocalUrl() |
217 | 215 | ); |
218 | 216 | } |
219 | 217 | |
220 | 218 | $viewLinks['history'] = array( |
221 | 219 | 'class' => $type === 'history' ? 'selected' : false, |
222 | | - 'text' => wfMsg( 'vector-view-history' ), |
| 220 | + 'text' => wfMsg( 'ep-tab-history' ), |
223 | 221 | 'href' => '' // TODO |
224 | 222 | //SpecialPage::getTitleFor( $specialSet['history'], $textParts[1] )->getLocalUrl() |
225 | 223 | ); |
| 224 | + |
| 225 | + if ( $canonicalSet['view'] === 'Course' ) { |
| 226 | + $user = $sktemplate->getUser(); |
| 227 | + |
| 228 | + if ( $user->isAllowed( 'ep-enroll' ) ) { |
| 229 | + $student = EPStudent::newFromUser( $user ); |
| 230 | + |
| 231 | + if ( $student === false || !$student->hasCourse( array( 'id' => $textParts[1] ) ) ) { |
| 232 | + $viewLinks['enroll'] = array( |
| 233 | + 'class' => $type === 'enroll' ? 'selected' : false, |
| 234 | + 'text' => wfMsg( 'ep-tab-enroll' ), |
| 235 | + 'href' => SpecialPage::getTitleFor( 'Enroll', $textParts[1] )->getLocalUrl() |
| 236 | + ); |
| 237 | + } |
| 238 | + } |
| 239 | + } |
226 | 240 | } |
227 | 241 | |
228 | 242 | $links['views'] = $viewLinks; |