Index: trunk/extensions/EducationProgram/includes/EPStudentPager.php |
— | — | @@ -14,6 +14,25 @@ |
15 | 15 | class EPStudentPager extends EPPager { |
16 | 16 | |
17 | 17 | /** |
| 18 | + * List of user ids mapped to user names and real names, set in doBatchLookups. |
| 19 | + * The real names will just hold the user name when no real name is set. |
| 20 | + * user id => array( user name, real name ) |
| 21 | + * |
| 22 | + * @since 0.1 |
| 23 | + * @var array |
| 24 | + */ |
| 25 | + protected $userNames = array(); |
| 26 | + |
| 27 | + /** |
| 28 | + * List of user ids with the names of their associated courses. |
| 29 | + * user id => array( course name 0, ... ) |
| 30 | + * |
| 31 | + * @since 0.1 |
| 32 | + * @var array |
| 33 | + */ |
| 34 | + protected $courseNames = array(); |
| 35 | + |
| 36 | + /** |
18 | 37 | * Constructor. |
19 | 38 | * |
20 | 39 | * @param IContextSource $context |
— | — | @@ -69,9 +88,13 @@ |
70 | 89 | ); |
71 | 90 | break; |
72 | 91 | case 'user_id': |
73 | | - $user = User::newFromId( $value ); |
74 | | - $realName = $user->getRealName() === '' ? false : $user->getRealName(); |
75 | | - $value = Linker::userLink( $value, $user->getName(), $realName ) . Linker::userToolLinks( $value, $user->getName() ); |
| 92 | + if ( array_key_exists( $value, $this->userNames ) ) { |
| 93 | + list( $userName, $realName ) = $this->userNames[$value]; |
| 94 | + $value = Linker::userLink( $value, $userName, $realName ) . Linker::userToolLinks( $value, $userName ); |
| 95 | + } |
| 96 | + else { |
| 97 | + wfWarn( 'User id not in $this->userNames in ' . __METHOD__ ); |
| 98 | + } |
76 | 99 | break; |
77 | 100 | case 'first_enroll': case 'last_active': |
78 | 101 | $value = htmlspecialchars( $this->getLanguage()->date( $value ) ); |
— | — | @@ -80,12 +103,16 @@ |
81 | 104 | $value = wfMsgHtml( $value === '1' ? 'epstudentpager-yes' : 'epstudentpager-no' ); |
82 | 105 | break; |
83 | 106 | case '_courses_current': |
84 | | - $value = $this->getLanguage()->pipeList( array_map( |
85 | | - function( EPCourse $course ) { |
86 | | - return $course->getLink(); |
87 | | - }, |
88 | | - $this->currentObject->getCourses( 'name', EPCourses::getStatusConds( 'current' ) ) |
89 | | - ) ); |
| 107 | + $userId = $this->currentObject->getField( 'user_id' ); |
| 108 | + |
| 109 | + if ( array_key_exists( $userId, $this->courseNames ) ) { |
| 110 | + $value = $this->getLanguage()->pipeList( array_map( |
| 111 | + function( $courseName ) { |
| 112 | + return EPCourses::singleton()->getLinkFor( $courseName ); |
| 113 | + }, |
| 114 | + $this->courseNames[$userId] |
| 115 | + ) ); |
| 116 | + } |
90 | 117 | break; |
91 | 118 | } |
92 | 119 | |
— | — | @@ -125,4 +152,57 @@ |
126 | 153 | return $fields; |
127 | 154 | } |
128 | 155 | |
| 156 | + /** |
| 157 | + * (non-PHPdoc) |
| 158 | + * @see IndexPager::doBatchLookups() |
| 159 | + */ |
| 160 | + protected function doBatchLookups() { |
| 161 | + $userIds = array(); |
| 162 | + $field = $this->table->getPrefixedField( 'user_id' ); |
| 163 | + |
| 164 | + while( $student = $this->mResult->fetchObject() ) { |
| 165 | + $userIds[] = (int)$student->$field; |
| 166 | + } |
| 167 | + |
| 168 | + if ( !empty( $userIds ) ) { |
| 169 | + $result = wfGetDB( DB_SLAVE )->select( |
| 170 | + 'user', |
| 171 | + array( 'user_id', 'user_name', 'user_real_name' ), |
| 172 | + array( 'user_id' => $userIds ), |
| 173 | + __METHOD__ |
| 174 | + ); |
| 175 | + |
| 176 | + while( $user = $result->fetchObject() ) { |
| 177 | + $real = $user->user_real_name === '' ? $user->user_name : $user->user_real_name; |
| 178 | + $this->userNames[$user->user_id] = array( $user->user_name, $real ); |
| 179 | + } |
| 180 | + |
| 181 | + $courseNameField = EPCourses::singleton()->getPrefixedField( 'name' ); |
| 182 | + |
| 183 | + $result = wfGetDB( DB_SLAVE )->select( |
| 184 | + array( 'ep_courses', 'ep_users_per_course' ), |
| 185 | + array( $courseNameField, 'upc_user_id' ), |
| 186 | + array_merge( array( |
| 187 | + 'upc_role' => EP_STUDENT, |
| 188 | + 'upc_user_id' => $userIds, |
| 189 | + ), EPCourses::getStatusConds( 'current', true ) ) , |
| 190 | + __METHOD__, |
| 191 | + array(), |
| 192 | + array( |
| 193 | + 'ep_users_per_course' => array( 'INNER JOIN', array( 'upc_course_id=course_id' ) ), |
| 194 | + ) |
| 195 | + ); |
| 196 | + |
| 197 | + while( $courseForUser = $result->fetchObject() ) { |
| 198 | + if ( !array_key_exists( $courseForUser->upc_user_id, $this->courseNames ) ) { |
| 199 | + $this->courseNames[$courseForUser->upc_user_id] = array(); |
| 200 | + } |
| 201 | + |
| 202 | + $this->courseNames[$courseForUser->upc_user_id][] = $courseForUser->$courseNameField; |
| 203 | + } |
| 204 | + } |
| 205 | + |
| 206 | + |
| 207 | + } |
| 208 | + |
129 | 209 | } |
Index: trunk/extensions/EducationProgram/includes/EPCoursePager.php |
— | — | @@ -87,6 +87,9 @@ |
88 | 88 | if ( array_key_exists( $value, $this->orgNames ) ) { |
89 | 89 | $value = EPOrgs::singleton()->getLinkFor( $this->orgNames[$value] ); |
90 | 90 | } |
| 91 | + else { |
| 92 | + wfWarn( 'Org id not in $this->orgNames in ' . __METHOD__ ); |
| 93 | + } |
91 | 94 | break; |
92 | 95 | case 'term': |
93 | 96 | $value = htmlspecialchars( $value ); |
Index: trunk/extensions/EducationProgram/includes/EPCourses.php |
— | — | @@ -172,8 +172,11 @@ |
173 | 173 | * @since 0.1 |
174 | 174 | * |
175 | 175 | * @param string $state |
| 176 | + * @param boolean $prefix |
| 177 | + * |
| 178 | + * @return array |
176 | 179 | */ |
177 | | - public static function getStatusConds( $state ) { |
| 180 | + public static function getStatusConds( $state, $prefix = false ) { |
178 | 181 | $now = wfGetDB( DB_SLAVE )->addQuotes( wfTimestampNow() ); |
179 | 182 | |
180 | 183 | $conditions = array(); |
— | — | @@ -190,6 +193,10 @@ |
191 | 194 | $conditions[] = 'start > ' . $now; |
192 | 195 | break; |
193 | 196 | } |
| 197 | + |
| 198 | + if ( $prefix ) { |
| 199 | + $conditions = self::singleton()->getPrefixedValues( $conditions ); |
| 200 | + } |
194 | 201 | |
195 | 202 | return $conditions; |
196 | 203 | } |