r109669 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109668‎ | r109669 | r109670 >
Date:01:00, 21 January 2012
Author:jeroendedauw
Status:deferred
Tags:
Comment:
follow up to r109656 - renaming
Modified paths:
  • /trunk/extensions/EducationProgram/EducationProgram.php (modified) (history)
  • /trunk/extensions/EducationProgram/api/ApiDeleteEducation.php (modified) (history)
  • /trunk/extensions/EducationProgram/api/ApiInstructor.php (modified) (history)
  • /trunk/extensions/EducationProgram/api/ApiRefreshEducation.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPCourse.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPMC.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPOrgPager.php (modified) (history)
  • /trunk/extensions/EducationProgram/includes/EPStudent.php (modified) (history)

Diff [purge]

Index: trunk/extensions/EducationProgram/includes/EPOrgPager.php
@@ -32,8 +32,8 @@
3333 'name',
3434 'city',
3535 'country',
 36+ 'mcs',
3637 'courses',
37 - 'terms',
3838 'students',
3939 'active',
4040 );
@@ -71,11 +71,11 @@
7272 $countries = array_flip( EPUtils::getCountryOptions( $this->getLanguage()->getCode() ) );
7373 $value = htmlspecialchars( $countries[$value] );
7474 break;
75 - case 'courses': case 'students': case 'terms':
 75+ case 'courses': case 'students': case 'mcs':
7676 $rawValue = $value;
7777 $value = htmlspecialchars( $this->getLanguage()->formatNum( $value ) );
7878
79 - if ( $rawValue > 0 && in_array( $name, array( 'terms', 'courses' ) ) ) {
 79+ if ( $rawValue > 0 && in_array( $name, array( 'mcs', 'courses' ) ) ) {
8080 $value = Linker::linkKnown(
8181 SpecialPage::getTitleFor( $this->getLanguage()->ucfirst( $name ) ),
8282 $value,
@@ -104,7 +104,7 @@
105105 'country',
106106 'courses',
107107 'students',
108 - 'terms',
 108+ 'mcs',
109109 'active',
110110 );
111111 }
Index: trunk/extensions/EducationProgram/includes/EPStudent.php
@@ -14,12 +14,12 @@
1515 class EPStudent extends EPDBObject {
1616
1717 /**
18 - * Cached array of the linked EPTerm objects.
 18+ * Cached array of the linked EPCourse objects.
1919 *
2020 * @since 0.1
2121 * @var array|false
2222 */
23 - protected $terms = false;
 23+ protected $courses = false;
2424
2525 /**
2626 * Cached user object of the user that is this student.
@@ -63,44 +63,44 @@
6464 }
6565
6666 /**
67 - * Associate the student with the provided terms.
 67+ * Associate the student with the provided courses.
6868 *
6969 * @since 0.1
7070 *
71 - * @param array $terms
 71+ * @param array $courses
7272 *
7373 * @return bool
7474 */
75 - public function associateWithTerms( array /* of EPTerm */ $terms ) {
 75+ public function associateWithTerms( array /* of EPCourse */ $courses ) {
7676 $dbw = wfGetDB( DB_MASTER );
7777
7878 $success = true;
7979
8080 $dbw->begin();
8181
82 - foreach ( $terms as /* EPTerm */ $term ) {
 82+ foreach ( $courses as /* EPCourse */ $course ) {
8383 $success = $dbw->insert(
84 - 'ep_students_per_term',
 84+ 'ep_students_per_course',
8585 array(
86 - 'spt_student_id' => $this->getId(),
87 - 'spt_term_id' => $term->getId(),
 86+ 'spc_student_id' => $this->getId(),
 87+ 'spc_term_id' => $course->getId(),
8888 )
8989 ) && $success;
9090 }
9191
9292 $dbw->commit();
9393
94 - foreach ( $terms as /* EPTerm */ $term ) {
95 - EPCourse::updateSummaryFields( 'students', array( 'id' => $term->getField( 'course_id' ) ) );
96 - EPOrg::updateSummaryFields( 'students', array( 'id' => $term->getField( 'org_id' ) ) );
97 - EPTerm::updateSummaryFields( 'students', array( 'id' => $this->getId() ) );
 94+ foreach ( $courses as /* EPCourse */ $course ) {
 95+ EPMC::updateSummaryFields( 'students', array( 'id' => $course->getField( 'mc_id' ) ) );
 96+ EPOrg::updateSummaryFields( 'students', array( 'id' => $course->getField( 'org_id' ) ) );
 97+ EPCourse::updateSummaryFields( 'students', array( 'id' => $this->getId() ) );
9898 }
9999
100100 return $success;
101101 }
102102
103103 /**
104 - * Returns the terms this student is enrolled in.
 104+ * Returns the courses this student is enrolled in.
105105 * Caches the result when no conditions are provided and all fields are selected.
106106 *
107107 * @since 0.1
@@ -108,98 +108,98 @@
109109 * @param string|array|null $fields
110110 * @param array $conditions
111111 *
112 - * @return array of EPTerm
 112+ * @return array of EPCourse
113113 */
114 - public function getTerms( $fields = null, array $conditions = array() ) {
 114+ public function getCourses( $fields = null, array $conditions = array() ) {
115115 if ( count( $conditions ) !== 0 ) {
116 - return $this->doGetTerms( $fields, $conditions );
 116+ return $this->doGetCourses( $fields, $conditions );
117117 }
118118
119 - if ( $this->terms === false ) {
120 - $terms = $this->doGetTerms( $fields, $conditions );
 119+ if ( $this->courses === false ) {
 120+ $courses = $this->doGetCourses( $fields, $conditions );
121121
122122 if ( is_null( $fields ) ) {
123 - $this->terms = $terms;
 123+ $this->courses = $courses;
124124 }
125125
126 - return $terms;
 126+ return $courses;
127127 }
128128 else {
129 - return $this->terms;
 129+ return $this->courses;
130130 }
131131 }
132132
133133 /**
134 - * Returns the courses this student is linked to (via terms).
 134+ * Returns the master courses this student is linked to (via courses).
135135 *
136136 * @since 0.1
137137 *
138138 * @param string|null|array $fields
139139 * @param array $conditions
140 - * @param array $termConditions
 140+ * @param array $courseConditions
141141 *
142 - * @return array of EPCourse
 142+ * @return array of EPMC
143143 */
144 - public function getCourses( $fields = null, array $conditions = array(), array $termConditions = array() ) {
145 - $courseIds = array_reduce(
146 - $this->getTerms( 'course_id', $termConditions ),
147 - function( array $ids, EPTerm $term ) {
148 - $ids[] = $term->getField( 'course_id' );
 144+ public function getMasterCourses( $fields = null, array $conditions = array(), array $courseConditions = array() ) {
 145+ $mcIds = array_reduce(
 146+ $this->getCourses( 'course_id', $courseConditions ),
 147+ function( array $ids, EPCourse $term ) {
 148+ $ids[] = $term->getField( 'mc_id' );
149149 return $ids;
150 - } ,
 150+ },
151151 array()
152152 );
153153
154 - if ( count( $courseIds ) < 1 ) {
 154+ if ( count( $mcIds ) < 1 ) {
155155 return array();
156156 }
157157
158 - $conditions['id'] = array_unique( $courseIds );
 158+ $conditions['id'] = array_unique( $mcIds );
159159
160 - return EPCourse::select( $fields, $conditions );
 160+ return EPMC::select( $fields, $conditions );
161161 }
162162
163163 /**
164 - * Returns the courses this student is currently enrolled in.
 164+ * Returns the master courses this student is currently enrolled in.
165165 *
166166 * @since 0.1
167167 *
168168 * @param string|null|array $fields
169169 * @param array $conditions
170170 *
171 - * @return array of EPCourse
 171+ * @return array of EPMC
172172 */
173 - public function getCurrentCourses( $fields = null, array $conditions = array() ) {
 173+ public function getCurrentMasterCourses( $fields = null, array $conditions = array() ) {
174174 $conditions['active'] = 1;
175 - return $this->getCourses( $fields, $conditions );
 175+ return $this->getMasterCourses( $fields, $conditions );
176176 }
177177
178178 /**
179 - * Returns the courses this student was previously enrolled in.
 179+ * Returns the master courses this student was previously enrolled in.
180180 *
181181 * @since 0.1
182182 *
183183 * @param string|null|array $fields
184184 * @param array $conditions
185185 *
186 - * @return array of EPCourse
 186+ * @return array of EPMC
187187 */
188 - public function getPassedCourses( $fields = null, array $conditions = array() ) {
 188+ public function getPassedMasterCourses( $fields = null, array $conditions = array() ) {
189189 $conditions['active'] = 0;
190 - return $this->getCourses( $fields, $conditions );
 190+ return $this->getMasterCourses( $fields, $conditions );
191191 }
192192
193193 /**
194 - * Returns the terms this student is enrolled in.
 194+ * Returns the courses this student is enrolled in.
195195 *
196196 * @since 0.1
197197 *
198198 * @param string|array|null $fields
199199 * @param array $conditions
200200 *
201 - * @return array of EPTerm
 201+ * @return array of EPCourse
202202 */
203 - protected function doGetTerms( $fields, array $conditions ) {
 203+ protected function doGetCourses( $fields, array $conditions ) {
204204 $conditions[] = array( array( 'ep_students', 'id' ), $this->getId() );
205205
206206 return EPTerm::select(
@@ -207,14 +207,14 @@
208208 $conditions,
209209 array(),
210210 array(
211 - 'ep_students_per_term' => array( 'INNER JOIN', array( array( array( 'ep_students_per_term', 'term_id' ), array( 'ep_terms', 'id' ) ) ) ),
212 - 'ep_students' => array( 'INNER JOIN', array( array( array( 'ep_students_per_term', 'student_id' ), array( 'ep_students', 'id' ) ) ) )
 211+ 'ep_students_per_course' => array( 'INNER JOIN', array( array( array( 'ep_students_per_course', 'course_id' ), array( 'ep_courses', 'id' ) ) ) ),
 212+ 'ep_students' => array( 'INNER JOIN', array( array( array( 'ep_students_per_course', 'student_id' ), array( 'ep_students', 'id' ) ) ) )
213213 )
214214 );
215215 }
216216
217217 /**
218 - * Retruns if the mentor has any term matching the provided conditions.
 218+ * Returns if the student has any course matching the provided conditions.
219219 *
220220 * @since 0.1
221221 *
@@ -222,8 +222,8 @@
223223 *
224224 * @return boolean
225225 */
226 - public function hasTerm( array $conditions = array() ) {
227 - return count( $this->getTerms( 'id', $conditions ) ) > 0;
 226+ public function hasCourse( array $conditions = array() ) {
 227+ return count( $this->getCourses( 'id', $conditions ) ) > 0;
228228 }
229229
230230 /**
Index: trunk/extensions/EducationProgram/includes/EPMC.php
@@ -192,19 +192,19 @@
193193 *
194194 * @since 0.1
195195 *
196 - * @param array|null $courses
 196+ * @param array|null $masterCourses
197197 *
198198 * @return array
199199 */
200 - public static function getCourseOptions( array /* EPCourse */ $courses = null ) {
 200+ public static function getMasterCourseOptions( array /* EPMC */ $masterCourses = null ) {
201201 $options = array();
202202
203 - if ( is_null( $courses ) ) {
204 - $courses = EPCourse::select( array( 'name', 'id' ) );
 203+ if ( is_null( $masterCourses ) ) {
 204+ $masterCourses = self::select( array( 'name', 'id' ) );
205205 }
206206
207 - foreach ( $courses as /* EPCourse */ $course ) {
208 - $options[$course->getField( 'name' )] = $course->getId();
 207+ foreach ( $masterCourses as /* EPMC */ $masterCourse ) {
 208+ $options[$masterCourse->getField( 'name' )] = $masterCourse->getId();
209209 }
210210
211211 return $options;
@@ -281,7 +281,7 @@
282282 }
283283
284284 /**
285 - * Adds a control to add a new course to the provided context
 285+ * Adds a control to add a new master course to the provided context
286286 * or show a message if this is not possible for some reason.
287287 *
288288 * @since 0.1
@@ -291,7 +291,7 @@
292292 */
293293 public static function displayAddNewRegion( IContextSource $context, array $args = array() ) {
294294 if ( EPOrg::has() ) {
295 - EPCourse::displayAddNewControl( $context, $args );
 295+ self::displayAddNewControl( $context, $args );
296296 }
297297 elseif ( $context->getUser()->isAllowed( 'ep-org' ) ) {
298298 $context->getOutput()->addWikiMsg( 'ep-courses-addorgfirst' );
@@ -346,7 +346,7 @@
347347 * @return Title
348348 */
349349 public function getTitle() {
350 - return SpecialPage::getTitleFor( 'Course', $this->getField( 'name' ) );
 350+ return SpecialPage::getTitleFor( 'MasterCourse', $this->getField( 'name' ) );
351351 }
352352
353353 /**
Index: trunk/extensions/EducationProgram/includes/EPCourse.php
@@ -14,12 +14,12 @@
1515 class EPCourse extends EPDBObject {
1616
1717 /**
18 - * Field for caching the linked course.
 18+ * Field for caching the linked master course.
1919 *
2020 * @since 0.1
21 - * @var EPCourse|false
 21+ * @var EPMC|false
2222 */
23 - protected $course = false;
 23+ protected $mc = false;
2424
2525 /**
2626 * Field for caching the linked org.
@@ -116,7 +116,7 @@
117117 }
118118
119119 /**
120 - * Returns the students enrolled in this term.
 120+ * Returns the students enrolled in this course.
121121 *
122122 * @since 0.1
123123 *
@@ -126,21 +126,21 @@
127127 * @return array of EPStudent
128128 */
129129 protected function doGetStudents( $fields, array $conditions ) {
130 - $conditions[] = array( array( 'ep_terms', 'id' ), $this->getId() );
 130+ $conditions[] = array( array( 'ep_courses', 'id' ), $this->getId() );
131131
132132 return EPStudent::select(
133133 $fields,
134134 $conditions,
135135 array(),
136136 array(
137 - 'ep_students_per_term' => array( 'INNER JOIN', array( array( array( 'ep_students_per_term', 'student_id' ), array( 'ep_students', 'id' ) ) ) ),
138 - 'ep_terms' => array( 'INNER JOIN', array( array( array( 'ep_students_per_term', 'term_id' ), array( 'ep_terms', 'id' ) ) ) )
 137+ 'ep_students_per_term' => array( 'INNER JOIN', array( array( array( 'ep_students_per_course', 'student_id' ), array( 'ep_students', 'id' ) ) ) ),
 138+ 'ep_courses' => array( 'INNER JOIN', array( array( array( 'ep_students_per_course', 'course_id' ), array( 'ep_courses', 'id' ) ) ) )
139139 )
140140 );
141141 }
142142
143143 /**
144 - * Returns the students enrolled in this term.
 144+ * Returns the students enrolled in this course.
145145 * Caches the result when no conditions are provided and all fields are selected.
146146 *
147147 * @since 0.1
@@ -282,20 +282,20 @@
283283 }
284284
285285 /**
286 - * Returns the course associated with this term.
 286+ * Returns the master course associated with this course.
287287 *
288288 * @since 0.1
289289 *
290290 * @param string|array|null $fields
291291 *
292 - * @return EPCourse
 292+ * @return EPMC
293293 */
294 - public function getCourse( $fields = null ) {
295 - if ( $this->course === false ) {
296 - $this->course = EPCourse::selectRow( $fields, array( 'id' => $this->loadAndGetField( 'course_id' ) ) );
 294+ public function getMasterCourse( $fields = null ) {
 295+ if ( $this->mc === false ) {
 296+ $this->mc = EPMC::selectRow( $fields, array( 'id' => $this->loadAndGetField( 'mc_id' ) ) );
297297 }
298298
299 - return $this->course;
 299+ return $this->mc;
300300 }
301301
302302 /**
Index: trunk/extensions/EducationProgram/EducationProgram.php
@@ -220,7 +220,7 @@
221221 $wgAvailableRights[] = 'ep-mc'; // Manage master courses
222222 $wgAvailableRights[] = 'ep-token'; // See enrollment tokens
223223 $wgAvailableRights[] = 'ep-enroll'; // Enroll as a student
224 -$wgAvailableRights[] = 'ep-remstudent'; // Dissasociate students from terms
 224+$wgAvailableRights[] = 'ep-remstudent'; // Disassociate students from terms
225225 $wgAvailableRights[] = 'ep-online'; // Add or remove online ambassadors from terms
226226 $wgAvailableRights[] = 'ep-campus'; // Add or remove campus ambassadors from terms
227227 $wgAvailableRights[] = 'ep-instructor'; // Add or remove instructors from courses
Index: trunk/extensions/EducationProgram/api/ApiRefreshEducation.php
@@ -24,8 +24,7 @@
2525 protected static $typeMap = array(
2626 'org' => 'EPOrg',
2727 'course' => 'EPCourse',
28 - 'term' => 'EPTerm',
29 - 'student' => 'EPStudent',
 28+ 'mc' => 'EPMC',
3029 );
3130
3231 public function execute() {
Index: trunk/extensions/EducationProgram/api/ApiInstructor.php
@@ -18,7 +18,7 @@
1919 $params = $this->extractRequestParams();
2020
2121 if ( !( isset( $params['username'] ) XOR isset( $params['userid'] ) ) ) {
22 - $this->dieUsage( wfMsgExt( 'ep-addinstructor-invalid-user-args' ), 'username-xor-userid' );
 22+ $this->dieUsage( wfMsg( 'ep-addinstructor-invalid-user-args' ), 'username-xor-userid' );
2323 }
2424
2525 if ( isset( $params['username'] ) ) {
@@ -30,27 +30,27 @@
3131 }
3232
3333 if ( $userId < 1 ) {
34 - $this->dieUsage( wfMsgExt( 'ep-addinstructor-invalid-user' ), 'invalid-user' );
 34+ $this->dieUsage( wfMsg( 'ep-addinstructor-invalid-user' ), 'invalid-user' );
3535 }
3636
3737 if ( !$this->userIsAllowed( $userId ) ) {
3838 $this->dieUsageMsg( array( 'badaccess-groups' ) );
3939 }
4040
41 - $course = EPCourse::selectRow( array( 'id', 'name', 'instructors' ), array( 'id' => $params['courseid'] ) );
 41+ $masterCourse = EPMC::selectRow( array( 'id', 'name', 'instructors' ), array( 'id' => $params['mcid'] ) );
4242
43 - if ( $course === false ) {
44 - $this->dieUsage( wfMsgExt( 'ep-addinstructor-invalid-course' ), 'invalid-course' );
 43+ if ( $masterCourse === false ) {
 44+ $this->dieUsage( wfMsg( 'ep-addinstructor-invalid-course' ), 'invalid-course' );
4545 }
4646
4747 $success = false;
4848
4949 switch ( $params['subaction'] ) {
5050 case 'add':
51 - $success = $course->addInstructors( array( $userId ), $params['reason'] );
 51+ $success = $masterCourse->addInstructors( array( $userId ), $params['reason'] );
5252 break;
5353 case 'remove':
54 - $success = $course->removeInstructors( array( $userId ), $params['reason'] );
 54+ $success = $masterCourse->removeInstructors( array( $userId ), $params['reason'] );
5555 break;
5656 }
5757
@@ -116,7 +116,7 @@
117117 ApiBase::PARAM_TYPE => 'integer',
118118 ApiBase::PARAM_REQUIRED => false,
119119 ),
120 - 'courseid' => array(
 120+ 'mcid' => array(
121121 ApiBase::PARAM_TYPE => 'integer',
122122 ApiBase::PARAM_REQUIRED => true,
123123 ),
@@ -132,7 +132,7 @@
133133 public function getParamDescription() {
134134 return array(
135135 'subaction' => 'Specifies what you want to do with the instructor',
136 - 'courseid' => 'The ID of the course to which the instructor should be added',
 136+ 'mcid' => 'The ID of the master course to/from which the instructor should be added/removed',
137137 'username' => 'Name of the user to associate as instructor',
138138 'userid' => 'Id of the user to associate as instructor',
139139 'reason' => 'Message with the reason for this change for nthe log',
@@ -142,7 +142,7 @@
143143
144144 public function getDescription() {
145145 return array(
146 - 'API module for associating/disassociating a user as instructor with/from a course.'
 146+ 'API module for associating/disassociating a user as instructor with/from a master course.'
147147 );
148148 }
149149
@@ -150,7 +150,7 @@
151151 return array_merge( parent::getPossibleErrors(), array(
152152 array( 'code' => 'username-xor-userid', 'info' => 'You need to either provide the username or the userid parameter' ),
153153 array( 'code' => 'invalid-user', 'info' => 'An invalid user name or id was provided' ),
154 - array( 'code' => 'invalid-course', 'info' => 'There is no course with the provided ID' ),
 154+ array( 'code' => 'invalid-course', 'info' => 'There is no master course with the provided ID' ),
155155 ) );
156156 }
157157
Index: trunk/extensions/EducationProgram/api/ApiDeleteEducation.php
@@ -24,7 +24,7 @@
2525 protected static $typeMap = array(
2626 'org' => 'EPOrg',
2727 'course' => 'EPCourse',
28 - 'term' => 'EPTerm',
 28+ 'mc' => 'EPMC',
2929 );
3030
3131 /**

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