Index: trunk/extensions/EducationProgram/actions/EPEditAction.php |
— | — | @@ -100,8 +100,7 @@ |
101 | 101 | } |
102 | 102 | else { |
103 | 103 | if ( $object === false ) { |
104 | | - $c = $this->table->getDataObjectClass(); |
105 | | - $c::displayDeletionLog( |
| 104 | + $this->table->displayDeletionLog( |
106 | 105 | $this->getContext(), |
107 | 106 | 'ep-' . strtolower( $this->getName() ) . '-deleted' |
108 | 107 | ); |
— | — | @@ -355,18 +354,16 @@ |
356 | 355 | return Title::newFromText( $this->getRequest()->getText( 'wpreturnto' ) ); |
357 | 356 | } |
358 | 357 | elseif ( !$addedItem && $this->isNew() ) { |
359 | | - $c = $this->table->getDataObjectClass(); // Yeah, this is needed in PHP 5.3 >_> |
360 | | - return SpecialPage::getTitleFor( $c::getListPage() ); |
| 358 | + return SpecialPage::getTitleFor( $this->table->getListPage() ); |
361 | 359 | } |
362 | 360 | elseif ( $this->item !== false ) { |
363 | 361 | return $this->item->getTitle(); |
364 | 362 | } |
365 | 363 | else { |
366 | | - $c = $this->table->getDataObjectClass(); // Yeah, this is needed in PHP 5.3 >_> |
367 | | - $fieldName = 'wpitem-' . $c::getIdentifierField(); |
| 364 | + $fieldName = 'wpitem-' . $this->table->getIdentifierField(); |
368 | 365 | |
369 | 366 | if ( $this->getRequest()->getCheck( $fieldName ) ) { |
370 | | - return $c::getTitleFor( $this->getRequest()->getText( $fieldName ) ); |
| 367 | + return $this->table->getTitleFor( $this->getRequest()->getText( $fieldName ) ); |
371 | 368 | } |
372 | 369 | else { |
373 | 370 | return $this->getTitle(); |
Index: trunk/extensions/EducationProgram/specials/SpecialMyCourses.php |
— | — | @@ -44,7 +44,7 @@ |
45 | 45 | $this->displayCourses(); |
46 | 46 | } |
47 | 47 | else { |
48 | | - $course = EPCourse::selectRow( null, array( 'name' => $this->subPage ) ); |
| 48 | + $course = EPCourses::singleton()->selectRow( null, array( 'name' => $this->subPage ) ); |
49 | 49 | |
50 | 50 | if ( $course === false ) { |
51 | 51 | // TODO |
— | — | @@ -108,7 +108,7 @@ |
109 | 109 | */ |
110 | 110 | protected function displayEnrollment() { |
111 | 111 | if ( $this->getRequest()->getCheck( 'enrolled' ) ) { |
112 | | - EPStudent::setReadDb( DB_MASTER ); |
| 112 | + EPStudents::singleton()->setReadDb( DB_MASTER ); |
113 | 113 | } |
114 | 114 | |
115 | 115 | $student = EPStudent::newFromUser( $this->getUser() ); |
— | — | @@ -123,7 +123,10 @@ |
124 | 124 | ); |
125 | 125 | |
126 | 126 | if ( $this->getRequest()->getCheck( 'enrolled' ) && in_array( $this->getRequest()->getInt( 'enrolled' ), $courseIds ) ) { |
127 | | - $course = EPCourse::selectRow( array( 'name', 'org_id' ), array( 'id' => $this->getRequest()->getInt( 'enrolled' ) ) ); |
| 127 | + $course = EPCourses::singleton()->selectRow( |
| 128 | + array( 'name', 'org_id' ), |
| 129 | + array( 'id' => $this->getRequest()->getInt( 'enrolled' ) ) |
| 130 | + ); |
128 | 131 | |
129 | 132 | $this->showSuccess( wfMessage( |
130 | 133 | 'ep-mycourses-enrolled', |
Index: trunk/extensions/EducationProgram/specials/SpecialDisenroll.php |
— | — | @@ -38,7 +38,7 @@ |
39 | 39 | $this->showWarning( wfMessage( 'ep-disenroll-no-name' ) ); |
40 | 40 | } |
41 | 41 | else { |
42 | | - $course = EPCourse::get( $args[0] ); |
| 42 | + $course = EPCourses::singleton()->get( $args[0] ); |
43 | 43 | |
44 | 44 | if ( $course === false ) { |
45 | 45 | $this->showWarning( wfMessage( 'ep-disenroll-invalid-name', $subPage ) ); |
Index: trunk/extensions/EducationProgram/specials/SpecialEnroll.php |
— | — | @@ -51,7 +51,7 @@ |
52 | 52 | $this->showWarning( wfMessage( 'ep-enroll-no-id' ) ); |
53 | 53 | } |
54 | 54 | else { |
55 | | - $course = EPCourse::get( $args[0] ); |
| 55 | + $course = EPCourses::singleton()->get( $args[0] ); |
56 | 56 | |
57 | 57 | if ( $course === false ) { |
58 | 58 | $this->showWarning( wfMessage( 'ep-enroll-invalid-id' ) ); |
Index: trunk/extensions/EducationProgram/specials/SpecialEducationProgram.php |
— | — | @@ -75,12 +75,12 @@ |
76 | 76 | |
77 | 77 | $lang = $this->getLanguage(); |
78 | 78 | |
79 | | - $data['org-count'] = $lang->formatNum( EPOrg::count() ); |
80 | | - $data['course-count'] = $lang->formatNum( EPCourse::count() ); |
81 | | - $data['student-count'] = $lang->formatNum( EPStudent::count() ); |
82 | | - $data['instructor-count'] = $lang->formatNum( EPInstructor::count() ); |
83 | | - $data['oa-count'] = $lang->formatNum( EPOA::count() ); |
84 | | - $data['ca-count'] = $lang->formatNum( EPCA::count() ); |
| 79 | + $data['org-count'] = $lang->formatNum( EPOrgs::singleton()->count() ); |
| 80 | + $data['course-count'] = $lang->formatNum( EPCourses::singleton()->count() ); |
| 81 | + $data['student-count'] = $lang->formatNum( EPStudents::singleton()->count() ); |
| 82 | + $data['instructor-count'] = $lang->formatNum( EPInstructors::singleton()->count() ); |
| 83 | + $data['oa-count'] = $lang->formatNum( EPOAs::singleton()->count() ); |
| 84 | + $data['ca-count'] = $lang->formatNum( EPCAs::singleton()->count() ); |
85 | 85 | |
86 | 86 | return $data; |
87 | 87 | } |
Index: trunk/extensions/EducationProgram/includes/EPPageTable.php |
— | — | @@ -114,7 +114,7 @@ |
115 | 115 | * (non-PHPdoc) |
116 | 116 | * @see EPRevisionedObject::getLogInfo() |
117 | 117 | */ |
118 | | - protected function getLogInfoForTitle( Title $title ) { |
| 118 | + public function getLogInfoForTitle( Title $title ) { |
119 | 119 | return array( |
120 | 120 | 'type' => self::$info[get_called_class()]['log-type'], |
121 | 121 | 'title' => $title, |
Index: trunk/extensions/EducationProgram/includes/EPRoleObject.php |
— | — | @@ -153,8 +153,8 @@ |
154 | 154 | $field = $fieldMap[$this->getRoleName()]; |
155 | 155 | |
156 | 156 | if ( count( $courseIds ) > 0 ) { |
157 | | - EPOrg::updateSummaryFields( $field, array( 'id' => array_unique( $courseIds ) ) ); |
158 | | - EPCourse::updateSummaryFields( $field, array( 'id' => $courseIds ) ); |
| 157 | + EPOrgs::singleton()->updateSummaryFields( $field, array( 'id' => array_unique( $courseIds ) ) ); |
| 158 | + EPCourses::singleton()->updateSummaryFields( $field, array( 'id' => $courseIds ) ); |
159 | 159 | } |
160 | 160 | |
161 | 161 | return $success; |
Index: trunk/extensions/EducationProgram/includes/EPRevisions.php |
— | — | @@ -66,4 +66,37 @@ |
67 | 67 | ); |
68 | 68 | } |
69 | 69 | |
| 70 | + /** |
| 71 | + * Create a new revision object for the provided EPRevisionedObject. |
| 72 | + * The EPRevisionedObject should have all it's fields loaded. |
| 73 | + * |
| 74 | + * @since 0.1 |
| 75 | + * |
| 76 | + * @param DBDataObject $object |
| 77 | + * @param EPRevisionAction $revAction |
| 78 | + * |
| 79 | + * @return EPRevision |
| 80 | + */ |
| 81 | + public function newFromObject( EPRevisionedObject $object, EPRevisionAction $revAction ) { |
| 82 | + $fields = array( |
| 83 | + 'object_id' => $object->getId(), |
| 84 | + 'user_id' => $revAction->getUser()->getID(), |
| 85 | + 'user_text' => $revAction->getUser()->getName(), |
| 86 | + 'type' => get_class( $object ), |
| 87 | + 'comment' => $revAction->getComment(), |
| 88 | + 'minor_edit' => $revAction->isMinor(), |
| 89 | + 'time' => $revAction->getTime(), |
| 90 | + 'deleted' => $revAction->isDelete(), |
| 91 | + 'data' => serialize( $object->toArray() ) |
| 92 | + ); |
| 93 | + |
| 94 | + $identifier = $object->getIdentifier(); |
| 95 | + |
| 96 | + if ( !is_null( $identifier ) ) { |
| 97 | + $fields['object_identifier'] = $identifier; |
| 98 | + } |
| 99 | + |
| 100 | + return new EPRevision( $this, $fields ); |
| 101 | + } |
| 102 | + |
70 | 103 | } |
Index: trunk/extensions/EducationProgram/includes/EPCourses.php |
— | — | @@ -121,4 +121,14 @@ |
122 | 122 | ); |
123 | 123 | } |
124 | 124 | |
| 125 | + public function hasActiveName( $courseName ) { |
| 126 | + $now = wfGetDB( DB_SLAVE )->addQuotes( wfTimestampNow() ); |
| 127 | + |
| 128 | + return $this->has( array( |
| 129 | + 'name' => $courseName, |
| 130 | + 'end >= ' . $now, |
| 131 | + 'start <= ' . $now, |
| 132 | + ) ); |
| 133 | + } |
| 134 | + |
125 | 135 | } |
Index: trunk/extensions/EducationProgram/includes/EPOrg.php |
— | — | @@ -36,7 +36,7 @@ |
37 | 37 | $fields = array(); |
38 | 38 | |
39 | 39 | if ( in_array( 'course_count', $summaryFields ) ) { |
40 | | - $fields['course_count'] = EPCourse::count( array( 'org_id' => $this->getId() ) ); |
| 40 | + $fields['course_count'] = EPCourses::singleton()->count( array( 'org_id' => $this->getId() ) ); |
41 | 41 | } |
42 | 42 | |
43 | 43 | $dbr = wfGetDB( DB_SLAVE ); |
— | — | @@ -44,7 +44,7 @@ |
45 | 45 | if ( in_array( 'active', $summaryFields ) ) { |
46 | 46 | $now = $dbr->addQuotes( wfTimestampNow() ); |
47 | 47 | |
48 | | - $fields['active'] = EPCourse::has( array( |
| 48 | + $fields['active'] = EPCourses::singleton()->has( array( |
49 | 49 | 'org_id' => $this->getId(), |
50 | 50 | 'end >= ' . $now, |
51 | 51 | 'start <= ' . $now, |
— | — | @@ -52,9 +52,9 @@ |
53 | 53 | } |
54 | 54 | |
55 | 55 | foreach ( array( 'student_count', 'instructor_count', 'oa_count', 'ca_count' ) as $field ) { |
56 | | - $fields[$field] = EPCourse::rawSelectRow( |
57 | | - array( 'SUM(' . EPCourse::getPrefixedField( $field ). ') AS sum' ), |
58 | | - EPCourse::getPrefixedValues( array( |
| 56 | + $fields[$field] = EPCourses::singleton()->rawSelectRow( |
| 57 | + array( 'SUM(' . EPCourses::singleton()->getPrefixedField( $field ). ') AS sum' ), |
| 58 | + EPCourses::singleton()->getPrefixedValues( array( |
59 | 59 | 'org_id' => $this->getId() |
60 | 60 | ) ) |
61 | 61 | )->sum; |
— | — | @@ -68,7 +68,7 @@ |
69 | 69 | * @see EPRevisionedObject::onRemoved() |
70 | 70 | */ |
71 | 71 | protected function onRemoved() { |
72 | | - foreach ( EPCourse::select( null, array( 'org_id' => $this->getId() ) ) as /* EPCourse */ $course ) { |
| 72 | + foreach ( EPCourses::singleton()->select( null, array( 'org_id' => $this->getId() ) ) as /* EPCourse */ $course ) { |
73 | 73 | $revAction = clone $this->revAction; |
74 | 74 | |
75 | 75 | if ( trim( $revAction->getComment() ) === '' ) { |
— | — | @@ -201,7 +201,7 @@ |
202 | 202 | */ |
203 | 203 | public function getCourses( array $fields = null ) { |
204 | 204 | if ( $this->courses === false ) { |
205 | | - $this->courses = EPCourse::select( $fields, array( 'org_id' => $this->getId() ) ); |
| 205 | + $this->courses = EPCourses::singleton()->select( $fields, array( 'org_id' => $this->getId() ) ); |
206 | 206 | } |
207 | 207 | |
208 | 208 | return $this->courses; |
Index: trunk/extensions/EducationProgram/includes/EPRevisionedObject.php |
— | — | @@ -101,7 +101,7 @@ |
102 | 102 | */ |
103 | 103 | protected function storeRevision( EPRevisionedObject $object ) { |
104 | 104 | if ( $this->storeRevisions && $this->revAction !== false ) { |
105 | | - return EPRevision::newFromObject( $object, $this->revAction )->save(); |
| 105 | + return EPRevisions::singleton()->newFromObject( $object, $this->revAction )->save(); |
106 | 106 | } |
107 | 107 | |
108 | 108 | return true; |
— | — | @@ -136,9 +136,9 @@ |
137 | 137 | */ |
138 | 138 | protected function saveExisting() { |
139 | 139 | if ( !$this->inSummaryMode ) { |
140 | | - static::setReadDb( DB_MASTER ); |
141 | | - $originalObject = static::selectRow( null, array( 'id' => $this->getId() ) ); |
142 | | - static::setReadDb( DB_SLAVE ); |
| 140 | + $this->table->setReadDb( DB_MASTER ); |
| 141 | + $originalObject = $this->table->selectRow( null, array( 'id' => $this->getId() ) ); |
| 142 | + $this->table->setReadDb( DB_SLAVE ); |
143 | 143 | |
144 | 144 | if ( $originalObject === false ) { |
145 | 145 | return false; |
Index: trunk/extensions/EducationProgram/includes/EPRevision.php |
— | — | @@ -22,51 +22,6 @@ |
23 | 23 | protected $user = false; |
24 | 24 | |
25 | 25 | /** |
26 | | - * @see parent::__construct |
27 | | - * |
28 | | - * @since 0.1 |
29 | | - * |
30 | | - * @param array|null $fields |
31 | | - * @param bool $loadDefaults |
32 | | - */ |
33 | | - public function __construct( $fields = null, $loadDefaults = false ) { |
34 | | - parent::__construct( $fields, $loadDefaults ); |
35 | | - } |
36 | | - |
37 | | - /** |
38 | | - * Create a new revision object for the provided EPRevisionedObject. |
39 | | - * The EPRevisionedObject should have all it's fields loaded. |
40 | | - * |
41 | | - * @since 0.1 |
42 | | - * |
43 | | - * @param DBDataObject $object |
44 | | - * @param EPRevisionAction $revAction |
45 | | - * |
46 | | - * @return EPRevision |
47 | | - */ |
48 | | - public static function newFromObject( EPRevisionedObject $object, EPRevisionAction $revAction ) { |
49 | | - $fields = array( |
50 | | - 'object_id' => $object->getId(), |
51 | | - 'user_id' => $revAction->getUser()->getID(), |
52 | | - 'user_text' => $revAction->getUser()->getName(), |
53 | | - 'type' => get_class( $object ), |
54 | | - 'comment' => $revAction->getComment(), |
55 | | - 'minor_edit' => $revAction->isMinor(), |
56 | | - 'time' => $revAction->getTime(), |
57 | | - 'deleted' => $revAction->isDelete(), |
58 | | - 'data' => serialize( $object->toArray() ) |
59 | | - ); |
60 | | - |
61 | | - $identifier = $object->getIdentifier(); |
62 | | - |
63 | | - if ( !is_null( $identifier ) ) { |
64 | | - $fields['object_identifier'] = $identifier; |
65 | | - } |
66 | | - |
67 | | - return new static( $fields ); |
68 | | - } |
69 | | - |
70 | | - /** |
71 | 26 | * Return the object as it was at this revision. |
72 | 27 | * |
73 | 28 | * @since 0,1 |
Index: trunk/extensions/EducationProgram/includes/EPCourse.php |
— | — | @@ -124,7 +124,7 @@ |
125 | 125 | $success = parent::insert(); |
126 | 126 | |
127 | 127 | if ( $success && $this->updateSummaries ) { |
128 | | - EPOrg::updateSummaryFields( array( 'course_count', 'active' ), array( 'id' => $this->getField( 'org_id' ) ) ); |
| 128 | + EPOrgs::singleton()->updateSummaryFields( array( 'course_count', 'active' ), array( 'id' => $this->getField( 'org_id' ) ) ); |
129 | 129 | } |
130 | 130 | |
131 | 131 | return $success; |
— | — | @@ -136,7 +136,7 @@ |
137 | 137 | */ |
138 | 138 | protected function onRemoved() { |
139 | 139 | if ( $this->updateSummaries ) { |
140 | | - EPOrg::updateSummaryFields( null, array( 'id' => $this->getField( 'org_id' ) ) ); |
| 140 | + EPOrgs::singleton()->updateSummaryFields( null, array( 'id' => $this->getField( 'org_id' ) ) ); |
141 | 141 | } |
142 | 142 | |
143 | 143 | wfGetDB( DB_MASTER )->delete( 'ep_users_per_course', array( 'upc_course_id' => $this->getId() ) ); |
— | — | @@ -203,10 +203,10 @@ |
204 | 204 | if ( $this->updateSummaries ) { |
205 | 205 | if ( $this->hasField( 'org_id' ) && $originalCourse->getField( 'org_id' ) !== $this->getField( 'org_id' ) ) { |
206 | 206 | $conds = array( 'id' => array( $originalCourse->getField( 'org_id' ), $this->getField( 'org_id' ) ) ); |
207 | | - EPOrg::updateSummaryFields( null, $conds ); |
| 207 | + EPOrgs::singleton()->updateSummaryFields( null, $conds ); |
208 | 208 | } |
209 | 209 | else if ( !empty( $changedSummaries ) ) { |
210 | | - EPOrg::updateSummaryFields( $changedSummaries, array( 'id' => $originalCourse->getField( 'org_id' ) ) ); |
| 210 | + EPOrgs::singleton()->updateSummaryFields( $changedSummaries, array( 'id' => $originalCourse->getField( 'org_id' ) ) ); |
211 | 211 | } |
212 | 212 | } |
213 | 213 | |
— | — | @@ -243,7 +243,7 @@ |
244 | 244 | */ |
245 | 245 | public function getOrg( $fields = null ) { |
246 | 246 | if ( $this->org === false ) { |
247 | | - $this->org = EPOrg::selectRow( $fields, array( 'id' => $this->loadAndGetField( 'org_id' ) ) ); |
| 247 | + $this->org = EPOrgs::singleton()->selectRow( $fields, array( 'id' => $this->loadAndGetField( 'org_id' ) ) ); |
248 | 248 | } |
249 | 249 | |
250 | 250 | return $this->org; |
— | — | @@ -701,15 +701,5 @@ |
702 | 702 | |
703 | 703 | EPUtils::log( $info ); |
704 | 704 | } |
705 | | - |
706 | | - public static function hasActiveName( $courseName ) { |
707 | | - $now = wfGetDB( DB_SLAVE )->addQuotes( wfTimestampNow() ); |
708 | | - |
709 | | - return EPCourses::singleton()->has( array( |
710 | | - 'name' => $courseName, |
711 | | - 'end >= ' . $now, |
712 | | - 'start <= ' . $now, |
713 | | - ) ); |
714 | | - } |
715 | 705 | |
716 | 706 | } |
Index: trunk/extensions/EducationProgram/api/ApiRefreshEducation.php |
— | — | @@ -22,8 +22,8 @@ |
23 | 23 | * @var array |
24 | 24 | */ |
25 | 25 | protected static $typeMap = array( |
26 | | - 'org' => 'EPOrg', |
27 | | - 'course' => 'EPCourse', |
| 26 | + 'org' => 'EPOrsg', |
| 27 | + 'course' => 'EPCourses', |
28 | 28 | ); |
29 | 29 | |
30 | 30 | public function execute() { |
— | — | @@ -34,7 +34,7 @@ |
35 | 35 | } |
36 | 36 | |
37 | 37 | $c = self::$typeMap[$params['type']]; |
38 | | - $c::updateSummaryFields( null, array( 'id' => $params['ids'] ) ); |
| 38 | + $c::singleton()->updateSummaryFields( null, array( 'id' => $params['ids'] ) ); |
39 | 39 | |
40 | 40 | $this->getResult()->addValue( |
41 | 41 | null, |
Index: trunk/extensions/EducationProgram/api/ApiEnlist.php |
— | — | @@ -46,7 +46,7 @@ |
47 | 47 | |
48 | 48 | $field = $roleMap[$params['role']]; |
49 | 49 | |
50 | | - $course = EPCourse::selectRow( array( 'id', 'name', $field ), array( 'id' => $params['courseid'] ) ); |
| 50 | + $course = EPCourses::singleton()->selectRow( array( 'id', 'name', $field ), array( 'id' => $params['courseid'] ) ); |
51 | 51 | |
52 | 52 | if ( $course === false ) { |
53 | 53 | $this->dieUsage( wfMsg( 'ep-enlist-invalid-course' ), 'invalid-course' ); |
Index: trunk/extensions/EducationProgram/EducationProgram.hooks.php |
— | — | @@ -207,7 +207,7 @@ |
208 | 208 | $textParts[1] = implode( '/', $textParts[1] ); |
209 | 209 | } |
210 | 210 | |
211 | | - $title = EPCourse::getTitleFor( $textParts[1] ); |
| 211 | + $title = EPCourses::singleton()->getTitleFor( $textParts[1] ); |
212 | 212 | |
213 | 213 | if ( !is_null( $title ) ) { |
214 | 214 | self::displayTabs( $sktemplate, $links, $title ); |
— | — | @@ -272,7 +272,7 @@ |
273 | 273 | $hasCourse = $student !== false && $student->hasCourse( array( 'name' => $title->getText() ) ); |
274 | 274 | |
275 | 275 | if ( $user->isAllowed( 'ep-enroll' ) ) { |
276 | | - if ( !$hasCourse && EPCourse::hasActiveName( $title->getText() ) ) { |
| 276 | + if ( !$hasCourse && EPCourses::singleton()->hasActiveName( $title->getText() ) ) { |
277 | 277 | $links['views']['enroll'] = array( |
278 | 278 | 'class' => $isSpecial ? 'selected' : false, |
279 | 279 | 'text' => wfMsg( 'ep-tab-enroll' ), |
— | — | @@ -281,7 +281,7 @@ |
282 | 282 | } |
283 | 283 | } |
284 | 284 | |
285 | | - if ( $hasCourse && EPCourse::hasActiveName( $title->getText() ) ) { |
| 285 | + if ( $hasCourse && EPCourses::singleton()->hasActiveName( $title->getText() ) ) { |
286 | 286 | $links[$isSpecial ? 'views' : 'actions']['disenroll'] = array( |
287 | 287 | 'class' => $isSpecial ? 'selected' : false, |
288 | 288 | 'text' => wfMsg( 'ep-tab-disenroll' ), |