r109665 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109664‎ | r109665 | r109666 >
Date:00:09, 21 January 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
follow up to r109656 - moving and renaming more stuff
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.hooks.php (modified) (history)
  • /trunk/extensions/EducationProgram/EducationProgram.i18n.php (modified) (history)
  • /trunk/extensions/EducationProgram/EducationProgram.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPCourse.php (added) (history)
  • /trunk/extensions/EducationProgram/includes/EPCoursePager.php (added) (history)
  • /trunk/extensions/EducationProgram/includes/EPMC.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPMCPager.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPTerm.php (deleted) (history)
  • /trunk/extensions/EducationProgram/includes/EPTermPager.php (deleted) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/includes/EPTerm.php
@@ -1,480 +0,0 @@
2 -<?php
3 -
4 -/**
5 - * Class representing a single term.
6 - * These are "instances" of a course in a certain period.
7 - *
8 - * @since 0.1
9 - *
10 - * @file EPTerm.php
11 - * @ingroup EducationProgram
12 - *
13 - * @licence GNU GPL v3 or later
14 - * @author Jeroen De Dauw < jeroendedauw@gmail.com >
15 - */
16 -class EPTerm extends EPDBObject {
17 -
18 - /**
19 - * Field for caching the linked course.
20 - *
21 - * @since 0.1
22 - * @var EPCourse|false
23 - */
24 - protected $course = false;
25 -
26 - /**
27 - * Field for caching the linked org.
28 - *
29 - * @since 0.1
30 - * @var EPOrg|false
31 - */
32 - protected $org = false;
33 -
34 - /**
35 - * Cached array of the linked EPStudent objects.
36 - *
37 - * @since 0.1
38 - * @var array|false
39 - */
40 - protected $students = false;
41 -
42 - /**
43 - * Returns a list of statuses a term can have.
44 - * Keys are messages, values are identifiers.
45 - *
46 - * @since 0.1
47 - *
48 - * @return array
49 - */
50 - public static function getStatuses() {
51 - return array(
52 - wfMsg( 'ep-term-status-passed' ) => 'passed',
53 - wfMsg( 'ep-term-status-current' ) => 'current',
54 - wfMsg( 'ep-term-status-planned' ) => 'planned',
55 - );
56 - }
57 -
58 - /**
59 - * Returns the message for the provided status identifier.
60 - *
61 - * @since 0.1
62 - *
63 - * @param string $status
64 - *
65 - * @return string
66 - */
67 - public static function getStatusMessage( $status ) {
68 - static $map = null;
69 -
70 - if ( is_null( $map ) ) {
71 - $map = array_flip( self::getStatuses() );
72 - }
73 -
74 - return $map[$status];
75 - }
76 -
77 - /**
78 - * @see parent::getFieldTypes
79 - *
80 - * @since 0.1
81 - *
82 - * @return array
83 - */
84 - protected static function getFieldTypes() {
85 - return array(
86 - 'id' => 'id',
87 - 'course_id' => 'id',
88 - 'org_id' => 'id',
89 -
90 - 'year' => 'int',
91 - 'start' => 'str', // TS_MW
92 - 'end' => 'str', // TS_MW
93 - 'description' => 'str',
94 - 'token' => 'str',
95 - 'online_ambs' => 'array',
96 - 'campus_ambs' => 'array',
97 -
98 - 'students' => 'int',
99 - );
100 - }
101 -
102 - /**
103 - * (non-PHPdoc)
104 - * @see EPDBObject::getDefaults()
105 - */
106 - public static function getDefaults() {
107 - return array(
108 - 'year' => substr( wfTimestamp( TS_MW ), 0, 4 ),
109 - 'start' => wfTimestamp( TS_MW ),
110 - 'end' => wfTimestamp( TS_MW ),
111 - 'description' => '',
112 - 'token' => '',
113 - 'online_ambs' => array(),
114 - 'campus_ambs' => array(),
115 -
116 - 'students' => 0,
117 - );
118 - }
119 -
120 - /**
121 - * Returns the students enrolled in this term.
122 - *
123 - * @since 0.1
124 - *
125 - * @param string|array|null $fields
126 - * @param array $conditions
127 - *
128 - * @return array of EPStudent
129 - */
130 - protected function doGetStudents( $fields, array $conditions ) {
131 - $conditions[] = array( array( 'ep_terms', 'id' ), $this->getId() );
132 -
133 - return EPStudent::select(
134 - $fields,
135 - $conditions,
136 - array(),
137 - array(
138 - 'ep_students_per_term' => array( 'INNER JOIN', array( array( array( 'ep_students_per_term', 'student_id' ), array( 'ep_students', 'id' ) ) ) ),
139 - 'ep_terms' => array( 'INNER JOIN', array( array( array( 'ep_students_per_term', 'term_id' ), array( 'ep_terms', 'id' ) ) ) )
140 - )
141 - );
142 - }
143 -
144 - /**
145 - * Returns the students enrolled in this term.
146 - * Caches the result when no conditions are provided and all fields are selected.
147 - *
148 - * @since 0.1
149 - *
150 - * @param string|array|null $fields
151 - * @param array $conditions
152 - *
153 - * @return array of EPStudent
154 - */
155 - public function getStudents( $fields = null, array $conditions = array() ) {
156 - if ( count( $conditions ) !== 0 ) {
157 - return $this->doGetStudents( $fields, $conditions );
158 - }
159 -
160 - if ( $this->students === false ) {
161 - $students = $this->doGetStudents( $fields, $conditions );
162 -
163 - if ( is_null( $fields ) ) {
164 - $this->students = $students;
165 - }
166 -
167 - return $students;
168 - }
169 - else {
170 - return $this->students;
171 - }
172 - }
173 -
174 - /**
175 - * (non-PHPdoc)
176 - * @see EPDBObject::loadSummaryFields()
177 - */
178 - public function loadSummaryFields( $summaryFields = null ) {
179 - if ( is_null( $summaryFields ) ) {
180 - $summaryFields = array( 'org_id', 'students' );
181 - }
182 - else {
183 - $summaryFields = (array)$summaryFields;
184 - }
185 -
186 - $fields = array();
187 -
188 - if ( in_array( 'org_id', $summaryFields ) ) {
189 - $fields['org_id'] = $this->getCourse( 'org_id' )->getField( 'org_id' );
190 - }
191 -
192 - if ( in_array( 'students', $summaryFields ) ) {
193 - $fields['students'] = wfGetDB( DB_SLAVE )->select(
194 - 'ep_students_per_term',
195 - 'COUNT(*) AS rowcount',
196 - array( 'spt_term_id' => $this->getId() )
197 - );
198 -
199 - $fields['students'] = $fields['students']->fetchObject()->rowcount;
200 - }
201 -
202 - $this->setFields( $fields );
203 - }
204 -
205 - /**
206 - * (non-PHPdoc)
207 - * @see EPDBObject::insertIntoDB()
208 - */
209 - protected function insertIntoDB() {
210 - if ( !$this->hasField( 'org_id' ) ) {
211 - $this->setField( 'org_id', $this->getCourse( 'org_id' )->getField( 'org_id' ) );
212 - }
213 -
214 - $success = parent::insertIntoDB();
215 -
216 - if ( $success && $this->updateSummaries ) {
217 - EPOrg::updateSummaryFields( array( 'terms', 'active' ), array( 'id' => $this->getField( 'org_id' ) ) );
218 - EPCourse::updateSummaryFields( 'active', array( 'id' => $this->getField( 'course_id' ) ) );
219 - }
220 -
221 - return $success;
222 - }
223 -
224 - /**
225 - * (non-PHPdoc)
226 - * @see EPDBObject::removeFromDB()
227 - */
228 - public function removeFromDB() {
229 - $id = $this->getId();
230 -
231 - if ( $this->updateSummaries ) {
232 - $this->loadFields( array( 'org_id', 'course_id' ) );
233 - $orgId = $this->getField( 'org_id' );
234 - $courseId = $this->getField( 'course_id' );
235 - }
236 -
237 - $success = parent::removeFromDB();
238 -
239 - if ( $success && $this->updateSummaries ) {
240 - EPCourse::updateSummaryFields( 'students', array( 'id' => $courseId ) );
241 - EPOrg::updateSummaryFields( array( 'terms', 'students', 'active' ), array( 'id' => $orgId ) );
242 - }
243 -
244 - if ( $success ) {
245 - $success = wfGetDB( DB_MASTER )->delete( 'ep_students_per_term', array( 'spt_term_id' => $id ) ) && $success;
246 - }
247 -
248 - return $success;
249 - }
250 -
251 - /**
252 - * (non-PHPdoc)
253 - * @see EPDBObject::updateInDB()
254 - */
255 - protected function updateInDB() {
256 - if ( $this->updateSummaries ) {
257 - $oldOrgId = $this->hasField( 'org_id' ) ? self::selectFieldsRow( 'org_id', array( 'id' => $this->getId() ) ) : false;
258 - $oldCourseId = $this->hasField( 'course_id' ) ? self::selectFieldsRow( 'course_id', array( 'id' => $this->getId() ) ) : false;
259 - }
260 -
261 - if ( $this->hasField( 'course_id' ) ) {
262 - $oldCourseId = self::selectFieldsRow( 'course_id', array( 'id' => $this->getId() ) );
263 -
264 - if ( $this->getField( 'course_id' ) !== $oldCourseId ) {
265 - $this->setField( 'org_id', EPCourse::selectFieldsRow( 'org_id', array( 'id' => $this->getField( 'course_id' ) ) ) );
266 - }
267 - }
268 -
269 - $success = parent::updateInDB();
270 -
271 - if ( $this->updateSummaries && $success ) {
272 - if ( $oldOrgId !== false && $oldOrgId !== $this->getField( 'org_id' ) ) {
273 - $conds = array( 'id' => array( $oldOrgId, $this->getField( 'org_id' ) ) );
274 - EPOrg::updateSummaryFields( array( 'terms', 'students', 'active' ), $conds );
275 - }
276 -
277 - if ( $oldCourseId !== false && $oldCourseId !== $this->getField( 'org_id' ) ) {
278 - $conds = array( 'id' => array( $oldCourseId, $this->getField( 'course_id' ) ) );
279 - EPCourse::updateSummaryFields( array( 'active', 'students' ), $conds );
280 - }
281 - }
282 -
283 - return $success;
284 - }
285 -
286 - /**
287 - * Returns the course associated with this term.
288 - *
289 - * @since 0.1
290 - *
291 - * @param string|array|null $fields
292 - *
293 - * @return EPCourse
294 - */
295 - public function getCourse( $fields = null ) {
296 - if ( $this->course === false ) {
297 - $this->course = EPCourse::selectRow( $fields, array( 'id' => $this->loadAndGetField( 'course_id' ) ) );
298 - }
299 -
300 - return $this->course;
301 - }
302 -
303 - /**
304 - * Returns the org associated with this term.
305 - *
306 - * @since 0.1
307 - *
308 - * @param string|array|null $fields
309 - *
310 - * @return EPOrg
311 - */
312 - public function getOrg( $fields = null ) {
313 - if ( $this->org === false ) {
314 - $this->org = EPOrg::selectRow( $fields, array( 'id' => $this->loadAndGetField( 'org_id' ) ) );
315 - }
316 -
317 - return $this->org;
318 - }
319 -
320 - /**
321 - * Display a pager with terms.
322 - *
323 - * @since 0.1
324 - *
325 - * @param IContextSource $context
326 - * @param array $conditions
327 - */
328 - public static function displayPager( IContextSource $context, array $conditions = array() ) {
329 - $pager = new EPTermPager( $context, $conditions );
330 -
331 - if ( $pager->getNumRows() ) {
332 - $context->getOutput()->addHTML(
333 - $pager->getFilterControl() .
334 - $pager->getNavigationBar() .
335 - $pager->getBody() .
336 - $pager->getNavigationBar() .
337 - $pager->getMultipleItemControl()
338 - );
339 - }
340 - else {
341 - $context->getOutput()->addHTML( $pager->getFilterControl( true ) );
342 - $context->getOutput()->addWikiMsg( 'ep-terms-noresults' );
343 - }
344 - }
345 -
346 - /**
347 - * Adds a control to add a term org to the provided context.
348 - * Additional arguments can be provided to set the default values for the control fields.
349 - *
350 - * @since 0.1
351 - *
352 - * @param IContextSource $context
353 - * @param array $args
354 - *
355 - * @return boolean
356 - */
357 - public static function displayAddNewControl( IContextSource $context, array $args ) {
358 - if ( !$context->getUser()->isAllowed( 'ep-term' ) ) {
359 - return false;
360 - }
361 -
362 - $out = $context->getOutput();
363 -
364 - $out->addHTML( Html::openElement(
365 - 'form',
366 - array(
367 - 'method' => 'post',
368 - 'action' => SpecialPage::getTitleFor( 'EditTerm' )->getLocalURL(),
369 - )
370 - ) );
371 -
372 - $out->addHTML( '<fieldset>' );
373 -
374 - $out->addHTML( '<legend>' . wfMsgHtml( 'ep-terms-addnew' ) . '</legend>' );
375 -
376 - $out->addHTML( Html::element( 'p', array(), wfMsg( 'ep-terms-namedoc' ) ) );
377 -
378 - $out->addHTML( Html::element( 'label', array( 'for' => 'newcourse' ), wfMsg( 'ep-terms-newcourse' ) ) );
379 -
380 - $select = new XmlSelect(
381 - 'newcourse',
382 - 'newcourse',
383 - array_key_exists( 'course', $args ) ? $args['course'] : false
384 - );
385 -
386 - $select->addOptions( EPCourse::getCourseOptions() );
387 - $out->addHTML( $select->getHTML() );
388 -
389 - $out->addHTML( '&#160;' . Xml::inputLabel( wfMsg( 'ep-terms-newyear' ), 'newyear', 'newyear', 10 ) );
390 -
391 - $out->addHTML( '&#160;' . Html::input(
392 - 'addnewterm',
393 - wfMsg( 'ep-terms-add' ),
394 - 'submit'
395 - ) );
396 -
397 - $out->addHTML( Html::hidden( 'isnew', 1 ) );
398 -
399 - $out->addHTML( '</fieldset></form>' );
400 -
401 - return true;
402 - }
403 -
404 - /**
405 - * Adds a control to add a new term to the provided context
406 - * or show a message if this is not possible for some reason.
407 - *
408 - * @since 0.1
409 - *
410 - * @param IContextSource $context
411 - * @param array $args
412 - */
413 - public static function displayAddNewRegion( IContextSource $context, array $args = array() ) {
414 - if ( EPCourse::has() ) {
415 - EPTerm::displayAddNewControl( $context, $args );
416 - }
417 - elseif ( $context->getUser()->isAllowed( 'ep-course' ) ) {
418 - $context->getOutput()->addWikiMsg( 'ep-terms-addcoursefirst' );
419 - }
420 - }
421 -
422 - /**
423 - * Gets the amount of days left, rounded up to the nearest integer.
424 - *
425 - * @since 0.1
426 - *
427 - * @return integer
428 - */
429 - public function getDaysLeft() {
430 - $timeLeft = (int)wfTimestamp( TS_UNIX, $this->getField( 'end' ) ) - time();
431 - return (int)ceil( $timeLeft / ( 60 * 60 * 24 ) );
432 - }
433 -
434 - /**
435 - * Gets the amount of days since term start, rounded up to the nearest integer.
436 - *
437 - * @since 0.1
438 - *
439 - * @return integer
440 - */
441 - public function getDaysPassed() {
442 - $daysPassed = time() - (int)wfTimestamp( TS_UNIX, $this->getField( 'start' ) );
443 - return (int)ceil( $daysPassed / ( 60 * 60 * 24 ) );
444 - }
445 -
446 - /**
447 - * Returns the status of the term.
448 - *
449 - * @since 0.1
450 - *
451 - * @return string
452 - */
453 - public function getStatus() {
454 - if ( $this->getDaysLeft() <= 0 ) {
455 - $status = 'passed';
456 - }
457 - elseif ( $this->getDaysPassed() <= 0 ) {
458 - $status = 'planned';
459 - }
460 - else {
461 - $status = 'current';
462 - }
463 -
464 - return $status;
465 - }
466 -
467 - /**
468 - * Get a link to Special:Term/id.
469 - *
470 - * @since 0.1
471 - *
472 - * @return string
473 - */
474 - public function getLink() {
475 - return Linker::linkKnown(
476 - SpecialPage::getTitleFor( 'Term', $this->getId() ),
477 - htmlspecialchars( $this->getId() )
478 - );
479 - }
480 -
481 -}
Index: trunk/extensions/EducationProgram/includes/EPTermPager.php
@@ -1,245 +0,0 @@
2 -<?php
3 -
4 -/**
5 - * Term pager, primarily for Special:Terms.
6 - *
7 - * @since 0.1
8 - *
9 - * @file EPTermPager.php
10 - * @ingroup EductaionProgram
11 - *
12 - * @licence GNU GPL v3 or later
13 - * @author Jeroen De Dauw < jeroendedauw@gmail.com >
14 - */
15 -class EPTermPager extends EPPager {
16 -
17 - /**
18 - * Constructor.
19 - *
20 - * @param IContextSource $context
21 - * @param array $conds
22 - */
23 - public function __construct( IContextSource $context, array $conds = array() ) {
24 - parent::__construct( $context, $conds, 'EPTerm' );
25 - }
26 -
27 - /**
28 - * (non-PHPdoc)
29 - * @see EPPager::getFields()
30 - */
31 - public function getFields() {
32 - return array(
33 - 'id',
34 - 'course_id',
35 - 'year',
36 - 'start',
37 - 'end',
38 - 'students',
39 - );
40 - }
41 -
42 - /**
43 - * (non-PHPdoc)
44 - * @see TablePager::getRowClass()
45 - */
46 - function getRowClass( $row ) {
47 - return 'ep-term-row';
48 - }
49 -
50 - /**
51 - * (non-PHPdoc)
52 - * @see TablePager::getTableClass()
53 - */
54 - public function getTableClass() {
55 - return 'TablePager ep-terms';
56 - }
57 -
58 - /**
59 - * (non-PHPdoc)
60 - * @see EPPager::getFormattedValue()
61 - */
62 - public function getFormattedValue( $name, $value ) {
63 - switch ( $name ) {
64 - case 'id':
65 - $value = Linker::linkKnown(
66 - SpecialPage::getTitleFor( 'Term', $value ),
67 - htmlspecialchars( $this->getLanguage()->formatNum( $value, true ) )
68 - );
69 - break;
70 - case 'course_id':
71 - $value = EPCourse::selectRow( 'name', array( 'id' => $value ) )->getField( 'name' );
72 -
73 - $value = Linker::linkKnown(
74 - SpecialPage::getTitleFor( 'Course', $value ),
75 - htmlspecialchars( $value )
76 - );
77 - break;
78 - case 'year':
79 - $value = htmlspecialchars( $this->getLanguage()->formatNum( $value, true ) );
80 - break;
81 - case 'start': case 'end':
82 - $value = htmlspecialchars( $this->getLanguage()->date( $value ) );
83 - break;
84 - case '_status':
85 - $value = htmlspecialchars( EPTerm::getStatusMessage( $this->currentObject->getStatus() ) );
86 - case 'students':
87 - $value = htmlspecialchars( $this->getLanguage()->formatNum( $value ) );
88 - break;
89 - }
90 -
91 - return $value;
92 - }
93 -
94 - /**
95 - * (non-PHPdoc)
96 - * @see EPPager::getSortableFields()
97 - */
98 - protected function getSortableFields() {
99 - return array(
100 - 'id',
101 - 'year',
102 - 'start',
103 - 'end',
104 - 'students',
105 - );
106 - }
107 -
108 - /**
109 - * (non-PHPdoc)
110 - * @see EPPager::getFieldNames()
111 - */
112 - public function getFieldNames() {
113 - $fields = parent::getFieldNames();
114 -
115 - if ( array_key_exists( 'course_id', $this->conds ) && array_key_exists( 'org_id', $fields ) ) {
116 - unset( $fields['org_id'] );
117 - }
118 -
119 - $fields = wfArrayInsertAfter( $fields, array( '_status' => 'status' ), 'students' );
120 -
121 - return $fields;
122 - }
123 -
124 - /**
125 - * (non-PHPdoc)
126 - * @see EPPager::getFilterOptions()
127 - */
128 - protected function getFilterOptions() {
129 - $options = array();
130 -
131 - if ( !array_key_exists( 'course_id', $this->conds ) ) {
132 - $options['course_id'] = array(
133 - 'type' => 'select',
134 - 'options' => array_merge(
135 - array( '' => '' ),
136 - EPCourse::getCourseOptions( EPCourse::select( array( 'name', 'id' ) ) )
137 - ),
138 - 'value' => '',
139 - 'datatype' => 'int',
140 - );
141 -
142 - $options['org_id'] = array(
143 - 'type' => 'select',
144 - 'options' => array_merge(
145 - array( '' => '' ),
146 - EPOrg::getOrgOptions( EPOrg::select( array( 'name', 'id' ) ) )
147 - ),
148 - 'value' => '',
149 - 'datatype' => 'int',
150 - );
151 - }
152 -
153 - $years = EPTerm::selectFields( 'year', array(), array( 'DISTINCT' ), array(), true );
154 - asort( $years, SORT_NUMERIC );
155 - $years = array_merge( array( '' ), $years );
156 - $years = array_combine( $years, $years );
157 -
158 - $options['year'] = array(
159 - 'type' => 'select',
160 - 'options' => $years,
161 - 'value' => '',
162 - );
163 -
164 - $options['status'] = array(
165 - 'type' => 'select',
166 - 'options' => array_merge(
167 - array( '' => '' ),
168 - EPTerm::getStatuses()
169 - ),
170 - 'value' => 'current',
171 - );
172 -
173 - return $options;
174 - }
175 -
176 - /**
177 - * (non-PHPdoc)
178 - * @see EPPager::getControlLinks()
179 - */
180 - protected function getControlLinks( EPDBObject $item ) {
181 - $links = parent::getControlLinks( $item );
182 -
183 - $links[] = $value = Linker::linkKnown(
184 - SpecialPage::getTitleFor( 'Term', $item->getId() ),
185 - wfMsgHtml( 'view' )
186 - );
187 -
188 - if ( $this->getUser()->isAllowed( 'ep-term' ) ) {
189 - $links[] = $value = Linker::linkKnown(
190 - SpecialPage::getTitleFor( 'EditTerm', $item->getId() ),
191 - wfMsgHtml( 'edit' )
192 - );
193 -
194 - $links[] = $this->getDeletionLink( 'term', $item->getId() );
195 - }
196 -
197 - return $links;
198 - }
199 -
200 - /**
201 - * (non-PHPdoc)
202 - * @see EPPager::getMultipleItemActions()
203 - */
204 - protected function getMultipleItemActions() {
205 - $actions = parent::getMultipleItemActions();
206 -
207 - if ( $this->getUser()->isAllowed( 'ep-term' ) ) {
208 - $actions[wfMsg( 'ep-pager-delete-selected' )] = array(
209 - 'class' => 'ep-pager-delete-selected',
210 - 'data-type' => ApiDeleteEducation::getTypeForClassName( $this->className )
211 - );
212 - }
213 -
214 - return $actions;
215 - }
216 -
217 - /**
218 - * (non-PHPdoc)
219 - * @see EPPager::getConditions()
220 - */
221 - protected function getConditions() {
222 - $conds = parent::getConditions();
223 -
224 - if ( array_key_exists( 'status', $conds ) ) {
225 - $now = wfGetDB( DB_SLAVE )->addQuotes( wfTimestampNow() );
226 -
227 - switch ( $conds['status'] ) {
228 - case 'passed':
229 - $conds[] = 'end < ' . $now;
230 - break;
231 - case 'planned':
232 - $conds[] = 'start > ' . $now;
233 - break;
234 - case 'current':
235 - $conds[] = 'end >= ' . $now;
236 - $conds[] = 'start <= ' . $now;
237 - break;
238 - }
239 -
240 - unset( $conds['status'] );
241 - }
242 -
243 - return $conds;
244 - }
245 -
246 -}
Index: trunk/extensions/EducationProgram/includes/EPMCPager.php
@@ -1,17 +1,17 @@
22 <?php
33
44 /**
5 - * Course pager, primarily for Special:Courses.
 5+ * Master course pager.
66 *
77 * @since 0.1
88 *
9 - * @file EPCoursePager.php
 9+ * @file EPMCPager.php
1010 * @ingroup EductaionProgram
1111 *
1212 * @licence GNU GPL v3 or later
1313 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1414 */
15 -class EPCoursePager extends EPPager {
 15+class EPMCPager extends EPPager {
1616
1717 /**
1818 * Constructor.
@@ -20,7 +20,7 @@
2121 * @param array $conds
2222 */
2323 public function __construct( IContextSource $context, array $conds = array() ) {
24 - parent::__construct( $context, $conds, 'EPCourse' );
 24+ parent::__construct( $context, $conds, 'EPMC' );
2525 }
2626
2727 /**
Index: trunk/extensions/EducationProgram/includes/EPCoursePager.php
@@ -0,0 +1,245 @@
 2+<?php
 3+
 4+/**
 5+ * Term pager, primarily for Special:Terms.
 6+ *
 7+ * @since 0.1
 8+ *
 9+ * @file EPCoursePager.php
 10+ * @ingroup EductaionProgram
 11+ *
 12+ * @licence GNU GPL v3 or later
 13+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 14+ */
 15+class EPCoursePager extends EPPager {
 16+
 17+ /**
 18+ * Constructor.
 19+ *
 20+ * @param IContextSource $context
 21+ * @param array $conds
 22+ */
 23+ public function __construct( IContextSource $context, array $conds = array() ) {
 24+ parent::__construct( $context, $conds, 'EPCourse' );
 25+ }
 26+
 27+ /**
 28+ * (non-PHPdoc)
 29+ * @see EPPager::getFields()
 30+ */
 31+ public function getFields() {
 32+ return array(
 33+ 'id',
 34+ 'mc_id',
 35+ 'year',
 36+ 'start',
 37+ 'end',
 38+ 'students',
 39+ );
 40+ }
 41+
 42+ /**
 43+ * (non-PHPdoc)
 44+ * @see TablePager::getRowClass()
 45+ */
 46+ function getRowClass( $row ) {
 47+ return 'ep-course-row';
 48+ }
 49+
 50+ /**
 51+ * (non-PHPdoc)
 52+ * @see TablePager::getTableClass()
 53+ */
 54+ public function getTableClass() {
 55+ return 'TablePager ep-courses';
 56+ }
 57+
 58+ /**
 59+ * (non-PHPdoc)
 60+ * @see EPPager::getFormattedValue()
 61+ */
 62+ public function getFormattedValue( $name, $value ) {
 63+ switch ( $name ) {
 64+ case 'id':
 65+ $value = Linker::linkKnown(
 66+ SpecialPage::getTitleFor( 'Course', $value ),
 67+ htmlspecialchars( $this->getLanguage()->formatNum( $value, true ) )
 68+ );
 69+ break;
 70+ case 'mc_id':
 71+ $value = EPMC::selectRow( 'name', array( 'id' => $value ) )->getField( 'name' );
 72+
 73+ $value = Linker::linkKnown(
 74+ SpecialPage::getTitleFor( 'MasterCourse', $value ),
 75+ htmlspecialchars( $value )
 76+ );
 77+ break;
 78+ case 'year':
 79+ $value = htmlspecialchars( $this->getLanguage()->formatNum( $value, true ) );
 80+ break;
 81+ case 'start': case 'end':
 82+ $value = htmlspecialchars( $this->getLanguage()->date( $value ) );
 83+ break;
 84+ case '_status':
 85+ $value = htmlspecialchars( EPTerm::getStatusMessage( $this->currentObject->getStatus() ) );
 86+ case 'students':
 87+ $value = htmlspecialchars( $this->getLanguage()->formatNum( $value ) );
 88+ break;
 89+ }
 90+
 91+ return $value;
 92+ }
 93+
 94+ /**
 95+ * (non-PHPdoc)
 96+ * @see EPPager::getSortableFields()
 97+ */
 98+ protected function getSortableFields() {
 99+ return array(
 100+ 'id',
 101+ 'year',
 102+ 'start',
 103+ 'end',
 104+ 'students',
 105+ );
 106+ }
 107+
 108+ /**
 109+ * (non-PHPdoc)
 110+ * @see EPPager::getFieldNames()
 111+ */
 112+ public function getFieldNames() {
 113+ $fields = parent::getFieldNames();
 114+
 115+ if ( array_key_exists( 'mc_id', $this->conds ) && array_key_exists( 'org_id', $fields ) ) {
 116+ unset( $fields['org_id'] );
 117+ }
 118+
 119+ $fields = wfArrayInsertAfter( $fields, array( '_status' => 'status' ), 'students' );
 120+
 121+ return $fields;
 122+ }
 123+
 124+ /**
 125+ * (non-PHPdoc)
 126+ * @see EPPager::getFilterOptions()
 127+ */
 128+ protected function getFilterOptions() {
 129+ $options = array();
 130+
 131+ if ( !array_key_exists( 'mc_id', $this->conds ) ) {
 132+ $options['mc_id'] = array(
 133+ 'type' => 'select',
 134+ 'options' => array_merge(
 135+ array( '' => '' ),
 136+ EPMC::getCourseOptions( EPMC::select( array( 'name', 'id' ) ) )
 137+ ),
 138+ 'value' => '',
 139+ 'datatype' => 'int',
 140+ );
 141+
 142+ $options['org_id'] = array(
 143+ 'type' => 'select',
 144+ 'options' => array_merge(
 145+ array( '' => '' ),
 146+ EPOrg::getOrgOptions( EPOrg::select( array( 'name', 'id' ) ) )
 147+ ),
 148+ 'value' => '',
 149+ 'datatype' => 'int',
 150+ );
 151+ }
 152+
 153+ $years = EPCourse::selectFields( 'year', array(), array( 'DISTINCT' ), array(), true );
 154+ asort( $years, SORT_NUMERIC );
 155+ $years = array_merge( array( '' ), $years );
 156+ $years = array_combine( $years, $years );
 157+
 158+ $options['year'] = array(
 159+ 'type' => 'select',
 160+ 'options' => $years,
 161+ 'value' => '',
 162+ );
 163+
 164+ $options['status'] = array(
 165+ 'type' => 'select',
 166+ 'options' => array_merge(
 167+ array( '' => '' ),
 168+ EPCourse::getStatuses()
 169+ ),
 170+ 'value' => 'current',
 171+ );
 172+
 173+ return $options;
 174+ }
 175+
 176+ /**
 177+ * (non-PHPdoc)
 178+ * @see EPPager::getControlLinks()
 179+ */
 180+ protected function getControlLinks( EPDBObject $item ) {
 181+ $links = parent::getControlLinks( $item );
 182+
 183+ $links[] = $value = Linker::linkKnown(
 184+ SpecialPage::getTitleFor( 'Course', $item->getId() ),
 185+ wfMsgHtml( 'view' )
 186+ );
 187+
 188+ if ( $this->getUser()->isAllowed( 'ep-term' ) ) {
 189+ $links[] = $value = Linker::linkKnown(
 190+ SpecialPage::getTitleFor( 'EditCourse', $item->getId() ),
 191+ wfMsgHtml( 'edit' )
 192+ );
 193+
 194+ $links[] = $this->getDeletionLink( 'course', $item->getId() );
 195+ }
 196+
 197+ return $links;
 198+ }
 199+
 200+ /**
 201+ * (non-PHPdoc)
 202+ * @see EPPager::getMultipleItemActions()
 203+ */
 204+ protected function getMultipleItemActions() {
 205+ $actions = parent::getMultipleItemActions();
 206+
 207+ if ( $this->getUser()->isAllowed( 'ep-course' ) ) {
 208+ $actions[wfMsg( 'ep-pager-delete-selected' )] = array(
 209+ 'class' => 'ep-pager-delete-selected',
 210+ 'data-type' => ApiDeleteEducation::getTypeForClassName( $this->className )
 211+ );
 212+ }
 213+
 214+ return $actions;
 215+ }
 216+
 217+ /**
 218+ * (non-PHPdoc)
 219+ * @see EPPager::getConditions()
 220+ */
 221+ protected function getConditions() {
 222+ $conds = parent::getConditions();
 223+
 224+ if ( array_key_exists( 'status', $conds ) ) {
 225+ $now = wfGetDB( DB_SLAVE )->addQuotes( wfTimestampNow() );
 226+
 227+ switch ( $conds['status'] ) {
 228+ case 'passed':
 229+ $conds[] = 'end < ' . $now;
 230+ break;
 231+ case 'planned':
 232+ $conds[] = 'start > ' . $now;
 233+ break;
 234+ case 'current':
 235+ $conds[] = 'end >= ' . $now;
 236+ $conds[] = 'start <= ' . $now;
 237+ break;
 238+ }
 239+
 240+ unset( $conds['status'] );
 241+ }
 242+
 243+ return $conds;
 244+ }
 245+
 246+}
Property changes on: trunk/extensions/EducationProgram/includes/EPCoursePager.php
___________________________________________________________________
Added: svn:eol-style
1247 + native
Index: trunk/extensions/EducationProgram/includes/EPMC.php
@@ -1,18 +1,18 @@
22 <?php
33
44 /**
5 - * Class representing a single course.
 5+ * Class representing a single master course.
66 * These describe a specific course, time-independent.
77 *
88 * @since 0.1
99 *
10 - * @file EPCourse.php
 10+ * @file EPMC.php
1111 * @ingroup EducationProgram
1212 *
1313 * @licence GNU GPL v3 or later
1414 * @author Jeroen De Dauw < jeroendedauw@gmail.com >
1515 */
16 -class EPCourse extends EPDBObject {
 16+class EPMC extends EPDBObject {
1717
1818 /**
1919 * Field for caching the linked org.
Index: trunk/extensions/EducationProgram/includes/EPCourse.php
@@ -0,0 +1,479 @@
 2+<?php
 3+
 4+/**
 5+ * Class representing a single course.
 6+ *
 7+ * @since 0.1
 8+ *
 9+ * @file EPCourse.php
 10+ * @ingroup EducationProgram
 11+ *
 12+ * @licence GNU GPL v3 or later
 13+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 14+ */
 15+class EPCourse extends EPDBObject {
 16+
 17+ /**
 18+ * Field for caching the linked course.
 19+ *
 20+ * @since 0.1
 21+ * @var EPCourse|false
 22+ */
 23+ protected $course = false;
 24+
 25+ /**
 26+ * Field for caching the linked org.
 27+ *
 28+ * @since 0.1
 29+ * @var EPOrg|false
 30+ */
 31+ protected $org = false;
 32+
 33+ /**
 34+ * Cached array of the linked EPStudent objects.
 35+ *
 36+ * @since 0.1
 37+ * @var array|false
 38+ */
 39+ protected $students = false;
 40+
 41+ /**
 42+ * Returns a list of statuses a term can have.
 43+ * Keys are messages, values are identifiers.
 44+ *
 45+ * @since 0.1
 46+ *
 47+ * @return array
 48+ */
 49+ public static function getStatuses() {
 50+ return array(
 51+ wfMsg( 'ep-course-status-passed' ) => 'passed',
 52+ wfMsg( 'ep-course-status-current' ) => 'current',
 53+ wfMsg( 'ep-course-status-planned' ) => 'planned',
 54+ );
 55+ }
 56+
 57+ /**
 58+ * Returns the message for the provided status identifier.
 59+ *
 60+ * @since 0.1
 61+ *
 62+ * @param string $status
 63+ *
 64+ * @return string
 65+ */
 66+ public static function getStatusMessage( $status ) {
 67+ static $map = null;
 68+
 69+ if ( is_null( $map ) ) {
 70+ $map = array_flip( self::getStatuses() );
 71+ }
 72+
 73+ return $map[$status];
 74+ }
 75+
 76+ /**
 77+ * @see parent::getFieldTypes
 78+ *
 79+ * @since 0.1
 80+ *
 81+ * @return array
 82+ */
 83+ protected static function getFieldTypes() {
 84+ return array(
 85+ 'id' => 'id',
 86+ 'course_id' => 'id',
 87+ 'org_id' => 'id',
 88+
 89+ 'year' => 'int',
 90+ 'start' => 'str', // TS_MW
 91+ 'end' => 'str', // TS_MW
 92+ 'description' => 'str',
 93+ 'token' => 'str',
 94+ 'online_ambs' => 'array',
 95+ 'campus_ambs' => 'array',
 96+
 97+ 'students' => 'int',
 98+ );
 99+ }
 100+
 101+ /**
 102+ * (non-PHPdoc)
 103+ * @see EPDBObject::getDefaults()
 104+ */
 105+ public static function getDefaults() {
 106+ return array(
 107+ 'year' => substr( wfTimestamp( TS_MW ), 0, 4 ),
 108+ 'start' => wfTimestamp( TS_MW ),
 109+ 'end' => wfTimestamp( TS_MW ),
 110+ 'description' => '',
 111+ 'token' => '',
 112+ 'online_ambs' => array(),
 113+ 'campus_ambs' => array(),
 114+
 115+ 'students' => 0,
 116+ );
 117+ }
 118+
 119+ /**
 120+ * Returns the students enrolled in this term.
 121+ *
 122+ * @since 0.1
 123+ *
 124+ * @param string|array|null $fields
 125+ * @param array $conditions
 126+ *
 127+ * @return array of EPStudent
 128+ */
 129+ protected function doGetStudents( $fields, array $conditions ) {
 130+ $conditions[] = array( array( 'ep_terms', 'id' ), $this->getId() );
 131+
 132+ return EPStudent::select(
 133+ $fields,
 134+ $conditions,
 135+ array(),
 136+ array(
 137+ 'ep_students_per_term' => array( 'INNER JOIN', array( array( array( 'ep_students_per_term', 'student_id' ), array( 'ep_students', 'id' ) ) ) ),
 138+ 'ep_terms' => array( 'INNER JOIN', array( array( array( 'ep_students_per_term', 'term_id' ), array( 'ep_terms', 'id' ) ) ) )
 139+ )
 140+ );
 141+ }
 142+
 143+ /**
 144+ * Returns the students enrolled in this term.
 145+ * Caches the result when no conditions are provided and all fields are selected.
 146+ *
 147+ * @since 0.1
 148+ *
 149+ * @param string|array|null $fields
 150+ * @param array $conditions
 151+ *
 152+ * @return array of EPStudent
 153+ */
 154+ public function getStudents( $fields = null, array $conditions = array() ) {
 155+ if ( count( $conditions ) !== 0 ) {
 156+ return $this->doGetStudents( $fields, $conditions );
 157+ }
 158+
 159+ if ( $this->students === false ) {
 160+ $students = $this->doGetStudents( $fields, $conditions );
 161+
 162+ if ( is_null( $fields ) ) {
 163+ $this->students = $students;
 164+ }
 165+
 166+ return $students;
 167+ }
 168+ else {
 169+ return $this->students;
 170+ }
 171+ }
 172+
 173+ /**
 174+ * (non-PHPdoc)
 175+ * @see EPDBObject::loadSummaryFields()
 176+ */
 177+ public function loadSummaryFields( $summaryFields = null ) {
 178+ if ( is_null( $summaryFields ) ) {
 179+ $summaryFields = array( 'org_id', 'students' );
 180+ }
 181+ else {
 182+ $summaryFields = (array)$summaryFields;
 183+ }
 184+
 185+ $fields = array();
 186+
 187+ if ( in_array( 'org_id', $summaryFields ) ) {
 188+ $fields['org_id'] = $this->getCourse( 'org_id' )->getField( 'org_id' );
 189+ }
 190+
 191+ if ( in_array( 'students', $summaryFields ) ) {
 192+ $fields['students'] = wfGetDB( DB_SLAVE )->select(
 193+ 'ep_students_per_term',
 194+ 'COUNT(*) AS rowcount',
 195+ array( 'spt_term_id' => $this->getId() )
 196+ );
 197+
 198+ $fields['students'] = $fields['students']->fetchObject()->rowcount;
 199+ }
 200+
 201+ $this->setFields( $fields );
 202+ }
 203+
 204+ /**
 205+ * (non-PHPdoc)
 206+ * @see EPDBObject::insertIntoDB()
 207+ */
 208+ protected function insertIntoDB() {
 209+ if ( !$this->hasField( 'org_id' ) ) {
 210+ $this->setField( 'org_id', $this->getCourse( 'org_id' )->getField( 'org_id' ) );
 211+ }
 212+
 213+ $success = parent::insertIntoDB();
 214+
 215+ if ( $success && $this->updateSummaries ) {
 216+ EPOrg::updateSummaryFields( array( 'terms', 'active' ), array( 'id' => $this->getField( 'org_id' ) ) );
 217+ EPCourse::updateSummaryFields( 'active', array( 'id' => $this->getField( 'course_id' ) ) );
 218+ }
 219+
 220+ return $success;
 221+ }
 222+
 223+ /**
 224+ * (non-PHPdoc)
 225+ * @see EPDBObject::removeFromDB()
 226+ */
 227+ public function removeFromDB() {
 228+ $id = $this->getId();
 229+
 230+ if ( $this->updateSummaries ) {
 231+ $this->loadFields( array( 'org_id', 'course_id' ) );
 232+ $orgId = $this->getField( 'org_id' );
 233+ $courseId = $this->getField( 'course_id' );
 234+ }
 235+
 236+ $success = parent::removeFromDB();
 237+
 238+ if ( $success && $this->updateSummaries ) {
 239+ EPCourse::updateSummaryFields( 'students', array( 'id' => $courseId ) );
 240+ EPOrg::updateSummaryFields( array( 'terms', 'students', 'active' ), array( 'id' => $orgId ) );
 241+ }
 242+
 243+ if ( $success ) {
 244+ $success = wfGetDB( DB_MASTER )->delete( 'ep_students_per_term', array( 'spt_term_id' => $id ) ) && $success;
 245+ }
 246+
 247+ return $success;
 248+ }
 249+
 250+ /**
 251+ * (non-PHPdoc)
 252+ * @see EPDBObject::updateInDB()
 253+ */
 254+ protected function updateInDB() {
 255+ if ( $this->updateSummaries ) {
 256+ $oldOrgId = $this->hasField( 'org_id' ) ? self::selectFieldsRow( 'org_id', array( 'id' => $this->getId() ) ) : false;
 257+ $oldCourseId = $this->hasField( 'course_id' ) ? self::selectFieldsRow( 'course_id', array( 'id' => $this->getId() ) ) : false;
 258+ }
 259+
 260+ if ( $this->hasField( 'course_id' ) ) {
 261+ $oldCourseId = self::selectFieldsRow( 'course_id', array( 'id' => $this->getId() ) );
 262+
 263+ if ( $this->getField( 'course_id' ) !== $oldCourseId ) {
 264+ $this->setField( 'org_id', EPCourse::selectFieldsRow( 'org_id', array( 'id' => $this->getField( 'course_id' ) ) ) );
 265+ }
 266+ }
 267+
 268+ $success = parent::updateInDB();
 269+
 270+ if ( $this->updateSummaries && $success ) {
 271+ if ( $oldOrgId !== false && $oldOrgId !== $this->getField( 'org_id' ) ) {
 272+ $conds = array( 'id' => array( $oldOrgId, $this->getField( 'org_id' ) ) );
 273+ EPOrg::updateSummaryFields( array( 'terms', 'students', 'active' ), $conds );
 274+ }
 275+
 276+ if ( $oldCourseId !== false && $oldCourseId !== $this->getField( 'org_id' ) ) {
 277+ $conds = array( 'id' => array( $oldCourseId, $this->getField( 'course_id' ) ) );
 278+ EPCourse::updateSummaryFields( array( 'active', 'students' ), $conds );
 279+ }
 280+ }
 281+
 282+ return $success;
 283+ }
 284+
 285+ /**
 286+ * Returns the course associated with this term.
 287+ *
 288+ * @since 0.1
 289+ *
 290+ * @param string|array|null $fields
 291+ *
 292+ * @return EPCourse
 293+ */
 294+ public function getCourse( $fields = null ) {
 295+ if ( $this->course === false ) {
 296+ $this->course = EPCourse::selectRow( $fields, array( 'id' => $this->loadAndGetField( 'course_id' ) ) );
 297+ }
 298+
 299+ return $this->course;
 300+ }
 301+
 302+ /**
 303+ * Returns the org associated with this term.
 304+ *
 305+ * @since 0.1
 306+ *
 307+ * @param string|array|null $fields
 308+ *
 309+ * @return EPOrg
 310+ */
 311+ public function getOrg( $fields = null ) {
 312+ if ( $this->org === false ) {
 313+ $this->org = EPOrg::selectRow( $fields, array( 'id' => $this->loadAndGetField( 'org_id' ) ) );
 314+ }
 315+
 316+ return $this->org;
 317+ }
 318+
 319+ /**
 320+ * Display a pager with terms.
 321+ *
 322+ * @since 0.1
 323+ *
 324+ * @param IContextSource $context
 325+ * @param array $conditions
 326+ */
 327+ public static function displayPager( IContextSource $context, array $conditions = array() ) {
 328+ $pager = new EPTermPager( $context, $conditions );
 329+
 330+ if ( $pager->getNumRows() ) {
 331+ $context->getOutput()->addHTML(
 332+ $pager->getFilterControl() .
 333+ $pager->getNavigationBar() .
 334+ $pager->getBody() .
 335+ $pager->getNavigationBar() .
 336+ $pager->getMultipleItemControl()
 337+ );
 338+ }
 339+ else {
 340+ $context->getOutput()->addHTML( $pager->getFilterControl( true ) );
 341+ $context->getOutput()->addWikiMsg( 'ep-terms-noresults' );
 342+ }
 343+ }
 344+
 345+ /**
 346+ * Adds a control to add a term org to the provided context.
 347+ * Additional arguments can be provided to set the default values for the control fields.
 348+ *
 349+ * @since 0.1
 350+ *
 351+ * @param IContextSource $context
 352+ * @param array $args
 353+ *
 354+ * @return boolean
 355+ */
 356+ public static function displayAddNewControl( IContextSource $context, array $args ) {
 357+ if ( !$context->getUser()->isAllowed( 'ep-term' ) ) {
 358+ return false;
 359+ }
 360+
 361+ $out = $context->getOutput();
 362+
 363+ $out->addHTML( Html::openElement(
 364+ 'form',
 365+ array(
 366+ 'method' => 'post',
 367+ 'action' => SpecialPage::getTitleFor( 'EditTerm' )->getLocalURL(),
 368+ )
 369+ ) );
 370+
 371+ $out->addHTML( '<fieldset>' );
 372+
 373+ $out->addHTML( '<legend>' . wfMsgHtml( 'ep-terms-addnew' ) . '</legend>' );
 374+
 375+ $out->addHTML( Html::element( 'p', array(), wfMsg( 'ep-terms-namedoc' ) ) );
 376+
 377+ $out->addHTML( Html::element( 'label', array( 'for' => 'newcourse' ), wfMsg( 'ep-terms-newcourse' ) ) );
 378+
 379+ $select = new XmlSelect(
 380+ 'newcourse',
 381+ 'newcourse',
 382+ array_key_exists( 'course', $args ) ? $args['course'] : false
 383+ );
 384+
 385+ $select->addOptions( EPCourse::getCourseOptions() );
 386+ $out->addHTML( $select->getHTML() );
 387+
 388+ $out->addHTML( '&#160;' . Xml::inputLabel( wfMsg( 'ep-terms-newyear' ), 'newyear', 'newyear', 10 ) );
 389+
 390+ $out->addHTML( '&#160;' . Html::input(
 391+ 'addnewterm',
 392+ wfMsg( 'ep-terms-add' ),
 393+ 'submit'
 394+ ) );
 395+
 396+ $out->addHTML( Html::hidden( 'isnew', 1 ) );
 397+
 398+ $out->addHTML( '</fieldset></form>' );
 399+
 400+ return true;
 401+ }
 402+
 403+ /**
 404+ * Adds a control to add a new term to the provided context
 405+ * or show a message if this is not possible for some reason.
 406+ *
 407+ * @since 0.1
 408+ *
 409+ * @param IContextSource $context
 410+ * @param array $args
 411+ */
 412+ public static function displayAddNewRegion( IContextSource $context, array $args = array() ) {
 413+ if ( EPCourse::has() ) {
 414+ EPTerm::displayAddNewControl( $context, $args );
 415+ }
 416+ elseif ( $context->getUser()->isAllowed( 'ep-course' ) ) {
 417+ $context->getOutput()->addWikiMsg( 'ep-terms-addcoursefirst' );
 418+ }
 419+ }
 420+
 421+ /**
 422+ * Gets the amount of days left, rounded up to the nearest integer.
 423+ *
 424+ * @since 0.1
 425+ *
 426+ * @return integer
 427+ */
 428+ public function getDaysLeft() {
 429+ $timeLeft = (int)wfTimestamp( TS_UNIX, $this->getField( 'end' ) ) - time();
 430+ return (int)ceil( $timeLeft / ( 60 * 60 * 24 ) );
 431+ }
 432+
 433+ /**
 434+ * Gets the amount of days since term start, rounded up to the nearest integer.
 435+ *
 436+ * @since 0.1
 437+ *
 438+ * @return integer
 439+ */
 440+ public function getDaysPassed() {
 441+ $daysPassed = time() - (int)wfTimestamp( TS_UNIX, $this->getField( 'start' ) );
 442+ return (int)ceil( $daysPassed / ( 60 * 60 * 24 ) );
 443+ }
 444+
 445+ /**
 446+ * Returns the status of the term.
 447+ *
 448+ * @since 0.1
 449+ *
 450+ * @return string
 451+ */
 452+ public function getStatus() {
 453+ if ( $this->getDaysLeft() <= 0 ) {
 454+ $status = 'passed';
 455+ }
 456+ elseif ( $this->getDaysPassed() <= 0 ) {
 457+ $status = 'planned';
 458+ }
 459+ else {
 460+ $status = 'current';
 461+ }
 462+
 463+ return $status;
 464+ }
 465+
 466+ /**
 467+ * Get a link to Special:Term/id.
 468+ *
 469+ * @since 0.1
 470+ *
 471+ * @return string
 472+ */
 473+ public function getLink() {
 474+ return Linker::linkKnown(
 475+ SpecialPage::getTitleFor( 'Term', $this->getId() ),
 476+ htmlspecialchars( $this->getId() )
 477+ );
 478+ }
 479+
 480+}
Property changes on: trunk/extensions/EducationProgram/includes/EPCourse.php
___________________________________________________________________
Added: svn:eol-style
1481 + native
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php
@@ -28,18 +28,18 @@
2929 'tooltip-ep-form-save' => 'Save',
3030 'tooltip-ep-edit-institution' => 'Edit this institution',
3131 'tooltip-ep-edit-course' => 'Edit this course',
32 - 'tooltip-ep-edit-term' => 'Edit this term',
 32+ 'tooltip-ep-edit-mc' => 'Edit this master course',
3333
3434 // Access keys
3535 'accesskey-ep-form-save' => 's', # do not translate or duplicate this message to other languages
3636 'accesskey-ep-edit-institution' => 'e', # do not translate or duplicate this message to other languages
3737 'accesskey-ep-edit-course' => 'e', # do not translate or duplicate this message to other languages
38 - 'accesskey-ep-edit-term' => 'e', # do not translate or duplicate this message to other languages
 38+ 'accesskey-ep-edit-mc' => 'e', # do not translate or duplicate this message to other languages
3939
4040 // Navigation links
4141 'ep-nav-orgs' => 'Institution list',
4242 'ep-nav-courses' => 'Courses list',
43 - 'ep-nav-terms' => 'Terms list',
 43+ 'ep-nav-mcs' => 'Master courses list',
4444 'ep-nav-mycourses' => 'My courses',
4545 'ep-nav-students' => 'Student list',
4646 'ep-nav-mentors' => 'Ambassador list',
@@ -47,14 +47,14 @@
4848 // Logging
4949 'log-name-institution' => 'Institution log',
5050 'log-name-course' => 'Course log',
51 - 'log-name-term' => 'Term log',
 51+ 'log-name-mc' => 'Master course log',
5252 'log-name-student' => 'Student log',
5353 'log-name-ambassador' => 'Ambassador log',
5454 'log-name-instructor' => 'Instructor log',
5555
56 - 'log-header-institution' => 'These events track when changes are made to institutions.',
57 - 'log-header-course' => 'These events track when changes are made to courses.',
58 - 'log-header-term' => 'These events track when changes are made to terms.',
 56+ 'log-header-institution' => 'These events track the changes that are made to institutions.',
 57+ 'log-header-course' => 'These events track the changes that are made to courses.',
 58+ 'log-header-mc' => 'These events track the changes that are made to master courses.',
5959
6060 'logentry-institution-add' => '$1 created institution $3',
6161 'logentry-institution-remove' => '$1 removed institution $3',
@@ -64,9 +64,9 @@
6565 'logentry-course-remove' => '$1 removed course $3',
6666 'logentry-course-update' => '$1 updated course $3',
6767
68 - 'logentry-term-add' => '$1 created term $3',
69 - 'logentry-term-remove' => '$1 removed term $3',
70 - 'logentry-term-update' => '$1 updated term $3',
 68+ 'logentry-mc-add' => '$1 created master course $3',
 69+ 'logentry-mc-remove' => '$1 removed master course $3',
 70+ 'logentry-mc-update' => '$1 updated master course $3',
7171
7272 'logentry-instructor-add' => '$1 {{GENDER:$2|added}} {{PLURAL:$4|instructor|instructors}} $5 to course $3',
7373 'logentry-instructor-remove' => '$1 {{GENDER:$2|removed}} {{PLURAL:$4|instructor|instructors}} $5 from course $3',
@@ -141,20 +141,22 @@
142142 'special-educationprogram' => 'Education Program',
143143 'special-editinstitution-add' => 'Add institution',
144144 'special-editinstitution-edit' => 'Edit institution',
145 - 'special-terms' => 'Terms',
146 - 'special-term' => 'Term',
147 - 'special-editterm-add' => 'Add term',
148 - 'special-editterm-edit' => 'Edit term',
 145+ 'special-mastercourses' => 'Master courses',
 146+ 'special-mastercourse' => 'Master course',
 147+ 'special-editmc-add' => 'Add master course',
 148+ 'special-editmc-edit' => 'Edit master course',
149149 'special-editcourse-add' => 'Add course',
150150 'special-editcourse-edit' => 'Edit course',
151151 'special-enroll' => 'Enroll',
152 - 'special-ambassadors' => 'Ambassadors',
153 - 'special-ambassador' => 'Ambassador',
 152+ 'special-onlineambassadors' => 'Online ambassadors',
 153+ 'special-campusambassadors' => 'Campus ambassadors',
 154+ 'special-onlineambassador' => 'Online ambassador',
 155+ 'special-campusambassador' => 'Campus ambassador',
154156
155 - // Term statuses
156 - 'ep-term-status-passed' => 'Passed',
157 - 'ep-term-status-current' => 'Current',
158 - 'ep-term-status-planned' => 'Planned',
 157+ // Course statuses
 158+ 'ep-course-status-passed' => 'Passed',
 159+ 'ep-course-status-current' => 'Current',
 160+ 'ep-course-status-planned' => 'Planned',
159161
160162 // Special:Institutions
161163 'ep-institutions-nosuchinstitution' => 'There is no institution with name "$1". Existing institutions are listed below.',
Index: trunk/extensions/EducationProgram/EducationProgram.php
@@ -165,7 +165,7 @@
166166 // Logging
167167 $wgLogTypes[] = 'institution';
168168 $wgLogTypes[] = 'course';
169 -$wgLogTypes[] = 'term';
 169+$wgLogTypes[] = 'mc';
170170 $wgLogTypes[] = 'student';
171171 $wgLogTypes[] = 'ambassador';
172172 $wgLogTypes[] = 'instructor';
@@ -173,14 +173,14 @@
174174 if ( array_key_exists( 'LogFormatter', $wgAutoloadLocalClasses ) ) {
175175 $wgLogActionsHandlers['institution/*'] = 'EPLogFormatter';
176176 $wgLogActionsHandlers['course/*'] = 'EPLogFormatter';
177 - $wgLogActionsHandlers['term/*'] = 'EPLogFormatter';
 177+ $wgLogActionsHandlers['mc/*'] = 'EPLogFormatter';
178178 $wgLogActionsHandlers['student/*'] = 'EPLogFormatter';
179179 $wgLogActionsHandlers['ambassador/*'] = 'EPLogFormatter';
180180 $wgLogActionsHandlers['instructor/*'] = 'EPLogFormatter';
181181 }
182182 else {
183183 // Compatibility with MediaWiki 1.18.
184 - foreach ( array( 'institution', 'course', 'term' ) as $type ) {
 184+ foreach ( array( 'institution', 'course', 'mc' ) as $type ) {
185185 foreach ( array( 'add', 'remove', 'update' ) as $action ) {
186186 $wgLogActionsHandlers[$type . '/' . $action] = 'EPHooks::formatLogEntry';
187187 }
@@ -198,7 +198,7 @@
199199 // Compatibility with MediaWiki 1.18.
200200 $wgLogNames['institution'] = 'log-name-institution';
201201 $wgLogNames['course'] = 'log-name-course';
202 - $wgLogNames['term'] = 'log-name-term';
 202+ $wgLogNames['term'] = 'log-name-mc';
203203 $wgLogNames['student'] = 'log-name-student';
204204 $wgLogNames['ambassador'] = 'log-name-ambassador';
205205 $wgLogNames['instructor'] = 'log-name-instructor';
@@ -206,7 +206,7 @@
207207 // Compatibility with MediaWiki 1.18.
208208 $wgLogHeaders['institution'] = 'log-header-institution';
209209 $wgLogHeaders['course'] = 'log-header-course';
210 - $wgLogHeaders['term'] = 'log-header-term';
 210+ $wgLogHeaders['term'] = 'log-header-mc';
211211 $wgLogHeaders['student'] = 'log-header-student';
212212 $wgLogHeaders['ambassador'] = 'log-header-ambassador';
213213 $wgLogHeaders['instructor'] = 'log-header-instructor';
@@ -215,7 +215,7 @@
216216 // Rights
217217 $wgAvailableRights[] = 'ep-org'; // Manage orgs
218218 $wgAvailableRights[] = 'ep-course'; // Manage courses
219 -$wgAvailableRights[] = 'ep-term'; // Manage terms
 219+$wgAvailableRights[] = 'ep-mc'; // Manage master courses
220220 $wgAvailableRights[] = 'ep-token'; // See enrollment tokens
221221 $wgAvailableRights[] = 'ep-enroll'; // Enroll as a student
222222 $wgAvailableRights[] = 'ep-remstudent'; // Dissasociate students from terms
@@ -230,7 +230,7 @@
231231 $wgGroupPermissions['*']['ep-enroll'] = true;
232232 $wgGroupPermissions['*']['ep-org'] = false;
233233 $wgGroupPermissions['*']['ep-course'] = false;
234 -$wgGroupPermissions['*']['ep-term'] = false;
 234+$wgGroupPermissions['*']['ep-mc'] = false;
235235 $wgGroupPermissions['*']['ep-token'] = false;
236236 $wgGroupPermissions['*']['ep-remstudent'] = false;
237237 $wgGroupPermissions['*']['ep-online'] = false;
@@ -242,7 +242,7 @@
243243
244244 $wgGroupPermissions['epstaff']['ep-org'] = true;
245245 $wgGroupPermissions['epstaff']['ep-course'] = true;
246 -$wgGroupPermissions['epstaff']['ep-term'] = true;
 246+$wgGroupPermissions['epstaff']['ep-mc'] = true;
247247 $wgGroupPermissions['epstaff']['ep-token'] = true;
248248 $wgGroupPermissions['epstaff']['ep-enroll'] = true;
249249 $wgGroupPermissions['epstaff']['ep-remstudent'] = true;
@@ -255,7 +255,7 @@
256256
257257 $wgGroupPermissions['epadmin']['ep-org'] = true;
258258 $wgGroupPermissions['epadmin']['ep-course'] = true;
259 -$wgGroupPermissions['epadmin']['ep-term'] = true;
 259+$wgGroupPermissions['epadmin']['ep-mc'] = true;
260260 $wgGroupPermissions['epadmin']['ep-token'] = true;
261261 $wgGroupPermissions['epadmin']['ep-enroll'] = true;
262262 $wgGroupPermissions['epadmin']['ep-remstudent'] = true;
@@ -268,19 +268,19 @@
269269
270270 $wgGroupPermissions['eponlineamb']['ep-org'] = true;
271271 $wgGroupPermissions['eponlineamb']['ep-course'] = true;
272 -$wgGroupPermissions['eponlineamb']['ep-term'] = true;
 272+$wgGroupPermissions['eponlineamb']['ep-mc'] = true;
273273 $wgGroupPermissions['eponlineamb']['ep-token'] = true;
274274 $wgGroupPermissions['eponlineamb']['ep-beonline'] = true;
275275
276276 $wgGroupPermissions['epcampamb']['ep-org'] = true;
277277 $wgGroupPermissions['epcampamb']['ep-course'] = true;
278 -$wgGroupPermissions['epcampamb']['ep-term'] = true;
 278+$wgGroupPermissions['epcampamb']['ep-mc'] = true;
279279 $wgGroupPermissions['epcampamb']['ep-token'] = true;
280280 $wgGroupPermissions['epcampamb']['ep-becampus'] = true;
281281
282282 $wgGroupPermissions['epinstructor']['ep-org'] = true;
283283 $wgGroupPermissions['epinstructor']['ep-course'] = true;
284 -$wgGroupPermissions['epinstructor']['ep-term'] = true;
 284+$wgGroupPermissions['epinstructor']['ep-mc'] = true;
285285 $wgGroupPermissions['epinstructor']['ep-token'] = true;
286286 $wgGroupPermissions['epinstructor']['ep-remstudent'] = true;
287287 $wgGroupPermissions['epinstructor']['ep-online'] = true;
Index: trunk/extensions/EducationProgram/EducationProgram.hooks.php
@@ -166,6 +166,8 @@
167167 }
168168
169169 $links['views'] = $viewLinks;
 170+
 171+ return true;
170172 }
171173
172174 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r109656schema changes currently completely breaking the extension and added hook to ...jeroendedauw22:24, 20 January 2012

Status & tagging log