r112343 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112342‎ | r112343 | r112344 >
Date:19:47, 24 February 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
re-added enrollment success message
Modified paths:
  • /trunk/extensions/EducationProgram/specials/SpecialMyCourses.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/specials/SpecialMyCourses.php
@@ -88,6 +88,18 @@
8989 protected function displayCourses() {
9090 if ( $this->getRequest()->getCheck( 'enrolled' ) ) {
9191 EPStudents::singleton()->setReadDb( DB_MASTER );
 92+
 93+ $course = EPCourses::singleton()->selectRow( null, array( 'id' => $this->getRequest()->getInt( 'enrolled' ) ) );
 94+
 95+ if ( $course !== false && in_array( $this->getUser()->getId(), $course->getField( 'students' ) ) ) {
 96+ $this->showSuccess( wfMessage(
 97+ 'ep-mycourses-enrolled',
 98+ array(
 99+ Message::rawParam( $course->getLink() ),
 100+ Message::rawParam( $course->getOrg()->getLink() )
 101+ )
 102+ ) );
 103+ }
92104 }
93105
94106 $this->displayRoleAssociation( 'EPStudent' );
@@ -106,44 +118,19 @@
107119 }
108120
109121 /**
110 - * Display the courses the user is enrolled in (if any).
 122+ * Display the courses the user is enrolled in.
111123 *
112124 * @since 0.1
 125+ *
 126+ * @param array $courses
113127 */
114 - protected function displayEnrollment() {
115 - $student = EPStudent::newFromUser( $this->getUser() );
116 -
117 - $courses = $student->getCourses( 'id' );
118 -
119 - $courseIds = array_map(
120 - function( EPCourse $course ) {
121 - return $course->getId();
122 - },
123 - $courses
124 - );
125 -
126 - if ( $this->getRequest()->getCheck( 'enrolled' ) && in_array( $this->getRequest()->getInt( 'enrolled' ), $courseIds ) ) {
127 - $course = EPCourses::singleton()->selectRow(
128 - array( 'name', 'org_id' ),
129 - array( 'id' => $this->getRequest()->getInt( 'enrolled' ) )
130 - );
131 -
132 - $this->showSuccess( wfMessage(
133 - 'ep-mycourses-enrolled',
134 - $course->getField( 'name' ),
135 - $course->getOrg()->getField( 'name' )
136 - ) );
 128+ protected function displayEnrollment( array $courses ) {
 129+ if ( count( $courses ) == 1 ) {
 130+ $this->displayCourse( $courses[0] );
137131 }
138 -
139 - if ( count( $courseIds ) === 1 ) {
140 - $course = $courses[0];
141 - $course->loadFields();
142 - $this->displayCourse( $course );
 132+ else {
 133+ $this->displayCourseList( $courses );
143134 }
144 - elseif ( count( $courseIds ) > 1 ) {
145 - $this->getOutput()->addElement( 'h2', array(), wfMsg( 'ep-mycourses-enrollment' ) );
146 - EPCourse::displayPager( $this->getContext(), array( 'id' => $courseIds ), true, 'enrollment' );
147 - }
148135 }
149136
150137 /**
@@ -163,12 +150,7 @@
164151 $this->getOutput()->addElement( 'h2', array(), $message );
165152
166153 if ( $class == 'EPStudent' ) {
167 - if ( count( $courses ) == 1 ) {
168 - $this->displayCourse( $courses[0] );
169 - }
170 - else {
171 - $this->displayCourseList( $courses );
172 - }
 154+ $this->displayEnrollment( $courses );
173155 }
174156 elseif ( $class == 'EPInstructor' ) {
175157 $this->displayCourseTables( $courses );

Status & tagging log