r109663 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109662‎ | r109663 | r109664 >
Date:23:56, 20 January 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
follow up to r109656 - renaming stuff and adding new files for campus and online ambassadors
Modified paths:
  • /trunk/extensions/EducationProgram/includes/EPCA.php (added) (history)
  • /trunk/extensions/EducationProgram/includes/EPCAPager.php (added) (history)
  • /trunk/extensions/EducationProgram/includes/EPCourse.php (deleted) (history)
  • /trunk/extensions/EducationProgram/includes/EPCoursePager.php (deleted) (history)
  • /trunk/extensions/EducationProgram/includes/EPMC.php (added) (history)
  • /trunk/extensions/EducationProgram/includes/EPMCPager.php (added) (history)
  • /trunk/extensions/EducationProgram/includes/EPMentor.php (deleted) (history)
  • /trunk/extensions/EducationProgram/includes/EPMentorPager.php (deleted) (history)
  • /trunk/extensions/EducationProgram/includes/EPOA.php (added) (history)
  • /trunk/extensions/EducationProgram/includes/EPOAPager.php (added) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/includes/EPMentor.php
@@ -1,56 +0,0 @@
2 -<?php
3 -
4 -/**
5 - * Class representing a single mentor.
6 - *
7 - * @since 0.1
8 - *
9 - * @file EPMentor.php
10 - * @ingroup EducationProgram
11 - *
12 - * @licence GNU GPL v3 or later
13 - * @author Jeroen De Dauw < jeroendedauw@gmail.com >
14 - */
15 -class EPMentor extends EPDBObject {
16 -
17 - /**
18 - * @see parent::getFieldTypes
19 - *
20 - * @since 0.1
21 - *
22 - * @return array
23 - */
24 - protected static function getFieldTypes() {
25 - return array(
26 - 'id' => 'id',
27 - 'user_id' => 'id',
28 - );
29 - }
30 -
31 - /**
32 - * Display a pager with mentors.
33 - *
34 - * @since 0.1
35 - *
36 - * @param IContextSource $context
37 - * @param array $conditions
38 - */
39 - public static function displayPager( IContextSource $context, array $conditions = array() ) {
40 - $pager = new EPMentorPager( $context, $conditions );
41 -
42 - if ( $pager->getNumRows() ) {
43 - $context->getOutput()->addHTML(
44 - $pager->getFilterControl() .
45 - $pager->getNavigationBar() .
46 - $pager->getBody() .
47 - $pager->getNavigationBar() .
48 - $pager->getMultipleItemControl()
49 - );
50 - }
51 - else {
52 - $context->getOutput()->addHTML( $pager->getFilterControl( true ) );
53 - $context->getOutput()->addWikiMsg( 'ep-mentors-noresults' );
54 - }
55 - }
56 -
57 -}
Index: trunk/extensions/EducationProgram/includes/EPCoursePager.php
@@ -1,171 +0,0 @@
2 -<?php
3 -
4 -/**
5 - * Course pager, primarily for Special:Courses.
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 - 'name',
34 - 'org_id',
35 - 'students',
36 - 'active',
37 - );
38 - }
39 -
40 - /**
41 - * (non-PHPdoc)
42 - * @see TablePager::getRowClass()
43 - */
44 - function getRowClass( $row ) {
45 - return 'ep-course-row';
46 - }
47 -
48 - /**
49 - * (non-PHPdoc)
50 - * @see TablePager::getTableClass()
51 - */
52 - public function getTableClass() {
53 - return 'TablePager ep-courses';
54 - }
55 -
56 - /**
57 - * (non-PHPdoc)
58 - * @see EPPager::getFormattedValue()
59 - */
60 - protected function getFormattedValue( $name, $value ) {
61 - switch ( $name ) {
62 - case 'name':
63 - $value = Linker::linkKnown(
64 - SpecialPage::getTitleFor( 'Course', $value ),
65 - htmlspecialchars( $value )
66 - );
67 - break;
68 - case 'org_id':
69 - $value = EPOrg::selectRow( 'name', array( 'id' => $value ) )->getField( 'name' );
70 -
71 - $value = Linker::linkKnown(
72 - SpecialPage::getTitleFor( 'Institution', $value ),
73 - htmlspecialchars( $value )
74 - );
75 - break;
76 - case 'students':
77 - $value = htmlspecialchars( $this->getLanguage()->formatNum( $value ) );
78 - break;
79 - case 'active':
80 - $value = wfMsgHtml( 'epcoursepager-' . ( $value == '1' ? 'yes' : 'no' ) );
81 - break;
82 - }
83 -
84 - return $value;
85 - }
86 -
87 - function getDefaultSort() {
88 - $c = $this->className; // Yeah, this is needed in PHP 5.3 >_>
89 - return $c::getPrefixedField( 'name' );
90 - }
91 -
92 - /**
93 - * (non-PHPdoc)
94 - * @see EPPager::getSortableFields()
95 - */
96 - protected function getSortableFields() {
97 - return array(
98 - 'name',
99 - 'students',
100 - 'active',
101 - );
102 - }
103 -
104 - /**
105 - * (non-PHPdoc)
106 - * @see EPPager::getFilterOptions()
107 - */
108 - protected function getFilterOptions() {
109 - return array(
110 - 'org_id' => array(
111 - 'type' => 'select',
112 - 'options' => array_merge(
113 - array( '' => '' ),
114 - EPOrg::getOrgOptions( EPOrg::select( array( 'name', 'id' ) ) )
115 - ),
116 - 'value' => '',
117 - 'datatype' => 'int',
118 - ),
119 - 'active' => array(
120 - 'type' => 'select',
121 - 'options' => array(
122 - '' => '',
123 - wfMsg( 'epcoursepager-yes' ) => '1',
124 - wfMsg( 'epcoursepager-no' ) => '0',
125 - ),
126 - 'value' => '',
127 - ),
128 - );
129 - }
130 -
131 - /**
132 - * (non-PHPdoc)
133 - * @see EPPager::getControlLinks()
134 - */
135 - protected function getControlLinks( EPDBObject $item ) {
136 - $links = parent::getControlLinks( $item );
137 -
138 - $links[] = $value = Linker::linkKnown(
139 - SpecialPage::getTitleFor( 'Course', $item->getField( 'name' ) ),
140 - wfMsgHtml( 'view' )
141 - );
142 -
143 - if ( $this->getUser()->isAllowed( 'ep-course' ) ) {
144 - $links[] = $value = Linker::linkKnown(
145 - SpecialPage::getTitleFor( 'EditCourse', $item->getField( 'name' ) ),
146 - wfMsgHtml( 'edit' )
147 - );
148 -
149 - $links[] = $this->getDeletionLink( 'course', $item->getId() );
150 - }
151 -
152 - return $links;
153 - }
154 -
155 - /**
156 - * (non-PHPdoc)
157 - * @see EPPager::getMultipleItemActions()
158 - */
159 - protected function getMultipleItemActions() {
160 - $actions = parent::getMultipleItemActions();
161 -
162 - if ( $this->getUser()->isAllowed( 'ep-course' ) ) {
163 - $actions[wfMsg( 'ep-pager-delete-selected' )] = array(
164 - 'class' => 'ep-pager-delete-selected',
165 - 'data-type' => ApiDeleteEducation::getTypeForClassName( $this->className )
166 - );
167 - }
168 -
169 - return $actions;
170 - }
171 -
172 -}
Index: trunk/extensions/EducationProgram/includes/EPCourse.php
@@ -1,520 +0,0 @@
2 -<?php
3 -
4 -/**
5 - * Class representing a single course.
6 - * These describe a specific course, time-independent.
7 - *
8 - * @since 0.1
9 - *
10 - * @file EPCourse.php
11 - * @ingroup EducationProgram
12 - *
13 - * @licence GNU GPL v3 or later
14 - * @author Jeroen De Dauw < jeroendedauw@gmail.com >
15 - */
16 -class EPCourse extends EPDBObject {
17 -
18 - /**
19 - * Field for caching the linked org.
20 - *
21 - * @since 0.1
22 - * @var EPOrg|false
23 - */
24 - protected $org = false;
25 -
26 - /**
27 - * Field for caching the instructors.
28 - *
29 - * @since 0.1
30 - * @var {array of EPInstructor}|false
31 - */
32 - protected $instructors = false;
33 -
34 - /**
35 - * @see parent::getFieldTypes
36 - *
37 - * @since 0.1
38 - *
39 - * @return array
40 - */
41 - protected static function getFieldTypes() {
42 - return array(
43 - 'id' => 'id',
44 - 'org_id' => 'id',
45 -
46 - 'name' => 'str',
47 - 'description' => 'str',
48 - 'lang' => 'str',
49 - 'instructors' => 'array',
50 -
51 - 'active' => 'bool',
52 - 'students' => 'int',
53 - );
54 - }
55 -
56 - /**
57 - * (non-PHPdoc)
58 - * @see EPDBObject::getDefaults()
59 - */
60 - public static function getDefaults() {
61 - return array(
62 - 'description' => '',
63 -
64 - 'active' => false,
65 - 'students' => 0,
66 - 'instructors' => array(),
67 - );
68 - }
69 -
70 - /**
71 - * (non-PHPdoc)
72 - * @see EPDBObject::loadSummaryFields()
73 - */
74 - public function loadSummaryFields( $summaryFields = null ) {
75 - if ( is_null( $summaryFields ) ) {
76 - $summaryFields = array( 'students', 'active' );
77 - }
78 - else {
79 - $summaryFields = (array)$summaryFields;
80 - }
81 -
82 - $fields = array();
83 -
84 - if ( in_array( 'students', $summaryFields ) ) {
85 - $termIds = EPTerm::selectFields( 'id', array( 'course_id' => $this->getId() ) );
86 -
87 - if ( count( $termIds ) > 0 ) {
88 - $fields['students'] = wfGetDB( DB_SLAVE )->select(
89 - 'ep_students_per_term',
90 - 'COUNT(*) AS rowcount',
91 - array( 'spt_term_id' => $termIds )
92 - );
93 -
94 - $fields['students'] = $fields['students']->fetchObject()->rowcount;
95 - }
96 - else {
97 - $fields['students'] = 0;
98 - }
99 - }
100 -
101 - if ( in_array( 'active', $summaryFields ) ) {
102 - $now = wfGetDB( DB_SLAVE )->addQuotes( wfTimestampNow() );
103 -
104 - $fields['active'] = EPTerm::has( array(
105 - 'course_id' => $this->getId(),
106 - 'end >= ' . $now,
107 - 'start <= ' . $now,
108 - ) );
109 - }
110 -
111 - $this->setFields( $fields );
112 - }
113 -
114 - /**
115 - * (non-PHPdoc)
116 - * @see EPDBObject::removeFromDB()
117 - */
118 - public function removeFromDB() {
119 - $id = $this->getId();
120 -
121 - if ( $this->updateSummaries ) {
122 - $this->loadFields( array( 'org_id' ) );
123 - $orgId = $this->getField( 'org_id', false );
124 - }
125 -
126 - $success = parent::removeFromDB();
127 -
128 - if ( $success ) {
129 - foreach ( EPTerm::select( 'id', array( 'course_id' => $id ) ) as /* EPTerm */ $term ) {
130 - $term->setUpdateSummaries( false );
131 - $success = $term->removeFromDB() && $success;
132 - }
133 - }
134 -
135 - if ( $this->updateSummaries && $orgId !== false ) {
136 - EPOrg::updateSummaryFields( array( 'terms', 'students', 'courses', 'active' ), array( 'id' => $orgId ) );
137 - }
138 -
139 - return $success;
140 - }
141 -
142 - /**
143 - * (non-PHPdoc)
144 - * @see EPDBObject::insertIntoDB()
145 - */
146 - protected function insertIntoDB() {
147 - $success = parent::insertIntoDB();
148 -
149 - if ( $this->updateSummaries ) {
150 - EPOrg::updateSummaryFields( array( 'courses', 'active' ), array( 'id' => $this->getField( 'org_id' ) ) );
151 - }
152 -
153 - return $success;
154 - }
155 -
156 - /**
157 - * (non-PHPdoc)
158 - * @see EPDBObject::updateInDB()
159 - */
160 - protected function updateInDB() {
161 - $oldOrgId = $this->hasField( 'org_id' ) ? self::selectFieldsRow( 'org_id', array( 'id' => $this->getId() ) ) : false;
162 -
163 - $success = parent::updateInDB();
164 -
165 - if ( $this->updateSummaries && $success && $oldOrgId !== false && $oldOrgId !== $this->getField( 'org_id' ) ) {
166 - $conds = array( 'id' => array( $oldOrgId, $this->getField( 'org_id' ) ) );
167 - EPTerm::updateSummaryFields( 'org_id', array( 'course_id' => $this->getId() ) );
168 - EPOrg::updateSummaryFields( array( 'terms', 'students', 'courses', 'active' ), $conds );
169 - }
170 -
171 - return $success;
172 - }
173 -
174 - /**
175 - * Returns the org associated with this course.
176 - *
177 - * @since 0.1
178 - *
179 - * @param string|array|null $fields
180 - *
181 - * @return EPOrg
182 - */
183 - public function getOrg( $fields = null ) {
184 - if ( $this->org === false ) {
185 - $this->org = EPOrg::selectRow( $fields, array( 'id' => $this->getField( 'org_id' ) ) );
186 - }
187 -
188 - return $this->org;
189 - }
190 -
191 - /**
192 - * Returns a list of courses in an array that can be fed to select inputs.
193 - *
194 - * @since 0.1
195 - *
196 - * @param array|null $courses
197 - *
198 - * @return array
199 - */
200 - public static function getCourseOptions( array /* EPCourse */ $courses = null ) {
201 - $options = array();
202 -
203 - if ( is_null( $courses ) ) {
204 - $courses = EPCourse::select( array( 'name', 'id' ) );
205 - }
206 -
207 - foreach ( $courses as /* EPCourse */ $course ) {
208 - $options[$course->getField( 'name' )] = $course->getId();
209 - }
210 -
211 - return $options;
212 - }
213 -
214 - /**
215 - * Adds a control to add a new course to the provided context.
216 - * Additional arguments can be provided to set the default values for the control fields.
217 - *
218 - * @since 0.1
219 - *
220 - * @param IContextSource $context
221 - * @param array $args
222 - *
223 - * @return boolean
224 - */
225 - public static function displayAddNewControl( IContextSource $context, array $args = array() ) {
226 - if ( !$context->getUser()->isAllowed( 'ep-course' ) ) {
227 - return false;
228 - }
229 -
230 - $out = $context->getOutput();
231 -
232 - $out->addHTML( Html::openElement(
233 - 'form',
234 - array(
235 - 'method' => 'post',
236 - 'action' => SpecialPage::getTitleFor( 'EditCourse' )->getLocalURL(),
237 - )
238 - ) );
239 -
240 - $out->addHTML( '<fieldset>' );
241 -
242 - $out->addHTML( '<legend>' . wfMsgHtml( 'ep-courses-addnew' ) . '</legend>' );
243 -
244 - $out->addHTML( Html::element( 'p', array(), wfMsg( 'ep-courses-namedoc' ) ) );
245 -
246 - $out->addHTML( Html::element( 'label', array( 'for' => 'neworg' ), wfMsg( 'ep-courses-neworg' ) ) );
247 -
248 - $out->addHTML( '&#160;' );
249 -
250 - $select = new XmlSelect(
251 - 'neworg',
252 - 'neworg',
253 - array_key_exists( 'org', $args ) ? $args['org'] : false
254 - );
255 -
256 - $select->addOptions( EPOrg::getOrgOptions() );
257 - $out->addHTML( $select->getHTML() );
258 -
259 - $out->addHTML( '&#160;' );
260 -
261 - $out->addHTML( Xml::inputLabel(
262 - wfMsg( 'ep-courses-newname' ),
263 - 'newname',
264 - 'newname',
265 - false,
266 - array_key_exists( 'name', $args ) ? $args['name'] : false
267 - ) );
268 -
269 - $out->addHTML( '&#160;' );
270 -
271 - $out->addHTML( Html::input(
272 - 'addneworg',
273 - wfMsg( 'ep-courses-add' ),
274 - 'submit'
275 - ) );
276 -
277 - $out->addHTML( Html::hidden( 'isnew', 1 ) );
278 -
279 - $out->addHTML( '</fieldset></form>' );
280 -
281 - return true;
282 - }
283 -
284 - /**
285 - * Adds a control to add a new course to the provided context
286 - * or show a message if this is not possible for some reason.
287 - *
288 - * @since 0.1
289 - *
290 - * @param IContextSource $context
291 - * @param array $args
292 - */
293 - public static function displayAddNewRegion( IContextSource $context, array $args = array() ) {
294 - if ( EPOrg::has() ) {
295 - EPCourse::displayAddNewControl( $context, $args );
296 - }
297 - elseif ( $context->getUser()->isAllowed( 'ep-org' ) ) {
298 - $context->getOutput()->addWikiMsg( 'ep-courses-addorgfirst' );
299 - }
300 - }
301 -
302 - /**
303 - * Display a pager with courses.
304 - *
305 - * @since 0.1
306 - *
307 - * @param IContextSource $context
308 - * @param array $conditions
309 - */
310 - public static function displayPager( IContextSource $context, array $conditions = array() ) {
311 - $pager = new EPCoursePager( $context, $conditions );
312 -
313 - if ( $pager->getNumRows() ) {
314 - $context->getOutput()->addHTML(
315 - $pager->getFilterControl() .
316 - $pager->getNavigationBar() .
317 - $pager->getBody() .
318 - $pager->getNavigationBar() .
319 - $pager->getMultipleItemControl()
320 - );
321 - }
322 - else {
323 - $context->getOutput()->addHTML( $pager->getFilterControl( true ) );
324 - $context->getOutput()->addWikiMsg( 'ep-courses-noresults' );
325 - }
326 - }
327 -
328 - /**
329 - * Get a link to Special:Course/name.
330 - *
331 - * @since 0.1
332 - *
333 - * @return string
334 - */
335 - public function getLink() {
336 - return Linker::linkKnown(
337 - $this->getTitle(),
338 - htmlspecialchars( $this->getField( 'name' ) )
339 - );
340 - }
341 -
342 - /**
343 - * Get the title of Special:Course/name.
344 - *
345 - * @since 0.1
346 - *
347 - * @return Title
348 - */
349 - public function getTitle() {
350 - return SpecialPage::getTitleFor( 'Course', $this->getField( 'name' ) );
351 - }
352 -
353 - /**
354 - * Returns the instructors as a list of EPInstructor objects.
355 - *
356 - * @since 0.1
357 - *
358 - * @return array of EPInstructor
359 - */
360 - public function getInstructors() {
361 - if ( $this->instructors === false ) {
362 - $this->instructors = array();
363 -
364 - foreach ( $this->getField( 'instructors' ) as $userId ) {
365 - $this->instructors[] = EPInstructor::newFromId( $userId );
366 - }
367 - }
368 -
369 - return $this->instructors;
370 - }
371 -
372 - /**
373 - * (non-PHPdoc)
374 - * @see EPDBObject::setField()
375 - */
376 - public function setField( $name, $value ) {
377 - if ( $name === 'instructors' ) {
378 - $this->instructors = false;
379 - }
380 - elseif ( $name === 'org_id' ) {
381 - $this->org = false;
382 - }
383 -
384 - parent::setField( $name, $value );
385 - }
386 -
387 - /**
388 - * Adds a number of instructors to this course,
389 - * by default also saving the course and only
390 - * logging the adittion of the instructors.
391 - *
392 - * @since 0.1
393 - *
394 - * @param array|integer $newInstructors
395 - * @param string $message
396 - * @param boolean $save
397 - * @param boolean $log
398 - *
399 - * @return boolean Success indicator
400 - */
401 - public function addInstructors( $newInstructors, $message = '', $save = true, $log = true ) {
402 - $instructors = $this->getField( 'instructors' );
403 - $addedInstructors = array();
404 -
405 - foreach ( (array)$newInstructors as $userId ) {
406 - if ( !is_integer( $userId ) ) {
407 - throw new MWException( 'Provided user id is not an integer' );
408 - }
409 -
410 - if ( !in_array( $userId, $instructors ) ) {
411 - $instructors[] = $userId;
412 - $addedInstructors[] = $userId;
413 - }
414 - }
415 -
416 - if ( count( $addedInstructors ) > 0 ) {
417 - $this->setField( 'instructors', $instructors );
418 -
419 - $success = true;
420 -
421 - if ( $save ) {
422 - $this->disableLogging();
423 - $success = $this->writeToDB();
424 - $this->enableLogging();
425 - }
426 -
427 - if ( $success && $log ) {
428 - $this->logInstructorChange( 'add', $addedInstructors, $message );
429 - }
430 -
431 - return $success;
432 - }
433 - else {
434 - return true;
435 - }
436 - }
437 -
438 - /**
439 - * Remove a number of instructors to this course,
440 - * by default also saving the course and only
441 - * logging the removal of the instructors.
442 - *
443 - * @since 0.1
444 - *
445 - * @param array|integer $sadInstructors
446 - * @param string $message
447 - * @param boolean $save
448 - * @param boolean $log
449 - *
450 - * @return boolean Success indicator
451 - */
452 - public function removeInstructors( $sadInstructors, $message = '', $save = true, $log = true ) {
453 - $removedInstructors = array();
454 - $remaimingInstructors = array();
455 - $sadInstructors = (array)$sadInstructors;
456 -
457 - foreach ( $this->getField( 'instructors' ) as $userId ) {
458 - if ( in_array( $userId, $sadInstructors ) ) {
459 - $removedInstructors[] = $userId;
460 - }
461 - else {
462 - $remaimingInstructors[] = $userId;
463 - }
464 - }
465 -
466 - if ( count( $removedInstructors ) > 0 ) {
467 - $this->setField( 'instructors', $remaimingInstructors );
468 -
469 - $success = true;
470 -
471 - if ( $save ) {
472 - $this->disableLogging();
473 - $success = $this->writeToDB();
474 - $this->enableLogging();
475 - }
476 -
477 - if ( $success && $log ) {
478 - $this->logInstructorChange( 'remove', $removedInstructors, $message );
479 - }
480 -
481 - return $success;
482 - }
483 - else {
484 - return true;
485 - }
486 - }
487 -
488 - /**
489 - * Log a change of the instructors of the course.
490 - *
491 - * @since 0.1
492 - *
493 - * @param string $action
494 - * @param array $instructors
495 - * @param string $message
496 - */
497 - protected function logInstructorChange( $action, array $instructors, $message ) {
498 - $names = array();
499 -
500 - foreach ( $instructors as $userId ) {
501 - $names[] = EPInstructor::newFromId( $userId )->getName();
502 - }
503 -
504 - $info = array(
505 - 'type' => 'instructor',
506 - 'subtype' => $action,
507 - 'title' => $this->getTitle(),
508 - 'parameters' => array(
509 - '4::instructorcount' => count( $names ),
510 - '5::instructors' => $GLOBALS['wgLang']->listToText( $names )
511 - ),
512 - );
513 -
514 - if ( $message !== '' ) {
515 - $info['comment'] = $message;
516 - }
517 -
518 - EPUtils::log( $info );
519 - }
520 -
521 -}
Index: trunk/extensions/EducationProgram/includes/EPMentorPager.php
@@ -1,103 +0,0 @@
2 -<?php
3 -
4 -/**
5 - * Mentor pager, primarily for Special:Mentors.
6 - *
7 - * @since 0.1
8 - *
9 - * @file EPMentorPager.php
10 - * @ingroup EductaionProgram
11 - *
12 - * @licence GNU GPL v3 or later
13 - * @author Jeroen De Dauw < jeroendedauw@gmail.com >
14 - */
15 -class EPMentorPager extends EPPager {
16 - /**
17 - * Constructor.
18 - *
19 - * @param IContextSource $context
20 - * @param array $conds
21 - */
22 - public function __construct( IContextSource $context, array $conds = array() ) {
23 - $this->mDefaultDirection = true;
24 -
25 - // when MW 1.19 becomes min, we want to pass an IContextSource $context here.
26 - parent::__construct( $context, $conds, 'EPMentor' );
27 - }
28 -
29 - /**
30 - * (non-PHPdoc)
31 - * @see EPPager::getFields()
32 - */
33 - public function getFields() {
34 - return array(
35 - 'id',
36 - 'user_id',
37 - );
38 - }
39 -
40 - /**
41 - * (non-PHPdoc)
42 - * @see TablePager::getRowClass()
43 - */
44 - function getRowClass( $row ) {
45 - return 'ep-mentor-row';
46 - }
47 -
48 - /**
49 - * (non-PHPdoc)
50 - * @see TablePager::getTableClass()
51 - */
52 - public function getTableClass() {
53 - return 'TablePager ep-mentors';
54 - }
55 -
56 - /**
57 - * (non-PHPdoc)
58 - * @see EPPager::getFormattedValue()
59 - */
60 - protected function getFormattedValue( $name, $value ) {
61 - switch ( $name ) {
62 - case 'id':
63 - $value = $value;
64 - break;
65 - case 'user_id':
66 - $user = User::newFromId( $value );
67 - $name = $user->getRealName() === '' ? $user->getName() : $user->getRealName();
68 -
69 - $value = Linker::userLink( $value, $name ) . Linker::userToolLinks( $value, $name );
70 - break;
71 - }
72 -
73 - return $value;
74 - }
75 -
76 - /**
77 - * (non-PHPdoc)
78 - * @see EPPager::getSortableFields()
79 - */
80 - protected function getSortableFields() {
81 - return array(
82 - 'id',
83 - );
84 - }
85 -
86 - /**
87 - * (non-PHPdoc)
88 - * @see EPPager::hasActionsColumn()
89 - */
90 - protected function hasActionsColumn() {
91 - return false;
92 - }
93 -
94 - /**
95 - * (non-PHPdoc)
96 - * @see EPPager::getFieldNames()
97 - */
98 - public function getFieldNames() {
99 - $fields = parent::getFieldNames();
100 -
101 - return $fields;
102 - }
103 -
104 -}
Index: trunk/extensions/EducationProgram/includes/EPMCPager.php
@@ -0,0 +1,171 @@
 2+<?php
 3+
 4+/**
 5+ * Course pager, primarily for Special:Courses.
 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+ 'name',
 34+ 'org_id',
 35+ 'students',
 36+ 'active',
 37+ );
 38+ }
 39+
 40+ /**
 41+ * (non-PHPdoc)
 42+ * @see TablePager::getRowClass()
 43+ */
 44+ function getRowClass( $row ) {
 45+ return 'ep-course-row';
 46+ }
 47+
 48+ /**
 49+ * (non-PHPdoc)
 50+ * @see TablePager::getTableClass()
 51+ */
 52+ public function getTableClass() {
 53+ return 'TablePager ep-courses';
 54+ }
 55+
 56+ /**
 57+ * (non-PHPdoc)
 58+ * @see EPPager::getFormattedValue()
 59+ */
 60+ protected function getFormattedValue( $name, $value ) {
 61+ switch ( $name ) {
 62+ case 'name':
 63+ $value = Linker::linkKnown(
 64+ SpecialPage::getTitleFor( 'Course', $value ),
 65+ htmlspecialchars( $value )
 66+ );
 67+ break;
 68+ case 'org_id':
 69+ $value = EPOrg::selectRow( 'name', array( 'id' => $value ) )->getField( 'name' );
 70+
 71+ $value = Linker::linkKnown(
 72+ SpecialPage::getTitleFor( 'Institution', $value ),
 73+ htmlspecialchars( $value )
 74+ );
 75+ break;
 76+ case 'students':
 77+ $value = htmlspecialchars( $this->getLanguage()->formatNum( $value ) );
 78+ break;
 79+ case 'active':
 80+ $value = wfMsgHtml( 'epcoursepager-' . ( $value == '1' ? 'yes' : 'no' ) );
 81+ break;
 82+ }
 83+
 84+ return $value;
 85+ }
 86+
 87+ function getDefaultSort() {
 88+ $c = $this->className; // Yeah, this is needed in PHP 5.3 >_>
 89+ return $c::getPrefixedField( 'name' );
 90+ }
 91+
 92+ /**
 93+ * (non-PHPdoc)
 94+ * @see EPPager::getSortableFields()
 95+ */
 96+ protected function getSortableFields() {
 97+ return array(
 98+ 'name',
 99+ 'students',
 100+ 'active',
 101+ );
 102+ }
 103+
 104+ /**
 105+ * (non-PHPdoc)
 106+ * @see EPPager::getFilterOptions()
 107+ */
 108+ protected function getFilterOptions() {
 109+ return array(
 110+ 'org_id' => array(
 111+ 'type' => 'select',
 112+ 'options' => array_merge(
 113+ array( '' => '' ),
 114+ EPOrg::getOrgOptions( EPOrg::select( array( 'name', 'id' ) ) )
 115+ ),
 116+ 'value' => '',
 117+ 'datatype' => 'int',
 118+ ),
 119+ 'active' => array(
 120+ 'type' => 'select',
 121+ 'options' => array(
 122+ '' => '',
 123+ wfMsg( 'epcoursepager-yes' ) => '1',
 124+ wfMsg( 'epcoursepager-no' ) => '0',
 125+ ),
 126+ 'value' => '',
 127+ ),
 128+ );
 129+ }
 130+
 131+ /**
 132+ * (non-PHPdoc)
 133+ * @see EPPager::getControlLinks()
 134+ */
 135+ protected function getControlLinks( EPDBObject $item ) {
 136+ $links = parent::getControlLinks( $item );
 137+
 138+ $links[] = $value = Linker::linkKnown(
 139+ SpecialPage::getTitleFor( 'Course', $item->getField( 'name' ) ),
 140+ wfMsgHtml( 'view' )
 141+ );
 142+
 143+ if ( $this->getUser()->isAllowed( 'ep-course' ) ) {
 144+ $links[] = $value = Linker::linkKnown(
 145+ SpecialPage::getTitleFor( 'EditCourse', $item->getField( 'name' ) ),
 146+ wfMsgHtml( 'edit' )
 147+ );
 148+
 149+ $links[] = $this->getDeletionLink( 'course', $item->getId() );
 150+ }
 151+
 152+ return $links;
 153+ }
 154+
 155+ /**
 156+ * (non-PHPdoc)
 157+ * @see EPPager::getMultipleItemActions()
 158+ */
 159+ protected function getMultipleItemActions() {
 160+ $actions = parent::getMultipleItemActions();
 161+
 162+ if ( $this->getUser()->isAllowed( 'ep-course' ) ) {
 163+ $actions[wfMsg( 'ep-pager-delete-selected' )] = array(
 164+ 'class' => 'ep-pager-delete-selected',
 165+ 'data-type' => ApiDeleteEducation::getTypeForClassName( $this->className )
 166+ );
 167+ }
 168+
 169+ return $actions;
 170+ }
 171+
 172+}
Property changes on: trunk/extensions/EducationProgram/includes/EPMCPager.php
___________________________________________________________________
Added: svn:eol-style
1173 + native
Index: trunk/extensions/EducationProgram/includes/EPOAPager.php
@@ -0,0 +1,101 @@
 2+<?php
 3+
 4+/**
 5+ * Online ambassador pager.
 6+ *
 7+ * @since 0.1
 8+ *
 9+ * @file EPOAPager.php
 10+ * @ingroup EductaionProgram
 11+ *
 12+ * @licence GNU GPL v3 or later
 13+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 14+ */
 15+class EPOAPager extends EPPager {
 16+ /**
 17+ * Constructor.
 18+ *
 19+ * @param IContextSource $context
 20+ * @param array $conds
 21+ */
 22+ public function __construct( IContextSource $context, array $conds = array() ) {
 23+ $this->mDefaultDirection = true;
 24+ parent::__construct( $context, $conds, 'EPOA' );
 25+ }
 26+
 27+ /**
 28+ * (non-PHPdoc)
 29+ * @see EPPager::getFields()
 30+ */
 31+ public function getFields() {
 32+ return array(
 33+ 'id',
 34+ 'user_id',
 35+ );
 36+ }
 37+
 38+ /**
 39+ * (non-PHPdoc)
 40+ * @see TablePager::getRowClass()
 41+ */
 42+ function getRowClass( $row ) {
 43+ return 'ep-oa-row';
 44+ }
 45+
 46+ /**
 47+ * (non-PHPdoc)
 48+ * @see TablePager::getTableClass()
 49+ */
 50+ public function getTableClass() {
 51+ return 'TablePager ep-oas';
 52+ }
 53+
 54+ /**
 55+ * (non-PHPdoc)
 56+ * @see EPPager::getFormattedValue()
 57+ */
 58+ protected function getFormattedValue( $name, $value ) {
 59+ switch ( $name ) {
 60+ case 'id':
 61+ $value = $value;
 62+ break;
 63+ case 'user_id':
 64+ $user = User::newFromId( $value );
 65+ $name = $user->getRealName() === '' ? $user->getName() : $user->getRealName();
 66+
 67+ $value = Linker::userLink( $value, $name ) . Linker::userToolLinks( $value, $name );
 68+ break;
 69+ }
 70+
 71+ return $value;
 72+ }
 73+
 74+ /**
 75+ * (non-PHPdoc)
 76+ * @see EPPager::getSortableFields()
 77+ */
 78+ protected function getSortableFields() {
 79+ return array(
 80+ 'id',
 81+ );
 82+ }
 83+
 84+ /**
 85+ * (non-PHPdoc)
 86+ * @see EPPager::hasActionsColumn()
 87+ */
 88+ protected function hasActionsColumn() {
 89+ return false;
 90+ }
 91+
 92+ /**
 93+ * (non-PHPdoc)
 94+ * @see EPPager::getFieldNames()
 95+ */
 96+ public function getFieldNames() {
 97+ $fields = parent::getFieldNames();
 98+
 99+ return $fields;
 100+ }
 101+
 102+}
Index: trunk/extensions/EducationProgram/includes/EPCA.php
@@ -0,0 +1,56 @@
 2+<?php
 3+
 4+/**
 5+ * Class representing a single campus ambassador.
 6+ *
 7+ * @since 0.1
 8+ *
 9+ * @file EPCA.php
 10+ * @ingroup EducationProgram
 11+ *
 12+ * @licence GNU GPL v3 or later
 13+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 14+ */
 15+class EPCA extends EPDBObject {
 16+
 17+ /**
 18+ * @see parent::getFieldTypes
 19+ *
 20+ * @since 0.1
 21+ *
 22+ * @return array
 23+ */
 24+ protected static function getFieldTypes() {
 25+ return array(
 26+ 'id' => 'id',
 27+ 'user_id' => 'id',
 28+ );
 29+ }
 30+
 31+ /**
 32+ * Display a pager with campus ambassadors.
 33+ *
 34+ * @since 0.1
 35+ *
 36+ * @param IContextSource $context
 37+ * @param array $conditions
 38+ */
 39+ public static function displayPager( IContextSource $context, array $conditions = array() ) {
 40+ $pager = new EPOAPager( $context, $conditions );
 41+
 42+ if ( $pager->getNumRows() ) {
 43+ $context->getOutput()->addHTML(
 44+ $pager->getFilterControl() .
 45+ $pager->getNavigationBar() .
 46+ $pager->getBody() .
 47+ $pager->getNavigationBar() .
 48+ $pager->getMultipleItemControl()
 49+ );
 50+ }
 51+ else {
 52+ $context->getOutput()->addHTML( $pager->getFilterControl( true ) );
 53+ $context->getOutput()->addWikiMsg( 'ep-ca-noresults' );
 54+ }
 55+ }
 56+
 57+}
Index: trunk/extensions/EducationProgram/includes/EPMC.php
@@ -0,0 +1,520 @@
 2+<?php
 3+
 4+/**
 5+ * Class representing a single course.
 6+ * These describe a specific course, time-independent.
 7+ *
 8+ * @since 0.1
 9+ *
 10+ * @file EPCourse.php
 11+ * @ingroup EducationProgram
 12+ *
 13+ * @licence GNU GPL v3 or later
 14+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 15+ */
 16+class EPCourse extends EPDBObject {
 17+
 18+ /**
 19+ * Field for caching the linked org.
 20+ *
 21+ * @since 0.1
 22+ * @var EPOrg|false
 23+ */
 24+ protected $org = false;
 25+
 26+ /**
 27+ * Field for caching the instructors.
 28+ *
 29+ * @since 0.1
 30+ * @var {array of EPInstructor}|false
 31+ */
 32+ protected $instructors = false;
 33+
 34+ /**
 35+ * @see parent::getFieldTypes
 36+ *
 37+ * @since 0.1
 38+ *
 39+ * @return array
 40+ */
 41+ protected static function getFieldTypes() {
 42+ return array(
 43+ 'id' => 'id',
 44+ 'org_id' => 'id',
 45+
 46+ 'name' => 'str',
 47+ 'description' => 'str',
 48+ 'lang' => 'str',
 49+ 'instructors' => 'array',
 50+
 51+ 'active' => 'bool',
 52+ 'students' => 'int',
 53+ );
 54+ }
 55+
 56+ /**
 57+ * (non-PHPdoc)
 58+ * @see EPDBObject::getDefaults()
 59+ */
 60+ public static function getDefaults() {
 61+ return array(
 62+ 'description' => '',
 63+
 64+ 'active' => false,
 65+ 'students' => 0,
 66+ 'instructors' => array(),
 67+ );
 68+ }
 69+
 70+ /**
 71+ * (non-PHPdoc)
 72+ * @see EPDBObject::loadSummaryFields()
 73+ */
 74+ public function loadSummaryFields( $summaryFields = null ) {
 75+ if ( is_null( $summaryFields ) ) {
 76+ $summaryFields = array( 'students', 'active' );
 77+ }
 78+ else {
 79+ $summaryFields = (array)$summaryFields;
 80+ }
 81+
 82+ $fields = array();
 83+
 84+ if ( in_array( 'students', $summaryFields ) ) {
 85+ $termIds = EPTerm::selectFields( 'id', array( 'course_id' => $this->getId() ) );
 86+
 87+ if ( count( $termIds ) > 0 ) {
 88+ $fields['students'] = wfGetDB( DB_SLAVE )->select(
 89+ 'ep_students_per_term',
 90+ 'COUNT(*) AS rowcount',
 91+ array( 'spt_term_id' => $termIds )
 92+ );
 93+
 94+ $fields['students'] = $fields['students']->fetchObject()->rowcount;
 95+ }
 96+ else {
 97+ $fields['students'] = 0;
 98+ }
 99+ }
 100+
 101+ if ( in_array( 'active', $summaryFields ) ) {
 102+ $now = wfGetDB( DB_SLAVE )->addQuotes( wfTimestampNow() );
 103+
 104+ $fields['active'] = EPTerm::has( array(
 105+ 'course_id' => $this->getId(),
 106+ 'end >= ' . $now,
 107+ 'start <= ' . $now,
 108+ ) );
 109+ }
 110+
 111+ $this->setFields( $fields );
 112+ }
 113+
 114+ /**
 115+ * (non-PHPdoc)
 116+ * @see EPDBObject::removeFromDB()
 117+ */
 118+ public function removeFromDB() {
 119+ $id = $this->getId();
 120+
 121+ if ( $this->updateSummaries ) {
 122+ $this->loadFields( array( 'org_id' ) );
 123+ $orgId = $this->getField( 'org_id', false );
 124+ }
 125+
 126+ $success = parent::removeFromDB();
 127+
 128+ if ( $success ) {
 129+ foreach ( EPTerm::select( 'id', array( 'course_id' => $id ) ) as /* EPTerm */ $term ) {
 130+ $term->setUpdateSummaries( false );
 131+ $success = $term->removeFromDB() && $success;
 132+ }
 133+ }
 134+
 135+ if ( $this->updateSummaries && $orgId !== false ) {
 136+ EPOrg::updateSummaryFields( array( 'terms', 'students', 'courses', 'active' ), array( 'id' => $orgId ) );
 137+ }
 138+
 139+ return $success;
 140+ }
 141+
 142+ /**
 143+ * (non-PHPdoc)
 144+ * @see EPDBObject::insertIntoDB()
 145+ */
 146+ protected function insertIntoDB() {
 147+ $success = parent::insertIntoDB();
 148+
 149+ if ( $this->updateSummaries ) {
 150+ EPOrg::updateSummaryFields( array( 'courses', 'active' ), array( 'id' => $this->getField( 'org_id' ) ) );
 151+ }
 152+
 153+ return $success;
 154+ }
 155+
 156+ /**
 157+ * (non-PHPdoc)
 158+ * @see EPDBObject::updateInDB()
 159+ */
 160+ protected function updateInDB() {
 161+ $oldOrgId = $this->hasField( 'org_id' ) ? self::selectFieldsRow( 'org_id', array( 'id' => $this->getId() ) ) : false;
 162+
 163+ $success = parent::updateInDB();
 164+
 165+ if ( $this->updateSummaries && $success && $oldOrgId !== false && $oldOrgId !== $this->getField( 'org_id' ) ) {
 166+ $conds = array( 'id' => array( $oldOrgId, $this->getField( 'org_id' ) ) );
 167+ EPTerm::updateSummaryFields( 'org_id', array( 'course_id' => $this->getId() ) );
 168+ EPOrg::updateSummaryFields( array( 'terms', 'students', 'courses', 'active' ), $conds );
 169+ }
 170+
 171+ return $success;
 172+ }
 173+
 174+ /**
 175+ * Returns the org associated with this course.
 176+ *
 177+ * @since 0.1
 178+ *
 179+ * @param string|array|null $fields
 180+ *
 181+ * @return EPOrg
 182+ */
 183+ public function getOrg( $fields = null ) {
 184+ if ( $this->org === false ) {
 185+ $this->org = EPOrg::selectRow( $fields, array( 'id' => $this->getField( 'org_id' ) ) );
 186+ }
 187+
 188+ return $this->org;
 189+ }
 190+
 191+ /**
 192+ * Returns a list of courses in an array that can be fed to select inputs.
 193+ *
 194+ * @since 0.1
 195+ *
 196+ * @param array|null $courses
 197+ *
 198+ * @return array
 199+ */
 200+ public static function getCourseOptions( array /* EPCourse */ $courses = null ) {
 201+ $options = array();
 202+
 203+ if ( is_null( $courses ) ) {
 204+ $courses = EPCourse::select( array( 'name', 'id' ) );
 205+ }
 206+
 207+ foreach ( $courses as /* EPCourse */ $course ) {
 208+ $options[$course->getField( 'name' )] = $course->getId();
 209+ }
 210+
 211+ return $options;
 212+ }
 213+
 214+ /**
 215+ * Adds a control to add a new course to the provided context.
 216+ * Additional arguments can be provided to set the default values for the control fields.
 217+ *
 218+ * @since 0.1
 219+ *
 220+ * @param IContextSource $context
 221+ * @param array $args
 222+ *
 223+ * @return boolean
 224+ */
 225+ public static function displayAddNewControl( IContextSource $context, array $args = array() ) {
 226+ if ( !$context->getUser()->isAllowed( 'ep-course' ) ) {
 227+ return false;
 228+ }
 229+
 230+ $out = $context->getOutput();
 231+
 232+ $out->addHTML( Html::openElement(
 233+ 'form',
 234+ array(
 235+ 'method' => 'post',
 236+ 'action' => SpecialPage::getTitleFor( 'EditCourse' )->getLocalURL(),
 237+ )
 238+ ) );
 239+
 240+ $out->addHTML( '<fieldset>' );
 241+
 242+ $out->addHTML( '<legend>' . wfMsgHtml( 'ep-courses-addnew' ) . '</legend>' );
 243+
 244+ $out->addHTML( Html::element( 'p', array(), wfMsg( 'ep-courses-namedoc' ) ) );
 245+
 246+ $out->addHTML( Html::element( 'label', array( 'for' => 'neworg' ), wfMsg( 'ep-courses-neworg' ) ) );
 247+
 248+ $out->addHTML( '&#160;' );
 249+
 250+ $select = new XmlSelect(
 251+ 'neworg',
 252+ 'neworg',
 253+ array_key_exists( 'org', $args ) ? $args['org'] : false
 254+ );
 255+
 256+ $select->addOptions( EPOrg::getOrgOptions() );
 257+ $out->addHTML( $select->getHTML() );
 258+
 259+ $out->addHTML( '&#160;' );
 260+
 261+ $out->addHTML( Xml::inputLabel(
 262+ wfMsg( 'ep-courses-newname' ),
 263+ 'newname',
 264+ 'newname',
 265+ false,
 266+ array_key_exists( 'name', $args ) ? $args['name'] : false
 267+ ) );
 268+
 269+ $out->addHTML( '&#160;' );
 270+
 271+ $out->addHTML( Html::input(
 272+ 'addneworg',
 273+ wfMsg( 'ep-courses-add' ),
 274+ 'submit'
 275+ ) );
 276+
 277+ $out->addHTML( Html::hidden( 'isnew', 1 ) );
 278+
 279+ $out->addHTML( '</fieldset></form>' );
 280+
 281+ return true;
 282+ }
 283+
 284+ /**
 285+ * Adds a control to add a new course to the provided context
 286+ * or show a message if this is not possible for some reason.
 287+ *
 288+ * @since 0.1
 289+ *
 290+ * @param IContextSource $context
 291+ * @param array $args
 292+ */
 293+ public static function displayAddNewRegion( IContextSource $context, array $args = array() ) {
 294+ if ( EPOrg::has() ) {
 295+ EPCourse::displayAddNewControl( $context, $args );
 296+ }
 297+ elseif ( $context->getUser()->isAllowed( 'ep-org' ) ) {
 298+ $context->getOutput()->addWikiMsg( 'ep-courses-addorgfirst' );
 299+ }
 300+ }
 301+
 302+ /**
 303+ * Display a pager with courses.
 304+ *
 305+ * @since 0.1
 306+ *
 307+ * @param IContextSource $context
 308+ * @param array $conditions
 309+ */
 310+ public static function displayPager( IContextSource $context, array $conditions = array() ) {
 311+ $pager = new EPCoursePager( $context, $conditions );
 312+
 313+ if ( $pager->getNumRows() ) {
 314+ $context->getOutput()->addHTML(
 315+ $pager->getFilterControl() .
 316+ $pager->getNavigationBar() .
 317+ $pager->getBody() .
 318+ $pager->getNavigationBar() .
 319+ $pager->getMultipleItemControl()
 320+ );
 321+ }
 322+ else {
 323+ $context->getOutput()->addHTML( $pager->getFilterControl( true ) );
 324+ $context->getOutput()->addWikiMsg( 'ep-courses-noresults' );
 325+ }
 326+ }
 327+
 328+ /**
 329+ * Get a link to Special:Course/name.
 330+ *
 331+ * @since 0.1
 332+ *
 333+ * @return string
 334+ */
 335+ public function getLink() {
 336+ return Linker::linkKnown(
 337+ $this->getTitle(),
 338+ htmlspecialchars( $this->getField( 'name' ) )
 339+ );
 340+ }
 341+
 342+ /**
 343+ * Get the title of Special:Course/name.
 344+ *
 345+ * @since 0.1
 346+ *
 347+ * @return Title
 348+ */
 349+ public function getTitle() {
 350+ return SpecialPage::getTitleFor( 'Course', $this->getField( 'name' ) );
 351+ }
 352+
 353+ /**
 354+ * Returns the instructors as a list of EPInstructor objects.
 355+ *
 356+ * @since 0.1
 357+ *
 358+ * @return array of EPInstructor
 359+ */
 360+ public function getInstructors() {
 361+ if ( $this->instructors === false ) {
 362+ $this->instructors = array();
 363+
 364+ foreach ( $this->getField( 'instructors' ) as $userId ) {
 365+ $this->instructors[] = EPInstructor::newFromId( $userId );
 366+ }
 367+ }
 368+
 369+ return $this->instructors;
 370+ }
 371+
 372+ /**
 373+ * (non-PHPdoc)
 374+ * @see EPDBObject::setField()
 375+ */
 376+ public function setField( $name, $value ) {
 377+ if ( $name === 'instructors' ) {
 378+ $this->instructors = false;
 379+ }
 380+ elseif ( $name === 'org_id' ) {
 381+ $this->org = false;
 382+ }
 383+
 384+ parent::setField( $name, $value );
 385+ }
 386+
 387+ /**
 388+ * Adds a number of instructors to this course,
 389+ * by default also saving the course and only
 390+ * logging the adittion of the instructors.
 391+ *
 392+ * @since 0.1
 393+ *
 394+ * @param array|integer $newInstructors
 395+ * @param string $message
 396+ * @param boolean $save
 397+ * @param boolean $log
 398+ *
 399+ * @return boolean Success indicator
 400+ */
 401+ public function addInstructors( $newInstructors, $message = '', $save = true, $log = true ) {
 402+ $instructors = $this->getField( 'instructors' );
 403+ $addedInstructors = array();
 404+
 405+ foreach ( (array)$newInstructors as $userId ) {
 406+ if ( !is_integer( $userId ) ) {
 407+ throw new MWException( 'Provided user id is not an integer' );
 408+ }
 409+
 410+ if ( !in_array( $userId, $instructors ) ) {
 411+ $instructors[] = $userId;
 412+ $addedInstructors[] = $userId;
 413+ }
 414+ }
 415+
 416+ if ( count( $addedInstructors ) > 0 ) {
 417+ $this->setField( 'instructors', $instructors );
 418+
 419+ $success = true;
 420+
 421+ if ( $save ) {
 422+ $this->disableLogging();
 423+ $success = $this->writeToDB();
 424+ $this->enableLogging();
 425+ }
 426+
 427+ if ( $success && $log ) {
 428+ $this->logInstructorChange( 'add', $addedInstructors, $message );
 429+ }
 430+
 431+ return $success;
 432+ }
 433+ else {
 434+ return true;
 435+ }
 436+ }
 437+
 438+ /**
 439+ * Remove a number of instructors to this course,
 440+ * by default also saving the course and only
 441+ * logging the removal of the instructors.
 442+ *
 443+ * @since 0.1
 444+ *
 445+ * @param array|integer $sadInstructors
 446+ * @param string $message
 447+ * @param boolean $save
 448+ * @param boolean $log
 449+ *
 450+ * @return boolean Success indicator
 451+ */
 452+ public function removeInstructors( $sadInstructors, $message = '', $save = true, $log = true ) {
 453+ $removedInstructors = array();
 454+ $remaimingInstructors = array();
 455+ $sadInstructors = (array)$sadInstructors;
 456+
 457+ foreach ( $this->getField( 'instructors' ) as $userId ) {
 458+ if ( in_array( $userId, $sadInstructors ) ) {
 459+ $removedInstructors[] = $userId;
 460+ }
 461+ else {
 462+ $remaimingInstructors[] = $userId;
 463+ }
 464+ }
 465+
 466+ if ( count( $removedInstructors ) > 0 ) {
 467+ $this->setField( 'instructors', $remaimingInstructors );
 468+
 469+ $success = true;
 470+
 471+ if ( $save ) {
 472+ $this->disableLogging();
 473+ $success = $this->writeToDB();
 474+ $this->enableLogging();
 475+ }
 476+
 477+ if ( $success && $log ) {
 478+ $this->logInstructorChange( 'remove', $removedInstructors, $message );
 479+ }
 480+
 481+ return $success;
 482+ }
 483+ else {
 484+ return true;
 485+ }
 486+ }
 487+
 488+ /**
 489+ * Log a change of the instructors of the course.
 490+ *
 491+ * @since 0.1
 492+ *
 493+ * @param string $action
 494+ * @param array $instructors
 495+ * @param string $message
 496+ */
 497+ protected function logInstructorChange( $action, array $instructors, $message ) {
 498+ $names = array();
 499+
 500+ foreach ( $instructors as $userId ) {
 501+ $names[] = EPInstructor::newFromId( $userId )->getName();
 502+ }
 503+
 504+ $info = array(
 505+ 'type' => 'instructor',
 506+ 'subtype' => $action,
 507+ 'title' => $this->getTitle(),
 508+ 'parameters' => array(
 509+ '4::instructorcount' => count( $names ),
 510+ '5::instructors' => $GLOBALS['wgLang']->listToText( $names )
 511+ ),
 512+ );
 513+
 514+ if ( $message !== '' ) {
 515+ $info['comment'] = $message;
 516+ }
 517+
 518+ EPUtils::log( $info );
 519+ }
 520+
 521+}
Property changes on: trunk/extensions/EducationProgram/includes/EPMC.php
___________________________________________________________________
Added: svn:eol-style
1522 + native
Index: trunk/extensions/EducationProgram/includes/EPOA.php
@@ -0,0 +1,56 @@
 2+<?php
 3+
 4+/**
 5+ * Class representing a single online ambassador.
 6+ *
 7+ * @since 0.1
 8+ *
 9+ * @file EPOA.php
 10+ * @ingroup EducationProgram
 11+ *
 12+ * @licence GNU GPL v3 or later
 13+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 14+ */
 15+class EPOA extends EPDBObject {
 16+
 17+ /**
 18+ * @see parent::getFieldTypes
 19+ *
 20+ * @since 0.1
 21+ *
 22+ * @return array
 23+ */
 24+ protected static function getFieldTypes() {
 25+ return array(
 26+ 'id' => 'id',
 27+ 'user_id' => 'id',
 28+ );
 29+ }
 30+
 31+ /**
 32+ * Display a pager with online ambassadors.
 33+ *
 34+ * @since 0.1
 35+ *
 36+ * @param IContextSource $context
 37+ * @param array $conditions
 38+ */
 39+ public static function displayPager( IContextSource $context, array $conditions = array() ) {
 40+ $pager = new EPOAPager( $context, $conditions );
 41+
 42+ if ( $pager->getNumRows() ) {
 43+ $context->getOutput()->addHTML(
 44+ $pager->getFilterControl() .
 45+ $pager->getNavigationBar() .
 46+ $pager->getBody() .
 47+ $pager->getNavigationBar() .
 48+ $pager->getMultipleItemControl()
 49+ );
 50+ }
 51+ else {
 52+ $context->getOutput()->addHTML( $pager->getFilterControl( true ) );
 53+ $context->getOutput()->addWikiMsg( 'ep-oa-noresults' );
 54+ }
 55+ }
 56+
 57+}
Index: trunk/extensions/EducationProgram/includes/EPCAPager.php
@@ -0,0 +1,101 @@
 2+<?php
 3+
 4+/**
 5+ * Campus ambassador pager.
 6+ *
 7+ * @since 0.1
 8+ *
 9+ * @file EPCAPager.php
 10+ * @ingroup EductaionProgram
 11+ *
 12+ * @licence GNU GPL v3 or later
 13+ * @author Jeroen De Dauw < jeroendedauw@gmail.com >
 14+ */
 15+class EPCAPager extends EPPager {
 16+ /**
 17+ * Constructor.
 18+ *
 19+ * @param IContextSource $context
 20+ * @param array $conds
 21+ */
 22+ public function __construct( IContextSource $context, array $conds = array() ) {
 23+ $this->mDefaultDirection = true;
 24+ parent::__construct( $context, $conds, 'EPCA' );
 25+ }
 26+
 27+ /**
 28+ * (non-PHPdoc)
 29+ * @see EPPager::getFields()
 30+ */
 31+ public function getFields() {
 32+ return array(
 33+ 'id',
 34+ 'user_id',
 35+ );
 36+ }
 37+
 38+ /**
 39+ * (non-PHPdoc)
 40+ * @see TablePager::getRowClass()
 41+ */
 42+ function getRowClass( $row ) {
 43+ return 'ep-ca-row';
 44+ }
 45+
 46+ /**
 47+ * (non-PHPdoc)
 48+ * @see TablePager::getTableClass()
 49+ */
 50+ public function getTableClass() {
 51+ return 'TablePager ep-cas';
 52+ }
 53+
 54+ /**
 55+ * (non-PHPdoc)
 56+ * @see EPPager::getFormattedValue()
 57+ */
 58+ protected function getFormattedValue( $name, $value ) {
 59+ switch ( $name ) {
 60+ case 'id':
 61+ $value = $value;
 62+ break;
 63+ case 'user_id':
 64+ $user = User::newFromId( $value );
 65+ $name = $user->getRealName() === '' ? $user->getName() : $user->getRealName();
 66+
 67+ $value = Linker::userLink( $value, $name ) . Linker::userToolLinks( $value, $name );
 68+ break;
 69+ }
 70+
 71+ return $value;
 72+ }
 73+
 74+ /**
 75+ * (non-PHPdoc)
 76+ * @see EPPager::getSortableFields()
 77+ */
 78+ protected function getSortableFields() {
 79+ return array(
 80+ 'id',
 81+ );
 82+ }
 83+
 84+ /**
 85+ * (non-PHPdoc)
 86+ * @see EPPager::hasActionsColumn()
 87+ */
 88+ protected function hasActionsColumn() {
 89+ return false;
 90+ }
 91+
 92+ /**
 93+ * (non-PHPdoc)
 94+ * @see EPPager::getFieldNames()
 95+ */
 96+ public function getFieldNames() {
 97+ $fields = parent::getFieldNames();
 98+
 99+ return $fields;
 100+ }
 101+
 102+}

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