@@ -453,6 +453,7 @@ |
||
453 | 453 | * @param string Session id field name |
454 | 454 | * @param string Session id value |
455 | 455 | * @param int State (1 to subscribe, 0 to unsubscribe) |
456 | + * @param integer $state |
|
456 | 457 | * @return mixed True on success, WSError otherwise |
457 | 458 | */ |
458 | 459 | protected function changeCourseSubscription($course_id_field_name, $course_id_value, $session_id_field_name, $session_id_value, $state) { |
@@ -12,490 +12,490 @@ |
||
12 | 12 | */ |
13 | 13 | class WSCourse extends WS |
14 | 14 | { |
15 | - /** |
|
16 | - * Deletes a course (helper method) |
|
17 | - * |
|
18 | - * @param string Course id field name |
|
19 | - * @param string Course id value |
|
20 | - * @return mixed True if the course was successfully deleted, WSError otherwise |
|
21 | - */ |
|
22 | - protected function deleteCourseHelper($course_id_field_name, $course_id_value) { |
|
23 | - $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
24 | - if($course_id instanceof WSError) { |
|
25 | - return $course_id; |
|
26 | - } else { |
|
27 | - $course_code = CourseManager::get_course_code_from_course_id($course_id); |
|
28 | - CourseManager::delete_course($course_code); |
|
29 | - return true; |
|
30 | - } |
|
31 | - } |
|
15 | + /** |
|
16 | + * Deletes a course (helper method) |
|
17 | + * |
|
18 | + * @param string Course id field name |
|
19 | + * @param string Course id value |
|
20 | + * @return mixed True if the course was successfully deleted, WSError otherwise |
|
21 | + */ |
|
22 | + protected function deleteCourseHelper($course_id_field_name, $course_id_value) { |
|
23 | + $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
24 | + if($course_id instanceof WSError) { |
|
25 | + return $course_id; |
|
26 | + } else { |
|
27 | + $course_code = CourseManager::get_course_code_from_course_id($course_id); |
|
28 | + CourseManager::delete_course($course_code); |
|
29 | + return true; |
|
30 | + } |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * Deletes a course |
|
35 | - * |
|
36 | - * @param string API secret key |
|
37 | - * @param string Course id field name |
|
38 | - * @param string Course id value |
|
39 | - */ |
|
40 | - public function DeleteCourse($secret_key, $course_id_field_name, $course_id_value) { |
|
41 | - $verifKey = $this->verifyKey($secret_key); |
|
42 | - if($verifKey instanceof WSError) { |
|
43 | - $this->handleError($verifKey); |
|
44 | - } else { |
|
45 | - $result = $this->deleteCourseHelper($course_id_field_name, $course_id_value); |
|
46 | - if($result instanceof WSError) { |
|
47 | - $this->handleError($result); |
|
48 | - } |
|
49 | - } |
|
50 | - } |
|
33 | + /** |
|
34 | + * Deletes a course |
|
35 | + * |
|
36 | + * @param string API secret key |
|
37 | + * @param string Course id field name |
|
38 | + * @param string Course id value |
|
39 | + */ |
|
40 | + public function DeleteCourse($secret_key, $course_id_field_name, $course_id_value) { |
|
41 | + $verifKey = $this->verifyKey($secret_key); |
|
42 | + if($verifKey instanceof WSError) { |
|
43 | + $this->handleError($verifKey); |
|
44 | + } else { |
|
45 | + $result = $this->deleteCourseHelper($course_id_field_name, $course_id_value); |
|
46 | + if($result instanceof WSError) { |
|
47 | + $this->handleError($result); |
|
48 | + } |
|
49 | + } |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Deletes multiple courses |
|
54 | - * |
|
55 | - * @param string API secret key |
|
56 | - * @param array Array of courses with elements of the form array('course_id_field_name' => 'name_of_field', 'course_id_value' => 'value') |
|
57 | - * @return array Array with elements like array('course_id_value' => 'value', 'result' => array('code' => 0, 'message' => 'Operation was successful')). Note that if the result array contains a code different |
|
58 | - * than 0, an error occured |
|
59 | - */ |
|
60 | - public function DeleteCourses($secret_key, $courses) { |
|
61 | - $verifKey = $this->verifyKey($secret_key); |
|
62 | - if($verifKey instanceof WSError) { |
|
63 | - $this->handleError($verifKey); |
|
64 | - } else { |
|
65 | - $results = array(); |
|
66 | - foreach($courses as $course) { |
|
67 | - $result_tmp = array(); |
|
68 | - $result_op = $this->deleteCourseHelper($course['course_id_field_name'], $course['course_id_value']); |
|
69 | - $result_tmp['course_id_value'] = $course['course_id_value']; |
|
70 | - if($result_op instanceof WSError) { |
|
71 | - // Return the error in the results |
|
72 | - $result_tmp['result'] = $result_op->toArray(); |
|
73 | - } else { |
|
74 | - $result_tmp['result'] = $this->getSuccessfulResult(); |
|
75 | - } |
|
76 | - $results[] = $result_tmp; |
|
77 | - } |
|
78 | - return $results; |
|
79 | - } |
|
80 | - } |
|
52 | + /** |
|
53 | + * Deletes multiple courses |
|
54 | + * |
|
55 | + * @param string API secret key |
|
56 | + * @param array Array of courses with elements of the form array('course_id_field_name' => 'name_of_field', 'course_id_value' => 'value') |
|
57 | + * @return array Array with elements like array('course_id_value' => 'value', 'result' => array('code' => 0, 'message' => 'Operation was successful')). Note that if the result array contains a code different |
|
58 | + * than 0, an error occured |
|
59 | + */ |
|
60 | + public function DeleteCourses($secret_key, $courses) { |
|
61 | + $verifKey = $this->verifyKey($secret_key); |
|
62 | + if($verifKey instanceof WSError) { |
|
63 | + $this->handleError($verifKey); |
|
64 | + } else { |
|
65 | + $results = array(); |
|
66 | + foreach($courses as $course) { |
|
67 | + $result_tmp = array(); |
|
68 | + $result_op = $this->deleteCourseHelper($course['course_id_field_name'], $course['course_id_value']); |
|
69 | + $result_tmp['course_id_value'] = $course['course_id_value']; |
|
70 | + if($result_op instanceof WSError) { |
|
71 | + // Return the error in the results |
|
72 | + $result_tmp['result'] = $result_op->toArray(); |
|
73 | + } else { |
|
74 | + $result_tmp['result'] = $this->getSuccessfulResult(); |
|
75 | + } |
|
76 | + $results[] = $result_tmp; |
|
77 | + } |
|
78 | + return $results; |
|
79 | + } |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * Creates a course (helper method) |
|
84 | - * |
|
85 | - * @param string Title |
|
86 | - * @param string Category code |
|
87 | - * @param string Wanted code. If it's not defined, it will be generated automatically |
|
88 | - * @param string Tutor name |
|
89 | - * @param string Course admin user id field name |
|
90 | - * @param string Course admin user id value |
|
91 | - * @param string Course language |
|
92 | - * @param string Course id field name |
|
93 | - * @param string Course id value |
|
94 | - * @param array Course extra fields |
|
95 | - * @return mixed Generated id if creation was successful, WSError otherwise |
|
96 | - */ |
|
97 | - protected function createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras) { |
|
98 | - // Add the original course id field name and value to the extra fields if needed |
|
99 | - $extras_associative = array(); |
|
100 | - if($course_id_field_name != "chamilo_course_id") { |
|
101 | - $extras_associative[$course_id_field_name] = $course_id_value; |
|
102 | - } |
|
103 | - foreach($extras as $extra) { |
|
104 | - $extras_associative[$extra['field_name']] = $extra['field_value']; |
|
105 | - } |
|
106 | - $course_admin_id = $this->getUserId($course_admin_user_id_field_name, $course_admin_user_id_value); |
|
107 | - if($course_admin_id instanceof WSError) { |
|
108 | - return $course_admin_id; |
|
109 | - } |
|
110 | - if($wanted_code == '') { |
|
111 | - $wanted_code = CourseManager::generate_course_code($title); |
|
112 | - } |
|
113 | - $result = create_course($wanted_code, $title, $tutor_name, $category_code, $language, $course_admin_id, $this->_configuration['db_prefix'], 0); |
|
114 | - if (!$result) { |
|
115 | - return new WSError(202, 'There was an error creating the course'); |
|
116 | - } else { |
|
117 | - // Update extra fields |
|
118 | - foreach($extras_associative as $fname => $fvalue) { |
|
119 | - CourseManager::update_course_extra_field_value($result, $fname, $fvalue); |
|
120 | - } |
|
121 | - // Get course id |
|
122 | - $course_info = CourseManager::get_course_information($result); |
|
123 | - return $course_info['real_id']; |
|
124 | - } |
|
125 | - } |
|
82 | + /** |
|
83 | + * Creates a course (helper method) |
|
84 | + * |
|
85 | + * @param string Title |
|
86 | + * @param string Category code |
|
87 | + * @param string Wanted code. If it's not defined, it will be generated automatically |
|
88 | + * @param string Tutor name |
|
89 | + * @param string Course admin user id field name |
|
90 | + * @param string Course admin user id value |
|
91 | + * @param string Course language |
|
92 | + * @param string Course id field name |
|
93 | + * @param string Course id value |
|
94 | + * @param array Course extra fields |
|
95 | + * @return mixed Generated id if creation was successful, WSError otherwise |
|
96 | + */ |
|
97 | + protected function createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras) { |
|
98 | + // Add the original course id field name and value to the extra fields if needed |
|
99 | + $extras_associative = array(); |
|
100 | + if($course_id_field_name != "chamilo_course_id") { |
|
101 | + $extras_associative[$course_id_field_name] = $course_id_value; |
|
102 | + } |
|
103 | + foreach($extras as $extra) { |
|
104 | + $extras_associative[$extra['field_name']] = $extra['field_value']; |
|
105 | + } |
|
106 | + $course_admin_id = $this->getUserId($course_admin_user_id_field_name, $course_admin_user_id_value); |
|
107 | + if($course_admin_id instanceof WSError) { |
|
108 | + return $course_admin_id; |
|
109 | + } |
|
110 | + if($wanted_code == '') { |
|
111 | + $wanted_code = CourseManager::generate_course_code($title); |
|
112 | + } |
|
113 | + $result = create_course($wanted_code, $title, $tutor_name, $category_code, $language, $course_admin_id, $this->_configuration['db_prefix'], 0); |
|
114 | + if (!$result) { |
|
115 | + return new WSError(202, 'There was an error creating the course'); |
|
116 | + } else { |
|
117 | + // Update extra fields |
|
118 | + foreach($extras_associative as $fname => $fvalue) { |
|
119 | + CourseManager::update_course_extra_field_value($result, $fname, $fvalue); |
|
120 | + } |
|
121 | + // Get course id |
|
122 | + $course_info = CourseManager::get_course_information($result); |
|
123 | + return $course_info['real_id']; |
|
124 | + } |
|
125 | + } |
|
126 | 126 | |
127 | - /** |
|
128 | - * Creates a course |
|
129 | - * |
|
130 | - * @param string API secret key |
|
131 | - * @param string Title |
|
132 | - * @param string Category code |
|
133 | - * @param string Wanted code. If it's not defined, it will be generated automatically |
|
134 | - * @param string Tutor name |
|
135 | - * @param string Course admin user id field name |
|
136 | - * @param string Course admin user id value |
|
137 | - * @param string Course language |
|
138 | - * @param string Course id field name |
|
139 | - * @param string Course id value |
|
140 | - * @param array Course extra fields |
|
141 | - * @return int Course id generated |
|
142 | - */ |
|
143 | - public function CreateCourse($secret_key, $title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras) { |
|
144 | - // First, verify the secret key |
|
145 | - $verifKey = $this->verifyKey($secret_key); |
|
146 | - if($verifKey instanceof WSError) { |
|
147 | - $this->handleError($verifKey); |
|
148 | - } else { |
|
149 | - $result = $this->createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras); |
|
150 | - if($result instanceof WSError) { |
|
151 | - $this->handleError($result); |
|
152 | - } else { |
|
153 | - return $result; |
|
154 | - } |
|
155 | - } |
|
156 | - } |
|
127 | + /** |
|
128 | + * Creates a course |
|
129 | + * |
|
130 | + * @param string API secret key |
|
131 | + * @param string Title |
|
132 | + * @param string Category code |
|
133 | + * @param string Wanted code. If it's not defined, it will be generated automatically |
|
134 | + * @param string Tutor name |
|
135 | + * @param string Course admin user id field name |
|
136 | + * @param string Course admin user id value |
|
137 | + * @param string Course language |
|
138 | + * @param string Course id field name |
|
139 | + * @param string Course id value |
|
140 | + * @param array Course extra fields |
|
141 | + * @return int Course id generated |
|
142 | + */ |
|
143 | + public function CreateCourse($secret_key, $title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras) { |
|
144 | + // First, verify the secret key |
|
145 | + $verifKey = $this->verifyKey($secret_key); |
|
146 | + if($verifKey instanceof WSError) { |
|
147 | + $this->handleError($verifKey); |
|
148 | + } else { |
|
149 | + $result = $this->createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras); |
|
150 | + if($result instanceof WSError) { |
|
151 | + $this->handleError($result); |
|
152 | + } else { |
|
153 | + return $result; |
|
154 | + } |
|
155 | + } |
|
156 | + } |
|
157 | 157 | |
158 | - /** |
|
159 | - * Create multiple courses |
|
160 | - * |
|
161 | - * @param string API secret key |
|
162 | - * @param array Courses to be created, with elements following the structure presented in CreateCourse |
|
163 | - * @return array Array with elements of the form array('course_id_value' => 'original value sent', 'course_id_generated' => 'value_generated', 'result' => array('code' => 0, 'message' => 'Operation was successful')) |
|
164 | - */ |
|
165 | - public function CreateCourses($secret_key, $courses) { |
|
166 | - // First, verify the secret key |
|
167 | - $verifKey = $this->verifyKey($secret_key); |
|
168 | - if($verifKey instanceof WSError) { |
|
169 | - $this->handleError($verifKey); |
|
170 | - } else { |
|
171 | - $results = array(); |
|
172 | - foreach($courses as $course) { |
|
173 | - $result_tmp = array(); |
|
158 | + /** |
|
159 | + * Create multiple courses |
|
160 | + * |
|
161 | + * @param string API secret key |
|
162 | + * @param array Courses to be created, with elements following the structure presented in CreateCourse |
|
163 | + * @return array Array with elements of the form array('course_id_value' => 'original value sent', 'course_id_generated' => 'value_generated', 'result' => array('code' => 0, 'message' => 'Operation was successful')) |
|
164 | + */ |
|
165 | + public function CreateCourses($secret_key, $courses) { |
|
166 | + // First, verify the secret key |
|
167 | + $verifKey = $this->verifyKey($secret_key); |
|
168 | + if($verifKey instanceof WSError) { |
|
169 | + $this->handleError($verifKey); |
|
170 | + } else { |
|
171 | + $results = array(); |
|
172 | + foreach($courses as $course) { |
|
173 | + $result_tmp = array(); |
|
174 | 174 | // re-initialize variables just in case |
175 | 175 | $title = $category_code = $wanted_code = $tutor_name = $course_admin_user_id_field_name = $course_admin_user_id_value = $language = $course_id_field_name = $course_id_value = $extras = 0; |
176 | - extract($course); |
|
177 | - $result = $this->createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras); |
|
178 | - if($result instanceof WSError) { |
|
179 | - $result_tmp['result'] = $result->toArray(); |
|
180 | - $result_tmp['course_id_value'] = $course_id_value; |
|
181 | - $result_tmp['course_id_generated'] = 0; |
|
182 | - } else { |
|
183 | - $result_tmp['result'] = $this->getSuccessfulResult(); |
|
184 | - $result_tmp['course_id_value'] = $course_id_value; |
|
185 | - $result_tmp['course_id_generated'] = $result; |
|
186 | - } |
|
187 | - $results[] = $result_tmp; |
|
188 | - } |
|
189 | - return $results; |
|
190 | - } |
|
191 | - } |
|
176 | + extract($course); |
|
177 | + $result = $this->createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras); |
|
178 | + if($result instanceof WSError) { |
|
179 | + $result_tmp['result'] = $result->toArray(); |
|
180 | + $result_tmp['course_id_value'] = $course_id_value; |
|
181 | + $result_tmp['course_id_generated'] = 0; |
|
182 | + } else { |
|
183 | + $result_tmp['result'] = $this->getSuccessfulResult(); |
|
184 | + $result_tmp['course_id_value'] = $course_id_value; |
|
185 | + $result_tmp['course_id_generated'] = $result; |
|
186 | + } |
|
187 | + $results[] = $result_tmp; |
|
188 | + } |
|
189 | + return $results; |
|
190 | + } |
|
191 | + } |
|
192 | 192 | |
193 | - /** |
|
194 | - * Edits a course (helper method) |
|
195 | - * |
|
196 | - * @param string Course id field name |
|
197 | - * @param string Course id value |
|
198 | - * @param string Title |
|
199 | - * @param string Category code |
|
200 | - * @param string Department name |
|
201 | - * @param string Department url |
|
202 | - * @param string Course language |
|
203 | - * @param int Visibility |
|
204 | - * @param int Subscribe (0 = denied, 1 = allowed) |
|
205 | - * @param int Unsubscribe (0 = denied, 1 = allowed) |
|
206 | - * @param string Visual code |
|
207 | - * @param array Course extra fields |
|
208 | - * @return mixed True in case of success, WSError otherwise |
|
209 | - */ |
|
210 | - protected function editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) { |
|
211 | - $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
212 | - if($course_id instanceof WSError) { |
|
213 | - return $course_id; |
|
214 | - } else { |
|
215 | - $attributes = array(); |
|
216 | - if(!empty($title)) { |
|
217 | - $attributes['title'] = $title; |
|
218 | - } |
|
219 | - if(!empty($category_code)) { |
|
220 | - $attributes['category_code'] = $category_code; |
|
221 | - } |
|
222 | - if(!empty($department_name)) { |
|
223 | - $attributes['department_name'] = $department_name; |
|
224 | - } |
|
225 | - if(!empty($department_url)) { |
|
226 | - $attributes['department_url'] = $department_url; |
|
227 | - } |
|
228 | - if(!empty($language)) { |
|
229 | - $attributes['course_language'] = $language; |
|
230 | - } |
|
231 | - if($visibility != '') { |
|
232 | - $attributes['visibility'] = (int)$visibility; |
|
233 | - } |
|
234 | - if($subscribe != '') { |
|
235 | - $attributes['subscribe'] = (int)$subscribe; |
|
236 | - } |
|
237 | - if($unsubscribe != '') { |
|
238 | - $attributes['unsubscribe'] = (int)$unsubscribe; |
|
239 | - } |
|
240 | - if(!empty($visual_code)) { |
|
241 | - $attributes['visual_code'] = $visual_code; |
|
242 | - } |
|
243 | - if(!empty($attributes)) { |
|
244 | - CourseManager::update_attributes($course_id, $attributes); |
|
245 | - } |
|
246 | - if(!empty($extras)) { |
|
247 | - $course_code = CourseManager::get_course_code_from_course_id($course_id); |
|
248 | - $extras_associative = array(); |
|
249 | - foreach($extras as $extra) { |
|
250 | - $extras_associative[$extra['field_name']] = $extra['field_value']; |
|
251 | - } |
|
252 | - foreach($extras_associative as $fname => $fvalue) { |
|
253 | - CourseManager::update_extra_field_value($course_code, $fname, $fvalue); |
|
254 | - } |
|
255 | - } |
|
256 | - return true; |
|
257 | - } |
|
258 | - } |
|
193 | + /** |
|
194 | + * Edits a course (helper method) |
|
195 | + * |
|
196 | + * @param string Course id field name |
|
197 | + * @param string Course id value |
|
198 | + * @param string Title |
|
199 | + * @param string Category code |
|
200 | + * @param string Department name |
|
201 | + * @param string Department url |
|
202 | + * @param string Course language |
|
203 | + * @param int Visibility |
|
204 | + * @param int Subscribe (0 = denied, 1 = allowed) |
|
205 | + * @param int Unsubscribe (0 = denied, 1 = allowed) |
|
206 | + * @param string Visual code |
|
207 | + * @param array Course extra fields |
|
208 | + * @return mixed True in case of success, WSError otherwise |
|
209 | + */ |
|
210 | + protected function editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) { |
|
211 | + $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
212 | + if($course_id instanceof WSError) { |
|
213 | + return $course_id; |
|
214 | + } else { |
|
215 | + $attributes = array(); |
|
216 | + if(!empty($title)) { |
|
217 | + $attributes['title'] = $title; |
|
218 | + } |
|
219 | + if(!empty($category_code)) { |
|
220 | + $attributes['category_code'] = $category_code; |
|
221 | + } |
|
222 | + if(!empty($department_name)) { |
|
223 | + $attributes['department_name'] = $department_name; |
|
224 | + } |
|
225 | + if(!empty($department_url)) { |
|
226 | + $attributes['department_url'] = $department_url; |
|
227 | + } |
|
228 | + if(!empty($language)) { |
|
229 | + $attributes['course_language'] = $language; |
|
230 | + } |
|
231 | + if($visibility != '') { |
|
232 | + $attributes['visibility'] = (int)$visibility; |
|
233 | + } |
|
234 | + if($subscribe != '') { |
|
235 | + $attributes['subscribe'] = (int)$subscribe; |
|
236 | + } |
|
237 | + if($unsubscribe != '') { |
|
238 | + $attributes['unsubscribe'] = (int)$unsubscribe; |
|
239 | + } |
|
240 | + if(!empty($visual_code)) { |
|
241 | + $attributes['visual_code'] = $visual_code; |
|
242 | + } |
|
243 | + if(!empty($attributes)) { |
|
244 | + CourseManager::update_attributes($course_id, $attributes); |
|
245 | + } |
|
246 | + if(!empty($extras)) { |
|
247 | + $course_code = CourseManager::get_course_code_from_course_id($course_id); |
|
248 | + $extras_associative = array(); |
|
249 | + foreach($extras as $extra) { |
|
250 | + $extras_associative[$extra['field_name']] = $extra['field_value']; |
|
251 | + } |
|
252 | + foreach($extras_associative as $fname => $fvalue) { |
|
253 | + CourseManager::update_extra_field_value($course_code, $fname, $fvalue); |
|
254 | + } |
|
255 | + } |
|
256 | + return true; |
|
257 | + } |
|
258 | + } |
|
259 | 259 | |
260 | - /** |
|
261 | - * Edits a course |
|
262 | - * |
|
263 | - * @param string API secret key |
|
264 | - * @param string Course id field name |
|
265 | - * @param string Course id value |
|
266 | - * @param string Title |
|
267 | - * @param string Category code |
|
268 | - * @param string Department name |
|
269 | - * @param string Department url |
|
270 | - * @param string Course language |
|
271 | - * @param int Visibility |
|
272 | - * @param int Subscribe (0 = denied, 1 = allowed) |
|
273 | - * @param int Unsubscribe (0 = denied, 1 = allowed) |
|
274 | - * @param string Visual code |
|
275 | - * @param array Course extra fields |
|
276 | - */ |
|
277 | - public function EditCourse($secret_key, $course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) { |
|
278 | - $verifKey = $this->verifyKey($secret_key); |
|
279 | - if($verifKey instanceof WSError) { |
|
280 | - $this->handleError($verifKey); |
|
281 | - } else { |
|
282 | - $result = $this->editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras); |
|
283 | - if($result instanceof WSError) { |
|
284 | - $this->handleError($result); |
|
285 | - } |
|
286 | - } |
|
287 | - } |
|
260 | + /** |
|
261 | + * Edits a course |
|
262 | + * |
|
263 | + * @param string API secret key |
|
264 | + * @param string Course id field name |
|
265 | + * @param string Course id value |
|
266 | + * @param string Title |
|
267 | + * @param string Category code |
|
268 | + * @param string Department name |
|
269 | + * @param string Department url |
|
270 | + * @param string Course language |
|
271 | + * @param int Visibility |
|
272 | + * @param int Subscribe (0 = denied, 1 = allowed) |
|
273 | + * @param int Unsubscribe (0 = denied, 1 = allowed) |
|
274 | + * @param string Visual code |
|
275 | + * @param array Course extra fields |
|
276 | + */ |
|
277 | + public function EditCourse($secret_key, $course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) { |
|
278 | + $verifKey = $this->verifyKey($secret_key); |
|
279 | + if($verifKey instanceof WSError) { |
|
280 | + $this->handleError($verifKey); |
|
281 | + } else { |
|
282 | + $result = $this->editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras); |
|
283 | + if($result instanceof WSError) { |
|
284 | + $this->handleError($result); |
|
285 | + } |
|
286 | + } |
|
287 | + } |
|
288 | 288 | |
289 | - /** |
|
290 | - * List courses |
|
291 | - * |
|
292 | - * @param string API secret key |
|
293 | - * @param string A list of visibility filter we want to apply |
|
294 | - * @return array An array with elements of the form ('id' => 'Course internal id', 'code' => 'Course code', 'title' => 'Course title', 'language' => 'Course language', 'visibility' => 'Course visibility', |
|
295 | - * 'category_name' => 'Name of the category of the course', 'number_students' => 'Number of students in the course', 'external_course_id' => 'External course id') |
|
296 | - */ |
|
297 | - public function ListCourses($secret_key, $visibility = 'public,public-registered,private,closed') { |
|
298 | - $verifKey = $this->verifyKey($secret_key); |
|
299 | - if($verifKey instanceof WSError) { |
|
300 | - $this->handleError($verifKey); |
|
301 | - } else { |
|
289 | + /** |
|
290 | + * List courses |
|
291 | + * |
|
292 | + * @param string API secret key |
|
293 | + * @param string A list of visibility filter we want to apply |
|
294 | + * @return array An array with elements of the form ('id' => 'Course internal id', 'code' => 'Course code', 'title' => 'Course title', 'language' => 'Course language', 'visibility' => 'Course visibility', |
|
295 | + * 'category_name' => 'Name of the category of the course', 'number_students' => 'Number of students in the course', 'external_course_id' => 'External course id') |
|
296 | + */ |
|
297 | + public function ListCourses($secret_key, $visibility = 'public,public-registered,private,closed') { |
|
298 | + $verifKey = $this->verifyKey($secret_key); |
|
299 | + if($verifKey instanceof WSError) { |
|
300 | + $this->handleError($verifKey); |
|
301 | + } else { |
|
302 | 302 | $visibilities = split(',',$visibility); |
303 | 303 | $vis = array('public' => '3', 'public-registered' => '2', 'private' => '1', 'closed' => '0'); |
304 | 304 | foreach ($visibilities as $p => $visibility) { |
305 | 305 | $visibilities[$p] = $vis[$visibility]; |
306 | 306 | } |
307 | - $courses_result = array(); |
|
308 | - $category_names = array(); |
|
307 | + $courses_result = array(); |
|
308 | + $category_names = array(); |
|
309 | 309 | |
310 | - $courses = CourseManager::get_courses_list(); |
|
311 | - foreach($courses as $course) { |
|
310 | + $courses = CourseManager::get_courses_list(); |
|
311 | + foreach($courses as $course) { |
|
312 | 312 | //skip elements that do not match required visibility |
313 | 313 | if (!in_array($course['visibility'],$visibilities)) { continue; } |
314 | - $course_tmp = array(); |
|
315 | - $course_tmp['id'] = $course['id']; |
|
316 | - $course_tmp['code'] = $course['code']; |
|
317 | - $course_tmp['title'] = $course['title']; |
|
318 | - $course_tmp['language'] = $course['course_language']; |
|
319 | - $course_tmp['visibility'] = $course['visibility']; |
|
314 | + $course_tmp = array(); |
|
315 | + $course_tmp['id'] = $course['id']; |
|
316 | + $course_tmp['code'] = $course['code']; |
|
317 | + $course_tmp['title'] = $course['title']; |
|
318 | + $course_tmp['language'] = $course['course_language']; |
|
319 | + $course_tmp['visibility'] = $course['visibility']; |
|
320 | 320 | |
321 | - // Determining category name |
|
322 | - if($category_names[$course['category_code']]) { |
|
323 | - $course_tmp['category_name'] = $category_names[$course['category_code']]; |
|
324 | - } else { |
|
325 | - $category = CourseManager::get_course_category($course['category_code']); |
|
326 | - $category_names[$course['category_code']] = $category['name']; |
|
327 | - $course_tmp['category_name'] = $category['name']; |
|
328 | - } |
|
321 | + // Determining category name |
|
322 | + if($category_names[$course['category_code']]) { |
|
323 | + $course_tmp['category_name'] = $category_names[$course['category_code']]; |
|
324 | + } else { |
|
325 | + $category = CourseManager::get_course_category($course['category_code']); |
|
326 | + $category_names[$course['category_code']] = $category['name']; |
|
327 | + $course_tmp['category_name'] = $category['name']; |
|
328 | + } |
|
329 | 329 | |
330 | - // Determining number of students registered in course |
|
331 | - $user_list = CourseManager::get_user_list_from_course_code($course['code'], 0); |
|
332 | - $course_tmp['number_students'] = count($user_list); |
|
330 | + // Determining number of students registered in course |
|
331 | + $user_list = CourseManager::get_user_list_from_course_code($course['code'], 0); |
|
332 | + $course_tmp['number_students'] = count($user_list); |
|
333 | 333 | |
334 | - // Determining external course id - this code misses the external course id field name |
|
335 | - // $course_tmp['external_course_id'] = CourseManager::get_course_extra_field_value($course_field_name, $course['code']); |
|
334 | + // Determining external course id - this code misses the external course id field name |
|
335 | + // $course_tmp['external_course_id'] = CourseManager::get_course_extra_field_value($course_field_name, $course['code']); |
|
336 | 336 | |
337 | 337 | |
338 | - $courses_result[] = $course_tmp; |
|
339 | - } |
|
338 | + $courses_result[] = $course_tmp; |
|
339 | + } |
|
340 | 340 | |
341 | - return $courses_result; |
|
342 | - } |
|
343 | - } |
|
341 | + return $courses_result; |
|
342 | + } |
|
343 | + } |
|
344 | 344 | |
345 | - /** |
|
346 | - * Subscribe or unsubscribe user to a course (helper method) |
|
347 | - * |
|
348 | - * @param string Course id field name. Use "chamilo_course_id" to use internal id |
|
349 | - * @param string Course id value. |
|
350 | - * @param string User id field name. Use "chamilo_user_id" to use internal id |
|
351 | - * @param string User id value |
|
352 | - * @param int Set to 1 to subscribe, 0 to unsubscribe |
|
353 | - * @param int Status (STUDENT or TEACHER) Used for subscription only |
|
354 | - * @return mixed True if subscription or unsubscription was successful, false otherwise |
|
355 | - */ |
|
356 | - protected function changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $state, $status = STUDENT) { |
|
357 | - $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
358 | - if($course_id instanceof WSError) { |
|
359 | - return $course_id; |
|
360 | - } else { |
|
361 | - $user_id = $this->getUserId($user_id_field_name, $user_id_value); |
|
362 | - if($user_id instanceof WSError) { |
|
363 | - return $user_id; |
|
364 | - } else { |
|
365 | - $course_code = CourseManager::get_course_code_from_course_id($course_id); |
|
366 | - if($state == 0) { |
|
367 | - // Unsubscribe user |
|
368 | - CourseManager::unsubscribe_user($user_id, $course_code); |
|
369 | - return true; |
|
370 | - } else { |
|
371 | - // Subscribe user |
|
372 | - if(CourseManager::subscribe_user($user_id, $course_code, $status)) { |
|
373 | - return true; |
|
374 | - } else { |
|
375 | - return new WSError(203, 'An error occured subscribing to this course'); |
|
376 | - } |
|
377 | - } |
|
378 | - } |
|
379 | - } |
|
380 | - } |
|
345 | + /** |
|
346 | + * Subscribe or unsubscribe user to a course (helper method) |
|
347 | + * |
|
348 | + * @param string Course id field name. Use "chamilo_course_id" to use internal id |
|
349 | + * @param string Course id value. |
|
350 | + * @param string User id field name. Use "chamilo_user_id" to use internal id |
|
351 | + * @param string User id value |
|
352 | + * @param int Set to 1 to subscribe, 0 to unsubscribe |
|
353 | + * @param int Status (STUDENT or TEACHER) Used for subscription only |
|
354 | + * @return mixed True if subscription or unsubscription was successful, false otherwise |
|
355 | + */ |
|
356 | + protected function changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $state, $status = STUDENT) { |
|
357 | + $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
358 | + if($course_id instanceof WSError) { |
|
359 | + return $course_id; |
|
360 | + } else { |
|
361 | + $user_id = $this->getUserId($user_id_field_name, $user_id_value); |
|
362 | + if($user_id instanceof WSError) { |
|
363 | + return $user_id; |
|
364 | + } else { |
|
365 | + $course_code = CourseManager::get_course_code_from_course_id($course_id); |
|
366 | + if($state == 0) { |
|
367 | + // Unsubscribe user |
|
368 | + CourseManager::unsubscribe_user($user_id, $course_code); |
|
369 | + return true; |
|
370 | + } else { |
|
371 | + // Subscribe user |
|
372 | + if(CourseManager::subscribe_user($user_id, $course_code, $status)) { |
|
373 | + return true; |
|
374 | + } else { |
|
375 | + return new WSError(203, 'An error occured subscribing to this course'); |
|
376 | + } |
|
377 | + } |
|
378 | + } |
|
379 | + } |
|
380 | + } |
|
381 | 381 | |
382 | - /** |
|
383 | - * Subscribe user to a course |
|
384 | - * |
|
385 | - * @param string API secret key |
|
386 | - * @param string Course id field name. Use "chamilo_course_id" to use internal id |
|
387 | - * @param string Course id value. |
|
388 | - * @param string User id field name. Use "chamilo_user_id" to use internal id |
|
389 | - * @param string User id value |
|
390 | - * @param int Status (1 = Teacher, 5 = Student) |
|
391 | - */ |
|
392 | - public function SubscribeUserToCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $status) { |
|
393 | - $verifKey = $this->verifyKey($secret_key); |
|
394 | - if($verifKey instanceof WSError) { |
|
395 | - $this->handleError($verifKey); |
|
396 | - } else { |
|
397 | - $result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 1, $status); |
|
398 | - if($result instanceof WSError) { |
|
399 | - $this->handleError($result); |
|
400 | - } |
|
401 | - } |
|
402 | - } |
|
382 | + /** |
|
383 | + * Subscribe user to a course |
|
384 | + * |
|
385 | + * @param string API secret key |
|
386 | + * @param string Course id field name. Use "chamilo_course_id" to use internal id |
|
387 | + * @param string Course id value. |
|
388 | + * @param string User id field name. Use "chamilo_user_id" to use internal id |
|
389 | + * @param string User id value |
|
390 | + * @param int Status (1 = Teacher, 5 = Student) |
|
391 | + */ |
|
392 | + public function SubscribeUserToCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $status) { |
|
393 | + $verifKey = $this->verifyKey($secret_key); |
|
394 | + if($verifKey instanceof WSError) { |
|
395 | + $this->handleError($verifKey); |
|
396 | + } else { |
|
397 | + $result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 1, $status); |
|
398 | + if($result instanceof WSError) { |
|
399 | + $this->handleError($result); |
|
400 | + } |
|
401 | + } |
|
402 | + } |
|
403 | 403 | |
404 | - /** |
|
405 | - * Unsusbscribe user from course |
|
406 | - * |
|
407 | - * @param string API secret key |
|
408 | - * @param string Course id field name. Use "chamilo_course_id" to use internal id |
|
409 | - * @param string Course id value. |
|
410 | - * @param string User id field name. Use "chamilo_user_id" to use internal id |
|
411 | - * @param string User id value |
|
412 | - */ |
|
413 | - public function UnsubscribeUserFromCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value) { |
|
414 | - $verifKey = $this->verifyKey($secret_key); |
|
415 | - if($verifKey instanceof WSError) { |
|
416 | - $this->handleError($verifKey); |
|
417 | - } else { |
|
418 | - $result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 0); |
|
419 | - if($result instanceof WSError) { |
|
420 | - $this->handleError($result); |
|
421 | - } |
|
422 | - } |
|
423 | - } |
|
404 | + /** |
|
405 | + * Unsusbscribe user from course |
|
406 | + * |
|
407 | + * @param string API secret key |
|
408 | + * @param string Course id field name. Use "chamilo_course_id" to use internal id |
|
409 | + * @param string Course id value. |
|
410 | + * @param string User id field name. Use "chamilo_user_id" to use internal id |
|
411 | + * @param string User id value |
|
412 | + */ |
|
413 | + public function UnsubscribeUserFromCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value) { |
|
414 | + $verifKey = $this->verifyKey($secret_key); |
|
415 | + if($verifKey instanceof WSError) { |
|
416 | + $this->handleError($verifKey); |
|
417 | + } else { |
|
418 | + $result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 0); |
|
419 | + if($result instanceof WSError) { |
|
420 | + $this->handleError($result); |
|
421 | + } |
|
422 | + } |
|
423 | + } |
|
424 | 424 | |
425 | - /** |
|
426 | - * Returns the descriptions of a course, along with their id |
|
427 | - * |
|
428 | - * @param string API secret key |
|
429 | - * @param string Course id field name |
|
430 | - * @param string Course id value |
|
431 | - * @return array Returns an array with elements of the form ('course_desc_id' => 1, 'course_desc_title' => 'Title', 'course_desc_content' => 'Content') |
|
432 | - */ |
|
433 | - public function GetCourseDescriptions($secret_key, $course_id_field_name, $course_id_value) { |
|
434 | - $verifKey = $this->verifyKey($secret_key); |
|
435 | - if($verifKey instanceof WSError) { |
|
436 | - $this->handleError($verifKey); |
|
437 | - } else { |
|
438 | - $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
439 | - if($course_id instanceof WSError) { |
|
440 | - return $course_id; |
|
441 | - } else { |
|
442 | - // Course exists, get its descriptions |
|
443 | - $descriptions = CourseDescription::get_descriptions($course_id); |
|
444 | - $results = array(); |
|
445 | - foreach($descriptions as $description) { |
|
446 | - $results[] = array('course_desc_id' => $description->get_description_type(), |
|
447 | - 'course_desc_title' => $description->get_title(), |
|
448 | - 'course_desc_content' => $description->get_content()); |
|
449 | - } |
|
450 | - return $results; |
|
451 | - } |
|
452 | - } |
|
453 | - } |
|
425 | + /** |
|
426 | + * Returns the descriptions of a course, along with their id |
|
427 | + * |
|
428 | + * @param string API secret key |
|
429 | + * @param string Course id field name |
|
430 | + * @param string Course id value |
|
431 | + * @return array Returns an array with elements of the form ('course_desc_id' => 1, 'course_desc_title' => 'Title', 'course_desc_content' => 'Content') |
|
432 | + */ |
|
433 | + public function GetCourseDescriptions($secret_key, $course_id_field_name, $course_id_value) { |
|
434 | + $verifKey = $this->verifyKey($secret_key); |
|
435 | + if($verifKey instanceof WSError) { |
|
436 | + $this->handleError($verifKey); |
|
437 | + } else { |
|
438 | + $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
439 | + if($course_id instanceof WSError) { |
|
440 | + return $course_id; |
|
441 | + } else { |
|
442 | + // Course exists, get its descriptions |
|
443 | + $descriptions = CourseDescription::get_descriptions($course_id); |
|
444 | + $results = array(); |
|
445 | + foreach($descriptions as $description) { |
|
446 | + $results[] = array('course_desc_id' => $description->get_description_type(), |
|
447 | + 'course_desc_title' => $description->get_title(), |
|
448 | + 'course_desc_content' => $description->get_content()); |
|
449 | + } |
|
450 | + return $results; |
|
451 | + } |
|
452 | + } |
|
453 | + } |
|
454 | 454 | |
455 | 455 | |
456 | - /** |
|
457 | - * Edit course description |
|
458 | - * |
|
459 | - * @param string API secret key |
|
460 | - * @param string Course id field name |
|
461 | - * @param string Course id value |
|
462 | - * @param int Category id from course description |
|
463 | - * @param string Description title |
|
464 | - * @param string Course description content |
|
465 | - */ |
|
466 | - public function EditCourseDescription($secret_key, $course_id_field_name, $course_id_value, $course_desc_id, $course_desc_title, $course_desc_content) { |
|
467 | - $verifKey = $this->verifyKey($secret_key); |
|
468 | - if($verifKey instanceof WSError) { |
|
469 | - $this->handleError($verifKey); |
|
470 | - } else { |
|
471 | - $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
472 | - if($course_id instanceof WSError) { |
|
473 | - return $course_id; |
|
474 | - } else { |
|
475 | - // Create the new course description |
|
476 | - $cd = new CourseDescription(); |
|
477 | - $cd->set_description_type($course_desc_id); |
|
478 | - $cd->set_title($course_desc_title); |
|
479 | - $cd->set_content($course_desc_content); |
|
480 | - $cd->set_session_id(0); |
|
481 | - // Get course info |
|
482 | - $course_info = CourseManager::get_course_information(CourseManager::get_course_code_from_course_id($course_id)); |
|
456 | + /** |
|
457 | + * Edit course description |
|
458 | + * |
|
459 | + * @param string API secret key |
|
460 | + * @param string Course id field name |
|
461 | + * @param string Course id value |
|
462 | + * @param int Category id from course description |
|
463 | + * @param string Description title |
|
464 | + * @param string Course description content |
|
465 | + */ |
|
466 | + public function EditCourseDescription($secret_key, $course_id_field_name, $course_id_value, $course_desc_id, $course_desc_title, $course_desc_content) { |
|
467 | + $verifKey = $this->verifyKey($secret_key); |
|
468 | + if($verifKey instanceof WSError) { |
|
469 | + $this->handleError($verifKey); |
|
470 | + } else { |
|
471 | + $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
472 | + if($course_id instanceof WSError) { |
|
473 | + return $course_id; |
|
474 | + } else { |
|
475 | + // Create the new course description |
|
476 | + $cd = new CourseDescription(); |
|
477 | + $cd->set_description_type($course_desc_id); |
|
478 | + $cd->set_title($course_desc_title); |
|
479 | + $cd->set_content($course_desc_content); |
|
480 | + $cd->set_session_id(0); |
|
481 | + // Get course info |
|
482 | + $course_info = CourseManager::get_course_information(CourseManager::get_course_code_from_course_id($course_id)); |
|
483 | 483 | $cd->set_course_id($course_info['real_id']); |
484 | - // Check if this course description exists |
|
485 | - $descriptions = CourseDescription::get_descriptions($course_id); |
|
486 | - $exists = false; |
|
487 | - foreach($descriptions as $description) { |
|
488 | - if($description->get_description_type() == $course_desc_id) { |
|
489 | - $exists = true; |
|
490 | - } |
|
491 | - } |
|
492 | - if (!$exists) { |
|
493 | - $cd->set_progress(0); |
|
494 | - $cd->insert(); |
|
495 | - } else { |
|
496 | - $cd->update(); |
|
497 | - } |
|
498 | - } |
|
499 | - } |
|
500 | - } |
|
484 | + // Check if this course description exists |
|
485 | + $descriptions = CourseDescription::get_descriptions($course_id); |
|
486 | + $exists = false; |
|
487 | + foreach($descriptions as $description) { |
|
488 | + if($description->get_description_type() == $course_desc_id) { |
|
489 | + $exists = true; |
|
490 | + } |
|
491 | + } |
|
492 | + if (!$exists) { |
|
493 | + $cd->set_progress(0); |
|
494 | + $cd->insert(); |
|
495 | + } else { |
|
496 | + $cd->update(); |
|
497 | + } |
|
498 | + } |
|
499 | + } |
|
500 | + } |
|
501 | 501 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | */ |
22 | 22 | protected function deleteCourseHelper($course_id_field_name, $course_id_value) { |
23 | 23 | $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
24 | - if($course_id instanceof WSError) { |
|
24 | + if ($course_id instanceof WSError) { |
|
25 | 25 | return $course_id; |
26 | 26 | } else { |
27 | 27 | $course_code = CourseManager::get_course_code_from_course_id($course_id); |
@@ -39,11 +39,11 @@ discard block |
||
39 | 39 | */ |
40 | 40 | public function DeleteCourse($secret_key, $course_id_field_name, $course_id_value) { |
41 | 41 | $verifKey = $this->verifyKey($secret_key); |
42 | - if($verifKey instanceof WSError) { |
|
42 | + if ($verifKey instanceof WSError) { |
|
43 | 43 | $this->handleError($verifKey); |
44 | 44 | } else { |
45 | 45 | $result = $this->deleteCourseHelper($course_id_field_name, $course_id_value); |
46 | - if($result instanceof WSError) { |
|
46 | + if ($result instanceof WSError) { |
|
47 | 47 | $this->handleError($result); |
48 | 48 | } |
49 | 49 | } |
@@ -59,15 +59,15 @@ discard block |
||
59 | 59 | */ |
60 | 60 | public function DeleteCourses($secret_key, $courses) { |
61 | 61 | $verifKey = $this->verifyKey($secret_key); |
62 | - if($verifKey instanceof WSError) { |
|
62 | + if ($verifKey instanceof WSError) { |
|
63 | 63 | $this->handleError($verifKey); |
64 | 64 | } else { |
65 | 65 | $results = array(); |
66 | - foreach($courses as $course) { |
|
66 | + foreach ($courses as $course) { |
|
67 | 67 | $result_tmp = array(); |
68 | 68 | $result_op = $this->deleteCourseHelper($course['course_id_field_name'], $course['course_id_value']); |
69 | 69 | $result_tmp['course_id_value'] = $course['course_id_value']; |
70 | - if($result_op instanceof WSError) { |
|
70 | + if ($result_op instanceof WSError) { |
|
71 | 71 | // Return the error in the results |
72 | 72 | $result_tmp['result'] = $result_op->toArray(); |
73 | 73 | } else { |
@@ -97,17 +97,17 @@ discard block |
||
97 | 97 | protected function createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras) { |
98 | 98 | // Add the original course id field name and value to the extra fields if needed |
99 | 99 | $extras_associative = array(); |
100 | - if($course_id_field_name != "chamilo_course_id") { |
|
100 | + if ($course_id_field_name != "chamilo_course_id") { |
|
101 | 101 | $extras_associative[$course_id_field_name] = $course_id_value; |
102 | 102 | } |
103 | - foreach($extras as $extra) { |
|
103 | + foreach ($extras as $extra) { |
|
104 | 104 | $extras_associative[$extra['field_name']] = $extra['field_value']; |
105 | 105 | } |
106 | 106 | $course_admin_id = $this->getUserId($course_admin_user_id_field_name, $course_admin_user_id_value); |
107 | - if($course_admin_id instanceof WSError) { |
|
107 | + if ($course_admin_id instanceof WSError) { |
|
108 | 108 | return $course_admin_id; |
109 | 109 | } |
110 | - if($wanted_code == '') { |
|
110 | + if ($wanted_code == '') { |
|
111 | 111 | $wanted_code = CourseManager::generate_course_code($title); |
112 | 112 | } |
113 | 113 | $result = create_course($wanted_code, $title, $tutor_name, $category_code, $language, $course_admin_id, $this->_configuration['db_prefix'], 0); |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | return new WSError(202, 'There was an error creating the course'); |
116 | 116 | } else { |
117 | 117 | // Update extra fields |
118 | - foreach($extras_associative as $fname => $fvalue) { |
|
118 | + foreach ($extras_associative as $fname => $fvalue) { |
|
119 | 119 | CourseManager::update_course_extra_field_value($result, $fname, $fvalue); |
120 | 120 | } |
121 | 121 | // Get course id |
@@ -143,11 +143,11 @@ discard block |
||
143 | 143 | public function CreateCourse($secret_key, $title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras) { |
144 | 144 | // First, verify the secret key |
145 | 145 | $verifKey = $this->verifyKey($secret_key); |
146 | - if($verifKey instanceof WSError) { |
|
146 | + if ($verifKey instanceof WSError) { |
|
147 | 147 | $this->handleError($verifKey); |
148 | 148 | } else { |
149 | 149 | $result = $this->createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras); |
150 | - if($result instanceof WSError) { |
|
150 | + if ($result instanceof WSError) { |
|
151 | 151 | $this->handleError($result); |
152 | 152 | } else { |
153 | 153 | return $result; |
@@ -165,17 +165,17 @@ discard block |
||
165 | 165 | public function CreateCourses($secret_key, $courses) { |
166 | 166 | // First, verify the secret key |
167 | 167 | $verifKey = $this->verifyKey($secret_key); |
168 | - if($verifKey instanceof WSError) { |
|
168 | + if ($verifKey instanceof WSError) { |
|
169 | 169 | $this->handleError($verifKey); |
170 | 170 | } else { |
171 | 171 | $results = array(); |
172 | - foreach($courses as $course) { |
|
172 | + foreach ($courses as $course) { |
|
173 | 173 | $result_tmp = array(); |
174 | 174 | // re-initialize variables just in case |
175 | 175 | $title = $category_code = $wanted_code = $tutor_name = $course_admin_user_id_field_name = $course_admin_user_id_value = $language = $course_id_field_name = $course_id_value = $extras = 0; |
176 | 176 | extract($course); |
177 | 177 | $result = $this->createCourseHelper($title, $category_code, $wanted_code, $tutor_name, $course_admin_user_id_field_name, $course_admin_user_id_value, $language, $course_id_field_name, $course_id_value, $extras); |
178 | - if($result instanceof WSError) { |
|
178 | + if ($result instanceof WSError) { |
|
179 | 179 | $result_tmp['result'] = $result->toArray(); |
180 | 180 | $result_tmp['course_id_value'] = $course_id_value; |
181 | 181 | $result_tmp['course_id_generated'] = 0; |
@@ -209,47 +209,47 @@ discard block |
||
209 | 209 | */ |
210 | 210 | protected function editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) { |
211 | 211 | $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
212 | - if($course_id instanceof WSError) { |
|
212 | + if ($course_id instanceof WSError) { |
|
213 | 213 | return $course_id; |
214 | 214 | } else { |
215 | 215 | $attributes = array(); |
216 | - if(!empty($title)) { |
|
216 | + if (!empty($title)) { |
|
217 | 217 | $attributes['title'] = $title; |
218 | 218 | } |
219 | - if(!empty($category_code)) { |
|
219 | + if (!empty($category_code)) { |
|
220 | 220 | $attributes['category_code'] = $category_code; |
221 | 221 | } |
222 | - if(!empty($department_name)) { |
|
222 | + if (!empty($department_name)) { |
|
223 | 223 | $attributes['department_name'] = $department_name; |
224 | 224 | } |
225 | - if(!empty($department_url)) { |
|
225 | + if (!empty($department_url)) { |
|
226 | 226 | $attributes['department_url'] = $department_url; |
227 | 227 | } |
228 | - if(!empty($language)) { |
|
228 | + if (!empty($language)) { |
|
229 | 229 | $attributes['course_language'] = $language; |
230 | 230 | } |
231 | - if($visibility != '') { |
|
232 | - $attributes['visibility'] = (int)$visibility; |
|
231 | + if ($visibility != '') { |
|
232 | + $attributes['visibility'] = (int) $visibility; |
|
233 | 233 | } |
234 | - if($subscribe != '') { |
|
235 | - $attributes['subscribe'] = (int)$subscribe; |
|
234 | + if ($subscribe != '') { |
|
235 | + $attributes['subscribe'] = (int) $subscribe; |
|
236 | 236 | } |
237 | - if($unsubscribe != '') { |
|
238 | - $attributes['unsubscribe'] = (int)$unsubscribe; |
|
237 | + if ($unsubscribe != '') { |
|
238 | + $attributes['unsubscribe'] = (int) $unsubscribe; |
|
239 | 239 | } |
240 | - if(!empty($visual_code)) { |
|
240 | + if (!empty($visual_code)) { |
|
241 | 241 | $attributes['visual_code'] = $visual_code; |
242 | 242 | } |
243 | - if(!empty($attributes)) { |
|
243 | + if (!empty($attributes)) { |
|
244 | 244 | CourseManager::update_attributes($course_id, $attributes); |
245 | 245 | } |
246 | - if(!empty($extras)) { |
|
246 | + if (!empty($extras)) { |
|
247 | 247 | $course_code = CourseManager::get_course_code_from_course_id($course_id); |
248 | 248 | $extras_associative = array(); |
249 | - foreach($extras as $extra) { |
|
249 | + foreach ($extras as $extra) { |
|
250 | 250 | $extras_associative[$extra['field_name']] = $extra['field_value']; |
251 | 251 | } |
252 | - foreach($extras_associative as $fname => $fvalue) { |
|
252 | + foreach ($extras_associative as $fname => $fvalue) { |
|
253 | 253 | CourseManager::update_extra_field_value($course_code, $fname, $fvalue); |
254 | 254 | } |
255 | 255 | } |
@@ -276,11 +276,11 @@ discard block |
||
276 | 276 | */ |
277 | 277 | public function EditCourse($secret_key, $course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) { |
278 | 278 | $verifKey = $this->verifyKey($secret_key); |
279 | - if($verifKey instanceof WSError) { |
|
279 | + if ($verifKey instanceof WSError) { |
|
280 | 280 | $this->handleError($verifKey); |
281 | 281 | } else { |
282 | 282 | $result = $this->editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras); |
283 | - if($result instanceof WSError) { |
|
283 | + if ($result instanceof WSError) { |
|
284 | 284 | $this->handleError($result); |
285 | 285 | } |
286 | 286 | } |
@@ -296,10 +296,10 @@ discard block |
||
296 | 296 | */ |
297 | 297 | public function ListCourses($secret_key, $visibility = 'public,public-registered,private,closed') { |
298 | 298 | $verifKey = $this->verifyKey($secret_key); |
299 | - if($verifKey instanceof WSError) { |
|
299 | + if ($verifKey instanceof WSError) { |
|
300 | 300 | $this->handleError($verifKey); |
301 | 301 | } else { |
302 | - $visibilities = split(',',$visibility); |
|
302 | + $visibilities = split(',', $visibility); |
|
303 | 303 | $vis = array('public' => '3', 'public-registered' => '2', 'private' => '1', 'closed' => '0'); |
304 | 304 | foreach ($visibilities as $p => $visibility) { |
305 | 305 | $visibilities[$p] = $vis[$visibility]; |
@@ -308,9 +308,9 @@ discard block |
||
308 | 308 | $category_names = array(); |
309 | 309 | |
310 | 310 | $courses = CourseManager::get_courses_list(); |
311 | - foreach($courses as $course) { |
|
311 | + foreach ($courses as $course) { |
|
312 | 312 | //skip elements that do not match required visibility |
313 | - if (!in_array($course['visibility'],$visibilities)) { continue; } |
|
313 | + if (!in_array($course['visibility'], $visibilities)) { continue; } |
|
314 | 314 | $course_tmp = array(); |
315 | 315 | $course_tmp['id'] = $course['id']; |
316 | 316 | $course_tmp['code'] = $course['code']; |
@@ -319,7 +319,7 @@ discard block |
||
319 | 319 | $course_tmp['visibility'] = $course['visibility']; |
320 | 320 | |
321 | 321 | // Determining category name |
322 | - if($category_names[$course['category_code']]) { |
|
322 | + if ($category_names[$course['category_code']]) { |
|
323 | 323 | $course_tmp['category_name'] = $category_names[$course['category_code']]; |
324 | 324 | } else { |
325 | 325 | $category = CourseManager::get_course_category($course['category_code']); |
@@ -355,21 +355,21 @@ discard block |
||
355 | 355 | */ |
356 | 356 | protected function changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $state, $status = STUDENT) { |
357 | 357 | $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
358 | - if($course_id instanceof WSError) { |
|
358 | + if ($course_id instanceof WSError) { |
|
359 | 359 | return $course_id; |
360 | 360 | } else { |
361 | 361 | $user_id = $this->getUserId($user_id_field_name, $user_id_value); |
362 | - if($user_id instanceof WSError) { |
|
362 | + if ($user_id instanceof WSError) { |
|
363 | 363 | return $user_id; |
364 | 364 | } else { |
365 | 365 | $course_code = CourseManager::get_course_code_from_course_id($course_id); |
366 | - if($state == 0) { |
|
366 | + if ($state == 0) { |
|
367 | 367 | // Unsubscribe user |
368 | 368 | CourseManager::unsubscribe_user($user_id, $course_code); |
369 | 369 | return true; |
370 | 370 | } else { |
371 | 371 | // Subscribe user |
372 | - if(CourseManager::subscribe_user($user_id, $course_code, $status)) { |
|
372 | + if (CourseManager::subscribe_user($user_id, $course_code, $status)) { |
|
373 | 373 | return true; |
374 | 374 | } else { |
375 | 375 | return new WSError(203, 'An error occured subscribing to this course'); |
@@ -391,11 +391,11 @@ discard block |
||
391 | 391 | */ |
392 | 392 | public function SubscribeUserToCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $status) { |
393 | 393 | $verifKey = $this->verifyKey($secret_key); |
394 | - if($verifKey instanceof WSError) { |
|
394 | + if ($verifKey instanceof WSError) { |
|
395 | 395 | $this->handleError($verifKey); |
396 | 396 | } else { |
397 | 397 | $result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 1, $status); |
398 | - if($result instanceof WSError) { |
|
398 | + if ($result instanceof WSError) { |
|
399 | 399 | $this->handleError($result); |
400 | 400 | } |
401 | 401 | } |
@@ -412,11 +412,11 @@ discard block |
||
412 | 412 | */ |
413 | 413 | public function UnsubscribeUserFromCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value) { |
414 | 414 | $verifKey = $this->verifyKey($secret_key); |
415 | - if($verifKey instanceof WSError) { |
|
415 | + if ($verifKey instanceof WSError) { |
|
416 | 416 | $this->handleError($verifKey); |
417 | 417 | } else { |
418 | 418 | $result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 0); |
419 | - if($result instanceof WSError) { |
|
419 | + if ($result instanceof WSError) { |
|
420 | 420 | $this->handleError($result); |
421 | 421 | } |
422 | 422 | } |
@@ -432,17 +432,17 @@ discard block |
||
432 | 432 | */ |
433 | 433 | public function GetCourseDescriptions($secret_key, $course_id_field_name, $course_id_value) { |
434 | 434 | $verifKey = $this->verifyKey($secret_key); |
435 | - if($verifKey instanceof WSError) { |
|
435 | + if ($verifKey instanceof WSError) { |
|
436 | 436 | $this->handleError($verifKey); |
437 | 437 | } else { |
438 | 438 | $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
439 | - if($course_id instanceof WSError) { |
|
439 | + if ($course_id instanceof WSError) { |
|
440 | 440 | return $course_id; |
441 | 441 | } else { |
442 | 442 | // Course exists, get its descriptions |
443 | 443 | $descriptions = CourseDescription::get_descriptions($course_id); |
444 | 444 | $results = array(); |
445 | - foreach($descriptions as $description) { |
|
445 | + foreach ($descriptions as $description) { |
|
446 | 446 | $results[] = array('course_desc_id' => $description->get_description_type(), |
447 | 447 | 'course_desc_title' => $description->get_title(), |
448 | 448 | 'course_desc_content' => $description->get_content()); |
@@ -465,11 +465,11 @@ discard block |
||
465 | 465 | */ |
466 | 466 | public function EditCourseDescription($secret_key, $course_id_field_name, $course_id_value, $course_desc_id, $course_desc_title, $course_desc_content) { |
467 | 467 | $verifKey = $this->verifyKey($secret_key); |
468 | - if($verifKey instanceof WSError) { |
|
468 | + if ($verifKey instanceof WSError) { |
|
469 | 469 | $this->handleError($verifKey); |
470 | 470 | } else { |
471 | 471 | $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
472 | - if($course_id instanceof WSError) { |
|
472 | + if ($course_id instanceof WSError) { |
|
473 | 473 | return $course_id; |
474 | 474 | } else { |
475 | 475 | // Create the new course description |
@@ -484,8 +484,8 @@ discard block |
||
484 | 484 | // Check if this course description exists |
485 | 485 | $descriptions = CourseDescription::get_descriptions($course_id); |
486 | 486 | $exists = false; |
487 | - foreach($descriptions as $description) { |
|
488 | - if($description->get_description_type() == $course_desc_id) { |
|
487 | + foreach ($descriptions as $description) { |
|
488 | + if ($description->get_description_type() == $course_desc_id) { |
|
489 | 489 | $exists = true; |
490 | 490 | } |
491 | 491 | } |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | $strings['VideoConferenceAddedToTheCalendar'] = "Videoconference added to the calendar"; |
21 | 21 | $strings['VideoConferenceAddedToTheLinkTool'] = "Videoconference added to the link tool"; |
22 | 22 | |
23 | -$strings['GoToTheVideoConference'] = "Go to the videoconference"; |
|
23 | +$strings['GoToTheVideoConference'] = "Go to the videoconference"; |
|
24 | 24 | |
25 | 25 | $strings['Records'] = "Recording"; |
26 | 26 | $strings['Meeting'] = "Meeting"; |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | $strings['EnterConference'] = "Enter the videoconference"; |
32 | 32 | $strings['RecordList'] = "Recording list"; |
33 | 33 | $strings['ServerIsNotRunning'] = "Videoconference server is not running"; |
34 | -$strings['ServerIsNotConfigured'] = "Videoconference server is not configured"; |
|
34 | +$strings['ServerIsNotConfigured'] = "Videoconference server is not configured"; |
|
35 | 35 | |
36 | 36 | $strings['XUsersOnLine'] = "%s user(s) online"; |
37 | 37 |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | $strings['VideoConferenceAddedToTheCalendar'] = "Vidéoconférence ajoutée au calendrier"; |
14 | 14 | $strings['VideoConferenceAddedToTheLinkTool'] = "Vidéoconférence ajoutée comme lien. Vous pouvez éditer et publier le lien sur la page principale du cours depuis l'outil liens."; |
15 | 15 | |
16 | -$strings['GoToTheVideoConference'] = "Entrer dans la salle de conférence"; |
|
16 | +$strings['GoToTheVideoConference'] = "Entrer dans la salle de conférence"; |
|
17 | 17 | |
18 | 18 | $strings['Records'] = "Enregistrement"; |
19 | 19 | $strings['Meeting'] = "Salle de conférence"; |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | $strings['EnterConference'] = "Entrer dans la salle de conférence"; |
25 | 25 | $strings['RecordList'] = "Liste des enregistrements"; |
26 | 26 | $strings['ServerIsNotRunning'] = "Le serveur de vidéoconférence ne fonctionne pas"; |
27 | -$strings['ServerIsNotConfigured'] = "Le serveur de vidéoconférence n'est pas configuré correctement"; |
|
27 | +$strings['ServerIsNotConfigured'] = "Le serveur de vidéoconférence n'est pas configuré correctement"; |
|
28 | 28 | |
29 | 29 | $strings['XUsersOnLine'] = "%s utilisateurs dans la salle"; |
30 | 30 |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | $strings['VideoConferenceAddedToTheCalendar'] = "Videoconferencia añadida al calendario"; |
14 | 14 | $strings['VideoConferenceAddedToTheLinkTool'] = "Videoconferencia añadida como enlace. Puede editar y publicar el enlace en la página principal del curso desde la herramienta de enlace."; |
15 | 15 | |
16 | -$strings['GoToTheVideoConference'] = "Ir a la videoconferencia"; |
|
16 | +$strings['GoToTheVideoConference'] = "Ir a la videoconferencia"; |
|
17 | 17 | |
18 | 18 | $strings['Records'] = "Grabación"; |
19 | 19 | $strings['Meeting'] = "Sala de conferencia"; |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | $strings['EnterConference'] = "Entrar a la videoconferencia"; |
25 | 25 | $strings['RecordList'] = "Lista de grabaciones"; |
26 | 26 | $strings['ServerIsNotRunning'] = "El servidor de videoconferencia no está funcionando"; |
27 | -$strings['ServerIsNotConfigured'] = "El servidor de videoconferencia no está configurado correctamente"; |
|
27 | +$strings['ServerIsNotConfigured'] = "El servidor de videoconferencia no está configurado correctamente"; |
|
28 | 28 | |
29 | 29 | $strings['XUsersOnLine'] = "%s usuario(s) en la sala"; |
30 | 30 |
@@ -5,6 +5,6 @@ |
||
5 | 5 | * @author Imanol Losada Oriol <[email protected]> |
6 | 6 | * @package chamilo.plugin.skype |
7 | 7 | */ |
8 | -require_once __DIR__ . '/config.php'; |
|
8 | +require_once __DIR__.'/config.php'; |
|
9 | 9 | |
10 | 10 | Skype::create()->install(); |
@@ -6,4 +6,4 @@ |
||
6 | 6 | * @package chamilo.plugin.skype |
7 | 7 | */ |
8 | 8 | |
9 | -require_once api_get_path(SYS_PATH) . 'main/inc/global.inc.php'; |
|
9 | +require_once api_get_path(SYS_PATH).'main/inc/global.inc.php'; |
@@ -5,6 +5,6 @@ |
||
5 | 5 | * @author Imanol Losada Oriol <[email protected]> |
6 | 6 | * @package chamilo.plugin.skype |
7 | 7 | */ |
8 | -require_once __DIR__ . '/config.php'; |
|
8 | +require_once __DIR__.'/config.php'; |
|
9 | 9 | |
10 | 10 | Skype::create()->install(); |
@@ -5,6 +5,6 @@ |
||
5 | 5 | * @author Imanol Losada Oriol <[email protected]> |
6 | 6 | * @package chamilo.plugin.skype |
7 | 7 | */ |
8 | -require_once __DIR__ . '/config.php'; |
|
8 | +require_once __DIR__.'/config.php'; |
|
9 | 9 | |
10 | 10 | Skype::create()->install(); |
@@ -5,6 +5,6 @@ |
||
5 | 5 | * @author Imanol Losada Oriol <[email protected]> |
6 | 6 | * @package chamilo.plugin.skype |
7 | 7 | */ |
8 | -require_once __DIR__ . '/config.php'; |
|
8 | +require_once __DIR__.'/config.php'; |
|
9 | 9 | |
10 | 10 | Skype::create()->install(); |