r106847 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106846‎ | r106847 | r106848 >
Date:19:52, 20 December 2011
Author:jeroendedauw
Status:deferred
Tags:educationprogram 
Comment:
work on special:terms
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.i18n.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPCourse.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPOrg.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPTermPager.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialTerms.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/specials/SpecialTerms.php
@@ -59,15 +59,13 @@
6060 protected function displayPage() {
6161 $user = $this->getUser();
6262
63 - if ( $user->isAllowed( 'epadmin' ) ) {
64 - $this->displayAddNewControl();
 63+ $courses = EPCourse::getEditableCourses( $this->getUser() );
 64+
 65+ if ( count( $courses ) > 0 ) {
 66+ $this->displayAddNewControl( $courses );
6567 }
6668 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' );
7270 }
7371
7472 $pager = new EPTermPager( $this->getContext() );
@@ -90,8 +88,10 @@
9189 * Displays a small form to add a new institution.
9290 *
9391 * @since 0.1
 92+ *
 93+ * @param array $courses
9494 */
95 - protected function displayAddNewControl() {
 95+ protected function displayAddNewControl( array $courses ) {
9696 $out = $this->getOutput();
9797
9898 $out->addHTML( Html::openElement(
@@ -106,12 +106,14 @@
107107
108108 $out->addHTML( '<legend>' . wfMsgHtml( 'ep-terms-addnew' ) . '</legend>' );
109109
 110+ $out = $this->getOutput();
 111+
110112 $out->addHTML( Html::element( 'p', array(), wfMsg( 'ep-terms-namedoc' ) ) );
111113
112114 $out->addHTML( Html::element( 'label', array( 'for' => 'newcourse' ), wfMsg( 'ep-terms-newcourse' ) ) );
113115
114116 $select = new XmlSelect( 'newcourse', 'newcourse' );
115 - $select->addOptions( EPCourse::getCoursesForAdmin( $this->getUser() ) );
 117+ $select->addOptions( EPCourse::getCourseOptions( $courses ) );
116118 $out->addHTML( $select->getHTML() );
117119
118120 $out->addHTML( Xml::inputLabel( wfMsg( 'ep-terms-newyear' ), 'newyear', 'newyear' ) );
@@ -123,7 +125,7 @@
124126 ) );
125127
126128 $out->addHTML( Html::hidden( 'newEditToken', $this->getUser()->editToken() ) );
127 -
 129+
128130 $out->addHTML( '</fieldset></form>' );
129131 }
130132
Index: trunk/extensions/EducationProgram/includes/EPTermPager.php
@@ -54,9 +54,9 @@
5555
5656 /**
5757 * (non-PHPdoc)
58 - * @see TablePager::formatValue()
 58+ * @see EPPager::getFormattedValue()
5959 */
60 - public function formatValue( $name, $value ) {
 60+ public function getFormattedValue( $name, $value ) {
6161 switch ( $name ) {
6262 case '': // TODO
6363 $value = $value;
Index: trunk/extensions/EducationProgram/includes/EPOrg.php
@@ -38,6 +38,15 @@
3939 );
4040 }
4141
 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+ */
4251 public static function getOrgOptions( array /* EPOrg */ $orgs ) {
4352 $options = array();
4453
Index: trunk/extensions/EducationProgram/includes/EPCourse.php
@@ -32,15 +32,35 @@
3333 }
3434
3535 /**
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.
3737 *
3838 * @since 0.1
3939 *
40 - * @param User|int $user User object or user id
 40+ * @param array $orgs
4141 *
 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+ *
4262 * @return array of EPCourse
4363 */
44 - public static function getCoursesForAdmin( $user ) {
 64+ public static function getEditableCourses( $user, array $fields = null ) {
4565 static $cache = array();
4666
4767 if ( is_int( $user ) ) {
@@ -58,13 +78,13 @@
5979 $courses = array();
6080
6181 if ( $user->isAllowed( 'epadmin' ) ) {
62 - $courses = self::select();
 82+ $courses = self::select( $fields );
6383 }
6484 elseif ( $user->isAllowed( 'epmentor' ) ) {
6585 $mentor = EPMentor::select( array( 'user_id' => $user->getId() ) );
6686
6787 if ( $mentor !== false ) {
68 - $courses = $mentor->getCourses();
 88+ $courses = $mentor->getCourses( $fields );
6989 }
7090 }
7191
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php
@@ -86,6 +86,7 @@
8787 'ep-terms-newyear' => 'Term year:',
8888 'ep-terms-newcourse' => 'Term course:',
8989 '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.',
9091
9192 // Pager
9293 'ep-pager-showonly' => 'Show only items with',

Status & tagging log