r110578 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110577‎ | r110578 | r110579 >
Date:15:53, 2 February 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
work on ambassador linking
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.hooks.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPCourse.php (modified) (history)
  • /trunk/extensions/EducationProgram/specials/SpecialMyCourses.php (modified) (history)
  • /trunk/extensions/EducationProgram/sql/AddAmbassadorLinks.sql (added) (history)
  • /trunk/extensions/EducationProgram/sql/EducationProgram.sql (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/sql/EducationProgram.sql
@@ -10,6 +10,7 @@
1111 org_city VARCHAR(255) NOT NULL, -- Name of the city where the org is located
1212 org_country VARCHAR(255) NOT NULL, -- Name of the country where the org is located
1313
 14+ -- Summary fields - cahing data or computations on data stored elswhere
1415 org_active TINYINT unsigned NOT NULL, -- If the org has any active courses
1516 org_courses SMALLINT unsigned NOT NULL, -- Amount of courses
1617 org_instructors SMALLINT unsigned NOT NULL, -- Amount of instructors
@@ -48,6 +49,7 @@
4950 course_term VARCHAR(255) NOT NULL, -- Academic term
5051 course_lang VARCHAR(10) NOT NULL, -- Language (code)
5152
 53+ -- Summary fields - cahing data or computations on data stored elswhere
5254 course_students SMALLINT unsigned NOT NULL -- Amount of students
5355 ) /*$wgDBTableOptions*/;
5456
@@ -134,13 +136,14 @@
135137
136138
137139
138 -CREATE TABLE IF NOT EXISTS /*_*/ep_cas_per_org (
139 - cpo_ca_id INT unsigned NOT NULL, -- Foreign key on ep_cas.ca_id
140 - cpo_org_id INT unsigned NOT NULL -- Foreign key on ep_orgs.org_id
 140+-- Links the campus ambassadors with all their courses.
 141+-- The is secondary storage for queries. The canonical data is in ep_course.campus_ambs
 142+CREATE TABLE IF NOT EXISTS /*_*/ep_cas_per_course (
 143+ cpc_ca_id INT unsigned NOT NULL, -- Foreign key on ep_cas.ca_id
 144+ cpc_course_id INT unsigned NOT NULL -- Foreign key on ep_course.course_id
141145 ) /*$wgDBTableOptions*/;
142146
143 -CREATE UNIQUE INDEX /*i*/ep_cas_per_org ON /*_*/ep_cas_per_org (cpo_ca_id, cpo_org_id);
 147+CREATE UNIQUE INDEX /*i*/ep_cas_per_course ON /*_*/ep_cas_per_course (cpc_ca_id, cpc_course_id);
144148
145149
146150
@@ -157,6 +160,17 @@
158161
159162
160163
 164+-- Links the online ambassadors with all their courses.
 165+-- The is secondary storage for queries. The canonical data is in ep_course.online_ambs
 166+CREATE TABLE IF NOT EXISTS /*_*/ep_oas_per_course (
 167+ opc_oa_id INT unsigned NOT NULL, -- Foreign key on ep_oas.oa_id
 168+ opc_course_id INT unsigned NOT NULL -- Foreign key on ep_course.course_id
 169+) /*$wgDBTableOptions*/;
 170+
 171+CREATE UNIQUE INDEX /*i*/ep_oas_per_course ON /*_*/ep_oas_per_course (opc_oa_id, opc_course_id);
 172+
 173+
 174+
161175 -- Revision table, holding blobs of various types of objects, such as orgs or students.
162176 -- This is somewhat based on the (core) revision table and is meant to serve
163177 -- as a prototype for a more general system to store this kind of data in a visioned fashion.
Index: trunk/extensions/EducationProgram/sql/AddAmbassadorLinks.sql
@@ -0,0 +1,22 @@
 2+-- MySQL for the Education Program extension.
 3+-- Licence: GNU GPL v3+
 4+-- Author: Jeroen De Dauw < jeroendedauw@gmail.com >
 5+
 6+
 7+-- Links the campus ambassadors with all their courses.
 8+-- The is secondary storage for queries. The canonical data is in ep_course.campus_ambs
 9+CREATE TABLE IF NOT EXISTS /*_*/ep_cas_per_course (
 10+ cpc_ca_id INT unsigned NOT NULL, -- Foreign key on ep_cas.ca_id
 11+ cpc_course_id INT unsigned NOT NULL -- Foreign key on ep_course.course_id
 12+) /*$wgDBTableOptions*/;
 13+
 14+CREATE UNIQUE INDEX /*i*/ep_cas_per_course ON /*_*/ep_cas_per_course (cpc_ca_id, cpc_course_id);
 15+
 16+-- Links the online ambassadors with all their courses.
 17+-- The is secondary storage for queries. The canonical data is in ep_course.online_ambs
 18+CREATE TABLE IF NOT EXISTS /*_*/ep_oas_per_course (
 19+ opc_oa_id INT unsigned NOT NULL, -- Foreign key on ep_oas.oa_id
 20+ opc_course_id INT unsigned NOT NULL -- Foreign key on ep_course.course_id
 21+) /*$wgDBTableOptions*/;
 22+
 23+CREATE UNIQUE INDEX /*i*/ep_oas_per_course ON /*_*/ep_oas_per_course (opc_oa_id, opc_course_id);
\ No newline at end of file
Property changes on: trunk/extensions/EducationProgram/sql/AddAmbassadorLinks.sql
___________________________________________________________________
Added: svn:eol-style
124 + native
Index: trunk/extensions/EducationProgram/specials/SpecialMyCourses.php
@@ -70,8 +70,18 @@
7171
7272 protected function displayCourses() {
7373 $this->displayEnrollment();
74 - $this->displayMentorship();
75 - $this->displayInstructorship();
 74+
 75+ if ( $this->getUser()->isAllowed( 'ep-instructor' ) ) {
 76+ $this->displayInstructorship();
 77+ }
 78+
 79+ if ( $this->getUser()->isAllowed( 'ep-online' ) ) {
 80+ $this->displayOnlineMentorship();
 81+ }
 82+
 83+ if ( $this->getUser()->isAllowed( 'ep-campus' ) ) {
 84+ $this->displayCampusMentorship();
 85+ }
7686 }
7787
7888 protected function displayEnrollment() {
@@ -116,10 +126,14 @@
117127 }
118128 }
119129
120 - protected function displayMentorship() {
 130+ protected function displayOnlineMentorship() {
121131
122132 }
123133
 134+ protected function displayCampusMentorship() {
 135+
 136+ }
 137+
124138 protected function displayInstructorship() {
125139
126140 }
Index: trunk/extensions/EducationProgram/includes/EPCourse.php
@@ -266,11 +266,13 @@
267267 $success = parent::removeFromDB();
268268
269269 if ( $success && $this->updateSummaries ) {
270 - EPOrg::updateSummaryFields( array( 'courses', 'students', 'active' ), array( 'id' => $orgId ) );
 270+ EPOrg::updateSummaryFields( array( 'courses', 'students', 'active', 'instructors', 'oas', 'cas' ), array( 'id' => $orgId ) );
271271 }
272272
273273 if ( $success ) {
274274 $success = wfGetDB( DB_MASTER )->delete( 'ep_students_per_course', array( 'spc_course_id' => $id ) ) && $success;
 275+ $success = wfGetDB( DB_MASTER )->delete( 'ep_cas_per_course', array( 'cpc_course_id' => $id ) ) && $success;
 276+ $success = wfGetDB( DB_MASTER )->delete( 'ep_oas_per_course', array( 'opc_course_id' => $id ) ) && $success;
275277 }
276278
277279 return $success;
@@ -282,16 +284,34 @@
283285 */
284286 protected function updateInDB() {
285287 if ( $this->updateSummaries ) {
286 - $oldOrgId = $this->hasField( 'org_id' ) ? self::selectFieldsRow( 'org_id', array( 'id' => $this->getId() ) ) : false;
 288+ $currentFields = array();
 289+
 290+ foreach ( array( 'org_id', 'online_ambs', 'campus_ambs' ) as $field ) {
 291+ if ( $this->hasField( $field ) ) {
 292+ $currentFields[] = $field;
 293+ }
 294+ }
 295+
 296+ if ( count( $currentFields ) > 0 ) {
 297+ $currentFields = self::selectFieldsRow( $currentFields, array( 'id' => $this->getId() ) );
 298+ }
287299 }
288300
289301 $success = parent::updateInDB();
290302
291303 if ( $this->updateSummaries && $success ) {
292 - if ( $oldOrgId !== false && $oldOrgId !== $this->getField( 'org_id' ) ) {
 304+ if ( array_key_exists( 'org_id', $currentFields ) && $currentFields['org_id'] !== $this->getField( 'org_id' ) ) {
293305 $conds = array( 'id' => array( $oldOrgId, $this->getField( 'org_id' ) ) );
294 - EPOrg::updateSummaryFields( array( 'courses', 'students', 'active' ), $conds );
 306+ EPOrg::updateSummaryFields( array( 'courses', 'students', 'active', 'instructors', 'oas', 'cas' ), $conds );
295307 }
 308+
 309+ foreach ( array( 'oas', 'cas' ) as $ambs ) {
 310+ $field = $ambs === 'oas' ? 'online_ambs' : 'campus_ambs';
 311+
 312+ if ( array_key_exists( $field, $currentFields ) && $currentFields[$field] !== $this->getField( $field ) ) {
 313+ // TODO
 314+ }
 315+ }
296316 }
297317
298318 return $success;
Index: trunk/extensions/EducationProgram/EducationProgram.hooks.php
@@ -29,13 +29,12 @@
3030 dirname( __FILE__ ) . '/sql/EducationProgram.sql'
3131 );
3232
33 -// $updater->addExtensionUpdate( array(
34 -// 'addField',
35 -// 'ep_courses',
36 -// 'course_name',
37 -// dirname( __FILE__ ) . '/sql/AddExtraFields.sql',
38 -// true
39 -// ) );
 33+ $updater->addExtensionUpdate( array(
 34+ 'addTable',
 35+ 'ep_oas_per_course',
 36+ dirname( __FILE__ ) . '/sql/AddAmbassadorLinks.sql',
 37+ true
 38+ ) );
4039
4140 return true;
4241 }

Status & tagging log