r112500 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112499‎ | r112500 | r112501 >
Date:18:53, 27 February 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
fixed issue with enbrollment status
Modified paths:
  • /trunk/extensions/EducationProgram/api/ApiRefreshEducation.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPCourses.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPOAPager.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPOrgs.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPRoleObject.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPStudent.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPStudentPager.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPStudents.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialEnroll.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/specials/SpecialEnroll.php
@@ -231,7 +231,7 @@
232232 $hadStudent = $student->hasIdField();
233233
234234 $fields = array(
235 - 'active_enroll' => 1
 235+ 'active_enroll' => true
236236 );
237237
238238 if ( !$hadStudent ) {
Index: trunk/extensions/EducationProgram/includes/EPOrgs.php
@@ -104,7 +104,6 @@
105105 );
106106 }
107107
108 -
109108 /**
110109 * Returns a list of orgs in an array that can be fed to select inputs.
111110 *
Index: trunk/extensions/EducationProgram/includes/EPRoleObject.php
@@ -200,37 +200,6 @@
201201 }
202202
203203 /**
204 - * Get the courses with a certain state.
205 - * States can be 'current', 'passed' and 'planned'
206 - *
207 - * @since 0.1
208 - *
209 - * @param string $state
210 - * @param array|null $fields
211 - * @param array $conditions
212 - *
213 - * @return array of EPCourse
214 - */
215 - public function getCoursesWithState( $state, $fields = null, array $conditions = array() ) {
216 - $now = wfGetDB( DB_SLAVE )->addQuotes( wfTimestampNow() );
217 -
218 - switch ( $state ) {
219 - case 'passed':
220 - $conditions[] = 'end < ' . $now;
221 - break;
222 - case 'planned':
223 - $conditions[] = 'start > ' . $now;
224 - break;
225 - case 'current':
226 - $conditions[] = 'end >= ' . $now;
227 - $conditions[] = 'start <= ' . $now;
228 - break;
229 - }
230 -
231 - return $this->getCourses( $fields, $conditions );
232 - }
233 -
234 - /**
235204 * Returns if the student has any course matching the provided conditions.
236205 *
237206 * @since 0.1
@@ -240,6 +209,7 @@
241210 * @return boolean
242211 */
243212 public function hasCourse( array $conditions = array() ) {
 213+ // TODO: make more efficient
244214 return count( $this->getCourses( 'id', $conditions ) ) > 0;
245215 }
246216
Index: trunk/extensions/EducationProgram/includes/EPStudentPager.php
@@ -85,7 +85,7 @@
8686 function( EPCourse $course ) {
8787 return $course->getLink();
8888 },
89 - $this->currentObject->getCoursesWithState( 'current', 'name' )
 89+ $this->currentObject->getCourses( 'name', EPCourses::getStatusConds( 'current' ) )
9090 ) );
9191 break;
9292 }
Index: trunk/extensions/EducationProgram/includes/EPStudents.php
@@ -60,5 +60,18 @@
6161 'active_enroll' => 'bool',
6262 );
6363 }
64 -
 64+
 65+ /**
 66+ * (non-PHPdoc)
 67+ * @see DBTable::getSummaryFields()
 68+ * @since 0.1
 69+ * @return array
 70+ */
 71+ public function getSummaryFields() {
 72+ return array(
 73+ 'last_active',
 74+ 'active_enroll',
 75+ );
 76+ }
 77+
6578 }
Index: trunk/extensions/EducationProgram/includes/EPOAPager.php
@@ -114,7 +114,7 @@
115115 function( EPCourse $course ) {
116116 return $course->getLink();
117117 },
118 - $oa->getCoursesWithState( 'current', 'name' )
 118+ $oa->getCourses( 'name', EPCourses::getStatusConds( 'current' ) )
119119 ) );
120120 break;
121121 }
Index: trunk/extensions/EducationProgram/includes/EPCourses.php
@@ -147,4 +147,32 @@
148148 return EP_NS_COURSE;
149149 }
150150
 151+ /**
 152+ * Get the conditions that will select courses with the provided state.
 153+ *
 154+ * @since 0.1
 155+ *
 156+ * @param string $state
 157+ */
 158+ public static function getStatusConds( $state ) {
 159+ $now = wfGetDB( DB_SLAVE )->addQuotes( wfTimestampNow() );
 160+
 161+ $conditions = array();
 162+
 163+ switch ( $state ) {
 164+ case 'current':
 165+ $conditions[] = 'end >= ' . $now;
 166+ $conditions[] = 'start <= ' . $now;
 167+ break;
 168+ case 'passed':
 169+ $conditions[] = 'end < ' . $now;
 170+ break;
 171+ case 'planned':
 172+ $conditions[] = 'start > ' . $now;
 173+ break;
 174+ }
 175+
 176+ return $conditions;
 177+ }
 178+
151179 }
Index: trunk/extensions/EducationProgram/includes/EPStudent.php
@@ -46,5 +46,30 @@
4747 public function getRoleName() {
4848 return 'student';
4949 }
 50+
 51+ /**
 52+ * (non-PHPdoc)
 53+ * @see DBDataObject::loadSummaryFields()
 54+ */
 55+ public function loadSummaryFields( $summaryFields = null ) {
 56+ if ( is_null( $summaryFields ) ) {
 57+ $summaryFields = array( 'last_active', 'active_enroll' );
 58+ }
 59+ else {
 60+ $summaryFields = (array)$summaryFields;
 61+ }
5062
 63+ $fields = array();
 64+
 65+ if ( in_array( 'active_enroll', $summaryFields ) ) {
 66+ $fields['active_enroll'] = $this->hasCourse( EPCourses::getStatusConds( 'current' ) );
 67+ }
 68+
 69+ if ( in_array( 'last_active', $summaryFields ) ) {
 70+ // TODO
 71+ }
 72+
 73+ $this->setFields( $fields );
 74+ }
 75+
5176 }
Index: trunk/extensions/EducationProgram/api/ApiRefreshEducation.php
@@ -24,6 +24,7 @@
2525 protected static $typeMap = array(
2626 'org' => 'EPOrsg',
2727 'course' => 'EPCourses',
 28+ 'student' => 'EPStudents',
2829 );
2930
3031 public function execute() {

Status & tagging log