Index: trunk/extensions/EducationProgram/EducationProgram.php |
— | — | @@ -96,6 +96,7 @@ |
97 | 97 | $wgAutoloadClasses['EPFailForm'] = dirname( __FILE__ ) . '/includes/EPFailForm.php'; |
98 | 98 | $wgAutoloadClasses['EPIRole'] = dirname( __FILE__ ) . '/includes/EPIRole.php'; |
99 | 99 | $wgAutoloadClasses['EPRevisionedObject'] = dirname( __FILE__ ) . '/includes/EPRevisionedObject.php'; |
| 100 | +$wgAutoloadClasses['EPRoleObject'] = dirname( __FILE__ ) . '/includes/EPRoleObject.php'; |
100 | 101 | |
101 | 102 | $wgAutoloadClasses['CoursePage'] = dirname( __FILE__ ) . '/pages/CoursePage.php'; |
102 | 103 | $wgAutoloadClasses['EPPage'] = dirname( __FILE__ ) . '/pages/EPPage.php'; |
— | — | @@ -152,6 +153,8 @@ |
153 | 154 | $egEPDBObjects['EPOA'] = array( 'table' => 'ep_oas', 'prefix' => 'oa_' ); |
154 | 155 | $egEPDBObjects['EPCA'] = array( 'table' => 'ep_cas', 'prefix' => 'ca_' ); |
155 | 156 | $egEPDBObjects[] = array( 'table' => 'ep_students_per_course', 'prefix' => 'spc_' ); |
| 157 | +$egEPDBObjects[] = array( 'table' => 'ep_oas_per_course', 'prefix' => 'opc_' ); |
| 158 | +$egEPDBObjects[] = array( 'table' => 'ep_cas_per_course', 'prefix' => 'cpc_' ); |
156 | 159 | |
157 | 160 | // API |
158 | 161 | $wgAPIModules['deleteeducation'] = 'ApiDeleteEducation'; |
Index: trunk/extensions/EducationProgram/sql/EducationProgram.sql |
— | — | @@ -40,9 +40,9 @@ |
41 | 41 | course_start varbinary(14) NOT NULL, -- Start time of the course |
42 | 42 | course_end varbinary(14) NOT NULL, -- End time of the course |
43 | 43 | course_description TEXT NOT NULL, -- Description of the course |
44 | | - course_online_ambs BLOB NOT NULL, -- List of associated online ambassadors (linking ep_oas.oa_id) |
45 | | - course_campus_ambs BLOB NOT NULL, -- List of associated campus ambassadors (linking ep_cas.ca_id) |
46 | | - course_instructors BLOB NOT NULL, -- List of associated instructors (linking ep_instructors.instructor_id) |
| 44 | + course_online_ambs BLOB NOT NULL, -- List of associated online ambassadors (linking user.user_id) |
| 45 | + course_campus_ambs BLOB NOT NULL, -- List of associated campus ambassadors (linking user.user_id) |
| 46 | + course_instructors BLOB NOT NULL, -- List of associated instructors (linking user.user_id) |
47 | 47 | course_token VARCHAR(255) NOT NULL, -- Token needed to enroll |
48 | 48 | course_field VARCHAR(255) NOT NULL, -- Field of study |
49 | 49 | course_level VARCHAR(255) NOT NULL, -- Study level |
— | — | @@ -139,11 +139,11 @@ |
140 | 140 | -- Links the campus ambassadors with all their courses. |
141 | 141 | -- The is secondary storage for queries. The canonical data is in ep_course.campus_ambs |
142 | 142 | CREATE TABLE IF NOT EXISTS /*_*/ep_cas_per_course ( |
143 | | - cpc_ca_id INT unsigned NOT NULL, -- Foreign key on ep_cas.ca_id |
| 143 | + cpc_user_id INT unsigned NOT NULL, -- Foreign key on user.user_id |
144 | 144 | cpc_course_id INT unsigned NOT NULL -- Foreign key on ep_course.course_id |
145 | 145 | ) /*$wgDBTableOptions*/; |
146 | 146 | |
147 | | -CREATE UNIQUE INDEX /*i*/ep_cas_per_course ON /*_*/ep_cas_per_course (cpc_ca_id, cpc_course_id); |
| 147 | +CREATE UNIQUE INDEX /*i*/ep_cas_per_course ON /*_*/ep_cas_per_course (cpc_user_id, cpc_course_id); |
148 | 148 | |
149 | 149 | |
150 | 150 | |
— | — | @@ -163,11 +163,11 @@ |
164 | 164 | -- Links the online ambassadors with all their courses. |
165 | 165 | -- The is secondary storage for queries. The canonical data is in ep_course.online_ambs |
166 | 166 | CREATE TABLE IF NOT EXISTS /*_*/ep_oas_per_course ( |
167 | | - opc_oa_id INT unsigned NOT NULL, -- Foreign key on ep_oas.oa_id |
| 167 | + opc_user_id INT unsigned NOT NULL, -- Foreign key on user.user_id |
168 | 168 | opc_course_id INT unsigned NOT NULL -- Foreign key on ep_course.course_id |
169 | 169 | ) /*$wgDBTableOptions*/; |
170 | 170 | |
171 | | -CREATE UNIQUE INDEX /*i*/ep_oas_per_course ON /*_*/ep_oas_per_course (opc_oa_id, opc_course_id); |
| 171 | +CREATE UNIQUE INDEX /*i*/ep_oas_per_course ON /*_*/ep_oas_per_course (opc_user_id, opc_course_id); |
172 | 172 | |
173 | 173 | |
174 | 174 | |
Index: trunk/extensions/EducationProgram/sql/RenameAmbUserField.sql |
— | — | @@ -0,0 +1,6 @@ |
| 2 | +-- MySQL for the Education Program extension. |
| 3 | +-- Licence: GNU GPL v3+ |
| 4 | +-- Author: Jeroen De Dauw < jeroendedauw@gmail.com > |
| 5 | + |
| 6 | +ALTER TABLE /*_*/ep_cas_per_course CHANGE `cpc_ca_id` `cpc_user_id` INT( 10 ) UNSIGNED NOT NULL; |
| 7 | +ALTER TABLE /*_*/ep_oas_per_course CHANGE `opc_oa_id` `opc_user_id` INT( 10 ) UNSIGNED NOT NULL; |
\ No newline at end of file |
Property changes on: trunk/extensions/EducationProgram/sql/RenameAmbUserField.sql |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 8 | + native |
Index: trunk/extensions/EducationProgram/specials/SpecialMyCourses.php |
— | — | @@ -35,23 +35,35 @@ |
36 | 36 | public function execute( $subPage ) { |
37 | 37 | parent::execute( $subPage ); |
38 | 38 | |
39 | | - if ( $this->getUser()->isAllowed( 'ep-org' ) ) { |
40 | | - $this->displayNavigation(); |
41 | | - } |
42 | | - |
43 | | - if ( $this->subPage === '' ) { |
44 | | - $this->displayCourses(); |
45 | | - } |
46 | | - else { |
47 | | - $course = EPCourse::selectRow( null, array( 'name' => $this->subPage ) ); |
| 39 | + if ( $this->getUser()->isLoggedIn() ) { |
| 40 | + if ( $this->getUser()->isAllowed( 'ep-org' ) ) { |
| 41 | + $this->displayNavigation(); |
| 42 | + } |
48 | 43 | |
49 | | - if ( $course === false ) { |
50 | | - |
| 44 | + if ( $this->subPage === '' ) { |
| 45 | + $this->displayCourses(); |
51 | 46 | } |
52 | 47 | else { |
53 | | - $this->displayCourse( $course ); |
54 | | - } |
| 48 | + $course = EPCourse::selectRow( null, array( 'name' => $this->subPage ) ); |
| 49 | + |
| 50 | + if ( $course === false ) { |
| 51 | + // TODO |
| 52 | + } |
| 53 | + else { |
| 54 | + $this->displayCourse( $course ); |
| 55 | + } |
| 56 | + } |
55 | 57 | } |
| 58 | + else { |
| 59 | + $this->getOutput()->addHTML( Linker::linkKnown( |
| 60 | + SpecialPage::getTitleFor( 'Userlogin' ), |
| 61 | + wfMsgHtml( 'ep-mycourses-login-first' ), |
| 62 | + array(), |
| 63 | + array( |
| 64 | + 'returnto' => $this->getTitle( $this->subPage )->getFullText() |
| 65 | + ) |
| 66 | + ) ); |
| 67 | + } |
56 | 68 | } |
57 | 69 | |
58 | 70 | /** |
— | — | @@ -76,11 +88,11 @@ |
77 | 89 | } |
78 | 90 | |
79 | 91 | if ( $this->getUser()->isAllowed( 'ep-online' ) ) { |
80 | | - $this->displayOnlineMentorship(); |
| 92 | + $this->displayMentorship( 'EPOA' ); |
81 | 93 | } |
82 | 94 | |
83 | 95 | if ( $this->getUser()->isAllowed( 'ep-campus' ) ) { |
84 | | - $this->displayCampusMentorship(); |
| 96 | + $this->displayMentorship( 'EPCA' ); |
85 | 97 | } |
86 | 98 | } |
87 | 99 | |
— | — | @@ -91,47 +103,53 @@ |
92 | 104 | |
93 | 105 | $student = EPStudent::newFromUser( $this->getUser() ); |
94 | 106 | |
95 | | - if ( $student !== false ) { |
96 | | - $courses = $student->getCourses( 'id' ); |
| 107 | + $courses = $student->getCourses( 'id' ); |
| 108 | + |
| 109 | + $courseIds = array_map( |
| 110 | + function( EPCourse $course ) { |
| 111 | + return $course->getId(); |
| 112 | + }, |
| 113 | + $courses |
| 114 | + ); |
| 115 | + |
| 116 | + if ( $this->getRequest()->getCheck( 'enrolled' ) && in_array( $this->getRequest()->getInt( 'enrolled' ), $courseIds ) ) { |
| 117 | + $course = EPCourse::selectRow( array( 'name', 'org_id' ), array( 'id' => $this->getRequest()->getInt( 'enrolled' ) ) ); |
97 | 118 | |
98 | | - $courseIds = array_map( |
99 | | - function( EPCourse $course ) { |
100 | | - return $course->getId(); |
101 | | - }, |
102 | | - $courses |
103 | | - ); |
104 | | - |
105 | | - if ( $this->getRequest()->getCheck( 'enrolled' ) && in_array( $this->getRequest()->getInt( 'enrolled' ), $courseIds ) ) { |
106 | | - $course = EPCourse::selectRow( array( 'name', 'org_id' ), array( 'id' => $this->getRequest()->getInt( 'enrolled' ) ) ); |
107 | | - |
108 | | - $this->showSuccess( wfMessage( |
109 | | - 'ep-mycourses-enrolled', |
110 | | - $course->getField( 'name' ), |
111 | | - $course->getOrg()->getField( 'name' ) |
112 | | - ) ); |
113 | | - } |
114 | | - |
115 | | - if ( count( $courseIds ) === 0 ) { |
116 | | - // TODO |
117 | | - } |
118 | | - elseif ( count( $courseIds ) === 1 ) { |
119 | | - $course = $courses[0]; |
120 | | - $course->loadFields(); |
121 | | - $this->displayCourse( $course ); |
122 | | - } |
123 | | - else { |
124 | | - $this->getOutput()->addElement( 'h2', array(), wfMsg( 'ep-mycourses-enrollment' ) ); |
125 | | - EPCourse::displayPager( $this->getContext(), array( 'id' => $courseIds ) ); |
126 | | - } |
| 119 | + $this->showSuccess( wfMessage( |
| 120 | + 'ep-mycourses-enrolled', |
| 121 | + $course->getField( 'name' ), |
| 122 | + $course->getOrg()->getField( 'name' ) |
| 123 | + ) ); |
127 | 124 | } |
128 | | - } |
129 | | - |
130 | | - protected function displayOnlineMentorship() { |
131 | 125 | |
| 126 | + if ( count( $courseIds ) === 1 ) { |
| 127 | + $course = $courses[0]; |
| 128 | + $course->loadFields(); |
| 129 | + $this->displayCourse( $course ); |
| 130 | + } |
| 131 | + elseif ( count( $courseIds ) > 1 ) { |
| 132 | + $this->getOutput()->addElement( 'h2', array(), wfMsg( 'ep-mycourses-enrollment' ) ); |
| 133 | + EPCourse::displayPager( $this->getContext(), array( 'id' => $courseIds ), true ); |
| 134 | + } |
132 | 135 | } |
133 | 136 | |
134 | | - protected function displayCampusMentorship() { |
| 137 | + protected function displayMentorship( $class ) { |
| 138 | + $ambassador = $class::newFromUser( $this->getUser() ); |
135 | 139 | |
| 140 | + $courseIds = array_map( |
| 141 | + function( EPCourse $course ) { |
| 142 | + return $course->getId(); |
| 143 | + }, |
| 144 | + $ambassador->getCourses( 'id' ) |
| 145 | + ); |
| 146 | + |
| 147 | + if ( count( $courseIds ) > 0 ) { |
| 148 | + $this->getOutput()->addElement( 'h2', array(), wfMsg( 'ep-mycourses-ambcourses-' . strtolower( $class ) ) ); |
| 149 | + EPCourse::displayPager( $this->getContext(), array( 'id' => $courseIds ), true ); |
| 150 | + } |
| 151 | + else { |
| 152 | + $this->getOutput()->addWikiMsg( 'ep-mycourses-noambcourses-' . strtolower( $class ) ); |
| 153 | + } |
136 | 154 | } |
137 | 155 | |
138 | 156 | protected function displayInstructorship() { |
Index: trunk/extensions/EducationProgram/includes/EPIRole.php |
— | — | @@ -19,10 +19,11 @@ |
20 | 20 | * @since 0.1 |
21 | 21 | * |
22 | 22 | * @param integer $userId |
| 23 | + * @param null|array|string $fields |
23 | 24 | * |
24 | 25 | * @return EPIRole |
25 | 26 | */ |
26 | | - public static function newFromUserId( $userId ); |
| 27 | + public static function newFromUserId( $userId, $fields = null ); |
27 | 28 | |
28 | 29 | /** |
29 | 30 | * Create a new role object from a user object. |
— | — | @@ -30,10 +31,11 @@ |
31 | 32 | * @since 0.1 |
32 | 33 | * |
33 | 34 | * @param User $user |
| 35 | + * @param null|array|string $fields |
34 | 36 | * |
35 | 37 | * @return EPIRole |
36 | 38 | */ |
37 | | - public static function newFromUser( User $user ); |
| 39 | + public static function newFromUser( User $user, $fields = null ); |
38 | 40 | |
39 | 41 | |
40 | 42 | /** |
Index: trunk/extensions/EducationProgram/includes/EPInstructor.php |
— | — | @@ -11,7 +11,7 @@ |
12 | 12 | * @licence GNU GPL v3 or later |
13 | 13 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
14 | 14 | */ |
15 | | -class EPInstructor implements EPIRole { |
| 15 | +class EPInstructor extends EPRoleObject implements EPIRole { |
16 | 16 | |
17 | 17 | /** |
18 | 18 | * Field for caching the linked user. |
— | — | @@ -35,10 +35,11 @@ |
36 | 36 | * @since 0.1 |
37 | 37 | * |
38 | 38 | * @param integer $userId |
| 39 | + * @param null|array|string $fields |
39 | 40 | * |
40 | 41 | * @return EPInstructor |
41 | 42 | */ |
42 | | - public static function newFromUserId( $userId ) { |
| 43 | + public static function newFromUserId( $userId, $fields = null ) { |
43 | 44 | return new self( $userId ); |
44 | 45 | } |
45 | 46 | |
— | — | @@ -48,10 +49,11 @@ |
49 | 50 | * @since 0.1 |
50 | 51 | * |
51 | 52 | * @param User $user |
| 53 | + * @param null|array|string $fields |
52 | 54 | * |
53 | 55 | * @return EPInstructor |
54 | 56 | */ |
55 | | - public static function newFromUser( User $user ) { |
| 57 | + public static function newFromUser( User $user, $fields = null ) { |
56 | 58 | return new self( $user ); |
57 | 59 | } |
58 | 60 | |
— | — | @@ -136,5 +138,21 @@ |
137 | 139 | public function getRoleName() { |
138 | 140 | return 'instructor'; |
139 | 141 | } |
| 142 | + |
| 143 | + /** |
| 144 | + * Not implemented as we do not need this, so no need for having it in the |
| 145 | + * db in a way we can efficiently query this. If needed at some point, |
| 146 | + * most stuff is in place already since the ambassador stuff is similar. |
| 147 | + * |
| 148 | + * @since 0.1 |
| 149 | + * |
| 150 | + * @param string|array|null $fields |
| 151 | + * @param array $conditions |
| 152 | + * |
| 153 | + * @return array of EPCourse |
| 154 | + */ |
| 155 | + protected function doGetCourses( $fields, array $conditions ) { |
| 156 | + throw new MWException( 'doGetCourses is not implemented by EPInstructor' ); |
| 157 | + } |
140 | 158 | |
141 | 159 | } |
Index: trunk/extensions/EducationProgram/includes/EPCoursePager.php |
— | — | @@ -14,12 +14,22 @@ |
15 | 15 | class EPCoursePager extends EPPager { |
16 | 16 | |
17 | 17 | /** |
| 18 | + * When in read only mode, the pager should not show any course editing controls. |
| 19 | + * |
| 20 | + * @since 0.1 |
| 21 | + * @var boolean |
| 22 | + */ |
| 23 | + protected $readOnlyMode; |
| 24 | + |
| 25 | + /** |
18 | 26 | * Constructor. |
19 | 27 | * |
20 | 28 | * @param IContextSource $context |
21 | 29 | * @param array $conds |
| 30 | + * @param boolean $readOnlyMode |
22 | 31 | */ |
23 | | - public function __construct( IContextSource $context, array $conds = array() ) { |
| 32 | + public function __construct( IContextSource $context, array $conds = array(), $readOnlyMode = false ) { |
| 33 | + $this->readOnlyMode = $readOnlyMode; |
24 | 34 | parent::__construct( $context, $conds, 'EPCourse' ); |
25 | 35 | } |
26 | 36 | |
— | — | @@ -177,7 +187,7 @@ |
178 | 188 | |
179 | 189 | $links[] = $item->getLink( 'view', wfMsgHtml( 'view' ) ); |
180 | 190 | |
181 | | - if ( $this->getUser()->isAllowed( 'ep-course' ) ) { |
| 191 | + if ( !$this->readOnlyMode && $this->getUser()->isAllowed( 'ep-course' ) ) { |
182 | 192 | $links[] = $item->getLink( |
183 | 193 | 'edit', |
184 | 194 | wfMsgHtml( 'edit' ), |
— | — | @@ -201,7 +211,7 @@ |
202 | 212 | protected function getMultipleItemActions() { |
203 | 213 | $actions = parent::getMultipleItemActions(); |
204 | 214 | |
205 | | - if ( $this->getUser()->isAllowed( 'ep-course' ) ) { |
| 215 | + if ( !$this->readOnlyMode && $this->getUser()->isAllowed( 'ep-course' ) ) { |
206 | 216 | $actions[wfMsg( 'ep-pager-delete-selected' )] = array( |
207 | 217 | 'class' => 'ep-pager-delete-selected', |
208 | 218 | 'data-type' => ApiDeleteEducation::getTypeForClassName( $this->className ) |
— | — | @@ -239,5 +249,13 @@ |
240 | 250 | |
241 | 251 | return $conds; |
242 | 252 | } |
| 253 | + |
| 254 | + /** |
| 255 | + * (non-PHPdoc) |
| 256 | + * @see EPPager::hasActionsColumn() |
| 257 | + */ |
| 258 | + protected function hasActionsColumn() { |
| 259 | + return !$this->readOnlyMode; |
| 260 | + } |
243 | 261 | |
244 | 262 | } |
Index: trunk/extensions/EducationProgram/includes/EPCA.php |
— | — | @@ -11,45 +11,9 @@ |
12 | 12 | * @licence GNU GPL v3 or later |
13 | 13 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
14 | 14 | */ |
15 | | -class EPCA extends EPDBObject implements EPIRole { |
| 15 | +class EPCA extends EPRoleObject implements EPIRole { |
16 | 16 | |
17 | 17 | /** |
18 | | - * Field for caching the linked user. |
19 | | - * |
20 | | - * @since 0.1 |
21 | | - * @var User|false |
22 | | - */ |
23 | | - protected $user = false; |
24 | | - |
25 | | - /** |
26 | | - * Create a new instructor object from a user id. |
27 | | - * |
28 | | - * @since 0.1 |
29 | | - * |
30 | | - * @param integer $userId |
31 | | - * |
32 | | - * @return EPCA |
33 | | - */ |
34 | | - public static function newFromUserId( $userId ) { |
35 | | - $data = array( 'user_id' => $userId ); |
36 | | - $ca = static::selectRow( null, $data ); |
37 | | - return $ca === false ? new static( $data, true ) : $ca; |
38 | | - } |
39 | | - |
40 | | - /** |
41 | | - * Create a new instructor object from a User object. |
42 | | - * |
43 | | - * @since 0.1 |
44 | | - * |
45 | | - * @param User $user |
46 | | - * |
47 | | - * @return EPCA|false |
48 | | - */ |
49 | | - public static function newFromUser( User $user ) { |
50 | | - return self::newFromUserId( $user->getId() ); |
51 | | - } |
52 | | - |
53 | | - /** |
54 | 18 | * @see parent::getFieldTypes |
55 | 19 | * |
56 | 20 | * @since 0.1 |
— | — | @@ -76,32 +40,6 @@ |
77 | 41 | 'photo' => '', |
78 | 42 | ); |
79 | 43 | } |
80 | | - |
81 | | - /** |
82 | | - * Returns the user that this instructor is. |
83 | | - * |
84 | | - * @since 0.1 |
85 | | - * |
86 | | - * @return User |
87 | | - */ |
88 | | - public function getUser() { |
89 | | - if ( $this->user === false ) { |
90 | | - $this->user = User::newFromId( $this->getField( 'user_id' ) ); |
91 | | - } |
92 | | - |
93 | | - return $this->user; |
94 | | - } |
95 | | - |
96 | | - /** |
97 | | - * Returns the name of the instroctor, using their real name when available. |
98 | | - * |
99 | | - * @since 0.1 |
100 | | - * |
101 | | - * @return string |
102 | | - */ |
103 | | - public function getName() { |
104 | | - return $this->getUser()->getRealName() === '' ? $this->getUser()->getName() : $this->getUser()->getRealName(); |
105 | | - } |
106 | 44 | |
107 | 45 | /** |
108 | 46 | * Display a pager with campus ambassadors. |
— | — | @@ -130,21 +68,7 @@ |
131 | 69 | } |
132 | 70 | |
133 | 71 | /** |
134 | | - * Returns the tool links for this ambassador. |
135 | | - * |
136 | 72 | * @since 0.1 |
137 | | - * |
138 | | - * @param IContextSource $context |
139 | | - * @param EPCourse|null $course |
140 | | - * |
141 | | - * @return string |
142 | | - */ |
143 | | - public function getToolLinks( IContextSource $context, EPCourse $course = null ) { |
144 | | - return EPUtils::getRoleToolLinks( $this, $context, $course ); |
145 | | - } |
146 | | - |
147 | | - /** |
148 | | - * @since 0.1 |
149 | 73 | * @see EPIRole::getRoleName |
150 | 74 | */ |
151 | 75 | public function getRoleName() { |
— | — | @@ -152,17 +76,25 @@ |
153 | 77 | } |
154 | 78 | |
155 | 79 | /** |
156 | | - * Retruns the user link for this ambassador, using their real name when available. |
157 | | - * |
| 80 | + * Returns the courses this campus ambassdor is associated with. |
| 81 | + * |
158 | 82 | * @since 0.1 |
159 | | - * |
160 | | - * @return string |
| 83 | + * |
| 84 | + * @param string|array|null $fields |
| 85 | + * @param array $conditions |
| 86 | + * |
| 87 | + * @return array of EPCourse |
161 | 88 | */ |
162 | | - public function getUserLink() { |
163 | | - return Linker::userLink( |
164 | | - $this->getUser()->getId(), |
165 | | - $this->getUser()->getName(), |
166 | | - $this->getName() |
| 89 | + protected function doGetCourses( $fields, array $conditions ) { |
| 90 | + $conditions[] = array( array( 'ep_cas_per_course', 'user_id' ), $this->getField( 'user_id' ) ); |
| 91 | + |
| 92 | + return EPCourse::select( |
| 93 | + $fields, |
| 94 | + $conditions, |
| 95 | + array(), |
| 96 | + array( |
| 97 | + 'ep_cas_per_course' => array( 'INNER JOIN', array( array( array( 'ep_cas_per_course', 'course_id' ), array( 'ep_courses', 'id' ) ) ) ), |
| 98 | + ) |
167 | 99 | ); |
168 | 100 | } |
169 | 101 | |
Index: trunk/extensions/EducationProgram/includes/EPStudent.php |
— | — | @@ -11,25 +11,9 @@ |
12 | 12 | * @licence GNU GPL v3 or later |
13 | 13 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
14 | 14 | */ |
15 | | -class EPStudent extends EPDBObject { |
| 15 | +class EPStudent extends EPRoleObject { |
16 | 16 | |
17 | 17 | /** |
18 | | - * Cached array of the linked EPCourse objects. |
19 | | - * |
20 | | - * @since 0.1 |
21 | | - * @var array|false |
22 | | - */ |
23 | | - protected $courses = false; |
24 | | - |
25 | | - /** |
26 | | - * Cached user object of the user that is this student. |
27 | | - * |
28 | | - * @since 0.1 |
29 | | - * @var User|false |
30 | | - */ |
31 | | - protected $user = false; |
32 | | - |
33 | | - /** |
34 | 18 | * @see parent::getFieldTypes |
35 | 19 | * |
36 | 20 | * @since 0.1 |
— | — | @@ -49,114 +33,37 @@ |
50 | 34 | } |
51 | 35 | |
52 | 36 | /** |
53 | | - * Get the student object of a user, or false if there is none. |
| 37 | + * Display a pager with students. |
54 | 38 | * |
55 | 39 | * @since 0.1 |
56 | 40 | * |
57 | | - * @param User $user |
58 | | - * @param string|array|null $fields |
59 | | - * |
60 | | - * @return EPStudent|false |
61 | | - */ |
62 | | - public static function newFromUser( User $user, $fields = null ) { |
63 | | - return self::selectRow( $fields, array( 'user_id' => $user->getId() ) ); |
64 | | - } |
65 | | - |
66 | | - /** |
67 | | - * Associate the student with the provided courses. |
68 | | - * |
69 | | - * @since 0.1 |
70 | | - * |
71 | | - * @param array $courses |
72 | | - * |
73 | | - * @return bool |
74 | | - */ |
75 | | - public function associateWithCourses( array /* of EPCourse */ $courses ) { |
76 | | - $dbw = wfGetDB( DB_MASTER ); |
77 | | - |
78 | | - $success = true; |
79 | | - |
80 | | - $dbw->begin(); |
81 | | - |
82 | | - foreach ( $courses as /* EPCourse */ $course ) { |
83 | | - $success = $dbw->insert( |
84 | | - 'ep_students_per_course', |
85 | | - array( |
86 | | - 'spc_student_id' => $this->getId(), |
87 | | - 'spc_course_id' => $course->getId(), |
88 | | - ) |
89 | | - ) && $success; |
90 | | - } |
91 | | - |
92 | | - $dbw->commit(); |
93 | | - |
94 | | - foreach ( $courses as /* EPCourse */ $course ) { |
95 | | - EPOrg::updateSummaryFields( 'students', array( 'id' => $course->getField( 'org_id' ) ) ); |
96 | | - EPCourse::updateSummaryFields( 'students', array( 'id' => $course->getId() ) ); |
97 | | - } |
98 | | - |
99 | | - return $success; |
100 | | - } |
101 | | - |
102 | | - /** |
103 | | - * Returns the courses this student is enrolled in. |
104 | | - * Caches the result when no conditions are provided and all fields are selected. |
105 | | - * |
106 | | - * @since 0.1 |
107 | | - * |
108 | | - * @param string|array|null $fields |
| 41 | + * @param IContextSource $context |
109 | 42 | * @param array $conditions |
110 | | - * |
111 | | - * @return array of EPCourse |
112 | 43 | */ |
113 | | - public function getCourses( $fields = null, array $conditions = array() ) { |
114 | | - if ( count( $conditions ) !== 0 ) { |
115 | | - return $this->doGetCourses( $fields, $conditions ); |
116 | | - } |
| 44 | + public static function displayPager( IContextSource $context, array $conditions = array() ) { |
| 45 | + $pager = new EPStudentPager( $context, $conditions ); |
117 | 46 | |
118 | | - if ( $this->courses === false ) { |
119 | | - $courses = $this->doGetCourses( $fields, $conditions ); |
120 | | - |
121 | | - if ( is_null( $fields ) ) { |
122 | | - $this->courses = $courses; |
123 | | - } |
124 | | - |
125 | | - return $courses; |
| 47 | + if ( $pager->getNumRows() ) { |
| 48 | + $context->getOutput()->addHTML( |
| 49 | + $pager->getFilterControl() . |
| 50 | + $pager->getNavigationBar() . |
| 51 | + $pager->getBody() . |
| 52 | + $pager->getNavigationBar() . |
| 53 | + $pager->getMultipleItemControl() |
| 54 | + ); |
126 | 55 | } |
127 | 56 | else { |
128 | | - return $this->courses; |
| 57 | + $context->getOutput()->addHTML( $pager->getFilterControl( true ) ); |
| 58 | + $context->getOutput()->addWikiMsg( 'ep-students-noresults' ); |
129 | 59 | } |
130 | 60 | } |
131 | 61 | |
132 | 62 | /** |
133 | | - * Get the courses with a certain state. |
134 | | - * States can be 'current', 'passed' and 'planned' |
135 | | - * |
136 | 63 | * @since 0.1 |
137 | | - * |
138 | | - * @param string $state |
139 | | - * @param array|null $fields |
140 | | - * @param array $conditions |
141 | | - * |
142 | | - * @return array of EPCourse |
| 64 | + * @see EPIRole::getRoleName |
143 | 65 | */ |
144 | | - public function getCoursesWithState( $state, $fields = null, array $conditions = array() ) { |
145 | | - $now = wfGetDB( DB_SLAVE )->addQuotes( wfTimestampNow() ); |
146 | | - |
147 | | - switch ( $state ) { |
148 | | - case 'passed': |
149 | | - $conditions[] = 'end < ' . $now; |
150 | | - break; |
151 | | - case 'planned': |
152 | | - $conditions[] = 'start > ' . $now; |
153 | | - break; |
154 | | - case 'current': |
155 | | - $conditions[] = 'end >= ' . $now; |
156 | | - $conditions[] = 'start <= ' . $now; |
157 | | - break; |
158 | | - } |
159 | | - |
160 | | - return $this->getCourses( $fields, $conditions ); |
| 66 | + public function getRoleName() { |
| 67 | + return 'student'; |
161 | 68 | } |
162 | 69 | |
163 | 70 | /** |
— | — | @@ -182,70 +89,5 @@ |
183 | 90 | ) |
184 | 91 | ); |
185 | 92 | } |
186 | | - |
187 | | - /** |
188 | | - * Returns if the student has any course matching the provided conditions. |
189 | | - * |
190 | | - * @since 0.1 |
191 | | - * |
192 | | - * @param array $conditions |
193 | | - * |
194 | | - * @return boolean |
195 | | - */ |
196 | | - public function hasCourse( array $conditions = array() ) { |
197 | | - return count( $this->getCourses( 'id', $conditions ) ) > 0; |
198 | | - } |
199 | | - |
200 | | - /** |
201 | | - * Display a pager with students. |
202 | | - * |
203 | | - * @since 0.1 |
204 | | - * |
205 | | - * @param IContextSource $context |
206 | | - * @param array $conditions |
207 | | - */ |
208 | | - public static function displayPager( IContextSource $context, array $conditions = array() ) { |
209 | | - $pager = new EPStudentPager( $context, $conditions ); |
210 | | - |
211 | | - if ( $pager->getNumRows() ) { |
212 | | - $context->getOutput()->addHTML( |
213 | | - $pager->getFilterControl() . |
214 | | - $pager->getNavigationBar() . |
215 | | - $pager->getBody() . |
216 | | - $pager->getNavigationBar() . |
217 | | - $pager->getMultipleItemControl() |
218 | | - ); |
219 | | - } |
220 | | - else { |
221 | | - $context->getOutput()->addHTML( $pager->getFilterControl( true ) ); |
222 | | - $context->getOutput()->addWikiMsg( 'ep-students-noresults' ); |
223 | | - } |
224 | | - } |
225 | | - |
226 | | - /** |
227 | | - * Returns the user that is this student. |
228 | | - * |
229 | | - * @since 0.1 |
230 | | - * |
231 | | - * @return User |
232 | | - */ |
233 | | - public function getUser() { |
234 | | - if ( $this->user === false ) { |
235 | | - $this->user = User::newFromId( $this->loadAndGetField( 'user_id' ) ); |
236 | | - } |
237 | | - |
238 | | - return $this->user; |
239 | | - } |
240 | | - |
241 | | - /** |
242 | | - * Returns the display name for the student. |
243 | | - * |
244 | | - * @since 0.1 |
245 | | - * |
246 | | - * @return String |
247 | | - */ |
248 | | - public function getName() { |
249 | | - return $this->getUser()->getRealName() === '' ? $this->user->getName() : $this->user->getRealName(); |
250 | | - } |
251 | | - |
| 93 | + |
252 | 94 | } |
Index: trunk/extensions/EducationProgram/includes/EPRoleObject.php |
— | — | @@ -0,0 +1,239 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Object representing a user in a certain role linked to courses. |
| 6 | + * |
| 7 | + * @since 0.1 |
| 8 | + * |
| 9 | + * @file EPRoleObject.php |
| 10 | + * @ingroup EducationProgram |
| 11 | + * |
| 12 | + * @licence GNU GPL v3 or later |
| 13 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 14 | + */ |
| 15 | +abstract class EPRoleObject extends EPDBObject implements EPIRole { |
| 16 | + |
| 17 | + /** |
| 18 | + * Field for caching the linked user. |
| 19 | + * |
| 20 | + * @since 0.1 |
| 21 | + * @var User|false |
| 22 | + */ |
| 23 | + protected $user = false; |
| 24 | + |
| 25 | + /** |
| 26 | + * Cached array of the linked EPCourse objects. |
| 27 | + * |
| 28 | + * @since 0.1 |
| 29 | + * @var array|false |
| 30 | + */ |
| 31 | + protected $courses = false; |
| 32 | + |
| 33 | + /** |
| 34 | + * Create a new instructor object from a user id. |
| 35 | + * |
| 36 | + * @since 0.1 |
| 37 | + * |
| 38 | + * @param integer $userId |
| 39 | + * @param null|array|string $fields |
| 40 | + * |
| 41 | + * @return EPRoleObject |
| 42 | + */ |
| 43 | + public static function newFromUserId( $userId, $fields = null ) { |
| 44 | + $data = array( 'user_id' => $userId ); |
| 45 | + $userRole = static::selectRow( null, $data ); |
| 46 | + return $userRole === false ? new static( $data, true ) : $userRole; |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * Create a new instructor object from a User object. |
| 51 | + * |
| 52 | + * @since 0.1 |
| 53 | + * |
| 54 | + * @param User $user |
| 55 | + * @param null|array|string $fields |
| 56 | + * |
| 57 | + * @return EPRoleObject |
| 58 | + */ |
| 59 | + public static function newFromUser( User $user, $fields = null ) { |
| 60 | + return static::newFromUserId( $user->getId(), $fields ); |
| 61 | + } |
| 62 | + |
| 63 | + /** |
| 64 | + * Returns the user that this instructor is. |
| 65 | + * |
| 66 | + * @since 0.1 |
| 67 | + * |
| 68 | + * @return User |
| 69 | + */ |
| 70 | + public function getUser() { |
| 71 | + if ( $this->user === false ) { |
| 72 | + $this->user = User::newFromId( $this->getField( 'user_id' ) ); |
| 73 | + } |
| 74 | + |
| 75 | + return $this->user; |
| 76 | + } |
| 77 | + |
| 78 | + /** |
| 79 | + * Returns the name of the instroctor, using their real name when available. |
| 80 | + * |
| 81 | + * @since 0.1 |
| 82 | + * |
| 83 | + * @return string |
| 84 | + */ |
| 85 | + public function getName() { |
| 86 | + return $this->getUser()->getRealName() === '' ? $this->getUser()->getName() : $this->getUser()->getRealName(); |
| 87 | + } |
| 88 | + |
| 89 | + /** |
| 90 | + * Returns the tool links for this ambassador. |
| 91 | + * |
| 92 | + * @since 0.1 |
| 93 | + * |
| 94 | + * @param IContextSource $context |
| 95 | + * @param EPCourse|null $course |
| 96 | + * |
| 97 | + * @return string |
| 98 | + */ |
| 99 | + public function getToolLinks( IContextSource $context, EPCourse $course = null ) { |
| 100 | + return EPUtils::getRoleToolLinks( $this, $context, $course ); |
| 101 | + } |
| 102 | + |
| 103 | + /** |
| 104 | + * Retruns the user link for this ambassador, using their real name when available. |
| 105 | + * |
| 106 | + * @since 0.1 |
| 107 | + * |
| 108 | + * @return string |
| 109 | + */ |
| 110 | + public function getUserLink() { |
| 111 | + return Linker::userLink( |
| 112 | + $this->getUser()->getId(), |
| 113 | + $this->getUser()->getName(), |
| 114 | + $this->getName() |
| 115 | + ); |
| 116 | + } |
| 117 | + |
| 118 | + /** |
| 119 | + * Associate the student with the provided courses. |
| 120 | + * |
| 121 | + * @since 0.1 |
| 122 | + * |
| 123 | + * @param array $courses |
| 124 | + * |
| 125 | + * @return bool |
| 126 | + */ |
| 127 | + public function associateWithCourses( array /* of EPCourse */ $courses ) { |
| 128 | + $dbw = wfGetDB( DB_MASTER ); |
| 129 | + |
| 130 | + $success = true; |
| 131 | + |
| 132 | + $dbw->begin(); |
| 133 | + |
| 134 | + foreach ( $courses as /* EPCourse */ $course ) { |
| 135 | + $success = $dbw->insert( |
| 136 | + 'ep_students_per_course', |
| 137 | + array( |
| 138 | + 'spc_student_id' => $this->getId(), |
| 139 | + 'spc_course_id' => $course->getId(), |
| 140 | + ) |
| 141 | + ) && $success; |
| 142 | + } |
| 143 | + |
| 144 | + $dbw->commit(); |
| 145 | + |
| 146 | + foreach ( $courses as /* EPCourse */ $course ) { |
| 147 | + EPOrg::updateSummaryFields( 'students', array( 'id' => $course->getField( 'org_id' ) ) ); |
| 148 | + EPCourse::updateSummaryFields( 'students', array( 'id' => $course->getId() ) ); |
| 149 | + } |
| 150 | + |
| 151 | + return $success; |
| 152 | + } |
| 153 | + |
| 154 | + /** |
| 155 | + * Returns the courses this student is enrolled in. |
| 156 | + * Caches the result when no conditions are provided and all fields are selected. |
| 157 | + * |
| 158 | + * @since 0.1 |
| 159 | + * |
| 160 | + * @param string|array|null $fields |
| 161 | + * @param array $conditions |
| 162 | + * |
| 163 | + * @return array of EPCourse |
| 164 | + */ |
| 165 | + public function getCourses( $fields = null, array $conditions = array() ) { |
| 166 | + if ( count( $conditions ) !== 0 ) { |
| 167 | + return $this->doGetCourses( $fields, $conditions ); |
| 168 | + } |
| 169 | + |
| 170 | + if ( $this->courses === false ) { |
| 171 | + $courses = $this->doGetCourses( $fields, $conditions ); |
| 172 | + |
| 173 | + if ( is_null( $fields ) ) { |
| 174 | + $this->courses = $courses; |
| 175 | + } |
| 176 | + |
| 177 | + return $courses; |
| 178 | + } |
| 179 | + else { |
| 180 | + return $this->courses; |
| 181 | + } |
| 182 | + } |
| 183 | + |
| 184 | + /** |
| 185 | + * Get the courses with a certain state. |
| 186 | + * States can be 'current', 'passed' and 'planned' |
| 187 | + * |
| 188 | + * @since 0.1 |
| 189 | + * |
| 190 | + * @param string $state |
| 191 | + * @param array|null $fields |
| 192 | + * @param array $conditions |
| 193 | + * |
| 194 | + * @return array of EPCourse |
| 195 | + */ |
| 196 | + public function getCoursesWithState( $state, $fields = null, array $conditions = array() ) { |
| 197 | + $now = wfGetDB( DB_SLAVE )->addQuotes( wfTimestampNow() ); |
| 198 | + |
| 199 | + switch ( $state ) { |
| 200 | + case 'passed': |
| 201 | + $conditions[] = 'end < ' . $now; |
| 202 | + break; |
| 203 | + case 'planned': |
| 204 | + $conditions[] = 'start > ' . $now; |
| 205 | + break; |
| 206 | + case 'current': |
| 207 | + $conditions[] = 'end >= ' . $now; |
| 208 | + $conditions[] = 'start <= ' . $now; |
| 209 | + break; |
| 210 | + } |
| 211 | + |
| 212 | + return $this->getCourses( $fields, $conditions ); |
| 213 | + } |
| 214 | + |
| 215 | + /** |
| 216 | + * Returns if the student has any course matching the provided conditions. |
| 217 | + * |
| 218 | + * @since 0.1 |
| 219 | + * |
| 220 | + * @param array $conditions |
| 221 | + * |
| 222 | + * @return boolean |
| 223 | + */ |
| 224 | + public function hasCourse( array $conditions = array() ) { |
| 225 | + return count( $this->getCourses( 'id', $conditions ) ) > 0; |
| 226 | + } |
| 227 | + |
| 228 | + /** |
| 229 | + * Returns the courses this user is associated with. |
| 230 | + * |
| 231 | + * @since 0.1 |
| 232 | + * |
| 233 | + * @param string|array|null $fields |
| 234 | + * @param array $conditions |
| 235 | + * |
| 236 | + * @return array of EPCourse |
| 237 | + */ |
| 238 | + protected abstract function doGetCourses( $fields, array $conditions ); |
| 239 | + |
| 240 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/EducationProgram/includes/EPRoleObject.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 241 | + native |
Index: trunk/extensions/EducationProgram/includes/EPOA.php |
— | — | @@ -11,45 +11,9 @@ |
12 | 12 | * @licence GNU GPL v3 or later |
13 | 13 | * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
14 | 14 | */ |
15 | | -class EPOA extends EPDBObject implements EPIRole { |
16 | | - |
17 | | - /** |
18 | | - * Field for caching the linked user. |
19 | | - * |
20 | | - * @since 0.1 |
21 | | - * @var User|false |
22 | | - */ |
23 | | - protected $user = false; |
24 | | - |
25 | | - /** |
26 | | - * Create a new instructor object from a user id. |
27 | | - * |
28 | | - * @since 0.1 |
29 | | - * |
30 | | - * @param integer $userId |
31 | | - * |
32 | | - * @return EPCA |
33 | | - */ |
34 | | - public static function newFromUserId( $userId ) { |
35 | | - $data = array( 'user_id' => $userId ); |
36 | | - $oa = static::selectRow( null, $data ); |
37 | | - return $oa === false ? new static( $data, true ) : $oa; |
38 | | - } |
| 15 | +class EPOA extends EPRoleObject implements EPIRole { |
39 | 16 | |
40 | 17 | /** |
41 | | - * Create a new instructor object from a User object. |
42 | | - * |
43 | | - * @since 0.1 |
44 | | - * |
45 | | - * @param User $user |
46 | | - * |
47 | | - * @return EPCA|false |
48 | | - */ |
49 | | - public static function newFromUser( User $user ) { |
50 | | - return self::newFromUserId( $user->getId() ); |
51 | | - } |
52 | | - |
53 | | - /** |
54 | 18 | * @see parent::getFieldTypes |
55 | 19 | * |
56 | 20 | * @since 0.1 |
— | — | @@ -78,32 +42,6 @@ |
79 | 43 | } |
80 | 44 | |
81 | 45 | /** |
82 | | - * Returns the user that this instructor is. |
83 | | - * |
84 | | - * @since 0.1 |
85 | | - * |
86 | | - * @return User |
87 | | - */ |
88 | | - public function getUser() { |
89 | | - if ( $this->user === false ) { |
90 | | - $this->user = User::newFromId( $this->getField( 'user_id' ) ); |
91 | | - } |
92 | | - |
93 | | - return $this->user; |
94 | | - } |
95 | | - |
96 | | - /** |
97 | | - * Returns the name of the instroctor, using their real name when available. |
98 | | - * |
99 | | - * @since 0.1 |
100 | | - * |
101 | | - * @return string |
102 | | - */ |
103 | | - public function getName() { |
104 | | - return $this->getUser()->getRealName() === '' ? $this->getUser()->getName() : $this->getUser()->getRealName(); |
105 | | - } |
106 | | - |
107 | | - /** |
108 | 46 | * Display a pager with online ambassadors. |
109 | 47 | * |
110 | 48 | * @since 0.1 |
— | — | @@ -130,21 +68,7 @@ |
131 | 69 | } |
132 | 70 | |
133 | 71 | /** |
134 | | - * Returns the tool links for this ambassador. |
135 | | - * |
136 | 72 | * @since 0.1 |
137 | | - * |
138 | | - * @param IContextSource $context |
139 | | - * @param EPCourse|null $course |
140 | | - * |
141 | | - * @return string |
142 | | - */ |
143 | | - public function getToolLinks( IContextSource $context, EPCourse $course = null ) { |
144 | | - return EPUtils::getRoleToolLinks( $this, $context, $course ); |
145 | | - } |
146 | | - |
147 | | - /** |
148 | | - * @since 0.1 |
149 | 73 | * @see EPIRole::getRoleName |
150 | 74 | */ |
151 | 75 | public function getRoleName() { |
— | — | @@ -152,18 +76,26 @@ |
153 | 77 | } |
154 | 78 | |
155 | 79 | /** |
156 | | - * Retruns the user link for this ambassador, using their real name when available. |
157 | | - * |
| 80 | + * Returns the courses this online ambassdor is associated with. |
| 81 | + * |
158 | 82 | * @since 0.1 |
159 | | - * |
160 | | - * @return string |
| 83 | + * |
| 84 | + * @param string|array|null $fields |
| 85 | + * @param array $conditions |
| 86 | + * |
| 87 | + * @return array of EPCourse |
161 | 88 | */ |
162 | | - public function getUserLink() { |
163 | | - return Linker::userLink( |
164 | | - $this->getUser()->getId(), |
165 | | - $this->getUser()->getName(), |
166 | | - $this->getName() |
| 89 | + protected function doGetCourses( $fields, array $conditions ) { |
| 90 | + $conditions[] = array( array( 'ep_oas_per_course', 'user_id' ), $this->getField( 'user_id' ) ); |
| 91 | + |
| 92 | + return EPCourse::select( |
| 93 | + $fields, |
| 94 | + $conditions, |
| 95 | + array(), |
| 96 | + array( |
| 97 | + 'ep_oas_per_course' => array( 'INNER JOIN', array( array( array( 'ep_oas_per_course', 'course_id' ), array( 'ep_courses', 'id' ) ) ) ), |
| 98 | + ) |
167 | 99 | ); |
168 | 100 | } |
169 | | - |
| 101 | + |
170 | 102 | } |
Index: trunk/extensions/EducationProgram/includes/EPCourse.php |
— | — | @@ -301,7 +301,7 @@ |
302 | 302 | |
303 | 303 | if ( $this->updateSummaries && $success ) { |
304 | 304 | if ( array_key_exists( 'org_id', $currentFields ) && $currentFields['org_id'] !== $this->getField( 'org_id' ) ) { |
305 | | - $conds = array( 'id' => array( $oldOrgId, $this->getField( 'org_id' ) ) ); |
| 305 | + $conds = array( 'id' => array( $currentFields['org_id'], $this->getField( 'org_id' ) ) ); |
306 | 306 | EPOrg::updateSummaryFields( array( 'courses', 'students', 'active', 'instructors', 'oas', 'cas' ), $conds ); |
307 | 307 | } |
308 | 308 | |
— | — | @@ -310,19 +310,27 @@ |
311 | 311 | |
312 | 312 | if ( array_key_exists( $field, $currentFields ) && $currentFields[$field] !== $this->getField( $field ) ) { |
313 | 313 | $courseField = $ambs === 'oas' ? 'opc_course_id' : 'cpc_course_id'; |
314 | | - $userField = $ambs === 'oas' ? 'opc_oa_id' : 'cpc_ca_id'; |
| 314 | + $userField = $ambs === 'oas' ? 'opc_user_id' : 'cpc_user_id'; |
315 | 315 | $table = 'ep_' . $ambs . '_per_course'; |
316 | 316 | |
| 317 | + $addedIds = array_diff( $this->getField( $field ), $currentFields[$field] ); |
| 318 | + $removedIds = array_diff( $currentFields[$field], $this->getField( $field ) ); |
| 319 | + |
317 | 320 | $dbw = wfGetDB( DB_MASTER ); |
318 | 321 | |
319 | | - $dbw->delete( $table, array( $courseField => $id ) ); |
| 322 | + if ( count( $removedIds ) > 0 ) { |
| 323 | + $dbw->delete( $table, array( |
| 324 | + $courseField => $this->getId(), |
| 325 | + $userField => $removedIds |
| 326 | + ) ); |
| 327 | + } |
320 | 328 | |
321 | 329 | $dbw->begin(); |
322 | 330 | |
323 | | - foreach ( $this->getField( $field ) as $userId ) { |
| 331 | + foreach ( $addedIds as $ambassadorId ) { |
324 | 332 | $dbw->insert( $table, array( |
325 | 333 | $courseField => $this->getId(), |
326 | | - $userField => $userId |
| 334 | + $userField => $ambassadorId |
327 | 335 | ) ); |
328 | 336 | } |
329 | 337 | |
— | — | @@ -370,9 +378,10 @@ |
371 | 379 | * |
372 | 380 | * @param IContextSource $context |
373 | 381 | * @param array $conditions |
| 382 | + * @param boolean $readOnlyMode |
374 | 383 | */ |
375 | | - public static function displayPager( IContextSource $context, array $conditions = array() ) { |
376 | | - $pager = new EPCoursePager( $context, $conditions ); |
| 384 | + public static function displayPager( IContextSource $context, array $conditions = array(), $readOnlyMode = false ) { |
| 385 | + $pager = new EPCoursePager( $context, $conditions, $readOnlyMode ); |
377 | 386 | |
378 | 387 | if ( $pager->getNumRows() ) { |
379 | 388 | $context->getOutput()->addHTML( |
Index: trunk/extensions/EducationProgram/EducationProgram.i18n.php |
— | — | @@ -388,6 +388,11 @@ |
389 | 389 | 'ep-mycourses-not-a-student' => 'You are not enrolled in any [[Special:Courses|courses]].', |
390 | 390 | 'ep-mycourses-enrollment' => 'Courses I am enrolled in', |
391 | 391 | 'ep-mycourses-course-enrollment' => 'Course I am enrolled in', |
| 392 | + 'ep-mycourses-login-first' => 'You need to login before you can view your courses.', |
| 393 | + 'ep-mycourses-ambcourses-epoa' => 'Courses I am Online Ambassador for', |
| 394 | + 'ep-mycourses-ambcourses-epca' => 'Courses I am Campus Ambassador for', |
| 395 | + 'ep-mycourses-noambcourses-epca' => 'There are no courses you are Campus Ambassador for yet.', |
| 396 | + 'ep-mycourses-noambcourses-epoa' => 'There are no courses you are Online Ambassador for yet.', |
392 | 397 | |
393 | 398 | // ep.enlist instructor |
394 | 399 | 'ep-instructor-remove-title' => 'Remove instructor from course', |
Index: trunk/extensions/EducationProgram/EducationProgram.hooks.php |
— | — | @@ -35,6 +35,14 @@ |
36 | 36 | dirname( __FILE__ ) . '/sql/AddAmbassadorLinks.sql', |
37 | 37 | true |
38 | 38 | ) ); |
| 39 | + |
| 40 | + $updater->addExtensionUpdate( array( |
| 41 | + 'addField', |
| 42 | + 'ep_oas_per_course', |
| 43 | + 'user_id', |
| 44 | + dirname( __FILE__ ) . '/sql/RenameAmbUserField.sql', |
| 45 | + true |
| 46 | + ) ); |
39 | 47 | |
40 | 48 | return true; |
41 | 49 | } |