r112273 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112272‎ | r112273 | r112274 >
Date:23:42, 23 February 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
work on special:mycourses
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.i18n.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPPager.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialMyCourses.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/specials/SpecialMyCourses.php
@@ -86,7 +86,11 @@
8787 * @since 0.1
8888 */
8989 protected function displayCourses() {
90 - $this->displayEnrollment();
 90+ if ( $this->getRequest()->getCheck( 'enrolled' ) ) {
 91+ EPStudents::singleton()->setReadDb( DB_MASTER );
 92+ }
 93+
 94+ $this->displayRoleAssociation( 'EPStudent' );
9195
9296 if ( $this->getUser()->isAllowed( 'ep-instructor' ) ) {
9397 $this->displayRoleAssociation( 'EPInstructor' );
@@ -107,10 +111,6 @@
108112 * @since 0.1
109113 */
110114 protected function displayEnrollment() {
111 - if ( $this->getRequest()->getCheck( 'enrolled' ) ) {
112 - EPStudents::singleton()->setReadDb( DB_MASTER );
113 - }
114 -
115115 $student = EPStudent::newFromUser( $this->getUser() );
116116
117117 $courses = $student->getCourses( 'id' );
@@ -155,24 +155,26 @@
156156 * @param $class The name of the EPIRole implementing class
157157 */
158158 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' ) );
161161
162162 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 );
164165
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' ) {
166175 $this->displayCourseTables( $courses );
167176 }
168177 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 );
177179 }
178180 }
179181 else {
@@ -191,6 +193,14 @@
192194 foreach ( $courses as /* EPCourse */ $course ) {
193195 $out->addElement( 'h3', array(), $course->getField( 'name' ) );
194196
 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+
195205 $pager = new EPArticleTable(
196206 $this->getContext(),
197207 array( 'id' => $this->getUser()->getId() ),
@@ -200,10 +210,10 @@
201211 if ( $pager->getNumRows() ) {
202212 $out->addHTML(
203213 $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()
208218 );
209219 }
210220 }
@@ -219,8 +229,6 @@
220230 protected function displayCourse( EPCourse $course ) {
221231 $out = $this->getOutput();
222232
223 - $out->addElement( 'h2', array(), wfMsg( 'ep-mycourses-course-enrollment' ) );
224 -
225233 $out->addHTML( $this->msg(
226234 'ep-mycourses-enrolledin',
227235 array(
@@ -245,12 +253,63 @@
246254 if ( $pager->getNumRows() ) {
247255 $out->addHTML(
248256 $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()
253261 );
254262 }
255263 }
256264
 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+
257316 }
Index: trunk/extensions/EducationProgram/includes/EPPager.php
@@ -42,6 +42,13 @@
4343 protected $context;
4444
4545 /**
 46+ * Enable filtering on the conditions of the filter control.
 47+ * @since 0.1
 48+ * @var boolean
 49+ */
 50+ protected $enableFilter = true;
 51+
 52+ /**
4653 * Constructor.
4754 *
4855 * @param IContextSource $context
@@ -237,12 +244,14 @@
238245 protected function getConditions() {
239246 $conds = array();
240247
241 - $filterOptions = $this->getFilterOptions();
242 - $this->addFilterValues( $filterOptions, false );
 248+ if ( $this->enableFilter ) {
 249+ $filterOptions = $this->getFilterOptions();
 250+ $this->addFilterValues( $filterOptions, false );
243251
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+ }
247256 }
248257 }
249258
@@ -285,6 +294,17 @@
286295 }
287296
288297 /**
 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+ /**
289309 * Gets the HTML for a filter control.
290310 *
291311 * @since 0.1
@@ -294,6 +314,10 @@
295315 * @return string
296316 */
297317 public function getFilterControl( $hideWhenNoResults = true ) {
 318+ if ( !$this->enableFilter ) {
 319+ return '';
 320+ }
 321+
298322 $filterOptions = $this->getFilterOptions();
299323
300324 foreach ( $this->conds as $name => $value ) {
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php
@@ -526,15 +526,16 @@
527527 'specialmycourses-summary-org' => 'Institution name',
528528 'ep-mycourses-not-a-student' => 'You are not enrolled in any [[Special:Courses|courses]].',
529529 'ep-mycourses-enrollment' => 'Courses I am enrolled in',
530 - 'ep-mycourses-course-enrollment' => 'Course I am enrolled in',
531530 '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',
535535 'ep-mycourses-nocourses-epca' => 'There are no courses you are Campus Ambassador for yet.',
536536 'ep-mycourses-nocourses-epoa' => 'There are no courses you are Online Ambassador for yet.',
537537 'ep-mycourses-nocourses-epinstructor' => 'There are no courses you are Instructor for yet.',
538538 'ep-mycourses-enrolledin' => 'You are currently enrolled in course $1 at institution $2.',
 539+ 'ep-mycourses-course-org-links' => 'Course $1 at institution $2.',
539540 'ep-mycourses-articletable' => 'These are the articles you are working on and their reviewers:',
540541
541542 // ep.enlist instructor

Status & tagging log