r107620 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107619‎ | r107620 | r107621 >
Date:02:47, 30 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/EPMentor.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPStudent.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialEnroll.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialMyCourses.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/specials/SpecialMyCourses.php
@@ -19,7 +19,7 @@
2020 * @since 0.1
2121 */
2222 public function __construct() {
23 - parent::__construct( 'MyCourses' );
 23+ parent::__construct( 'MyCourses', 'epstudent' );
2424 }
2525
2626 /**
@@ -32,9 +32,47 @@
3333 public function execute( $subPage ) {
3434 parent::execute( $subPage );
3535
 36+ if ( $this->getRequest()->getCheck( 'enrolled' ) ) {
 37+ EPStudent::setReadDb( DB_MASTER );
 38+ }
 39+
 40+ $student = EPStudent::newFromUser( $this->getUser() );
 41+ EPStudent::setReadDb( DB_SLAVE );
 42+
 43+ if ( $student === false ) {
 44+ $this->getOutput()->addWikiMsg( 'ep-mycourses-not-a-student' );
 45+ }
 46+ else {
 47+ if ( $this->subPage === '' ) {
 48+ $this->displayCourse( $student, $this->subPage );
 49+ }
 50+ else {
 51+ $this->displayCourses( $student );
 52+ }
 53+ }
 54+ }
 55+
 56+ protected function displayCourses( EPStudent $student ) {
3657 $out = $this->getOutput();
3758
38 - // TODO: AUTH
 59+ if ( $student->hasTerm() ) {
 60+ if ( $this->getRequest()->getCheck( 'enrolled' ) ) {
 61+ $this->showSuccess( wfMessage( 'ep-mycourses-enrolled', '', '' ) ); // TODO
 62+ }
 63+
 64+ $this->displayCourses( $student );
 65+ }
 66+ else {
 67+ $out->addWikiMsg( 'ep-mycourses-not-enrolled' );
 68+ }
3969 }
4070
 71+ protected function displayCourse( EPStudent $student, $courseName ) {
 72+ $course = EPCourse::selectRow( null, array( 'name' => $courseName ) );
 73+
 74+ if ( $student->hasTerm( array( ) ) ) {
 75+ // TODO
 76+ }
 77+ }
 78+
4179 }
Index: trunk/extensions/EducationProgram/specials/SpecialEnroll.php
@@ -208,7 +208,7 @@
209209 public function onSuccess() {
210210 $this->getOutput()->redirect(
211211 SpecialPage::getTitleFor( 'MyCourses' )->getLocalURL( array(
212 - 'enrolled' => 1
 212+ 'enrolled' => $this->term->getId()
213213 ) )
214214 );
215215 }
Index: trunk/extensions/EducationProgram/includes/EPMentor.php
@@ -57,9 +57,12 @@
5858 if ( is_null( $fields ) ) {
5959 $this->orgs = $orgs;
6060 }
 61+
 62+ return $orgs;
6163 }
62 -
63 - return $orgs;
 64+ else {
 65+ return $this->orgs;
 66+ }
6467 }
6568
6669 /**
@@ -140,7 +143,7 @@
141144 }
142145
143146 /**
144 - * Retruns if the mentor has any term matching the provided contitions.
 147+ * Retruns if the mentor has any term matching the provided conditions.
145148 *
146149 * @since 0.1
147150 *
Index: trunk/extensions/EducationProgram/includes/EPStudent.php
@@ -14,6 +14,14 @@
1515 class EPStudent extends EPDBObject {
1616
1717 /**
 18+ * Cached array of the linked EPTerm objects.
 19+ *
 20+ * @since 0.1
 21+ * @var array|false
 22+ */
 23+ protected $terms = false;
 24+
 25+ /**
1826 * @see parent::getFieldTypes
1927 *
2028 * @since 0.1
@@ -71,5 +79,72 @@
7280
7381 return $success;
7482 }
 83+
 84+ /**
 85+ * Returns the orgs this mentor is part of.
 86+ * Caches the result when no conditions are provided and all fields are selected.
 87+ *
 88+ * @since 0.1
 89+ *
 90+ * @param array|null $fields
 91+ * @param array $conditions
 92+ *
 93+ * @return array of EPTerm
 94+ */
 95+ public function getTerms( array $fields = null, array $conditions = array() ) {
 96+ if ( count( $conditions ) !== 0 ) {
 97+ return $this->doGetTerms( $fields, $conditions );
 98+ }
 99+
 100+ if ( $this->terms === false ) {
 101+ $terms = $this->doGetTerms( $fields, $conditions );
 102+
 103+ if ( is_null( $fields ) ) {
 104+ $this->terms = $terms;
 105+ }
 106+
 107+ return $terms;
 108+ }
 109+ else {
 110+ return $this->terms;
 111+ }
 112+ }
 113+
 114+ /**
 115+ * Returns the terms this student is enrolled in.
 116+ *
 117+ * @since 0.1
 118+ *
 119+ * @param array|null $fields
 120+ * @param array $conditions
 121+ *
 122+ * @return array of EPTerm
 123+ */
 124+ protected function doGetTerms( $fields, array $conditions ) {
 125+ $conditions = array_merge(
 126+ array( array( 'ep_students_per_term', 'student_id' ), $this->getId() ),
 127+ $conditions
 128+ );
 129+
 130+ return EPTerm::select(
 131+ $fields,
 132+ $conditions,
 133+ array(),
 134+ array( 'terms' => array( 'INNER JOIN', array( array( array( 'ep_students_per_term', 'term_id' ), array( 'terms', 'id' ) ) ) ) )
 135+ );
 136+ }
 137+
 138+ /**
 139+ * Retruns if the mentor has any term matching the provided conditions.
 140+ *
 141+ * @since 0.1
 142+ *
 143+ * @param array $conditions
 144+ *
 145+ * @return boolean
 146+ */
 147+ public function hasTerm( array $conditions = array() ) {
 148+ return count( $this->getTerms( 'id', $conditions ) ) > 0;
 149+ }
75150
76151 }
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php
@@ -205,7 +205,10 @@
206206 'ep-enroll-no-token' => 'You need to provide the token needed to enroll for this term.',
207207 'ep-enroll-invalid-token' => 'The token you provided is invalid.',
208208 'ep-enroll-legend' => 'Enroll',
209 -
 209+
 210+ // Special:MyCourses
 211+ 'ep-mycourses-enrolled' => 'You have successfully enrolled for $1 at $2',
 212+
210213 // Navigation links
211214 'ep-nav-orgs' => 'Institution list',
212215 'ep-nav-courses' => 'Courses list',

Status & tagging log