Index: trunk/extensions/EducationProgram/sql/EducationProgram.sql |
— | — | @@ -27,6 +27,7 @@ |
28 | 28 | CREATE TABLE IF NOT EXISTS /*_*/ep_terms ( |
29 | 29 | term_id INT unsigned NOT NULL auto_increment PRIMARY KEY, |
30 | 30 | term_course_id INT unsigned NOT NULL, -- Foreign key on ep_courses.course_id |
| 31 | + term_org_id INT unsigned NOT NULL, -- Foreign key on ep_orgs.org_id. Helper field, not strictly needed. |
31 | 32 | term_year SMALLINT unsigned NOT NULL, -- Yeah in which the term takes place |
32 | 33 | term_start varbinary(14) NOT NULL, -- Start time of the term |
33 | 34 | term_end varbinary(14) NOT NULL -- End time of the term |
Index: trunk/extensions/EducationProgram/specials/SpecialInstitution.php |
— | — | @@ -35,25 +35,30 @@ |
36 | 36 | |
37 | 37 | $out = $this->getOutput(); |
38 | 38 | |
39 | | - $out->setPageTitle( wfMsgExt( 'ep-institution-title', 'parsemag', $this->subPage ) ); |
40 | | - |
41 | | - $org = EPOrg::selectRow( null, array( 'name' => $this->subPage ) ); |
42 | | - |
43 | | - if ( $org === false ) { |
44 | | - if ( $this->getUser()->isAllowed( 'epadmin' ) ) { |
45 | | - $out->addWikiMsg( 'ep-institution-create', $this->subPage ); |
46 | | - EPOrg::displayAddNewControl( $this->getContext(), array( 'name' => $this->subPage ) ); |
47 | | - } |
48 | | - else { |
49 | | - $out->addWikiMsg( 'ep-institution-none', $this->subPage ); |
50 | | - } |
| 39 | + if ( trim( $subPage ) === '' ) { |
| 40 | + $this->getOutput()->redirect( SpecialPage::getTitleFor( 'Institutions' )->getLocalURL() ); |
51 | 41 | } |
52 | 42 | else { |
53 | | - $this->displayInfo( $org ); |
| 43 | + $out->setPageTitle( wfMsgExt( 'ep-institution-title', 'parsemag', $this->subPage ) ); |
54 | 44 | |
55 | | - $out->addHTML( Html::element( 'h2', array(), wfMsg( 'ep-institution-courses' ) ) ); |
| 45 | + $org = EPOrg::selectRow( null, array( 'name' => $this->subPage ) ); |
56 | 46 | |
57 | | - EPCourse::displayPager( $this->getContext(), array( 'org_id' => $org->getId() ) ); |
| 47 | + if ( $org === false ) { |
| 48 | + if ( $this->getUser()->isAllowed( 'epadmin' ) ) { |
| 49 | + $out->addWikiMsg( 'ep-institution-create', $this->subPage ); |
| 50 | + EPOrg::displayAddNewControl( $this->getContext(), array( 'name' => $this->subPage ) ); |
| 51 | + } |
| 52 | + else { |
| 53 | + $out->addWikiMsg( 'ep-institution-none', $this->subPage ); |
| 54 | + } |
| 55 | + } |
| 56 | + else { |
| 57 | + $this->displayInfo( $org ); |
| 58 | + |
| 59 | + $out->addHTML( Html::element( 'h2', array(), wfMsg( 'ep-institution-courses' ) ) ); |
| 60 | + |
| 61 | + EPCourse::displayPager( $this->getContext(), array( 'org_id' => $org->getId() ) ); |
| 62 | + } |
58 | 63 | } |
59 | 64 | } |
60 | 65 | |
Index: trunk/extensions/EducationProgram/specials/SpecialCourse.php |
— | — | @@ -35,26 +35,31 @@ |
36 | 36 | |
37 | 37 | $out = $this->getOutput(); |
38 | 38 | |
39 | | - $out->setPageTitle( wfMsgExt( 'ep-course-title', 'parsemag', $this->subPage ) ); |
| 39 | + if ( trim( $subPage ) === '' ) { |
| 40 | + $this->getOutput()->redirect( SpecialPage::getTitleFor( 'Courses' )->getLocalURL() ); |
| 41 | + } |
| 42 | + else { |
| 43 | + $out->setPageTitle( wfMsgExt( 'ep-course-title', 'parsemag', $this->subPage ) ); |
40 | 44 | |
41 | | - $course = EPCourse::selectRow( null, array( 'name' => $this->subPage ) ); |
42 | | - |
43 | | - if ( $course === false ) { |
44 | | - if ( $this->getUser()->isAllowed( 'epadmin' ) || $this->getUser()->isAllowed( 'epmentor' ) ) { |
45 | | - $out->addWikiMsg( 'ep-course-create', $this->subPage ); |
46 | | - EPCourse::displayAddNewRegion( $this->getContext(), array( 'name' => $this->subPage ) ); |
| 45 | + $course = EPCourse::selectRow( null, array( 'name' => $this->subPage ) ); |
| 46 | + |
| 47 | + if ( $course === false ) { |
| 48 | + if ( $this->getUser()->isAllowed( 'epadmin' ) || $this->getUser()->isAllowed( 'epmentor' ) ) { |
| 49 | + $out->addWikiMsg( 'ep-course-create', $this->subPage ); |
| 50 | + EPCourse::displayAddNewRegion( $this->getContext(), array( 'name' => $this->subPage ) ); |
| 51 | + } |
| 52 | + else { |
| 53 | + $out->addWikiMsg( 'ep-course-none', $this->subPage ); |
| 54 | + } |
47 | 55 | } |
48 | 56 | else { |
49 | | - $out->addWikiMsg( 'ep-course-none', $this->subPage ); |
| 57 | + $this->displayInfo( $course ); |
| 58 | + |
| 59 | + $out->addHTML( Html::element( 'h2', array(), wfMsg( 'ep-course-terms' ) ) ); |
| 60 | + |
| 61 | + EPTerm::displayPager( $this->getContext(), array( 'course_id' => $course->getId() ) ); |
50 | 62 | } |
51 | 63 | } |
52 | | - else { |
53 | | - $this->displayInfo( $course ); |
54 | | - |
55 | | - $out->addHTML( Html::element( 'h2', array(), wfMsg( 'ep-course-terms' ) ) ); |
56 | | - |
57 | | - EPTerm::displayPager( $this->getContext(), array( 'course_id' => $course->getId() ) ); |
58 | | - } |
59 | 64 | } |
60 | 65 | |
61 | 66 | /** |
Index: trunk/extensions/EducationProgram/specials/SpecialTerm.php |
— | — | @@ -35,26 +35,31 @@ |
36 | 36 | |
37 | 37 | $out = $this->getOutput(); |
38 | 38 | |
39 | | - $out->setPageTitle( wfMsgExt( 'ep-term-title', 'parsemag', $this->subPage ) ); |
| 39 | + if ( trim( $subPage ) === '' ) { |
| 40 | + $this->getOutput()->redirect( SpecialPage::getTitleFor( 'Terms' )->getLocalURL() ); |
| 41 | + } |
| 42 | + else { |
| 43 | + $out->setPageTitle( wfMsgExt( 'ep-term-title', 'parsemag', $this->subPage ) ); |
40 | 44 | |
41 | | - $term = EPTerm::selectRow( null, array( 'id' => $this->subPage ) ); |
42 | | - |
43 | | - if ( $term === false ) { |
44 | | - if ( $this->getUser()->isAllowed( 'epadmin' ) || $this->getUser()->isAllowed( 'epmentor' ) ) { |
45 | | - $out->addWikiMsg( 'ep-term-create', $this->subPage ); |
46 | | - EPTerm::displayAddNewRegion( $this->getContext(), array( 'id' => $this->subPage ) ); |
| 45 | + $term = EPTerm::selectRow( null, array( 'id' => $this->subPage ) ); |
| 46 | + |
| 47 | + if ( $term === false ) { |
| 48 | + if ( $this->getUser()->isAllowed( 'epadmin' ) || $this->getUser()->isAllowed( 'epmentor' ) ) { |
| 49 | + $out->addWikiMsg( 'ep-term-create', $this->subPage ); |
| 50 | + EPTerm::displayAddNewRegion( $this->getContext(), array( 'id' => $this->subPage ) ); |
| 51 | + } |
| 52 | + else { |
| 53 | + $out->addWikiMsg( 'ep-term-none', $this->subPage ); |
| 54 | + } |
47 | 55 | } |
48 | 56 | else { |
49 | | - $out->addWikiMsg( 'ep-term-none', $this->subPage ); |
| 57 | + $this->displayInfo( $term ); |
| 58 | + |
| 59 | + $out->addHTML( Html::element( 'h2', array(), wfMsg( 'ep-term-students' ) ) ); |
| 60 | + |
| 61 | + // TODO: students |
50 | 62 | } |
51 | 63 | } |
52 | | - else { |
53 | | - $this->displayInfo( $term ); |
54 | | - |
55 | | - $out->addHTML( Html::element( 'h2', array(), wfMsg( 'ep-term-students' ) ) ); |
56 | | - |
57 | | - // TODO |
58 | | - } |
59 | 64 | } |
60 | 65 | |
61 | 66 | /** |
Index: trunk/extensions/EducationProgram/includes/EPMentor.php |
— | — | @@ -14,6 +14,14 @@ |
15 | 15 | class EPMentor extends EPDBObject { |
16 | 16 | |
17 | 17 | /** |
| 18 | + * Cached array of the linked EPOrg objects. |
| 19 | + * |
| 20 | + * @since 0.1 |
| 21 | + * @var array|false |
| 22 | + */ |
| 23 | + protected $orgs = false; |
| 24 | + |
| 25 | + /** |
18 | 26 | * @see parent::getFieldTypes |
19 | 27 | * |
20 | 28 | * @since 0.1 |
— | — | @@ -37,12 +45,16 @@ |
38 | 46 | * @return array of EPOrg |
39 | 47 | */ |
40 | 48 | public function getOrgs( array $fields = null ) { |
41 | | - return EPOrg::select( |
42 | | - $fields, |
43 | | - array( array( 'ep_mentors_per_org', 'mentor_id' ), $this->getId() ), |
44 | | - array(), |
45 | | - array( 'orgs' => array( 'INNER JOIN', array( array( array( 'ep_mentors_per_org', 'org_id' ), array( 'orgs', 'id' ) ) ) ) ) |
46 | | - ); |
| 49 | + if ( $this->orgs === false ) { |
| 50 | + $this->orgs = EPOrg::select( |
| 51 | + $fields, |
| 52 | + array( array( 'ep_mentors_per_org', 'mentor_id' ), $this->getId() ), |
| 53 | + array(), |
| 54 | + array( 'orgs' => array( 'INNER JOIN', array( array( array( 'ep_mentors_per_org', 'org_id' ), array( 'orgs', 'id' ) ) ) ) ) |
| 55 | + ); |
| 56 | + } |
| 57 | + |
| 58 | + return $this->orgs; |
47 | 59 | } |
48 | 60 | |
49 | 61 | /** |
— | — | @@ -55,10 +67,27 @@ |
56 | 68 | * @return array of EPCourse |
57 | 69 | */ |
58 | 70 | public function getCourses( array $fields = null ) { |
59 | | - return array(); // TODO |
| 71 | + return array_reduce( $this->getOrgs(), function( array $courses, EPOrg $org ) use ( $fields ) { |
| 72 | + return array_merge( $courses, $org->getCourses( $fields ) ); |
| 73 | + }, array() ); |
60 | 74 | } |
61 | 75 | |
62 | 76 | /** |
| 77 | + * Retruns the terms this mentor can manage. |
| 78 | + * |
| 79 | + * @since 0.1 |
| 80 | + * |
| 81 | + * @param array|null $fields |
| 82 | + * |
| 83 | + * @return array of EPTerm |
| 84 | + */ |
| 85 | + public function getTerms( array $fields = null ) { |
| 86 | + return array_reduce( $this->getOrgs(), function( array $terms, EPOrg $org ) use ( $fields ) { |
| 87 | + return array_merge( $terms, $org->getTerms( $fields ) ); |
| 88 | + }, array() ); |
| 89 | + } |
| 90 | + |
| 91 | + /** |
63 | 92 | * Retruns if the mentor has any course matching the provided contitions. |
64 | 93 | * |
65 | 94 | * @since 0.1 |
— | — | @@ -68,7 +97,7 @@ |
69 | 98 | * @return boolean |
70 | 99 | */ |
71 | 100 | public function hasCourse( array $conditions = array() ) { |
72 | | - return true; // TODO |
| 101 | + return true; |
73 | 102 | } |
74 | 103 | |
75 | 104 | /** |
Index: trunk/extensions/EducationProgram/includes/EPOrg.php |
— | — | @@ -14,6 +14,22 @@ |
15 | 15 | class EPOrg extends EPDBObject { |
16 | 16 | |
17 | 17 | /** |
| 18 | + * Cached array of the linked EPCourse objects. |
| 19 | + * |
| 20 | + * @since 0.1 |
| 21 | + * @var array|false |
| 22 | + */ |
| 23 | + protected $courses = false; |
| 24 | + |
| 25 | + /** |
| 26 | + * Cached array of the linked EPTerm objects. |
| 27 | + * |
| 28 | + * @since 0.1 |
| 29 | + * @var array|false |
| 30 | + */ |
| 31 | + protected $terms = false; |
| 32 | + |
| 33 | + /** |
18 | 34 | * @see parent::getFieldTypes |
19 | 35 | * |
20 | 36 | * @since 0.1 |
— | — | @@ -182,4 +198,38 @@ |
183 | 199 | } |
184 | 200 | } |
185 | 201 | |
| 202 | + /** |
| 203 | + * Retruns the courses linked to this org. |
| 204 | + * |
| 205 | + * @since 0.1 |
| 206 | + * |
| 207 | + * @param array|null $fields |
| 208 | + * |
| 209 | + * @return array of EPCourse |
| 210 | + */ |
| 211 | + public function getCourses( array $fields = null ) { |
| 212 | + if ( $this->courses === false ) { |
| 213 | + $this->courses = EPCourse::select( $fields, array( 'org_id' => $this->getId() ) ); |
| 214 | + } |
| 215 | + |
| 216 | + return $this->courses; |
| 217 | + } |
| 218 | + |
| 219 | + /** |
| 220 | + * Retruns the terms linked to this org. |
| 221 | + * |
| 222 | + * @since 0.1 |
| 223 | + * |
| 224 | + * @param array|null $fields |
| 225 | + * |
| 226 | + * @return array of EPTerm |
| 227 | + */ |
| 228 | + public function getTerms( array $fields = null ) { |
| 229 | + if ( $this->terms === false ) { |
| 230 | + $this->terms = EPTerm::select( $fields, array( 'org_id' => $this->getId() ) ); |
| 231 | + } |
| 232 | + |
| 233 | + return $this->terms; |
| 234 | + } |
| 235 | + |
186 | 236 | } |
Index: trunk/extensions/EducationProgram/includes/EPTerm.php |
— | — | @@ -15,6 +15,22 @@ |
16 | 16 | class EPTerm extends EPDBObject { |
17 | 17 | |
18 | 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 | + /** |
19 | 35 | * @see parent::getFieldTypes |
20 | 36 | * |
21 | 37 | * @since 0.1 |
— | — | @@ -25,6 +41,7 @@ |
26 | 42 | return array( |
27 | 43 | 'id' => 'id', |
28 | 44 | 'course_id' => 'id', |
| 45 | + 'org_id' => 'id', |
29 | 46 | |
30 | 47 | 'year' => 'int', |
31 | 48 | 'start' => 'str', // TS_MW |
— | — | @@ -46,6 +63,19 @@ |
47 | 64 | |
48 | 65 | /** |
49 | 66 | * (non-PHPdoc) |
| 67 | + * @see EPDBObject::insertIntoDB() |
| 68 | + */ |
| 69 | + protected function insertIntoDB() { |
| 70 | + if ( !$this->hasField( 'org_id' ) ) { |
| 71 | + $this->setField( 'org_id', $this->getCourse( 'org_id' )->getField( 'org_id' ) ); |
| 72 | + } |
| 73 | + |
| 74 | + |
| 75 | + parent::insertIntoDB(); |
| 76 | + } |
| 77 | + |
| 78 | + /** |
| 79 | + * (non-PHPdoc) |
50 | 80 | * @see EPDBObject::removeFromDB() |
51 | 81 | */ |
52 | 82 | public function removeFromDB() { |
— | — | @@ -61,6 +91,40 @@ |
62 | 92 | } |
63 | 93 | |
64 | 94 | /** |
| 95 | + * Returns the course associated with this term. |
| 96 | + * |
| 97 | + * @since 0.1 |
| 98 | + * |
| 99 | + * @param string|array|null $fields |
| 100 | + * |
| 101 | + * @return EPCourse |
| 102 | + */ |
| 103 | + public function getCourse( $fields = null ) { |
| 104 | + if ( $this->course === false ) { |
| 105 | + $this->course = EPCourse::selectRow( $fields, array( 'id' => $this->getField( 'course_id' ) ) ); |
| 106 | + } |
| 107 | + |
| 108 | + return $this->course; |
| 109 | + } |
| 110 | + |
| 111 | + /** |
| 112 | + * Returns the org associated with this term. |
| 113 | + * |
| 114 | + * @since 0.1 |
| 115 | + * |
| 116 | + * @param string|array|null $fields |
| 117 | + * |
| 118 | + * @return EPOrg |
| 119 | + */ |
| 120 | + public function getOrg( $fields = null ) { |
| 121 | + if ( $this->org === false ) { |
| 122 | + $this->org = EPOrg::selectRow( $fields, array( 'id' => $this->getField( 'org_id' ) ) ); |
| 123 | + } |
| 124 | + |
| 125 | + return $this->org; |
| 126 | + } |
| 127 | + |
| 128 | + /** |
65 | 129 | * Display a pager with terms. |
66 | 130 | * |
67 | 131 | * @since 0.1 |
Index: trunk/extensions/EducationProgram/includes/EPCourse.php |
— | — | @@ -15,6 +15,14 @@ |
16 | 16 | class EPCourse extends EPDBObject { |
17 | 17 | |
18 | 18 | /** |
| 19 | + * Field for caching the linked org. |
| 20 | + * |
| 21 | + * @since 0.1 |
| 22 | + * @var EPOrg|false |
| 23 | + */ |
| 24 | + protected $org = false; |
| 25 | + |
| 26 | + /** |
19 | 27 | * @see parent::getFieldTypes |
20 | 28 | * |
21 | 29 | * @since 0.1 |
— | — | @@ -60,6 +68,23 @@ |
61 | 69 | } |
62 | 70 | |
63 | 71 | /** |
| 72 | + * Returns the org associated with this course. |
| 73 | + * |
| 74 | + * @since 0.1 |
| 75 | + * |
| 76 | + * @param string|array|null $fields |
| 77 | + * |
| 78 | + * @return EPOrg |
| 79 | + */ |
| 80 | + public function getOrg( $fields = null ) { |
| 81 | + if ( $this->org === false ) { |
| 82 | + $this->org = EPOrg::selectRow( $fields, array( 'id' => $this->getField( 'org_id' ) ) ); |
| 83 | + } |
| 84 | + |
| 85 | + return $this->org; |
| 86 | + } |
| 87 | + |
| 88 | + /** |
64 | 89 | * Returns a list of courses in an array that can be fed to select inputs. |
65 | 90 | * |
66 | 91 | * @since 0.1 |
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php |
— | — | @@ -160,14 +160,14 @@ |
161 | 161 | // Special:Course |
162 | 162 | 'ep-course-title' => 'Course: $1', |
163 | 163 | 'ep-course-terms' => 'Terms', |
164 | | - 'ep-course-none' => 'There is no course with name "$1". See [[Special:Course|here]] for a list of courses.', |
| 164 | + 'ep-course-none' => 'There is no course with name "$1". See [[Special:Courses|here]] for a list of courses.', |
165 | 165 | 'ep-course-create' => 'There is no course with name "$1" yet, but you can create it.', |
166 | 166 | |
167 | 167 | // Special:Term |
168 | 168 | 'ep-term-title' => 'Term: $1', |
169 | 169 | 'ep-term-students' => 'Students', |
170 | | - 'ep-term-none' => 'There is no term with name "$1". See [[Special:Terms|here]] for a list of terms.', |
171 | | - 'ep-term-create' => 'There is no term with name "$1" yet, but you can create it.', |
| 170 | + 'ep-term-none' => 'There is no term with id "$1". See [[Special:Terms|here]] for a list of terms.', |
| 171 | + 'ep-term-create' => 'There is no term with id "$1", but you can create a new one.', |
172 | 172 | ); |
173 | 173 | |
174 | 174 | /** Message documentation (Message documentation) |