Index: trunk/extensions/EducationProgram/actions/ViewCourseAction.php |
— | — | @@ -47,12 +47,7 @@ |
48 | 48 | |
49 | 49 | $out->addHTML( $this->getOutput()->parse( $course->getField( 'description' ) ) ); |
50 | 50 | |
51 | | - $studentIds = array_map( |
52 | | - function( EPStudent $student ) { |
53 | | - return $student->getId(); |
54 | | - }, |
55 | | - $course->getStudents( 'id' ) |
56 | | - ); |
| 51 | + $studentIds = $course->getField( 'students' ); |
57 | 52 | |
58 | 53 | if ( !empty( $studentIds ) ) { |
59 | 54 | $out->addElement( 'h2', array(), wfMsg( 'ep-course-students' ) ); |
Index: trunk/extensions/EducationProgram/includes/EPCourse.php |
— | — | @@ -430,15 +430,7 @@ |
431 | 431 | * @return array of EPStudent |
432 | 432 | */ |
433 | 433 | public function getStudents() { |
434 | | - if ( $this->students === false ) { |
435 | | - $this->students = array(); |
436 | | - |
437 | | - foreach ( $this->getField( 'students' ) as $userId ) { |
438 | | - $this->students[] = EPStudent::newFromUserId( $userId, true ); |
439 | | - } |
440 | | - } |
441 | | - |
442 | | - return $this->students; |
| 434 | + return $this->getRoleList( 'students', 'EPStudents', 'students' ); |
443 | 435 | } |
444 | 436 | |
445 | 437 | /** |
— | — | @@ -449,15 +441,36 @@ |
450 | 442 | * @return array of EPInstructor |
451 | 443 | */ |
452 | 444 | public function getInstructors() { |
453 | | - if ( $this->instructors === false ) { |
454 | | - $this->instructors = array(); |
| 445 | + return $this->getRoleList( 'instructors', 'EPInstructors', 'instructors' ); |
| 446 | + } |
455 | 447 | |
456 | | - foreach ( $this->getField( 'instructors' ) as $userId ) { |
457 | | - $this->instructors[] = EPInstructor::newFromUserId( $userId ); |
| 448 | + /** |
| 449 | + * Returns the users that have the specified role. |
| 450 | + * |
| 451 | + * @since 0.1 |
| 452 | + * |
| 453 | + * @param string $fieldName Name of the role field. |
| 454 | + * @param string $tableName Name of the table class in which this role is kept track of. |
| 455 | + * @param string $classField Name of the field in which the list is cached in this class. |
| 456 | + * |
| 457 | + * @return array of EPRole |
| 458 | + */ |
| 459 | + protected function getRoleList( $fieldName, $tableName, $classField ) { |
| 460 | + if ( $this->$classField === false ) { |
| 461 | + $userIds = $this->getField( $fieldName ); |
| 462 | + |
| 463 | + if ( empty( $userIds ) ) { |
| 464 | + $this->$classField = array(); |
458 | 465 | } |
| 466 | + else { |
| 467 | + $this->$classField = $tableName::singleton()->select( |
| 468 | + null, |
| 469 | + array( 'user_id' => $userIds ) |
| 470 | + ); |
| 471 | + } |
459 | 472 | } |
460 | 473 | |
461 | | - return $this->instructors; |
| 474 | + return $this->$classField; |
462 | 475 | } |
463 | 476 | |
464 | 477 | /** |
— | — | @@ -468,15 +481,7 @@ |
469 | 482 | * @return array of EPCA |
470 | 483 | */ |
471 | 484 | public function getCampusAmbassadors() { |
472 | | - if ( $this->cas === false ) { |
473 | | - $this->cas = array(); |
474 | | - |
475 | | - foreach ( $this->getField( 'campus_ambs' ) as $userId ) { |
476 | | - $this->cas[] = EPCA::newFromUserId( $userId ); |
477 | | - } |
478 | | - } |
479 | | - |
480 | | - return $this->cas; |
| 485 | + return $this->getRoleList( 'campus_ambs', 'EPCAs', 'cas' ); |
481 | 486 | } |
482 | 487 | |
483 | 488 | /** |
— | — | @@ -487,15 +492,7 @@ |
488 | 493 | * @return array of EPOA |
489 | 494 | */ |
490 | 495 | public function getOnlineAmbassadors() { |
491 | | - if ( $this->oas === false ) { |
492 | | - $this->oas = array(); |
493 | | - |
494 | | - foreach ( $this->getField( 'online_ambs' ) as $userId ) { |
495 | | - $this->oas[] = EPOA::newFromUserId( $userId ); |
496 | | - } |
497 | | - } |
498 | | - |
499 | | - return $this->oas; |
| 496 | + return $this->getRoleList( 'online_ambs', 'EPOAs', 'oas' ); |
500 | 497 | } |
501 | 498 | |
502 | 499 | /** |