Index: trunk/extensions/EducationProgram/specials/SpecialMyCourses.php |
— | — | @@ -86,7 +86,11 @@ |
87 | 87 | * @since 0.1 |
88 | 88 | */ |
89 | 89 | protected function displayCourses() { |
90 | | - $this->displayEnrollment(); |
| 90 | + if ( $this->getRequest()->getCheck( 'enrolled' ) ) { |
| 91 | + EPStudents::singleton()->setReadDb( DB_MASTER ); |
| 92 | + } |
| 93 | + |
| 94 | + $this->displayRoleAssociation( 'EPStudent' ); |
91 | 95 | |
92 | 96 | if ( $this->getUser()->isAllowed( 'ep-instructor' ) ) { |
93 | 97 | $this->displayRoleAssociation( 'EPInstructor' ); |
— | — | @@ -107,10 +111,6 @@ |
108 | 112 | * @since 0.1 |
109 | 113 | */ |
110 | 114 | protected function displayEnrollment() { |
111 | | - if ( $this->getRequest()->getCheck( 'enrolled' ) ) { |
112 | | - EPStudents::singleton()->setReadDb( DB_MASTER ); |
113 | | - } |
114 | | - |
115 | 115 | $student = EPStudent::newFromUser( $this->getUser() ); |
116 | 116 | |
117 | 117 | $courses = $student->getCourses( 'id' ); |
— | — | @@ -155,24 +155,26 @@ |
156 | 156 | * @param $class The name of the EPIRole implementing class |
157 | 157 | */ |
158 | 158 | protected function displayRoleAssociation( $class ) { |
159 | | - $ambassador = $class::newFromUser( $this->getUser() ); |
160 | | - $courses = $ambassador->getCourses( array( 'id', 'name' ) ); |
| 159 | + $userRole = $class::newFromUser( $this->getUser() ); |
| 160 | + $courses = $userRole->getCourses( array( 'id', 'name', 'org_id' ) ); |
161 | 161 | |
162 | 162 | if ( count( $courses ) > 0 ) { |
163 | | - $this->getOutput()->addElement( 'h2', array(), wfMsg( 'ep-mycourses-courses-' . strtolower( $class ) ) ); |
| 163 | + $message = wfMsgExt( 'ep-mycourses-courses-' . strtolower( $class ), 'parsemag', count( $courses ), $this->getUser()->getName() ); |
| 164 | + $this->getOutput()->addElement( 'h2', array(), $message ); |
164 | 165 | |
165 | | - if ( $class == 'EPInstructor' ) { |
| 166 | + if ( $class == 'EPStudent' ) { |
| 167 | + if ( count( $courses ) == 1 ) { |
| 168 | + $this->displayCourse( $courses[0] ); |
| 169 | + } |
| 170 | + else { |
| 171 | + $this->displayCourseList( $courses ); |
| 172 | + } |
| 173 | + } |
| 174 | + elseif ( $class == 'EPInstructor' ) { |
166 | 175 | $this->displayCourseTables( $courses ); |
167 | 176 | } |
168 | 177 | else { |
169 | | - $courseIds = array_map( |
170 | | - function( EPCourse $course ) { |
171 | | - return $course->getId(); |
172 | | - }, |
173 | | - $courses |
174 | | - ); |
175 | | - |
176 | | - EPCourse::displayPager( $this->getContext(), array( 'id' => $courseIds ), true, $class ); |
| 178 | + $this->displayCoursePager( $courses, $class ); |
177 | 179 | } |
178 | 180 | } |
179 | 181 | else { |
— | — | @@ -191,6 +193,14 @@ |
192 | 194 | foreach ( $courses as /* EPCourse */ $course ) { |
193 | 195 | $out->addElement( 'h3', array(), $course->getField( 'name' ) ); |
194 | 196 | |
| 197 | + $out->addHTML( $this->msg( |
| 198 | + 'ep-mycourses-course-org-links', |
| 199 | + array( |
| 200 | + Message::rawParam( $course->getLink() ), |
| 201 | + Message::rawParam( $course->getOrg()->getLink() ) |
| 202 | + ) |
| 203 | + )->text() ); |
| 204 | + |
195 | 205 | $pager = new EPArticleTable( |
196 | 206 | $this->getContext(), |
197 | 207 | array( 'id' => $this->getUser()->getId() ), |
— | — | @@ -200,10 +210,10 @@ |
201 | 211 | if ( $pager->getNumRows() ) { |
202 | 212 | $out->addHTML( |
203 | 213 | $pager->getFilterControl() . |
204 | | - $pager->getNavigationBar() . |
205 | | - $pager->getBody() . |
206 | | - $pager->getNavigationBar() . |
207 | | - $pager->getMultipleItemControl() |
| 214 | + $pager->getNavigationBar() . |
| 215 | + $pager->getBody() . |
| 216 | + $pager->getNavigationBar() . |
| 217 | + $pager->getMultipleItemControl() |
208 | 218 | ); |
209 | 219 | } |
210 | 220 | } |
— | — | @@ -219,8 +229,6 @@ |
220 | 230 | protected function displayCourse( EPCourse $course ) { |
221 | 231 | $out = $this->getOutput(); |
222 | 232 | |
223 | | - $out->addElement( 'h2', array(), wfMsg( 'ep-mycourses-course-enrollment' ) ); |
224 | | - |
225 | 233 | $out->addHTML( $this->msg( |
226 | 234 | 'ep-mycourses-enrolledin', |
227 | 235 | array( |
— | — | @@ -245,12 +253,63 @@ |
246 | 254 | if ( $pager->getNumRows() ) { |
247 | 255 | $out->addHTML( |
248 | 256 | $pager->getFilterControl() . |
249 | | - $pager->getNavigationBar() . |
250 | | - $pager->getBody() . |
251 | | - $pager->getNavigationBar() . |
252 | | - $pager->getMultipleItemControl() |
| 257 | + $pager->getNavigationBar() . |
| 258 | + $pager->getBody() . |
| 259 | + $pager->getNavigationBar() . |
| 260 | + $pager->getMultipleItemControl() |
253 | 261 | ); |
254 | 262 | } |
255 | 263 | } |
256 | 264 | |
| 265 | + /** |
| 266 | + * Display enrollment info for a list of courses. |
| 267 | + * |
| 268 | + * @since 0.1 |
| 269 | + * |
| 270 | + * @param array $courses |
| 271 | + */ |
| 272 | + protected function displayCourseList( array $courses ) { |
| 273 | + foreach ( $courses as /* EPCourse */ $course ) { |
| 274 | + $this->getOutput()->addElement( 'h3', array(), $course->getField( 'name' ) ); |
| 275 | + $this->displayCourse( $course ); |
| 276 | + } |
| 277 | + } |
| 278 | + |
| 279 | + /** |
| 280 | + * Display a course pager with the provided courses. |
| 281 | + * |
| 282 | + * @since 0.1 |
| 283 | + * |
| 284 | + * @param array $courses |
| 285 | + * @param string $class |
| 286 | + */ |
| 287 | + protected function displayCoursePager( array $courses, $class ) { |
| 288 | + $out = $this->getOutput(); |
| 289 | + |
| 290 | + $courseIds = array_map( |
| 291 | + function( EPCourse $course ) { |
| 292 | + return $course->getId(); |
| 293 | + }, |
| 294 | + $courses |
| 295 | + ); |
| 296 | + |
| 297 | + $pager = new EPCoursePager( $this->getContext(), array( 'id' => $courseIds ), true ); |
| 298 | + |
| 299 | + $pager->setFilterPrefix( $class ); |
| 300 | + $pager->setEnableFilter( count( $courses ) > 1 ); |
| 301 | + |
| 302 | + if ( $pager->getNumRows() ) { |
| 303 | + $out->addHTML( |
| 304 | + $pager->getFilterControl() . |
| 305 | + $pager->getNavigationBar() . |
| 306 | + $pager->getBody() . |
| 307 | + $pager->getNavigationBar() |
| 308 | + ); |
| 309 | + } |
| 310 | + else { |
| 311 | + $out->addHTML( $pager->getFilterControl() ); |
| 312 | + $out->addWikiMsg( 'ep-courses-noresults' ); |
| 313 | + } |
| 314 | + } |
| 315 | + |
257 | 316 | } |
Index: trunk/extensions/EducationProgram/includes/EPPager.php |
— | — | @@ -42,6 +42,13 @@ |
43 | 43 | protected $context; |
44 | 44 | |
45 | 45 | /** |
| 46 | + * Enable filtering on the conditions of the filter control. |
| 47 | + * @since 0.1 |
| 48 | + * @var boolean |
| 49 | + */ |
| 50 | + protected $enableFilter = true; |
| 51 | + |
| 52 | + /** |
46 | 53 | * Constructor. |
47 | 54 | * |
48 | 55 | * @param IContextSource $context |
— | — | @@ -237,12 +244,14 @@ |
238 | 245 | protected function getConditions() { |
239 | 246 | $conds = array(); |
240 | 247 | |
241 | | - $filterOptions = $this->getFilterOptions(); |
242 | | - $this->addFilterValues( $filterOptions, false ); |
| 248 | + if ( $this->enableFilter ) { |
| 249 | + $filterOptions = $this->getFilterOptions(); |
| 250 | + $this->addFilterValues( $filterOptions, false ); |
243 | 251 | |
244 | | - foreach ( $filterOptions as $optionName => $optionData ) { |
245 | | - if ( array_key_exists( 'value', $optionData ) && $optionData['value'] !== '' ) { |
246 | | - $conds[$optionName] = $optionData['value']; |
| 252 | + foreach ( $filterOptions as $optionName => $optionData ) { |
| 253 | + if ( array_key_exists( 'value', $optionData ) && $optionData['value'] !== '' ) { |
| 254 | + $conds[$optionName] = $optionData['value']; |
| 255 | + } |
247 | 256 | } |
248 | 257 | } |
249 | 258 | |
— | — | @@ -285,6 +294,17 @@ |
286 | 295 | } |
287 | 296 | |
288 | 297 | /** |
| 298 | + * Sets if the filter control should be enabled. |
| 299 | + * |
| 300 | + * @since 0.1 |
| 301 | + * |
| 302 | + * @param $enableFilter |
| 303 | + */ |
| 304 | + public function setEnableFilter( $enableFilter ) { |
| 305 | + $this->enableFilter = $enableFilter; |
| 306 | + } |
| 307 | + |
| 308 | + /** |
289 | 309 | * Gets the HTML for a filter control. |
290 | 310 | * |
291 | 311 | * @since 0.1 |
— | — | @@ -294,6 +314,10 @@ |
295 | 315 | * @return string |
296 | 316 | */ |
297 | 317 | public function getFilterControl( $hideWhenNoResults = true ) { |
| 318 | + if ( !$this->enableFilter ) { |
| 319 | + return ''; |
| 320 | + } |
| 321 | + |
298 | 322 | $filterOptions = $this->getFilterOptions(); |
299 | 323 | |
300 | 324 | foreach ( $this->conds as $name => $value ) { |
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php |
— | — | @@ -526,15 +526,16 @@ |
527 | 527 | 'specialmycourses-summary-org' => 'Institution name', |
528 | 528 | 'ep-mycourses-not-a-student' => 'You are not enrolled in any [[Special:Courses|courses]].', |
529 | 529 | 'ep-mycourses-enrollment' => 'Courses I am enrolled in', |
530 | | - 'ep-mycourses-course-enrollment' => 'Course I am enrolled in', |
531 | 530 | 'ep-mycourses-login-first' => 'You need to login before you can view your courses.', |
532 | | - 'ep-mycourses-courses-epoa' => 'Courses I am Online Ambassador for', |
533 | | - 'ep-mycourses-courses-epca' => 'Courses I am Campus Ambassador for', |
534 | | - 'ep-mycourses-courses-epinstructor' => 'Courses I am Instructor for', |
| 531 | + 'ep-mycourses-courses-epoa' => '{{PLURAL:$1|Course|Courses}} I am {{GENDER:$1|Online Ambassador}} for', |
| 532 | + 'ep-mycourses-courses-epca' => '{{PLURAL:$1|Course|Courses}} I am {{GENDER:$1|Campus Ambassador}} for', |
| 533 | + 'ep-mycourses-courses-epinstructor' => '{{PLURAL:$1|Course|Courses}} I am {{GENDER:$1|Instructor}} for', |
| 534 | + 'ep-mycourses-courses-epstudent' => '{{PLURAL:$1|Course|Courses}} I am enrolled in', |
535 | 535 | 'ep-mycourses-nocourses-epca' => 'There are no courses you are Campus Ambassador for yet.', |
536 | 536 | 'ep-mycourses-nocourses-epoa' => 'There are no courses you are Online Ambassador for yet.', |
537 | 537 | 'ep-mycourses-nocourses-epinstructor' => 'There are no courses you are Instructor for yet.', |
538 | 538 | 'ep-mycourses-enrolledin' => 'You are currently enrolled in course $1 at institution $2.', |
| 539 | + 'ep-mycourses-course-org-links' => 'Course $1 at institution $2.', |
539 | 540 | 'ep-mycourses-articletable' => 'These are the articles you are working on and their reviewers:', |
540 | 541 | |
541 | 542 | // ep.enlist instructor |