Index: trunk/extensions/EducationProgram/specials/SpecialMyCourses.php |
— | — | @@ -88,6 +88,18 @@ |
89 | 89 | protected function displayCourses() { |
90 | 90 | if ( $this->getRequest()->getCheck( 'enrolled' ) ) { |
91 | 91 | 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 | + } |
92 | 104 | } |
93 | 105 | |
94 | 106 | $this->displayRoleAssociation( 'EPStudent' ); |
— | — | @@ -106,44 +118,19 @@ |
107 | 119 | } |
108 | 120 | |
109 | 121 | /** |
110 | | - * Display the courses the user is enrolled in (if any). |
| 122 | + * Display the courses the user is enrolled in. |
111 | 123 | * |
112 | 124 | * @since 0.1 |
| 125 | + * |
| 126 | + * @param array $courses |
113 | 127 | */ |
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] ); |
137 | 131 | } |
138 | | - |
139 | | - if ( count( $courseIds ) === 1 ) { |
140 | | - $course = $courses[0]; |
141 | | - $course->loadFields(); |
142 | | - $this->displayCourse( $course ); |
| 132 | + else { |
| 133 | + $this->displayCourseList( $courses ); |
143 | 134 | } |
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 | | - } |
148 | 135 | } |
149 | 136 | |
150 | 137 | /** |
— | — | @@ -163,12 +150,7 @@ |
164 | 151 | $this->getOutput()->addElement( 'h2', array(), $message ); |
165 | 152 | |
166 | 153 | 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 ); |
173 | 155 | } |
174 | 156 | elseif ( $class == 'EPInstructor' ) { |
175 | 157 | $this->displayCourseTables( $courses ); |