Index: trunk/extensions/EducationProgram/sql/EducationProgram.sql |
— | — | @@ -16,7 +16,8 @@ |
17 | 17 | org_instructor_count SMALLINT unsigned NOT NULL, -- Amount of instructors |
18 | 18 | org_oa_count INT unsigned NOT NULL, -- Amount of online ambassadors |
19 | 19 | org_ca_count INT unsigned NOT NULL, -- Amount of campus ambassadors |
20 | | - org_student_count INT unsigned NOT NULL -- Amount of students |
| 20 | + org_student_count INT unsigned NOT NULL, -- Amount of students |
| 21 | + org_courses BLOB NOT NULL -- The ids of the courses (linking ep_courses.course_id) |
21 | 22 | ) /*$wgDBTableOptions*/; |
22 | 23 | |
23 | 24 | CREATE UNIQUE INDEX /*i*/ep_org_name ON /*_*/ep_orgs (org_name); |
Index: trunk/extensions/EducationProgram/sql/AddCoursesField.sql |
— | — | @@ -0,0 +1,7 @@ |
| 2 | +-- MySQL patch for the Education Program extension. |
| 3 | +-- Licence: GNU GPL v3+ |
| 4 | +-- Author: Jeroen De Dauw < jeroendedauw@gmail.com > |
| 5 | + |
| 6 | +ALTER TABLE /*_*/ep_orgs ADD COLUMN org_courses BLOB NOT NULL; |
| 7 | + |
| 8 | +UPDATE /*_*/ep_orgs SET org_courses = 'a:0:{}'; -- Serialized empty array |
\ No newline at end of file |
Property changes on: trunk/extensions/EducationProgram/sql/AddCoursesField.sql |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 9 | + native |
Index: trunk/extensions/EducationProgram/actions/ViewCourseAction.php |
— | — | @@ -26,10 +26,18 @@ |
27 | 27 | parent::__construct( $page, $context, EPCourses::singleton() ); |
28 | 28 | } |
29 | 29 | |
| 30 | + /** |
| 31 | + * (non-PHPdoc) |
| 32 | + * @see Action::getName() |
| 33 | + */ |
30 | 34 | public function getName() { |
31 | 35 | return 'viewcourse'; |
32 | 36 | } |
33 | 37 | |
| 38 | + /** |
| 39 | + * (non-PHPdoc) |
| 40 | + * @see EPViewAction::displayPage() |
| 41 | + */ |
34 | 42 | protected function displayPage( DBDataObject $course ) { |
35 | 43 | parent::displayPage( $course ); |
36 | 44 | |
— | — | @@ -205,4 +213,4 @@ |
206 | 214 | } |
207 | 215 | } |
208 | 216 | |
209 | | -} |
\ No newline at end of file |
| 217 | +} |
Index: trunk/extensions/EducationProgram/actions/ViewOrgAction.php |
— | — | @@ -26,10 +26,18 @@ |
27 | 27 | parent::__construct( $page, $context, EPOrgs::singleton() ); |
28 | 28 | } |
29 | 29 | |
| 30 | + /** |
| 31 | + * (non-PHPdoc) |
| 32 | + * @see Action::getName() |
| 33 | + */ |
30 | 34 | public function getName() { |
31 | 35 | return 'vieworg'; |
32 | 36 | } |
33 | 37 | |
| 38 | + /** |
| 39 | + * (non-PHPdoc) |
| 40 | + * @see EPViewAction::displayPage() |
| 41 | + */ |
34 | 42 | protected function displayPage( DBDataObject $org ) { |
35 | 43 | parent::displayPage( $org ); |
36 | 44 | |
— | — | @@ -85,4 +93,4 @@ |
86 | 94 | return $stats; |
87 | 95 | } |
88 | 96 | |
89 | | -} |
\ No newline at end of file |
| 97 | +} |
Index: trunk/extensions/EducationProgram/actions/EPUndeleteAction.php |
— | — | @@ -49,8 +49,9 @@ |
50 | 50 | |
51 | 51 | if ( $object === false ) { |
52 | 52 | $revision = EPRevisions::singleton()->getLatestRevision( array( |
53 | | - 'object_identifier' => $this->getTitle()->getText() |
54 | | - ) ); |
| 53 | + 'object_identifier' => $this->getTitle()->getText(), |
| 54 | + 'type' => $this->page->getTable()->getDataObjectClass(), |
| 55 | + ) ); |
55 | 56 | |
56 | 57 | if ( $revision === false ) { |
57 | 58 | $query = array( 'undeletefailed' => 'norevs' ); // TODO: handle |
Index: trunk/extensions/EducationProgram/includes/EPOrgs.php |
— | — | @@ -63,6 +63,7 @@ |
64 | 64 | 'instructor_count' => 'int', |
65 | 65 | 'ca_count' => 'int', |
66 | 66 | 'oa_count' => 'int', |
| 67 | + 'courses' => 'array', |
67 | 68 | ); |
68 | 69 | } |
69 | 70 | |
— | — | @@ -84,6 +85,7 @@ |
85 | 86 | 'instructor_count' => 0, |
86 | 87 | 'ca_count' => 0, |
87 | 88 | 'oa_count' => 0, |
| 89 | + 'courses' => array(), |
88 | 90 | ); |
89 | 91 | } |
90 | 92 | |
— | — | @@ -112,6 +114,7 @@ |
113 | 115 | 'instructor_count', |
114 | 116 | 'oa_count', |
115 | 117 | 'ca_count', |
| 118 | + 'courses', |
116 | 119 | ); |
117 | 120 | } |
118 | 121 | |
Index: trunk/extensions/EducationProgram/includes/EPRevisionAction.php |
— | — | @@ -1,5 +1,18 @@ |
2 | 2 | <?php |
3 | 3 | |
| 4 | +/** |
| 5 | + * Class representing a single revision action. |
| 6 | + * This can be any kind of change creating a new revision, |
| 7 | + * such as page creation, edits, deletion and reverts. |
| 8 | + * |
| 9 | + * @since 0.1 |
| 10 | + * |
| 11 | + * @file EPRevisionAction.php |
| 12 | + * @ingroup EducationProgram |
| 13 | + * |
| 14 | + * @licence GNU GPL v3 or later |
| 15 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 16 | + */ |
4 | 17 | class EPRevisionAction { |
5 | 18 | |
6 | 19 | protected $user; |
— | — | @@ -8,49 +21,82 @@ |
9 | 22 | protected $comment = ''; |
10 | 23 | protected $time = false; |
11 | 24 | |
12 | | - public function __construct() { |
13 | | - |
14 | | - } |
15 | | - |
| 25 | + /** |
| 26 | + * @since 0.1 |
| 27 | + * @return boolean |
| 28 | + */ |
16 | 29 | public function isMinor() { |
17 | 30 | return $this->isMinor; |
18 | 31 | } |
19 | 32 | |
| 33 | + /** |
| 34 | + * @since 0.1 |
| 35 | + * @return boolean |
| 36 | + */ |
20 | 37 | public function isDelete() { |
21 | 38 | return $this->isDelete; |
22 | 39 | } |
23 | 40 | |
| 41 | + /** |
| 42 | + * @since 0.1 |
| 43 | + * @return string |
| 44 | + */ |
24 | 45 | public function getComment() { |
25 | 46 | return $this->comment; |
26 | 47 | } |
27 | 48 | |
28 | 49 | /** |
| 50 | + * @since 0.1 |
29 | 51 | * @return User |
30 | 52 | */ |
31 | 53 | public function getUser() { |
32 | 54 | return $this->user; |
33 | 55 | } |
34 | 56 | |
| 57 | + /** |
| 58 | + * @since 0.1 |
| 59 | + * @return string |
| 60 | + */ |
35 | 61 | public function getTime() { |
36 | 62 | return $this->time === false ? wfTimestampNow() : $this->time; |
37 | 63 | } |
38 | 64 | |
| 65 | + /** |
| 66 | + * @since 0.1 |
| 67 | + * @param User $user |
| 68 | + */ |
39 | 69 | public function setUser( User $user ) { |
40 | 70 | $this->user = $user; |
41 | 71 | } |
42 | 72 | |
| 73 | + /** |
| 74 | + * @since 0.1 |
| 75 | + * @param string $comment |
| 76 | + */ |
43 | 77 | public function setComment( $comment ) { |
44 | 78 | $this->comment = $comment; |
45 | 79 | } |
46 | 80 | |
| 81 | + /** |
| 82 | + * @since 0.1 |
| 83 | + * @param boolean $isDelete |
| 84 | + */ |
47 | 85 | public function setDelete( $isDelete ) { |
48 | 86 | $this->isDelete = $isDelete; |
49 | 87 | } |
50 | 88 | |
| 89 | + /** |
| 90 | + * @since 0.1 |
| 91 | + * @param boolean $isMinor |
| 92 | + */ |
51 | 93 | public function setMinor( $isMinor ) { |
52 | 94 | $this->isMinor = $isMinor; |
53 | 95 | } |
54 | 96 | |
| 97 | + /** |
| 98 | + * @since 0.1 |
| 99 | + * @param string $time |
| 100 | + */ |
55 | 101 | public function setTime( $time ) { |
56 | 102 | $this->time = $time; |
57 | 103 | } |
Index: trunk/extensions/EducationProgram/includes/EPOrg.php |
— | — | @@ -27,7 +27,7 @@ |
28 | 28 | */ |
29 | 29 | public function loadSummaryFields( $summaryFields = null ) { |
30 | 30 | if ( is_null( $summaryFields ) ) { |
31 | | - $summaryFields = array( 'course_count', 'active', 'student_count', 'instructor_count', 'oa_count', 'ca_count' ); |
| 31 | + $summaryFields = array( 'course_count', 'active', 'student_count', 'instructor_count', 'oa_count', 'ca_count', 'courses' ); |
32 | 32 | } |
33 | 33 | else { |
34 | 34 | $summaryFields = (array)$summaryFields; |
— | — | @@ -35,8 +35,9 @@ |
36 | 36 | |
37 | 37 | $fields = array(); |
38 | 38 | |
39 | | - if ( in_array( 'course_count', $summaryFields ) ) { |
40 | | - $fields['course_count'] = EPCourses::singleton()->count( array( 'org_id' => $this->getId() ) ); |
| 39 | + if ( in_array( 'course_count', $summaryFields ) || in_array( 'courses', $summaryFields ) ) { |
| 40 | + $fields['courses'] = EPCourses::singleton()->selectFields( 'id', array( 'org_id' => $this->getId() ) ); |
| 41 | + $fields['course_count'] = count( $fields['courses'] ); |
41 | 42 | } |
42 | 43 | |
43 | 44 | $dbr = wfGetDB( DB_SLAVE ); |
— | — | @@ -104,6 +105,34 @@ |
105 | 106 | |
106 | 107 | return parent::save(); |
107 | 108 | } |
| 109 | + |
| 110 | + /** |
| 111 | + * (non-PHPdoc) |
| 112 | + * @see EPRevisionedObject::undelete() |
| 113 | + */ |
| 114 | + public function undelete( EPRevisionAction $revAction ) { |
| 115 | + $success = parent::undelete( $revAction ); |
| 116 | + |
| 117 | + if ( $success ) { |
| 118 | + $courseRevAction = new EPRevisionAction(); |
| 119 | + |
| 120 | + $courseRevAction->setUser( $revAction->getUser() ); |
| 121 | + $courseRevAction->setComment( '' ); // TODO |
| 122 | + |
| 123 | + foreach ( $this->getField( 'courses' ) as $courseId ) { |
| 124 | + $courseRevision = EPRevisions::singleton()->getLatestRevision( array( |
| 125 | + 'object_id' => $courseId, |
| 126 | + 'type' => 'EPCourse', |
| 127 | + ) ); |
| 128 | + |
| 129 | + if ( $courseRevision !== false ) { |
| 130 | + $courseRevision->getObject()->undelete( $courseRevAction ); |
| 131 | + } |
| 132 | + } |
| 133 | + } |
| 134 | + |
| 135 | + return $success; |
| 136 | + } |
108 | 137 | |
109 | 138 | /** |
110 | 139 | * Adds a control to add a new org to the provided context. |
— | — | @@ -201,10 +230,14 @@ |
202 | 231 | */ |
203 | 232 | public function getCourses( array $fields = null ) { |
204 | 233 | if ( $this->courses === false ) { |
205 | | - $this->courses = EPCourses::singleton()->select( $fields, array( 'org_id' => $this->getId() ) ); |
| 234 | + $courses = EPCourses::singleton()->select( $fields, array( 'org_id' => $this->getId() ) ); |
| 235 | + |
| 236 | + if ( is_null( $fields ) ) { |
| 237 | + $this->courses = $courses; |
| 238 | + } |
206 | 239 | } |
207 | 240 | |
208 | | - return $this->courses; |
| 241 | + return $this->courses === false ? $courses : $courses; |
209 | 242 | } |
210 | 243 | |
211 | 244 | } |
Index: trunk/extensions/EducationProgram/includes/EPRevisionedObject.php |
— | — | @@ -193,7 +193,7 @@ |
194 | 194 | * @since 0.1 |
195 | 195 | */ |
196 | 196 | protected function onRemoved() { |
197 | | - //$this->storeRevision( $this ); |
| 197 | + $this->storeRevision( $this ); |
198 | 198 | $this->log( 'remove' ); |
199 | 199 | parent::onRemoved(); |
200 | 200 | } |
Index: trunk/extensions/EducationProgram/EducationProgram.hooks.php |
— | — | @@ -29,20 +29,13 @@ |
30 | 30 | dirname( __FILE__ ) . '/sql/EducationProgram.sql' |
31 | 31 | ); |
32 | 32 | |
33 | | -// $updater->addExtensionUpdate( array( |
34 | | -// 'addField', |
35 | | -// 'ep_revisions', |
36 | | -// 'rev_object_identifier', |
37 | | -// dirname( __FILE__ ) . '/sql/AddRevIdentifier.sql', |
38 | | -// true |
39 | | -// ) ); |
40 | | -// |
41 | | -// $updater->addExtensionUpdate( array( |
42 | | -// 'addTable', |
43 | | -// 'ep_users_per_course', |
44 | | -// dirname( __FILE__ ) . '/sql/UpdateUserLinks.sql', |
45 | | -// true |
46 | | -// ) ); |
| 33 | + $updater->addExtensionUpdate( array( |
| 34 | + 'addField', |
| 35 | + 'ep_orgs', |
| 36 | + 'org_courses', |
| 37 | + dirname( __FILE__ ) . '/sql/AddCoursesField.sql', |
| 38 | + true |
| 39 | + ) ); |
47 | 40 | |
48 | 41 | return true; |
49 | 42 | } |