r108401 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:< r108400‎ | r108401 | r108402 >
Date:11:52, 9 January 2012
Author:jeroendedauw
Status:ok
Tags:
Comment:
work on course and term pagers
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.i18n.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPCoursePager.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPTerm.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPTermPager.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/includes/EPTermPager.php
——@@ -78,6 +78,8 @@
7979 case 'start': case 'end':
8080 $value = $this->getLanguage()->date( $value );
8181 break;
 82+ case '_status':
 83+ $value = htmlspecialchars( EPTerm::getStatusMessage( $this->currentObject->getStatus() ) );
8284 }
8385
8486 return $value;
——@@ -107,6 +109,8 @@
108110 unset( $fields['org_id'] );
109111 }
110112
 113+ $fields = wfArrayInsertAfter( $fields, array( '_status' => 'status' ), 'end' );
 114+
111115 return $fields;
112116 }
113117
——@@ -150,6 +154,15 @@
151155 'value' => '',
152156 );
153157
 158+ $options['status'] = array(
 159+ 'type' => 'select',
 160+ 'options' => array_merge(
 161+ array( '' => '' ),
 162+ EPTerm::getStatuses()
 163+ ),
 164+ 'value' => '',
 165+ );
 166+
154167 return $options;
155168 }
156169
——@@ -187,4 +200,33 @@
188201 return $actions;
189202 }
190203
 204+ /**
 205+ * (non-PHPdoc)
 206+ * @see EPPager::getConditions()
 207+ */
 208+ protected function getConditions() {
 209+ $conds = parent::getConditions();
 210+
 211+ if ( array_key_exists( 'status', $conds ) ) {
 212+ $now = wfGetDB( DB_SLAVE )->addQuotes( wfTimestampNow() );
 213+
 214+ switch ( $conds['status'] ) {
 215+ case 'passed':
 216+ $conds[] = 'end < ' . $now;
 217+ break;
 218+ case 'planned':
 219+ $conds[] = 'start > ' . $now;
 220+ break;
 221+ case 'current':
 222+ $conds[] = 'end >= ' . $now;
 223+ $conds[] = 'start <= ' . $now;
 224+ break;
 225+ }
 226+
 227+ unset( $conds['status'] );
 228+ }
 229+
 230+ return $conds;
 231+ }
 232+
191233 }
Index: trunk/extensions/EducationProgram/includes/EPTerm.php
——@@ -29,8 +29,43 @@
3030 * @var EPOrg|false
3131 */
3232 protected $org = false;
33 -
 33+
3434 /**
 35+ * Returns a list of statuses a term can have.
 36+ * Keys are messages, values are identifiers.
 37+ *
 38+ * @since 0.1
 39+ *
 40+ * @return array
 41+ */
 42+ public static function getStatuses() {
 43+ return array(
 44+ wfMsg( 'ep-term-status-passed' ) => 'passed',
 45+ wfMsg( 'ep-term-status-current' ) => 'current',
 46+ wfMsg( 'ep-term-status-planned' ) => 'planned',
 47+ );
 48+ }
 49+
 50+ /**
 51+ * Returns the message for the provided status identifier.
 52+ *
 53+ * @since 0.1
 54+ *
 55+ * @param string $status
 56+ *
 57+ * @return string
 58+ */
 59+ public static function getStatusMessage( $status ) {
 60+ static $map = null;
 61+
 62+ if ( is_null( $map ) ) {
 63+ $map = array_flip( self::getStatuses() );
 64+ }
 65+
 66+ return $map[$status];
 67+ }
 68+
 69+ /**
3570 * @see parent::getFieldTypes
3671 *
3772 * @since 0.1
——@@ -324,4 +359,49 @@
325360 return false;
326361 }
327362
 363+ /**
 364+ * Gets the amount of days left, rounded up to the nearest integer.
 365+ *
 366+ * @since 0.1
 367+ *
 368+ * @return integer
 369+ */
 370+ public function getDaysLeft() {
 371+ $timeLeft = (int)wfTimestamp( TS_UNIX, $this->getField( 'end' ) ) - time();
 372+ return (int)ceil( $timeLeft / ( 60 * 60 * 24 ) );
 373+ }
 374+
 375+ /**
 376+ * Gets the amount of days since term start, rounded up to the nearest integer.
 377+ *
 378+ * @since 0.1
 379+ *
 380+ * @return integer
 381+ */
 382+ public function getDaysPassed() {
 383+ $daysPassed = time() - (int)wfTimestamp( TS_UNIX, $this->getField( 'start' ) );
 384+ return (int)ceil( $daysPassed / ( 60 * 60 * 24 ) );
 385+ }
 386+
 387+ /**
 388+ * Returns the status of the term.
 389+ *
 390+ * @since 0.1
 391+ *
 392+ * @return string
 393+ */
 394+ public function getStatus() {
 395+ if ( $this->getDaysLeft() <= 0 ) {
 396+ $status = 'passed';
 397+ }
 398+ elseif( $this->getDaysPassed() <= 0 ) {
 399+ $status = 'planned';
 400+ }
 401+ else {
 402+ $status = 'current';
 403+ }
 404+
 405+ return $status;
 406+ }
 407+
328408 }
Index: trunk/extensions/EducationProgram/includes/EPCoursePager.php
——@@ -31,6 +31,7 @@
3232 return array(
3333 'name',
3434 'org_id',
 35+ 'students',
3536 );
3637 }
3738
——@@ -70,6 +71,9 @@
7172 htmlspecialchars( $value )
7273 );
7374 break;
 75+ case 'students':
 76+ $value = htmlspecialchars( $this->getLanguage()->formatNum( $value ) );
 77+ break;
7478 }
7579
7680 return $value;
——@@ -87,6 +91,7 @@
8892 protected function getSortableFields() {
8993 return array(
9094 'name',
 95+ 'students',
9196 );
9297 }
9398
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php
——@@ -81,6 +81,11 @@
8282 'special-ambassadors' => 'Ambassadors',
8383 'special-ambassador' => 'Ambassador',
8484
 85+ // Term statuses
 86+ 'ep-term-status-passed' => 'Passed',
 87+ 'ep-term-status-current' => 'Current',
 88+ 'ep-term-status-planned' => 'Planned',
 89+
8590 // Special:Institutions
8691 'ep-institutions-nosuchinstitution' => 'There is no institution with name "$1". Existing institutions are listed below.',
8792 'ep-institutions-noresults' => 'There are no institutions to list.',
——@@ -134,10 +139,11 @@
135140 'eporgpager-header-students' => 'Students',
136141 'eporgpager-header-terms' => 'Terms',
137142
138 - // Institution pager
 143+ // Course pager
139144 'epcoursepager-header-name' => 'Name',
140145 'epcoursepager-header-org-id' => 'Institution',
141146 'epcoursepager-filter-org-id' => 'Institution',
 147+ 'epcoursepager-header-students' => 'Students',
142148
143149 // Term pager
144150 'eptermpager-header-id' => 'Id',
——@@ -148,6 +154,8 @@
149155 'eptermpager-filter-course-id' => 'Course',
150156 'eptermpager-filter-year' => 'Year',
151157 'eptermpager-filter-org-id' => 'Institution',
 158+ 'eptermpager-header-status' => 'Status',
 159+ 'eptermpager-filter-status' => 'Status',
152160
153161 // Student pager
154162 'epstudentpager-header-user-id' => 'User',

Status & tagging log