Index: trunk/extensions/EducationProgram/specials/SpecialStudentActivity.php |
— | — | @@ -80,8 +80,8 @@ |
81 | 81 | protected $userNames = array(); |
82 | 82 | |
83 | 83 | /** |
84 | | - * List of user ids with the names of their associated courses. |
85 | | - * user id => array( course name 0, ... ) |
| 84 | + * List of course ids mapped to their title names. |
| 85 | + * course id => course name |
86 | 86 | * |
87 | 87 | * @since 0.1 |
88 | 88 | * @var array |
— | — | @@ -89,6 +89,24 @@ |
90 | 90 | protected $courseNames = array(); |
91 | 91 | |
92 | 92 | /** |
| 93 | + * List of course ids pointing to the id of their org. |
| 94 | + * course id => org id |
| 95 | + * |
| 96 | + * @since 0.1 |
| 97 | + * @var array |
| 98 | + */ |
| 99 | + protected $courseOrgs = array(); |
| 100 | + |
| 101 | + /** |
| 102 | + * List of org ids mapped to their title names. |
| 103 | + * org id => org name |
| 104 | + * |
| 105 | + * @since 0.1 |
| 106 | + * @var array |
| 107 | + */ |
| 108 | + protected $orgNames = array(); |
| 109 | + |
| 110 | + /** |
93 | 111 | * Constructor. |
94 | 112 | * |
95 | 113 | * @param IContextSource $context |
— | — | @@ -148,9 +166,36 @@ |
149 | 167 | wfWarn( 'User id not in $this->userNames in ' . __METHOD__ ); |
150 | 168 | } |
151 | 169 | break; |
152 | | - case 'first_enroll': case 'last_active': |
153 | | - $value = htmlspecialchars( $this->getLanguage()->date( $value ) ); |
154 | | - break; |
| 170 | + case 'last_active': |
| 171 | + $value = htmlspecialchars( $this->getLanguage()->date( $value ) ); |
| 172 | + break; |
| 173 | + case 'last_course': |
| 174 | + if ( array_key_exists( $value, $this->courseNames ) ) { |
| 175 | + $value = EPCourses::singleton()->getLinkFor( $this->courseNames[$value] ); |
| 176 | + } |
| 177 | + else { |
| 178 | + // TODO: enable |
| 179 | + //wfWarn( 'Course id not in $this->courseNames in ' . __METHOD__ ); |
| 180 | + } |
| 181 | + break; |
| 182 | + case 'org_id': |
| 183 | + $courseId = $this->currentObject->getField( 'last_course' ); |
| 184 | + |
| 185 | + if ( array_key_exists( $courseId, $this->courseOrgs ) ) { |
| 186 | + $orgId = $this->courseOrgs[$courseId]; |
| 187 | + |
| 188 | + if ( array_key_exists( $orgId, $this->orgNames ) ) { |
| 189 | + $value = EPOrgs::singleton()->getLinkFor( $this->orgNames[$orgId] ); |
| 190 | + } |
| 191 | + else { |
| 192 | + wfWarn( 'Org id not in $this->orgNames in ' . __METHOD__ ); |
| 193 | + } |
| 194 | + } |
| 195 | + else { |
| 196 | + // TODO: enable |
| 197 | + //wfWarn( 'Course id not in $this->courseOrgs in ' . __METHOD__ ); |
| 198 | + } |
| 199 | + break; |
155 | 200 | } |
156 | 201 | |
157 | 202 | return $value; |
— | — | @@ -201,10 +246,14 @@ |
202 | 247 | */ |
203 | 248 | protected function doBatchLookups() { |
204 | 249 | $userIds = array(); |
205 | | - $field = $this->table->getPrefixedField( 'user_id' ); |
| 250 | + $courseIds = array(); |
206 | 251 | |
| 252 | + $userField = $this->table->getPrefixedField( 'user_id' ); |
| 253 | + $courseField = $this->table->getPrefixedField( 'last_course' ); |
| 254 | + |
207 | 255 | while( $student = $this->mResult->fetchObject() ) { |
208 | | - $userIds[] = (int)$student->$field; |
| 256 | + $userIds[] = (int)$student->$userField; |
| 257 | + $courseIds[] = (int)$student->$courseField; |
209 | 258 | } |
210 | 259 | |
211 | 260 | if ( !empty( $userIds ) ) { |
— | — | @@ -219,10 +268,26 @@ |
220 | 269 | $real = $user->user_real_name === '' ? $user->user_name : $user->user_real_name; |
221 | 270 | $this->userNames[$user->user_id] = array( $user->user_name, $real ); |
222 | 271 | } |
| 272 | + } |
223 | 273 | |
224 | | - $courseNameField = EPCourses::singleton()->getPrefixedField( 'name' ); |
| 274 | + if ( !empty( $courseIds ) ) { |
| 275 | + $courses = EPCourses::singleton()->selectFields( |
| 276 | + array( 'id', 'name', 'org_id' ), |
| 277 | + array( 'id' => array_unique( $courseIds ) ) |
| 278 | + ); |
225 | 279 | |
226 | | - // TODO: $this->courseNames[] = |
| 280 | + $orgIds = array(); |
| 281 | + |
| 282 | + foreach ( $courses as $courseData ) { |
| 283 | + $this->courseNames[$courseData['id']] = $courseData['name']; |
| 284 | + $orgIds[] = $courseData['org_id']; |
| 285 | + $this->courseOrgs[$courseData['id']] = $courseData['org_id']; |
| 286 | + } |
| 287 | + |
| 288 | + $this->orgNames = EPOrgs::singleton()->selectFields( |
| 289 | + array( 'id', 'name' ), |
| 290 | + array( 'id' => array_unique( $orgIds ) ) |
| 291 | + ); |
227 | 292 | } |
228 | 293 | } |
229 | 294 | |