| Index: trunk/extensions/EducationProgram/includes/EPTermPager.php |
| — | — | @@ -78,6 +78,8 @@ |
| 79 | 79 | case 'start': case 'end': |
| 80 | 80 | $value = $this->getLanguage()->date( $value ); |
| 81 | 81 | break; |
| | 82 | + case '_status': |
| | 83 | + $value = htmlspecialchars( EPTerm::getStatusMessage( $this->currentObject->getStatus() ) ); |
| 82 | 84 | } |
| 83 | 85 | |
| 84 | 86 | return $value; |
| — | — | @@ -107,6 +109,8 @@ |
| 108 | 110 | unset( $fields['org_id'] ); |
| 109 | 111 | } |
| 110 | 112 | |
| | 113 | + $fields = wfArrayInsertAfter( $fields, array( '_status' => 'status' ), 'end' ); |
| | 114 | + |
| 111 | 115 | return $fields; |
| 112 | 116 | } |
| 113 | 117 | |
| — | — | @@ -150,6 +154,15 @@ |
| 151 | 155 | 'value' => '', |
| 152 | 156 | ); |
| 153 | 157 | |
| | 158 | + $options['status'] = array( |
| | 159 | + 'type' => 'select', |
| | 160 | + 'options' => array_merge( |
| | 161 | + array( '' => '' ), |
| | 162 | + EPTerm::getStatuses() |
| | 163 | + ), |
| | 164 | + 'value' => '', |
| | 165 | + ); |
| | 166 | + |
| 154 | 167 | return $options; |
| 155 | 168 | } |
| 156 | 169 | |
| — | — | @@ -187,4 +200,33 @@ |
| 188 | 201 | return $actions; |
| 189 | 202 | } |
| 190 | 203 | |
| | 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 | + |
| 191 | 233 | } |
| Index: trunk/extensions/EducationProgram/includes/EPTerm.php |
| — | — | @@ -29,8 +29,43 @@ |
| 30 | 30 | * @var EPOrg|false |
| 31 | 31 | */ |
| 32 | 32 | protected $org = false; |
| 33 | | - |
| | 33 | + |
| 34 | 34 | /** |
| | 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 | + /** |
| 35 | 70 | * @see parent::getFieldTypes |
| 36 | 71 | * |
| 37 | 72 | * @since 0.1 |
| — | — | @@ -324,4 +359,49 @@ |
| 325 | 360 | return false; |
| 326 | 361 | } |
| 327 | 362 | |
| | 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 | + |
| 328 | 408 | } |
| Index: trunk/extensions/EducationProgram/includes/EPCoursePager.php |
| — | — | @@ -31,6 +31,7 @@ |
| 32 | 32 | return array( |
| 33 | 33 | 'name', |
| 34 | 34 | 'org_id', |
| | 35 | + 'students', |
| 35 | 36 | ); |
| 36 | 37 | } |
| 37 | 38 | |
| — | — | @@ -70,6 +71,9 @@ |
| 71 | 72 | htmlspecialchars( $value ) |
| 72 | 73 | ); |
| 73 | 74 | break; |
| | 75 | + case 'students': |
| | 76 | + $value = htmlspecialchars( $this->getLanguage()->formatNum( $value ) ); |
| | 77 | + break; |
| 74 | 78 | } |
| 75 | 79 | |
| 76 | 80 | return $value; |
| — | — | @@ -87,6 +91,7 @@ |
| 88 | 92 | protected function getSortableFields() { |
| 89 | 93 | return array( |
| 90 | 94 | 'name', |
| | 95 | + 'students', |
| 91 | 96 | ); |
| 92 | 97 | } |
| 93 | 98 | |
| Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php |
| — | — | @@ -81,6 +81,11 @@ |
| 82 | 82 | 'special-ambassadors' => 'Ambassadors', |
| 83 | 83 | 'special-ambassador' => 'Ambassador', |
| 84 | 84 | |
| | 85 | + // Term statuses |
| | 86 | + 'ep-term-status-passed' => 'Passed', |
| | 87 | + 'ep-term-status-current' => 'Current', |
| | 88 | + 'ep-term-status-planned' => 'Planned', |
| | 89 | + |
| 85 | 90 | // Special:Institutions |
| 86 | 91 | 'ep-institutions-nosuchinstitution' => 'There is no institution with name "$1". Existing institutions are listed below.', |
| 87 | 92 | 'ep-institutions-noresults' => 'There are no institutions to list.', |
| — | — | @@ -134,10 +139,11 @@ |
| 135 | 140 | 'eporgpager-header-students' => 'Students', |
| 136 | 141 | 'eporgpager-header-terms' => 'Terms', |
| 137 | 142 | |
| 138 | | - // Institution pager |
| | 143 | + // Course pager |
| 139 | 144 | 'epcoursepager-header-name' => 'Name', |
| 140 | 145 | 'epcoursepager-header-org-id' => 'Institution', |
| 141 | 146 | 'epcoursepager-filter-org-id' => 'Institution', |
| | 147 | + 'epcoursepager-header-students' => 'Students', |
| 142 | 148 | |
| 143 | 149 | // Term pager |
| 144 | 150 | 'eptermpager-header-id' => 'Id', |
| — | — | @@ -148,6 +154,8 @@ |
| 149 | 155 | 'eptermpager-filter-course-id' => 'Course', |
| 150 | 156 | 'eptermpager-filter-year' => 'Year', |
| 151 | 157 | 'eptermpager-filter-org-id' => 'Institution', |
| | 158 | + 'eptermpager-header-status' => 'Status', |
| | 159 | + 'eptermpager-filter-status' => 'Status', |
| 152 | 160 | |
| 153 | 161 | // Student pager |
| 154 | 162 | 'epstudentpager-header-user-id' => 'User', |