@@ -735,7 +735,6 @@ |
||
735 | 735 | * lock = the user can no longer use this account |
736 | 736 | * @author Patrick Cool <[email protected]>, Ghent University |
737 | 737 | * @param int $active the current state of the account |
738 | - * @param int $user_id The user id |
|
739 | 738 | * @param string $urlParams |
740 | 739 | * |
741 | 740 | * @return string Some HTML-code with the lock/unlock button |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | */ |
14 | 14 | $use_anonymous = true; |
15 | 15 | require_once __DIR__.'/../inc/global.inc.php'; |
16 | -$current_course_tool = TOOL_USER; |
|
16 | +$current_course_tool = TOOL_USER; |
|
17 | 17 | $this_section = SECTION_COURSES; |
18 | 18 | |
19 | 19 | // notice for unauthorized people. |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | |
42 | 42 | //Can't auto unregister from a session |
43 | 43 | if (!empty($sessionId)) { |
44 | - $course_info['unsubscribe'] = 0; |
|
44 | + $course_info['unsubscribe'] = 0; |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | /* Unregistering a user section */ |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | '#', |
174 | 174 | get_lang('UserPicture'), |
175 | 175 | get_lang('OfficialCode'), |
176 | - get_lang('FirstName') . ', ' . get_lang('LastName'), |
|
176 | + get_lang('FirstName').', '.get_lang('LastName'), |
|
177 | 177 | get_lang('Email'), |
178 | 178 | get_lang('Phone') |
179 | 179 | ); |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | '#', |
183 | 183 | get_lang('UserPicture'), |
184 | 184 | get_lang('OfficialCode'), |
185 | - get_lang('LastName') . ', ' . get_lang('FirstName'), |
|
185 | + get_lang('LastName').', '.get_lang('FirstName'), |
|
186 | 186 | get_lang('Email'), |
187 | 187 | get_lang('Phone') |
188 | 188 | ); |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | if (api_is_multiple_url_enabled()) { |
208 | 208 | $sql .= ' , '.Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER).' au '; |
209 | 209 | } |
210 | - $sql .=" WHERE c_id = '$courseId' AND session_course_user.user_id = user.user_id "; |
|
210 | + $sql .= " WHERE c_id = '$courseId' AND session_course_user.user_id = user.user_id "; |
|
211 | 211 | $sql .= ' AND session_id = '.$sessionId; |
212 | 212 | |
213 | 213 | if (api_is_multiple_url_enabled()) { |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | $counter, |
256 | 256 | $user_image, |
257 | 257 | $user['official_code'], |
258 | - $user['firstname'] . ', ' . $user['lastname'], |
|
258 | + $user['firstname'].', '.$user['lastname'], |
|
259 | 259 | $user['email'], |
260 | 260 | $user['phone'] |
261 | 261 | ); |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | $counter, |
265 | 265 | $user_image, |
266 | 266 | $user['official_code'], |
267 | - $user['lastname'] . ', ' . $user['firstname'], |
|
267 | + $user['lastname'].', '.$user['firstname'], |
|
268 | 268 | $user['email'], |
269 | 269 | $user['phone'] |
270 | 270 | ); |
@@ -343,7 +343,7 @@ discard block |
||
343 | 343 | $counter, |
344 | 344 | $user_image, |
345 | 345 | $user['official_code'], |
346 | - $user['firstname'] . ', ' . $user['lastname'], |
|
346 | + $user['firstname'].', '.$user['lastname'], |
|
347 | 347 | $user['email'], |
348 | 348 | $user['phone'] |
349 | 349 | ); |
@@ -352,7 +352,7 @@ discard block |
||
352 | 352 | $counter, |
353 | 353 | $user_image, |
354 | 354 | $user['official_code'], |
355 | - $user['lastname'] . ', ' . $user['firstname'], |
|
355 | + $user['lastname'].', '.$user['firstname'], |
|
356 | 356 | $user['email'], |
357 | 357 | $user['phone'] |
358 | 358 | ); |
@@ -701,7 +701,7 @@ discard block |
||
701 | 701 | $userInfo = api_get_user_info($user_id); |
702 | 702 | $userPicture = $userInfo['avatar']; |
703 | 703 | |
704 | - $photo= '<img src="'.$userPicture.'" alt="'.$userInfo['complete_name'].'" width="22" height="22" title="'.$userInfo['complete_name'].'" />'; |
|
704 | + $photo = '<img src="'.$userPicture.'" alt="'.$userInfo['complete_name'].'" width="22" height="22" title="'.$userInfo['complete_name'].'" />'; |
|
705 | 705 | |
706 | 706 | $temp[] = $user_id; |
707 | 707 | $temp[] = $photo; |
@@ -824,7 +824,7 @@ discard block |
||
824 | 824 | if (api_get_setting('allow_user_course_subscription_by_course_admin') === 'true' or api_is_platform_admin()) { |
825 | 825 | // unregister |
826 | 826 | if ($user_id != $current_user_id || api_is_platform_admin()) { |
827 | - $result .= '<a class="btn btn-small btn-danger" href="'.api_get_self().'?'.api_get_cidreq().'&type='.$type.'&unregister=yes&user_id='.$user_id.'" title="'.get_lang('Unreg').' " onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES,$charset)).'\')) return false;">'. |
|
827 | + $result .= '<a class="btn btn-small btn-danger" href="'.api_get_self().'?'.api_get_cidreq().'&type='.$type.'&unregister=yes&user_id='.$user_id.'" title="'.get_lang('Unreg').' " onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset)).'\')) return false;">'. |
|
828 | 828 | get_lang('Unreg').'</a> '; |
829 | 829 | } else { |
830 | 830 | //$result .= Display::return_icon('unsubscribe_course_na.png', get_lang('Unreg'),'',ICON_SIZE_SMALL).'</a> '; |
@@ -834,7 +834,7 @@ discard block |
||
834 | 834 | // Show buttons for unsubscribe |
835 | 835 | if ($course_info['unsubscribe'] == 1) { |
836 | 836 | if ($user_id == $current_user_id) { |
837 | - $result .= '<a class="btn btn-small btn-danger" href="'.api_get_self().'?'.api_get_cidreq().'&type='.$type.'&unregister=yes&user_id='.$user_id.'" title="'.get_lang('Unreg').' " onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES,$charset)).'\')) return false;">'. |
|
837 | + $result .= '<a class="btn btn-small btn-danger" href="'.api_get_self().'?'.api_get_cidreq().'&type='.$type.'&unregister=yes&user_id='.$user_id.'" title="'.get_lang('Unreg').' " onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset)).'\')) return false;">'. |
|
838 | 838 | get_lang('Unreg').'</a> '; |
839 | 839 | } |
840 | 840 | } |
@@ -914,7 +914,7 @@ discard block |
||
914 | 914 | |
915 | 915 | // Actions column |
916 | 916 | $table->set_header($header_nr++, get_lang('Action'), false); |
917 | - $table->set_column_filter($header_nr-1, 'modify_filter'); |
|
917 | + $table->set_column_filter($header_nr - 1, 'modify_filter'); |
|
918 | 918 | |
919 | 919 | if (api_get_setting('allow_user_course_subscription_by_course_admin') == 'true') { |
920 | 920 | $table->set_form_actions(array('unsubscribe' => get_lang('Unreg')), 'user'); |
@@ -922,7 +922,7 @@ discard block |
||
922 | 922 | } else { |
923 | 923 | if ($course_info['unsubscribe'] == 1) { |
924 | 924 | $table->set_header($header_nr++, get_lang('Action'), false); |
925 | - $table->set_column_filter($header_nr-1, 'modify_filter'); |
|
925 | + $table->set_column_filter($header_nr - 1, 'modify_filter'); |
|
926 | 926 | } |
927 | 927 | } |
928 | 928 | |
@@ -978,19 +978,19 @@ discard block |
||
978 | 978 | echo '<div class="col-md-6">'; |
979 | 979 | echo $icon; |
980 | 980 | $actions .= '<a href="user.php?'.api_get_cidreq().'&action=export&format=csv&type='.$type.'">'. |
981 | - Display::return_icon('export_csv.png', get_lang('ExportAsCSV'),'',ICON_SIZE_MEDIUM).'</a> '; |
|
981 | + Display::return_icon('export_csv.png', get_lang('ExportAsCSV'), '', ICON_SIZE_MEDIUM).'</a> '; |
|
982 | 982 | $actions .= '<a href="user.php?'.api_get_cidreq().'&action=export&format=xls&type='.$type.'">'. |
983 | - Display::return_icon('export_excel.png', get_lang('ExportAsXLS'),'',ICON_SIZE_MEDIUM).'</a> '; |
|
983 | + Display::return_icon('export_excel.png', get_lang('ExportAsXLS'), '', ICON_SIZE_MEDIUM).'</a> '; |
|
984 | 984 | |
985 | 985 | if (api_get_setting('allow_user_course_subscription_by_course_admin') == 'true' || |
986 | 986 | api_is_platform_admin() |
987 | 987 | ) { |
988 | 988 | $actions .= '<a href="user_import.php?'.api_get_cidreq().'&action=import">'. |
989 | - Display::return_icon('import_csv.png', get_lang('ImportUsersToACourse'),'',ICON_SIZE_MEDIUM).'</a> '; |
|
989 | + Display::return_icon('import_csv.png', get_lang('ImportUsersToACourse'), '', ICON_SIZE_MEDIUM).'</a> '; |
|
990 | 990 | } |
991 | 991 | |
992 | 992 | $actions .= '<a href="user.php?'.api_get_cidreq().'&action=export&format=pdf&type='.$type.'">'. |
993 | - Display::return_icon('pdf.png', get_lang('ExportToPDF'),'',ICON_SIZE_MEDIUM).'</a> '; |
|
993 | + Display::return_icon('pdf.png', get_lang('ExportToPDF'), '', ICON_SIZE_MEDIUM).'</a> '; |
|
994 | 994 | echo $actions; |
995 | 995 | |
996 | 996 | echo '</div>'; |
@@ -17,6 +17,9 @@ |
||
17 | 17 | define('WS_ERROR_INVALID_INPUT', 3); |
18 | 18 | define('WS_ERROR_SETTING', 4); |
19 | 19 | |
20 | +/** |
|
21 | + * @param integer $code |
|
22 | + */ |
|
20 | 23 | function return_error($code) { |
21 | 24 | $fault = null; |
22 | 25 | switch ($code) { |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | } |
76 | 76 | |
77 | 77 | if ($debug) { |
78 | - error_log("checkip " . intval($check_ip)); |
|
78 | + error_log("checkip ".intval($check_ip)); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | if ($check_ip) { |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | '', |
132 | 132 | 'SOAP-ENC:Array', |
133 | 133 | array(), |
134 | - array(array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType' => 'tns:portalItem[]')),'tns:portalItem' |
|
134 | + array(array('ref'=>'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:portalItem[]')), 'tns:portalItem' |
|
135 | 135 | ); |
136 | 136 | |
137 | 137 | $server->wsdl->addComplexType( |
@@ -146,13 +146,13 @@ discard block |
||
146 | 146 | ); |
147 | 147 | |
148 | 148 | // Register the method to expose |
149 | -$server->register('WSGetPortals', // method name |
|
150 | - array('getPortals' => 'tns:getPortals'), // input parameters |
|
151 | - array('return' => 'tns:portalList'), // output parameters |
|
152 | - 'urn:WSAccessUrl', // namespace |
|
153 | - 'urn:WSAccessUrl#WSGetPortals', // soapaction |
|
154 | - 'rpc', // style |
|
155 | - 'encoded', // use |
|
149 | +$server->register('WSGetPortals', // method name |
|
150 | + array('getPortals' => 'tns:getPortals'), // input parameters |
|
151 | + array('return' => 'tns:portalList'), // output parameters |
|
152 | + 'urn:WSAccessUrl', // namespace |
|
153 | + 'urn:WSAccessUrl#WSGetPortals', // soapaction |
|
154 | + 'rpc', // style |
|
155 | + 'encoded', // use |
|
156 | 156 | 'This service adds a user to portal' // documentation |
157 | 157 | ); |
158 | 158 | |
@@ -193,13 +193,13 @@ discard block |
||
193 | 193 | ); |
194 | 194 | |
195 | 195 | // Register the method to expose |
196 | -$server->register('WSAddUserToPortal', // method name |
|
197 | - array('addUserToPortal' => 'tns:AddUserToPortal'), // input parameters |
|
198 | - array('return' => 'xsd:string'), // output parameters |
|
199 | - 'urn:WSAccessUrl', // namespace |
|
200 | - 'urn:WSAccessUrl#WSAddUserToPortal', // soapaction |
|
201 | - 'rpc', // style |
|
202 | - 'encoded', // use |
|
196 | +$server->register('WSAddUserToPortal', // method name |
|
197 | + array('addUserToPortal' => 'tns:AddUserToPortal'), // input parameters |
|
198 | + array('return' => 'xsd:string'), // output parameters |
|
199 | + 'urn:WSAccessUrl', // namespace |
|
200 | + 'urn:WSAccessUrl#WSAddUserToPortal', // soapaction |
|
201 | + 'rpc', // style |
|
202 | + 'encoded', // use |
|
203 | 203 | 'This service adds a user to portal' // documentation |
204 | 204 | ); |
205 | 205 | |
@@ -224,13 +224,13 @@ discard block |
||
224 | 224 | } |
225 | 225 | |
226 | 226 | // Register the method to expose |
227 | -$server->register('WSRemoveUserFromPortal', // method name |
|
228 | - array('removeUserFromPortal' => 'tns:AddUserToPortal'), // input parameters |
|
229 | - array('return' => 'xsd:string'), // output parameters |
|
230 | - 'urn:WSAccessUrl', // namespace |
|
231 | - 'urn:WSAccessUrl#WSRemoveUserFromPortal', // soapaction |
|
232 | - 'rpc', // style |
|
233 | - 'encoded', // use |
|
227 | +$server->register('WSRemoveUserFromPortal', // method name |
|
228 | + array('removeUserFromPortal' => 'tns:AddUserToPortal'), // input parameters |
|
229 | + array('return' => 'xsd:string'), // output parameters |
|
230 | + 'urn:WSAccessUrl', // namespace |
|
231 | + 'urn:WSAccessUrl#WSRemoveUserFromPortal', // soapaction |
|
232 | + 'rpc', // style |
|
233 | + 'encoded', // use |
|
234 | 234 | 'This service remove a user from a portal' // documentation |
235 | 235 | ); |
236 | 236 | |
@@ -267,13 +267,13 @@ discard block |
||
267 | 267 | ); |
268 | 268 | |
269 | 269 | // Register the method to expose |
270 | -$server->register('WSGetPortalListFromUser', // method name |
|
271 | - array('getPortalListFromUser' => 'tns:getPortalListFromUser'), // input parameters |
|
272 | - array('return' => 'tns:portalList'), // output parameters |
|
273 | - 'urn:WSAccessUrl', // namespace |
|
274 | - 'urn:WSAccessUrl#WSGetPortalListFromUser', // soapaction |
|
275 | - 'rpc', // style |
|
276 | - 'encoded', // use |
|
270 | +$server->register('WSGetPortalListFromUser', // method name |
|
271 | + array('getPortalListFromUser' => 'tns:getPortalListFromUser'), // input parameters |
|
272 | + array('return' => 'tns:portalList'), // output parameters |
|
273 | + 'urn:WSAccessUrl', // namespace |
|
274 | + 'urn:WSAccessUrl#WSGetPortalListFromUser', // soapaction |
|
275 | + 'rpc', // style |
|
276 | + 'encoded', // use |
|
277 | 277 | 'This service remove a user from a portal' // documentation |
278 | 278 | ); |
279 | 279 | |
@@ -311,13 +311,13 @@ discard block |
||
311 | 311 | ); |
312 | 312 | |
313 | 313 | // Register the method to expose |
314 | -$server->register('WSGetPortalListFromCourse', // method name |
|
315 | - array('getPortalListFromCourse' => 'tns:getPortalListFromCourse'), // input parameters |
|
316 | - array('return' => 'tns:portalList'), // output parameters |
|
317 | - 'urn:WSAccessUrl', // namespace |
|
318 | - 'urn:WSAccessUrl#getPortalListFromCourse', // soapaction |
|
319 | - 'rpc', // style |
|
320 | - 'encoded', // use |
|
314 | +$server->register('WSGetPortalListFromCourse', // method name |
|
315 | + array('getPortalListFromCourse' => 'tns:getPortalListFromCourse'), // input parameters |
|
316 | + array('return' => 'tns:portalList'), // output parameters |
|
317 | + 'urn:WSAccessUrl', // namespace |
|
318 | + 'urn:WSAccessUrl#getPortalListFromCourse', // soapaction |
|
319 | + 'rpc', // style |
|
320 | + 'encoded', // use |
|
321 | 321 | 'This service remove a user from a portal' // documentation |
322 | 322 | ); |
323 | 323 | |
@@ -361,13 +361,13 @@ discard block |
||
361 | 361 | ); |
362 | 362 | |
363 | 363 | // Register the method to expose |
364 | -$server->register('WSAddCourseToPortal', // method name |
|
365 | - array('addCourseToPortal' => 'tns:addCourseToPortal'), // input parameters |
|
366 | - array('return' => 'xsd:string'), // output parameters |
|
367 | - 'urn:WSAccessUrl', // namespace |
|
368 | - 'urn:WSAccessUrl#WSAddCourseToPortal', // soapaction |
|
369 | - 'rpc', // style |
|
370 | - 'encoded', // use |
|
364 | +$server->register('WSAddCourseToPortal', // method name |
|
365 | + array('addCourseToPortal' => 'tns:addCourseToPortal'), // input parameters |
|
366 | + array('return' => 'xsd:string'), // output parameters |
|
367 | + 'urn:WSAccessUrl', // namespace |
|
368 | + 'urn:WSAccessUrl#WSAddCourseToPortal', // soapaction |
|
369 | + 'rpc', // style |
|
370 | + 'encoded', // use |
|
371 | 371 | 'This service adds a course to portal' // documentation |
372 | 372 | ); |
373 | 373 | |
@@ -394,13 +394,13 @@ discard block |
||
394 | 394 | } |
395 | 395 | |
396 | 396 | // Register the method to expose |
397 | -$server->register('WSRemoveCourseFromPortal', // method name |
|
398 | - array('removeCourseFromPortal' => 'tns:addCourseToPortal'), // input parameters |
|
399 | - array('return' => 'xsd:string'), // output parameters |
|
400 | - 'urn:WSAccessUrl', // namespace |
|
401 | - 'urn:WSAccessUrl#WSRemoveCourseFromPortal', // soapaction |
|
402 | - 'rpc', // style |
|
403 | - 'encoded', // use |
|
397 | +$server->register('WSRemoveCourseFromPortal', // method name |
|
398 | + array('removeCourseFromPortal' => 'tns:addCourseToPortal'), // input parameters |
|
399 | + array('return' => 'xsd:string'), // output parameters |
|
400 | + 'urn:WSAccessUrl', // namespace |
|
401 | + 'urn:WSAccessUrl#WSRemoveCourseFromPortal', // soapaction |
|
402 | + 'rpc', // style |
|
403 | + 'encoded', // use |
|
404 | 404 | 'This service remove a course from a portal' // documentation |
405 | 405 | ); |
406 | 406 |
@@ -58,19 +58,22 @@ discard block |
||
58 | 58 | list($ip1, $ip2) = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); |
59 | 59 | $ip = trim($ip1); |
60 | 60 | } |
61 | - if ($debug) |
|
62 | - error_log("ip: $ip"); |
|
61 | + if ($debug) { |
|
62 | + error_log("ip: $ip"); |
|
63 | + } |
|
63 | 64 | // Check if a file that limits access from webservices exists and contains |
64 | 65 | // the restraining check |
65 | 66 | if (is_file('webservice-auth-ip.conf.php')) { |
66 | 67 | include 'webservice-auth-ip.conf.php'; |
67 | - if ($debug) |
|
68 | - error_log("webservice-auth-ip.conf.php file included"); |
|
68 | + if ($debug) { |
|
69 | + error_log("webservice-auth-ip.conf.php file included"); |
|
70 | + } |
|
69 | 71 | if (!empty($ws_auth_ip)) { |
70 | 72 | $check_ip = true; |
71 | 73 | $ip_matches = api_check_ip_in_range($ip, $ws_auth_ip); |
72 | - if ($debug) |
|
73 | - error_log("ip_matches: $ip_matches"); |
|
74 | + if ($debug) { |
|
75 | + error_log("ip_matches: $ip_matches"); |
|
76 | + } |
|
74 | 77 | } |
75 | 78 | } |
76 | 79 | |
@@ -87,8 +90,9 @@ discard block |
||
87 | 90 | |
88 | 91 | $result = api_is_valid_secret_key($secret_key, $security_key); |
89 | 92 | //error_log($secret_key.'-'.$security_key); |
90 | - if ($debug) |
|
91 | - error_log('WSHelperVerifyKey result: '.intval($result)); |
|
93 | + if ($debug) { |
|
94 | + error_log('WSHelperVerifyKey result: '.intval($result)); |
|
95 | + } |
|
92 | 96 | return $result; |
93 | 97 | } |
94 | 98 |
@@ -84,7 +84,7 @@ |
||
84 | 84 | } |
85 | 85 | |
86 | 86 | /** |
87 | - * @param $directoryPath |
|
87 | + * @param string $directoryPath |
|
88 | 88 | * @return bool |
89 | 89 | */ |
90 | 90 | function deleteDirectory($directoryPath) |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | } |
29 | 29 | $fileData = $pptData['file_data']; |
30 | 30 | $dataInfo = pathinfo($pptData['file_name']); |
31 | - $fileName = basename($pptData['file_name'], '.' . $dataInfo['extension']); |
|
31 | + $fileName = basename($pptData['file_name'], '.'.$dataInfo['extension']); |
|
32 | 32 | $fullFileName = $pptData['file_name']; |
33 | 33 | $size = $pptData['service_ppt2lp_size']; |
34 | 34 | $w = '800'; |
@@ -38,8 +38,8 @@ discard block |
||
38 | 38 | } |
39 | 39 | |
40 | 40 | $tempArchivePath = api_get_path(SYS_ARCHIVE_PATH); |
41 | - $tempPath = $tempArchivePath . 'wsConvert/' . $fileName . '/'; |
|
42 | - $tempPathNewFiles = $tempArchivePath . 'wsConvert/' . $fileName . '-n/'; |
|
41 | + $tempPath = $tempArchivePath.'wsConvert/'.$fileName.'/'; |
|
42 | + $tempPathNewFiles = $tempArchivePath.'wsConvert/'.$fileName.'-n/'; |
|
43 | 43 | |
44 | 44 | $oldumask = umask(0); |
45 | 45 | //$perms = api_get_permissions_for_new_directories(); |
@@ -49,13 +49,13 @@ discard block |
||
49 | 49 | pptConverterDirectoriesCreate($tempPath, $tempPathNewFiles, $fileName, $perms); |
50 | 50 | |
51 | 51 | $file = base64_decode($fileData); |
52 | - file_put_contents($tempPath . $fullFileName, $file); |
|
52 | + file_put_contents($tempPath.$fullFileName, $file); |
|
53 | 53 | |
54 | 54 | $cmd = pptConverterGetCommandBaseParams(); |
55 | - $cmd .= ' -w ' . $w . ' -h ' . $h . ' -d oogie "' . $tempPath . $fullFileName.'" "' . $tempPathNewFiles . $fileName . '.html"'; |
|
55 | + $cmd .= ' -w '.$w.' -h '.$h.' -d oogie "'.$tempPath.$fullFileName.'" "'.$tempPathNewFiles.$fileName.'.html"'; |
|
56 | 56 | |
57 | 57 | //$perms = api_get_permissions_for_new_files(); |
58 | - chmod($tempPathNewFiles . $fileName, $perms); |
|
58 | + chmod($tempPathNewFiles.$fileName, $perms); |
|
59 | 59 | |
60 | 60 | $files = array(); |
61 | 61 | $return = 0; |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | if (is_array($files) && !empty($files)) { |
68 | 68 | foreach ($files as $file) { |
69 | 69 | $imageData = explode('||', $file); |
70 | - $images[$imageData[1]] = base64_encode(file_get_contents($tempPathNewFiles . $fileName . '/' . $imageData[1])); |
|
70 | + $images[$imageData[1]] = base64_encode(file_get_contents($tempPathNewFiles.$fileName.'/'.$imageData[1])); |
|
71 | 71 | } |
72 | 72 | } |
73 | 73 | $data = array( |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | */ |
94 | 94 | function deleteDirectory($directoryPath) |
95 | 95 | { |
96 | - $files = array_diff(scandir($directoryPath), array('.','..')); |
|
96 | + $files = array_diff(scandir($directoryPath), array('.', '..')); |
|
97 | 97 | foreach ($files as $file) { |
98 | 98 | if (is_dir("$directoryPath/$file")) { |
99 | 99 | deleteDirectory("$directoryPath/$file"); |
@@ -121,8 +121,8 @@ discard block |
||
121 | 121 | if (!is_dir($tempPathNewFiles)) { |
122 | 122 | mkdir($tempPathNewFiles, $perms, true); |
123 | 123 | } |
124 | - if (!is_dir($tempPathNewFiles . $fileName)) { |
|
125 | - mkdir($tempPathNewFiles . $fileName, $perms, true); |
|
124 | + if (!is_dir($tempPathNewFiles.$fileName)) { |
|
125 | + mkdir($tempPathNewFiles.$fileName, $perms, true); |
|
126 | 126 | } |
127 | 127 | } |
128 | 128 | |
@@ -133,16 +133,16 @@ discard block |
||
133 | 133 | function pptConverterGetCommandBaseParams() |
134 | 134 | { |
135 | 135 | if (IS_WINDOWS_OS) { // IS_WINDOWS_OS has been defined in main_api.lib.php |
136 | - $converterPath = str_replace('/', '\\', api_get_path(SYS_PATH) . 'main/inc/lib/ppt2png'); |
|
137 | - $classPath = $converterPath . ';' . $converterPath . '/jodconverter-2.2.2.jar;' . $converterPath . '/jodconverter-cli-2.2.2.jar'; |
|
138 | - $cmd = 'java -Dfile.encoding=UTF-8 -cp "' . $classPath . '" DokeosConverter'; |
|
136 | + $converterPath = str_replace('/', '\\', api_get_path(SYS_PATH).'main/inc/lib/ppt2png'); |
|
137 | + $classPath = $converterPath.';'.$converterPath.'/jodconverter-2.2.2.jar;'.$converterPath.'/jodconverter-cli-2.2.2.jar'; |
|
138 | + $cmd = 'java -Dfile.encoding=UTF-8 -cp "'.$classPath.'" DokeosConverter'; |
|
139 | 139 | } else { |
140 | - $converterPath = api_get_path(SYS_PATH) . 'main/inc/lib/ppt2png'; |
|
140 | + $converterPath = api_get_path(SYS_PATH).'main/inc/lib/ppt2png'; |
|
141 | 141 | $classPath = ' -Dfile.encoding=UTF-8 -cp .:jodconverter-2.2.2.jar:jodconverter-cli-2.2.2.jar'; |
142 | - $cmd = 'cd ' . $converterPath . ' && java ' . $classPath . ' DokeosConverter'; |
|
142 | + $cmd = 'cd '.$converterPath.' && java '.$classPath.' DokeosConverter'; |
|
143 | 143 | } |
144 | 144 | |
145 | - $cmd .= ' -p ' . api_get_setting('service_ppt2lp', 'port'); |
|
145 | + $cmd .= ' -p '.api_get_setting('service_ppt2lp', 'port'); |
|
146 | 146 | return $cmd; |
147 | 147 | } |
148 | 148 | |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | $webCodePath = api_get_path(WEB_CODE_PATH); |
152 | 152 | $options = array( |
153 | 153 | 'uri' => $webPath, |
154 | - 'location' => $webCodePath . 'webservices/additional_webservices.php' |
|
154 | + 'location' => $webCodePath.'webservices/additional_webservices.php' |
|
155 | 155 | ); |
156 | 156 | |
157 | 157 | $soapServer = new SoapServer(NULL, $options); |
@@ -342,6 +342,7 @@ |
||
342 | 342 | * @param string User id value |
343 | 343 | * @param int Set to 1 to subscribe, 0 to unsubscribe |
344 | 344 | * @param int Status (STUDENT or TEACHER) Used for subscription only |
345 | + * @param integer $state |
|
345 | 346 | * @return mixed True if subscription or unsubscription was successful, false otherwise |
346 | 347 | */ |
347 | 348 | protected function changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $state, $status = STUDENT) { |
@@ -521,8 +521,9 @@ |
||
521 | 521 | |
522 | 522 | public function nada($username, $password) |
523 | 523 | { |
524 | - if($this->verifyUserPass($username, $password) == "valid") |
|
525 | - return $username.$password; |
|
524 | + if($this->verifyUserPass($username, $password) == "valid") { |
|
525 | + return $username.$password; |
|
526 | + } |
|
526 | 527 | return $username; |
527 | 528 | } |
528 | 529 |
@@ -10,521 +10,521 @@ |
||
10 | 10 | */ |
11 | 11 | class WSCMCourse extends WSCM |
12 | 12 | { |
13 | - /** |
|
14 | - * Deletes a course (helper method) |
|
15 | - * |
|
16 | - * @param string Course id field name |
|
17 | - * @param string Course id value |
|
18 | - * @return mixed True if the course was successfully deleted, WSError otherwise |
|
19 | - */ |
|
20 | - protected function deleteCourseHelper($course_id_field_name, $course_id_value) { |
|
21 | - $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
22 | - if($course_id instanceof WSCMError) { |
|
23 | - return $course_id; |
|
24 | - } else { |
|
25 | - $course_code = CourseManager::get_course_code_from_course_id($course_id); |
|
26 | - CourseManager::delete_course($course_code); |
|
27 | - return true; |
|
28 | - } |
|
29 | - } |
|
30 | - |
|
31 | - /** |
|
32 | - * Deletes a course |
|
33 | - * |
|
34 | - * @param string API secret key |
|
35 | - * @param string Course id field name |
|
36 | - * @param string Course id value |
|
37 | - */ |
|
38 | - public function DeleteCourse($secret_key, $course_id_field_name, $course_id_value) { |
|
39 | - $verifKey = $this->verifyKey($secret_key); |
|
40 | - if($verifKey instanceof WSError) { |
|
41 | - $this->handleError($verifKey); |
|
42 | - } else { |
|
43 | - $result = $this->deleteCourseHelper($course_id_field_name, $course_id_value); |
|
44 | - if($result instanceof WSError) { |
|
45 | - $this->handleError($result); |
|
46 | - } |
|
47 | - } |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * Deletes multiple courses |
|
52 | - * |
|
53 | - * @param string API secret key |
|
54 | - * @param array Array of courses with elements of the form array('course_id_field_name' => 'name_of_field', 'course_id_value' => 'value') |
|
55 | - * @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 |
|
56 | - * than 0, an error occured |
|
57 | - */ |
|
58 | - public function DeleteCourses($secret_key, $courses) { |
|
59 | - $verifKey = $this->verifyKey($secret_key); |
|
60 | - if($verifKey instanceof WSError) { |
|
61 | - $this->handleError($verifKey); |
|
62 | - } else { |
|
63 | - $results = array(); |
|
64 | - foreach($courses as $course) { |
|
65 | - $result_tmp = array(); |
|
66 | - $result_op = $this->deleteCourseHelper($course['course_id_field_name'], $course['course_id_value']); |
|
67 | - $result_tmp['course_id_value'] = $course['course_id_value']; |
|
68 | - if($result_op instanceof WSCMError) { |
|
69 | - // Return the error in the results |
|
70 | - $result_tmp['result'] = $result_op->toArray(); |
|
71 | - } else { |
|
72 | - $result_tmp['result'] = $this->getSuccessfulResult(); |
|
73 | - } |
|
74 | - $results[] = $result_tmp; |
|
75 | - } |
|
76 | - return $results; |
|
77 | - } |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * Creates a course (helper method) |
|
82 | - * |
|
83 | - * @param string Title |
|
84 | - * @param string Category code |
|
85 | - * @param string Wanted code. If it's not defined, it will be generated automatically |
|
86 | - * @param string Tutor name |
|
87 | - * @param string Course admin user id field name |
|
88 | - * @param string Course admin user id value |
|
89 | - * @param string Course language |
|
90 | - * @param string Course id field name |
|
91 | - * @param string Course id value |
|
92 | - * @param array Course extra fields |
|
93 | - * @return mixed Generated id if creation was successful, WSError otherwise |
|
94 | - */ |
|
95 | - 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) { |
|
96 | - // Add the original course id field name and value to the extra fields if needed |
|
97 | - $extras_associative = array(); |
|
98 | - if($course_id_field_name != "chamilo_course_id") { |
|
99 | - $extras_associative[$course_id_field_name] = $course_id_value; |
|
100 | - } |
|
101 | - foreach($extras as $extra) { |
|
102 | - $extras_associative[$extra['field_name']] = $extra['field_value']; |
|
103 | - } |
|
104 | - $course_admin_id = $this->getUserId($course_admin_user_id_field_name, $course_admin_user_id_value); |
|
105 | - if($course_admin_id instanceof WSError) { |
|
106 | - return $course_admin_id; |
|
107 | - } |
|
108 | - if($wanted_code == '') { |
|
109 | - $wanted_code = CourseManager::generate_course_code($title); |
|
110 | - } |
|
111 | - $result = create_course($wanted_code, $title, $tutor_name, $category_code, $language, $course_admin_id, $this->_configuration['db_prefix'], 0); |
|
112 | - if (!$result) { |
|
113 | - return new WSError(202, 'There was an error creating the course'); |
|
114 | - } else { |
|
115 | - // Update extra fields |
|
116 | - foreach($extras_associative as $fname => $fvalue) { |
|
117 | - CourseManager::update_course_extra_field_value($result, $fname, $fvalue); |
|
118 | - } |
|
119 | - // Get course id |
|
120 | - $course_info = CourseManager::get_course_information($result); |
|
121 | - return $course_info['real_id']; |
|
122 | - } |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * Creates a course |
|
127 | - * |
|
128 | - * @param string API secret key |
|
129 | - * @param string Title |
|
130 | - * @param string Category code |
|
131 | - * @param string Wanted code. If it's not defined, it will be generated automatically |
|
132 | - * @param string Tutor name |
|
133 | - * @param string Course admin user id field name |
|
134 | - * @param string Course admin user id value |
|
135 | - * @param string Course language |
|
136 | - * @param string Course id field name |
|
137 | - * @param string Course id value |
|
138 | - * @param array Course extra fields |
|
139 | - * @return int Course id generated |
|
140 | - */ |
|
141 | - 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) { |
|
142 | - // First, verify the secret key |
|
143 | - $verifKey = $this->verifyKey($secret_key); |
|
144 | - if($verifKey instanceof WSError) { |
|
145 | - $this->handleError($verifKey); |
|
146 | - } else { |
|
147 | - $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); |
|
148 | - if($result instanceof WSError) { |
|
149 | - $this->handleError($result); |
|
150 | - } else { |
|
151 | - return $result; |
|
152 | - } |
|
153 | - } |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * Create multiple courses |
|
158 | - * |
|
159 | - * @param string API secret key |
|
160 | - * @param array Courses to be created, with elements following the structure presented in CreateCourse |
|
161 | - * @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')) |
|
162 | - */ |
|
163 | - public function CreateCourses($secret_key, $courses) { |
|
164 | - // First, verify the secret key |
|
165 | - $verifKey = $this->verifyKey($secret_key); |
|
166 | - if($verifKey instanceof WSCMError) { |
|
167 | - $this->handleError($verifKey); |
|
168 | - } else { |
|
169 | - $results = array(); |
|
170 | - foreach($courses as $course) { |
|
171 | - $result_tmp = array(); |
|
172 | - //reinitialize variables just in case |
|
173 | - $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 = null; |
|
174 | - extract($course); |
|
175 | - $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); |
|
176 | - if($result instanceof WSCMError) { |
|
177 | - $result_tmp['result'] = $result->toArray(); |
|
178 | - $result_tmp['course_id_value'] = $course_id_value; |
|
179 | - $result_tmp['course_id_generated'] = 0; |
|
180 | - } else { |
|
181 | - $result_tmp['result'] = $this->getSuccessfulResult(); |
|
182 | - $result_tmp['course_id_value'] = $course_id_value; |
|
183 | - $result_tmp['course_id_generated'] = $result; |
|
184 | - } |
|
185 | - $results[] = $result_tmp; |
|
186 | - } |
|
187 | - return $results; |
|
188 | - } |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * Edits a course (helper method) |
|
193 | - * |
|
194 | - * @param string Course id field name |
|
195 | - * @param string Course id value |
|
196 | - * @param string Title |
|
197 | - * @param string Category code |
|
198 | - * @param string Department name |
|
199 | - * @param string Department url |
|
200 | - * @param string Course language |
|
201 | - * @param int Visibility |
|
202 | - * @param int Subscribe (0 = denied, 1 = allowed) |
|
203 | - * @param int Unsubscribe (0 = denied, 1 = allowed) |
|
204 | - * @param string Visual code |
|
205 | - * @param array Course extra fields |
|
206 | - * @return mixed True in case of success, WSError otherwise |
|
207 | - */ |
|
208 | - protected function editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) { |
|
209 | - $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
210 | - if($course_id instanceof WSCMError) { |
|
211 | - return $course_id; |
|
212 | - } else { |
|
213 | - $attributes = array(); |
|
214 | - if(!empty($title)) { |
|
215 | - $attributes['title'] = $title; |
|
216 | - } |
|
217 | - if(!empty($category_code)) { |
|
218 | - $attributes['category_code'] = $category_code; |
|
219 | - } |
|
220 | - if(!empty($department_name)) { |
|
221 | - $attributes['department_name'] = $department_name; |
|
222 | - } |
|
223 | - if(!empty($department_url)) { |
|
224 | - $attributes['department_url'] = $department_url; |
|
225 | - } |
|
226 | - if(!empty($language)) { |
|
227 | - $attributes['course_language'] = $language; |
|
228 | - } |
|
229 | - if($visibility != '') { |
|
230 | - $attributes['visibility'] = (int)$visibility; |
|
231 | - } |
|
232 | - if($subscribe != '') { |
|
233 | - $attributes['subscribe'] = (int)$subscribe; |
|
234 | - } |
|
235 | - if($unsubscribe != '') { |
|
236 | - $attributes['unsubscribe'] = (int)$unsubscribe; |
|
237 | - } |
|
238 | - if(!empty($visual_code)) { |
|
239 | - $attributes['visual_code'] = $visual_code; |
|
240 | - } |
|
241 | - if(!empty($attributes)) { |
|
242 | - CourseManager::update_attributes($course_id, $attributes); |
|
243 | - } |
|
244 | - if(!empty($extras)) { |
|
245 | - $course_code = CourseManager::get_course_code_from_course_id($course_id); |
|
246 | - $extras_associative = array(); |
|
247 | - foreach($extras as $extra) { |
|
248 | - $extras_associative[$extra['field_name']] = $extra['field_value']; |
|
249 | - } |
|
250 | - foreach($extras_associative as $fname => $fvalue) { |
|
251 | - CourseManager::update_extra_field_value($course_code, $fname, $fvalue); |
|
252 | - } |
|
253 | - } |
|
254 | - return true; |
|
255 | - } |
|
256 | - } |
|
257 | - |
|
258 | - /** |
|
259 | - * Edits a course |
|
260 | - * |
|
261 | - * @param string API secret key |
|
262 | - * @param string Course id field name |
|
263 | - * @param string Course id value |
|
264 | - * @param string Title |
|
265 | - * @param string Category code |
|
266 | - * @param string Department name |
|
267 | - * @param string Department url |
|
268 | - * @param string Course language |
|
269 | - * @param int Visibility |
|
270 | - * @param int Subscribe (0 = denied, 1 = allowed) |
|
271 | - * @param int Unsubscribe (0 = denied, 1 = allowed) |
|
272 | - * @param string Visual code |
|
273 | - * @param array Course extra fields |
|
274 | - */ |
|
275 | - 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) { |
|
276 | - $verifKey = $this->verifyKey($secret_key); |
|
277 | - if($verifKey instanceof WSCMError) { |
|
278 | - $this->handleError($verifKey); |
|
279 | - } else { |
|
280 | - $result = $this->editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras); |
|
281 | - if($result instanceof WSCMError) { |
|
282 | - $this->handleError($result); |
|
283 | - } |
|
284 | - } |
|
285 | - } |
|
286 | - |
|
287 | - /** |
|
288 | - * List courses |
|
289 | - * |
|
290 | - * @param string API secret key |
|
291 | - * @param string Course id field name. Use "chamilo_course_id" to use internal id |
|
292 | - * @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', |
|
293 | - * 'category_name' => 'Name of the category of the course', 'number_students' => 'Number of students in the course', 'external_course_id' => 'External course id') |
|
294 | - */ |
|
295 | - public function ListCourses($secret_key, $course_id_field_name) { |
|
296 | - $verifKey = $this->verifyKey($secret_key); |
|
297 | - if($verifKey instanceof WSError) { |
|
298 | - $this->handleError($verifKey); |
|
299 | - } else { |
|
300 | - $courses_result = array(); |
|
301 | - $category_names = array(); |
|
302 | - |
|
303 | - $courses = CourseManager::get_courses_list(); |
|
304 | - foreach($courses as $course) { |
|
305 | - $course_tmp = array(); |
|
306 | - $course_tmp['id'] = $course['id']; |
|
307 | - $course_tmp['code'] = $course['code']; |
|
308 | - $course_tmp['title'] = $course['title']; |
|
309 | - $course_tmp['language'] = $course['course_language']; |
|
310 | - $course_tmp['visibility'] = $course['visibility']; |
|
311 | - |
|
312 | - // Determining category name |
|
313 | - if($category_names[$course['category_code']]) { |
|
314 | - $course_tmp['category_name'] = $category_names[$course['category_code']]; |
|
315 | - } else { |
|
316 | - $category = CourseManager::get_course_category($course['category_code']); |
|
317 | - $category_names[$course['category_code']] = $category['name']; |
|
318 | - $course_tmp['category_name'] = $category['name']; |
|
319 | - } |
|
320 | - |
|
321 | - // Determining number of students registered in course |
|
322 | - $user_list = CourseManager::get_user_list_from_course_code($course['code']); |
|
323 | - $course_tmp['number_students'] = count($user_list); |
|
324 | - |
|
325 | - // Determining external course id |
|
326 | - $course_tmp['external_course_id'] = CourseManager::get_course_extra_field_value($course_id_field_name, $course['code']); |
|
327 | - |
|
328 | - |
|
329 | - $courses_result[] = $course_tmp; |
|
330 | - } |
|
331 | - |
|
332 | - return $courses_result; |
|
333 | - } |
|
334 | - } |
|
335 | - |
|
336 | - /** |
|
337 | - * Subscribe or unsubscribe user to a course (helper method) |
|
338 | - * |
|
339 | - * @param string Course id field name. Use "chamilo_course_id" to use internal id |
|
340 | - * @param string Course id value. |
|
341 | - * @param string User id field name. Use "chamilo_user_id" to use internal id |
|
342 | - * @param string User id value |
|
343 | - * @param int Set to 1 to subscribe, 0 to unsubscribe |
|
344 | - * @param int Status (STUDENT or TEACHER) Used for subscription only |
|
345 | - * @return mixed True if subscription or unsubscription was successful, false otherwise |
|
346 | - */ |
|
347 | - protected function changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $state, $status = STUDENT) { |
|
348 | - $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
349 | - if($course_id instanceof WSError) { |
|
350 | - return $course_id; |
|
351 | - } else { |
|
352 | - $user_id = $this->getUserId($user_id_field_name, $user_id_value); |
|
353 | - if($user_id instanceof WSError) { |
|
354 | - return $user_id; |
|
355 | - } else { |
|
356 | - $course_code = CourseManager::get_course_code_from_course_id($course_id); |
|
357 | - if($state == 0) { |
|
358 | - // Unsubscribe user |
|
359 | - CourseManager::unsubscribe_user($user_id, $course_code); |
|
360 | - return true; |
|
361 | - } else { |
|
362 | - // Subscribe user |
|
363 | - if(CourseManager::subscribe_user($user_id, $course_code, $status)) { |
|
364 | - return true; |
|
365 | - } else { |
|
366 | - return new WSError(203, 'An error occured subscribing to this course'); |
|
367 | - } |
|
368 | - } |
|
369 | - } |
|
370 | - } |
|
371 | - } |
|
372 | - |
|
373 | - /** |
|
374 | - * Subscribe user to a course |
|
375 | - * |
|
376 | - * @param string API secret key |
|
377 | - * @param string Course id field name. Use "chamilo_course_id" to use internal id |
|
378 | - * @param string Course id value. |
|
379 | - * @param string User id field name. Use "chamilo_user_id" to use internal id |
|
380 | - * @param string User id value |
|
381 | - * @param int Status (1 = Teacher, 5 = Student) |
|
382 | - */ |
|
383 | - public function SubscribeUserToCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $status) { |
|
384 | - $verifKey = $this->verifyKey($secret_key); |
|
385 | - if($verifKey instanceof WSError) { |
|
386 | - $this->handleError($verifKey); |
|
387 | - } else { |
|
388 | - $result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 1, $status); |
|
389 | - if($result instanceof WSError) { |
|
390 | - $this->handleError($result); |
|
391 | - } |
|
392 | - } |
|
393 | - } |
|
394 | - |
|
395 | - /** |
|
396 | - * Unsusbscribe user from course |
|
397 | - * |
|
398 | - * @param string API secret key |
|
399 | - * @param string Course id field name. Use "chamilo_course_id" to use internal id |
|
400 | - * @param string Course id value. |
|
401 | - * @param string User id field name. Use "chamilo_user_id" to use internal id |
|
402 | - * @param string User id value |
|
403 | - */ |
|
404 | - public function UnsubscribeUserFromCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value) { |
|
405 | - $verifKey = $this->verifyKey($secret_key); |
|
406 | - if($verifKey instanceof WSError) { |
|
407 | - $this->handleError($verifKey); |
|
408 | - } else { |
|
409 | - $result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 0); |
|
410 | - if($result instanceof WSError) { |
|
411 | - $this->handleError($result); |
|
412 | - } |
|
413 | - } |
|
414 | - } |
|
415 | - |
|
416 | - /** |
|
417 | - * Returns the descriptions of a course, along with their id |
|
418 | - * |
|
419 | - * @param string API secret key |
|
420 | - * @param string Course id field name |
|
421 | - * @param string Course id value |
|
422 | - * @return array Returns an array with elements of the form ('course_desc_id' => 1, 'course_desc_title' => 'Title', 'course_desc_content' => 'Content') |
|
423 | - */ |
|
424 | - public function GetCourseDescriptions($secret_key, $course_id_field_name, $course_id_value) { |
|
425 | - $verifKey = $this->verifyKey($secret_key); |
|
426 | - if($verifKey instanceof WSError) { |
|
427 | - $this->handleError($verifKey); |
|
428 | - } else { |
|
429 | - $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
430 | - if($course_id instanceof WSError) { |
|
431 | - return $course_id; |
|
432 | - } else { |
|
433 | - // Course exists, get its descriptions |
|
434 | - $descriptions = CourseDescription::get_descriptions($course_id); |
|
435 | - $results = array(); |
|
436 | - foreach($descriptions as $description) { |
|
437 | - $results[] = array('course_desc_id' => $description->get_description_type(), |
|
438 | - 'course_desc_title' => $description->get_title(), |
|
439 | - 'course_desc_content' => $description->get_content()); |
|
440 | - } |
|
441 | - return $results; |
|
442 | - } |
|
443 | - } |
|
444 | - } |
|
445 | - |
|
446 | - |
|
447 | - /** |
|
448 | - * Edit course description |
|
449 | - * |
|
450 | - * @param string API secret key |
|
451 | - * @param string Course id field name |
|
452 | - * @param string Course id value |
|
453 | - * @param int Category id from course description |
|
454 | - * @param string Description title |
|
455 | - * @param string Course description content |
|
456 | - */ |
|
457 | - public function EditCourseDescription($secret_key, $course_id_field_name, $course_id_value, $course_desc_id, $course_desc_title, $course_desc_content) { |
|
458 | - $verifKey = $this->verifyKey($secret_key); |
|
459 | - if($verifKey instanceof WSError) { |
|
460 | - $this->handleError($verifKey); |
|
461 | - } else { |
|
462 | - $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
463 | - if($course_id instanceof WSError) { |
|
464 | - return $course_id; |
|
465 | - } else { |
|
466 | - // Create the new course description |
|
467 | - $cd = new CourseDescription(); |
|
468 | - $cd->set_description_type($course_desc_id); |
|
469 | - $cd->set_title($course_desc_title); |
|
470 | - $cd->set_content($course_desc_content); |
|
471 | - $cd->set_session_id(0); |
|
472 | - |
|
473 | - // Get course info |
|
13 | + /** |
|
14 | + * Deletes a course (helper method) |
|
15 | + * |
|
16 | + * @param string Course id field name |
|
17 | + * @param string Course id value |
|
18 | + * @return mixed True if the course was successfully deleted, WSError otherwise |
|
19 | + */ |
|
20 | + protected function deleteCourseHelper($course_id_field_name, $course_id_value) { |
|
21 | + $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
22 | + if($course_id instanceof WSCMError) { |
|
23 | + return $course_id; |
|
24 | + } else { |
|
25 | + $course_code = CourseManager::get_course_code_from_course_id($course_id); |
|
26 | + CourseManager::delete_course($course_code); |
|
27 | + return true; |
|
28 | + } |
|
29 | + } |
|
30 | + |
|
31 | + /** |
|
32 | + * Deletes a course |
|
33 | + * |
|
34 | + * @param string API secret key |
|
35 | + * @param string Course id field name |
|
36 | + * @param string Course id value |
|
37 | + */ |
|
38 | + public function DeleteCourse($secret_key, $course_id_field_name, $course_id_value) { |
|
39 | + $verifKey = $this->verifyKey($secret_key); |
|
40 | + if($verifKey instanceof WSError) { |
|
41 | + $this->handleError($verifKey); |
|
42 | + } else { |
|
43 | + $result = $this->deleteCourseHelper($course_id_field_name, $course_id_value); |
|
44 | + if($result instanceof WSError) { |
|
45 | + $this->handleError($result); |
|
46 | + } |
|
47 | + } |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * Deletes multiple courses |
|
52 | + * |
|
53 | + * @param string API secret key |
|
54 | + * @param array Array of courses with elements of the form array('course_id_field_name' => 'name_of_field', 'course_id_value' => 'value') |
|
55 | + * @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 |
|
56 | + * than 0, an error occured |
|
57 | + */ |
|
58 | + public function DeleteCourses($secret_key, $courses) { |
|
59 | + $verifKey = $this->verifyKey($secret_key); |
|
60 | + if($verifKey instanceof WSError) { |
|
61 | + $this->handleError($verifKey); |
|
62 | + } else { |
|
63 | + $results = array(); |
|
64 | + foreach($courses as $course) { |
|
65 | + $result_tmp = array(); |
|
66 | + $result_op = $this->deleteCourseHelper($course['course_id_field_name'], $course['course_id_value']); |
|
67 | + $result_tmp['course_id_value'] = $course['course_id_value']; |
|
68 | + if($result_op instanceof WSCMError) { |
|
69 | + // Return the error in the results |
|
70 | + $result_tmp['result'] = $result_op->toArray(); |
|
71 | + } else { |
|
72 | + $result_tmp['result'] = $this->getSuccessfulResult(); |
|
73 | + } |
|
74 | + $results[] = $result_tmp; |
|
75 | + } |
|
76 | + return $results; |
|
77 | + } |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * Creates a course (helper method) |
|
82 | + * |
|
83 | + * @param string Title |
|
84 | + * @param string Category code |
|
85 | + * @param string Wanted code. If it's not defined, it will be generated automatically |
|
86 | + * @param string Tutor name |
|
87 | + * @param string Course admin user id field name |
|
88 | + * @param string Course admin user id value |
|
89 | + * @param string Course language |
|
90 | + * @param string Course id field name |
|
91 | + * @param string Course id value |
|
92 | + * @param array Course extra fields |
|
93 | + * @return mixed Generated id if creation was successful, WSError otherwise |
|
94 | + */ |
|
95 | + 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) { |
|
96 | + // Add the original course id field name and value to the extra fields if needed |
|
97 | + $extras_associative = array(); |
|
98 | + if($course_id_field_name != "chamilo_course_id") { |
|
99 | + $extras_associative[$course_id_field_name] = $course_id_value; |
|
100 | + } |
|
101 | + foreach($extras as $extra) { |
|
102 | + $extras_associative[$extra['field_name']] = $extra['field_value']; |
|
103 | + } |
|
104 | + $course_admin_id = $this->getUserId($course_admin_user_id_field_name, $course_admin_user_id_value); |
|
105 | + if($course_admin_id instanceof WSError) { |
|
106 | + return $course_admin_id; |
|
107 | + } |
|
108 | + if($wanted_code == '') { |
|
109 | + $wanted_code = CourseManager::generate_course_code($title); |
|
110 | + } |
|
111 | + $result = create_course($wanted_code, $title, $tutor_name, $category_code, $language, $course_admin_id, $this->_configuration['db_prefix'], 0); |
|
112 | + if (!$result) { |
|
113 | + return new WSError(202, 'There was an error creating the course'); |
|
114 | + } else { |
|
115 | + // Update extra fields |
|
116 | + foreach($extras_associative as $fname => $fvalue) { |
|
117 | + CourseManager::update_course_extra_field_value($result, $fname, $fvalue); |
|
118 | + } |
|
119 | + // Get course id |
|
120 | + $course_info = CourseManager::get_course_information($result); |
|
121 | + return $course_info['real_id']; |
|
122 | + } |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * Creates a course |
|
127 | + * |
|
128 | + * @param string API secret key |
|
129 | + * @param string Title |
|
130 | + * @param string Category code |
|
131 | + * @param string Wanted code. If it's not defined, it will be generated automatically |
|
132 | + * @param string Tutor name |
|
133 | + * @param string Course admin user id field name |
|
134 | + * @param string Course admin user id value |
|
135 | + * @param string Course language |
|
136 | + * @param string Course id field name |
|
137 | + * @param string Course id value |
|
138 | + * @param array Course extra fields |
|
139 | + * @return int Course id generated |
|
140 | + */ |
|
141 | + 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) { |
|
142 | + // First, verify the secret key |
|
143 | + $verifKey = $this->verifyKey($secret_key); |
|
144 | + if($verifKey instanceof WSError) { |
|
145 | + $this->handleError($verifKey); |
|
146 | + } else { |
|
147 | + $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); |
|
148 | + if($result instanceof WSError) { |
|
149 | + $this->handleError($result); |
|
150 | + } else { |
|
151 | + return $result; |
|
152 | + } |
|
153 | + } |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * Create multiple courses |
|
158 | + * |
|
159 | + * @param string API secret key |
|
160 | + * @param array Courses to be created, with elements following the structure presented in CreateCourse |
|
161 | + * @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')) |
|
162 | + */ |
|
163 | + public function CreateCourses($secret_key, $courses) { |
|
164 | + // First, verify the secret key |
|
165 | + $verifKey = $this->verifyKey($secret_key); |
|
166 | + if($verifKey instanceof WSCMError) { |
|
167 | + $this->handleError($verifKey); |
|
168 | + } else { |
|
169 | + $results = array(); |
|
170 | + foreach($courses as $course) { |
|
171 | + $result_tmp = array(); |
|
172 | + //reinitialize variables just in case |
|
173 | + $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 = null; |
|
174 | + extract($course); |
|
175 | + $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); |
|
176 | + if($result instanceof WSCMError) { |
|
177 | + $result_tmp['result'] = $result->toArray(); |
|
178 | + $result_tmp['course_id_value'] = $course_id_value; |
|
179 | + $result_tmp['course_id_generated'] = 0; |
|
180 | + } else { |
|
181 | + $result_tmp['result'] = $this->getSuccessfulResult(); |
|
182 | + $result_tmp['course_id_value'] = $course_id_value; |
|
183 | + $result_tmp['course_id_generated'] = $result; |
|
184 | + } |
|
185 | + $results[] = $result_tmp; |
|
186 | + } |
|
187 | + return $results; |
|
188 | + } |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * Edits a course (helper method) |
|
193 | + * |
|
194 | + * @param string Course id field name |
|
195 | + * @param string Course id value |
|
196 | + * @param string Title |
|
197 | + * @param string Category code |
|
198 | + * @param string Department name |
|
199 | + * @param string Department url |
|
200 | + * @param string Course language |
|
201 | + * @param int Visibility |
|
202 | + * @param int Subscribe (0 = denied, 1 = allowed) |
|
203 | + * @param int Unsubscribe (0 = denied, 1 = allowed) |
|
204 | + * @param string Visual code |
|
205 | + * @param array Course extra fields |
|
206 | + * @return mixed True in case of success, WSError otherwise |
|
207 | + */ |
|
208 | + protected function editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) { |
|
209 | + $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
210 | + if($course_id instanceof WSCMError) { |
|
211 | + return $course_id; |
|
212 | + } else { |
|
213 | + $attributes = array(); |
|
214 | + if(!empty($title)) { |
|
215 | + $attributes['title'] = $title; |
|
216 | + } |
|
217 | + if(!empty($category_code)) { |
|
218 | + $attributes['category_code'] = $category_code; |
|
219 | + } |
|
220 | + if(!empty($department_name)) { |
|
221 | + $attributes['department_name'] = $department_name; |
|
222 | + } |
|
223 | + if(!empty($department_url)) { |
|
224 | + $attributes['department_url'] = $department_url; |
|
225 | + } |
|
226 | + if(!empty($language)) { |
|
227 | + $attributes['course_language'] = $language; |
|
228 | + } |
|
229 | + if($visibility != '') { |
|
230 | + $attributes['visibility'] = (int)$visibility; |
|
231 | + } |
|
232 | + if($subscribe != '') { |
|
233 | + $attributes['subscribe'] = (int)$subscribe; |
|
234 | + } |
|
235 | + if($unsubscribe != '') { |
|
236 | + $attributes['unsubscribe'] = (int)$unsubscribe; |
|
237 | + } |
|
238 | + if(!empty($visual_code)) { |
|
239 | + $attributes['visual_code'] = $visual_code; |
|
240 | + } |
|
241 | + if(!empty($attributes)) { |
|
242 | + CourseManager::update_attributes($course_id, $attributes); |
|
243 | + } |
|
244 | + if(!empty($extras)) { |
|
245 | + $course_code = CourseManager::get_course_code_from_course_id($course_id); |
|
246 | + $extras_associative = array(); |
|
247 | + foreach($extras as $extra) { |
|
248 | + $extras_associative[$extra['field_name']] = $extra['field_value']; |
|
249 | + } |
|
250 | + foreach($extras_associative as $fname => $fvalue) { |
|
251 | + CourseManager::update_extra_field_value($course_code, $fname, $fvalue); |
|
252 | + } |
|
253 | + } |
|
254 | + return true; |
|
255 | + } |
|
256 | + } |
|
257 | + |
|
258 | + /** |
|
259 | + * Edits a course |
|
260 | + * |
|
261 | + * @param string API secret key |
|
262 | + * @param string Course id field name |
|
263 | + * @param string Course id value |
|
264 | + * @param string Title |
|
265 | + * @param string Category code |
|
266 | + * @param string Department name |
|
267 | + * @param string Department url |
|
268 | + * @param string Course language |
|
269 | + * @param int Visibility |
|
270 | + * @param int Subscribe (0 = denied, 1 = allowed) |
|
271 | + * @param int Unsubscribe (0 = denied, 1 = allowed) |
|
272 | + * @param string Visual code |
|
273 | + * @param array Course extra fields |
|
274 | + */ |
|
275 | + 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) { |
|
276 | + $verifKey = $this->verifyKey($secret_key); |
|
277 | + if($verifKey instanceof WSCMError) { |
|
278 | + $this->handleError($verifKey); |
|
279 | + } else { |
|
280 | + $result = $this->editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras); |
|
281 | + if($result instanceof WSCMError) { |
|
282 | + $this->handleError($result); |
|
283 | + } |
|
284 | + } |
|
285 | + } |
|
286 | + |
|
287 | + /** |
|
288 | + * List courses |
|
289 | + * |
|
290 | + * @param string API secret key |
|
291 | + * @param string Course id field name. Use "chamilo_course_id" to use internal id |
|
292 | + * @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', |
|
293 | + * 'category_name' => 'Name of the category of the course', 'number_students' => 'Number of students in the course', 'external_course_id' => 'External course id') |
|
294 | + */ |
|
295 | + public function ListCourses($secret_key, $course_id_field_name) { |
|
296 | + $verifKey = $this->verifyKey($secret_key); |
|
297 | + if($verifKey instanceof WSError) { |
|
298 | + $this->handleError($verifKey); |
|
299 | + } else { |
|
300 | + $courses_result = array(); |
|
301 | + $category_names = array(); |
|
302 | + |
|
303 | + $courses = CourseManager::get_courses_list(); |
|
304 | + foreach($courses as $course) { |
|
305 | + $course_tmp = array(); |
|
306 | + $course_tmp['id'] = $course['id']; |
|
307 | + $course_tmp['code'] = $course['code']; |
|
308 | + $course_tmp['title'] = $course['title']; |
|
309 | + $course_tmp['language'] = $course['course_language']; |
|
310 | + $course_tmp['visibility'] = $course['visibility']; |
|
311 | + |
|
312 | + // Determining category name |
|
313 | + if($category_names[$course['category_code']]) { |
|
314 | + $course_tmp['category_name'] = $category_names[$course['category_code']]; |
|
315 | + } else { |
|
316 | + $category = CourseManager::get_course_category($course['category_code']); |
|
317 | + $category_names[$course['category_code']] = $category['name']; |
|
318 | + $course_tmp['category_name'] = $category['name']; |
|
319 | + } |
|
320 | + |
|
321 | + // Determining number of students registered in course |
|
322 | + $user_list = CourseManager::get_user_list_from_course_code($course['code']); |
|
323 | + $course_tmp['number_students'] = count($user_list); |
|
324 | + |
|
325 | + // Determining external course id |
|
326 | + $course_tmp['external_course_id'] = CourseManager::get_course_extra_field_value($course_id_field_name, $course['code']); |
|
327 | + |
|
328 | + |
|
329 | + $courses_result[] = $course_tmp; |
|
330 | + } |
|
331 | + |
|
332 | + return $courses_result; |
|
333 | + } |
|
334 | + } |
|
335 | + |
|
336 | + /** |
|
337 | + * Subscribe or unsubscribe user to a course (helper method) |
|
338 | + * |
|
339 | + * @param string Course id field name. Use "chamilo_course_id" to use internal id |
|
340 | + * @param string Course id value. |
|
341 | + * @param string User id field name. Use "chamilo_user_id" to use internal id |
|
342 | + * @param string User id value |
|
343 | + * @param int Set to 1 to subscribe, 0 to unsubscribe |
|
344 | + * @param int Status (STUDENT or TEACHER) Used for subscription only |
|
345 | + * @return mixed True if subscription or unsubscription was successful, false otherwise |
|
346 | + */ |
|
347 | + protected function changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $state, $status = STUDENT) { |
|
348 | + $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
349 | + if($course_id instanceof WSError) { |
|
350 | + return $course_id; |
|
351 | + } else { |
|
352 | + $user_id = $this->getUserId($user_id_field_name, $user_id_value); |
|
353 | + if($user_id instanceof WSError) { |
|
354 | + return $user_id; |
|
355 | + } else { |
|
356 | + $course_code = CourseManager::get_course_code_from_course_id($course_id); |
|
357 | + if($state == 0) { |
|
358 | + // Unsubscribe user |
|
359 | + CourseManager::unsubscribe_user($user_id, $course_code); |
|
360 | + return true; |
|
361 | + } else { |
|
362 | + // Subscribe user |
|
363 | + if(CourseManager::subscribe_user($user_id, $course_code, $status)) { |
|
364 | + return true; |
|
365 | + } else { |
|
366 | + return new WSError(203, 'An error occured subscribing to this course'); |
|
367 | + } |
|
368 | + } |
|
369 | + } |
|
370 | + } |
|
371 | + } |
|
372 | + |
|
373 | + /** |
|
374 | + * Subscribe user to a course |
|
375 | + * |
|
376 | + * @param string API secret key |
|
377 | + * @param string Course id field name. Use "chamilo_course_id" to use internal id |
|
378 | + * @param string Course id value. |
|
379 | + * @param string User id field name. Use "chamilo_user_id" to use internal id |
|
380 | + * @param string User id value |
|
381 | + * @param int Status (1 = Teacher, 5 = Student) |
|
382 | + */ |
|
383 | + public function SubscribeUserToCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $status) { |
|
384 | + $verifKey = $this->verifyKey($secret_key); |
|
385 | + if($verifKey instanceof WSError) { |
|
386 | + $this->handleError($verifKey); |
|
387 | + } else { |
|
388 | + $result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 1, $status); |
|
389 | + if($result instanceof WSError) { |
|
390 | + $this->handleError($result); |
|
391 | + } |
|
392 | + } |
|
393 | + } |
|
394 | + |
|
395 | + /** |
|
396 | + * Unsusbscribe user from course |
|
397 | + * |
|
398 | + * @param string API secret key |
|
399 | + * @param string Course id field name. Use "chamilo_course_id" to use internal id |
|
400 | + * @param string Course id value. |
|
401 | + * @param string User id field name. Use "chamilo_user_id" to use internal id |
|
402 | + * @param string User id value |
|
403 | + */ |
|
404 | + public function UnsubscribeUserFromCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value) { |
|
405 | + $verifKey = $this->verifyKey($secret_key); |
|
406 | + if($verifKey instanceof WSError) { |
|
407 | + $this->handleError($verifKey); |
|
408 | + } else { |
|
409 | + $result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 0); |
|
410 | + if($result instanceof WSError) { |
|
411 | + $this->handleError($result); |
|
412 | + } |
|
413 | + } |
|
414 | + } |
|
415 | + |
|
416 | + /** |
|
417 | + * Returns the descriptions of a course, along with their id |
|
418 | + * |
|
419 | + * @param string API secret key |
|
420 | + * @param string Course id field name |
|
421 | + * @param string Course id value |
|
422 | + * @return array Returns an array with elements of the form ('course_desc_id' => 1, 'course_desc_title' => 'Title', 'course_desc_content' => 'Content') |
|
423 | + */ |
|
424 | + public function GetCourseDescriptions($secret_key, $course_id_field_name, $course_id_value) { |
|
425 | + $verifKey = $this->verifyKey($secret_key); |
|
426 | + if($verifKey instanceof WSError) { |
|
427 | + $this->handleError($verifKey); |
|
428 | + } else { |
|
429 | + $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
430 | + if($course_id instanceof WSError) { |
|
431 | + return $course_id; |
|
432 | + } else { |
|
433 | + // Course exists, get its descriptions |
|
434 | + $descriptions = CourseDescription::get_descriptions($course_id); |
|
435 | + $results = array(); |
|
436 | + foreach($descriptions as $description) { |
|
437 | + $results[] = array('course_desc_id' => $description->get_description_type(), |
|
438 | + 'course_desc_title' => $description->get_title(), |
|
439 | + 'course_desc_content' => $description->get_content()); |
|
440 | + } |
|
441 | + return $results; |
|
442 | + } |
|
443 | + } |
|
444 | + } |
|
445 | + |
|
446 | + |
|
447 | + /** |
|
448 | + * Edit course description |
|
449 | + * |
|
450 | + * @param string API secret key |
|
451 | + * @param string Course id field name |
|
452 | + * @param string Course id value |
|
453 | + * @param int Category id from course description |
|
454 | + * @param string Description title |
|
455 | + * @param string Course description content |
|
456 | + */ |
|
457 | + public function EditCourseDescription($secret_key, $course_id_field_name, $course_id_value, $course_desc_id, $course_desc_title, $course_desc_content) { |
|
458 | + $verifKey = $this->verifyKey($secret_key); |
|
459 | + if($verifKey instanceof WSError) { |
|
460 | + $this->handleError($verifKey); |
|
461 | + } else { |
|
462 | + $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
463 | + if($course_id instanceof WSError) { |
|
464 | + return $course_id; |
|
465 | + } else { |
|
466 | + // Create the new course description |
|
467 | + $cd = new CourseDescription(); |
|
468 | + $cd->set_description_type($course_desc_id); |
|
469 | + $cd->set_title($course_desc_title); |
|
470 | + $cd->set_content($course_desc_content); |
|
471 | + $cd->set_session_id(0); |
|
472 | + |
|
473 | + // Get course info |
|
474 | 474 | $course_info = CourseManager::get_course_information( |
475 | 475 | CourseManager::get_course_code_from_course_id($course_id) |
476 | 476 | ); |
477 | - // Check if this course description exists |
|
478 | - $descriptions = CourseDescription::get_descriptions($course_id); |
|
479 | - $exists = false; |
|
480 | - foreach($descriptions as $description) { |
|
481 | - if($description->get_description_type() == $course_desc_id) { |
|
482 | - $exists = true; |
|
483 | - } |
|
484 | - } |
|
477 | + // Check if this course description exists |
|
478 | + $descriptions = CourseDescription::get_descriptions($course_id); |
|
479 | + $exists = false; |
|
480 | + foreach($descriptions as $description) { |
|
481 | + if($description->get_description_type() == $course_desc_id) { |
|
482 | + $exists = true; |
|
483 | + } |
|
484 | + } |
|
485 | 485 | $cd->set_course_id($course_info['real_id']); |
486 | - if (!$exists) { |
|
487 | - $cd->set_progress(0); |
|
488 | - $cd->insert(); |
|
489 | - } else { |
|
490 | - $cd->update(); |
|
491 | - } |
|
492 | - } |
|
493 | - } |
|
494 | - } |
|
495 | - public function unreadMessage($username, $password) |
|
496 | - { |
|
497 | - if($this->verifyUserPass($username, $password) == "valid") |
|
498 | - { |
|
499 | - $table_message = Database::get_main_table(TABLE_MESSAGE); |
|
500 | - $user_id = UserManager::get_user_id_from_username($username); |
|
501 | - $condition_msg_status = ' msg_status = 1 '; // define('MESSAGE_STATUS_UNREAD', '1'); |
|
502 | - |
|
503 | - $sql_query = "SELECT COUNT(*) as number_messages FROM $table_message WHERE $condition_msg_status AND user_receiver_id=".$user_id; |
|
504 | - |
|
505 | - $sql_result = Database::query($sql_query); |
|
506 | - $result = Database::fetch_array($sql_result); |
|
507 | - return $result['number_messages']; |
|
508 | - } |
|
509 | - return "0"; |
|
510 | - } |
|
511 | - |
|
512 | - public function get_message_data($username, $password) |
|
513 | - { |
|
514 | - if($this->verifyUserPass($username, $password) == "valid") |
|
515 | - { |
|
516 | - $user_id = get_user_id_from_username($username); |
|
517 | - |
|
518 | - } |
|
519 | - |
|
520 | - } |
|
521 | - |
|
522 | - public function nada($username, $password) |
|
523 | - { |
|
524 | - if($this->verifyUserPass($username, $password) == "valid") |
|
525 | - return $username.$password; |
|
526 | - return $username; |
|
527 | - } |
|
486 | + if (!$exists) { |
|
487 | + $cd->set_progress(0); |
|
488 | + $cd->insert(); |
|
489 | + } else { |
|
490 | + $cd->update(); |
|
491 | + } |
|
492 | + } |
|
493 | + } |
|
494 | + } |
|
495 | + public function unreadMessage($username, $password) |
|
496 | + { |
|
497 | + if($this->verifyUserPass($username, $password) == "valid") |
|
498 | + { |
|
499 | + $table_message = Database::get_main_table(TABLE_MESSAGE); |
|
500 | + $user_id = UserManager::get_user_id_from_username($username); |
|
501 | + $condition_msg_status = ' msg_status = 1 '; // define('MESSAGE_STATUS_UNREAD', '1'); |
|
502 | + |
|
503 | + $sql_query = "SELECT COUNT(*) as number_messages FROM $table_message WHERE $condition_msg_status AND user_receiver_id=".$user_id; |
|
504 | + |
|
505 | + $sql_result = Database::query($sql_query); |
|
506 | + $result = Database::fetch_array($sql_result); |
|
507 | + return $result['number_messages']; |
|
508 | + } |
|
509 | + return "0"; |
|
510 | + } |
|
511 | + |
|
512 | + public function get_message_data($username, $password) |
|
513 | + { |
|
514 | + if($this->verifyUserPass($username, $password) == "valid") |
|
515 | + { |
|
516 | + $user_id = get_user_id_from_username($username); |
|
517 | + |
|
518 | + } |
|
519 | + |
|
520 | + } |
|
521 | + |
|
522 | + public function nada($username, $password) |
|
523 | + { |
|
524 | + if($this->verifyUserPass($username, $password) == "valid") |
|
525 | + return $username.$password; |
|
526 | + return $username; |
|
527 | + } |
|
528 | 528 | |
529 | 529 | |
530 | 530 |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | */ |
20 | 20 | protected function deleteCourseHelper($course_id_field_name, $course_id_value) { |
21 | 21 | $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
22 | - if($course_id instanceof WSCMError) { |
|
22 | + if ($course_id instanceof WSCMError) { |
|
23 | 23 | return $course_id; |
24 | 24 | } else { |
25 | 25 | $course_code = CourseManager::get_course_code_from_course_id($course_id); |
@@ -37,11 +37,11 @@ discard block |
||
37 | 37 | */ |
38 | 38 | public function DeleteCourse($secret_key, $course_id_field_name, $course_id_value) { |
39 | 39 | $verifKey = $this->verifyKey($secret_key); |
40 | - if($verifKey instanceof WSError) { |
|
40 | + if ($verifKey instanceof WSError) { |
|
41 | 41 | $this->handleError($verifKey); |
42 | 42 | } else { |
43 | 43 | $result = $this->deleteCourseHelper($course_id_field_name, $course_id_value); |
44 | - if($result instanceof WSError) { |
|
44 | + if ($result instanceof WSError) { |
|
45 | 45 | $this->handleError($result); |
46 | 46 | } |
47 | 47 | } |
@@ -57,15 +57,15 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function DeleteCourses($secret_key, $courses) { |
59 | 59 | $verifKey = $this->verifyKey($secret_key); |
60 | - if($verifKey instanceof WSError) { |
|
60 | + if ($verifKey instanceof WSError) { |
|
61 | 61 | $this->handleError($verifKey); |
62 | 62 | } else { |
63 | 63 | $results = array(); |
64 | - foreach($courses as $course) { |
|
64 | + foreach ($courses as $course) { |
|
65 | 65 | $result_tmp = array(); |
66 | 66 | $result_op = $this->deleteCourseHelper($course['course_id_field_name'], $course['course_id_value']); |
67 | 67 | $result_tmp['course_id_value'] = $course['course_id_value']; |
68 | - if($result_op instanceof WSCMError) { |
|
68 | + if ($result_op instanceof WSCMError) { |
|
69 | 69 | // Return the error in the results |
70 | 70 | $result_tmp['result'] = $result_op->toArray(); |
71 | 71 | } else { |
@@ -95,17 +95,17 @@ discard block |
||
95 | 95 | 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) { |
96 | 96 | // Add the original course id field name and value to the extra fields if needed |
97 | 97 | $extras_associative = array(); |
98 | - if($course_id_field_name != "chamilo_course_id") { |
|
98 | + if ($course_id_field_name != "chamilo_course_id") { |
|
99 | 99 | $extras_associative[$course_id_field_name] = $course_id_value; |
100 | 100 | } |
101 | - foreach($extras as $extra) { |
|
101 | + foreach ($extras as $extra) { |
|
102 | 102 | $extras_associative[$extra['field_name']] = $extra['field_value']; |
103 | 103 | } |
104 | 104 | $course_admin_id = $this->getUserId($course_admin_user_id_field_name, $course_admin_user_id_value); |
105 | - if($course_admin_id instanceof WSError) { |
|
105 | + if ($course_admin_id instanceof WSError) { |
|
106 | 106 | return $course_admin_id; |
107 | 107 | } |
108 | - if($wanted_code == '') { |
|
108 | + if ($wanted_code == '') { |
|
109 | 109 | $wanted_code = CourseManager::generate_course_code($title); |
110 | 110 | } |
111 | 111 | $result = create_course($wanted_code, $title, $tutor_name, $category_code, $language, $course_admin_id, $this->_configuration['db_prefix'], 0); |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | return new WSError(202, 'There was an error creating the course'); |
114 | 114 | } else { |
115 | 115 | // Update extra fields |
116 | - foreach($extras_associative as $fname => $fvalue) { |
|
116 | + foreach ($extras_associative as $fname => $fvalue) { |
|
117 | 117 | CourseManager::update_course_extra_field_value($result, $fname, $fvalue); |
118 | 118 | } |
119 | 119 | // Get course id |
@@ -141,11 +141,11 @@ discard block |
||
141 | 141 | 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) { |
142 | 142 | // First, verify the secret key |
143 | 143 | $verifKey = $this->verifyKey($secret_key); |
144 | - if($verifKey instanceof WSError) { |
|
144 | + if ($verifKey instanceof WSError) { |
|
145 | 145 | $this->handleError($verifKey); |
146 | 146 | } else { |
147 | 147 | $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); |
148 | - if($result instanceof WSError) { |
|
148 | + if ($result instanceof WSError) { |
|
149 | 149 | $this->handleError($result); |
150 | 150 | } else { |
151 | 151 | return $result; |
@@ -163,17 +163,17 @@ discard block |
||
163 | 163 | public function CreateCourses($secret_key, $courses) { |
164 | 164 | // First, verify the secret key |
165 | 165 | $verifKey = $this->verifyKey($secret_key); |
166 | - if($verifKey instanceof WSCMError) { |
|
166 | + if ($verifKey instanceof WSCMError) { |
|
167 | 167 | $this->handleError($verifKey); |
168 | 168 | } else { |
169 | 169 | $results = array(); |
170 | - foreach($courses as $course) { |
|
170 | + foreach ($courses as $course) { |
|
171 | 171 | $result_tmp = array(); |
172 | 172 | //reinitialize variables just in case |
173 | 173 | $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 = null; |
174 | 174 | extract($course); |
175 | 175 | $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); |
176 | - if($result instanceof WSCMError) { |
|
176 | + if ($result instanceof WSCMError) { |
|
177 | 177 | $result_tmp['result'] = $result->toArray(); |
178 | 178 | $result_tmp['course_id_value'] = $course_id_value; |
179 | 179 | $result_tmp['course_id_generated'] = 0; |
@@ -207,47 +207,47 @@ discard block |
||
207 | 207 | */ |
208 | 208 | protected function editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras) { |
209 | 209 | $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
210 | - if($course_id instanceof WSCMError) { |
|
210 | + if ($course_id instanceof WSCMError) { |
|
211 | 211 | return $course_id; |
212 | 212 | } else { |
213 | 213 | $attributes = array(); |
214 | - if(!empty($title)) { |
|
214 | + if (!empty($title)) { |
|
215 | 215 | $attributes['title'] = $title; |
216 | 216 | } |
217 | - if(!empty($category_code)) { |
|
217 | + if (!empty($category_code)) { |
|
218 | 218 | $attributes['category_code'] = $category_code; |
219 | 219 | } |
220 | - if(!empty($department_name)) { |
|
220 | + if (!empty($department_name)) { |
|
221 | 221 | $attributes['department_name'] = $department_name; |
222 | 222 | } |
223 | - if(!empty($department_url)) { |
|
223 | + if (!empty($department_url)) { |
|
224 | 224 | $attributes['department_url'] = $department_url; |
225 | 225 | } |
226 | - if(!empty($language)) { |
|
226 | + if (!empty($language)) { |
|
227 | 227 | $attributes['course_language'] = $language; |
228 | 228 | } |
229 | - if($visibility != '') { |
|
230 | - $attributes['visibility'] = (int)$visibility; |
|
229 | + if ($visibility != '') { |
|
230 | + $attributes['visibility'] = (int) $visibility; |
|
231 | 231 | } |
232 | - if($subscribe != '') { |
|
233 | - $attributes['subscribe'] = (int)$subscribe; |
|
232 | + if ($subscribe != '') { |
|
233 | + $attributes['subscribe'] = (int) $subscribe; |
|
234 | 234 | } |
235 | - if($unsubscribe != '') { |
|
236 | - $attributes['unsubscribe'] = (int)$unsubscribe; |
|
235 | + if ($unsubscribe != '') { |
|
236 | + $attributes['unsubscribe'] = (int) $unsubscribe; |
|
237 | 237 | } |
238 | - if(!empty($visual_code)) { |
|
238 | + if (!empty($visual_code)) { |
|
239 | 239 | $attributes['visual_code'] = $visual_code; |
240 | 240 | } |
241 | - if(!empty($attributes)) { |
|
241 | + if (!empty($attributes)) { |
|
242 | 242 | CourseManager::update_attributes($course_id, $attributes); |
243 | 243 | } |
244 | - if(!empty($extras)) { |
|
244 | + if (!empty($extras)) { |
|
245 | 245 | $course_code = CourseManager::get_course_code_from_course_id($course_id); |
246 | 246 | $extras_associative = array(); |
247 | - foreach($extras as $extra) { |
|
247 | + foreach ($extras as $extra) { |
|
248 | 248 | $extras_associative[$extra['field_name']] = $extra['field_value']; |
249 | 249 | } |
250 | - foreach($extras_associative as $fname => $fvalue) { |
|
250 | + foreach ($extras_associative as $fname => $fvalue) { |
|
251 | 251 | CourseManager::update_extra_field_value($course_code, $fname, $fvalue); |
252 | 252 | } |
253 | 253 | } |
@@ -274,11 +274,11 @@ discard block |
||
274 | 274 | */ |
275 | 275 | 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) { |
276 | 276 | $verifKey = $this->verifyKey($secret_key); |
277 | - if($verifKey instanceof WSCMError) { |
|
277 | + if ($verifKey instanceof WSCMError) { |
|
278 | 278 | $this->handleError($verifKey); |
279 | 279 | } else { |
280 | 280 | $result = $this->editCourseHelper($course_id_field_name, $course_id_value, $title, $category_code, $department_name, $department_url, $language, $visibility, $subscribe, $unsubscribe, $visual_code, $extras); |
281 | - if($result instanceof WSCMError) { |
|
281 | + if ($result instanceof WSCMError) { |
|
282 | 282 | $this->handleError($result); |
283 | 283 | } |
284 | 284 | } |
@@ -294,14 +294,14 @@ discard block |
||
294 | 294 | */ |
295 | 295 | public function ListCourses($secret_key, $course_id_field_name) { |
296 | 296 | $verifKey = $this->verifyKey($secret_key); |
297 | - if($verifKey instanceof WSError) { |
|
297 | + if ($verifKey instanceof WSError) { |
|
298 | 298 | $this->handleError($verifKey); |
299 | 299 | } else { |
300 | 300 | $courses_result = array(); |
301 | 301 | $category_names = array(); |
302 | 302 | |
303 | 303 | $courses = CourseManager::get_courses_list(); |
304 | - foreach($courses as $course) { |
|
304 | + foreach ($courses as $course) { |
|
305 | 305 | $course_tmp = array(); |
306 | 306 | $course_tmp['id'] = $course['id']; |
307 | 307 | $course_tmp['code'] = $course['code']; |
@@ -310,7 +310,7 @@ discard block |
||
310 | 310 | $course_tmp['visibility'] = $course['visibility']; |
311 | 311 | |
312 | 312 | // Determining category name |
313 | - if($category_names[$course['category_code']]) { |
|
313 | + if ($category_names[$course['category_code']]) { |
|
314 | 314 | $course_tmp['category_name'] = $category_names[$course['category_code']]; |
315 | 315 | } else { |
316 | 316 | $category = CourseManager::get_course_category($course['category_code']); |
@@ -346,21 +346,21 @@ discard block |
||
346 | 346 | */ |
347 | 347 | protected function changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $state, $status = STUDENT) { |
348 | 348 | $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
349 | - if($course_id instanceof WSError) { |
|
349 | + if ($course_id instanceof WSError) { |
|
350 | 350 | return $course_id; |
351 | 351 | } else { |
352 | 352 | $user_id = $this->getUserId($user_id_field_name, $user_id_value); |
353 | - if($user_id instanceof WSError) { |
|
353 | + if ($user_id instanceof WSError) { |
|
354 | 354 | return $user_id; |
355 | 355 | } else { |
356 | 356 | $course_code = CourseManager::get_course_code_from_course_id($course_id); |
357 | - if($state == 0) { |
|
357 | + if ($state == 0) { |
|
358 | 358 | // Unsubscribe user |
359 | 359 | CourseManager::unsubscribe_user($user_id, $course_code); |
360 | 360 | return true; |
361 | 361 | } else { |
362 | 362 | // Subscribe user |
363 | - if(CourseManager::subscribe_user($user_id, $course_code, $status)) { |
|
363 | + if (CourseManager::subscribe_user($user_id, $course_code, $status)) { |
|
364 | 364 | return true; |
365 | 365 | } else { |
366 | 366 | return new WSError(203, 'An error occured subscribing to this course'); |
@@ -382,11 +382,11 @@ discard block |
||
382 | 382 | */ |
383 | 383 | public function SubscribeUserToCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, $status) { |
384 | 384 | $verifKey = $this->verifyKey($secret_key); |
385 | - if($verifKey instanceof WSError) { |
|
385 | + if ($verifKey instanceof WSError) { |
|
386 | 386 | $this->handleError($verifKey); |
387 | 387 | } else { |
388 | 388 | $result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 1, $status); |
389 | - if($result instanceof WSError) { |
|
389 | + if ($result instanceof WSError) { |
|
390 | 390 | $this->handleError($result); |
391 | 391 | } |
392 | 392 | } |
@@ -403,11 +403,11 @@ discard block |
||
403 | 403 | */ |
404 | 404 | public function UnsubscribeUserFromCourse($secret_key, $course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value) { |
405 | 405 | $verifKey = $this->verifyKey($secret_key); |
406 | - if($verifKey instanceof WSError) { |
|
406 | + if ($verifKey instanceof WSError) { |
|
407 | 407 | $this->handleError($verifKey); |
408 | 408 | } else { |
409 | 409 | $result = $this->changeUserSubscription($course_id_field_name, $course_id_value, $user_id_field_name, $user_id_value, 0); |
410 | - if($result instanceof WSError) { |
|
410 | + if ($result instanceof WSError) { |
|
411 | 411 | $this->handleError($result); |
412 | 412 | } |
413 | 413 | } |
@@ -423,17 +423,17 @@ discard block |
||
423 | 423 | */ |
424 | 424 | public function GetCourseDescriptions($secret_key, $course_id_field_name, $course_id_value) { |
425 | 425 | $verifKey = $this->verifyKey($secret_key); |
426 | - if($verifKey instanceof WSError) { |
|
426 | + if ($verifKey instanceof WSError) { |
|
427 | 427 | $this->handleError($verifKey); |
428 | 428 | } else { |
429 | 429 | $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
430 | - if($course_id instanceof WSError) { |
|
430 | + if ($course_id instanceof WSError) { |
|
431 | 431 | return $course_id; |
432 | 432 | } else { |
433 | 433 | // Course exists, get its descriptions |
434 | 434 | $descriptions = CourseDescription::get_descriptions($course_id); |
435 | 435 | $results = array(); |
436 | - foreach($descriptions as $description) { |
|
436 | + foreach ($descriptions as $description) { |
|
437 | 437 | $results[] = array('course_desc_id' => $description->get_description_type(), |
438 | 438 | 'course_desc_title' => $description->get_title(), |
439 | 439 | 'course_desc_content' => $description->get_content()); |
@@ -456,11 +456,11 @@ discard block |
||
456 | 456 | */ |
457 | 457 | public function EditCourseDescription($secret_key, $course_id_field_name, $course_id_value, $course_desc_id, $course_desc_title, $course_desc_content) { |
458 | 458 | $verifKey = $this->verifyKey($secret_key); |
459 | - if($verifKey instanceof WSError) { |
|
459 | + if ($verifKey instanceof WSError) { |
|
460 | 460 | $this->handleError($verifKey); |
461 | 461 | } else { |
462 | 462 | $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
463 | - if($course_id instanceof WSError) { |
|
463 | + if ($course_id instanceof WSError) { |
|
464 | 464 | return $course_id; |
465 | 465 | } else { |
466 | 466 | // Create the new course description |
@@ -477,8 +477,8 @@ discard block |
||
477 | 477 | // Check if this course description exists |
478 | 478 | $descriptions = CourseDescription::get_descriptions($course_id); |
479 | 479 | $exists = false; |
480 | - foreach($descriptions as $description) { |
|
481 | - if($description->get_description_type() == $course_desc_id) { |
|
480 | + foreach ($descriptions as $description) { |
|
481 | + if ($description->get_description_type() == $course_desc_id) { |
|
482 | 482 | $exists = true; |
483 | 483 | } |
484 | 484 | } |
@@ -494,7 +494,7 @@ discard block |
||
494 | 494 | } |
495 | 495 | public function unreadMessage($username, $password) |
496 | 496 | { |
497 | - if($this->verifyUserPass($username, $password) == "valid") |
|
497 | + if ($this->verifyUserPass($username, $password) == "valid") |
|
498 | 498 | { |
499 | 499 | $table_message = Database::get_main_table(TABLE_MESSAGE); |
500 | 500 | $user_id = UserManager::get_user_id_from_username($username); |
@@ -511,7 +511,7 @@ discard block |
||
511 | 511 | |
512 | 512 | public function get_message_data($username, $password) |
513 | 513 | { |
514 | - if($this->verifyUserPass($username, $password) == "valid") |
|
514 | + if ($this->verifyUserPass($username, $password) == "valid") |
|
515 | 515 | { |
516 | 516 | $user_id = get_user_id_from_username($username); |
517 | 517 | |
@@ -521,7 +521,7 @@ discard block |
||
521 | 521 | |
522 | 522 | public function nada($username, $password) |
523 | 523 | { |
524 | - if($this->verifyUserPass($username, $password) == "valid") |
|
524 | + if ($this->verifyUserPass($username, $password) == "valid") |
|
525 | 525 | return $username.$password; |
526 | 526 | return $username; |
527 | 527 | } |
@@ -204,6 +204,9 @@ |
||
204 | 204 | |
205 | 205 | } |
206 | 206 | |
207 | + /** |
|
208 | + * @param integer $user_id |
|
209 | + */ |
|
207 | 210 | protected function set_message_as_read($user_id, $message_id){ |
208 | 211 | $table_message = Database::get_main_table(TABLE_MESSAGE); |
209 | 212 | $query = "UPDATE $table_message SET msg_status = '".MESSAGE_STATUS_NEW."' WHERE user_receiver_id=".$user_id." AND id='".$message_id."';"; |
@@ -37,8 +37,8 @@ discard block |
||
37 | 37 | $table_message = Database::get_main_table(TABLE_MESSAGE); |
38 | 38 | |
39 | 39 | $sql_query = "SELECT id FROM $table_message " . |
40 | - " WHERE user_receiver_id=".$user_id." AND msg_status IN (0,1)" . |
|
41 | - " ORDER BY send_date LIMIT $from,$number_of_items"; |
|
40 | + " WHERE user_receiver_id=".$user_id." AND msg_status IN (0,1)" . |
|
41 | + " ORDER BY send_date LIMIT $from,$number_of_items"; |
|
42 | 42 | |
43 | 43 | $sql_result = Database::query($sql_query); |
44 | 44 | $message = "#"; |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | $table_message = Database::get_main_table(TABLE_MESSAGE); |
87 | 87 | |
88 | 88 | $sql_query = "SELECT ".$field_table." FROM $table_message " . |
89 | - " WHERE user_receiver_id=".$user_id." AND id=".$message_id; |
|
89 | + " WHERE user_receiver_id=".$user_id." AND id=".$message_id; |
|
90 | 90 | |
91 | 91 | $sql_result = Database::query($sql_query); |
92 | 92 | $result = Database::fetch_row($sql_result); |
@@ -107,8 +107,8 @@ discard block |
||
107 | 107 | $table_message = Database::get_main_table(TABLE_MESSAGE); |
108 | 108 | |
109 | 109 | $sql_query = "SELECT id FROM $table_message " . |
110 | - "WHERE user_sender_id=".$user_id." AND msg_status=".MESSAGE_STATUS_OUTBOX." " . |
|
111 | - "ORDER BY send_date LIMIT $from,$number_of_items"; |
|
110 | + "WHERE user_sender_id=".$user_id." AND msg_status=".MESSAGE_STATUS_OUTBOX." " . |
|
111 | + "ORDER BY send_date LIMIT $from,$number_of_items"; |
|
112 | 112 | |
113 | 113 | $sql_result = Database::query($sql_query); |
114 | 114 | $message = "#"; |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | $table_message = Database::get_main_table(TABLE_MESSAGE); |
158 | 158 | |
159 | 159 | $sql_query = "SELECT ".$field_table." FROM $table_message " . |
160 | - " WHERE user_sender_id=".$user_id." AND id=".$id; |
|
160 | + " WHERE user_sender_id=".$user_id." AND id=".$id; |
|
161 | 161 | |
162 | 162 | $sql_result = Database::query($sql_query); |
163 | 163 | $result = Database::fetch_row($sql_result); |
@@ -188,11 +188,11 @@ discard block |
||
188 | 188 | $table_message = Database::get_main_table(TABLE_MESSAGE); |
189 | 189 | |
190 | 190 | $query = "INSERT INTO $table_message(user_sender_id, user_receiver_id, msg_status, send_date, title, content, group_id, parent_id, update_date ) ". |
191 | - " VALUES ('$user_sender_id', '$receiver_user_id', '1', '".api_get_utc_datetime()."','$subject','$content','$group_id','$parent_id', '".api_get_utc_datetime()."')"; |
|
191 | + " VALUES ('$user_sender_id', '$receiver_user_id', '1', '".api_get_utc_datetime()."','$subject','$content','$group_id','$parent_id', '".api_get_utc_datetime()."')"; |
|
192 | 192 | $result = Database::query($query); |
193 | 193 | |
194 | 194 | $query = "INSERT INTO $table_message(user_sender_id, user_receiver_id, msg_status, send_date, title, content, group_id, parent_id, update_date ) ". |
195 | - " VALUES ('$user_sender_id', '$receiver_user_id', '4', '".api_get_utc_datetime()."','$subject','$content','$group_id','$parent_id', '".api_get_utc_datetime()."')"; |
|
195 | + " VALUES ('$user_sender_id', '$receiver_user_id', '4', '".api_get_utc_datetime()."','$subject','$content','$group_id','$parent_id', '".api_get_utc_datetime()."')"; |
|
196 | 196 | $result = Database::query($query); |
197 | 197 | |
198 | 198 | $inbox_last_id = Database::insert_id(); |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | { |
13 | 13 | public function unreadMessage($username, $password) |
14 | 14 | { |
15 | - if($this->verifyUserPass($username, $password) == "valid") |
|
15 | + if ($this->verifyUserPass($username, $password) == "valid") |
|
16 | 16 | { |
17 | 17 | $table_message = Database::get_main_table(TABLE_MESSAGE); |
18 | 18 | $user_id = UserManager::get_user_id_from_username($username); |
@@ -30,14 +30,14 @@ discard block |
||
30 | 30 | |
31 | 31 | public function get_message_id($username, $password, $from, $number_of_items) |
32 | 32 | { |
33 | - if($this->verifyUserPass($username, $password) == "valid") |
|
33 | + if ($this->verifyUserPass($username, $password) == "valid") |
|
34 | 34 | { |
35 | 35 | $user_id = UserManager::get_user_id_from_username($username); |
36 | 36 | |
37 | 37 | $table_message = Database::get_main_table(TABLE_MESSAGE); |
38 | 38 | |
39 | - $sql_query = "SELECT id FROM $table_message " . |
|
40 | - " WHERE user_receiver_id=".$user_id." AND msg_status IN (0,1)" . |
|
39 | + $sql_query = "SELECT id FROM $table_message ". |
|
40 | + " WHERE user_receiver_id=".$user_id." AND msg_status IN (0,1)". |
|
41 | 41 | " ORDER BY send_date LIMIT $from,$number_of_items"; |
42 | 42 | |
43 | 43 | $sql_result = Database::query($sql_query); |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | |
56 | 56 | public function get_message_data($username, $password, $message_id, $field) |
57 | 57 | { |
58 | - if($this->verifyUserPass($username, $password) == "valid") |
|
58 | + if ($this->verifyUserPass($username, $password) == "valid") |
|
59 | 59 | { |
60 | 60 | $htmlcode = false; |
61 | 61 | $user_id = UserManager::get_user_id_from_username($username); |
@@ -85,14 +85,14 @@ discard block |
||
85 | 85 | |
86 | 86 | $table_message = Database::get_main_table(TABLE_MESSAGE); |
87 | 87 | |
88 | - $sql_query = "SELECT ".$field_table." FROM $table_message " . |
|
88 | + $sql_query = "SELECT ".$field_table." FROM $table_message ". |
|
89 | 89 | " WHERE user_receiver_id=".$user_id." AND id=".$message_id; |
90 | 90 | |
91 | 91 | $sql_result = Database::query($sql_query); |
92 | 92 | $result = Database::fetch_row($sql_result); |
93 | 93 | return (htmlcode) ? html_entity_decode($result[0]) : $result[0]; |
94 | 94 | |
95 | - }else |
|
95 | + } else |
|
96 | 96 | return get_lang('InvalidId'); |
97 | 97 | |
98 | 98 | |
@@ -100,14 +100,14 @@ discard block |
||
100 | 100 | |
101 | 101 | public function get_message_id_sent($username, $password, $from, $number_of_items) |
102 | 102 | { |
103 | - if($this->verifyUserPass($username, $password) == "valid") |
|
103 | + if ($this->verifyUserPass($username, $password) == "valid") |
|
104 | 104 | { |
105 | 105 | $user_id = UserManager::get_user_id_from_username($username); |
106 | 106 | |
107 | 107 | $table_message = Database::get_main_table(TABLE_MESSAGE); |
108 | 108 | |
109 | - $sql_query = "SELECT id FROM $table_message " . |
|
110 | - "WHERE user_sender_id=".$user_id." AND msg_status=".MESSAGE_STATUS_OUTBOX." " . |
|
109 | + $sql_query = "SELECT id FROM $table_message ". |
|
110 | + "WHERE user_sender_id=".$user_id." AND msg_status=".MESSAGE_STATUS_OUTBOX." ". |
|
111 | 111 | "ORDER BY send_date LIMIT $from,$number_of_items"; |
112 | 112 | |
113 | 113 | $sql_result = Database::query($sql_query); |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | |
127 | 127 | public function get_message_data_sent($username, $password, $id, $field) |
128 | 128 | { |
129 | - if($this->verifyUserPass($username, $password) == "valid") |
|
129 | + if ($this->verifyUserPass($username, $password) == "valid") |
|
130 | 130 | { |
131 | 131 | $htmlcode = false; |
132 | 132 | switch ($field) |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | |
157 | 157 | $table_message = Database::get_main_table(TABLE_MESSAGE); |
158 | 158 | |
159 | - $sql_query = "SELECT ".$field_table." FROM $table_message " . |
|
159 | + $sql_query = "SELECT ".$field_table." FROM $table_message ". |
|
160 | 160 | " WHERE user_sender_id=".$user_id." AND id=".$id; |
161 | 161 | |
162 | 162 | $sql_result = Database::query($sql_query); |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | |
165 | 165 | return (htmlcode) ? html_entity_decode($result[0]) : $result[0]; |
166 | 166 | |
167 | - }else |
|
167 | + } else |
|
168 | 168 | return get_lang('InvalidId'); |
169 | 169 | |
170 | 170 | |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | public function message_send($username, $password, $receiver_user_id, $subject, $content) |
174 | 174 | { |
175 | 175 | //TODO: verificar data de envio. Esta divergindo de data! |
176 | - if($this->verifyUserPass($username, $password) == "valid") |
|
176 | + if ($this->verifyUserPass($username, $password) == "valid") |
|
177 | 177 | { |
178 | 178 | $group_id = intval(0); |
179 | 179 | $parent_id = intval(0); |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | |
205 | 205 | } |
206 | 206 | |
207 | - protected function set_message_as_read($user_id, $message_id){ |
|
207 | + protected function set_message_as_read($user_id, $message_id) { |
|
208 | 208 | $table_message = Database::get_main_table(TABLE_MESSAGE); |
209 | 209 | $query = "UPDATE $table_message SET msg_status = '".MESSAGE_STATUS_NEW."' WHERE user_receiver_id=".$user_id." AND id='".$message_id."';"; |
210 | 210 | $result = Database::query($query); |
@@ -48,8 +48,9 @@ discard block |
||
48 | 48 | |
49 | 49 | return $message; |
50 | 50 | |
51 | - } else |
|
52 | - return get_lang('InvalidId'); |
|
51 | + } else { |
|
52 | + return get_lang('InvalidId'); |
|
53 | + } |
|
53 | 54 | |
54 | 55 | } |
55 | 56 | |
@@ -92,8 +93,9 @@ discard block |
||
92 | 93 | $result = Database::fetch_row($sql_result); |
93 | 94 | return (htmlcode) ? html_entity_decode($result[0]) : $result[0]; |
94 | 95 | |
95 | - }else |
|
96 | - return get_lang('InvalidId'); |
|
96 | + } else { |
|
97 | + return get_lang('InvalidId'); |
|
98 | + } |
|
97 | 99 | |
98 | 100 | |
99 | 101 | } |
@@ -118,8 +120,9 @@ discard block |
||
118 | 120 | |
119 | 121 | return $message; |
120 | 122 | |
121 | - } else |
|
122 | - return get_lang('InvalidId'); |
|
123 | + } else { |
|
124 | + return get_lang('InvalidId'); |
|
125 | + } |
|
123 | 126 | |
124 | 127 | } |
125 | 128 | |
@@ -164,8 +167,9 @@ discard block |
||
164 | 167 | |
165 | 168 | return (htmlcode) ? html_entity_decode($result[0]) : $result[0]; |
166 | 169 | |
167 | - }else |
|
168 | - return get_lang('InvalidId'); |
|
170 | + } else { |
|
171 | + return get_lang('InvalidId'); |
|
172 | + } |
|
169 | 173 | |
170 | 174 | |
171 | 175 | } |
@@ -199,8 +203,9 @@ discard block |
||
199 | 203 | |
200 | 204 | return $inbox_last_id; |
201 | 205 | |
202 | - } else |
|
203 | - return get_lang('InvalidId'); |
|
206 | + } else { |
|
207 | + return get_lang('InvalidId'); |
|
208 | + } |
|
204 | 209 | |
205 | 210 | } |
206 | 211 |
@@ -137,7 +137,7 @@ |
||
137 | 137 | /** |
138 | 138 | * Get a list of users of which the given conditions match with a LIKE '%cond%' |
139 | 139 | * @param array $conditions a list of condition (exemple : status=>STUDENT) |
140 | - * @param array $order_by a list of fields on which sort |
|
140 | + * @param string[] $order_by a list of fields on which sort |
|
141 | 141 | * @return array An array with all users of the platform. |
142 | 142 | * @todo optional course code parameter, optional sorting parameters... |
143 | 143 | *@todo Use the UserManager class |
@@ -13,21 +13,21 @@ discard block |
||
13 | 13 | |
14 | 14 | public function find_id_user($username, $password, $name) |
15 | 15 | { |
16 | - if ($this->verifyUserPass($username, $password) == "valid") { |
|
16 | + if ($this->verifyUserPass($username, $password) == "valid") { |
|
17 | 17 | $listResult = "#"; |
18 | 18 | |
19 | 19 | $listArrayResult = Array(); |
20 | 20 | $listArray = Array(); |
21 | 21 | |
22 | 22 | $list = $this->get_user_list_like_start(array('firstname'=>$name), array('firstname')); |
23 | - foreach ($list as $userData) { |
|
24 | - $listArray[] = $userData['user_id']; |
|
25 | - } |
|
23 | + foreach ($list as $userData) { |
|
24 | + $listArray[] = $userData['user_id']; |
|
25 | + } |
|
26 | 26 | |
27 | 27 | $list = $this->get_user_list_like_start(array('lastname'=>$name), array('firstname')); |
28 | - foreach ($list as $userData) { |
|
29 | - $listArray[] = $userData['user_id']; |
|
30 | - } |
|
28 | + foreach ($list as $userData) { |
|
29 | + $listArray[] = $userData['user_id']; |
|
30 | + } |
|
31 | 31 | |
32 | 32 | $list = $this->get_user_list_like_start(array('email'=>$name), array('firstname')); |
33 | 33 | foreach ($list as $userData) { |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | { |
90 | 90 | global $charset; |
91 | 91 | if ($this->verifyUserPass($username, $password) == "valid") { |
92 | - $user_id = UserManager::get_user_id_from_username($username); |
|
92 | + $user_id = UserManager::get_user_id_from_username($username); |
|
93 | 93 | $message_title = get_lang('Invitation'); |
94 | 94 | $count_is_true = SocialManager::send_invitation_friend($user_id,$userfriend_id, $message_title, $content_message); |
95 | 95 | |
@@ -129,14 +129,14 @@ discard block |
||
129 | 129 | |
130 | 130 | |
131 | 131 | /** |
132 | - * Get a list of users of which the given conditions match with a LIKE '%cond%' |
|
133 | - * @param array $conditions a list of condition (exemple : status=>STUDENT) |
|
134 | - * @param array $order_by a list of fields on which sort |
|
135 | - * @return array An array with all users of the platform. |
|
136 | - * @todo optional course code parameter, optional sorting parameters... |
|
132 | + * Get a list of users of which the given conditions match with a LIKE '%cond%' |
|
133 | + * @param array $conditions a list of condition (exemple : status=>STUDENT) |
|
134 | + * @param array $order_by a list of fields on which sort |
|
135 | + * @return array An array with all users of the platform. |
|
136 | + * @todo optional course code parameter, optional sorting parameters... |
|
137 | 137 | *@todo Use the UserManager class |
138 | 138 | * @todo security filter order by |
139 | - */ |
|
139 | + */ |
|
140 | 140 | private static function get_user_list_like_start($conditions = array(), $order_by = array()) |
141 | 141 | { |
142 | 142 | $user_table = Database :: get_main_table(TABLE_MAIN_USER); |
@@ -91,12 +91,12 @@ |
||
91 | 91 | if ($this->verifyUserPass($username, $password) == "valid") { |
92 | 92 | $user_id = UserManager::get_user_id_from_username($username); |
93 | 93 | $message_title = get_lang('Invitation'); |
94 | - $count_is_true = SocialManager::send_invitation_friend($user_id,$userfriend_id, $message_title, $content_message); |
|
94 | + $count_is_true = SocialManager::send_invitation_friend($user_id, $userfriend_id, $message_title, $content_message); |
|
95 | 95 | |
96 | 96 | if ($count_is_true) { |
97 | - return Display::display_normal_message(api_htmlentities(get_lang('InvitationHasBeenSent'), ENT_QUOTES,$charset),false); |
|
97 | + return Display::display_normal_message(api_htmlentities(get_lang('InvitationHasBeenSent'), ENT_QUOTES, $charset), false); |
|
98 | 98 | } else { |
99 | - return Display::display_error_message(api_htmlentities(get_lang('YouAlreadySentAnInvitation'), ENT_QUOTES,$charset),false); |
|
99 | + return Display::display_error_message(api_htmlentities(get_lang('YouAlreadySentAnInvitation'), ENT_QUOTES, $charset), false); |
|
100 | 100 | } |
101 | 101 | } |
102 | 102 | return get_lang('InvalidId'); |
@@ -20,6 +20,9 @@ |
||
20 | 20 | |
21 | 21 | define('WS_ERROR_SECRET_KEY', 1); |
22 | 22 | |
23 | +/** |
|
24 | + * @param integer $code |
|
25 | + */ |
|
23 | 26 | function return_error($code) { |
24 | 27 | $fault = null; |
25 | 28 | switch ($code) { |
@@ -581,7 +581,7 @@ |
||
581 | 581 | /*$sessionIdName = isset($params['session_id_name']) ? $params['session_id_name'] : null; |
582 | 582 | $sessionIdValue = isset($params['session_id_value']) ? $params['session_id_value'] : null;*/ |
583 | 583 | |
584 | - $courseInfo = CourseManager::getCourseInfoFromOriginalId( |
|
584 | + $courseInfo = CourseManager::getCourseInfoFromOriginalId( |
|
585 | 585 | $courseIdValue, |
586 | 586 | $courseIdName |
587 | 587 | ); |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | } |
66 | 66 | |
67 | 67 | if ($debug) { |
68 | - error_log("checkip " . intval($check_ip)); |
|
68 | + error_log("checkip ".intval($check_ip)); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | if ($check_ip) { |
@@ -120,13 +120,13 @@ discard block |
||
120 | 120 | ); |
121 | 121 | |
122 | 122 | // Register the method to expose |
123 | -$server->register('WSImportLP', // method name |
|
124 | - array('params' => 'tns:params'), // input parameters |
|
125 | - array('return' => 'xsd:string'), // output parameters |
|
126 | - 'urn:WSLP', // namespace |
|
127 | - 'urn:WSLP#WSImportLP', // soapaction |
|
128 | - 'rpc', // style |
|
129 | - 'encoded', // use |
|
123 | +$server->register('WSImportLP', // method name |
|
124 | + array('params' => 'tns:params'), // input parameters |
|
125 | + array('return' => 'xsd:string'), // output parameters |
|
126 | + 'urn:WSLP', // namespace |
|
127 | + 'urn:WSLP#WSImportLP', // soapaction |
|
128 | + 'rpc', // style |
|
129 | + 'encoded', // use |
|
130 | 130 | 'This service adds users' // documentation |
131 | 131 | ); |
132 | 132 | |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | |
184 | 184 | $uniqueFile = uniqid(); |
185 | 185 | $userId = 1; // admin |
186 | - $filePath = api_get_path(SYS_ARCHIVE_PATH) . $uniqueFile; |
|
186 | + $filePath = api_get_path(SYS_ARCHIVE_PATH).$uniqueFile; |
|
187 | 187 | file_put_contents($filePath, $fileData); |
188 | 188 | |
189 | 189 | $fileName = $params['filename']; |
@@ -257,8 +257,8 @@ discard block |
||
257 | 257 | 'all', |
258 | 258 | '', |
259 | 259 | array( |
260 | - 'id' => array('name' => 'id', 'type' => 'xsd:string'), |
|
261 | - 'name' => array('name' => 'name', 'type' => 'xsd:string'), |
|
260 | + 'id' => array('name' => 'id', 'type' => 'xsd:string'), |
|
261 | + 'name' => array('name' => 'name', 'type' => 'xsd:string'), |
|
262 | 262 | ) |
263 | 263 | ); |
264 | 264 | |
@@ -274,13 +274,13 @@ discard block |
||
274 | 274 | ); |
275 | 275 | |
276 | 276 | // Register the method to expose |
277 | -$server->register('WSGetLpList', // method name |
|
278 | - array('params' => 'tns:paramsGetLpList'), // input parameters |
|
279 | - array('return' => 'tns:lpList'), // output parameters |
|
280 | - 'urn:WSLP', // namespace |
|
281 | - 'urn:WSLP#WSGetLpList', // soapaction |
|
282 | - 'rpc', // style |
|
283 | - 'encoded', // use |
|
277 | +$server->register('WSGetLpList', // method name |
|
278 | + array('params' => 'tns:paramsGetLpList'), // input parameters |
|
279 | + array('return' => 'tns:lpList'), // output parameters |
|
280 | + 'urn:WSLP', // namespace |
|
281 | + 'urn:WSLP#WSGetLpList', // soapaction |
|
282 | + 'rpc', // style |
|
283 | + 'encoded', // use |
|
284 | 284 | 'This service adds users' // documentation |
285 | 285 | ); |
286 | 286 | |
@@ -295,9 +295,9 @@ discard block |
||
295 | 295 | return return_error(WS_ERROR_SECRET_KEY); |
296 | 296 | } |
297 | 297 | |
298 | - require_once api_get_path(SYS_CODE_PATH) . 'lp/learnpathList.class.php'; |
|
299 | - require_once api_get_path(SYS_CODE_PATH) . 'lp/learnpath.class.php'; |
|
300 | - require_once api_get_path(SYS_CODE_PATH) . 'lp/learnpathItem.class.php'; |
|
298 | + require_once api_get_path(SYS_CODE_PATH).'lp/learnpathList.class.php'; |
|
299 | + require_once api_get_path(SYS_CODE_PATH).'lp/learnpath.class.php'; |
|
300 | + require_once api_get_path(SYS_CODE_PATH).'lp/learnpathItem.class.php'; |
|
301 | 301 | |
302 | 302 | $courseIdName = $params['course_id_name']; |
303 | 303 | $courseIdValue = $params['course_id_value']; |
@@ -369,13 +369,13 @@ discard block |
||
369 | 369 | ); |
370 | 370 | |
371 | 371 | // Register the method to expose |
372 | -$server->register('WSDeleteLp', // method name |
|
373 | - array('params' => 'tns:paramsDeleteLp'), // input parameters |
|
374 | - array('return' => 'xsd:string'), // output parameters |
|
375 | - 'urn:WSLP', // namespace |
|
376 | - 'urn:WSLP#WSDeleteLp', // soapaction |
|
377 | - 'rpc', // style |
|
378 | - 'encoded', // use |
|
372 | +$server->register('WSDeleteLp', // method name |
|
373 | + array('params' => 'tns:paramsDeleteLp'), // input parameters |
|
374 | + array('return' => 'xsd:string'), // output parameters |
|
375 | + 'urn:WSLP', // namespace |
|
376 | + 'urn:WSLP#WSDeleteLp', // soapaction |
|
377 | + 'rpc', // style |
|
378 | + 'encoded', // use |
|
379 | 379 | 'This service deletes a LP' // documentation |
380 | 380 | ); |
381 | 381 | |
@@ -390,9 +390,9 @@ discard block |
||
390 | 390 | return return_error(WS_ERROR_SECRET_KEY); |
391 | 391 | } |
392 | 392 | |
393 | - require_once api_get_path(SYS_CODE_PATH) . 'lp/learnpathList.class.php'; |
|
394 | - require_once api_get_path(SYS_CODE_PATH) . 'lp/learnpath.class.php'; |
|
395 | - require_once api_get_path(SYS_CODE_PATH) . 'lp/learnpathItem.class.php'; |
|
393 | + require_once api_get_path(SYS_CODE_PATH).'lp/learnpathList.class.php'; |
|
394 | + require_once api_get_path(SYS_CODE_PATH).'lp/learnpath.class.php'; |
|
395 | + require_once api_get_path(SYS_CODE_PATH).'lp/learnpathItem.class.php'; |
|
396 | 396 | |
397 | 397 | $courseIdName = $params['course_id_name']; |
398 | 398 | $courseIdValue = $params['course_id_value']; |
@@ -434,9 +434,9 @@ discard block |
||
434 | 434 | if ($lp) { |
435 | 435 | if ($debug) error_log("LP deleted $lpId"); |
436 | 436 | |
437 | - $course_dir = $courseInfo['directory'] . '/document'; |
|
437 | + $course_dir = $courseInfo['directory'].'/document'; |
|
438 | 438 | $sys_course_path = api_get_path(SYS_COURSE_PATH); |
439 | - $base_work_dir = $sys_course_path . $course_dir; |
|
439 | + $base_work_dir = $sys_course_path.$course_dir; |
|
440 | 440 | |
441 | 441 | $items = $lp->get_flat_ordered_items_list($lpId, 0, $courseId); |
442 | 442 | |
@@ -495,9 +495,9 @@ discard block |
||
495 | 495 | 'all', |
496 | 496 | '', |
497 | 497 | array( |
498 | - 'data' => array('name' => 'data', 'type' => 'xsd:string'), |
|
499 | - 'title' => array('name' => 'title', 'type' => 'xsd:string'), |
|
500 | - 'filename' => array('name' => 'filename', 'type' => 'xsd:string'), |
|
498 | + 'data' => array('name' => 'data', 'type' => 'xsd:string'), |
|
499 | + 'title' => array('name' => 'title', 'type' => 'xsd:string'), |
|
500 | + 'filename' => array('name' => 'filename', 'type' => 'xsd:string'), |
|
501 | 501 | ) |
502 | 502 | ); |
503 | 503 | |
@@ -548,13 +548,13 @@ discard block |
||
548 | 548 | ); |
549 | 549 | |
550 | 550 | // Register the method to expose |
551 | -$server->register('WSCreateLp', // method name |
|
552 | - array('params' => 'tns:paramsCreateLp'), // input parameters |
|
553 | - array('return' => 'xsd:string'), // output parameters |
|
554 | - 'urn:WSLP', // namespace |
|
555 | - 'urn:WSLP#WSCreateLp', // soapaction |
|
556 | - 'rpc', // style |
|
557 | - 'encoded', // use |
|
551 | +$server->register('WSCreateLp', // method name |
|
552 | + array('params' => 'tns:paramsCreateLp'), // input parameters |
|
553 | + array('return' => 'xsd:string'), // output parameters |
|
554 | + 'urn:WSLP', // namespace |
|
555 | + 'urn:WSLP#WSCreateLp', // soapaction |
|
556 | + 'rpc', // style |
|
557 | + 'encoded', // use |
|
558 | 558 | 'This service creates a LP' // documentation |
559 | 559 | ); |
560 | 560 |
@@ -48,19 +48,22 @@ discard block |
||
48 | 48 | list($ip1) = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); |
49 | 49 | $ip = trim($ip1); |
50 | 50 | } |
51 | - if ($debug) |
|
52 | - error_log("ip: $ip"); |
|
51 | + if ($debug) { |
|
52 | + error_log("ip: $ip"); |
|
53 | + } |
|
53 | 54 | // Check if a file that limits access from webservices exists and contains |
54 | 55 | // the restraining check |
55 | 56 | if (is_file('webservice-auth-ip.conf.php')) { |
56 | 57 | include 'webservice-auth-ip.conf.php'; |
57 | - if ($debug) |
|
58 | - error_log("webservice-auth-ip.conf.php file included"); |
|
58 | + if ($debug) { |
|
59 | + error_log("webservice-auth-ip.conf.php file included"); |
|
60 | + } |
|
59 | 61 | if (!empty($ws_auth_ip)) { |
60 | 62 | $check_ip = true; |
61 | 63 | $ip_matches = api_check_ip_in_range($ip, $ws_auth_ip); |
62 | - if ($debug) |
|
63 | - error_log("ip_matches: $ip_matches"); |
|
64 | + if ($debug) { |
|
65 | + error_log("ip_matches: $ip_matches"); |
|
66 | + } |
|
64 | 67 | } |
65 | 68 | } |
66 | 69 | |
@@ -76,8 +79,9 @@ discard block |
||
76 | 79 | } |
77 | 80 | $result = api_is_valid_secret_key($secret_key, $security_key); |
78 | 81 | //error_log($secret_key.'-'.$security_key); |
79 | - if ($debug) |
|
80 | - error_log('WSHelperVerifyKey result: '.intval($result)); |
|
82 | + if ($debug) { |
|
83 | + error_log('WSHelperVerifyKey result: '.intval($result)); |
|
84 | + } |
|
81 | 85 | return $result; |
82 | 86 | } |
83 | 87 | |
@@ -140,7 +144,9 @@ discard block |
||
140 | 144 | if (!WSHelperVerifyKey($params)) { |
141 | 145 | return return_error(WS_ERROR_SECRET_KEY); |
142 | 146 | } |
143 | - if ($debug) error_log('WSImportLP'); |
|
147 | + if ($debug) { |
|
148 | + error_log('WSImportLP'); |
|
149 | + } |
|
144 | 150 | |
145 | 151 | $courseIdName = $params['course_id_name']; |
146 | 152 | $courseIdValue = $params['course_id_value']; |
@@ -156,7 +162,9 @@ discard block |
||
156 | 162 | $courseId = $courseInfo['real_id']; |
157 | 163 | |
158 | 164 | if (empty($courseInfo)) { |
159 | - if ($debug) error_log('Course not found'); |
|
165 | + if ($debug) { |
|
166 | + error_log('Course not found'); |
|
167 | + } |
|
160 | 168 | return 'Course not found'; |
161 | 169 | } |
162 | 170 | |
@@ -169,7 +177,9 @@ discard block |
||
169 | 177 | |
170 | 178 | if (empty($sessionId)) { |
171 | 179 | |
172 | - if ($debug) error_log('Session not found'); |
|
180 | + if ($debug) { |
|
181 | + error_log('Session not found'); |
|
182 | + } |
|
173 | 183 | return 'Session not found'; |
174 | 184 | } |
175 | 185 | } |
@@ -196,7 +206,9 @@ discard block |
||
196 | 206 | $manifest = $oScorm->import_package($fileInfo, '', $courseInfo); |
197 | 207 | |
198 | 208 | if (!$manifest) { |
199 | - if ($debug) error_log('manifest.xml file not found'); |
|
209 | + if ($debug) { |
|
210 | + error_log('manifest.xml file not found'); |
|
211 | + } |
|
200 | 212 | return 'manifest.xml file not found'; |
201 | 213 | } |
202 | 214 | |
@@ -214,10 +226,14 @@ discard block |
||
214 | 226 | $oScorm->set_maker($maker, $courseId); |
215 | 227 | //$oScorm->set_jslib('scorm_api.php'); |
216 | 228 | |
217 | - if ($debug) error_log('scorm was added'); |
|
229 | + if ($debug) { |
|
230 | + error_log('scorm was added'); |
|
231 | + } |
|
218 | 232 | return 1; |
219 | 233 | } else { |
220 | - if ($debug) error_log('manifest data empty'); |
|
234 | + if ($debug) { |
|
235 | + error_log('manifest data empty'); |
|
236 | + } |
|
221 | 237 | return 'manifest data empty'; |
222 | 238 | } |
223 | 239 | } |
@@ -310,7 +326,9 @@ discard block |
||
310 | 326 | ); |
311 | 327 | |
312 | 328 | if (empty($courseInfo)) { |
313 | - if ($debug) error_log("Course not found: $courseIdName : $courseIdValue"); |
|
329 | + if ($debug) { |
|
330 | + error_log("Course not found: $courseIdName : $courseIdValue"); |
|
331 | + } |
|
314 | 332 | return 'Course not found'; |
315 | 333 | } |
316 | 334 | |
@@ -325,7 +343,9 @@ discard block |
||
325 | 343 | |
326 | 344 | if (empty($sessionId)) { |
327 | 345 | |
328 | - if ($debug) error_log('Session not found'); |
|
346 | + if ($debug) { |
|
347 | + error_log('Session not found'); |
|
348 | + } |
|
329 | 349 | return 'Session not found'; |
330 | 350 | } |
331 | 351 | } |
@@ -406,7 +426,9 @@ discard block |
||
406 | 426 | ); |
407 | 427 | |
408 | 428 | if (empty($courseInfo)) { |
409 | - if ($debug) error_log("Course not found: $courseIdName : $courseIdValue"); |
|
429 | + if ($debug) { |
|
430 | + error_log("Course not found: $courseIdName : $courseIdValue"); |
|
431 | + } |
|
410 | 432 | return 'Course not found'; |
411 | 433 | } |
412 | 434 | $courseId = $courseInfo['real_id']; |
@@ -431,7 +453,9 @@ discard block |
||
431 | 453 | |
432 | 454 | $lp = new learnpath($courseCode, $lpId, null); |
433 | 455 | if ($lp) { |
434 | - if ($debug) error_log("LP deleted $lpId"); |
|
456 | + if ($debug) { |
|
457 | + error_log("LP deleted $lpId"); |
|
458 | + } |
|
435 | 459 | |
436 | 460 | $course_dir = $courseInfo['directory'] . '/document'; |
437 | 461 | $sys_course_path = api_get_path(SYS_COURSE_PATH); |
@@ -447,7 +471,9 @@ discard block |
||
447 | 471 | if ($item) { |
448 | 472 | $documentId = $item->get_path(); |
449 | 473 | |
450 | - if ($debug) error_log("lp item id found #$itemId"); |
|
474 | + if ($debug) { |
|
475 | + error_log("lp item id found #$itemId"); |
|
476 | + } |
|
451 | 477 | |
452 | 478 | $documentInfo = DocumentManager::get_document_data_by_id( |
453 | 479 | $documentId, |
@@ -473,7 +499,9 @@ discard block |
||
473 | 499 | } |
474 | 500 | } |
475 | 501 | } else { |
476 | - if ($debug) error_log("Document not found #$itemId"); |
|
502 | + if ($debug) { |
|
503 | + error_log("Document not found #$itemId"); |
|
504 | + } |
|
477 | 505 | } |
478 | 506 | } |
479 | 507 | } |
@@ -37,6 +37,8 @@ discard block |
||
37 | 37 | * |
38 | 38 | * @param int Error code |
39 | 39 | * @param string Error message |
40 | + * @param integer $code |
|
41 | + * @param string $message |
|
40 | 42 | */ |
41 | 43 | public function __construct($code, $message) { |
42 | 44 | $this->code = $code; |
@@ -47,6 +49,7 @@ discard block |
||
47 | 49 | * Sets the error handler |
48 | 50 | * |
49 | 51 | * @param WSErrorHandler Error handler |
52 | + * @param WSSoapErrorHandler $handler |
|
50 | 53 | */ |
51 | 54 | public static function setErrorHandler($handler) { |
52 | 55 | if($handler instanceof WSErrorHandler) { |
@@ -81,6 +84,7 @@ discard block |
||
81 | 84 | * Handle method |
82 | 85 | * |
83 | 86 | * @param WSError Error |
87 | + * @return void |
|
84 | 88 | */ |
85 | 89 | public function handle($error); |
86 | 90 | } |
@@ -107,7 +111,7 @@ discard block |
||
107 | 111 | * Verifies the API key |
108 | 112 | * |
109 | 113 | * @param string Secret key |
110 | - * @return mixed WSError in case of failure, null in case of success |
|
114 | + * @return WSError|null WSError in case of failure, null in case of success |
|
111 | 115 | */ |
112 | 116 | protected function verifyKey($secret_key) { |
113 | 117 | $ip = trim($_SERVER['REMOTE_ADDR']); |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | * @param WSErrorHandler Error handler |
50 | 50 | */ |
51 | 51 | public static function setErrorHandler($handler) { |
52 | - if($handler instanceof WSErrorHandler) { |
|
52 | + if ($handler instanceof WSErrorHandler) { |
|
53 | 53 | self::$_handler = $handler; |
54 | 54 | } |
55 | 55 | } |
@@ -114,12 +114,12 @@ discard block |
||
114 | 114 | // if we are behind a reverse proxy, assume it will send the |
115 | 115 | // HTTP_X_FORWARDED_FOR header and use this IP instead |
116 | 116 | if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
117 | - list($ip1,$ip2) = preg_split('/,/',$_SERVER['HTTP_X_FORWARDED_FOR']); |
|
117 | + list($ip1, $ip2) = preg_split('/,/', $_SERVER['HTTP_X_FORWARDED_FOR']); |
|
118 | 118 | $ip = trim($ip1); |
119 | 119 | } |
120 | 120 | $security_key = $ip.$this->_configuration['security_key']; |
121 | 121 | |
122 | - if(!api_is_valid_secret_key($secret_key, $security_key)) { |
|
122 | + if (!api_is_valid_secret_key($secret_key, $security_key)) { |
|
123 | 123 | return new WSError(1, "API key is invalid"); |
124 | 124 | } else { |
125 | 125 | return null; |
@@ -136,15 +136,15 @@ discard block |
||
136 | 136 | * @return mixed System user id if the user was found, WSError otherwise |
137 | 137 | */ |
138 | 138 | protected function getUserId($user_id_field_name, $user_id_value) { |
139 | - if($user_id_field_name == "chamilo_user_id") { |
|
140 | - if(UserManager::is_user_id_valid(intval($user_id_value))) { |
|
139 | + if ($user_id_field_name == "chamilo_user_id") { |
|
140 | + if (UserManager::is_user_id_valid(intval($user_id_value))) { |
|
141 | 141 | return intval($user_id_value); |
142 | 142 | } else { |
143 | 143 | return new WSError(100, "User not found"); |
144 | 144 | } |
145 | 145 | } else { |
146 | 146 | $user_id = UserManager::get_user_id_from_original_id($user_id_value, $user_id_field_name); |
147 | - if($user_id == 0) { |
|
147 | + if ($user_id == 0) { |
|
148 | 148 | return new WSError(100, "User not found"); |
149 | 149 | } else { |
150 | 150 | return $user_id; |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | protected function getSessionId($session_id_field_name, $session_id_value) |
198 | 198 | { |
199 | 199 | if ($session_id_field_name == "chamilo_session_id") { |
200 | - $session = SessionManager::fetch((int)$session_id_value); |
|
200 | + $session = SessionManager::fetch((int) $session_id_value); |
|
201 | 201 | if (!empty($session)) { |
202 | 202 | return intval($session_id_value); |
203 | 203 | } else { |
@@ -11,237 +11,237 @@ |
||
11 | 11 | */ |
12 | 12 | class WSError |
13 | 13 | { |
14 | - /** |
|
15 | - * Error handler. This needs to be a class that implements the interface WSErrorHandler |
|
16 | - * |
|
17 | - * @var WSErrorHandler |
|
18 | - */ |
|
19 | - protected static $_handler; |
|
20 | - |
|
21 | - /** |
|
22 | - * Error code |
|
23 | - * |
|
24 | - * @var int |
|
25 | - */ |
|
26 | - public $code; |
|
27 | - |
|
28 | - /** |
|
29 | - * Error message |
|
30 | - * |
|
31 | - * @var string |
|
32 | - */ |
|
33 | - public $message; |
|
34 | - |
|
35 | - /** |
|
36 | - * Constructor |
|
37 | - * |
|
38 | - * @param int Error code |
|
39 | - * @param string Error message |
|
40 | - */ |
|
41 | - public function __construct($code, $message) { |
|
42 | - $this->code = $code; |
|
43 | - $this->message = $message; |
|
44 | - } |
|
45 | - |
|
46 | - /** |
|
47 | - * Sets the error handler |
|
48 | - * |
|
49 | - * @param WSErrorHandler Error handler |
|
50 | - */ |
|
51 | - public static function setErrorHandler($handler) { |
|
52 | - if($handler instanceof WSErrorHandler) { |
|
53 | - self::$_handler = $handler; |
|
54 | - } |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * Returns the error handler |
|
59 | - * |
|
60 | - * @return WSErrorHandler Error handler |
|
61 | - */ |
|
62 | - public static function getErrorHandler() { |
|
63 | - return self::$_handler; |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * Transforms the error into an array |
|
68 | - * |
|
69 | - * @return array Associative array with code and message |
|
70 | - */ |
|
71 | - public function toArray() { |
|
72 | - return array('code' => $this->code, 'message' => $this->message); |
|
73 | - } |
|
14 | + /** |
|
15 | + * Error handler. This needs to be a class that implements the interface WSErrorHandler |
|
16 | + * |
|
17 | + * @var WSErrorHandler |
|
18 | + */ |
|
19 | + protected static $_handler; |
|
20 | + |
|
21 | + /** |
|
22 | + * Error code |
|
23 | + * |
|
24 | + * @var int |
|
25 | + */ |
|
26 | + public $code; |
|
27 | + |
|
28 | + /** |
|
29 | + * Error message |
|
30 | + * |
|
31 | + * @var string |
|
32 | + */ |
|
33 | + public $message; |
|
34 | + |
|
35 | + /** |
|
36 | + * Constructor |
|
37 | + * |
|
38 | + * @param int Error code |
|
39 | + * @param string Error message |
|
40 | + */ |
|
41 | + public function __construct($code, $message) { |
|
42 | + $this->code = $code; |
|
43 | + $this->message = $message; |
|
44 | + } |
|
45 | + |
|
46 | + /** |
|
47 | + * Sets the error handler |
|
48 | + * |
|
49 | + * @param WSErrorHandler Error handler |
|
50 | + */ |
|
51 | + public static function setErrorHandler($handler) { |
|
52 | + if($handler instanceof WSErrorHandler) { |
|
53 | + self::$_handler = $handler; |
|
54 | + } |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * Returns the error handler |
|
59 | + * |
|
60 | + * @return WSErrorHandler Error handler |
|
61 | + */ |
|
62 | + public static function getErrorHandler() { |
|
63 | + return self::$_handler; |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * Transforms the error into an array |
|
68 | + * |
|
69 | + * @return array Associative array with code and message |
|
70 | + */ |
|
71 | + public function toArray() { |
|
72 | + return array('code' => $this->code, 'message' => $this->message); |
|
73 | + } |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
77 | 77 | * Interface that must be implemented by any error handler |
78 | 78 | */ |
79 | 79 | interface WSErrorHandler { |
80 | - /** |
|
81 | - * Handle method |
|
82 | - * |
|
83 | - * @param WSError Error |
|
84 | - */ |
|
85 | - public function handle($error); |
|
80 | + /** |
|
81 | + * Handle method |
|
82 | + * |
|
83 | + * @param WSError Error |
|
84 | + */ |
|
85 | + public function handle($error); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | /** |
89 | 89 | * Main class of the webservice. Webservice classes extend this class |
90 | 90 | */ |
91 | 91 | class WS { |
92 | - /** |
|
93 | - * Chamilo configuration |
|
94 | - * |
|
95 | - * @var array |
|
96 | - */ |
|
97 | - protected $_configuration; |
|
98 | - |
|
99 | - /** |
|
100 | - * Constructor |
|
101 | - */ |
|
102 | - public function __construct() { |
|
103 | - $this->_configuration = $GLOBALS['_configuration']; |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * Verifies the API key |
|
108 | - * |
|
109 | - * @param string Secret key |
|
110 | - * @return mixed WSError in case of failure, null in case of success |
|
111 | - */ |
|
112 | - protected function verifyKey($secret_key) { |
|
113 | - $ip = trim($_SERVER['REMOTE_ADDR']); |
|
114 | - // if we are behind a reverse proxy, assume it will send the |
|
115 | - // HTTP_X_FORWARDED_FOR header and use this IP instead |
|
116 | - if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
|
117 | - list($ip1,$ip2) = preg_split('/,/',$_SERVER['HTTP_X_FORWARDED_FOR']); |
|
118 | - $ip = trim($ip1); |
|
119 | - } |
|
120 | - $security_key = $ip.$this->_configuration['security_key']; |
|
121 | - |
|
122 | - if(!api_is_valid_secret_key($secret_key, $security_key)) { |
|
123 | - return new WSError(1, "API key is invalid"); |
|
124 | - } else { |
|
125 | - return null; |
|
126 | - } |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * Gets the real user id based on the user id field name and value. |
|
131 | - * Note that if the user id field name is "chamilo_user_id", it will use the user id |
|
132 | - * in the system database |
|
133 | - * |
|
134 | - * @param string User id field name |
|
135 | - * @param string User id value |
|
136 | - * @return mixed System user id if the user was found, WSError otherwise |
|
137 | - */ |
|
138 | - protected function getUserId($user_id_field_name, $user_id_value) { |
|
139 | - if($user_id_field_name == "chamilo_user_id") { |
|
140 | - if(UserManager::is_user_id_valid(intval($user_id_value))) { |
|
141 | - return intval($user_id_value); |
|
142 | - } else { |
|
143 | - return new WSError(100, "User not found"); |
|
144 | - } |
|
145 | - } else { |
|
146 | - $user_id = UserManager::get_user_id_from_original_id($user_id_value, $user_id_field_name); |
|
147 | - if($user_id == 0) { |
|
148 | - return new WSError(100, "User not found"); |
|
149 | - } else { |
|
150 | - return $user_id; |
|
151 | - } |
|
152 | - } |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * Gets the real course id based on the course id field name and value. |
|
157 | - * Note that if the course id field name is "chamilo_course_id", it will use the course id |
|
158 | - * in the system database |
|
159 | - * |
|
160 | - * @param string Course id field name |
|
161 | - * @param string Course id value |
|
162 | - * @return mixed System course id if the course was found, WSError otherwise |
|
163 | - */ |
|
164 | - protected function getCourseId($course_id_field_name, $course_id_value) |
|
165 | - { |
|
166 | - if ($course_id_field_name == "chamilo_course_id") { |
|
167 | - if (CourseManager::get_course_code_from_course_id( |
|
168 | - intval($course_id_value) |
|
169 | - ) != null |
|
170 | - ) { |
|
171 | - return intval($course_id_value); |
|
172 | - } else { |
|
173 | - return new WSError(200, "Course not found"); |
|
174 | - } |
|
175 | - } else { |
|
176 | - $courseId = CourseManager::get_course_code_from_original_id( |
|
177 | - $course_id_value, |
|
178 | - $course_id_field_name |
|
179 | - ); |
|
180 | - if (!empty($courseId)) { |
|
181 | - return $courseId; |
|
182 | - } else { |
|
183 | - return new WSError(200, "Course not found"); |
|
184 | - } |
|
185 | - } |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * Gets the real session id based on the session id field name and value. |
|
190 | - * Note that if the session id field name is "chamilo_session_id", it will use the session id |
|
191 | - * in the system database |
|
192 | - * |
|
193 | - * @param string Session id field name |
|
194 | - * @param string Session id value |
|
195 | - * @return mixed System session id if the session was found, WSError otherwise |
|
196 | - */ |
|
197 | - protected function getSessionId($session_id_field_name, $session_id_value) |
|
198 | - { |
|
199 | - if ($session_id_field_name == "chamilo_session_id") { |
|
200 | - $session = SessionManager::fetch((int)$session_id_value); |
|
201 | - if (!empty($session)) { |
|
202 | - return intval($session_id_value); |
|
203 | - } else { |
|
204 | - return new WSError(300, "Session not found"); |
|
205 | - } |
|
206 | - } else { |
|
207 | - $session_id = SessionManager::getSessionIdFromOriginalId( |
|
208 | - $session_id_value, |
|
209 | - $session_id_field_name |
|
210 | - ); |
|
211 | - if ($session_id == 0) { |
|
212 | - return new WSError(300, "Session not found"); |
|
213 | - } else { |
|
214 | - return $session_id; |
|
215 | - } |
|
216 | - } |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * Handles an error by calling the WSError error handler |
|
221 | - * |
|
222 | - * @param WSError Error |
|
223 | - */ |
|
224 | - protected function handleError($error) { |
|
225 | - $handler = WSError::getErrorHandler(); |
|
226 | - $handler->handle($error); |
|
227 | - } |
|
228 | - |
|
229 | - /** |
|
230 | - * Gets a successful result |
|
231 | - * |
|
232 | - * @return array Array with a code of 0 and a message 'Operation was successful' |
|
233 | - */ |
|
234 | - protected function getSuccessfulResult() { |
|
235 | - return array('code' => 0, 'message' => 'Operation was successful'); |
|
236 | - } |
|
237 | - |
|
238 | - /** |
|
239 | - * Test function. Returns the string success |
|
240 | - * |
|
241 | - * @return string Success |
|
242 | - */ |
|
243 | - public function test() { |
|
244 | - return "success"; |
|
245 | - } |
|
92 | + /** |
|
93 | + * Chamilo configuration |
|
94 | + * |
|
95 | + * @var array |
|
96 | + */ |
|
97 | + protected $_configuration; |
|
98 | + |
|
99 | + /** |
|
100 | + * Constructor |
|
101 | + */ |
|
102 | + public function __construct() { |
|
103 | + $this->_configuration = $GLOBALS['_configuration']; |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * Verifies the API key |
|
108 | + * |
|
109 | + * @param string Secret key |
|
110 | + * @return mixed WSError in case of failure, null in case of success |
|
111 | + */ |
|
112 | + protected function verifyKey($secret_key) { |
|
113 | + $ip = trim($_SERVER['REMOTE_ADDR']); |
|
114 | + // if we are behind a reverse proxy, assume it will send the |
|
115 | + // HTTP_X_FORWARDED_FOR header and use this IP instead |
|
116 | + if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { |
|
117 | + list($ip1,$ip2) = preg_split('/,/',$_SERVER['HTTP_X_FORWARDED_FOR']); |
|
118 | + $ip = trim($ip1); |
|
119 | + } |
|
120 | + $security_key = $ip.$this->_configuration['security_key']; |
|
121 | + |
|
122 | + if(!api_is_valid_secret_key($secret_key, $security_key)) { |
|
123 | + return new WSError(1, "API key is invalid"); |
|
124 | + } else { |
|
125 | + return null; |
|
126 | + } |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * Gets the real user id based on the user id field name and value. |
|
131 | + * Note that if the user id field name is "chamilo_user_id", it will use the user id |
|
132 | + * in the system database |
|
133 | + * |
|
134 | + * @param string User id field name |
|
135 | + * @param string User id value |
|
136 | + * @return mixed System user id if the user was found, WSError otherwise |
|
137 | + */ |
|
138 | + protected function getUserId($user_id_field_name, $user_id_value) { |
|
139 | + if($user_id_field_name == "chamilo_user_id") { |
|
140 | + if(UserManager::is_user_id_valid(intval($user_id_value))) { |
|
141 | + return intval($user_id_value); |
|
142 | + } else { |
|
143 | + return new WSError(100, "User not found"); |
|
144 | + } |
|
145 | + } else { |
|
146 | + $user_id = UserManager::get_user_id_from_original_id($user_id_value, $user_id_field_name); |
|
147 | + if($user_id == 0) { |
|
148 | + return new WSError(100, "User not found"); |
|
149 | + } else { |
|
150 | + return $user_id; |
|
151 | + } |
|
152 | + } |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * Gets the real course id based on the course id field name and value. |
|
157 | + * Note that if the course id field name is "chamilo_course_id", it will use the course id |
|
158 | + * in the system database |
|
159 | + * |
|
160 | + * @param string Course id field name |
|
161 | + * @param string Course id value |
|
162 | + * @return mixed System course id if the course was found, WSError otherwise |
|
163 | + */ |
|
164 | + protected function getCourseId($course_id_field_name, $course_id_value) |
|
165 | + { |
|
166 | + if ($course_id_field_name == "chamilo_course_id") { |
|
167 | + if (CourseManager::get_course_code_from_course_id( |
|
168 | + intval($course_id_value) |
|
169 | + ) != null |
|
170 | + ) { |
|
171 | + return intval($course_id_value); |
|
172 | + } else { |
|
173 | + return new WSError(200, "Course not found"); |
|
174 | + } |
|
175 | + } else { |
|
176 | + $courseId = CourseManager::get_course_code_from_original_id( |
|
177 | + $course_id_value, |
|
178 | + $course_id_field_name |
|
179 | + ); |
|
180 | + if (!empty($courseId)) { |
|
181 | + return $courseId; |
|
182 | + } else { |
|
183 | + return new WSError(200, "Course not found"); |
|
184 | + } |
|
185 | + } |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * Gets the real session id based on the session id field name and value. |
|
190 | + * Note that if the session id field name is "chamilo_session_id", it will use the session id |
|
191 | + * in the system database |
|
192 | + * |
|
193 | + * @param string Session id field name |
|
194 | + * @param string Session id value |
|
195 | + * @return mixed System session id if the session was found, WSError otherwise |
|
196 | + */ |
|
197 | + protected function getSessionId($session_id_field_name, $session_id_value) |
|
198 | + { |
|
199 | + if ($session_id_field_name == "chamilo_session_id") { |
|
200 | + $session = SessionManager::fetch((int)$session_id_value); |
|
201 | + if (!empty($session)) { |
|
202 | + return intval($session_id_value); |
|
203 | + } else { |
|
204 | + return new WSError(300, "Session not found"); |
|
205 | + } |
|
206 | + } else { |
|
207 | + $session_id = SessionManager::getSessionIdFromOriginalId( |
|
208 | + $session_id_value, |
|
209 | + $session_id_field_name |
|
210 | + ); |
|
211 | + if ($session_id == 0) { |
|
212 | + return new WSError(300, "Session not found"); |
|
213 | + } else { |
|
214 | + return $session_id; |
|
215 | + } |
|
216 | + } |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * Handles an error by calling the WSError error handler |
|
221 | + * |
|
222 | + * @param WSError Error |
|
223 | + */ |
|
224 | + protected function handleError($error) { |
|
225 | + $handler = WSError::getErrorHandler(); |
|
226 | + $handler->handle($error); |
|
227 | + } |
|
228 | + |
|
229 | + /** |
|
230 | + * Gets a successful result |
|
231 | + * |
|
232 | + * @return array Array with a code of 0 and a message 'Operation was successful' |
|
233 | + */ |
|
234 | + protected function getSuccessfulResult() { |
|
235 | + return array('code' => 0, 'message' => 'Operation was successful'); |
|
236 | + } |
|
237 | + |
|
238 | + /** |
|
239 | + * Test function. Returns the string success |
|
240 | + * |
|
241 | + * @return string Success |
|
242 | + */ |
|
243 | + public function test() { |
|
244 | + return "success"; |
|
245 | + } |
|
246 | 246 | } |
247 | 247 |
@@ -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) { |
@@ -14,177 +14,177 @@ discard block |
||
14 | 14 | class WSSession extends WS |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * Creates a session (helper method) |
|
19 | - * |
|
20 | - * @param string Name of the session |
|
21 | - * @param string Start date, use the 'YYYY-MM-DD' format |
|
22 | - * @param string End date, use the 'YYYY-MM-DD' format |
|
23 | - * @param int Access delays of the coach (days before) |
|
24 | - * @param int Access delays of the coach (days after) |
|
25 | - * @param int Nolimit (0 = no limit of time, 1 = limit of time) |
|
26 | - * @param int Visibility |
|
27 | - * @param string User id field name for the coach |
|
28 | - * @param string User id value for the coach |
|
29 | - * @param string Original session id field name (use "chamilo_session_id" to use internal id) |
|
30 | - * @param string Original session id value |
|
31 | - * @param array Array of extra fields |
|
32 | - * @return mixed Generated id in case of success, WSError otherwise |
|
33 | - */ |
|
34 | - protected function createSessionHelper( |
|
35 | - $name, |
|
36 | - $start_date, |
|
37 | - $end_date, |
|
38 | - $nb_days_access_before, |
|
39 | - $nb_days_access_after, |
|
40 | - $nolimit, |
|
41 | - $visibility, |
|
42 | - $user_id_field_name, |
|
43 | - $user_id_value, |
|
44 | - $session_id_field_name, |
|
45 | - $session_id_value, |
|
46 | - $extras |
|
47 | - ) { |
|
48 | - // Verify that coach exists and get its id |
|
49 | - $user_id = $this->getUserId($user_id_field_name, $user_id_value); |
|
50 | - if ($user_id instanceof WSError) { |
|
51 | - return $user_id; |
|
52 | - } |
|
17 | + /** |
|
18 | + * Creates a session (helper method) |
|
19 | + * |
|
20 | + * @param string Name of the session |
|
21 | + * @param string Start date, use the 'YYYY-MM-DD' format |
|
22 | + * @param string End date, use the 'YYYY-MM-DD' format |
|
23 | + * @param int Access delays of the coach (days before) |
|
24 | + * @param int Access delays of the coach (days after) |
|
25 | + * @param int Nolimit (0 = no limit of time, 1 = limit of time) |
|
26 | + * @param int Visibility |
|
27 | + * @param string User id field name for the coach |
|
28 | + * @param string User id value for the coach |
|
29 | + * @param string Original session id field name (use "chamilo_session_id" to use internal id) |
|
30 | + * @param string Original session id value |
|
31 | + * @param array Array of extra fields |
|
32 | + * @return mixed Generated id in case of success, WSError otherwise |
|
33 | + */ |
|
34 | + protected function createSessionHelper( |
|
35 | + $name, |
|
36 | + $start_date, |
|
37 | + $end_date, |
|
38 | + $nb_days_access_before, |
|
39 | + $nb_days_access_after, |
|
40 | + $nolimit, |
|
41 | + $visibility, |
|
42 | + $user_id_field_name, |
|
43 | + $user_id_value, |
|
44 | + $session_id_field_name, |
|
45 | + $session_id_value, |
|
46 | + $extras |
|
47 | + ) { |
|
48 | + // Verify that coach exists and get its id |
|
49 | + $user_id = $this->getUserId($user_id_field_name, $user_id_value); |
|
50 | + if ($user_id instanceof WSError) { |
|
51 | + return $user_id; |
|
52 | + } |
|
53 | 53 | |
54 | - $coachStartDate = null; |
|
55 | - if (!empty($nb_days_access_before)) { |
|
56 | - $day = intval($nb_days_access_before); |
|
57 | - $coachStartDate = date('Y-m-d ', strtotime($start_date. ' + '.$day.' days')); |
|
58 | - } |
|
54 | + $coachStartDate = null; |
|
55 | + if (!empty($nb_days_access_before)) { |
|
56 | + $day = intval($nb_days_access_before); |
|
57 | + $coachStartDate = date('Y-m-d ', strtotime($start_date. ' + '.$day.' days')); |
|
58 | + } |
|
59 | 59 | |
60 | - $coachEndDate = null; |
|
61 | - if (!empty($nb_days_access_after)) { |
|
62 | - $day = intval($nb_days_access_after); |
|
63 | - $coachEndDate = date('Y-m-d ', strtotime($end_date. ' + '.$day.' days')); |
|
64 | - } |
|
60 | + $coachEndDate = null; |
|
61 | + if (!empty($nb_days_access_after)) { |
|
62 | + $day = intval($nb_days_access_after); |
|
63 | + $coachEndDate = date('Y-m-d ', strtotime($end_date. ' + '.$day.' days')); |
|
64 | + } |
|
65 | 65 | |
66 | - // Try to create the session |
|
67 | - $session_id = SessionManager::create_session( |
|
68 | - $name, |
|
69 | - $start_date, |
|
70 | - $end_date, |
|
71 | - $start_date, |
|
72 | - $end_date, |
|
73 | - $coachStartDate, |
|
74 | - $coachEndDate, |
|
75 | - $user_id, |
|
76 | - 0, |
|
77 | - $visibility |
|
78 | - ); |
|
79 | - if(!is_int($session_id)) { |
|
80 | - return new WSError(301, 'Could not create the session'); |
|
81 | - } else { |
|
82 | - // Add the Original session id to the extra fields |
|
83 | - $extras_associative = array(); |
|
84 | - if($session_id_field_name != "chamilo_session_id") { |
|
85 | - $extras_associative[$session_id_field_name] = $session_id_value; |
|
86 | - } |
|
87 | - foreach($extras as $extra) { |
|
88 | - $extras_associative[$extra['field_name']] = $extra['field_value']; |
|
89 | - } |
|
90 | - // Create the extra fields |
|
91 | - foreach($extras_associative as $fname => $fvalue) { |
|
92 | - SessionManager::create_session_extra_field($fname, 1, $fname); |
|
93 | - SessionManager::update_session_extra_field_value( |
|
94 | - $session_id, |
|
95 | - $fname, |
|
96 | - $fvalue |
|
97 | - ); |
|
98 | - } |
|
99 | - return $session_id; |
|
100 | - } |
|
101 | - } |
|
66 | + // Try to create the session |
|
67 | + $session_id = SessionManager::create_session( |
|
68 | + $name, |
|
69 | + $start_date, |
|
70 | + $end_date, |
|
71 | + $start_date, |
|
72 | + $end_date, |
|
73 | + $coachStartDate, |
|
74 | + $coachEndDate, |
|
75 | + $user_id, |
|
76 | + 0, |
|
77 | + $visibility |
|
78 | + ); |
|
79 | + if(!is_int($session_id)) { |
|
80 | + return new WSError(301, 'Could not create the session'); |
|
81 | + } else { |
|
82 | + // Add the Original session id to the extra fields |
|
83 | + $extras_associative = array(); |
|
84 | + if($session_id_field_name != "chamilo_session_id") { |
|
85 | + $extras_associative[$session_id_field_name] = $session_id_value; |
|
86 | + } |
|
87 | + foreach($extras as $extra) { |
|
88 | + $extras_associative[$extra['field_name']] = $extra['field_value']; |
|
89 | + } |
|
90 | + // Create the extra fields |
|
91 | + foreach($extras_associative as $fname => $fvalue) { |
|
92 | + SessionManager::create_session_extra_field($fname, 1, $fname); |
|
93 | + SessionManager::update_session_extra_field_value( |
|
94 | + $session_id, |
|
95 | + $fname, |
|
96 | + $fvalue |
|
97 | + ); |
|
98 | + } |
|
99 | + return $session_id; |
|
100 | + } |
|
101 | + } |
|
102 | 102 | |
103 | - /** |
|
104 | - * Creates a session |
|
105 | - * |
|
106 | - * @param string API secret key |
|
107 | - * @param string Name of the session |
|
108 | - * @param string Start date, use the 'YYYY-MM-DD' format |
|
109 | - * @param string End date, use the 'YYYY-MM-DD' format |
|
110 | - * @param int Access delays of the coach (days before) |
|
111 | - * @param int Access delays of the coach (days after) |
|
112 | - * @param int Nolimit (0 = no limit of time, 1 = limit of time) |
|
113 | - * @param int Visibility |
|
114 | - * @param string User id field name for the coach |
|
115 | - * @param string User id value for the coach |
|
116 | - * @param string Original session id field name (use "chamilo_session_id" to use internal id) |
|
117 | - * @param string Original session id value |
|
118 | - * @param array Array of extra fields |
|
119 | - * @return int Session id generated |
|
120 | - */ |
|
121 | - public function CreateSession($secret_key, $name, $start_date, $end_date, $nb_days_access_before, $nb_days_access_after, $nolimit, $visibility, $user_id_field_name, $user_id_value, $session_id_field_name, $session_id_value, $extras) { |
|
122 | - $verifKey = $this->verifyKey($secret_key); |
|
123 | - if($verifKey instanceof WSError) { |
|
124 | - $this->handleError($verifKey); |
|
125 | - } else { |
|
126 | - $session_id = $this->createSessionHelper($name, $start_date, $end_date, $nb_days_access_before, $nb_days_access_after, $nolimit, $visibility, $user_id_field_name, $user_id_value, $session_id_field_name, $session_id_value, $extras); |
|
127 | - if($session_id instanceof WSError) { |
|
128 | - $this->handleError($session_id); |
|
129 | - } else { |
|
130 | - return $session_id; |
|
131 | - } |
|
132 | - } |
|
133 | - } |
|
103 | + /** |
|
104 | + * Creates a session |
|
105 | + * |
|
106 | + * @param string API secret key |
|
107 | + * @param string Name of the session |
|
108 | + * @param string Start date, use the 'YYYY-MM-DD' format |
|
109 | + * @param string End date, use the 'YYYY-MM-DD' format |
|
110 | + * @param int Access delays of the coach (days before) |
|
111 | + * @param int Access delays of the coach (days after) |
|
112 | + * @param int Nolimit (0 = no limit of time, 1 = limit of time) |
|
113 | + * @param int Visibility |
|
114 | + * @param string User id field name for the coach |
|
115 | + * @param string User id value for the coach |
|
116 | + * @param string Original session id field name (use "chamilo_session_id" to use internal id) |
|
117 | + * @param string Original session id value |
|
118 | + * @param array Array of extra fields |
|
119 | + * @return int Session id generated |
|
120 | + */ |
|
121 | + public function CreateSession($secret_key, $name, $start_date, $end_date, $nb_days_access_before, $nb_days_access_after, $nolimit, $visibility, $user_id_field_name, $user_id_value, $session_id_field_name, $session_id_value, $extras) { |
|
122 | + $verifKey = $this->verifyKey($secret_key); |
|
123 | + if($verifKey instanceof WSError) { |
|
124 | + $this->handleError($verifKey); |
|
125 | + } else { |
|
126 | + $session_id = $this->createSessionHelper($name, $start_date, $end_date, $nb_days_access_before, $nb_days_access_after, $nolimit, $visibility, $user_id_field_name, $user_id_value, $session_id_field_name, $session_id_value, $extras); |
|
127 | + if($session_id instanceof WSError) { |
|
128 | + $this->handleError($session_id); |
|
129 | + } else { |
|
130 | + return $session_id; |
|
131 | + } |
|
132 | + } |
|
133 | + } |
|
134 | 134 | |
135 | - /** |
|
136 | - * Deletes a session (helper method) |
|
137 | - * |
|
138 | - * @param string Session id field name |
|
139 | - * @param string Session id value |
|
140 | - * @return mixed True in case of success, WSError otherwise |
|
141 | - */ |
|
142 | - protected function deleteSessionHelper($session_id_field_name, $session_id_value) { |
|
143 | - $session_id = $this->getSessionId($session_id_field_name, $session_id_value); |
|
144 | - if($session_id instanceof WSError) { |
|
145 | - return $session_id; |
|
146 | - } else { |
|
147 | - SessionManager::delete($session_id, true); |
|
148 | - return true; |
|
149 | - } |
|
150 | - } |
|
135 | + /** |
|
136 | + * Deletes a session (helper method) |
|
137 | + * |
|
138 | + * @param string Session id field name |
|
139 | + * @param string Session id value |
|
140 | + * @return mixed True in case of success, WSError otherwise |
|
141 | + */ |
|
142 | + protected function deleteSessionHelper($session_id_field_name, $session_id_value) { |
|
143 | + $session_id = $this->getSessionId($session_id_field_name, $session_id_value); |
|
144 | + if($session_id instanceof WSError) { |
|
145 | + return $session_id; |
|
146 | + } else { |
|
147 | + SessionManager::delete($session_id, true); |
|
148 | + return true; |
|
149 | + } |
|
150 | + } |
|
151 | 151 | |
152 | - /** |
|
153 | - * Deletes a session |
|
154 | - * |
|
155 | - * @param string API secret key |
|
156 | - * @param string Session id field name |
|
157 | - * @param string Session id value |
|
158 | - */ |
|
159 | - public function DeleteSession($secret_key, $session_id_field_name, $session_id_value) { |
|
160 | - $verifKey = $this->verifyKey($secret_key); |
|
161 | - if($verifKey instanceof WSError) { |
|
162 | - $this->handleError($verifKey); |
|
163 | - } else { |
|
164 | - $result = $this->deleteSessionHelper($session_id_field_name, $session_id_value); |
|
165 | - if($result instanceof WSError) { |
|
166 | - $this->handleError($result); |
|
167 | - } |
|
168 | - } |
|
169 | - } |
|
152 | + /** |
|
153 | + * Deletes a session |
|
154 | + * |
|
155 | + * @param string API secret key |
|
156 | + * @param string Session id field name |
|
157 | + * @param string Session id value |
|
158 | + */ |
|
159 | + public function DeleteSession($secret_key, $session_id_field_name, $session_id_value) { |
|
160 | + $verifKey = $this->verifyKey($secret_key); |
|
161 | + if($verifKey instanceof WSError) { |
|
162 | + $this->handleError($verifKey); |
|
163 | + } else { |
|
164 | + $result = $this->deleteSessionHelper($session_id_field_name, $session_id_value); |
|
165 | + if($result instanceof WSError) { |
|
166 | + $this->handleError($result); |
|
167 | + } |
|
168 | + } |
|
169 | + } |
|
170 | 170 | |
171 | - /** |
|
172 | - * Edits a session (helper method) |
|
173 | - * |
|
174 | - * @param string Name of the session |
|
175 | - * @param string Start date, use the 'YYYY-MM-DD' format |
|
176 | - * @param string End date, use the 'YYYY-MM-DD' format |
|
177 | - * @param int Access delays of the coach (days before) |
|
178 | - * @param int Access delays of the coach (days after) |
|
179 | - * @param int Nolimit (0 = no limit of time, 1 = limit of time) |
|
180 | - * @param int Visibility |
|
181 | - * @param string User id field name for the coach |
|
182 | - * @param string User id value for the coach |
|
183 | - * @param string Original session id field name (use "chamilo_session_id" to use internal id) |
|
184 | - * @param string Original session id value |
|
185 | - * @param array Array of extra fields |
|
186 | - * @return mixed True on success, WSError otherwise |
|
187 | - */ |
|
171 | + /** |
|
172 | + * Edits a session (helper method) |
|
173 | + * |
|
174 | + * @param string Name of the session |
|
175 | + * @param string Start date, use the 'YYYY-MM-DD' format |
|
176 | + * @param string End date, use the 'YYYY-MM-DD' format |
|
177 | + * @param int Access delays of the coach (days before) |
|
178 | + * @param int Access delays of the coach (days after) |
|
179 | + * @param int Nolimit (0 = no limit of time, 1 = limit of time) |
|
180 | + * @param int Visibility |
|
181 | + * @param string User id field name for the coach |
|
182 | + * @param string User id value for the coach |
|
183 | + * @param string Original session id field name (use "chamilo_session_id" to use internal id) |
|
184 | + * @param string Original session id value |
|
185 | + * @param array Array of extra fields |
|
186 | + * @return mixed True on success, WSError otherwise |
|
187 | + */ |
|
188 | 188 | protected function editSessionHelper( |
189 | 189 | $name, |
190 | 190 | $start_date, |
@@ -199,15 +199,15 @@ discard block |
||
199 | 199 | $session_id_value, |
200 | 200 | $extras |
201 | 201 | ) { |
202 | - $session_id = $this->getSessionId($session_id_field_name, $session_id_value); |
|
203 | - if($session_id instanceof WSError) { |
|
204 | - return $session_id; |
|
205 | - } else { |
|
206 | - // Verify that coach exists and get its id |
|
207 | - $user_id = $this->getUserId($user_id_field_name, $user_id_value); |
|
208 | - if ($user_id instanceof WSError) { |
|
209 | - return $user_id; |
|
210 | - } |
|
202 | + $session_id = $this->getSessionId($session_id_field_name, $session_id_value); |
|
203 | + if($session_id instanceof WSError) { |
|
204 | + return $session_id; |
|
205 | + } else { |
|
206 | + // Verify that coach exists and get its id |
|
207 | + $user_id = $this->getUserId($user_id_field_name, $user_id_value); |
|
208 | + if ($user_id instanceof WSError) { |
|
209 | + return $user_id; |
|
210 | + } |
|
211 | 211 | |
212 | 212 | $coachStartDate = null; |
213 | 213 | if (!empty($nb_days_access_before)) { |
@@ -234,127 +234,127 @@ discard block |
||
234 | 234 | 0, |
235 | 235 | (int)$visibility |
236 | 236 | ); |
237 | - if(!is_int($result_id)) { |
|
238 | - return new WSError(302, 'Could not edit the session'); |
|
239 | - } else { |
|
240 | - if(!empty($extras)) { |
|
241 | - $extras_associative = array(); |
|
242 | - foreach($extras as $extra) { |
|
243 | - $extras_associative[$extra['field_name']] = $extra['field_value']; |
|
244 | - } |
|
245 | - // Create the extra fields |
|
246 | - foreach($extras_associative as $fname => $fvalue) { |
|
247 | - SessionManager::create_session_extra_field($fname, 1, $fname); |
|
248 | - SessionManager::update_session_extra_field_value($session_id, $fname, $fvalue); |
|
249 | - } |
|
250 | - } |
|
251 | - return true; |
|
252 | - } |
|
253 | - } |
|
254 | - } |
|
237 | + if(!is_int($result_id)) { |
|
238 | + return new WSError(302, 'Could not edit the session'); |
|
239 | + } else { |
|
240 | + if(!empty($extras)) { |
|
241 | + $extras_associative = array(); |
|
242 | + foreach($extras as $extra) { |
|
243 | + $extras_associative[$extra['field_name']] = $extra['field_value']; |
|
244 | + } |
|
245 | + // Create the extra fields |
|
246 | + foreach($extras_associative as $fname => $fvalue) { |
|
247 | + SessionManager::create_session_extra_field($fname, 1, $fname); |
|
248 | + SessionManager::update_session_extra_field_value($session_id, $fname, $fvalue); |
|
249 | + } |
|
250 | + } |
|
251 | + return true; |
|
252 | + } |
|
253 | + } |
|
254 | + } |
|
255 | 255 | |
256 | - /** |
|
257 | - * Edits a session |
|
258 | - * |
|
259 | - * @param string API secret key |
|
260 | - * @param string Name of the session |
|
261 | - * @param string Start date, use the 'YYYY-MM-DD' format |
|
262 | - * @param string End date, use the 'YYYY-MM-DD' format |
|
263 | - * @param int Access delays of the coach (days before) |
|
264 | - * @param int Access delays of the coach (days after) |
|
265 | - * @param int Nolimit (0 = no limit of time, 1 = limit of time) |
|
266 | - * @param int Visibility |
|
267 | - * @param string User id field name for the coach |
|
268 | - * @param string User id value for the coach |
|
269 | - * @param string Original session id field name (use "chamilo_session_id" to use internal id) |
|
270 | - * @param string Original session id value |
|
271 | - * @param array Array of extra fields |
|
272 | - */ |
|
273 | - public function EditSession($secret_key, $name, $start_date, $end_date, $nb_days_access_before, $nb_days_access_after, $nolimit, $visibility, $user_id_field_name, $user_id_value, $session_id_field_name, $session_id_value, $extras) { |
|
274 | - $verifKey = $this->verifyKey($secret_key); |
|
275 | - if($verifKey instanceof WSError) { |
|
276 | - $this->handleError($verifKey); |
|
277 | - } else { |
|
278 | - $result = $this->editSessionHelper($name, $start_date, $end_date, $nb_days_access_before, $nb_days_access_after, $nolimit, $visibility, $user_id_field_name, $user_id_value, $session_id_field_name, $session_id_value, $extras); |
|
279 | - if($session_id_value instanceof WSError) { |
|
280 | - $this->handleError($result); |
|
281 | - } |
|
282 | - } |
|
283 | - } |
|
256 | + /** |
|
257 | + * Edits a session |
|
258 | + * |
|
259 | + * @param string API secret key |
|
260 | + * @param string Name of the session |
|
261 | + * @param string Start date, use the 'YYYY-MM-DD' format |
|
262 | + * @param string End date, use the 'YYYY-MM-DD' format |
|
263 | + * @param int Access delays of the coach (days before) |
|
264 | + * @param int Access delays of the coach (days after) |
|
265 | + * @param int Nolimit (0 = no limit of time, 1 = limit of time) |
|
266 | + * @param int Visibility |
|
267 | + * @param string User id field name for the coach |
|
268 | + * @param string User id value for the coach |
|
269 | + * @param string Original session id field name (use "chamilo_session_id" to use internal id) |
|
270 | + * @param string Original session id value |
|
271 | + * @param array Array of extra fields |
|
272 | + */ |
|
273 | + public function EditSession($secret_key, $name, $start_date, $end_date, $nb_days_access_before, $nb_days_access_after, $nolimit, $visibility, $user_id_field_name, $user_id_value, $session_id_field_name, $session_id_value, $extras) { |
|
274 | + $verifKey = $this->verifyKey($secret_key); |
|
275 | + if($verifKey instanceof WSError) { |
|
276 | + $this->handleError($verifKey); |
|
277 | + } else { |
|
278 | + $result = $this->editSessionHelper($name, $start_date, $end_date, $nb_days_access_before, $nb_days_access_after, $nolimit, $visibility, $user_id_field_name, $user_id_value, $session_id_field_name, $session_id_value, $extras); |
|
279 | + if($session_id_value instanceof WSError) { |
|
280 | + $this->handleError($result); |
|
281 | + } |
|
282 | + } |
|
283 | + } |
|
284 | 284 | |
285 | - /** |
|
286 | - * Change user subscription (helper method) |
|
287 | - * |
|
288 | - * @param string User id field name |
|
289 | - * @param string User id value |
|
290 | - * @param string Session id field name |
|
291 | - * @param string Session id value |
|
292 | - * @param int State (1 to subscribe, 0 to unsubscribe) |
|
293 | - * @return mixed True on success, WSError otherwise |
|
294 | - */ |
|
295 | - protected function changeUserSubscription($user_id_field_name, $user_id_value, $session_id_field_name, $session_id_value, $state) { |
|
296 | - $session_id = $this->getSessionId($session_id_field_name, $session_id_value); |
|
297 | - if($session_id instanceof WSError) { |
|
298 | - return $session_id; |
|
299 | - } else { |
|
300 | - $user_id = $this->getUserId($user_id_field_name, $user_id_value); |
|
301 | - if($user_id instanceof WSError) { |
|
302 | - return $user_id; |
|
303 | - } else { |
|
304 | - if($state == 1) { |
|
305 | - SessionManager::subscribe_users_to_session($session_id, array($user_id)); |
|
306 | - } else { |
|
307 | - $result = SessionManager::unsubscribe_user_from_session($session_id, $user_id); |
|
308 | - if (!$result) { |
|
309 | - return new WSError(303, 'There was an error unsubscribing this user from the session'); |
|
310 | - } |
|
311 | - } |
|
312 | - return true; |
|
313 | - } |
|
314 | - } |
|
315 | - } |
|
285 | + /** |
|
286 | + * Change user subscription (helper method) |
|
287 | + * |
|
288 | + * @param string User id field name |
|
289 | + * @param string User id value |
|
290 | + * @param string Session id field name |
|
291 | + * @param string Session id value |
|
292 | + * @param int State (1 to subscribe, 0 to unsubscribe) |
|
293 | + * @return mixed True on success, WSError otherwise |
|
294 | + */ |
|
295 | + protected function changeUserSubscription($user_id_field_name, $user_id_value, $session_id_field_name, $session_id_value, $state) { |
|
296 | + $session_id = $this->getSessionId($session_id_field_name, $session_id_value); |
|
297 | + if($session_id instanceof WSError) { |
|
298 | + return $session_id; |
|
299 | + } else { |
|
300 | + $user_id = $this->getUserId($user_id_field_name, $user_id_value); |
|
301 | + if($user_id instanceof WSError) { |
|
302 | + return $user_id; |
|
303 | + } else { |
|
304 | + if($state == 1) { |
|
305 | + SessionManager::subscribe_users_to_session($session_id, array($user_id)); |
|
306 | + } else { |
|
307 | + $result = SessionManager::unsubscribe_user_from_session($session_id, $user_id); |
|
308 | + if (!$result) { |
|
309 | + return new WSError(303, 'There was an error unsubscribing this user from the session'); |
|
310 | + } |
|
311 | + } |
|
312 | + return true; |
|
313 | + } |
|
314 | + } |
|
315 | + } |
|
316 | 316 | |
317 | - /** |
|
318 | - * Subscribe user to a session |
|
319 | - * |
|
320 | - * @param string API secret key |
|
321 | - * @param string User id field name |
|
322 | - * @param string User id value |
|
323 | - * @param string Session id field name |
|
324 | - * @param string Session id value |
|
325 | - */ |
|
326 | - public function SubscribeUserToSession($secret_key, $user_id_field_name, $user_id_value, $session_id_field_name, $session_id_value) { |
|
327 | - $verifKey = $this->verifyKey($secret_key); |
|
328 | - if($verifKey instanceof WSError) { |
|
329 | - $this->handleError($verifKey); |
|
330 | - } else { |
|
331 | - $result = $this->changeUserSubscription($user_id_field_name, $user_id_value, $session_id_field_name, $session_id_value, 1); |
|
332 | - if($result instanceof WSError) { |
|
333 | - $this->handleError($result); |
|
334 | - } |
|
335 | - } |
|
336 | - } |
|
317 | + /** |
|
318 | + * Subscribe user to a session |
|
319 | + * |
|
320 | + * @param string API secret key |
|
321 | + * @param string User id field name |
|
322 | + * @param string User id value |
|
323 | + * @param string Session id field name |
|
324 | + * @param string Session id value |
|
325 | + */ |
|
326 | + public function SubscribeUserToSession($secret_key, $user_id_field_name, $user_id_value, $session_id_field_name, $session_id_value) { |
|
327 | + $verifKey = $this->verifyKey($secret_key); |
|
328 | + if($verifKey instanceof WSError) { |
|
329 | + $this->handleError($verifKey); |
|
330 | + } else { |
|
331 | + $result = $this->changeUserSubscription($user_id_field_name, $user_id_value, $session_id_field_name, $session_id_value, 1); |
|
332 | + if($result instanceof WSError) { |
|
333 | + $this->handleError($result); |
|
334 | + } |
|
335 | + } |
|
336 | + } |
|
337 | 337 | |
338 | - /** |
|
339 | - * Subscribe user to a session |
|
340 | - * |
|
341 | - * @param string API secret key |
|
342 | - * @param string User id field name |
|
343 | - * @param string User id value |
|
344 | - * @param string Session id field name |
|
345 | - * @param string Session id value |
|
346 | - */ |
|
347 | - public function UnsubscribeUserFromSession($secret_key, $user_id_field_name, $user_id_value, $session_id_field_name, $session_id_value) { |
|
348 | - $verifKey = $this->verifyKey($secret_key); |
|
349 | - if($verifKey instanceof WSError) { |
|
350 | - $this->handleError($verifKey); |
|
351 | - } else { |
|
352 | - $result = $this->changeUserSubscription($user_id_field_name, $user_id_value, $session_id_field_name, $session_id_value, 0); |
|
353 | - if($result instanceof WSError) { |
|
354 | - $this->handleError($result); |
|
355 | - } |
|
356 | - } |
|
357 | - } |
|
338 | + /** |
|
339 | + * Subscribe user to a session |
|
340 | + * |
|
341 | + * @param string API secret key |
|
342 | + * @param string User id field name |
|
343 | + * @param string User id value |
|
344 | + * @param string Session id field name |
|
345 | + * @param string Session id value |
|
346 | + */ |
|
347 | + public function UnsubscribeUserFromSession($secret_key, $user_id_field_name, $user_id_value, $session_id_field_name, $session_id_value) { |
|
348 | + $verifKey = $this->verifyKey($secret_key); |
|
349 | + if($verifKey instanceof WSError) { |
|
350 | + $this->handleError($verifKey); |
|
351 | + } else { |
|
352 | + $result = $this->changeUserSubscription($user_id_field_name, $user_id_value, $session_id_field_name, $session_id_value, 0); |
|
353 | + if($result instanceof WSError) { |
|
354 | + $this->handleError($result); |
|
355 | + } |
|
356 | + } |
|
357 | + } |
|
358 | 358 | |
359 | 359 | /** |
360 | 360 | * Change Teacher subscription (helper method) |
@@ -446,79 +446,79 @@ discard block |
||
446 | 446 | } |
447 | 447 | |
448 | 448 | /** |
449 | - * Change course subscription |
|
450 | - * |
|
451 | - * @param string Course id field name |
|
452 | - * @param string Course id value |
|
453 | - * @param string Session id field name |
|
454 | - * @param string Session id value |
|
455 | - * @param int State (1 to subscribe, 0 to unsubscribe) |
|
456 | - * @return mixed True on success, WSError otherwise |
|
457 | - */ |
|
458 | - protected function changeCourseSubscription($course_id_field_name, $course_id_value, $session_id_field_name, $session_id_value, $state) { |
|
459 | - $session_id = $this->getSessionId($session_id_field_name, $session_id_value); |
|
460 | - if($session_id instanceof WSError) { |
|
461 | - return $session_id; |
|
462 | - } else { |
|
463 | - $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
464 | - if($course_id instanceof WSError) { |
|
465 | - return $course_id; |
|
466 | - } else { |
|
467 | - if($state == 1) { |
|
468 | - SessionManager::add_courses_to_session($session_id, array($course_id)); |
|
469 | - return true; |
|
470 | - } else { |
|
471 | - $result = SessionManager::unsubscribe_course_from_session($session_id, $course_id); |
|
472 | - if ($result) { |
|
473 | - return true; |
|
474 | - } else { |
|
475 | - return new WSError(304, 'Error unsubscribing course from session'); |
|
476 | - } |
|
477 | - } |
|
478 | - } |
|
479 | - } |
|
449 | + * Change course subscription |
|
450 | + * |
|
451 | + * @param string Course id field name |
|
452 | + * @param string Course id value |
|
453 | + * @param string Session id field name |
|
454 | + * @param string Session id value |
|
455 | + * @param int State (1 to subscribe, 0 to unsubscribe) |
|
456 | + * @return mixed True on success, WSError otherwise |
|
457 | + */ |
|
458 | + protected function changeCourseSubscription($course_id_field_name, $course_id_value, $session_id_field_name, $session_id_value, $state) { |
|
459 | + $session_id = $this->getSessionId($session_id_field_name, $session_id_value); |
|
460 | + if($session_id instanceof WSError) { |
|
461 | + return $session_id; |
|
462 | + } else { |
|
463 | + $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
|
464 | + if($course_id instanceof WSError) { |
|
465 | + return $course_id; |
|
466 | + } else { |
|
467 | + if($state == 1) { |
|
468 | + SessionManager::add_courses_to_session($session_id, array($course_id)); |
|
469 | + return true; |
|
470 | + } else { |
|
471 | + $result = SessionManager::unsubscribe_course_from_session($session_id, $course_id); |
|
472 | + if ($result) { |
|
473 | + return true; |
|
474 | + } else { |
|
475 | + return new WSError(304, 'Error unsubscribing course from session'); |
|
476 | + } |
|
477 | + } |
|
478 | + } |
|
479 | + } |
|
480 | 480 | } |
481 | 481 | |
482 | - /** |
|
483 | - * Subscribe course to session |
|
484 | - * |
|
485 | - * @param string API secret key |
|
486 | - * @param string Course id field name |
|
487 | - * @param string Course id value |
|
488 | - * @param string Session id field name |
|
489 | - * @param string Session id value |
|
490 | - */ |
|
491 | - public function SubscribeCourseToSession($secret_key, $course_id_field_name, $course_id_value, $session_id_field_name, $session_id_value) { |
|
492 | - $verifKey = $this->verifyKey($secret_key); |
|
493 | - if($verifKey instanceof WSError) { |
|
494 | - $this->handleError($verifKey); |
|
495 | - } else { |
|
496 | - $result = $this->changeCourseSubscription($course_id_field_name, $course_id_value, $session_id_field_name, $session_id_value, 1); |
|
497 | - if($result instanceof WSError) { |
|
498 | - $this->handleError($result); |
|
499 | - } |
|
500 | - } |
|
501 | - } |
|
482 | + /** |
|
483 | + * Subscribe course to session |
|
484 | + * |
|
485 | + * @param string API secret key |
|
486 | + * @param string Course id field name |
|
487 | + * @param string Course id value |
|
488 | + * @param string Session id field name |
|
489 | + * @param string Session id value |
|
490 | + */ |
|
491 | + public function SubscribeCourseToSession($secret_key, $course_id_field_name, $course_id_value, $session_id_field_name, $session_id_value) { |
|
492 | + $verifKey = $this->verifyKey($secret_key); |
|
493 | + if($verifKey instanceof WSError) { |
|
494 | + $this->handleError($verifKey); |
|
495 | + } else { |
|
496 | + $result = $this->changeCourseSubscription($course_id_field_name, $course_id_value, $session_id_field_name, $session_id_value, 1); |
|
497 | + if($result instanceof WSError) { |
|
498 | + $this->handleError($result); |
|
499 | + } |
|
500 | + } |
|
501 | + } |
|
502 | 502 | |
503 | - /** |
|
504 | - * Unsubscribe course from session |
|
505 | - * |
|
506 | - * @param string API secret key |
|
507 | - * @param string Course id field name |
|
508 | - * @param string Course id value |
|
509 | - * @param string Session id field name |
|
510 | - * @param string Session id value |
|
511 | - */ |
|
512 | - public function UnsubscribeCourseFromSession($secret_key, $course_id_field_name, $course_id_value, $session_id_field_name, $session_id_value) { |
|
513 | - $verifKey = $this->verifyKey($secret_key); |
|
514 | - if($verifKey instanceof WSError) { |
|
515 | - $this->handleError($verifKey); |
|
516 | - } else { |
|
517 | - $result = $this->changeCourseSubscription($course_id_field_name, $course_id_value, $session_id_field_name, $session_id_value, 0); |
|
518 | - if($result instanceof WSError) { |
|
519 | - $this->handleError($result); |
|
520 | - } |
|
521 | - } |
|
522 | - } |
|
503 | + /** |
|
504 | + * Unsubscribe course from session |
|
505 | + * |
|
506 | + * @param string API secret key |
|
507 | + * @param string Course id field name |
|
508 | + * @param string Course id value |
|
509 | + * @param string Session id field name |
|
510 | + * @param string Session id value |
|
511 | + */ |
|
512 | + public function UnsubscribeCourseFromSession($secret_key, $course_id_field_name, $course_id_value, $session_id_field_name, $session_id_value) { |
|
513 | + $verifKey = $this->verifyKey($secret_key); |
|
514 | + if($verifKey instanceof WSError) { |
|
515 | + $this->handleError($verifKey); |
|
516 | + } else { |
|
517 | + $result = $this->changeCourseSubscription($course_id_field_name, $course_id_value, $session_id_field_name, $session_id_value, 0); |
|
518 | + if($result instanceof WSError) { |
|
519 | + $this->handleError($result); |
|
520 | + } |
|
521 | + } |
|
522 | + } |
|
523 | 523 | |
524 | 524 | } |
@@ -54,13 +54,13 @@ discard block |
||
54 | 54 | $coachStartDate = null; |
55 | 55 | if (!empty($nb_days_access_before)) { |
56 | 56 | $day = intval($nb_days_access_before); |
57 | - $coachStartDate = date('Y-m-d ', strtotime($start_date. ' + '.$day.' days')); |
|
57 | + $coachStartDate = date('Y-m-d ', strtotime($start_date.' + '.$day.' days')); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | $coachEndDate = null; |
61 | 61 | if (!empty($nb_days_access_after)) { |
62 | 62 | $day = intval($nb_days_access_after); |
63 | - $coachEndDate = date('Y-m-d ', strtotime($end_date. ' + '.$day.' days')); |
|
63 | + $coachEndDate = date('Y-m-d ', strtotime($end_date.' + '.$day.' days')); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | // Try to create the session |
@@ -76,19 +76,19 @@ discard block |
||
76 | 76 | 0, |
77 | 77 | $visibility |
78 | 78 | ); |
79 | - if(!is_int($session_id)) { |
|
79 | + if (!is_int($session_id)) { |
|
80 | 80 | return new WSError(301, 'Could not create the session'); |
81 | 81 | } else { |
82 | 82 | // Add the Original session id to the extra fields |
83 | 83 | $extras_associative = array(); |
84 | - if($session_id_field_name != "chamilo_session_id") { |
|
84 | + if ($session_id_field_name != "chamilo_session_id") { |
|
85 | 85 | $extras_associative[$session_id_field_name] = $session_id_value; |
86 | 86 | } |
87 | - foreach($extras as $extra) { |
|
87 | + foreach ($extras as $extra) { |
|
88 | 88 | $extras_associative[$extra['field_name']] = $extra['field_value']; |
89 | 89 | } |
90 | 90 | // Create the extra fields |
91 | - foreach($extras_associative as $fname => $fvalue) { |
|
91 | + foreach ($extras_associative as $fname => $fvalue) { |
|
92 | 92 | SessionManager::create_session_extra_field($fname, 1, $fname); |
93 | 93 | SessionManager::update_session_extra_field_value( |
94 | 94 | $session_id, |
@@ -120,11 +120,11 @@ discard block |
||
120 | 120 | */ |
121 | 121 | public function CreateSession($secret_key, $name, $start_date, $end_date, $nb_days_access_before, $nb_days_access_after, $nolimit, $visibility, $user_id_field_name, $user_id_value, $session_id_field_name, $session_id_value, $extras) { |
122 | 122 | $verifKey = $this->verifyKey($secret_key); |
123 | - if($verifKey instanceof WSError) { |
|
123 | + if ($verifKey instanceof WSError) { |
|
124 | 124 | $this->handleError($verifKey); |
125 | 125 | } else { |
126 | 126 | $session_id = $this->createSessionHelper($name, $start_date, $end_date, $nb_days_access_before, $nb_days_access_after, $nolimit, $visibility, $user_id_field_name, $user_id_value, $session_id_field_name, $session_id_value, $extras); |
127 | - if($session_id instanceof WSError) { |
|
127 | + if ($session_id instanceof WSError) { |
|
128 | 128 | $this->handleError($session_id); |
129 | 129 | } else { |
130 | 130 | return $session_id; |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | */ |
142 | 142 | protected function deleteSessionHelper($session_id_field_name, $session_id_value) { |
143 | 143 | $session_id = $this->getSessionId($session_id_field_name, $session_id_value); |
144 | - if($session_id instanceof WSError) { |
|
144 | + if ($session_id instanceof WSError) { |
|
145 | 145 | return $session_id; |
146 | 146 | } else { |
147 | 147 | SessionManager::delete($session_id, true); |
@@ -158,11 +158,11 @@ discard block |
||
158 | 158 | */ |
159 | 159 | public function DeleteSession($secret_key, $session_id_field_name, $session_id_value) { |
160 | 160 | $verifKey = $this->verifyKey($secret_key); |
161 | - if($verifKey instanceof WSError) { |
|
161 | + if ($verifKey instanceof WSError) { |
|
162 | 162 | $this->handleError($verifKey); |
163 | 163 | } else { |
164 | 164 | $result = $this->deleteSessionHelper($session_id_field_name, $session_id_value); |
165 | - if($result instanceof WSError) { |
|
165 | + if ($result instanceof WSError) { |
|
166 | 166 | $this->handleError($result); |
167 | 167 | } |
168 | 168 | } |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | $extras |
201 | 201 | ) { |
202 | 202 | $session_id = $this->getSessionId($session_id_field_name, $session_id_value); |
203 | - if($session_id instanceof WSError) { |
|
203 | + if ($session_id instanceof WSError) { |
|
204 | 204 | return $session_id; |
205 | 205 | } else { |
206 | 206 | // Verify that coach exists and get its id |
@@ -212,13 +212,13 @@ discard block |
||
212 | 212 | $coachStartDate = null; |
213 | 213 | if (!empty($nb_days_access_before)) { |
214 | 214 | $day = intval($nb_days_access_before); |
215 | - $coachStartDate = date('Y-m-d ', strtotime($start_date. ' + '.$day.' days')); |
|
215 | + $coachStartDate = date('Y-m-d ', strtotime($start_date.' + '.$day.' days')); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | $coachEndDate = null; |
219 | 219 | if (!empty($nb_days_access_after)) { |
220 | 220 | $day = intval($nb_days_access_after); |
221 | - $coachEndDate = date('Y-m-d ', strtotime($end_date. ' + '.$day.' days')); |
|
221 | + $coachEndDate = date('Y-m-d ', strtotime($end_date.' + '.$day.' days')); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | $result_id = SessionManager::edit_session( |
@@ -232,18 +232,18 @@ discard block |
||
232 | 232 | $coachEndDate, |
233 | 233 | $user_id, |
234 | 234 | 0, |
235 | - (int)$visibility |
|
235 | + (int) $visibility |
|
236 | 236 | ); |
237 | - if(!is_int($result_id)) { |
|
237 | + if (!is_int($result_id)) { |
|
238 | 238 | return new WSError(302, 'Could not edit the session'); |
239 | 239 | } else { |
240 | - if(!empty($extras)) { |
|
240 | + if (!empty($extras)) { |
|
241 | 241 | $extras_associative = array(); |
242 | - foreach($extras as $extra) { |
|
242 | + foreach ($extras as $extra) { |
|
243 | 243 | $extras_associative[$extra['field_name']] = $extra['field_value']; |
244 | 244 | } |
245 | 245 | // Create the extra fields |
246 | - foreach($extras_associative as $fname => $fvalue) { |
|
246 | + foreach ($extras_associative as $fname => $fvalue) { |
|
247 | 247 | SessionManager::create_session_extra_field($fname, 1, $fname); |
248 | 248 | SessionManager::update_session_extra_field_value($session_id, $fname, $fvalue); |
249 | 249 | } |
@@ -272,11 +272,11 @@ discard block |
||
272 | 272 | */ |
273 | 273 | public function EditSession($secret_key, $name, $start_date, $end_date, $nb_days_access_before, $nb_days_access_after, $nolimit, $visibility, $user_id_field_name, $user_id_value, $session_id_field_name, $session_id_value, $extras) { |
274 | 274 | $verifKey = $this->verifyKey($secret_key); |
275 | - if($verifKey instanceof WSError) { |
|
275 | + if ($verifKey instanceof WSError) { |
|
276 | 276 | $this->handleError($verifKey); |
277 | 277 | } else { |
278 | 278 | $result = $this->editSessionHelper($name, $start_date, $end_date, $nb_days_access_before, $nb_days_access_after, $nolimit, $visibility, $user_id_field_name, $user_id_value, $session_id_field_name, $session_id_value, $extras); |
279 | - if($session_id_value instanceof WSError) { |
|
279 | + if ($session_id_value instanceof WSError) { |
|
280 | 280 | $this->handleError($result); |
281 | 281 | } |
282 | 282 | } |
@@ -294,14 +294,14 @@ discard block |
||
294 | 294 | */ |
295 | 295 | protected function changeUserSubscription($user_id_field_name, $user_id_value, $session_id_field_name, $session_id_value, $state) { |
296 | 296 | $session_id = $this->getSessionId($session_id_field_name, $session_id_value); |
297 | - if($session_id instanceof WSError) { |
|
297 | + if ($session_id instanceof WSError) { |
|
298 | 298 | return $session_id; |
299 | 299 | } else { |
300 | 300 | $user_id = $this->getUserId($user_id_field_name, $user_id_value); |
301 | - if($user_id instanceof WSError) { |
|
301 | + if ($user_id instanceof WSError) { |
|
302 | 302 | return $user_id; |
303 | 303 | } else { |
304 | - if($state == 1) { |
|
304 | + if ($state == 1) { |
|
305 | 305 | SessionManager::subscribe_users_to_session($session_id, array($user_id)); |
306 | 306 | } else { |
307 | 307 | $result = SessionManager::unsubscribe_user_from_session($session_id, $user_id); |
@@ -325,11 +325,11 @@ discard block |
||
325 | 325 | */ |
326 | 326 | public function SubscribeUserToSession($secret_key, $user_id_field_name, $user_id_value, $session_id_field_name, $session_id_value) { |
327 | 327 | $verifKey = $this->verifyKey($secret_key); |
328 | - if($verifKey instanceof WSError) { |
|
328 | + if ($verifKey instanceof WSError) { |
|
329 | 329 | $this->handleError($verifKey); |
330 | 330 | } else { |
331 | 331 | $result = $this->changeUserSubscription($user_id_field_name, $user_id_value, $session_id_field_name, $session_id_value, 1); |
332 | - if($result instanceof WSError) { |
|
332 | + if ($result instanceof WSError) { |
|
333 | 333 | $this->handleError($result); |
334 | 334 | } |
335 | 335 | } |
@@ -346,11 +346,11 @@ discard block |
||
346 | 346 | */ |
347 | 347 | public function UnsubscribeUserFromSession($secret_key, $user_id_field_name, $user_id_value, $session_id_field_name, $session_id_value) { |
348 | 348 | $verifKey = $this->verifyKey($secret_key); |
349 | - if($verifKey instanceof WSError) { |
|
349 | + if ($verifKey instanceof WSError) { |
|
350 | 350 | $this->handleError($verifKey); |
351 | 351 | } else { |
352 | 352 | $result = $this->changeUserSubscription($user_id_field_name, $user_id_value, $session_id_field_name, $session_id_value, 0); |
353 | - if($result instanceof WSError) { |
|
353 | + if ($result instanceof WSError) { |
|
354 | 354 | $this->handleError($result); |
355 | 355 | } |
356 | 356 | } |
@@ -385,7 +385,7 @@ discard block |
||
385 | 385 | if ($state == 1) { |
386 | 386 | SessionManager::set_coach_to_course_session($user_id, $session_id, $course_id); |
387 | 387 | } else { |
388 | - $user_id = array (0 => $user_id); |
|
388 | + $user_id = array(0 => $user_id); |
|
389 | 389 | $result = SessionManager::removeUsersFromCourseSession($user_id, $session_id, $course_id); |
390 | 390 | if (!$result) { |
391 | 391 | return new WSError(303, 'There was an error unsubscribing this Teacher from the session'); |
@@ -457,14 +457,14 @@ discard block |
||
457 | 457 | */ |
458 | 458 | protected function changeCourseSubscription($course_id_field_name, $course_id_value, $session_id_field_name, $session_id_value, $state) { |
459 | 459 | $session_id = $this->getSessionId($session_id_field_name, $session_id_value); |
460 | - if($session_id instanceof WSError) { |
|
460 | + if ($session_id instanceof WSError) { |
|
461 | 461 | return $session_id; |
462 | 462 | } else { |
463 | 463 | $course_id = $this->getCourseId($course_id_field_name, $course_id_value); |
464 | - if($course_id instanceof WSError) { |
|
464 | + if ($course_id instanceof WSError) { |
|
465 | 465 | return $course_id; |
466 | 466 | } else { |
467 | - if($state == 1) { |
|
467 | + if ($state == 1) { |
|
468 | 468 | SessionManager::add_courses_to_session($session_id, array($course_id)); |
469 | 469 | return true; |
470 | 470 | } else { |
@@ -490,11 +490,11 @@ discard block |
||
490 | 490 | */ |
491 | 491 | public function SubscribeCourseToSession($secret_key, $course_id_field_name, $course_id_value, $session_id_field_name, $session_id_value) { |
492 | 492 | $verifKey = $this->verifyKey($secret_key); |
493 | - if($verifKey instanceof WSError) { |
|
493 | + if ($verifKey instanceof WSError) { |
|
494 | 494 | $this->handleError($verifKey); |
495 | 495 | } else { |
496 | 496 | $result = $this->changeCourseSubscription($course_id_field_name, $course_id_value, $session_id_field_name, $session_id_value, 1); |
497 | - if($result instanceof WSError) { |
|
497 | + if ($result instanceof WSError) { |
|
498 | 498 | $this->handleError($result); |
499 | 499 | } |
500 | 500 | } |
@@ -511,11 +511,11 @@ discard block |
||
511 | 511 | */ |
512 | 512 | public function UnsubscribeCourseFromSession($secret_key, $course_id_field_name, $course_id_value, $session_id_field_name, $session_id_value) { |
513 | 513 | $verifKey = $this->verifyKey($secret_key); |
514 | - if($verifKey instanceof WSError) { |
|
514 | + if ($verifKey instanceof WSError) { |
|
515 | 515 | $this->handleError($verifKey); |
516 | 516 | } else { |
517 | 517 | $result = $this->changeCourseSubscription($course_id_field_name, $course_id_value, $session_id_field_name, $session_id_value, 0); |
518 | - if($result instanceof WSError) { |
|
518 | + if ($result instanceof WSError) { |
|
519 | 519 | $this->handleError($result); |
520 | 520 | } |
521 | 521 | } |