r109667 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109666‎ | r109667 | r109668 >
Date:00:36, 21 January 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
follow up to r109656 - renaming and added tables for online and campus ambassadors
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPOrg.php (modified) (history)
  • /trunk/extensions/EducationProgram/sql/EducationProgram.sql (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/sql/EducationProgram.sql
@@ -12,7 +12,7 @@
1313
1414 org_active TINYINT unsigned NOT NULL, -- If the org has any active terms
1515 org_courses SMALLINT unsigned NOT NULL, -- Amount of courses
16 - org_terms SMALLINT unsigned NOT NULL, -- Amount of terms
 16+ org_mcs SMALLINT unsigned NOT NULL, -- Amount of master courses
1717 org_students INT unsigned NOT NULL -- Amount of students
1818 ) /*$wgDBTableOptions*/;
1919
@@ -22,6 +22,8 @@
2323 CREATE INDEX /*i*/ep_org_students ON /*_*/ep_orgs (org_students);
2424 CREATE INDEX /*i*/ep_org_active ON /*_*/ep_orgs (org_active);
2525
 26+
 27+
2628 -- Master courses. These describe a specific course, time-independent.
2729 CREATE TABLE IF NOT EXISTS /*_*/ep_mcs (
2830 mc_id INT unsigned NOT NULL auto_increment PRIMARY KEY,
@@ -42,6 +44,8 @@
4345 CREATE INDEX /*i*/ep_mc_students ON /*_*/ep_mcs (mc_students);
4446 CREATE INDEX /*i*/ep_mc_active ON /*_*/ep_mcs (mc_active);
4547
 48+
 49+
4650 -- Courses. These are "instances" of a master course in a certain period.
4751 CREATE TABLE IF NOT EXISTS /*_*/ep_courses (
4852 course_id INT unsigned NOT NULL auto_increment PRIMARY KEY,
@@ -65,6 +69,8 @@
6670 CREATE UNIQUE INDEX /*i*/ep_trem_period ON /*_*/ep_courses (course_org_id, course_start, course_end);
6771 CREATE INDEX /*i*/ep_course_students ON /*_*/ep_courses (course_students);
6872
 73+
 74+
6975 -- Students. In essence this is an extension to the user table.
7076 CREATE TABLE IF NOT EXISTS /*_*/ep_students (
7177 student_id INT unsigned NOT NULL auto_increment PRIMARY KEY,
@@ -81,15 +87,7 @@
8288 CREATE INDEX /*i*/ep_students_last_active ON /*_*/ep_students (student_last_active);
8389 CREATE INDEX /*i*/ep_students_active_enroll ON /*_*/ep_students (student_active_enroll);
8490
85 -CREATE TABLE IF NOT EXISTS /*_*/ep_mentors (
86 - mentor_id INT unsigned NOT NULL auto_increment PRIMARY KEY,
87 - mentor_user_id INT unsigned NOT NULL -- Foreign key on user.user_id
88 -) /*$wgDBTableOptions*/;
89 -
90 -CREATE UNIQUE INDEX /*i*/ep_mentors_user_id ON /*_*/ep_mentors (mentor_user_id);
91 -
 91+-- Links the students with their courses.
9292 CREATE TABLE IF NOT EXISTS /*_*/ep_students_per_course (
9393 spc_student_id INT unsigned NOT NULL, -- Foreign key on ep_students.student_id
9494 spc_course_id INT unsigned NOT NULL -- Foreign key on ep_courses.course_id
@@ -97,6 +95,26 @@
9896
9997 CREATE UNIQUE INDEX /*i*/ep_students_per_course ON /*_*/ep_students_per_course (spc_student_id, spc_course_id);
10098
 99+
 100+
 101+-- Instructors. In essence this is an extension to the user table.
 102+CREATE TABLE IF NOT EXISTS /*_*/ep_instructors (
 103+ instructor_id INT unsigned NOT NULL auto_increment PRIMARY KEY,
 104+ instructor_user_id INT unsigned NOT NULL -- Foreign key on user.user_id
 105+) /*$wgDBTableOptions*/;
 106+
 107+CREATE UNIQUE INDEX /*i*/ep_instructors_user_id ON /*_*/ep_instructors (instructor_user_id);
 108+
 109+
 110+
 111+-- Campus ambassadors. In essence this is an extension to the user table.
 112+CREATE TABLE IF NOT EXISTS /*_*/ep_cas (
 113+ ca_id INT unsigned NOT NULL auto_increment PRIMARY KEY,
 114+ ca_user_id INT unsigned NOT NULL -- Foreign key on user.user_id
 115+) /*$wgDBTableOptions*/;
 116+
 117+CREATE UNIQUE INDEX /*i*/ep_cas_user_id ON /*_*/ep_cas (ca_user_id);
 118+
101119 -- Links the campus ambassadors with all their orgs.
102120 CREATE TABLE IF NOT EXISTS /*_*/ep_cas_per_org (
103121 cpo_ca_id INT unsigned NOT NULL, -- Foreign key on ep_cas.ca_id
@@ -105,6 +123,18 @@
106124
107125 CREATE UNIQUE INDEX /*i*/ep_cas_per_org ON /*_*/ep_cas_per_org (cpo_ca_id, cpo_org_id);
108126
 127+
 128+
 129+-- Online ambassadors. In essence this is an extension to the user table.
 130+CREATE TABLE IF NOT EXISTS /*_*/ep_oas (
 131+ oa_id INT unsigned NOT NULL auto_increment PRIMARY KEY,
 132+ oa_user_id INT unsigned NOT NULL -- Foreign key on user.user_id
 133+) /*$wgDBTableOptions*/;
 134+
 135+CREATE UNIQUE INDEX /*i*/ep_oas_user_id ON /*_*/ep_oas (oa_user_id);
 136+
 137+
 138+
109139 -- Revision table, holding blobs of various types of objects, such as orgs or students.
110140 -- This is somewhat based on the (core) revision table and is meant to serve
111141 -- as a prototype for a more general system to store this kind of data in a versioned fashion.
Index: trunk/extensions/EducationProgram/includes/EPOrg.php
@@ -14,20 +14,20 @@
1515 class EPOrg extends EPDBObject {
1616
1717 /**
18 - * Cached array of the linked EPCourse objects.
 18+ * Cached array of the linked EPMC objects.
1919 *
2020 * @since 0.1
2121 * @var array|false
2222 */
23 - protected $courses = false;
 23+ protected $mcs = false;
2424
2525 /**
26 - * Cached array of the linked EPTerm objects.
 26+ * Cached array of the linked EPCourse objects.
2727 *
2828 * @since 0.1
2929 * @var array|false
3030 */
31 - protected $terms = false;
 31+ protected $courses = false;
3232
3333 /**
3434 * @see parent::getFieldTypes
@@ -46,7 +46,7 @@
4747
4848 'active' => 'bool',
4949 'courses' => 'int',
50 - 'terms' => 'int',
 50+ 'mcs' => 'int',
5151 'students' => 'int',
5252 );
5353 }
@@ -63,7 +63,7 @@
6464
6565 'active' => false,
6666 'courses' => 0,
67 - 'terms' => 0,
 67+ 'mcs' => 0,
6868 'students' => 0,
6969 );
7070 }
@@ -85,7 +85,7 @@
8686 */
8787 public function loadSummaryFields( $summaryFields = null ) {
8888 if ( is_null( $summaryFields ) ) {
89 - $summaryFields = array( 'courses', 'terms', 'students', 'active' );
 89+ $summaryFields = array( 'courses', 'mcs', 'students', 'active' );
9090 }
9191 else {
9292 $summaryFields = (array)$summaryFields;
@@ -97,20 +97,20 @@
9898 $fields['courses'] = EPCourse::count( array( 'org_id' => $this->getId() ) );
9999 }
100100
101 - if ( in_array( 'terms', $summaryFields ) ) {
102 - $fields['terms'] = EPTerm::count( array( 'org_id' => $this->getId() ) );
 101+ if ( in_array( 'mcs', $summaryFields ) ) {
 102+ $fields['mcs'] = EPMC::count( array( 'org_id' => $this->getId() ) );
103103 }
104104
105105 $dbr = wfGetDB( DB_SLAVE );
106106
107107 if ( in_array( 'students', $summaryFields ) ) {
108 - $termIds = EPTerm::selectFields( 'id', array( 'org_id' => $this->getId() ) );
 108+ $courseIds = EPCourse::selectFields( 'id', array( 'org_id' => $this->getId() ) );
109109
110 - if ( count( $termIds ) > 0 ) {
 110+ if ( count( $courseIds ) > 0 ) {
111111 $fields['students'] = $dbr->select(
112 - 'ep_students_per_term',
 112+ 'ep_students_per_course',
113113 'COUNT(*) AS rowcount',
114 - array( 'spt_term_id' => $termIds )
 114+ array( 'spc_course_id' => $courseIds )
115115 );
116116
117117 $fields['students'] = $fields['students']->fetchObject()->rowcount;
@@ -123,7 +123,7 @@
124124 if ( in_array( 'active', $summaryFields ) ) {
125125 $now = wfGetDB( DB_SLAVE )->addQuotes( wfTimestampNow() );
126126
127 - $fields['active'] = EPTerm::has( array(
 127+ $fields['active'] = EPCourse::has( array(
128128 'org_id' => $this->getId(),
129129 'end >= ' . $now,
130130 'start <= ' . $now,
@@ -144,10 +144,10 @@
145145 $success = parent::removeFromDB();
146146
147147 if ( $success ) {
148 - $success = wfGetDB( DB_MASTER )->delete( 'ep_mentors_per_org', array( 'mpo_org_id' => $id ) ) && $success;
 148+ $success = wfGetDB( DB_MASTER )->delete( 'ep_cas_per_org', array( 'cpo_org_id' => $id ) ) && $success;
149149
150 - foreach ( EPCourse::select( 'id', array( 'org_id' => $id ) ) as /* EPCourse */ $course ) {
151 - $success = $course->removeFromDB() && $success;
 150+ foreach ( EPMC::select( 'id', array( 'org_id' => $id ) ) as /* EPMC */ $masterCourse ) {
 151+ $success = $masterCourse->removeFromDB() && $success;
152152 }
153153 }
154154
@@ -257,37 +257,37 @@
258258 }
259259
260260 /**
261 - * Retruns the courses linked to this org.
 261+ * Retruns the master courses linked to this org.
262262 *
263263 * @since 0.1
264264 *
265265 * @param array|null $fields
266266 *
267 - * @return array of EPCourse
 267+ * @return array of EPMC
268268 */
269 - public function getCourses( array $fields = null ) {
270 - if ( $this->courses === false ) {
271 - $this->courses = EPCourse::select( $fields, array( 'org_id' => $this->getId() ) );
 269+ public function getMasterCourses( array $fields = null ) {
 270+ if ( $this->mcs === false ) {
 271+ $this->mcs = EPMC::select( $fields, array( 'org_id' => $this->getId() ) );
272272 }
273273
274 - return $this->courses;
 274+ return $this->mcs;
275275 }
276276
277277 /**
278 - * Retruns the terms linked to this org.
 278+ * Retruns the courses linked to this org.
279279 *
280280 * @since 0.1
281281 *
282282 * @param array|null $fields
283283 *
284 - * @return array of EPTerm
 284+ * @return array of EPCourse
285285 */
286 - public function getTerms( array $fields = null ) {
287 - if ( $this->terms === false ) {
288 - $this->terms = EPTerm::select( $fields, array( 'org_id' => $this->getId() ) );
 286+ public function getCourses( array $fields = null ) {
 287+ if ( $this->courses === false ) {
 288+ $this->courses = EPCourse::select( $fields, array( 'org_id' => $this->getId() ) );
289289 }
290290
291 - return $this->terms;
 291+ return $this->courses;
292292 }
293293
294294 /**
Index: trunk/extensions/EducationProgram/EducationProgram.php
@@ -148,7 +148,9 @@
149149 $egEPDBObjects['EPMC'] = array( 'table' => 'ep_mcs', 'prefix' => 'mc_' );
150150 $egEPDBObjects['EPCourse'] = array( 'table' => 'ep_courses', 'prefix' => 'course_' );
151151 $egEPDBObjects['EPStudent'] = array( 'table' => 'ep_students', 'prefix' => 'student_' );
152 -$egEPDBObjects[] = array( 'table' => 'ep_students_per_term', 'prefix' => 'spt_' );
 152+$egEPDBObjects['EPOA'] = array( 'table' => 'ep_oas', 'prefix' => 'oa_' );
 153+$egEPDBObjects['EPCA'] = array( 'table' => 'ep_cas', 'prefix' => 'ca_' );
 154+$egEPDBObjects[] = array( 'table' => 'ep_students_per_course', 'prefix' => 'spc_' );
153155
154156 // API
155157 $wgAPIModules['deleteeducation'] = 'ApiDeleteEducation';
@@ -198,7 +200,7 @@
199201 // Compatibility with MediaWiki 1.18.
200202 $wgLogNames['institution'] = 'log-name-institution';
201203 $wgLogNames['course'] = 'log-name-course';
202 - $wgLogNames['term'] = 'log-name-mc';
 204+ $wgLogNames['mc'] = 'log-name-mc';
203205 $wgLogNames['student'] = 'log-name-student';
204206 $wgLogNames['ambassador'] = 'log-name-ambassador';
205207 $wgLogNames['instructor'] = 'log-name-instructor';
@@ -206,7 +208,7 @@
207209 // Compatibility with MediaWiki 1.18.
208210 $wgLogHeaders['institution'] = 'log-header-institution';
209211 $wgLogHeaders['course'] = 'log-header-course';
210 - $wgLogHeaders['term'] = 'log-header-mc';
 212+ $wgLogHeaders['mc'] = 'log-header-mc';
211213 $wgLogHeaders['student'] = 'log-header-student';
212214 $wgLogHeaders['ambassador'] = 'log-header-ambassador';
213215 $wgLogHeaders['instructor'] = 'log-header-instructor';

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r109656schema changes currently completely breaking the extension and added hook to ...jeroendedauw22:24, 20 January 2012

Status & tagging log