r110303 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110302‎ | r110303 | r110304 >
Date:16:46, 30 January 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
added instructor functionality again after I accidentally deleted it at some point
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.i18n.php (modified) (history)
  • /trunk/extensions/EducationProgram/actions/ViewCourseAction.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPCourse.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/actions/ViewCourseAction.php
@@ -79,7 +79,99 @@
8080 );
8181 }
8282
 83+ $stats['instructors'] = $this->getInstructorsList( $course ) . $this->getInstructorControls( $course );
 84+
8385 return $stats;
8486 }
 87+
 88+ /**
 89+ * Returns a list with the instructors for the provided course
 90+ * or a message indicating there are none.
 91+ *
 92+ * @since 0.1
 93+ *
 94+ * @param EPCourse $course
 95+ *
 96+ * @return string
 97+ */
 98+ protected function getInstructorsList( EPCourse $course ) {
 99+ $instructors = $course->getInstructors();
 100+
 101+ if ( count( $instructors ) > 0 ) {
 102+ $instList = array();
 103+
 104+ foreach ( $instructors as /* EPInstructor */ $instructor ) {
 105+ $instList[] = $instructor->getUserLink() . $instructor->getToolLinks( $this->getContext(), $course );
 106+ }
 107+
 108+ if ( false ) { // count( $instructors ) == 1
 109+ $html = $instList[0];
 110+ }
 111+ else {
 112+ $html = '<ul><li>' . implode( '</li><li>', $instList ) . '</li></ul>';
 113+ }
 114+ }
 115+ else {
 116+ $html = wfMsgHtml( 'ep-course-no-instructors' );
 117+ }
 118+
 119+ return Html::rawElement(
 120+ 'div',
 121+ array( 'id' => 'ep-course-instructors' ),
 122+ $html
 123+ );
 124+ }
 125+
 126+ /**
 127+ * Returns instructor addition controls for the course if the
 128+ * current user has the right permissions.
 129+ *
 130+ * @since 0.1
 131+ *
 132+ * @param EPCourse $course
 133+ *
 134+ * @return string
 135+ */
 136+ protected function getInstructorControls( EPCourse $course ) {
 137+ $user = $this->getUser();
 138+ $links = array();
 139+
 140+ if ( ( $user->isAllowed( 'ep-instructor' ) || $user->isAllowed( 'ep-beinstructor' ) )
 141+ && !in_array( $user->getId(), $course->getField( 'instructors' ) )
 142+ ) {
 143+ $links[] = Html::element(
 144+ 'a',
 145+ array(
 146+ 'href' => '#',
 147+ 'class' => 'ep-add-instructor',
 148+ 'data-courseid' => $course->getId(),
 149+ 'data-coursename' => $course->getField( 'name' ),
 150+ 'data-mode' => 'self',
 151+ ),
 152+ wfMsg( 'ep-course-become-instructor' )
 153+ );
 154+ }
 155+
 156+ if ( $user->isAllowed( 'ep-instructor' ) ) {
 157+ $links[] = Html::element(
 158+ 'a',
 159+ array(
 160+ 'href' => '#',
 161+ 'class' => 'ep-add-instructor',
 162+ 'data-courseid' => $course->getId(),
 163+ 'data-coursename' => $course->getField( 'name' ),
 164+ ),
 165+ wfMsg( 'ep-course-add-instructor' )
 166+ );
 167+ }
 168+
 169+ if ( count( $links ) > 0 ) {
 170+ $this->getOutput()->addModules( 'ep.instructor' );
 171+ return '<br />' . $this->getLanguage()->pipeList( $links );
 172+ }
 173+ else {
 174+ return '';
 175+ }
 176+ }
85177
86178 }
\ No newline at end of file
Index: trunk/extensions/EducationProgram/includes/EPCourse.php
@@ -89,6 +89,7 @@
9090 'end' => 'str', // TS_MW
9191 'description' => 'str',
9292 'token' => 'str',
 93+ 'instructors' => 'array',
9394 'online_ambs' => 'array',
9495 'campus_ambs' => 'array',
9596 'field' => 'str',
@@ -112,6 +113,7 @@
113114 'end' => wfTimestamp( TS_MW ),
114115 'description' => '',
115116 'token' => '',
 117+ 'instructors' => array(),
116118 'online_ambs' => array(),
117119 'campus_ambs' => array(),
118120 'field' => '',
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php
@@ -172,6 +172,9 @@
173173 'ep-courses-add' => 'Add course',
174174 'ep-courses-noorgs' => 'There are no institutions yet. You need to [[Special:Institutions|add an institution]] before you can create any courses.',
175175 'ep-courses-addorgfirst' => 'There are no institutions yet. You need to [[Special:Institutions|add an institution]] before you can create any courses.',
 176+ 'ep-course-no-instructors' => 'There are no instructors for this course yet.',
 177+ 'ep-course-become-instructor' => 'Become an instructor',
 178+ 'ep-course-add-instructor' => 'Add an instructor',
176179
177180 // Special:Students
178181 'ep-students-noresults' => 'There are no students to list.',
@@ -300,6 +303,7 @@
301304 'viewcourseaction-summary-students' => 'Student count',
302305 'viewcourseaction-summary-status' => 'Status',
303306 'viewcourseaction-summary-token' => 'Enrollment token',
 307+ 'viewcourseaction-summary-instructors' => 'Instructors',
304308 'ep-course-description' => 'description',
305309
306310 // Institution history

Status & tagging log