r111172 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111171‎ | r111172 | r111173 >
Date:18:07, 10 February 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
schema changes
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.hooks.php (modified) (history)
  • /trunk/extensions/EducationProgram/EducationProgram.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPCA.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPCourse.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPInstructor.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPOA.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPOrg.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPRoleObject.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPStudent.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPUtils.php (modified) (history)
  • /trunk/extensions/EducationProgram/sql/AddRevIdentifier.sql (deleted) (history)
  • /trunk/extensions/EducationProgram/sql/EducationProgram.sql (modified) (history)
  • /trunk/extensions/EducationProgram/sql/UpdateUserLinks.sql (deleted) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/EducationProgram.php
@@ -161,6 +161,11 @@
162162 $egEPDBObjects['EPArticle'] = array( 'table' => 'ep_articles', 'prefix' => 'article_' );
163163 $egEPDBObjects[] = array( 'table' => 'ep_users_per_course', 'prefix' => 'upc_' );
164164
 165+define( 'EP_STUDENT', 0 );
 166+define( 'EP_INSTRUCTOR', 1 );
 167+define( 'EP_OA', 2 );
 168+define( 'EP_CA', 3 );
 169+
165170 // API
166171 $wgAPIModules['deleteeducation'] = 'ApiDeleteEducation';
167172 $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 @@
1313
1414 -- Summary fields - cahing data or computations on data stored elswhere
1515 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
2121 ) /*$wgDBTableOptions*/;
2222
2323 CREATE UNIQUE INDEX /*i*/ep_org_name ON /*_*/ep_orgs (org_name);
2424 CREATE INDEX /*i*/ep_org_city ON /*_*/ep_orgs (org_city);
2525 CREATE INDEX /*i*/ep_org_country ON /*_*/ep_orgs (org_country);
2626 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);
3132
3233
3334
@@ -35,11 +36,12 @@
3637 course_id INT unsigned NOT NULL auto_increment PRIMARY KEY,
3738
3839 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"
4142 course_start varbinary(14) NOT NULL, -- Start time of the course
4243 course_end varbinary(14) NOT NULL, -- End time of the course
4344 course_description TEXT NOT NULL, -- Description of the course
 45+ course_students BLOB NOT NULL, -- List of associated students (linking user.user_id)
4446 course_online_ambs BLOB NOT NULL, -- List of associated online ambassadors (linking user.user_id)
4547 course_campus_ambs BLOB NOT NULL, -- List of associated campus ambassadors (linking user.user_id)
4648 course_instructors BLOB NOT NULL, -- List of associated instructors (linking user.user_id)
@@ -50,7 +52,10 @@
5153 course_lang VARCHAR(10) NOT NULL, -- Language (code)
5254
5355 -- 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
5560 ) /*$wgDBTableOptions*/;
5661
5762 CREATE INDEX /*i*/ep_course_org_id ON /*_*/ep_courses (course_org_id);
@@ -63,7 +68,10 @@
6469 CREATE INDEX /*i*/ep_course_level ON /*_*/ep_courses (course_level);
6570 CREATE INDEX /*i*/ep_course_term ON /*_*/ep_courses (course_term);
6671 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);
6876
6977
7078
Index: trunk/extensions/EducationProgram/includes/EPInstructor.php
@@ -140,9 +140,7 @@
141141 }
142142
143143 /**
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.
147145 *
148146 * @since 0.1
149147 *
@@ -152,7 +150,12 @@
153151 * @return array of EPCourse
154152 */
155153 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+ );
157160 }
158161
159162 }
Index: trunk/extensions/EducationProgram/includes/EPCA.php
@@ -75,27 +75,4 @@
7676 return 'campus';
7777 }
7878
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 -
10279 }
Index: trunk/extensions/EducationProgram/includes/EPStudent.php
@@ -66,28 +66,4 @@
6767 return 'student';
6868 }
6969
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 -
9470 }
Index: trunk/extensions/EducationProgram/includes/EPOrg.php
@@ -85,7 +85,7 @@
8686 */
8787 public function loadSummaryFields( $summaryFields = null ) {
8888 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' );
9090 }
9191 else {
9292 $summaryFields = (array)$summaryFields;
@@ -99,25 +99,8 @@
100100
101101 $dbr = wfGetDB( DB_SLAVE );
102102
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 -
120103 if ( in_array( 'active', $summaryFields ) ) {
121 - $now = wfGetDB( DB_SLAVE )->addQuotes( wfTimestampNow() );
 104+ $now = $dbr->addQuotes( wfTimestampNow() );
122105
123106 $fields['active'] = EPCourse::has( array(
124107 'org_id' => $this->getId(),
@@ -126,29 +109,15 @@
127110 ) );
128111 }
129112
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;
138120 }
139121
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 -
153122 $this->setFields( $fields );
154123 }
155124
Index: trunk/extensions/EducationProgram/includes/EPRoleObject.php
@@ -124,30 +124,31 @@
125125 * @return bool
126126 */
127127 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;
152153 }
153154
154155 /**
@@ -225,7 +226,7 @@
226227 }
227228
228229 /**
229 - * Returns the courses this user is associated with.
 230+ * Returns the courses this campus ambassdor is associated with.
230231 *
231232 * @since 0.1
232233 *
@@ -234,6 +235,13 @@
235236 *
236237 * @return array of EPCourse
237238 */
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+ }
239247
240248 }
\ No newline at end of file
Index: trunk/extensions/EducationProgram/includes/EPOA.php
@@ -74,28 +74,5 @@
7575 public function getRoleName() {
7676 return 'online';
7777 }
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' ) );
9178
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 -
10279 }
Index: trunk/extensions/EducationProgram/includes/EPCourse.php
@@ -105,6 +105,7 @@
106106 'end' => 'str', // TS_MW
107107 'description' => 'str',
108108 'token' => 'str',
 109+ 'students' => 'array',
109110 'instructors' => 'array',
110111 'online_ambs' => 'array',
111112 'campus_ambs' => 'array',
@@ -113,8 +114,11 @@
114115 'term' => 'str',
115116 'lang' => 'str',
116117 'mc' => 'str',
117 -
118 - 'students' => 'int',
 118+
 119+ 'student_count' => 'int',
 120+ 'instructor_count' => 'int',
 121+ 'oa_count' => 'int',
 122+ 'ca_count' => 'int',
119123 );
120124 }
121125
@@ -129,6 +133,7 @@
130134 'end' => wfTimestamp( TS_MW ),
131135 'description' => '',
132136 'token' => '',
 137+ 'students' => array(),
133138 'instructors' => array(),
134139 'online_ambs' => array(),
135140 'campus_ambs' => array(),
@@ -138,7 +143,10 @@
139144 'lang' => '',
140145 'mc' => '',
141146
142 - 'students' => 0,
 147+ 'student_count' => 0,
 148+ 'instructor_count' => 0,
 149+ 'oa_count' => 0,
 150+ 'ca_count' => 0,
143151 );
144152 }
145153
@@ -148,71 +156,20 @@
149157 */
150158 public static function getSummaryFields() {
151159 return array(
152 - 'students',
 160+ 'student_count',
 161+ 'instructor_count',
 162+ 'oa_count',
 163+ 'ca_count',
153164 );
154165 }
155166
156167 /**
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 - /**
211168 * (non-PHPdoc)
212169 * @see EPDBObject::loadSummaryFields()
213170 */
214171 public function loadSummaryFields( $summaryFields = null ) {
215172 if ( is_null( $summaryFields ) ) {
216 - $summaryFields = array( 'org_id', 'students' );
 173+ $summaryFields = array( 'org_id', 'student_count', 'instructor_count', 'oa_count', 'ca_count' );
217174 }
218175 else {
219176 $summaryFields = (array)$summaryFields;
@@ -221,17 +178,20 @@
222179 $fields = array();
223180
224181 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' );
226183 }
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 - );
234184
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+ }
236196 }
237197
238198 $this->setFields( $fields );
@@ -535,6 +495,25 @@
536496 }
537497
538498 /**
 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+ /**
539518 * Returns the instructors as a list of EPInstructor objects.
540519 *
541520 * @since 0.1
Index: trunk/extensions/EducationProgram/includes/EPUtils.php
@@ -176,6 +176,8 @@
177177 *
178178 * @since 0.1
179179 *
 180+ * @param IContextSource $context
 181+ *
180182 * @return array
181183 */
182184 public static function getDefaultNavigationItems( IContextSource $context ) {
@@ -207,4 +209,44 @@
208210 return $items;
209211 }
210212
 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+
211253 }
Index: trunk/extensions/EducationProgram/EducationProgram.hooks.php
@@ -29,20 +29,20 @@
3030 dirname( __FILE__ ) . '/sql/EducationProgram.sql'
3131 );
3232
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+// ) );
4747
4848 return true;
4949 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r111184Follow up to r111172;jeroendedauw19:21, 10 February 2012
r111196Follow up to r111172; r111184jeroendedauw20:31, 10 February 2012

Status & tagging log