Index: trunk/extensions/EducationProgram/includes/EPStudent.php |
— | — | @@ -26,5 +26,19 @@ |
27 | 27 | 'user_id' => 'id', |
28 | 28 | ); |
29 | 29 | } |
30 | | - |
| 30 | + |
| 31 | + /** |
| 32 | + * Get the student object of a user, or false if there is none. |
| 33 | + * |
| 34 | + * @since 0.1 |
| 35 | + * |
| 36 | + * @param User $user |
| 37 | + * @param string|array|null $fields |
| 38 | + * |
| 39 | + * @return EPStudent|false |
| 40 | + */ |
| 41 | + public static function newFromUser( User $user, $fields = null ) { |
| 42 | + return self::selectRow( $fields, array( 'user_id' => $user->getId() ) ); |
| 43 | + } |
| 44 | + |
31 | 45 | } |
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php |
— | — | @@ -168,6 +168,12 @@ |
169 | 169 | 'ep-term-students' => 'Students', |
170 | 170 | 'ep-term-none' => 'There is no term with id "$1". See [[Special:Terms|here]] for a list of terms.', |
171 | 171 | 'ep-term-create' => 'There is no term with id "$1", but you can create a new one.', |
| 172 | + |
| 173 | + // Navigation links |
| 174 | + 'ep-nav-orgs' => 'Institution list', |
| 175 | + 'ep-nav-courses' => 'Courses list', |
| 176 | + 'ep-nav-terms' => 'Terms list', |
| 177 | + 'ep-nav-mycourses' => 'My courses', |
172 | 178 | ); |
173 | 179 | |
174 | 180 | /** Message documentation (Message documentation) |
Index: trunk/extensions/EducationProgram/specials/SpecialTerm.php |
— | — | @@ -41,6 +41,8 @@ |
42 | 42 | else { |
43 | 43 | $out->setPageTitle( wfMsgExt( 'ep-term-title', 'parsemag', $this->subPage ) ); |
44 | 44 | |
| 45 | + $this->displayNavigation(); |
| 46 | + |
45 | 47 | $term = EPTerm::selectRow( null, array( 'id' => $this->subPage ) ); |
46 | 48 | |
47 | 49 | if ( $term === false ) { |
Index: trunk/extensions/EducationProgram/specials/SpecialInstitution.php |
— | — | @@ -41,6 +41,8 @@ |
42 | 42 | else { |
43 | 43 | $out->setPageTitle( wfMsgExt( 'ep-institution-title', 'parsemag', $this->subPage ) ); |
44 | 44 | |
| 45 | + $this->displayNavigation(); |
| 46 | + |
45 | 47 | $org = EPOrg::selectRow( null, array( 'name' => $this->subPage ) ); |
46 | 48 | |
47 | 49 | if ( $org === false ) { |
Index: trunk/extensions/EducationProgram/specials/SpecialTerms.php |
— | — | @@ -34,6 +34,7 @@ |
35 | 35 | parent::execute( $subPage ); |
36 | 36 | |
37 | 37 | if ( $this->subPage === '' ) { |
| 38 | + $this->displayNavigation(); |
38 | 39 | EPTerm::displayAddNewRegion( $this->getContext() ); |
39 | 40 | EPTerm::displayPager( $this->getContext() ); |
40 | 41 | } |
— | — | @@ -41,40 +42,5 @@ |
42 | 43 | $this->getOutput()->redirect( SpecialPage::getTitleFor( 'Term', $this->subPage )->getLocalURL() ); |
43 | 44 | } |
44 | 45 | } |
45 | | - |
46 | | - /** |
47 | | - * Display all the stuff that should be on the page. |
48 | | - * |
49 | | - * @since 0.1 |
50 | | - */ |
51 | | - protected function displayPage() { |
52 | | - $user = $this->getUser(); |
53 | | - |
54 | | - $courses = EPCourse::getEditableCourses( $this->getUser() ); |
55 | | - |
56 | | - if ( count( $courses ) > 0 ) { |
57 | | - $this->displayAddNewControl( $courses ); |
58 | | - } |
59 | | - elseif ( $user->isAllowed( 'epmentor' ) ) { |
60 | | - $this->getOutput()->addWikiMsg( 'ep-terms-addcoursefirst' ); |
61 | | - } |
62 | | - |
63 | | - $pager = new EPTermPager( $this->getContext() ); |
64 | | - |
65 | | - if ( $pager->getNumRows() ) { |
66 | | - $this->getOutput()->addHTML( |
67 | | - $pager->getFilterControl() . |
68 | | - $pager->getNavigationBar() . |
69 | | - $pager->getBody() . |
70 | | - $pager->getNavigationBar() |
71 | | - ); |
72 | | - } |
73 | | - else { |
74 | | - $this->getOutput()->addHTML( $pager->getFilterControl( true ) ); |
75 | | - $this->getOutput()->addWikiMsg( 'ep-terms-noresults' ); |
76 | | - } |
77 | | - } |
78 | 46 | |
79 | | - |
80 | | - |
81 | 47 | } |
Index: trunk/extensions/EducationProgram/specials/SpecialInstitutions.php |
— | — | @@ -34,6 +34,7 @@ |
35 | 35 | parent::execute( $subPage ); |
36 | 36 | |
37 | 37 | if ( $this->subPage === '' ) { |
| 38 | + $this->displayNavigation(); |
38 | 39 | EPOrg::displayAddNewControl( $this->getContext() ); |
39 | 40 | EPOrg::displayPager( $this->getContext() ); |
40 | 41 | } |
Index: trunk/extensions/EducationProgram/specials/SpecialCourse.php |
— | — | @@ -41,6 +41,8 @@ |
42 | 42 | else { |
43 | 43 | $out->setPageTitle( wfMsgExt( 'ep-course-title', 'parsemag', $this->subPage ) ); |
44 | 44 | |
| 45 | + $this->displayNavigation(); |
| 46 | + |
45 | 47 | $course = EPCourse::selectRow( null, array( 'name' => $this->subPage ) ); |
46 | 48 | |
47 | 49 | if ( $course === false ) { |
Index: trunk/extensions/EducationProgram/specials/SpecialEPPage.php |
— | — | @@ -120,5 +120,51 @@ |
121 | 121 | public function getLanguage() { |
122 | 122 | return method_exists( get_parent_class(), 'getLanguage' ) ? parent::getLanguage() : $this->getLang(); |
123 | 123 | } |
| 124 | + |
| 125 | + /** |
| 126 | + * Adds a navigation menu with the provided links. |
| 127 | + * Links should be provided in an array with: |
| 128 | + * label => Title (object) |
| 129 | + * |
| 130 | + * @since 0.1 |
| 131 | + * |
| 132 | + * @param array $links |
| 133 | + */ |
| 134 | + protected function displayNavigation( array $items = array() ) { |
| 135 | + $links = array(); |
| 136 | + $items = array_merge( $this->getDefaultNavigationItems(), $items ); |
| 137 | + |
| 138 | + foreach ( $items as $label => $target ) { |
| 139 | + $links[] = Linker::linkKnown( |
| 140 | + $target, |
| 141 | + htmlspecialchars( $label ) |
| 142 | + ); |
| 143 | + } |
| 144 | + |
| 145 | + $this->getOutput()->addHTML( |
| 146 | + Html::rawElement( 'p', array(), $this->getLang()->pipeList( $links ) ) |
| 147 | + ); |
| 148 | + } |
| 149 | + |
| 150 | + /** |
| 151 | + * Returns the default nav items for @see displayNavigation. |
| 152 | + * |
| 153 | + * @since 0.1 |
| 154 | + * |
| 155 | + * @return array |
| 156 | + */ |
| 157 | + protected function getDefaultNavigationItems() { |
| 158 | + $items = array( |
| 159 | + wfMsg( 'ep-nav-orgs' ) => SpecialPage::getTitleFor( 'Institutions' ), |
| 160 | + wfMsg( 'ep-nav-courses' ) => SpecialPage::getTitleFor( 'Courses' ), |
| 161 | + wfMsg( 'ep-nav-terms' ) => SpecialPage::getTitleFor( 'Terms' ), |
| 162 | + ); |
| 163 | + |
| 164 | + if ( $this->getUser()->isAllowed( 'epmentor' ) || EPStudent::has( array( 'user_id' => $this->getUser()->getId() ) ) ) { |
| 165 | + $items[wfMsg( 'ep-nav-mycourses' )] = SpecialPage::getTitleFor( 'MyCourses' ); |
| 166 | + } |
| 167 | + |
| 168 | + return $items; |
| 169 | + } |
124 | 170 | |
125 | 171 | } |
Index: trunk/extensions/EducationProgram/specials/SpecialCourses.php |
— | — | @@ -34,6 +34,7 @@ |
35 | 35 | parent::execute( $subPage ); |
36 | 36 | |
37 | 37 | if ( $this->subPage === '' ) { |
| 38 | + $this->displayNavigation(); |
38 | 39 | EPCourse::displayAddNewRegion( $this->getContext() ); |
39 | 40 | EPCourse::displayPager( $this->getContext() ); |
40 | 41 | } |