r107740 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107739‎ | r107740 | r107741 >
Date:21:17, 31 December 2011
Author:jeroendedauw
Status:deferred
Tags:educationprogram 
Comment:
work on student workflow
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.i18n.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPDBObject.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPStudent.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialCourse.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialEPPage.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialInstitution.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialMyCourses.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialTerm.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/specials/SpecialInstitution.php
@@ -90,6 +90,10 @@
9191 $countries = CountryNames::getNames( $this->getLang()->getCode() );
9292 $stats['country'] = $countries[$org->getField( 'country' )];
9393
 94+ foreach ( $stats as &$stat ) {
 95+ $stat = htmlspecialchars( $stat );
 96+ }
 97+
9498 return $stats;
9599 }
96100
Index: trunk/extensions/EducationProgram/specials/SpecialMyCourses.php
@@ -1,7 +1,9 @@
22 <?php
33
44 /**
5 - *
 5+ * Special page listing the courses that have at least one term in which the current user
 6+ * is or has been enrolled. When a subpage param is provided, and it's a valid course
 7+ * name, info for that course is shown.
68 *
79 * @since 0.1
810 *
@@ -27,7 +29,7 @@
2830 *
2931 * @since 0.1
3032 *
31 - * @param string $arg
 33+ * @param string $subPage
3234 */
3335 public function execute( $subPage ) {
3436 parent::execute( $subPage );
@@ -37,7 +39,6 @@
3840 }
3941
4042 $student = EPStudent::newFromUser( $this->getUser() );
41 - EPStudent::setReadDb( DB_SLAVE );
4243
4344 if ( $student === false ) {
4445 $this->getOutput()->addWikiMsg( 'ep-mycourses-not-a-student' );
@@ -52,6 +53,13 @@
5354 }
5455 }
5556
 57+ /**
 58+ *
 59+ *
 60+ * @since 0.1
 61+ *
 62+ * @param EPStudent $student
 63+ */
5664 protected function displayCourses( EPStudent $student ) {
5765 $out = $this->getOutput();
5866
@@ -64,15 +72,51 @@
6573 'ep-mycourses-enrolled',
6674 $term->getCourse()->getField( 'name' ),
6775 $term->getOrg()->getField( 'name' )
68 - ) ); // TODO
 76+ ) );
6977 }
7078 }
 79+
 80+ $currentCourses = $student->getCurrentCourses();
 81+ $passedCourses = $student->getPassedCourses();
 82+
 83+ if ( count( $currentCourses ) > 0 ) {
 84+ $out->addHTML( Html::element( 'h2', array(), wfMsg( 'ep-mycourses-current' ) ) );
 85+ $this->displayCoursesList( $currentCourses );
 86+ }
 87+
 88+ if ( count( $passedCourses ) > 0 ) {
 89+ $out->addHTML( Html::element( 'h2', array(), wfMsg( 'ep-mycourses-passed' ) ) );
 90+ $this->displayCoursesList( $passedCourses );
 91+ }
7192 }
7293 else {
7394 $out->addWikiMsg( 'ep-mycourses-not-enrolled' );
7495 }
7596 }
7697
 98+ /**
 99+ *
 100+ *
 101+ * @since 0.1
 102+ *
 103+ * @param array $courses
 104+ */
 105+ protected function displayCoursesList( array /* of EPCourse */ $courses ) {
 106+ $out = $this->getOutput();
 107+
 108+ foreach ( $courses as /* EPCourse */ $course ) {
 109+
 110+ }
 111+ }
 112+
 113+ /**
 114+ *
 115+ *
 116+ * @since 0.1
 117+ *
 118+ * @param EPStudent $student
 119+ * @param string $courseName
 120+ */
77121 protected function displayCourse( EPStudent $student, $courseName ) {
78122 $course = EPCourse::selectRow( null, array( 'name' => $courseName ) );
79123
Index: trunk/extensions/EducationProgram/specials/SpecialCourse.php
@@ -91,6 +91,10 @@
9292 $stats['name'] = $course->getField( 'name' );
9393 $stats['org'] = EPOrg::selectFieldsRow( 'name', array( 'id' => $course->getField( 'org_id' ) ) );
9494
 95+ foreach ( $stats as &$stat ) {
 96+ $stat = htmlspecialchars( $stat );
 97+ }
 98+
9599 return $stats;
96100 }
97101
Index: trunk/extensions/EducationProgram/specials/SpecialEPPage.php
@@ -199,7 +199,7 @@
200200 wfMsg( strtolower( get_called_class() ) . '-summary-' . $stat )
201201 ) );
202202
203 - $out->addHTML( Html::element(
 203+ $out->addHTML( Html::rawElement(
204204 'td',
205205 array( 'class' => 'ep-summary-value' ),
206206 $value
@@ -213,6 +213,7 @@
214214
215215 /**
216216 * Gets the summary data.
 217+ * Returned values must be escaped.
217218 *
218219 * @since 0.1
219220 *
Index: trunk/extensions/EducationProgram/specials/SpecialTerm.php
@@ -93,9 +93,16 @@
9494 $stats['year'] = $term->getField( 'year' ); // TODO: how to properly i18n this?
9595 $stats['start'] = $this->getLanguage()->timeanddate( $term->getField( 'start' ), true );
9696 $stats['end'] = $this->getLanguage()->timeanddate( $term->getField( 'end' ), true );
97 -
 97+
 98+ foreach ( $stats as &$stat ) {
 99+ $stat = htmlspecialchars( $stat );
 100+ }
 101+
98102 if ( $term->useCanManage( $this->getUser() ) ) {
99 - $stats['token'] = $term->getField( 'token' );
 103+ $stats['token'] = Linker::linkKnown(
 104+ SpecialPage::getTitleFor( 'Enroll', $term->getId() . '/' . $term->getField( 'token' ) ),
 105+ htmlspecialchars( $term->getField( 'token' ) )
 106+ );
100107 }
101108
102109 return $stats;
Index: trunk/extensions/EducationProgram/includes/EPStudent.php
@@ -22,6 +22,14 @@
2323 protected $terms = false;
2424
2525 /**
 26+ * Cached array of the EPCourse objects.
 27+ *
 28+ * @since 0.1
 29+ * @var array|false
 30+ */
 31+ protected $courses = false;
 32+
 33+ /**
2634 * @see parent::getFieldTypes
2735 *
2836 * @since 0.1
@@ -111,6 +119,46 @@
112120 }
113121
114122 /**
 123+ *
 124+ *
 125+ * @since 0.1
 126+ *
 127+ * @param null $fields
 128+ * @param array $conditions
 129+ * @param array $termConditions
 130+ *
 131+ * @return array
 132+ */
 133+ public function getCourses( $fields = null, array $conditions = array(), array $termConditions = array() ) {
 134+ $courseIds = array_reduce(
 135+ $this->getTerms( 'course_id', $termConditions ),
 136+ function( array $ids, EPTerm $term ) {
 137+ $ids[] = $term->getField( 'course_id' );
 138+ },
 139+ array() );
 140+
 141+ if ( count( $courseIds ) < 1 ) {
 142+ return array();
 143+ }
 144+
 145+ $conditions['id'] = $courseIds;
 146+
 147+ return EPCourse::select( $fields, array( 'id' => $conditions ) );
 148+ }
 149+
 150+ public function getCurrentCourses( $fields = null, array $conditions = array() ) {
 151+ return $this->getCourses( $fields, $conditions, array(
 152+ 'end >= ' . wfGetDB( DB_SLAVE )->addQuotes( wfTimestampNow() )
 153+ ) );
 154+ }
 155+
 156+ public function getPassedCourses( $fields = null, array $conditions = array() ) {
 157+ return $this->getCourses( $fields, $conditions, array(
 158+ 'end < ' . wfGetDB( DB_SLAVE )->addQuotes( wfTimestampNow() )
 159+ ) );
 160+ }
 161+
 162+ /**
115163 * Returns the terms this student is enrolled in.
116164 *
117165 * @since 0.1
Index: trunk/extensions/EducationProgram/includes/EPDBObject.php
@@ -593,8 +593,16 @@
594594
595595 foreach ( $values as $field => $value ) {
596596 if ( is_integer( $field ) ) {
597 - $field = $value[0];
598 - $value = $value[1];
 597+ if ( is_array( $value ) ) {
 598+ $field = $value[0];
 599+ $value = $value[1];
 600+ }
 601+ else {
 602+ $value = explode( ' ', $value, 2 );
 603+ $value[0] = static::getPrefixedField( $value[0] );
 604+ $prefixedValues[] = implode( ' ', $value );
 605+ continue;
 606+ }
599607 }
600608
601609 $prefixedValues[static::getPrefixedField( $field )] = $value;
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php
@@ -217,6 +217,8 @@
218218 // Special:MyCourses
219219 'ep-mycourses-enrolled' => 'You have successfully enrolled for $1 at $2.',
220220 'ep-mycourses-not-enrolled' => 'You are not enrolled in any course. A list of courses can be found [[Special:Courses|here]].',
 221+ 'ep-mycourses-current' => 'Active courses',
 222+ 'ep-mycourses-passed' => 'Passed courses',
221223
222224 // Navigation links
223225 'ep-nav-orgs' => 'Institution list',

Follow-up revisions

RevisionCommit summaryAuthorDate
r107742Follow up to r107740; docs++jeroendedauw21:30, 31 December 2011

Status & tagging log