Index: trunk/extensions/EducationProgram/EducationProgram.php |
— | — | @@ -161,6 +161,11 @@ |
162 | 162 | $egEPDBObjects['EPArticle'] = array( 'table' => 'ep_articles', 'prefix' => 'article_' ); |
163 | 163 | $egEPDBObjects[] = array( 'table' => 'ep_users_per_course', 'prefix' => 'upc_' ); |
164 | 164 | |
| 165 | +define( 'EP_STUDENT', 0 ); |
| 166 | +define( 'EP_INSTRUCTOR', 1 ); |
| 167 | +define( 'EP_OA', 2 ); |
| 168 | +define( 'EP_CA', 3 ); |
| 169 | + |
165 | 170 | // API |
166 | 171 | $wgAPIModules['deleteeducation'] = 'ApiDeleteEducation'; |
167 | 172 | $wgAPIModules['enlist'] = 'ApiEnlist'; |
Index: trunk/extensions/EducationProgram/sql/UpdateUserLinks.sql |
— | — | @@ -1,18 +0,0 @@ |
2 | | - |
3 | | -DROP TABLE IF EXISTS /*_*/ep_cas_per_course; |
4 | | -DROP TABLE IF EXISTS /*_*/ep_oas_per_course; |
5 | | -DROP TABLE IF EXISTS /*_*/ep_students_per_course; |
6 | | - |
7 | | -CREATE TABLE IF NOT EXISTS /*_*/ep_users_per_course ( |
8 | | - upc_user_id INT unsigned NOT NULL, -- Foreign key on ep_user.user_id |
9 | | - upc_course_id INT unsigned NOT NULL, -- Foreign key on ep_courses.course_id |
10 | | - upc_role TINYINT unsigned NOT NULL -- The role the user has for the course |
11 | | -) /*$wgDBTableOptions*/; |
12 | | - |
13 | | -CREATE UNIQUE INDEX /*i*/ep_users_per_course ON /*_*/ep_users_per_course (upc_user_id, upc_course_id, upc_role); |
14 | | -CREATE INDEX /*i*/ep_upc_course_id ON /*_*/ep_users_per_course (upc_course_id); |
15 | | -CREATE INDEX /*i*/ep_upc_role ON /*_*/ep_users_per_course (upc_role); |
\ No newline at end of file |
Index: trunk/extensions/EducationProgram/sql/AddRevIdentifier.sql |
— | — | @@ -1,6 +0,0 @@ |
2 | | - |
3 | | -ALTER TABLE /*_*/ep_revisions ADD COLUMN rev_object_identifier VARCHAR(255) NULL; |
4 | | -CREATE INDEX /*i*/ep_revision_object_identifier ON /*_*/ep_revisions (rev_object_identifier); |
\ No newline at end of file |
Index: trunk/extensions/EducationProgram/sql/EducationProgram.sql |
— | — | @@ -12,21 +12,22 @@ |
13 | 13 | |
14 | 14 | -- Summary fields - cahing data or computations on data stored elswhere |
15 | 15 | org_active TINYINT unsigned NOT NULL, -- If the org has any active courses |
16 | | - org_courses SMALLINT unsigned NOT NULL, -- Amount of courses |
17 | | - org_instructors SMALLINT unsigned NOT NULL, -- Amount of instructors |
18 | | - org_online_ambs INT unsigned NOT NULL, -- Amount of online ambassadors |
19 | | - org_campus_ambs INT unsigned NOT NULL, -- Amount of campus ambassadors |
20 | | - org_students INT unsigned NOT NULL -- Amount of students |
| 16 | + org_course_count SMALLINT unsigned NOT NULL, -- Amount of courses |
| 17 | + org_instructor_count SMALLINT unsigned NOT NULL, -- Amount of instructors |
| 18 | + org_oa_count INT unsigned NOT NULL, -- Amount of online ambassadors |
| 19 | + org_ca_count INT unsigned NOT NULL, -- Amount of campus ambassadors |
| 20 | + org_student_count INT unsigned NOT NULL -- Amount of students |
21 | 21 | ) /*$wgDBTableOptions*/; |
22 | 22 | |
23 | 23 | CREATE UNIQUE INDEX /*i*/ep_org_name ON /*_*/ep_orgs (org_name); |
24 | 24 | CREATE INDEX /*i*/ep_org_city ON /*_*/ep_orgs (org_city); |
25 | 25 | CREATE INDEX /*i*/ep_org_country ON /*_*/ep_orgs (org_country); |
26 | 26 | CREATE INDEX /*i*/ep_org_active ON /*_*/ep_orgs (org_active); |
27 | | -CREATE INDEX /*i*/ep_org_courses ON /*_*/ep_orgs (org_courses); |
28 | | -CREATE INDEX /*i*/ep_org_online_ambs ON /*_*/ep_orgs (org_online_ambs); |
29 | | -CREATE INDEX /*i*/ep_org_campus_ambs ON /*_*/ep_orgs (org_campus_ambs); |
30 | | -CREATE INDEX /*i*/ep_org_students ON /*_*/ep_orgs (org_students); |
| 27 | +CREATE INDEX /*i*/ep_org_course_count ON /*_*/ep_orgs (org_course_count); |
| 28 | +CREATE INDEX /*i*/ep_org_oa_count ON /*_*/ep_orgs (org_oa_count); |
| 29 | +CREATE INDEX /*i*/ep_org_ca_count ON /*_*/ep_orgs (org_ca_count); |
| 30 | +CREATE INDEX /*i*/ep_org_student_count ON /*_*/ep_orgs (org_student_count); |
| 31 | +CREATE INDEX /*i*/ep_org_instructor_count ON /*_*/ep_orgs (org_instructor_count); |
31 | 32 | |
32 | 33 | |
33 | 34 | |
— | — | @@ -35,11 +36,12 @@ |
36 | 37 | course_id INT unsigned NOT NULL auto_increment PRIMARY KEY, |
37 | 38 | |
38 | 39 | course_org_id INT unsigned NOT NULL, -- Foreign key on ep_orgs.org_id. Helper field, not strictly needed. |
39 | | - course_name VARCHAR(255) NOT NULL, -- Name of the course |
40 | | - course_mc VARCHAR(255) NOT NULL, -- Name of the master course |
| 40 | + course_name VARCHAR(255) NOT NULL, -- Title of the course. ie "Master in Angry Birds (2012 q1)" |
| 41 | + course_mc VARCHAR(255) NOT NULL, -- Name of the course. ie "Master in Angry Birds" |
41 | 42 | course_start varbinary(14) NOT NULL, -- Start time of the course |
42 | 43 | course_end varbinary(14) NOT NULL, -- End time of the course |
43 | 44 | course_description TEXT NOT NULL, -- Description of the course |
| 45 | + course_students BLOB NOT NULL, -- List of associated students (linking user.user_id) |
44 | 46 | course_online_ambs BLOB NOT NULL, -- List of associated online ambassadors (linking user.user_id) |
45 | 47 | course_campus_ambs BLOB NOT NULL, -- List of associated campus ambassadors (linking user.user_id) |
46 | 48 | course_instructors BLOB NOT NULL, -- List of associated instructors (linking user.user_id) |
— | — | @@ -50,7 +52,10 @@ |
51 | 53 | course_lang VARCHAR(10) NOT NULL, -- Language (code) |
52 | 54 | |
53 | 55 | -- Summary fields - cahing data or computations on data stored elswhere |
54 | | - course_students SMALLINT unsigned NOT NULL -- Amount of students |
| 56 | + course_instructor_count TINYINT unsigned NOT NULL, -- Amount of instructors |
| 57 | + course_oa_count SMALLINT unsigned NOT NULL, -- Amount of online ambassadors |
| 58 | + course_ca_count SMALLINT unsigned NOT NULL, -- Amount of campus ambassadors |
| 59 | + course_student_count SMALLINT unsigned NOT NULL -- Amount of students |
55 | 60 | ) /*$wgDBTableOptions*/; |
56 | 61 | |
57 | 62 | CREATE INDEX /*i*/ep_course_org_id ON /*_*/ep_courses (course_org_id); |
— | — | @@ -63,7 +68,10 @@ |
64 | 69 | CREATE INDEX /*i*/ep_course_level ON /*_*/ep_courses (course_level); |
65 | 70 | CREATE INDEX /*i*/ep_course_term ON /*_*/ep_courses (course_term); |
66 | 71 | CREATE INDEX /*i*/ep_course_lang ON /*_*/ep_courses (course_lang); |
67 | | -CREATE INDEX /*i*/ep_course_students ON /*_*/ep_courses (course_students); |
| 72 | +CREATE INDEX /*i*/ep_course_student_count ON /*_*/ep_courses (course_student_count); |
| 73 | +CREATE INDEX /*i*/ep_course_oa_count ON /*_*/ep_courses (course_oa_count); |
| 74 | +CREATE INDEX /*i*/ep_course_ca_count ON /*_*/ep_courses (course_ca_count); |
| 75 | +CREATE INDEX /*i*/ep_course_instructor_count ON /*_*/ep_courses (course_instructor_count); |
68 | 76 | |
69 | 77 | |
70 | 78 | |
Index: trunk/extensions/EducationProgram/includes/EPInstructor.php |
— | — | @@ -140,9 +140,7 @@ |
141 | 141 | } |
142 | 142 | |
143 | 143 | /** |
144 | | - * Not implemented as we do not need this, so no need for having it in the |
145 | | - * db in a way we can efficiently query this. If needed at some point, |
146 | | - * most stuff is in place already since the ambassador stuff is similar. |
| 144 | + * Returns the courses this campus ambassdor is associated with. |
147 | 145 | * |
148 | 146 | * @since 0.1 |
149 | 147 | * |
— | — | @@ -152,7 +150,12 @@ |
153 | 151 | * @return array of EPCourse |
154 | 152 | */ |
155 | 153 | protected function doGetCourses( $fields, array $conditions ) { |
156 | | - throw new MWException( 'doGetCourses is not implemented by EPInstructor' ); |
| 154 | + return EPUtils::getCoursesForUser( |
| 155 | + $fields, |
| 156 | + $this->getField( 'user_id' ), |
| 157 | + EP_INSTRUCTOR, |
| 158 | + $conditions |
| 159 | + ); |
157 | 160 | } |
158 | 161 | |
159 | 162 | } |
Index: trunk/extensions/EducationProgram/includes/EPCA.php |
— | — | @@ -75,27 +75,4 @@ |
76 | 76 | return 'campus'; |
77 | 77 | } |
78 | 78 | |
79 | | - /** |
80 | | - * Returns the courses this campus ambassdor is associated with. |
81 | | - * |
82 | | - * @since 0.1 |
83 | | - * |
84 | | - * @param string|array|null $fields |
85 | | - * @param array $conditions |
86 | | - * |
87 | | - * @return array of EPCourse |
88 | | - */ |
89 | | - protected function doGetCourses( $fields, array $conditions ) { |
90 | | - $conditions[] = array( array( 'ep_cas_per_course', 'user_id' ), $this->getField( 'user_id' ) ); |
91 | | - |
92 | | - return EPCourse::select( |
93 | | - $fields, |
94 | | - $conditions, |
95 | | - array(), |
96 | | - array( |
97 | | - 'ep_cas_per_course' => array( 'INNER JOIN', array( array( array( 'ep_cas_per_course', 'course_id' ), array( 'ep_courses', 'id' ) ) ) ), |
98 | | - ) |
99 | | - ); |
100 | | - } |
101 | | - |
102 | 79 | } |
Index: trunk/extensions/EducationProgram/includes/EPStudent.php |
— | — | @@ -66,28 +66,4 @@ |
67 | 67 | return 'student'; |
68 | 68 | } |
69 | 69 | |
70 | | - /** |
71 | | - * Returns the courses this student is enrolled in. |
72 | | - * |
73 | | - * @since 0.1 |
74 | | - * |
75 | | - * @param string|array|null $fields |
76 | | - * @param array $conditions |
77 | | - * |
78 | | - * @return array of EPCourse |
79 | | - */ |
80 | | - protected function doGetCourses( $fields, array $conditions ) { |
81 | | - $conditions[] = array( array( 'ep_students', 'id' ), $this->getId() ); |
82 | | - |
83 | | - return EPCourse::select( |
84 | | - $fields, |
85 | | - $conditions, |
86 | | - array(), |
87 | | - array( |
88 | | - 'ep_students_per_course' => array( 'INNER JOIN', array( array( array( 'ep_students_per_course', 'course_id' ), array( 'ep_courses', 'id' ) ) ) ), |
89 | | - 'ep_students' => array( 'INNER JOIN', array( array( array( 'ep_students_per_course', 'student_id' ), array( 'ep_students', 'id' ) ) ) ) |
90 | | - ) |
91 | | - ); |
92 | | - } |
93 | | - |
94 | 70 | } |
Index: trunk/extensions/EducationProgram/includes/EPOrg.php |
— | — | @@ -85,7 +85,7 @@ |
86 | 86 | */ |
87 | 87 | public function loadSummaryFields( $summaryFields = null ) { |
88 | 88 | if ( is_null( $summaryFields ) ) { |
89 | | - $summaryFields = array( 'courses', 'students', 'active', 'instructors', 'oas', 'cas' ); |
| 89 | + $summaryFields = array( 'courses', 'active', 'student_count', 'instructor_count', 'oa_count', 'ca_count' ); |
90 | 90 | } |
91 | 91 | else { |
92 | 92 | $summaryFields = (array)$summaryFields; |
— | — | @@ -99,25 +99,8 @@ |
100 | 100 | |
101 | 101 | $dbr = wfGetDB( DB_SLAVE ); |
102 | 102 | |
103 | | - if ( in_array( 'students', $summaryFields ) ) { |
104 | | - $courseIds = EPCourse::selectFields( 'id', array( 'org_id' => $this->getId() ) ); |
105 | | - |
106 | | - if ( count( $courseIds ) > 0 ) { |
107 | | - $fields['students'] = $dbr->select( |
108 | | - 'ep_students_per_course', |
109 | | - 'COUNT(*) AS rowcount', |
110 | | - array( 'spc_course_id' => $courseIds ) |
111 | | - ); |
112 | | - |
113 | | - $fields['students'] = $fields['students']->fetchObject()->rowcount; |
114 | | - } |
115 | | - else { |
116 | | - $fields['students'] = 0; |
117 | | - } |
118 | | - } |
119 | | - |
120 | 103 | if ( in_array( 'active', $summaryFields ) ) { |
121 | | - $now = wfGetDB( DB_SLAVE )->addQuotes( wfTimestampNow() ); |
| 104 | + $now = $dbr->addQuotes( wfTimestampNow() ); |
122 | 105 | |
123 | 106 | $fields['active'] = EPCourse::has( array( |
124 | 107 | 'org_id' => $this->getId(), |
— | — | @@ -126,29 +109,15 @@ |
127 | 110 | ) ); |
128 | 111 | } |
129 | 112 | |
130 | | - $courseFields = array(); |
131 | | - |
132 | | - $upInstructors = in_array( 'instructors', $summaryFields ); |
133 | | - $upOas = in_array( 'oas', $summaryFields ); |
134 | | - |
135 | | - if ( $upInstructors ) { |
136 | | - $courseFields[] = 'instructors'; |
137 | | - $fields['instructors'] = 0; |
| 113 | + foreach ( array( 'student_count', 'instructor_count', 'oa_count', 'ca_count' ) as $field ) { |
| 114 | + $fields[$field] = EPCourse::rawSelect( |
| 115 | + 'SUM(' . $dbr->addQuotes( $field ) . ') AS sum', |
| 116 | + EPCourse::getPrefixedValues( array( |
| 117 | + 'org_id' => $this->getId() |
| 118 | + ) ) |
| 119 | + )->fetchObject()->sum; |
138 | 120 | } |
139 | 121 | |
140 | | - if ( $upOas ) { |
141 | | - $courseFields[] = 'online_ambs'; |
142 | | - $fields['online_ambs'] = 0; |
143 | | - } |
144 | | - |
145 | | - if ( count( $courseFields ) > 0 ) { |
146 | | - $courses = EPCourse::select( $courseFields, array( 'org_id' => $this->getId() ) ); |
147 | | - |
148 | | - foreach ( $courses as /* EPCourse */ $course ) { |
149 | | - // TODO: foreach set field: count and add to fields[name] |
150 | | - } |
151 | | - } |
152 | | - |
153 | 122 | $this->setFields( $fields ); |
154 | 123 | } |
155 | 124 | |
Index: trunk/extensions/EducationProgram/includes/EPRoleObject.php |
— | — | @@ -124,30 +124,31 @@ |
125 | 125 | * @return bool |
126 | 126 | */ |
127 | 127 | public function associateWithCourses( array /* of EPCourse */ $courses ) { |
128 | | - $dbw = wfGetDB( DB_MASTER ); |
129 | | - |
130 | | - $success = true; |
131 | | - |
132 | | - $dbw->begin(); |
133 | | - |
134 | | - foreach ( $courses as /* EPCourse */ $course ) { |
135 | | - $success = $dbw->insert( |
136 | | - 'ep_students_per_course', |
137 | | - array( |
138 | | - 'spc_student_id' => $this->getId(), |
139 | | - 'spc_course_id' => $course->getId(), |
140 | | - ) |
141 | | - ) && $success; |
142 | | - } |
143 | | - |
144 | | - $dbw->commit(); |
145 | | - |
146 | | - foreach ( $courses as /* EPCourse */ $course ) { |
147 | | - EPOrg::updateSummaryFields( 'students', array( 'id' => $course->getField( 'org_id' ) ) ); |
148 | | - EPCourse::updateSummaryFields( 'students', array( 'id' => $course->getId() ) ); |
149 | | - } |
150 | | - |
151 | | - return $success; |
| 128 | +// $dbw = wfGetDB( DB_MASTER ); |
| 129 | +// |
| 130 | +// $success = true; |
| 131 | +// |
| 132 | +// $dbw->begin(); |
| 133 | +// |
| 134 | +// foreach ( $courses as /* EPCourse */ $course ) { |
| 135 | +// $success = $dbw->insert( |
| 136 | +// 'ep_users_per_course', |
| 137 | +// array( |
| 138 | +// 'upc_student_id' => $this->getId(), |
| 139 | +// 'upc_course_id' => $course->getId(), |
| 140 | +// 'upc_role' => EPUtils::getRoleId( $this->getRoleName() ), |
| 141 | +// ) |
| 142 | +// ) && $success; |
| 143 | +// } |
| 144 | +// |
| 145 | +// $dbw->commit(); |
| 146 | +// |
| 147 | +// foreach ( $courses as /* EPCourse */ $course ) { |
| 148 | +// EPOrg::updateSummaryFields( 'students', array( 'id' => $course->getField( 'org_id' ) ) ); |
| 149 | +// EPCourse::updateSummaryFields( 'students', array( 'id' => $course->getId() ) ); |
| 150 | +// } |
| 151 | +// |
| 152 | +// return $success; |
152 | 153 | } |
153 | 154 | |
154 | 155 | /** |
— | — | @@ -225,7 +226,7 @@ |
226 | 227 | } |
227 | 228 | |
228 | 229 | /** |
229 | | - * Returns the courses this user is associated with. |
| 230 | + * Returns the courses this campus ambassdor is associated with. |
230 | 231 | * |
231 | 232 | * @since 0.1 |
232 | 233 | * |
— | — | @@ -234,6 +235,13 @@ |
235 | 236 | * |
236 | 237 | * @return array of EPCourse |
237 | 238 | */ |
238 | | - protected abstract function doGetCourses( $fields, array $conditions ); |
| 239 | + protected function doGetCourses( $fields, array $conditions ) { |
| 240 | + return EPUtils::getCoursesForUser( |
| 241 | + $fields, |
| 242 | + $this->getField( 'user_id' ), |
| 243 | + $this->getRoleName( getRoleId ), |
| 244 | + $conditions |
| 245 | + ); |
| 246 | + } |
239 | 247 | |
240 | 248 | } |
\ No newline at end of file |
Index: trunk/extensions/EducationProgram/includes/EPOA.php |
— | — | @@ -74,28 +74,5 @@ |
75 | 75 | public function getRoleName() { |
76 | 76 | return 'online'; |
77 | 77 | } |
78 | | - |
79 | | - /** |
80 | | - * Returns the courses this online ambassdor is associated with. |
81 | | - * |
82 | | - * @since 0.1 |
83 | | - * |
84 | | - * @param string|array|null $fields |
85 | | - * @param array $conditions |
86 | | - * |
87 | | - * @return array of EPCourse |
88 | | - */ |
89 | | - protected function doGetCourses( $fields, array $conditions ) { |
90 | | - $conditions[] = array( array( 'ep_oas_per_course', 'user_id' ), $this->getField( 'user_id' ) ); |
91 | 78 | |
92 | | - return EPCourse::select( |
93 | | - $fields, |
94 | | - $conditions, |
95 | | - array(), |
96 | | - array( |
97 | | - 'ep_oas_per_course' => array( 'INNER JOIN', array( array( array( 'ep_oas_per_course', 'course_id' ), array( 'ep_courses', 'id' ) ) ) ), |
98 | | - ) |
99 | | - ); |
100 | | - } |
101 | | - |
102 | 79 | } |
Index: trunk/extensions/EducationProgram/includes/EPCourse.php |
— | — | @@ -105,6 +105,7 @@ |
106 | 106 | 'end' => 'str', // TS_MW |
107 | 107 | 'description' => 'str', |
108 | 108 | 'token' => 'str', |
| 109 | + 'students' => 'array', |
109 | 110 | 'instructors' => 'array', |
110 | 111 | 'online_ambs' => 'array', |
111 | 112 | 'campus_ambs' => 'array', |
— | — | @@ -113,8 +114,11 @@ |
114 | 115 | 'term' => 'str', |
115 | 116 | 'lang' => 'str', |
116 | 117 | 'mc' => 'str', |
117 | | - |
118 | | - 'students' => 'int', |
| 118 | + |
| 119 | + 'student_count' => 'int', |
| 120 | + 'instructor_count' => 'int', |
| 121 | + 'oa_count' => 'int', |
| 122 | + 'ca_count' => 'int', |
119 | 123 | ); |
120 | 124 | } |
121 | 125 | |
— | — | @@ -129,6 +133,7 @@ |
130 | 134 | 'end' => wfTimestamp( TS_MW ), |
131 | 135 | 'description' => '', |
132 | 136 | 'token' => '', |
| 137 | + 'students' => array(), |
133 | 138 | 'instructors' => array(), |
134 | 139 | 'online_ambs' => array(), |
135 | 140 | 'campus_ambs' => array(), |
— | — | @@ -138,7 +143,10 @@ |
139 | 144 | 'lang' => '', |
140 | 145 | 'mc' => '', |
141 | 146 | |
142 | | - 'students' => 0, |
| 147 | + 'student_count' => 0, |
| 148 | + 'instructor_count' => 0, |
| 149 | + 'oa_count' => 0, |
| 150 | + 'ca_count' => 0, |
143 | 151 | ); |
144 | 152 | } |
145 | 153 | |
— | — | @@ -148,71 +156,20 @@ |
149 | 157 | */ |
150 | 158 | public static function getSummaryFields() { |
151 | 159 | return array( |
152 | | - 'students', |
| 160 | + 'student_count', |
| 161 | + 'instructor_count', |
| 162 | + 'oa_count', |
| 163 | + 'ca_count', |
153 | 164 | ); |
154 | 165 | } |
155 | 166 | |
156 | 167 | /** |
157 | | - * Returns the students enrolled in this course. |
158 | | - * |
159 | | - * @since 0.1 |
160 | | - * |
161 | | - * @param string|array|null $fields |
162 | | - * @param array $conditions |
163 | | - * |
164 | | - * @return array of EPStudent |
165 | | - */ |
166 | | - protected function doGetStudents( $fields, array $conditions ) { |
167 | | - $conditions[] = array( array( 'ep_courses', 'id' ), $this->getId() ); |
168 | | - |
169 | | - return EPStudent::select( |
170 | | - $fields, |
171 | | - $conditions, |
172 | | - array(), |
173 | | - array( |
174 | | - 'ep_students_per_course' => array( 'INNER JOIN', array( array( array( 'ep_students_per_course', 'student_id' ), array( 'ep_students', 'id' ) ) ) ), |
175 | | - 'ep_courses' => array( 'INNER JOIN', array( array( array( 'ep_students_per_course', 'course_id' ), array( 'ep_courses', 'id' ) ) ) ) |
176 | | - ) |
177 | | - ); |
178 | | - } |
179 | | - |
180 | | - /** |
181 | | - * Returns the students enrolled in this course. |
182 | | - * Caches the result when no conditions are provided and all fields are selected. |
183 | | - * |
184 | | - * @since 0.1 |
185 | | - * |
186 | | - * @param string|array|null $fields |
187 | | - * @param array $conditions |
188 | | - * |
189 | | - * @return array of EPStudent |
190 | | - */ |
191 | | - public function getStudents( $fields = null, array $conditions = array() ) { |
192 | | - if ( count( $conditions ) !== 0 ) { |
193 | | - return $this->doGetStudents( $fields, $conditions ); |
194 | | - } |
195 | | - |
196 | | - if ( $this->students === false ) { |
197 | | - $students = $this->doGetStudents( $fields, $conditions ); |
198 | | - |
199 | | - if ( is_null( $fields ) ) { |
200 | | - $this->students = $students; |
201 | | - } |
202 | | - |
203 | | - return $students; |
204 | | - } |
205 | | - else { |
206 | | - return $this->students; |
207 | | - } |
208 | | - } |
209 | | - |
210 | | - /** |
211 | 168 | * (non-PHPdoc) |
212 | 169 | * @see EPDBObject::loadSummaryFields() |
213 | 170 | */ |
214 | 171 | public function loadSummaryFields( $summaryFields = null ) { |
215 | 172 | if ( is_null( $summaryFields ) ) { |
216 | | - $summaryFields = array( 'org_id', 'students' ); |
| 173 | + $summaryFields = array( 'org_id', 'student_count', 'instructor_count', 'oa_count', 'ca_count' ); |
217 | 174 | } |
218 | 175 | else { |
219 | 176 | $summaryFields = (array)$summaryFields; |
— | — | @@ -221,17 +178,20 @@ |
222 | 179 | $fields = array(); |
223 | 180 | |
224 | 181 | if ( in_array( 'org_id', $summaryFields ) ) { |
225 | | - $fields['org_id'] = $this->getCourse( 'org_id' )->getField( 'org_id' ); |
| 182 | + $fields['org_id'] = $this->getField( 'org_id' ); |
226 | 183 | } |
227 | | - |
228 | | - if ( in_array( 'students', $summaryFields ) ) { |
229 | | - $fields['students'] = wfGetDB( DB_SLAVE )->select( |
230 | | - 'ep_students_per_course', |
231 | | - 'COUNT(*) AS rowcount', |
232 | | - array( 'spc_course_id' => $this->getId() ) |
233 | | - ); |
234 | 184 | |
235 | | - $fields['students'] = $fields['students']->fetchObject()->rowcount; |
| 185 | + $map = array( |
| 186 | + 'student_count' => 'students', |
| 187 | + 'instructor_count' => 'instructors', |
| 188 | + 'oa_count' => 'online_ambs', |
| 189 | + 'ca_count' => 'campus_ambs', |
| 190 | + ); |
| 191 | + |
| 192 | + foreach ( array( 'student_count', 'instructor_count', 'oa_count', 'ca_count' ) as $field ) { |
| 193 | + if ( in_array( $field, $summaryFields ) ) { |
| 194 | + $fields[$field] = count( $this->getField( $map[$field] ) ); |
| 195 | + } |
236 | 196 | } |
237 | 197 | |
238 | 198 | $this->setFields( $fields ); |
— | — | @@ -535,6 +495,25 @@ |
536 | 496 | } |
537 | 497 | |
538 | 498 | /** |
| 499 | + * Returns the students as a list of EPStudent objects. |
| 500 | + * |
| 501 | + * @since 0.1 |
| 502 | + * |
| 503 | + * @return array of EPStudent |
| 504 | + */ |
| 505 | + public function getStudents() { |
| 506 | + if ( $this->students === false ) { |
| 507 | + $this->students = array(); |
| 508 | + |
| 509 | + foreach ( $this->getField( 'students' ) as $userId ) { |
| 510 | + $this->students[] = EPStudent::newFromUserId( $userId ); |
| 511 | + } |
| 512 | + } |
| 513 | + |
| 514 | + return $this->students; |
| 515 | + } |
| 516 | + |
| 517 | + /** |
539 | 518 | * Returns the instructors as a list of EPInstructor objects. |
540 | 519 | * |
541 | 520 | * @since 0.1 |
Index: trunk/extensions/EducationProgram/includes/EPUtils.php |
— | — | @@ -176,6 +176,8 @@ |
177 | 177 | * |
178 | 178 | * @since 0.1 |
179 | 179 | * |
| 180 | + * @param IContextSource $context |
| 181 | + * |
180 | 182 | * @return array |
181 | 183 | */ |
182 | 184 | public static function getDefaultNavigationItems( IContextSource $context ) { |
— | — | @@ -207,4 +209,44 @@ |
208 | 210 | return $items; |
209 | 211 | } |
210 | 212 | |
| 213 | + /** |
| 214 | + * Gets the courses for a user. |
| 215 | + * |
| 216 | + * @since 0.1 |
| 217 | + * |
| 218 | + * @param array|string|null $fields |
| 219 | + * @param integer $userId |
| 220 | + * @param null|integer $role |
| 221 | + * @param array $conditions |
| 222 | + * |
| 223 | + * @return array of EPCourse |
| 224 | + */ |
| 225 | + public static function getCoursesForUser( $fields, $userId, $role = null, $conditions = array() ) { |
| 226 | + $conditions[] = array( array( 'ep_users_per_course', 'user_id' ), $userId ); |
| 227 | + |
| 228 | + if ( !is_null( $role ) ) { |
| 229 | + $conditions[] = array( array( 'ep_users_per_course', 'role' ), $role ); |
| 230 | + } |
| 231 | + |
| 232 | + return EPCourse::select( |
| 233 | + $fields, |
| 234 | + $conditions, |
| 235 | + array(), |
| 236 | + array( |
| 237 | + 'ep_users_per_course' => array( 'INNER JOIN', array( array( array( 'ep_users_per_course', 'course_id' ), array( 'ep_courses', 'id' ) ) ) ), |
| 238 | + ) |
| 239 | + ); |
| 240 | + } |
| 241 | + |
| 242 | + public static function getRoleId( $roleName ) { |
| 243 | + $map = array( |
| 244 | + 'campus' => EP_CA, |
| 245 | + 'online' => EP_OA, |
| 246 | + 'instructor' => EP_INSTRUCTOR, |
| 247 | + 'student' => EP_STUDENT, |
| 248 | + ); |
| 249 | + |
| 250 | + return $map[$roleName]; |
| 251 | + } |
| 252 | + |
211 | 253 | } |
Index: trunk/extensions/EducationProgram/EducationProgram.hooks.php |
— | — | @@ -29,20 +29,20 @@ |
30 | 30 | dirname( __FILE__ ) . '/sql/EducationProgram.sql' |
31 | 31 | ); |
32 | 32 | |
33 | | - $updater->addExtensionUpdate( array( |
34 | | - 'addField', |
35 | | - 'ep_revisions', |
36 | | - 'rev_object_identifier', |
37 | | - dirname( __FILE__ ) . '/sql/AddRevIdentifier.sql', |
38 | | - true |
39 | | - ) ); |
40 | | - |
41 | | - $updater->addExtensionUpdate( array( |
42 | | - 'addTable', |
43 | | - 'ep_users_per_course', |
44 | | - dirname( __FILE__ ) . '/sql/UpdateUserLinks.sql', |
45 | | - true |
46 | | - ) ); |
| 33 | +// $updater->addExtensionUpdate( array( |
| 34 | +// 'addField', |
| 35 | +// 'ep_revisions', |
| 36 | +// 'rev_object_identifier', |
| 37 | +// dirname( __FILE__ ) . '/sql/AddRevIdentifier.sql', |
| 38 | +// true |
| 39 | +// ) ); |
| 40 | +// |
| 41 | +// $updater->addExtensionUpdate( array( |
| 42 | +// 'addTable', |
| 43 | +// 'ep_users_per_course', |
| 44 | +// dirname( __FILE__ ) . '/sql/UpdateUserLinks.sql', |
| 45 | +// true |
| 46 | +// ) ); |
47 | 47 | |
48 | 48 | return true; |
49 | 49 | } |