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

Revision: 109665
Author:   jeroendedauw
Date:     2012-01-21 00:09:24 +0000 (Sat, 21 Jan 2012)
Log Message:
-----------
follow up to r109656 - moving and renaming more stuff

Modified Paths:
--------------
    trunk/extensions/EducationProgram/EducationProgram.hooks.php
    trunk/extensions/EducationProgram/EducationProgram.i18n.php
    trunk/extensions/EducationProgram/EducationProgram.php
    trunk/extensions/EducationProgram/includes/EPMC.php
    trunk/extensions/EducationProgram/includes/EPMCPager.php

Added Paths:
-----------
    trunk/extensions/EducationProgram/includes/EPCourse.php
    trunk/extensions/EducationProgram/includes/EPCoursePager.php

Removed Paths:
-------------
    trunk/extensions/EducationProgram/includes/EPTerm.php
    trunk/extensions/EducationProgram/includes/EPTermPager.php

Modified: trunk/extensions/EducationProgram/EducationProgram.hooks.php
===================================================================
--- trunk/extensions/EducationProgram/EducationProgram.hooks.php        
2012-01-21 00:04:09 UTC (rev 109664)
+++ trunk/extensions/EducationProgram/EducationProgram.hooks.php        
2012-01-21 00:09:24 UTC (rev 109665)
@@ -166,6 +166,8 @@
                }
 
                $links['views'] = $viewLinks;
+
+               return true;
        }
 
 }

Modified: trunk/extensions/EducationProgram/EducationProgram.i18n.php
===================================================================
--- trunk/extensions/EducationProgram/EducationProgram.i18n.php 2012-01-21 
00:04:09 UTC (rev 109664)
+++ trunk/extensions/EducationProgram/EducationProgram.i18n.php 2012-01-21 
00:09:24 UTC (rev 109665)
@@ -28,18 +28,18 @@
        'tooltip-ep-form-save' => 'Save',
        'tooltip-ep-edit-institution' => 'Edit this institution',
        'tooltip-ep-edit-course' => 'Edit this course',
-       'tooltip-ep-edit-term' => 'Edit this term',
+       'tooltip-ep-edit-mc' => 'Edit this master course',
 
        // Access keys
        'accesskey-ep-form-save' => 's', # do not translate or duplicate this 
message to other languages
        'accesskey-ep-edit-institution' => 'e', # do not translate or duplicate 
this message to other languages
        'accesskey-ep-edit-course' => 'e', # do not translate or duplicate this 
message to other languages
-       'accesskey-ep-edit-term' => 'e', # do not translate or duplicate this 
message to other languages
+       'accesskey-ep-edit-mc' => 'e', # do not translate or duplicate this 
message to other languages
 
        // Navigation links
        'ep-nav-orgs' => 'Institution list',
        'ep-nav-courses' => 'Courses list',
-       'ep-nav-terms' => 'Terms list',
+       'ep-nav-mcs' => 'Master courses list',
        'ep-nav-mycourses' => 'My courses',
        'ep-nav-students' => 'Student list',
        'ep-nav-mentors' => 'Ambassador list',
@@ -47,14 +47,14 @@
        // Logging
        'log-name-institution' => 'Institution log',
        'log-name-course' => 'Course log',
-       'log-name-term' => 'Term log',
+       'log-name-mc' => 'Master course log',
        'log-name-student' => 'Student log',
        'log-name-ambassador' => 'Ambassador log',
        'log-name-instructor' => 'Instructor log',
 
-       'log-header-institution' => 'These events track when changes are made 
to institutions.',
-       'log-header-course' => 'These events track when changes are made to 
courses.',
-       'log-header-term' => 'These events track when changes are made to 
terms.',
+       'log-header-institution' => 'These events track the changes that are 
made to institutions.',
+       'log-header-course' => 'These events track the changes that are made to 
courses.',
+       'log-header-mc' => 'These events track the changes that are made to 
master courses.',
 
        'logentry-institution-add' => '$1 created institution $3',
        'logentry-institution-remove' => '$1 removed institution $3',
@@ -64,9 +64,9 @@
        'logentry-course-remove' => '$1 removed course $3',
        'logentry-course-update' => '$1 updated course $3',
 
-       'logentry-term-add' => '$1 created term $3',
-       'logentry-term-remove' => '$1 removed term $3',
-       'logentry-term-update' => '$1 updated term $3',
+       'logentry-mc-add' => '$1 created master course $3',
+       'logentry-mc-remove' => '$1 removed master course $3',
+       'logentry-mc-update' => '$1 updated master course $3',
 
        'logentry-instructor-add' => '$1 {{GENDER:$2|added}} 
{{PLURAL:$4|instructor|instructors}} $5 to course $3',
        'logentry-instructor-remove' => '$1 {{GENDER:$2|removed}} 
{{PLURAL:$4|instructor|instructors}} $5 from course $3',
@@ -141,20 +141,22 @@
        'special-educationprogram' => 'Education Program',
        'special-editinstitution-add' => 'Add institution',
        'special-editinstitution-edit' => 'Edit institution',
-       'special-terms' => 'Terms',
-       'special-term' => 'Term',
-       'special-editterm-add' => 'Add term',
-       'special-editterm-edit' => 'Edit term',
+       'special-mastercourses' => 'Master courses',
+       'special-mastercourse' => 'Master course',
+       'special-editmc-add' => 'Add master course',
+       'special-editmc-edit' => 'Edit master course',
        'special-editcourse-add' => 'Add course',
        'special-editcourse-edit' => 'Edit course',
        'special-enroll' => 'Enroll',
-    'special-ambassadors' => 'Ambassadors',
-       'special-ambassador' => 'Ambassador',
+       'special-onlineambassadors' => 'Online ambassadors',
+       'special-campusambassadors' => 'Campus ambassadors',
+       'special-onlineambassador' => 'Online ambassador',
+       'special-campusambassador' => 'Campus ambassador',
 
-       // Term statuses
-       'ep-term-status-passed' => 'Passed',
-       'ep-term-status-current' => 'Current',
-       'ep-term-status-planned' => 'Planned',
+       // Course statuses
+       'ep-course-status-passed' => 'Passed',
+       'ep-course-status-current' => 'Current',
+       'ep-course-status-planned' => 'Planned',
 
        // Special:Institutions
        'ep-institutions-nosuchinstitution' => 'There is no institution with 
name "$1". Existing institutions are listed below.',

Modified: trunk/extensions/EducationProgram/EducationProgram.php
===================================================================
--- trunk/extensions/EducationProgram/EducationProgram.php      2012-01-21 
00:04:09 UTC (rev 109664)
+++ trunk/extensions/EducationProgram/EducationProgram.php      2012-01-21 
00:09:24 UTC (rev 109665)
@@ -165,7 +165,7 @@
 // Logging
 $wgLogTypes[] = 'institution';
 $wgLogTypes[] = 'course';
-$wgLogTypes[] = 'term';
+$wgLogTypes[] = 'mc';
 $wgLogTypes[] = 'student';
 $wgLogTypes[] = 'ambassador';
 $wgLogTypes[] = 'instructor';
@@ -173,14 +173,14 @@
 if ( array_key_exists( 'LogFormatter', $wgAutoloadLocalClasses ) ) {
        $wgLogActionsHandlers['institution/*'] = 'EPLogFormatter';
        $wgLogActionsHandlers['course/*'] = 'EPLogFormatter';
-       $wgLogActionsHandlers['term/*'] = 'EPLogFormatter';
+       $wgLogActionsHandlers['mc/*'] = 'EPLogFormatter';
        $wgLogActionsHandlers['student/*'] = 'EPLogFormatter';
        $wgLogActionsHandlers['ambassador/*'] = 'EPLogFormatter';
        $wgLogActionsHandlers['instructor/*'] = 'EPLogFormatter';
 }
 else {
        // Compatibility with MediaWiki 1.18.
-       foreach ( array( 'institution', 'course', 'term' ) as $type ) {
+       foreach ( array( 'institution', 'course', 'mc' ) as $type ) {
                foreach ( array( 'add', 'remove', 'update' ) as $action ) {
                        $wgLogActionsHandlers[$type . '/' . $action] = 
'EPHooks::formatLogEntry';
                }
@@ -198,7 +198,7 @@
        // Compatibility with MediaWiki 1.18.
        $wgLogNames['institution'] = 'log-name-institution';
        $wgLogNames['course'] = 'log-name-course';
-       $wgLogNames['term'] = 'log-name-term';
+       $wgLogNames['term'] = 'log-name-mc';
        $wgLogNames['student'] = 'log-name-student';
        $wgLogNames['ambassador'] = 'log-name-ambassador';
        $wgLogNames['instructor'] = 'log-name-instructor';
@@ -206,7 +206,7 @@
        // Compatibility with MediaWiki 1.18.
        $wgLogHeaders['institution'] = 'log-header-institution';
        $wgLogHeaders['course'] = 'log-header-course';
-       $wgLogHeaders['term'] = 'log-header-term';
+       $wgLogHeaders['term'] = 'log-header-mc';
        $wgLogHeaders['student'] = 'log-header-student';
        $wgLogHeaders['ambassador'] = 'log-header-ambassador';
        $wgLogHeaders['instructor'] = 'log-header-instructor';
@@ -215,7 +215,7 @@
 // Rights
 $wgAvailableRights[] = 'ep-org';                       // Manage orgs
 $wgAvailableRights[] = 'ep-course';                    // Manage courses
-$wgAvailableRights[] = 'ep-term';                      // Manage terms
+$wgAvailableRights[] = 'ep-mc';                            // Manage master 
courses
 $wgAvailableRights[] = 'ep-token';                     // See enrollment tokens
 $wgAvailableRights[] = 'ep-enroll';                    // Enroll as a student
 $wgAvailableRights[] = 'ep-remstudent';                // Dissasociate 
students from terms
@@ -230,7 +230,7 @@
 $wgGroupPermissions['*']['ep-enroll'] = true;
 $wgGroupPermissions['*']['ep-org'] = false;
 $wgGroupPermissions['*']['ep-course'] = false;
-$wgGroupPermissions['*']['ep-term'] = false;
+$wgGroupPermissions['*']['ep-mc'] = false;
 $wgGroupPermissions['*']['ep-token'] = false;
 $wgGroupPermissions['*']['ep-remstudent'] = false;
 $wgGroupPermissions['*']['ep-online'] = false;
@@ -242,7 +242,7 @@
 
 $wgGroupPermissions['epstaff']['ep-org'] = true;
 $wgGroupPermissions['epstaff']['ep-course'] = true;
-$wgGroupPermissions['epstaff']['ep-term'] = true;
+$wgGroupPermissions['epstaff']['ep-mc'] = true;
 $wgGroupPermissions['epstaff']['ep-token'] = true;
 $wgGroupPermissions['epstaff']['ep-enroll'] = true;
 $wgGroupPermissions['epstaff']['ep-remstudent'] = true;
@@ -255,7 +255,7 @@
 
 $wgGroupPermissions['epadmin']['ep-org'] = true;
 $wgGroupPermissions['epadmin']['ep-course'] = true;
-$wgGroupPermissions['epadmin']['ep-term'] = true;
+$wgGroupPermissions['epadmin']['ep-mc'] = true;
 $wgGroupPermissions['epadmin']['ep-token'] = true;
 $wgGroupPermissions['epadmin']['ep-enroll'] = true;
 $wgGroupPermissions['epadmin']['ep-remstudent'] = true;
@@ -268,19 +268,19 @@
 
 $wgGroupPermissions['eponlineamb']['ep-org'] = true;
 $wgGroupPermissions['eponlineamb']['ep-course'] = true;
-$wgGroupPermissions['eponlineamb']['ep-term'] = true;
+$wgGroupPermissions['eponlineamb']['ep-mc'] = true;
 $wgGroupPermissions['eponlineamb']['ep-token'] = true;
 $wgGroupPermissions['eponlineamb']['ep-beonline'] = true;
 
 $wgGroupPermissions['epcampamb']['ep-org'] = true;
 $wgGroupPermissions['epcampamb']['ep-course'] = true;
-$wgGroupPermissions['epcampamb']['ep-term'] = true;
+$wgGroupPermissions['epcampamb']['ep-mc'] = true;
 $wgGroupPermissions['epcampamb']['ep-token'] = true;
 $wgGroupPermissions['epcampamb']['ep-becampus'] = true;
 
 $wgGroupPermissions['epinstructor']['ep-org'] = true;
 $wgGroupPermissions['epinstructor']['ep-course'] = true;
-$wgGroupPermissions['epinstructor']['ep-term'] = true;
+$wgGroupPermissions['epinstructor']['ep-mc'] = true;
 $wgGroupPermissions['epinstructor']['ep-token'] = true;
 $wgGroupPermissions['epinstructor']['ep-remstudent'] = true;
 $wgGroupPermissions['epinstructor']['ep-online'] = true;

Copied: trunk/extensions/EducationProgram/includes/EPCourse.php (from rev 
109661, trunk/extensions/EducationProgram/includes/EPTerm.php)
===================================================================
--- trunk/extensions/EducationProgram/includes/EPCourse.php                     
        (rev 0)
+++ trunk/extensions/EducationProgram/includes/EPCourse.php     2012-01-21 
00:09:24 UTC (rev 109665)
@@ -0,0 +1,479 @@
+<?php
+
+/**
+ * Class representing a single course.
+ *
+ * @since 0.1
+ *
+ * @file EPCourse.php
+ * @ingroup EducationProgram
+ *
+ * @licence GNU GPL v3 or later
+ * @author Jeroen De Dauw < [email protected] >
+ */
+class EPCourse extends EPDBObject {
+
+       /**
+        * Field for caching the linked course.
+        *
+        * @since 0.1
+        * @var EPCourse|false
+        */
+       protected $course = false;
+
+       /**
+        * Field for caching the linked org.
+        *
+        * @since 0.1
+        * @var EPOrg|false
+        */
+       protected $org = false;
+
+       /**
+        * Cached array of the linked EPStudent objects.
+        *
+        * @since 0.1
+        * @var array|false
+        */
+       protected $students = false;
+
+       /**
+        * Returns a list of statuses a term can have.
+        * Keys are messages, values are identifiers.
+        *
+        * @since 0.1
+        *
+        * @return array
+        */
+       public static function getStatuses() {
+               return array(
+                       wfMsg( 'ep-course-status-passed' ) => 'passed',
+                       wfMsg( 'ep-course-status-current' ) => 'current',
+                       wfMsg( 'ep-course-status-planned' ) => 'planned',
+               );
+       }
+
+       /**
+        * Returns the message for the provided status identifier.
+        *
+        * @since 0.1
+        *
+        * @param string $status
+        *
+        * @return string
+        */
+       public static function getStatusMessage( $status ) {
+               static $map = null;
+
+               if ( is_null( $map ) ) {
+                       $map = array_flip( self::getStatuses() );
+               }
+
+               return $map[$status];
+       }
+
+       /**
+        * @see parent::getFieldTypes
+        *
+        * @since 0.1
+        *
+        * @return array
+        */
+       protected static function getFieldTypes() {
+               return array(
+                       'id' => 'id',
+                       'course_id' => 'id',
+                       'org_id' => 'id',
+
+                       'year' => 'int',
+                       'start' => 'str', // TS_MW
+                       'end' => 'str', // TS_MW
+                       'description' => 'str',
+                       'token' => 'str',
+                       'online_ambs' => 'array',
+                       'campus_ambs' => 'array',
+               
+                       'students' => 'int',
+               );
+       }
+
+       /**
+        * (non-PHPdoc)
+        * @see EPDBObject::getDefaults()
+        */
+       public static function getDefaults() {
+               return array(
+                       'year' => substr( wfTimestamp( TS_MW ), 0, 4 ),
+                       'start' => wfTimestamp( TS_MW ),
+                       'end' => wfTimestamp( TS_MW ),
+                       'description' => '',
+                       'token' => '',
+                       'online_ambs' => array(),
+                       'campus_ambs' => array(),
+               
+                       'students' => 0,
+               );
+       }
+
+       /**
+        * Returns the students enrolled in this term.
+        *
+        * @since 0.1
+        *
+        * @param string|array|null $fields
+        * @param array $conditions
+        *
+        * @return array of EPStudent
+        */
+       protected function doGetStudents( $fields, array $conditions ) {
+               $conditions[] = array( array( 'ep_terms', 'id' ), 
$this->getId() );
+
+               return EPStudent::select(
+                       $fields,
+                       $conditions,
+                       array(),
+                       array(
+                               'ep_students_per_term' => array( 'INNER JOIN', 
array( array( array( 'ep_students_per_term', 'student_id' ), array( 
'ep_students', 'id' ) ) ) ),
+                               'ep_terms' => array( 'INNER JOIN', array( 
array( array( 'ep_students_per_term', 'term_id' ), array( 'ep_terms', 'id' ) ) 
) )
+                       )
+               );
+       }
+
+       /**
+        * Returns the students enrolled in this term.
+        * Caches the result when no conditions are provided and all fields are 
selected.
+        *
+        * @since 0.1
+        *
+        * @param string|array|null $fields
+        * @param array $conditions
+        *
+        * @return array of EPStudent
+        */
+       public function getStudents( $fields = null, array $conditions = 
array() ) {
+               if ( count( $conditions ) !== 0 ) {
+                       return $this->doGetStudents( $fields, $conditions );
+               }
+
+               if ( $this->students === false ) {
+                       $students = $this->doGetStudents( $fields, $conditions 
);
+
+                       if ( is_null( $fields ) ) {
+                               $this->students = $students;
+                       }
+
+                       return $students;
+               }
+               else {
+                       return $this->students;
+               }
+       }
+
+       /**
+        * (non-PHPdoc)
+        * @see EPDBObject::loadSummaryFields()
+        */
+       public function loadSummaryFields( $summaryFields = null ) {
+               if ( is_null( $summaryFields ) ) {
+                       $summaryFields = array( 'org_id', 'students' );
+               }
+               else {
+                       $summaryFields = (array)$summaryFields;
+               }
+
+               $fields = array();
+
+               if ( in_array( 'org_id', $summaryFields ) ) {
+                       $fields['org_id'] = $this->getCourse( 'org_id' 
)->getField( 'org_id' );
+               }
+               
+               if ( in_array( 'students', $summaryFields ) ) {
+                       $fields['students'] = wfGetDB( DB_SLAVE )->select(
+                               'ep_students_per_term',
+                               'COUNT(*) AS rowcount',
+                               array( 'spt_term_id' => $this->getId() )
+                       );
+
+                       $fields['students'] = 
$fields['students']->fetchObject()->rowcount;
+               }
+
+               $this->setFields( $fields );
+       }
+
+       /**
+        * (non-PHPdoc)
+        * @see EPDBObject::insertIntoDB()
+        */
+       protected function insertIntoDB() {
+               if ( !$this->hasField( 'org_id' ) ) {
+                       $this->setField( 'org_id', $this->getCourse( 'org_id' 
)->getField( 'org_id' ) );
+               }
+
+               $success = parent::insertIntoDB();
+
+               if ( $success && $this->updateSummaries ) {
+                       EPOrg::updateSummaryFields( array( 'terms', 'active' ), 
array( 'id' => $this->getField( 'org_id' ) ) );
+                       EPCourse::updateSummaryFields( 'active', array( 'id' => 
$this->getField( 'course_id' ) ) );
+               }
+
+               return $success;
+       }
+
+       /**
+        * (non-PHPdoc)
+        * @see EPDBObject::removeFromDB()
+        */
+       public function removeFromDB() {
+               $id = $this->getId();
+
+               if ( $this->updateSummaries ) {
+                       $this->loadFields( array( 'org_id', 'course_id' ) );
+                       $orgId = $this->getField( 'org_id' );
+                       $courseId = $this->getField( 'course_id' );
+               }
+
+               $success = parent::removeFromDB();
+
+               if ( $success && $this->updateSummaries ) {
+                       EPCourse::updateSummaryFields( 'students', array( 'id' 
=> $courseId ) );
+                       EPOrg::updateSummaryFields( array( 'terms', 'students', 
'active' ), array( 'id' => $orgId ) );
+               }
+
+               if ( $success ) {
+                       $success = wfGetDB( DB_MASTER )->delete( 
'ep_students_per_term', array( 'spt_term_id' => $id ) ) && $success;
+               }
+
+               return $success;
+       }
+
+       /**
+        * (non-PHPdoc)
+        * @see EPDBObject::updateInDB()
+        */
+       protected function updateInDB() {
+               if ( $this->updateSummaries ) {
+                       $oldOrgId = $this->hasField( 'org_id' ) ? 
self::selectFieldsRow( 'org_id', array( 'id' => $this->getId() ) ) : false;
+                       $oldCourseId = $this->hasField( 'course_id' ) ? 
self::selectFieldsRow( 'course_id', array( 'id' => $this->getId() ) ) : false;
+               }
+
+               if ( $this->hasField( 'course_id' ) ) {
+                       $oldCourseId = self::selectFieldsRow( 'course_id', 
array( 'id' => $this->getId() ) );
+
+                       if ( $this->getField( 'course_id' ) !== $oldCourseId ) {
+                               $this->setField( 'org_id', 
EPCourse::selectFieldsRow( 'org_id', array( 'id' => $this->getField( 
'course_id' ) ) ) );
+                       }
+               }
+
+               $success = parent::updateInDB();
+
+               if ( $this->updateSummaries && $success ) {
+                       if ( $oldOrgId !== false && $oldOrgId !== 
$this->getField( 'org_id' ) ) {
+                               $conds = array( 'id' => array( $oldOrgId, 
$this->getField( 'org_id' ) ) );
+                               EPOrg::updateSummaryFields( array( 'terms', 
'students', 'active' ), $conds );
+                       }
+
+                       if ( $oldCourseId !== false && $oldCourseId !== 
$this->getField( 'org_id' ) ) {
+                               $conds = array( 'id' => array( $oldCourseId, 
$this->getField( 'course_id' ) ) );
+                               EPCourse::updateSummaryFields( array( 'active', 
'students' ), $conds );
+                       }
+               }
+
+               return $success;
+       }
+
+       /**
+        * Returns the course associated with this term.
+        *
+        * @since 0.1
+        *
+        * @param string|array|null $fields
+        *
+        * @return EPCourse
+        */
+       public function getCourse( $fields = null ) {
+               if ( $this->course === false ) {
+                       $this->course = EPCourse::selectRow( $fields, array( 
'id' => $this->loadAndGetField( 'course_id' ) ) );
+               }
+
+               return $this->course;
+       }
+
+       /**
+        * Returns the org associated with this term.
+        *
+        * @since 0.1
+        *
+        * @param string|array|null $fields
+        *
+        * @return EPOrg
+        */
+       public function getOrg( $fields = null ) {
+               if ( $this->org === false ) {
+                       $this->org = EPOrg::selectRow( $fields, array( 'id' => 
$this->loadAndGetField( 'org_id' ) ) );
+               }
+
+               return $this->org;
+       }
+
+       /**
+        * Display a pager with terms.
+        *
+        * @since 0.1
+        *
+        * @param IContextSource $context
+        * @param array $conditions
+        */
+       public static function displayPager( IContextSource $context, array 
$conditions = array() ) {
+               $pager = new EPTermPager( $context, $conditions );
+
+               if ( $pager->getNumRows() ) {
+                       $context->getOutput()->addHTML(
+                               $pager->getFilterControl() .
+                               $pager->getNavigationBar() .
+                               $pager->getBody() .
+                               $pager->getNavigationBar() .
+                               $pager->getMultipleItemControl()
+                       );
+               }
+               else {
+                       $context->getOutput()->addHTML( 
$pager->getFilterControl( true ) );
+                       $context->getOutput()->addWikiMsg( 'ep-terms-noresults' 
);
+               }
+       }
+
+       /**
+        * Adds a control to add a term org to the provided context.
+        * Additional arguments can be provided to set the default values for 
the control fields.
+        *
+        * @since 0.1
+        *
+        * @param IContextSource $context
+        * @param array $args
+        *
+        * @return boolean
+        */
+       public static function displayAddNewControl( IContextSource $context, 
array $args ) {
+               if ( !$context->getUser()->isAllowed( 'ep-term' ) ) {
+                       return false;
+               }
+
+               $out = $context->getOutput();
+
+               $out->addHTML( Html::openElement(
+                       'form',
+                       array(
+                               'method' => 'post',
+                               'action' => SpecialPage::getTitleFor( 
'EditTerm' )->getLocalURL(),
+                       )
+               ) );
+
+               $out->addHTML( '<fieldset>' );
+
+               $out->addHTML( '<legend>' . wfMsgHtml( 'ep-terms-addnew' ) . 
'</legend>' );
+
+               $out->addHTML( Html::element( 'p', array(), wfMsg( 
'ep-terms-namedoc' ) ) );
+
+               $out->addHTML( Html::element( 'label', array( 'for' => 
'newcourse' ), wfMsg( 'ep-terms-newcourse' ) ) );
+
+               $select = new XmlSelect(
+                       'newcourse',
+                       'newcourse',
+                       array_key_exists( 'course', $args ) ? $args['course'] : 
false
+               );
+
+               $select->addOptions( EPCourse::getCourseOptions() );
+               $out->addHTML( $select->getHTML() );
+
+               $out->addHTML( '&#160;' . Xml::inputLabel( wfMsg( 
'ep-terms-newyear' ), 'newyear', 'newyear', 10 ) );
+
+               $out->addHTML( '&#160;' . Html::input(
+                       'addnewterm',
+                       wfMsg( 'ep-terms-add' ),
+                       'submit'
+               ) );
+
+               $out->addHTML( Html::hidden( 'isnew', 1 ) );
+
+               $out->addHTML( '</fieldset></form>' );
+
+               return true;
+       }
+
+       /**
+        * Adds a control to add a new term to the provided context
+        * or show a message if this is not possible for some reason.
+        *
+        * @since 0.1
+        *
+        * @param IContextSource $context
+        * @param array $args
+        */
+       public static function displayAddNewRegion( IContextSource $context, 
array $args = array() ) {
+               if ( EPCourse::has() ) {
+                       EPTerm::displayAddNewControl( $context, $args );
+               }
+               elseif ( $context->getUser()->isAllowed( 'ep-course' ) ) {
+                       $context->getOutput()->addWikiMsg( 
'ep-terms-addcoursefirst' );
+               }
+       }
+
+       /**
+        * Gets the amount of days left, rounded up to the nearest integer.
+        *
+        * @since 0.1
+        *
+        * @return integer
+        */
+       public function getDaysLeft() {
+               $timeLeft = (int)wfTimestamp( TS_UNIX, $this->getField( 'end' ) 
) - time();
+               return (int)ceil( $timeLeft / ( 60 * 60 * 24 ) );
+       }
+
+       /**
+        * Gets the amount of days since term start, rounded up to the nearest 
integer.
+        *
+        * @since 0.1
+        *
+        * @return integer
+        */
+       public function getDaysPassed() {
+               $daysPassed = time() - (int)wfTimestamp( TS_UNIX, 
$this->getField( 'start' ) );
+               return (int)ceil( $daysPassed / ( 60 * 60 * 24 ) );
+       }
+
+       /**
+        * Returns the status of the term.
+        *
+        * @since 0.1
+        *
+        * @return string
+        */
+       public function getStatus() {
+               if ( $this->getDaysLeft() <= 0 ) {
+                       $status = 'passed';
+               }
+               elseif ( $this->getDaysPassed() <= 0 ) {
+                       $status = 'planned';
+               }
+               else {
+                       $status = 'current';
+               }
+
+               return $status;
+       }
+
+       /**
+        * Get a link to Special:Term/id.
+        *
+        * @since 0.1
+        *
+        * @return string
+        */
+       public function getLink() {
+               return Linker::linkKnown(
+                       SpecialPage::getTitleFor( 'Term', $this->getId() ),
+                       htmlspecialchars( $this->getId() )
+               );
+       }
+
+}


Property changes on: trunk/extensions/EducationProgram/includes/EPCourse.php
___________________________________________________________________
Added: svn:eol-style
   + native

Copied: trunk/extensions/EducationProgram/includes/EPCoursePager.php (from rev 
109661, trunk/extensions/EducationProgram/includes/EPTermPager.php)
===================================================================
--- trunk/extensions/EducationProgram/includes/EPCoursePager.php                
                (rev 0)
+++ trunk/extensions/EducationProgram/includes/EPCoursePager.php        
2012-01-21 00:09:24 UTC (rev 109665)
@@ -0,0 +1,245 @@
+<?php
+
+/**
+ * Term pager, primarily for Special:Terms.
+ *
+ * @since 0.1
+ *
+ * @file EPCoursePager.php
+ * @ingroup EductaionProgram
+ *
+ * @licence GNU GPL v3 or later
+ * @author Jeroen De Dauw < [email protected] >
+ */
+class EPCoursePager extends EPPager {
+
+       /**
+        * Constructor.
+        *
+        * @param IContextSource $context
+        * @param array $conds
+        */
+       public function __construct( IContextSource $context, array $conds = 
array() ) {
+               parent::__construct( $context, $conds, 'EPCourse' );
+       }
+
+       /**
+        * (non-PHPdoc)
+        * @see EPPager::getFields()
+        */
+       public function getFields() {
+               return array(
+                       'id',
+                       'mc_id',
+                       'year',
+                       'start',
+                       'end',
+                       'students',
+               );
+       }
+
+       /**
+        * (non-PHPdoc)
+        * @see TablePager::getRowClass()
+        */
+       function getRowClass( $row ) {
+               return 'ep-course-row';
+       }
+
+       /**
+        * (non-PHPdoc)
+        * @see TablePager::getTableClass()
+        */
+       public function getTableClass() {
+               return 'TablePager ep-courses';
+       }
+
+       /**
+        * (non-PHPdoc)
+        * @see EPPager::getFormattedValue()
+        */
+       public function getFormattedValue( $name, $value ) {
+               switch ( $name ) {
+                       case 'id':
+                               $value = Linker::linkKnown(
+                                       SpecialPage::getTitleFor( 'Course', 
$value ),
+                                       htmlspecialchars( 
$this->getLanguage()->formatNum( $value, true ) )
+                               );
+                               break;
+                       case 'mc_id':
+                               $value = EPMC::selectRow( 'name', array( 'id' 
=> $value ) )->getField( 'name' );
+
+                               $value = Linker::linkKnown(
+                                       SpecialPage::getTitleFor( 
'MasterCourse', $value ),
+                                       htmlspecialchars( $value )
+                               );
+                               break;
+                       case 'year':
+                               $value = htmlspecialchars( 
$this->getLanguage()->formatNum( $value, true ) );
+                               break;
+                       case 'start': case 'end':
+                               $value = htmlspecialchars( 
$this->getLanguage()->date( $value ) );
+                               break;
+                       case '_status':
+                               $value = htmlspecialchars( 
EPTerm::getStatusMessage( $this->currentObject->getStatus() ) );
+                       case 'students':
+                               $value = htmlspecialchars( 
$this->getLanguage()->formatNum( $value ) );
+                               break;
+               }
+
+               return $value;
+       }
+
+       /**
+        * (non-PHPdoc)
+        * @see EPPager::getSortableFields()
+        */
+       protected function getSortableFields() {
+               return array(
+                       'id',
+                       'year',
+                       'start',
+                       'end',
+                       'students',
+               );
+       }
+
+       /**
+        * (non-PHPdoc)
+        * @see EPPager::getFieldNames()
+        */
+       public function getFieldNames() {
+               $fields = parent::getFieldNames();
+
+               if ( array_key_exists( 'mc_id', $this->conds ) && 
array_key_exists( 'org_id', $fields ) ) {
+                       unset( $fields['org_id'] );
+               }
+
+               $fields = wfArrayInsertAfter( $fields, array( '_status' => 
'status' ), 'students' );
+
+               return $fields;
+       }
+
+       /**
+        * (non-PHPdoc)
+        * @see EPPager::getFilterOptions()
+        */
+       protected function getFilterOptions() {
+               $options = array();
+
+               if ( !array_key_exists( 'mc_id', $this->conds ) ) {
+                       $options['mc_id'] = array(
+                               'type' => 'select',
+                               'options' => array_merge(
+                                       array( '' => '' ),
+                                       EPMC::getCourseOptions( EPMC::select( 
array( 'name', 'id' ) ) )
+                               ),
+                               'value' => '',
+                               'datatype' => 'int',
+                       );
+
+                       $options['org_id'] = array(
+                               'type' => 'select',
+                               'options' => array_merge(
+                                       array( '' => '' ),
+                                       EPOrg::getOrgOptions( EPOrg::select( 
array( 'name', 'id' ) ) )
+                               ),
+                               'value' => '',
+                               'datatype' => 'int',
+                       );
+               }
+
+               $years = EPCourse::selectFields( 'year', array(), array( 
'DISTINCT' ), array(), true );
+               asort( $years, SORT_NUMERIC );
+               $years = array_merge( array( '' ), $years );
+               $years = array_combine( $years, $years );
+
+               $options['year'] = array(
+                       'type' => 'select',
+                       'options' => $years,
+                       'value' => '',
+               );
+
+               $options['status'] = array(
+                       'type' => 'select',
+                       'options' => array_merge(
+                               array( '' => '' ),
+                               EPCourse::getStatuses()
+                       ),
+                       'value' => 'current',
+               );
+
+               return $options;
+       }
+
+       /**
+        * (non-PHPdoc)
+        * @see EPPager::getControlLinks()
+        */
+       protected function getControlLinks( EPDBObject $item ) {
+               $links = parent::getControlLinks( $item );
+
+               $links[] = $value = Linker::linkKnown(
+                       SpecialPage::getTitleFor( 'Course', $item->getId() ),
+                       wfMsgHtml( 'view' )
+               );
+
+               if ( $this->getUser()->isAllowed( 'ep-term' ) ) {
+                       $links[] = $value = Linker::linkKnown(
+                               SpecialPage::getTitleFor( 'EditCourse', 
$item->getId() ),
+                               wfMsgHtml( 'edit' )
+                       );
+
+                       $links[] = $this->getDeletionLink( 'course', 
$item->getId() );
+               }
+
+               return $links;
+       }
+
+       /**
+        * (non-PHPdoc)
+        * @see EPPager::getMultipleItemActions()
+        */
+       protected function getMultipleItemActions() {
+               $actions = parent::getMultipleItemActions();
+
+               if ( $this->getUser()->isAllowed( 'ep-course' ) ) {
+                       $actions[wfMsg( 'ep-pager-delete-selected' )] = array(
+                               'class' => 'ep-pager-delete-selected',
+                               'data-type' => 
ApiDeleteEducation::getTypeForClassName( $this->className )
+                       );
+               }
+               
+               return $actions;
+       }
+
+       /**
+        * (non-PHPdoc)
+        * @see EPPager::getConditions()
+        */
+       protected function getConditions() {
+               $conds = parent::getConditions();
+
+               if ( array_key_exists( 'status', $conds ) ) {
+                       $now = wfGetDB( DB_SLAVE )->addQuotes( wfTimestampNow() 
);
+
+                       switch ( $conds['status'] ) {
+                               case 'passed':
+                                       $conds[] = 'end < ' . $now;
+                                       break;
+                               case 'planned':
+                                       $conds[] = 'start > ' . $now;
+                                       break;
+                               case 'current':
+                                       $conds[] = 'end >= ' . $now;
+                                       $conds[] = 'start <= ' . $now;
+                                       break;
+                       }
+
+                       unset( $conds['status'] );
+               }
+
+               return $conds;
+       }
+
+}


Property changes on: 
trunk/extensions/EducationProgram/includes/EPCoursePager.php
___________________________________________________________________
Added: svn:eol-style
   + native

Modified: trunk/extensions/EducationProgram/includes/EPMC.php
===================================================================
--- trunk/extensions/EducationProgram/includes/EPMC.php 2012-01-21 00:04:09 UTC 
(rev 109664)
+++ trunk/extensions/EducationProgram/includes/EPMC.php 2012-01-21 00:09:24 UTC 
(rev 109665)
@@ -1,18 +1,18 @@
 <?php
 
 /**
- * Class representing a single course.
+ * Class representing a single master course.
  * These describe a specific course, time-independent.
  *
  * @since 0.1
  *
- * @file EPCourse.php
+ * @file EPMC.php
  * @ingroup EducationProgram
  *
  * @licence GNU GPL v3 or later
  * @author Jeroen De Dauw < [email protected] >
  */
-class EPCourse extends EPDBObject {
+class EPMC extends EPDBObject {
 
        /**
         * Field for caching the linked org.

Modified: trunk/extensions/EducationProgram/includes/EPMCPager.php
===================================================================
--- trunk/extensions/EducationProgram/includes/EPMCPager.php    2012-01-21 
00:04:09 UTC (rev 109664)
+++ trunk/extensions/EducationProgram/includes/EPMCPager.php    2012-01-21 
00:09:24 UTC (rev 109665)
@@ -1,17 +1,17 @@
 <?php
 
 /**
- * Course pager, primarily for Special:Courses.
+ * Master course pager.
  *
  * @since 0.1
  *
- * @file EPCoursePager.php
+ * @file EPMCPager.php
  * @ingroup EductaionProgram
  *
  * @licence GNU GPL v3 or later
  * @author Jeroen De Dauw < [email protected] >
  */
-class EPCoursePager extends EPPager {
+class EPMCPager extends EPPager {
 
        /**
         * Constructor.
@@ -20,7 +20,7 @@
         * @param array $conds
         */
        public function __construct( IContextSource $context, array $conds = 
array() ) {
-               parent::__construct( $context, $conds, 'EPCourse' );
+               parent::__construct( $context, $conds, 'EPMC' );
        }
 
        /**

Deleted: trunk/extensions/EducationProgram/includes/EPTerm.php
===================================================================
--- trunk/extensions/EducationProgram/includes/EPTerm.php       2012-01-21 
00:04:09 UTC (rev 109664)
+++ trunk/extensions/EducationProgram/includes/EPTerm.php       2012-01-21 
00:09:24 UTC (rev 109665)
@@ -1,480 +0,0 @@
-<?php
-
-/**
- * Class representing a single term.
- * These are "instances" of a course in a certain period.
- *
- * @since 0.1
- *
- * @file EPTerm.php
- * @ingroup EducationProgram
- *
- * @licence GNU GPL v3 or later
- * @author Jeroen De Dauw < [email protected] >
- */
-class EPTerm extends EPDBObject {
-
-       /**
-        * Field for caching the linked course.
-        *
-        * @since 0.1
-        * @var EPCourse|false
-        */
-       protected $course = false;
-
-       /**
-        * Field for caching the linked org.
-        *
-        * @since 0.1
-        * @var EPOrg|false
-        */
-       protected $org = false;
-
-       /**
-        * Cached array of the linked EPStudent objects.
-        *
-        * @since 0.1
-        * @var array|false
-        */
-       protected $students = false;
-
-       /**
-        * Returns a list of statuses a term can have.
-        * Keys are messages, values are identifiers.
-        *
-        * @since 0.1
-        *
-        * @return array
-        */
-       public static function getStatuses() {
-               return array(
-                       wfMsg( 'ep-term-status-passed' ) => 'passed',
-                       wfMsg( 'ep-term-status-current' ) => 'current',
-                       wfMsg( 'ep-term-status-planned' ) => 'planned',
-               );
-       }
-
-       /**
-        * Returns the message for the provided status identifier.
-        *
-        * @since 0.1
-        *
-        * @param string $status
-        *
-        * @return string
-        */
-       public static function getStatusMessage( $status ) {
-               static $map = null;
-
-               if ( is_null( $map ) ) {
-                       $map = array_flip( self::getStatuses() );
-               }
-
-               return $map[$status];
-       }
-
-       /**
-        * @see parent::getFieldTypes
-        *
-        * @since 0.1
-        *
-        * @return array
-        */
-       protected static function getFieldTypes() {
-               return array(
-                       'id' => 'id',
-                       'course_id' => 'id',
-                       'org_id' => 'id',
-
-                       'year' => 'int',
-                       'start' => 'str', // TS_MW
-                       'end' => 'str', // TS_MW
-                       'description' => 'str',
-                       'token' => 'str',
-                       'online_ambs' => 'array',
-                       'campus_ambs' => 'array',
-               
-                       'students' => 'int',
-               );
-       }
-
-       /**
-        * (non-PHPdoc)
-        * @see EPDBObject::getDefaults()
-        */
-       public static function getDefaults() {
-               return array(
-                       'year' => substr( wfTimestamp( TS_MW ), 0, 4 ),
-                       'start' => wfTimestamp( TS_MW ),
-                       'end' => wfTimestamp( TS_MW ),
-                       'description' => '',
-                       'token' => '',
-                       'online_ambs' => array(),
-                       'campus_ambs' => array(),
-               
-                       'students' => 0,
-               );
-       }
-
-       /**
-        * Returns the students enrolled in this term.
-        *
-        * @since 0.1
-        *
-        * @param string|array|null $fields
-        * @param array $conditions
-        *
-        * @return array of EPStudent
-        */
-       protected function doGetStudents( $fields, array $conditions ) {
-               $conditions[] = array( array( 'ep_terms', 'id' ), 
$this->getId() );
-
-               return EPStudent::select(
-                       $fields,
-                       $conditions,
-                       array(),
-                       array(
-                               'ep_students_per_term' => array( 'INNER JOIN', 
array( array( array( 'ep_students_per_term', 'student_id' ), array( 
'ep_students', 'id' ) ) ) ),
-                               'ep_terms' => array( 'INNER JOIN', array( 
array( array( 'ep_students_per_term', 'term_id' ), array( 'ep_terms', 'id' ) ) 
) )
-                       )
-               );
-       }
-
-       /**
-        * Returns the students enrolled in this term.
-        * Caches the result when no conditions are provided and all fields are 
selected.
-        *
-        * @since 0.1
-        *
-        * @param string|array|null $fields
-        * @param array $conditions
-        *
-        * @return array of EPStudent
-        */
-       public function getStudents( $fields = null, array $conditions = 
array() ) {
-               if ( count( $conditions ) !== 0 ) {
-                       return $this->doGetStudents( $fields, $conditions );
-               }
-
-               if ( $this->students === false ) {
-                       $students = $this->doGetStudents( $fields, $conditions 
);
-
-                       if ( is_null( $fields ) ) {
-                               $this->students = $students;
-                       }
-
-                       return $students;
-               }
-               else {
-                       return $this->students;
-               }
-       }
-
-       /**
-        * (non-PHPdoc)
-        * @see EPDBObject::loadSummaryFields()
-        */
-       public function loadSummaryFields( $summaryFields = null ) {
-               if ( is_null( $summaryFields ) ) {
-                       $summaryFields = array( 'org_id', 'students' );
-               }
-               else {
-                       $summaryFields = (array)$summaryFields;
-               }
-
-               $fields = array();
-
-               if ( in_array( 'org_id', $summaryFields ) ) {
-                       $fields['org_id'] = $this->getCourse( 'org_id' 
)->getField( 'org_id' );
-               }
-               
-               if ( in_array( 'students', $summaryFields ) ) {
-                       $fields['students'] = wfGetDB( DB_SLAVE )->select(
-                               'ep_students_per_term',
-                               'COUNT(*) AS rowcount',
-                               array( 'spt_term_id' => $this->getId() )
-                       );
-
-                       $fields['students'] = 
$fields['students']->fetchObject()->rowcount;
-               }
-
-               $this->setFields( $fields );
-       }
-
-       /**
-        * (non-PHPdoc)
-        * @see EPDBObject::insertIntoDB()
-        */
-       protected function insertIntoDB() {
-               if ( !$this->hasField( 'org_id' ) ) {
-                       $this->setField( 'org_id', $this->getCourse( 'org_id' 
)->getField( 'org_id' ) );
-               }
-
-               $success = parent::insertIntoDB();
-
-               if ( $success && $this->updateSummaries ) {
-                       EPOrg::updateSummaryFields( array( 'terms', 'active' ), 
array( 'id' => $this->getField( 'org_id' ) ) );
-                       EPCourse::updateSummaryFields( 'active', array( 'id' => 
$this->getField( 'course_id' ) ) );
-               }
-
-               return $success;
-       }
-
-       /**
-        * (non-PHPdoc)
-        * @see EPDBObject::removeFromDB()
-        */
-       public function removeFromDB() {
-               $id = $this->getId();
-
-               if ( $this->updateSummaries ) {
-                       $this->loadFields( array( 'org_id', 'course_id' ) );
-                       $orgId = $this->getField( 'org_id' );
-                       $courseId = $this->getField( 'course_id' );
-               }
-
-               $success = parent::removeFromDB();
-
-               if ( $success && $this->updateSummaries ) {
-                       EPCourse::updateSummaryFields( 'students', array( 'id' 
=> $courseId ) );
-                       EPOrg::updateSummaryFields( array( 'terms', 'students', 
'active' ), array( 'id' => $orgId ) );
-               }
-
-               if ( $success ) {
-                       $success = wfGetDB( DB_MASTER )->delete( 
'ep_students_per_term', array( 'spt_term_id' => $id ) ) && $success;
-               }
-
-               return $success;
-       }
-
-       /**
-        * (non-PHPdoc)
-        * @see EPDBObject::updateInDB()
-        */
-       protected function updateInDB() {
-               if ( $this->updateSummaries ) {
-                       $oldOrgId = $this->hasField( 'org_id' ) ? 
self::selectFieldsRow( 'org_id', array( 'id' => $this->getId() ) ) : false;
-                       $oldCourseId = $this->hasField( 'course_id' ) ? 
self::selectFieldsRow( 'course_id', array( 'id' => $this->getId() ) ) : false;
-               }
-
-               if ( $this->hasField( 'course_id' ) ) {
-                       $oldCourseId = self::selectFieldsRow( 'course_id', 
array( 'id' => $this->getId() ) );
-
-                       if ( $this->getField( 'course_id' ) !== $oldCourseId ) {
-                               $this->setField( 'org_id', 
EPCourse::selectFieldsRow( 'org_id', array( 'id' => $this->getField( 
'course_id' ) ) ) );
-                       }
-               }
-
-               $success = parent::updateInDB();
-
-               if ( $this->updateSummaries && $success ) {
-                       if ( $oldOrgId !== false && $oldOrgId !== 
$this->getField( 'org_id' ) ) {
-                               $conds = array( 'id' => array( $oldOrgId, 
$this->getField( 'org_id' ) ) );
-                               EPOrg::updateSummaryFields( array( 'terms', 
'students', 'active' ), $conds );
-                       }
-
-                       if ( $oldCourseId !== false && $oldCourseId !== 
$this->getField( 'org_id' ) ) {
-                               $conds = array( 'id' => array( $oldCourseId, 
$this->getField( 'course_id' ) ) );
-                               EPCourse::updateSummaryFields( array( 'active', 
'students' ), $conds );
-                       }
-               }
-
-               return $success;
-       }
-
-       /**
-        * Returns the course associated with this term.
-        *
-        * @since 0.1
-        *
-        * @param string|array|null $fields
-        *
-        * @return EPCourse
-        */
-       public function getCourse( $fields = null ) {
-               if ( $this->course === false ) {
-                       $this->course = EPCourse::selectRow( $fields, array( 
'id' => $this->loadAndGetField( 'course_id' ) ) );
-               }
-
-               return $this->course;
-       }
-
-       /**
-        * Returns the org associated with this term.
-        *
-        * @since 0.1
-        *
-        * @param string|array|null $fields
-        *
-        * @return EPOrg
-        */
-       public function getOrg( $fields = null ) {
-               if ( $this->org === false ) {
-                       $this->org = EPOrg::selectRow( $fields, array( 'id' => 
$this->loadAndGetField( 'org_id' ) ) );
-               }
-
-               return $this->org;
-       }
-
-       /**
-        * Display a pager with terms.
-        *
-        * @since 0.1
-        *
-        * @param IContextSource $context
-        * @param array $conditions
-        */
-       public static function displayPager( IContextSource $context, array 
$conditions = array() ) {
-               $pager = new EPTermPager( $context, $conditions );
-
-               if ( $pager->getNumRows() ) {
-                       $context->getOutput()->addHTML(
-                               $pager->getFilterControl() .
-                               $pager->getNavigationBar() .
-                               $pager->getBody() .
-                               $pager->getNavigationBar() .
-                               $pager->getMultipleItemControl()
-                       );
-               }
-               else {
-                       $context->getOutput()->addHTML( 
$pager->getFilterControl( true ) );
-                       $context->getOutput()->addWikiMsg( 'ep-terms-noresults' 
);
-               }
-       }
-
-       /**
-        * Adds a control to add a term org to the provided context.
-        * Additional arguments can be provided to set the default values for 
the control fields.
-        *
-        * @since 0.1
-        *
-        * @param IContextSource $context
-        * @param array $args
-        *
-        * @return boolean
-        */
-       public static function displayAddNewControl( IContextSource $context, 
array $args ) {
-               if ( !$context->getUser()->isAllowed( 'ep-term' ) ) {
-                       return false;
-               }
-
-               $out = $context->getOutput();
-
-               $out->addHTML( Html::openElement(
-                       'form',
-                       array(
-                               'method' => 'post',
-                               'action' => SpecialPage::getTitleFor( 
'EditTerm' )->getLocalURL(),
-                       )
-               ) );
-
-               $out->addHTML( '<fieldset>' );
-
-               $out->addHTML( '<legend>' . wfMsgHtml( 'ep-terms-addnew' ) . 
'</legend>' );
-
-               $out->addHTML( Html::element( 'p', array(), wfMsg( 
'ep-terms-namedoc' ) ) );
-
-               $out->addHTML( Html::element( 'label', array( 'for' => 
'newcourse' ), wfMsg( 'ep-terms-newcourse' ) ) );
-
-               $select = new XmlSelect(
-                       'newcourse',
-                       'newcourse',
-                       array_key_exists( 'course', $args ) ? $args['course'] : 
false
-               );
-
-               $select->addOptions( EPCourse::getCourseOptions() );
-               $out->addHTML( $select->getHTML() );
-
-               $out->addHTML( '&#160;' . Xml::inputLabel( wfMsg( 
'ep-terms-newyear' ), 'newyear', 'newyear', 10 ) );
-
-               $out->addHTML( '&#160;' . Html::input(
-                       'addnewterm',
-                       wfMsg( 'ep-terms-add' ),
-                       'submit'
-               ) );
-
-               $out->addHTML( Html::hidden( 'isnew', 1 ) );
-
-               $out->addHTML( '</fieldset></form>' );
-
-               return true;
-       }
-
-       /**
-        * Adds a control to add a new term to the provided context
-        * or show a message if this is not possible for some reason.
-        *
-        * @since 0.1
-        *
-        * @param IContextSource $context
-        * @param array $args
-        */
-       public static function displayAddNewRegion( IContextSource $context, 
array $args = array() ) {
-               if ( EPCourse::has() ) {
-                       EPTerm::displayAddNewControl( $context, $args );
-               }
-               elseif ( $context->getUser()->isAllowed( 'ep-course' ) ) {
-                       $context->getOutput()->addWikiMsg( 
'ep-terms-addcoursefirst' );
-               }
-       }
-
-       /**
-        * Gets the amount of days left, rounded up to the nearest integer.
-        *
-        * @since 0.1
-        *
-        * @return integer
-        */
-       public function getDaysLeft() {
-               $timeLeft = (int)wfTimestamp( TS_UNIX, $this->getField( 'end' ) 
) - time();
-               return (int)ceil( $timeLeft / ( 60 * 60 * 24 ) );
-       }
-
-       /**
-        * Gets the amount of days since term start, rounded up to the nearest 
integer.
-        *
-        * @since 0.1
-        *
-        * @return integer
-        */
-       public function getDaysPassed() {
-               $daysPassed = time() - (int)wfTimestamp( TS_UNIX, 
$this->getField( 'start' ) );
-               return (int)ceil( $daysPassed / ( 60 * 60 * 24 ) );
-       }
-
-       /**
-        * Returns the status of the term.
-        *
-        * @since 0.1
-        *
-        * @return string
-        */
-       public function getStatus() {
-               if ( $this->getDaysLeft() <= 0 ) {
-                       $status = 'passed';
-               }
-               elseif ( $this->getDaysPassed() <= 0 ) {
-                       $status = 'planned';
-               }
-               else {
-                       $status = 'current';
-               }
-
-               return $status;
-       }
-
-       /**
-        * Get a link to Special:Term/id.
-        *
-        * @since 0.1
-        *
-        * @return string
-        */
-       public function getLink() {
-               return Linker::linkKnown(
-                       SpecialPage::getTitleFor( 'Term', $this->getId() ),
-                       htmlspecialchars( $this->getId() )
-               );
-       }
-
-}

Deleted: trunk/extensions/EducationProgram/includes/EPTermPager.php
===================================================================
--- trunk/extensions/EducationProgram/includes/EPTermPager.php  2012-01-21 
00:04:09 UTC (rev 109664)
+++ trunk/extensions/EducationProgram/includes/EPTermPager.php  2012-01-21 
00:09:24 UTC (rev 109665)
@@ -1,245 +0,0 @@
-<?php
-
-/**
- * Term pager, primarily for Special:Terms.
- *
- * @since 0.1
- *
- * @file EPTermPager.php
- * @ingroup EductaionProgram
- *
- * @licence GNU GPL v3 or later
- * @author Jeroen De Dauw < [email protected] >
- */
-class EPTermPager extends EPPager {
-
-       /**
-        * Constructor.
-        *
-        * @param IContextSource $context
-        * @param array $conds
-        */
-       public function __construct( IContextSource $context, array $conds = 
array() ) {
-               parent::__construct( $context, $conds, 'EPTerm' );
-       }
-
-       /**
-        * (non-PHPdoc)
-        * @see EPPager::getFields()
-        */
-       public function getFields() {
-               return array(
-                       'id',
-                       'course_id',
-                       'year',
-                       'start',
-                       'end',
-                       'students',
-               );
-       }
-
-       /**
-        * (non-PHPdoc)
-        * @see TablePager::getRowClass()
-        */
-       function getRowClass( $row ) {
-               return 'ep-term-row';
-       }
-
-       /**
-        * (non-PHPdoc)
-        * @see TablePager::getTableClass()
-        */
-       public function getTableClass() {
-               return 'TablePager ep-terms';
-       }
-
-       /**
-        * (non-PHPdoc)
-        * @see EPPager::getFormattedValue()
-        */
-       public function getFormattedValue( $name, $value ) {
-               switch ( $name ) {
-                       case 'id':
-                               $value = Linker::linkKnown(
-                                       SpecialPage::getTitleFor( 'Term', 
$value ),
-                                       htmlspecialchars( 
$this->getLanguage()->formatNum( $value, true ) )
-                               );
-                               break;
-                       case 'course_id':
-                               $value = EPCourse::selectRow( 'name', array( 
'id' => $value ) )->getField( 'name' );
-
-                               $value = Linker::linkKnown(
-                                       SpecialPage::getTitleFor( 'Course', 
$value ),
-                                       htmlspecialchars( $value )
-                               );
-                               break;
-                       case 'year':
-                               $value = htmlspecialchars( 
$this->getLanguage()->formatNum( $value, true ) );
-                               break;
-                       case 'start': case 'end':
-                               $value = htmlspecialchars( 
$this->getLanguage()->date( $value ) );
-                               break;
-                       case '_status':
-                               $value = htmlspecialchars( 
EPTerm::getStatusMessage( $this->currentObject->getStatus() ) );
-                       case 'students':
-                               $value = htmlspecialchars( 
$this->getLanguage()->formatNum( $value ) );
-                               break;
-               }
-
-               return $value;
-       }
-
-       /**
-        * (non-PHPdoc)
-        * @see EPPager::getSortableFields()
-        */
-       protected function getSortableFields() {
-               return array(
-                       'id',
-                       'year',
-                       'start',
-                       'end',
-                       'students',
-               );
-       }
-
-       /**
-        * (non-PHPdoc)
-        * @see EPPager::getFieldNames()
-        */
-       public function getFieldNames() {
-               $fields = parent::getFieldNames();
-
-               if ( array_key_exists( 'course_id', $this->conds ) && 
array_key_exists( 'org_id', $fields ) ) {
-                       unset( $fields['org_id'] );
-               }
-
-               $fields = wfArrayInsertAfter( $fields, array( '_status' => 
'status' ), 'students' );
-
-               return $fields;
-       }
-
-       /**
-        * (non-PHPdoc)
-        * @see EPPager::getFilterOptions()
-        */
-       protected function getFilterOptions() {
-               $options = array();
-
-               if ( !array_key_exists( 'course_id', $this->conds ) ) {
-                       $options['course_id'] = array(
-                               'type' => 'select',
-                               'options' => array_merge(
-                                       array( '' => '' ),
-                                       EPCourse::getCourseOptions( 
EPCourse::select( array( 'name', 'id' ) ) )
-                               ),
-                               'value' => '',
-                               'datatype' => 'int',
-                       );
-
-                       $options['org_id'] = array(
-                               'type' => 'select',
-                               'options' => array_merge(
-                                       array( '' => '' ),
-                                       EPOrg::getOrgOptions( EPOrg::select( 
array( 'name', 'id' ) ) )
-                               ),
-                               'value' => '',
-                               'datatype' => 'int',
-                       );
-               }
-
-               $years = EPTerm::selectFields( 'year', array(), array( 
'DISTINCT' ), array(), true );
-               asort( $years, SORT_NUMERIC );
-               $years = array_merge( array( '' ), $years );
-               $years = array_combine( $years, $years );
-
-               $options['year'] = array(
-                       'type' => 'select',
-                       'options' => $years,
-                       'value' => '',
-               );
-
-               $options['status'] = array(
-                       'type' => 'select',
-                       'options' => array_merge(
-                               array( '' => '' ),
-                               EPTerm::getStatuses()
-                       ),
-                       'value' => 'current',
-               );
-
-               return $options;
-       }
-
-       /**
-        * (non-PHPdoc)
-        * @see EPPager::getControlLinks()
-        */
-       protected function getControlLinks( EPDBObject $item ) {
-               $links = parent::getControlLinks( $item );
-
-               $links[] = $value = Linker::linkKnown(
-                       SpecialPage::getTitleFor( 'Term', $item->getId() ),
-                       wfMsgHtml( 'view' )
-               );
-
-               if ( $this->getUser()->isAllowed( 'ep-term' ) ) {
-                       $links[] = $value = Linker::linkKnown(
-                               SpecialPage::getTitleFor( 'EditTerm', 
$item->getId() ),
-                               wfMsgHtml( 'edit' )
-                       );
-
-                       $links[] = $this->getDeletionLink( 'term', 
$item->getId() );
-               }
-
-               return $links;
-       }
-
-       /**
-        * (non-PHPdoc)
-        * @see EPPager::getMultipleItemActions()
-        */
-       protected function getMultipleItemActions() {
-               $actions = parent::getMultipleItemActions();
-
-               if ( $this->getUser()->isAllowed( 'ep-term' ) ) {
-                       $actions[wfMsg( 'ep-pager-delete-selected' )] = array(
-                               'class' => 'ep-pager-delete-selected',
-                               'data-type' => 
ApiDeleteEducation::getTypeForClassName( $this->className )
-                       );
-               }
-               
-               return $actions;
-       }
-
-       /**
-        * (non-PHPdoc)
-        * @see EPPager::getConditions()
-        */
-       protected function getConditions() {
-               $conds = parent::getConditions();
-
-               if ( array_key_exists( 'status', $conds ) ) {
-                       $now = wfGetDB( DB_SLAVE )->addQuotes( wfTimestampNow() 
);
-
-                       switch ( $conds['status'] ) {
-                               case 'passed':
-                                       $conds[] = 'end < ' . $now;
-                                       break;
-                               case 'planned':
-                                       $conds[] = 'start > ' . $now;
-                                       break;
-                               case 'current':
-                                       $conds[] = 'end >= ' . $now;
-                                       $conds[] = 'start <= ' . $now;
-                                       break;
-                       }
-
-                       unset( $conds['status'] );
-               }
-
-               return $conds;
-       }
-
-}


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

Reply via email to