r109766 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109765‎ | r109766 | r109767 >
Date:21:54, 22 January 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
fixed several issues with enrollment and mycourses and added enrollment tab to course pages
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.hooks.php (modified) (history)
  • /trunk/extensions/EducationProgram/EducationProgram.i18n.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPCourse.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPStudent.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPStudentPager.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialEPFormPage.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialEnroll.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialMyCourses.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/specials/SpecialMyCourses.php
@@ -1,8 +1,8 @@
22 <?php
33
44 /**
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
77 * name, info for that course is shown.
88 *
99 * @since 0.1
@@ -21,7 +21,7 @@
2222 * @since 0.1
2323 */
2424 public function __construct() {
25 - parent::__construct( 'MyCourses', 'ep-enroll' );
 25+ parent::__construct( 'MyCourses' );
2626 }
2727
2828 /**
@@ -67,7 +67,7 @@
6868 protected function displayCourses( EPStudent $student ) {
6969 $out = $this->getOutput();
7070
71 - if ( $student->hasTerm() ) {
 71+ if ( $student->hasCourse() ) {
7272 if ( $this->getRequest()->getCheck( 'enrolled' ) ) {
7373 $course = EPCourse::selectRow( null, array( 'id' => $this->getRequest()->getInt( 'enrolled' ) ) );
7474
@@ -80,8 +80,8 @@
8181 }
8282 }
8383
84 - $currentCourses = $student->getCurrentMasterCourses();
85 - $passedCourses = $student->getPassedMasterCourses();
 84+ $currentCourses = $student->getCoursesWithState( 'current' );
 85+ $passedCourses = $student->getCoursesWithState( 'passed' );
8686
8787 if ( count( $currentCourses ) > 0 ) {
8888 $out->addHTML( Html::element( 'h2', array(), wfMsg( 'ep-mycourses-current' ) ) );
@@ -105,7 +105,7 @@
106106 *
107107 * @param array $courses
108108 */
109 - protected function displayCoursesList( array /* of EPMC */ $courses ) {
 109+ protected function displayCoursesList( array /* of EPCourse */ $courses ) {
110110 $out = $this->getOutput();
111111
112112 $out->addHTML( Xml::openElement(
@@ -122,12 +122,12 @@
123123
124124 $out->addHTML( '<tbody>' );
125125
126 - foreach ( $courses as /* EPMC */ $course ) {
 126+ foreach ( $courses as /* EPCourse */ $course ) {
127127 $fields = array();
128128
129129 $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>'
132132 );
133133
134134 $fields[] = Linker::link(
@@ -158,7 +158,7 @@
159159 $out = $this->getOutput();
160160
161161 $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() ) );
163163
164164 if ( $course !== false && count( $terms ) > 0 ) {
165165 $out->addWikiMsg( 'ep-mycourses-show-all' );
Index: trunk/extensions/EducationProgram/specials/SpecialEnroll.php
@@ -69,7 +69,7 @@
7070 $this->showEnrollmentView( $course );
7171 }
7272 else {
73 - if ( $token !== '' ) {
 73+ if ( $token !== '' ) {q($token);
7474 $this->showWarning( wfMessage( 'ep-enroll-invalid-token' ) );
7575 }
7676
@@ -84,7 +84,7 @@
8585
8686 /**
8787 * 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.
8989 *
9090 * @since 0.1
9191 *
@@ -203,7 +203,7 @@
204204 }
205205
206206 /**
207 - * Just enroll the user in the term.
 207+ * Just enroll the user in the course.
208208 *
209209 * @since 0.1
210210 *
@@ -335,7 +335,7 @@
336336
337337 $this->getUser()->saveSettings();
338338
339 - if ( $this->doEnroll( $this->term ) ) {
 339+ if ( $this->doEnroll( $this->course ) ) {
340340 return true;
341341 }
342342 else {
@@ -351,7 +351,7 @@
352352 public function onSuccess() {
353353 $this->getOutput()->redirect(
354354 SpecialPage::getTitleFor( 'MyCourses' )->getLocalURL( array(
355 - 'enrolled' => $this->term->getId()
 355+ 'enrolled' => $this->course->getId()
356356 ) )
357357 );
358358 }
Index: trunk/extensions/EducationProgram/specials/SpecialEPFormPage.php
@@ -341,7 +341,7 @@
342342 $title = SpecialPage::getTitleFor( $parts[0], count( $parts ) === 2 ? $parts[1] : false )->getLocalURL();
343343 }
344344 else {
345 - $title = SpecialPage::getTitleFor( $this->itemPage )->getLocalURL();
 345+ $title = SpecialPage::getTitleFor( $this->itemPage, $this->subPage )->getLocalURL();
346346 }
347347
348348 $this->getOutput()->redirect( $title );
Index: trunk/extensions/EducationProgram/includes/EPStudentPager.php
@@ -85,7 +85,7 @@
8686 function( EPCourse $course ) {
8787 return $course->getLink();
8888 },
89 - $this->currentObject->getCurrentCourses( 'name' )
 89+ $this->currentObject->getCoursesWithState( 'current', 'id' )
9090 ) );
9191 break;
9292 }
Index: trunk/extensions/EducationProgram/includes/EPStudent.php
@@ -83,7 +83,7 @@
8484 'ep_students_per_course',
8585 array(
8686 'spc_student_id' => $this->getId(),
87 - 'spc_term_id' => $course->getId(),
 87+ 'spc_course_id' => $course->getId(),
8888 )
8989 ) && $success;
9090 }
@@ -130,6 +130,37 @@
131131 }
132132
133133 /**
 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+ /**
134165 * Returns the master courses this student is linked to (via courses).
135166 *
136167 * @since 0.1
Index: trunk/extensions/EducationProgram/includes/EPCourse.php
@@ -240,7 +240,7 @@
241241 }
242242
243243 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;
245245 }
246246
247247 return $success;
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php
@@ -24,6 +24,12 @@
2525 'ep-item-summary' => 'Summary',
2626 'ep-toplink' => 'My courses',
2727
 28+ // Tabs
 29+ 'ep-tab-view' => 'View',
 30+ 'ep-tab-edit' => 'Edit',
 31+ 'ep-tab-history' => 'history',
 32+ 'ep-tab-enroll' => 'Enroll',
 33+
2834 // Tooltips
2935 'tooltip-ep-form-save' => 'Save',
3036 'tooltip-ep-edit-institution' => 'Edit this institution',
Index: trunk/extensions/EducationProgram/EducationProgram.hooks.php
@@ -151,8 +151,6 @@
152152 public static function onSpecialPageTabs( SkinTemplate &$sktemplate, array &$links ) {
153153 $viewLinks = $links['views'];
154154
155 - $title = $sktemplate->getTitle();
156 -
157155 // The Title getBaseText and getSubpageText methods only do what we want when
158156 // the special pages NS is in teh list of NS with subpages.
159157 $textParts = SpecialPageFactory::resolveAlias( $sktemplate->getTitle()->getText() );
@@ -196,7 +194,7 @@
197195
198196 // TODO: messages
199197 if ( $specialSet !== false ) {
200 - $editRight = $editRights[$specialSet['edit']];
 198+ $canonicalSet = $specialSet;
201199
202200 foreach ( $specialSet as &$special ) {
203201 $special = SpecialPageFactory::getLocalNameFor( $special );
@@ -204,24 +202,40 @@
205203
206204 $viewLinks['view'] = array(
207205 'class' => $type === 'view' ? 'selected' : false,
208 - 'text' => wfMsg( 'vector-view-view' ),
 206+ 'text' => wfMsg( 'ep-tab-view' ),
209207 'href' => SpecialPage::getTitleFor( $specialSet['view'], $textParts[1] )->getLocalUrl()
210208 );
211209
212 - if ( $sktemplate->getUser()->isAllowed( $editRight ) ) {
 210+ if ( $sktemplate->getUser()->isAllowed( $editRights[$canonicalSet['edit']] ) ) {
213211 $viewLinks['edit'] = array(
214212 'class' => $type === 'edit' ? 'selected' : false,
215 - 'text' => wfMsg( 'vector-view-edit' ),
 213+ 'text' => wfMsg( 'ep-tab-edit' ),
216214 'href' => SpecialPage::getTitleFor( $specialSet['edit'], $textParts[1] )->getLocalUrl()
217215 );
218216 }
219217
220218 $viewLinks['history'] = array(
221219 'class' => $type === 'history' ? 'selected' : false,
222 - 'text' => wfMsg( 'vector-view-history' ),
 220+ 'text' => wfMsg( 'ep-tab-history' ),
223221 'href' => '' // TODO
224222 //SpecialPage::getTitleFor( $specialSet['history'], $textParts[1] )->getLocalUrl()
225223 );
 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+ }
226240 }
227241
228242 $links['views'] = $viewLinks;

Status & tagging log