https://www.mediawiki.org/wiki/Special:Code/MediaWiki/112273

Revision: 112273
Author:   jeroendedauw
Date:     2012-02-23 23:42:39 +0000 (Thu, 23 Feb 2012)
Log Message:
-----------
work on special:mycourses

Modified Paths:
--------------
    trunk/extensions/EducationProgram/EducationProgram.i18n.php
    trunk/extensions/EducationProgram/includes/EPPager.php
    trunk/extensions/EducationProgram/specials/SpecialMyCourses.php

Modified: trunk/extensions/EducationProgram/EducationProgram.i18n.php
===================================================================
--- trunk/extensions/EducationProgram/EducationProgram.i18n.php 2012-02-23 
23:37:09 UTC (rev 112272)
+++ trunk/extensions/EducationProgram/EducationProgram.i18n.php 2012-02-23 
23:42:39 UTC (rev 112273)
@@ -526,15 +526,16 @@
        'specialmycourses-summary-org' => 'Institution name',
     'ep-mycourses-not-a-student' => 'You are not enrolled in any 
[[Special:Courses|courses]].',
        'ep-mycourses-enrollment' => 'Courses I am enrolled in',
-       'ep-mycourses-course-enrollment' => 'Course I am enrolled in',
        'ep-mycourses-login-first' => 'You need to login before you can view 
your courses.',
-       'ep-mycourses-courses-epoa' => 'Courses I am Online Ambassador for',
-       'ep-mycourses-courses-epca' => 'Courses I am Campus Ambassador for',
-       'ep-mycourses-courses-epinstructor' => 'Courses I am Instructor for',
+       'ep-mycourses-courses-epoa' => '{{PLURAL:$1|Course|Courses}} I am 
{{GENDER:$1|Online Ambassador}} for',
+       'ep-mycourses-courses-epca' => '{{PLURAL:$1|Course|Courses}} I am 
{{GENDER:$1|Campus Ambassador}} for',
+       'ep-mycourses-courses-epinstructor' => '{{PLURAL:$1|Course|Courses}} I 
am {{GENDER:$1|Instructor}} for',
+       'ep-mycourses-courses-epstudent' => '{{PLURAL:$1|Course|Courses}} I am 
enrolled in',
        'ep-mycourses-nocourses-epca' => 'There are no courses you are Campus 
Ambassador for yet.',
        'ep-mycourses-nocourses-epoa' => 'There are no courses you are Online 
Ambassador for yet.',
        'ep-mycourses-nocourses-epinstructor' => 'There are no courses you are 
Instructor for yet.',
        'ep-mycourses-enrolledin' => 'You are currently enrolled in course $1 
at institution $2.',
+       'ep-mycourses-course-org-links' => 'Course $1 at institution $2.',
        'ep-mycourses-articletable' => 'These are the articles you are working 
on and their reviewers:',
 
        // ep.enlist instructor

Modified: trunk/extensions/EducationProgram/includes/EPPager.php
===================================================================
--- trunk/extensions/EducationProgram/includes/EPPager.php      2012-02-23 
23:37:09 UTC (rev 112272)
+++ trunk/extensions/EducationProgram/includes/EPPager.php      2012-02-23 
23:42:39 UTC (rev 112273)
@@ -42,6 +42,13 @@
        protected $context;
 
        /**
+        * Enable filtering on the conditions of the filter control.
+        * @since 0.1
+        * @var boolean
+        */
+       protected $enableFilter = true;
+
+       /**
         * Constructor.
         *
         * @param IContextSource $context
@@ -237,12 +244,14 @@
        protected function getConditions() {
                $conds = array();
 
-               $filterOptions = $this->getFilterOptions();
-               $this->addFilterValues( $filterOptions, false );
+               if ( $this->enableFilter ) {
+                       $filterOptions = $this->getFilterOptions();
+                       $this->addFilterValues( $filterOptions, false );
 
-               foreach ( $filterOptions as $optionName => $optionData ) {
-                       if ( array_key_exists( 'value', $optionData ) && 
$optionData['value'] !== '' ) {
-                               $conds[$optionName] = $optionData['value'];
+                       foreach ( $filterOptions as $optionName => $optionData 
) {
+                               if ( array_key_exists( 'value', $optionData ) 
&& $optionData['value'] !== '' ) {
+                                       $conds[$optionName] = 
$optionData['value'];
+                               }
                        }
                }
 
@@ -285,6 +294,17 @@
        }
 
        /**
+        * Sets if the filter control should be enabled.
+        *
+        * @since 0.1
+        *
+        * @param $enableFilter
+        */
+       public function setEnableFilter( $enableFilter ) {
+               $this->enableFilter = $enableFilter;
+       }
+
+       /**
         * Gets the HTML for a filter control.
         *
         * @since 0.1
@@ -294,6 +314,10 @@
         * @return string
         */
        public function getFilterControl( $hideWhenNoResults = true ) {
+               if ( !$this->enableFilter ) {
+                       return '';
+               }
+
                $filterOptions = $this->getFilterOptions();
 
                foreach ( $this->conds as $name => $value ) {

Modified: trunk/extensions/EducationProgram/specials/SpecialMyCourses.php
===================================================================
--- trunk/extensions/EducationProgram/specials/SpecialMyCourses.php     
2012-02-23 23:37:09 UTC (rev 112272)
+++ trunk/extensions/EducationProgram/specials/SpecialMyCourses.php     
2012-02-23 23:42:39 UTC (rev 112273)
@@ -86,7 +86,11 @@
         * @since 0.1
         */
        protected function displayCourses() {
-               $this->displayEnrollment();
+               if ( $this->getRequest()->getCheck( 'enrolled' ) ) {
+                       EPStudents::singleton()->setReadDb( DB_MASTER );
+               }
+
+               $this->displayRoleAssociation( 'EPStudent' );
                
                if ( $this->getUser()->isAllowed( 'ep-instructor' ) ) {
                        $this->displayRoleAssociation( 'EPInstructor' );
@@ -107,10 +111,6 @@
         * @since 0.1
         */
        protected function displayEnrollment() {
-               if ( $this->getRequest()->getCheck( 'enrolled' ) ) {
-                       EPStudents::singleton()->setReadDb( DB_MASTER );
-               }
-
                $student = EPStudent::newFromUser( $this->getUser() );
 
                $courses = $student->getCourses( 'id' );
@@ -155,24 +155,26 @@
         * @param $class The name of the EPIRole implementing class
         */
        protected function displayRoleAssociation( $class ) {
-               $ambassador = $class::newFromUser( $this->getUser() );
-               $courses = $ambassador->getCourses( array( 'id', 'name' ) );
+               $userRole = $class::newFromUser( $this->getUser() );
+               $courses = $userRole->getCourses( array( 'id', 'name', 'org_id' 
) );
 
                if ( count( $courses ) > 0 ) {
-                       $this->getOutput()->addElement( 'h2', array(), wfMsg( 
'ep-mycourses-courses-' . strtolower( $class ) ) );
+                       $message = wfMsgExt( 'ep-mycourses-courses-' . 
strtolower( $class ), 'parsemag', count( $courses ), 
$this->getUser()->getName() );
+                       $this->getOutput()->addElement( 'h2', array(), $message 
);
 
-                       if ( $class == 'EPInstructor' ) {
+                       if ( $class == 'EPStudent' ) {
+                               if ( count( $courses ) == 1 ) {
+                                       $this->displayCourse( $courses[0] );
+                               }
+                               else {
+                                       $this->displayCourseList( $courses );
+                               }
+                       }
+                       elseif ( $class == 'EPInstructor' ) {
                                $this->displayCourseTables( $courses );
                        }
                        else {
-                               $courseIds = array_map(
-                                       function( EPCourse $course ) {
-                                               return $course->getId();
-                                       },
-                                       $courses
-                               );
-
-                               EPCourse::displayPager( $this->getContext(), 
array( 'id' => $courseIds ), true, $class );
+                               $this->displayCoursePager( $courses, $class );
                        }
                }
                else {
@@ -191,6 +193,14 @@
                foreach ( $courses as /* EPCourse */ $course ) {
                        $out->addElement( 'h3', array(), $course->getField( 
'name' ) );
 
+                       $out->addHTML( $this->msg(
+                               'ep-mycourses-course-org-links',
+                               array(
+                                       Message::rawParam( $course->getLink() ),
+                                       Message::rawParam( 
$course->getOrg()->getLink() )
+                               )
+                       )->text() );
+
                        $pager = new EPArticleTable(
                                $this->getContext(),
                                array( 'id' => $this->getUser()->getId() ),
@@ -200,10 +210,10 @@
                        if ( $pager->getNumRows() ) {
                                $out->addHTML(
                                        $pager->getFilterControl() .
-                                               $pager->getNavigationBar() .
-                                               $pager->getBody() .
-                                               $pager->getNavigationBar() .
-                                               $pager->getMultipleItemControl()
+                                       $pager->getNavigationBar() .
+                                       $pager->getBody() .
+                                       $pager->getNavigationBar() .
+                                       $pager->getMultipleItemControl()
                                );
                        }
                }
@@ -219,8 +229,6 @@
        protected function displayCourse( EPCourse $course ) {
                $out = $this->getOutput();
                
-               $out->addElement( 'h2', array(), wfMsg( 
'ep-mycourses-course-enrollment' ) );
-               
                $out->addHTML( $this->msg(
                        'ep-mycourses-enrolledin',
                        array(
@@ -245,12 +253,63 @@
                if ( $pager->getNumRows() ) {
                        $out->addHTML(
                                $pager->getFilterControl() .
-                                       $pager->getNavigationBar() .
-                                       $pager->getBody() .
-                                       $pager->getNavigationBar() .
-                                       $pager->getMultipleItemControl()
+                               $pager->getNavigationBar() .
+                               $pager->getBody() .
+                               $pager->getNavigationBar() .
+                               $pager->getMultipleItemControl()
                        );
                }
        }
 
+       /**
+        * Display enrollment info for a list of courses.
+        *
+        * @since 0.1
+        *
+        * @param array $courses
+        */
+       protected function displayCourseList( array $courses ) {
+               foreach ( $courses as /* EPCourse */ $course ) {
+                       $this->getOutput()->addElement( 'h3', array(), 
$course->getField( 'name' ) );
+                       $this->displayCourse( $course );
+               }
+       }
+
+       /**
+        * Display a course pager with the provided courses.
+        *
+        * @since 0.1
+        *
+        * @param array $courses
+        * @param string $class
+        */
+       protected function displayCoursePager( array $courses, $class ) {
+               $out = $this->getOutput();
+
+               $courseIds = array_map(
+                       function( EPCourse $course ) {
+                               return $course->getId();
+                       },
+                       $courses
+               );
+
+               $pager = new EPCoursePager( $this->getContext(), array( 'id' => 
$courseIds ), true );
+
+               $pager->setFilterPrefix( $class );
+               $pager->setEnableFilter( count( $courses ) > 1 );
+
+               if ( $pager->getNumRows() ) {
+                       $out->addHTML(
+                               $pager->getFilterControl() .
+                               $pager->getNavigationBar() .
+                               $pager->getBody() .
+                               $pager->getNavigationBar()
+                       );
+               }
+               else {
+                       $out->addHTML( $pager->getFilterControl() );
+                       $out->addWikiMsg( 'ep-courses-noresults' );
+               }
+       }
+
 }


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to