Index: trunk/extensions/EducationProgram/includes/EPCoursePager.php |
— | — | @@ -122,7 +122,7 @@ |
123 | 123 | wfMsg( 'epcoursepager-yes' ) => '1', |
124 | 124 | wfMsg( 'epcoursepager-no' ) => '0', |
125 | 125 | ), |
126 | | - 'value' => '1', |
| 126 | + 'value' => '', |
127 | 127 | ), |
128 | 128 | ); |
129 | 129 | } |
Index: trunk/extensions/EducationProgram/includes/EPCourse.php |
— | — | @@ -62,7 +62,7 @@ |
63 | 63 | */ |
64 | 64 | public function loadSummaryFields( $summaryFields = null ) { |
65 | 65 | if ( is_null( $summaryFields ) ) { |
66 | | - $summaryFields = array( 'students' ); |
| 66 | + $summaryFields = array( 'students', 'active' ); |
67 | 67 | } |
68 | 68 | else { |
69 | 69 | $summaryFields = (array)$summaryFields; |
— | — | @@ -87,6 +87,16 @@ |
88 | 88 | } |
89 | 89 | } |
90 | 90 | |
| 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 | + |
91 | 101 | $this->setFields( $fields ); |
92 | 102 | } |
93 | 103 | |
— | — | @@ -112,7 +122,7 @@ |
113 | 123 | } |
114 | 124 | |
115 | 125 | 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 ) ); |
117 | 127 | } |
118 | 128 | |
119 | 129 | return $success; |
— | — | @@ -126,7 +136,7 @@ |
127 | 137 | $success = parent::insertIntoDB(); |
128 | 138 | |
129 | 139 | 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' ) ) ); |
131 | 141 | } |
132 | 142 | |
133 | 143 | return $success; |
— | — | @@ -144,7 +154,7 @@ |
145 | 155 | if ( $this->updateSummaries && $success && $oldOrgId !== false && $oldOrgId !== $this->getField( 'org_id' ) ) { |
146 | 156 | $conds = array( 'id' => array( $oldOrgId, $this->getField( 'org_id' ) ) ); |
147 | 157 | 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 ); |
149 | 159 | } |
150 | 160 | |
151 | 161 | return $success; |
Index: trunk/extensions/EducationProgram/includes/EPOrgPager.php |
— | — | @@ -134,7 +134,7 @@ |
135 | 135 | wfMsg( 'eporgpager-yes' ) => '1', |
136 | 136 | wfMsg( 'eporgpager-no' ) => '0', |
137 | 137 | ), |
138 | | - 'value' => '1', |
| 138 | + 'value' => '', |
139 | 139 | ), |
140 | 140 | ); |
141 | 141 | } |
Index: trunk/extensions/EducationProgram/includes/EPOrg.php |
— | — | @@ -76,7 +76,7 @@ |
77 | 77 | */ |
78 | 78 | public function loadSummaryFields( $summaryFields = null ) { |
79 | 79 | if ( is_null( $summaryFields ) ) { |
80 | | - $summaryFields = array( 'courses', 'terms', 'mentors', 'students' ); |
| 80 | + $summaryFields = array( 'courses', 'terms', 'mentors', 'students', 'active' ); |
81 | 81 | } |
82 | 82 | else { |
83 | 83 | $summaryFields = (array)$summaryFields; |
— | — | @@ -121,6 +121,16 @@ |
122 | 122 | } |
123 | 123 | } |
124 | 124 | |
| 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 | + |
125 | 135 | $this->setFields( $fields ); |
126 | 136 | } |
127 | 137 | |
Index: trunk/extensions/EducationProgram/includes/EPTerm.php |
— | — | @@ -133,7 +133,8 @@ |
134 | 134 | $success = parent::insertIntoDB(); |
135 | 135 | |
136 | 136 | 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' ) ) ); |
138 | 139 | } |
139 | 140 | |
140 | 141 | return $success; |
— | — | @@ -156,7 +157,7 @@ |
157 | 158 | |
158 | 159 | if ( $success && $this->updateSummaries ) { |
159 | 160 | 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 ) ); |
161 | 162 | } |
162 | 163 | |
163 | 164 | if ( $success ) { |
— | — | @@ -173,6 +174,7 @@ |
174 | 175 | protected function updateInDB() { |
175 | 176 | if ( $this->updateSummaries ) { |
176 | 177 | $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; |
177 | 179 | } |
178 | 180 | |
179 | 181 | if ( $this->hasField( 'course_id' ) ) { |
— | — | @@ -185,9 +187,16 @@ |
186 | 188 | |
187 | 189 | $success = parent::updateInDB(); |
188 | 190 | |
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 | + } |
192 | 201 | } |
193 | 202 | |
194 | 203 | return $success; |