Index: trunk/extensions/EducationProgram/specials/SpecialEnroll.php |
— | — | @@ -231,7 +231,7 @@ |
232 | 232 | $hadStudent = $student->hasIdField(); |
233 | 233 | |
234 | 234 | $fields = array( |
235 | | - 'active_enroll' => 1 |
| 235 | + 'active_enroll' => true |
236 | 236 | ); |
237 | 237 | |
238 | 238 | if ( !$hadStudent ) { |
Index: trunk/extensions/EducationProgram/includes/EPOrgs.php |
— | — | @@ -104,7 +104,6 @@ |
105 | 105 | ); |
106 | 106 | } |
107 | 107 | |
108 | | - |
109 | 108 | /** |
110 | 109 | * Returns a list of orgs in an array that can be fed to select inputs. |
111 | 110 | * |
Index: trunk/extensions/EducationProgram/includes/EPRoleObject.php |
— | — | @@ -200,37 +200,6 @@ |
201 | 201 | } |
202 | 202 | |
203 | 203 | /** |
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 | | - /** |
235 | 204 | * Returns if the student has any course matching the provided conditions. |
236 | 205 | * |
237 | 206 | * @since 0.1 |
— | — | @@ -240,6 +209,7 @@ |
241 | 210 | * @return boolean |
242 | 211 | */ |
243 | 212 | public function hasCourse( array $conditions = array() ) { |
| 213 | + // TODO: make more efficient |
244 | 214 | return count( $this->getCourses( 'id', $conditions ) ) > 0; |
245 | 215 | } |
246 | 216 | |
Index: trunk/extensions/EducationProgram/includes/EPStudentPager.php |
— | — | @@ -85,7 +85,7 @@ |
86 | 86 | function( EPCourse $course ) { |
87 | 87 | return $course->getLink(); |
88 | 88 | }, |
89 | | - $this->currentObject->getCoursesWithState( 'current', 'name' ) |
| 89 | + $this->currentObject->getCourses( 'name', EPCourses::getStatusConds( 'current' ) ) |
90 | 90 | ) ); |
91 | 91 | break; |
92 | 92 | } |
Index: trunk/extensions/EducationProgram/includes/EPStudents.php |
— | — | @@ -60,5 +60,18 @@ |
61 | 61 | 'active_enroll' => 'bool', |
62 | 62 | ); |
63 | 63 | } |
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 | + |
65 | 78 | } |
Index: trunk/extensions/EducationProgram/includes/EPOAPager.php |
— | — | @@ -114,7 +114,7 @@ |
115 | 115 | function( EPCourse $course ) { |
116 | 116 | return $course->getLink(); |
117 | 117 | }, |
118 | | - $oa->getCoursesWithState( 'current', 'name' ) |
| 118 | + $oa->getCourses( 'name', EPCourses::getStatusConds( 'current' ) ) |
119 | 119 | ) ); |
120 | 120 | break; |
121 | 121 | } |
Index: trunk/extensions/EducationProgram/includes/EPCourses.php |
— | — | @@ -147,4 +147,32 @@ |
148 | 148 | return EP_NS_COURSE; |
149 | 149 | } |
150 | 150 | |
| 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 | + |
151 | 179 | } |
Index: trunk/extensions/EducationProgram/includes/EPStudent.php |
— | — | @@ -46,5 +46,30 @@ |
47 | 47 | public function getRoleName() { |
48 | 48 | return 'student'; |
49 | 49 | } |
| 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 | + } |
50 | 62 | |
| 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 | + |
51 | 76 | } |
Index: trunk/extensions/EducationProgram/api/ApiRefreshEducation.php |
— | — | @@ -24,6 +24,7 @@ |
25 | 25 | protected static $typeMap = array( |
26 | 26 | 'org' => 'EPOrsg', |
27 | 27 | 'course' => 'EPCourses', |
| 28 | + 'student' => 'EPStudents', |
28 | 29 | ); |
29 | 30 | |
30 | 31 | public function execute() { |