r108634 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108633‎ | r108634 | r108635 >
Date:16:52, 11 January 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
work on org and course status
Modified paths:
  • /trunk/extensions/EducationProgram/includes/EPCourse.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPCoursePager.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPOrg.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPOrgPager.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPTerm.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/includes/EPCoursePager.php
@@ -122,7 +122,7 @@
123123 wfMsg( 'epcoursepager-yes' ) => '1',
124124 wfMsg( 'epcoursepager-no' ) => '0',
125125 ),
126 - 'value' => '1',
 126+ 'value' => '',
127127 ),
128128 );
129129 }
Index: trunk/extensions/EducationProgram/includes/EPCourse.php
@@ -62,7 +62,7 @@
6363 */
6464 public function loadSummaryFields( $summaryFields = null ) {
6565 if ( is_null( $summaryFields ) ) {
66 - $summaryFields = array( 'students' );
 66+ $summaryFields = array( 'students', 'active' );
6767 }
6868 else {
6969 $summaryFields = (array)$summaryFields;
@@ -87,6 +87,16 @@
8888 }
8989 }
9090
 91+ if ( in_array( 'active', $summaryFields ) ) {
 92+ $now = wfGetDB( DB_SLAVE )->addQuotes( wfTimestampNow() );
 93+
 94+ $fields['active'] = EPTerm::has( array(
 95+ 'course_id' => $this->getId(),
 96+ 'end >= ' . $now,
 97+ 'start <= ' . $now,
 98+ ) );
 99+ }
 100+
91101 $this->setFields( $fields );
92102 }
93103
@@ -112,7 +122,7 @@
113123 }
114124
115125 if ( $this->updateSummaries && $orgId !== false ) {
116 - EPOrg::updateSummaryFields( array( 'terms', 'students', 'courses' ), array( 'id' => $orgId ) );
 126+ EPOrg::updateSummaryFields( array( 'terms', 'students', 'courses', 'active' ), array( 'id' => $orgId ) );
117127 }
118128
119129 return $success;
@@ -126,7 +136,7 @@
127137 $success = parent::insertIntoDB();
128138
129139 if ( $this->updateSummaries ) {
130 - EPOrg::updateSummaryFields( 'courses', array( 'id' => $this->getField( 'org_id' ) ) );
 140+ EPOrg::updateSummaryFields( array( 'courses', 'active' ), array( 'id' => $this->getField( 'org_id' ) ) );
131141 }
132142
133143 return $success;
@@ -144,7 +154,7 @@
145155 if ( $this->updateSummaries && $success && $oldOrgId !== false && $oldOrgId !== $this->getField( 'org_id' ) ) {
146156 $conds = array( 'id' => array( $oldOrgId, $this->getField( 'org_id' ) ) );
147157 EPTerm::updateSummaryFields( 'org_id', array( 'course_id' => $this->getId() ) );
148 - EPOrg::updateSummaryFields( array( 'terms', 'students', 'courses' ), $conds );
 158+ EPOrg::updateSummaryFields( array( 'terms', 'students', 'courses', 'active' ), $conds );
149159 }
150160
151161 return $success;
Index: trunk/extensions/EducationProgram/includes/EPOrgPager.php
@@ -134,7 +134,7 @@
135135 wfMsg( 'eporgpager-yes' ) => '1',
136136 wfMsg( 'eporgpager-no' ) => '0',
137137 ),
138 - 'value' => '1',
 138+ 'value' => '',
139139 ),
140140 );
141141 }
Index: trunk/extensions/EducationProgram/includes/EPOrg.php
@@ -76,7 +76,7 @@
7777 */
7878 public function loadSummaryFields( $summaryFields = null ) {
7979 if ( is_null( $summaryFields ) ) {
80 - $summaryFields = array( 'courses', 'terms', 'mentors', 'students' );
 80+ $summaryFields = array( 'courses', 'terms', 'mentors', 'students', 'active' );
8181 }
8282 else {
8383 $summaryFields = (array)$summaryFields;
@@ -121,6 +121,16 @@
122122 }
123123 }
124124
 125+ if ( in_array( 'active', $summaryFields ) ) {
 126+ $now = wfGetDB( DB_SLAVE )->addQuotes( wfTimestampNow() );
 127+
 128+ $fields['active'] = EPTerm::has( array(
 129+ 'org_id' => $this->getId(),
 130+ 'end >= ' . $now,
 131+ 'start <= ' . $now,
 132+ ) );
 133+ }
 134+
125135 $this->setFields( $fields );
126136 }
127137
Index: trunk/extensions/EducationProgram/includes/EPTerm.php
@@ -133,7 +133,8 @@
134134 $success = parent::insertIntoDB();
135135
136136 if ( $success && $this->updateSummaries ) {
137 - EPOrg::updateSummaryFields( 'terms', array( 'id' => $this->getField( 'org_id' ) ) );
 137+ EPOrg::updateSummaryFields( array( 'terms', 'active' ), array( 'id' => $this->getField( 'org_id' ) ) );
 138+ EPCourse::updateSummaryFields( 'active', array( 'id' => $this->getField( 'course_id' ) ) );
138139 }
139140
140141 return $success;
@@ -156,7 +157,7 @@
157158
158159 if ( $success && $this->updateSummaries ) {
159160 EPCourse::updateSummaryFields( 'students', array( 'id' => $courseId ) );
160 - EPOrg::updateSummaryFields( array( 'terms', 'students' ), array( 'id' => $orgId ) );
 161+ EPOrg::updateSummaryFields( array( 'terms', 'students', 'active' ), array( 'id' => $orgId ) );
161162 }
162163
163164 if ( $success ) {
@@ -173,6 +174,7 @@
174175 protected function updateInDB() {
175176 if ( $this->updateSummaries ) {
176177 $oldOrgId = $this->hasField( 'org_id' ) ? self::selectFieldsRow( 'org_id', array( 'id' => $this->getId() ) ) : false;
 178+ $oldCourseId = $this->hasField( 'course_id' ) ? self::selectFieldsRow( 'course_id', array( 'id' => $this->getId() ) ) : false;
177179 }
178180
179181 if ( $this->hasField( 'course_id' ) ) {
@@ -185,9 +187,16 @@
186188
187189 $success = parent::updateInDB();
188190
189 - if ( $this->updateSummaries && $success && $oldOrgId !== false && $oldOrgId !== $this->getField( 'org_id' ) ) {
190 - $conds = array( 'id' => array( $oldOrgId, $this->getField( 'org_id' ) ) );
191 - EPOrg::updateSummaryFields( array( 'terms', 'students' ), $conds );
 191+ if ( $this->updateSummaries && $success ) {
 192+ if ( $oldOrgId !== false && $oldOrgId !== $this->getField( 'org_id' ) ) {
 193+ $conds = array( 'id' => array( $oldOrgId, $this->getField( 'org_id' ) ) );
 194+ EPOrg::updateSummaryFields( array( 'terms', 'students', 'active' ), $conds );
 195+ }
 196+
 197+ if ( $oldCourseId !== false && $oldCourseId !== $this->getField( 'org_id' ) ) {
 198+ $conds = array( 'id' => array( $oldCourseId, $this->getField( 'course_id' ) ) );
 199+ EPCourse::updateSummaryFields( array( 'active', 'students' ), $conds );
 200+ }
192201 }
193202
194203 return $success;

Status & tagging log