r108931 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108930‎ | r108931 | r108932 >
Date:18:12, 14 January 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
added students field to terms table
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.hooks.php (modified) (history)
  • /trunk/extensions/EducationProgram/EducationProgram.i18n.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPStudent.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPTerm.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPTermPager.php (modified) (history)
  • /trunk/extensions/EducationProgram/sql/AddStudentsField.sql (added) (history)
  • /trunk/extensions/EducationProgram/sql/EducationProgram.sql (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/sql/EducationProgram.sql
@@ -56,13 +56,16 @@
5757 term_description TEXT NOT NULL, -- Description of the term
5858 term_online_ambs BLOB NOT NULL, -- List of associated online abmassadors
5959 term_campus_ambs BLOB NOT NULL, -- List of associated campus abmassadors
60 - term_token VARCHAR(255) NOT NULL -- Token needed to enroll
 60+ term_token VARCHAR(255) NOT NULL, -- Token needed to enroll
 61+
 62+ term_students SMALLINT unsigned NOT NULL -- Amount of students
6163 ) /*$wgDBTableOptions*/;
6264
6365 CREATE INDEX /*i*/ep_term_year ON /*_*/ep_terms (term_year);
6466 CREATE INDEX /*i*/ep_term_start ON /*_*/ep_terms (term_start);
6567 CREATE INDEX /*i*/ep_term_end ON /*_*/ep_terms (term_end);
6668 CREATE UNIQUE INDEX /*i*/ep_trem_period ON /*_*/ep_terms (term_org_id, term_start, term_start);
 69+CREATE INDEX /*i*/ep_term_students ON /*_*/ep_terms (term_students);
6770
6871 -- Students. In essence this is an extension to the user table.
6972 CREATE TABLE IF NOT EXISTS /*_*/ep_students (
Index: trunk/extensions/EducationProgram/sql/AddStudentsField.sql
@@ -0,0 +1,8 @@
 2+-- SQL for the Education Program extension.
 3+-- Adds additional fields.
 4+-- Licence: GNU GPL v3+
 5+-- Author: Jeroen De Dauw < jeroendedauw@gmail.com >
 6+
 7+ALTER TABLE /*_*/ep_terms ADD COLUMN term_students SMALLINT unsigned NOT NULL default 0;
 8+
 9+CREATE INDEX /*i*/ep_term_students ON /*_*/ep_terms (term_students);
\ No newline at end of file
Property changes on: trunk/extensions/EducationProgram/sql/AddStudentsField.sql
___________________________________________________________________
Added: svn:eol-style
110 + native
Index: trunk/extensions/EducationProgram/includes/EPStudent.php
@@ -93,6 +93,7 @@
9494 foreach ( $terms as /* EPTerm */ $term ) {
9595 EPCourse::updateSummaryFields( 'students', array( 'id' => $term->getField( 'course_id' ) ) );
9696 EPOrg::updateSummaryFields( 'students', array( 'id' => $term->getField( 'org_id' ) ) );
 97+ EPTerm::updateSummaryFields( 'students', array( 'id' => $this->getId() ) );
9798 }
9899
99100 return $success;
Index: trunk/extensions/EducationProgram/includes/EPTermPager.php
@@ -34,6 +34,7 @@
3535 'year',
3636 'start',
3737 'end',
 38+ 'students',
3839 );
3940 }
4041
@@ -81,6 +82,9 @@
8283 break;
8384 case '_status':
8485 $value = htmlspecialchars( EPTerm::getStatusMessage( $this->currentObject->getStatus() ) );
 86+ case 'students':
 87+ $value = htmlspecialchars( $this->getLanguage()->formatNum( $value ) );
 88+ break;
8589 }
8690
8791 return $value;
@@ -96,6 +100,7 @@
97101 'year',
98102 'start',
99103 'end',
 104+ 'students',
100105 );
101106 }
102107
Index: trunk/extensions/EducationProgram/includes/EPTerm.php
@@ -91,6 +91,8 @@
9292 'end' => 'str', // TS_MW
9393 'description' => 'str',
9494 'token' => 'str',
 95+
 96+ 'students' => 'int',
9597 );
9698 }
9799
@@ -105,6 +107,8 @@
106108 'end' => wfTimestamp( TS_MW ),
107109 'description' => '',
108110 'token' => '',
 111+
 112+ 'students' => 0,
109113 );
110114 }
111115
@@ -168,7 +172,7 @@
169173 */
170174 public function loadSummaryFields( $summaryFields = null ) {
171175 if ( is_null( $summaryFields ) ) {
172 - $summaryFields = array( 'org_id' );
 176+ $summaryFields = array( 'org_id', 'students' );
173177 }
174178 else {
175179 $summaryFields = (array)$summaryFields;
@@ -179,7 +183,17 @@
180184 if ( in_array( 'org_id', $summaryFields ) ) {
181185 $fields['org_id'] = $this->getCourse( 'org_id' )->getField( 'org_id' );
182186 }
 187+
 188+ if ( in_array( 'students', $summaryFields ) ) {
 189+ $fields['students'] = wfGetDB( DB_SLAVE )->select(
 190+ 'ep_students_per_term',
 191+ 'COUNT(*) AS rowcount',
 192+ array( 'spt_term_id' => $this->getId() )
 193+ );
183194
 195+ $fields['students'] = $fields['students']->fetchObject()->rowcount;
 196+ }
 197+
184198 $this->setFields( $fields );
185199 }
186200
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php
@@ -205,6 +205,7 @@
206206 'eptermpager-filter-org-id' => 'Institution',
207207 'eptermpager-header-status' => 'Status',
208208 'eptermpager-filter-status' => 'Status',
 209+ 'eptermpager-header-students' => 'Students',
209210
210211 // Student pager
211212 'epstudentpager-header-user-id' => 'User',
Index: trunk/extensions/EducationProgram/EducationProgram.hooks.php
@@ -52,6 +52,14 @@
5353 dirname( __FILE__ ) . '/sql/AddMentorFields.sql',
5454 true
5555 ) );
 56+
 57+ $updater->addExtensionUpdate( array(
 58+ 'addField',
 59+ 'ep_terms',
 60+ 'term_students',
 61+ dirname( __FILE__ ) . '/sql/AddStudentsField.sql',
 62+ true
 63+ ) );
5664
5765 return true;
5866 }

Status & tagging log