Index: trunk/extensions/EducationProgram/specials/SpecialMyCourses.php |
— | — | @@ -19,7 +19,7 @@ |
20 | 20 | * @since 0.1 |
21 | 21 | */ |
22 | 22 | public function __construct() { |
23 | | - parent::__construct( 'MyCourses' ); |
| 23 | + parent::__construct( 'MyCourses', 'epstudent' ); |
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
— | — | @@ -32,9 +32,47 @@ |
33 | 33 | public function execute( $subPage ) { |
34 | 34 | parent::execute( $subPage ); |
35 | 35 | |
| 36 | + if ( $this->getRequest()->getCheck( 'enrolled' ) ) { |
| 37 | + EPStudent::setReadDb( DB_MASTER ); |
| 38 | + } |
| 39 | + |
| 40 | + $student = EPStudent::newFromUser( $this->getUser() ); |
| 41 | + EPStudent::setReadDb( DB_SLAVE ); |
| 42 | + |
| 43 | + if ( $student === false ) { |
| 44 | + $this->getOutput()->addWikiMsg( 'ep-mycourses-not-a-student' ); |
| 45 | + } |
| 46 | + else { |
| 47 | + if ( $this->subPage === '' ) { |
| 48 | + $this->displayCourse( $student, $this->subPage ); |
| 49 | + } |
| 50 | + else { |
| 51 | + $this->displayCourses( $student ); |
| 52 | + } |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + protected function displayCourses( EPStudent $student ) { |
36 | 57 | $out = $this->getOutput(); |
37 | 58 | |
38 | | - // TODO: AUTH |
| 59 | + if ( $student->hasTerm() ) { |
| 60 | + if ( $this->getRequest()->getCheck( 'enrolled' ) ) { |
| 61 | + $this->showSuccess( wfMessage( 'ep-mycourses-enrolled', '', '' ) ); // TODO |
| 62 | + } |
| 63 | + |
| 64 | + $this->displayCourses( $student ); |
| 65 | + } |
| 66 | + else { |
| 67 | + $out->addWikiMsg( 'ep-mycourses-not-enrolled' ); |
| 68 | + } |
39 | 69 | } |
40 | 70 | |
| 71 | + protected function displayCourse( EPStudent $student, $courseName ) { |
| 72 | + $course = EPCourse::selectRow( null, array( 'name' => $courseName ) ); |
| 73 | + |
| 74 | + if ( $student->hasTerm( array( ) ) ) { |
| 75 | + // TODO |
| 76 | + } |
| 77 | + } |
| 78 | + |
41 | 79 | } |
Index: trunk/extensions/EducationProgram/specials/SpecialEnroll.php |
— | — | @@ -208,7 +208,7 @@ |
209 | 209 | public function onSuccess() { |
210 | 210 | $this->getOutput()->redirect( |
211 | 211 | SpecialPage::getTitleFor( 'MyCourses' )->getLocalURL( array( |
212 | | - 'enrolled' => 1 |
| 212 | + 'enrolled' => $this->term->getId() |
213 | 213 | ) ) |
214 | 214 | ); |
215 | 215 | } |
Index: trunk/extensions/EducationProgram/includes/EPMentor.php |
— | — | @@ -57,9 +57,12 @@ |
58 | 58 | if ( is_null( $fields ) ) { |
59 | 59 | $this->orgs = $orgs; |
60 | 60 | } |
| 61 | + |
| 62 | + return $orgs; |
61 | 63 | } |
62 | | - |
63 | | - return $orgs; |
| 64 | + else { |
| 65 | + return $this->orgs; |
| 66 | + } |
64 | 67 | } |
65 | 68 | |
66 | 69 | /** |
— | — | @@ -140,7 +143,7 @@ |
141 | 144 | } |
142 | 145 | |
143 | 146 | /** |
144 | | - * Retruns if the mentor has any term matching the provided contitions. |
| 147 | + * Retruns if the mentor has any term matching the provided conditions. |
145 | 148 | * |
146 | 149 | * @since 0.1 |
147 | 150 | * |
Index: trunk/extensions/EducationProgram/includes/EPStudent.php |
— | — | @@ -14,6 +14,14 @@ |
15 | 15 | class EPStudent extends EPDBObject { |
16 | 16 | |
17 | 17 | /** |
| 18 | + * Cached array of the linked EPTerm objects. |
| 19 | + * |
| 20 | + * @since 0.1 |
| 21 | + * @var array|false |
| 22 | + */ |
| 23 | + protected $terms = false; |
| 24 | + |
| 25 | + /** |
18 | 26 | * @see parent::getFieldTypes |
19 | 27 | * |
20 | 28 | * @since 0.1 |
— | — | @@ -71,5 +79,72 @@ |
72 | 80 | |
73 | 81 | return $success; |
74 | 82 | } |
| 83 | + |
| 84 | + /** |
| 85 | + * Returns the orgs this mentor is part of. |
| 86 | + * Caches the result when no conditions are provided and all fields are selected. |
| 87 | + * |
| 88 | + * @since 0.1 |
| 89 | + * |
| 90 | + * @param array|null $fields |
| 91 | + * @param array $conditions |
| 92 | + * |
| 93 | + * @return array of EPTerm |
| 94 | + */ |
| 95 | + public function getTerms( array $fields = null, array $conditions = array() ) { |
| 96 | + if ( count( $conditions ) !== 0 ) { |
| 97 | + return $this->doGetTerms( $fields, $conditions ); |
| 98 | + } |
| 99 | + |
| 100 | + if ( $this->terms === false ) { |
| 101 | + $terms = $this->doGetTerms( $fields, $conditions ); |
| 102 | + |
| 103 | + if ( is_null( $fields ) ) { |
| 104 | + $this->terms = $terms; |
| 105 | + } |
| 106 | + |
| 107 | + return $terms; |
| 108 | + } |
| 109 | + else { |
| 110 | + return $this->terms; |
| 111 | + } |
| 112 | + } |
| 113 | + |
| 114 | + /** |
| 115 | + * Returns the terms this student is enrolled in. |
| 116 | + * |
| 117 | + * @since 0.1 |
| 118 | + * |
| 119 | + * @param array|null $fields |
| 120 | + * @param array $conditions |
| 121 | + * |
| 122 | + * @return array of EPTerm |
| 123 | + */ |
| 124 | + protected function doGetTerms( $fields, array $conditions ) { |
| 125 | + $conditions = array_merge( |
| 126 | + array( array( 'ep_students_per_term', 'student_id' ), $this->getId() ), |
| 127 | + $conditions |
| 128 | + ); |
| 129 | + |
| 130 | + return EPTerm::select( |
| 131 | + $fields, |
| 132 | + $conditions, |
| 133 | + array(), |
| 134 | + array( 'terms' => array( 'INNER JOIN', array( array( array( 'ep_students_per_term', 'term_id' ), array( 'terms', 'id' ) ) ) ) ) |
| 135 | + ); |
| 136 | + } |
| 137 | + |
| 138 | + /** |
| 139 | + * Retruns if the mentor has any term matching the provided conditions. |
| 140 | + * |
| 141 | + * @since 0.1 |
| 142 | + * |
| 143 | + * @param array $conditions |
| 144 | + * |
| 145 | + * @return boolean |
| 146 | + */ |
| 147 | + public function hasTerm( array $conditions = array() ) { |
| 148 | + return count( $this->getTerms( 'id', $conditions ) ) > 0; |
| 149 | + } |
75 | 150 | |
76 | 151 | } |
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php |
— | — | @@ -205,7 +205,10 @@ |
206 | 206 | 'ep-enroll-no-token' => 'You need to provide the token needed to enroll for this term.', |
207 | 207 | 'ep-enroll-invalid-token' => 'The token you provided is invalid.', |
208 | 208 | 'ep-enroll-legend' => 'Enroll', |
209 | | - |
| 209 | + |
| 210 | + // Special:MyCourses |
| 211 | + 'ep-mycourses-enrolled' => 'You have successfully enrolled for $1 at $2', |
| 212 | + |
210 | 213 | // Navigation links |
211 | 214 | 'ep-nav-orgs' => 'Institution list', |
212 | 215 | 'ep-nav-courses' => 'Courses list', |