Index: trunk/extensions/EducationProgram/specials/SpecialTerms.php |
— | — | @@ -59,15 +59,13 @@ |
60 | 60 | protected function displayPage() { |
61 | 61 | $user = $this->getUser(); |
62 | 62 | |
63 | | - if ( $user->isAllowed( 'epadmin' ) ) { |
64 | | - $this->displayAddNewControl(); |
| 63 | + $courses = EPCourse::getEditableCourses( $this->getUser() ); |
| 64 | + |
| 65 | + if ( count( $courses ) > 0 ) { |
| 66 | + $this->displayAddNewControl( $courses ); |
65 | 67 | } |
66 | 68 | elseif ( $user->isAllowed( 'epmentor' ) ) { |
67 | | - $mentor = EPMentor::select( array( 'user_id' => $user->getId() ) ); |
68 | | - |
69 | | - if ( $mentor !== false && count( $mentor->getOrgs() ) > 0 ) { |
70 | | - $this->displayAddNewControl(); |
71 | | - } |
| 69 | + $this->getOutput()->addWikiMsg( 'ep-terms-addcoursefirst' ); |
72 | 70 | } |
73 | 71 | |
74 | 72 | $pager = new EPTermPager( $this->getContext() ); |
— | — | @@ -90,8 +88,10 @@ |
91 | 89 | * Displays a small form to add a new institution. |
92 | 90 | * |
93 | 91 | * @since 0.1 |
| 92 | + * |
| 93 | + * @param array $courses |
94 | 94 | */ |
95 | | - protected function displayAddNewControl() { |
| 95 | + protected function displayAddNewControl( array $courses ) { |
96 | 96 | $out = $this->getOutput(); |
97 | 97 | |
98 | 98 | $out->addHTML( Html::openElement( |
— | — | @@ -106,12 +106,14 @@ |
107 | 107 | |
108 | 108 | $out->addHTML( '<legend>' . wfMsgHtml( 'ep-terms-addnew' ) . '</legend>' ); |
109 | 109 | |
| 110 | + $out = $this->getOutput(); |
| 111 | + |
110 | 112 | $out->addHTML( Html::element( 'p', array(), wfMsg( 'ep-terms-namedoc' ) ) ); |
111 | 113 | |
112 | 114 | $out->addHTML( Html::element( 'label', array( 'for' => 'newcourse' ), wfMsg( 'ep-terms-newcourse' ) ) ); |
113 | 115 | |
114 | 116 | $select = new XmlSelect( 'newcourse', 'newcourse' ); |
115 | | - $select->addOptions( EPCourse::getCoursesForAdmin( $this->getUser() ) ); |
| 117 | + $select->addOptions( EPCourse::getCourseOptions( $courses ) ); |
116 | 118 | $out->addHTML( $select->getHTML() ); |
117 | 119 | |
118 | 120 | $out->addHTML( Xml::inputLabel( wfMsg( 'ep-terms-newyear' ), 'newyear', 'newyear' ) ); |
— | — | @@ -123,7 +125,7 @@ |
124 | 126 | ) ); |
125 | 127 | |
126 | 128 | $out->addHTML( Html::hidden( 'newEditToken', $this->getUser()->editToken() ) ); |
127 | | - |
| 129 | + |
128 | 130 | $out->addHTML( '</fieldset></form>' ); |
129 | 131 | } |
130 | 132 | |
Index: trunk/extensions/EducationProgram/includes/EPTermPager.php |
— | — | @@ -54,9 +54,9 @@ |
55 | 55 | |
56 | 56 | /** |
57 | 57 | * (non-PHPdoc) |
58 | | - * @see TablePager::formatValue() |
| 58 | + * @see EPPager::getFormattedValue() |
59 | 59 | */ |
60 | | - public function formatValue( $name, $value ) { |
| 60 | + public function getFormattedValue( $name, $value ) { |
61 | 61 | switch ( $name ) { |
62 | 62 | case '': // TODO |
63 | 63 | $value = $value; |
Index: trunk/extensions/EducationProgram/includes/EPOrg.php |
— | — | @@ -38,6 +38,15 @@ |
39 | 39 | ); |
40 | 40 | } |
41 | 41 | |
| 42 | + /** |
| 43 | + * Returns a list of orgs in an array that can be fed to select inputs. |
| 44 | + * |
| 45 | + * @since 0.1 |
| 46 | + * |
| 47 | + * @param array $orgs |
| 48 | + * |
| 49 | + * @return array |
| 50 | + */ |
42 | 51 | public static function getOrgOptions( array /* EPOrg */ $orgs ) { |
43 | 52 | $options = array(); |
44 | 53 | |
Index: trunk/extensions/EducationProgram/includes/EPCourse.php |
— | — | @@ -32,15 +32,35 @@ |
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
36 | | - * Returns a lift of courses that can be administered by the provided user. |
| 36 | + * Returns a list of courses in an array that can be fed to select inputs. |
37 | 37 | * |
38 | 38 | * @since 0.1 |
39 | 39 | * |
40 | | - * @param User|int $user User object or user id |
| 40 | + * @param array $orgs |
41 | 41 | * |
| 42 | + * @return array |
| 43 | + */ |
| 44 | + public static function getCourseOptions( array /* EPCourse */ $courses ) { |
| 45 | + $options = array(); |
| 46 | + |
| 47 | + foreach ( $courses as /* EPCourse */ $course ) { |
| 48 | + $options[$course->getField( 'name' )] = $course->getId(); |
| 49 | + } |
| 50 | + |
| 51 | + return $options; |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * Returns the list of orgs that the specified user can edit. |
| 56 | + * |
| 57 | + * @since 0.1 |
| 58 | + * |
| 59 | + * @param User|int $user |
| 60 | + * @param array|null $fields |
| 61 | + * |
42 | 62 | * @return array of EPCourse |
43 | 63 | */ |
44 | | - public static function getCoursesForAdmin( $user ) { |
| 64 | + public static function getEditableCourses( $user, array $fields = null ) { |
45 | 65 | static $cache = array(); |
46 | 66 | |
47 | 67 | if ( is_int( $user ) ) { |
— | — | @@ -58,13 +78,13 @@ |
59 | 79 | $courses = array(); |
60 | 80 | |
61 | 81 | if ( $user->isAllowed( 'epadmin' ) ) { |
62 | | - $courses = self::select(); |
| 82 | + $courses = self::select( $fields ); |
63 | 83 | } |
64 | 84 | elseif ( $user->isAllowed( 'epmentor' ) ) { |
65 | 85 | $mentor = EPMentor::select( array( 'user_id' => $user->getId() ) ); |
66 | 86 | |
67 | 87 | if ( $mentor !== false ) { |
68 | | - $courses = $mentor->getCourses(); |
| 88 | + $courses = $mentor->getCourses( $fields ); |
69 | 89 | } |
70 | 90 | } |
71 | 91 | |
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php |
— | — | @@ -86,6 +86,7 @@ |
87 | 87 | 'ep-terms-newyear' => 'Term year:', |
88 | 88 | 'ep-terms-newcourse' => 'Term course:', |
89 | 89 | 'ep-terms-add' => 'Add term', |
| 90 | + 'ep-terms-addcoursefirst' => 'The institutions you are a mentor for do not have any courses associated with them. You need to [[Special:Courses|add a course]] before you can create any terms.', |
90 | 91 | |
91 | 92 | // Pager |
92 | 93 | 'ep-pager-showonly' => 'Show only items with', |