@@ -76,19 +76,19 @@ discard block |
||
76 | 76 | |
77 | 77 | function show_compose_reply_to_message($message_id, $receiver_id) |
78 | 78 | { |
79 | - $table_message = Database::get_main_table(TABLE_MESSAGE); |
|
80 | - $query = "SELECT user_sender_id FROM $table_message |
|
79 | + $table_message = Database::get_main_table(TABLE_MESSAGE); |
|
80 | + $query = "SELECT user_sender_id FROM $table_message |
|
81 | 81 | WHERE user_receiver_id=".intval($receiver_id)." AND id='".intval($message_id)."';"; |
82 | - $result = Database::query($query); |
|
83 | - $row = Database::fetch_array($result,'ASSOC'); |
|
84 | - if (!isset($row['user_sender_id'])) { |
|
85 | - $html = get_lang('InvalidMessageId'); |
|
82 | + $result = Database::query($query); |
|
83 | + $row = Database::fetch_array($result,'ASSOC'); |
|
84 | + if (!isset($row['user_sender_id'])) { |
|
85 | + $html = get_lang('InvalidMessageId'); |
|
86 | 86 | |
87 | - return $html; |
|
88 | - } |
|
89 | - $userInfo = api_get_user_info($row['user_sender_id']); |
|
90 | - $default['users'] = array($row['user_sender_id']); |
|
91 | - $html = manage_form($default, null, $userInfo['complete_name']); |
|
87 | + return $html; |
|
88 | + } |
|
89 | + $userInfo = api_get_user_info($row['user_sender_id']); |
|
90 | + $default['users'] = array($row['user_sender_id']); |
|
91 | + $html = manage_form($default, null, $userInfo['complete_name']); |
|
92 | 92 | |
93 | 93 | return $html; |
94 | 94 | } |
@@ -96,10 +96,10 @@ discard block |
||
96 | 96 | function show_compose_to_user ($receiver_id) |
97 | 97 | { |
98 | 98 | $userInfo = api_get_user_info($receiver_id); |
99 | - $html = get_lang('To').': <strong>'.$userInfo['complete_name'].'</strong>'; |
|
100 | - $default['title'] = api_xml_http_response_encode(get_lang('EnterTitle')); |
|
101 | - $default['users'] = array($receiver_id); |
|
102 | - $html .= manage_form($default); |
|
99 | + $html = get_lang('To').': <strong>'.$userInfo['complete_name'].'</strong>'; |
|
100 | + $default['title'] = api_xml_http_response_encode(get_lang('EnterTitle')); |
|
101 | + $default['users'] = array($receiver_id); |
|
102 | + $html .= manage_form($default); |
|
103 | 103 | return $html; |
104 | 104 | } |
105 | 105 | |
@@ -265,13 +265,13 @@ discard block |
||
265 | 265 | |
266 | 266 | /* MAIN SECTION */ |
267 | 267 | if ($socialToolIsActive) { |
268 | - $this_section = SECTION_SOCIAL; |
|
268 | + $this_section = SECTION_SOCIAL; |
|
269 | 269 | $interbreadcrumb[] = array( |
270 | 270 | 'url' => api_get_path(WEB_PATH).'main/social/home.php', |
271 | 271 | 'name' => get_lang('SocialNetwork'), |
272 | 272 | ); |
273 | 273 | } else { |
274 | - $this_section = SECTION_MYPROFILE; |
|
274 | + $this_section = SECTION_MYPROFILE; |
|
275 | 275 | $interbreadcrumb[] = array( |
276 | 276 | 'url' => api_get_path(WEB_PATH).'main/auth/profile.php', |
277 | 277 | 'name' => get_lang('Profile'), |
@@ -281,30 +281,30 @@ discard block |
||
281 | 281 | $group_id = isset($_REQUEST['group_id']) ? intval($_REQUEST['group_id']) : null; |
282 | 282 | $social_right_content = null; |
283 | 283 | if ($group_id != 0) { |
284 | - $social_right_content .= '<div class=actions>'; |
|
285 | - $social_right_content .= '<a href="'.api_get_path(WEB_PATH).'main/social/group_view.php?id='.$group_id.'">'. |
|
286 | - Display::return_icon('back.png',api_xml_http_response_encode(get_lang('ComposeMessage'))).'</a>'; |
|
287 | - $social_right_content .= '<a href="'.api_get_path(WEB_PATH).'main/messages/new_message.php?group_id='.$group_id.'">'. |
|
288 | - Display::return_icon('message_new.png',api_xml_http_response_encode(get_lang('ComposeMessage'))).'</a>'; |
|
289 | - $social_right_content .= '</div>'; |
|
284 | + $social_right_content .= '<div class=actions>'; |
|
285 | + $social_right_content .= '<a href="'.api_get_path(WEB_PATH).'main/social/group_view.php?id='.$group_id.'">'. |
|
286 | + Display::return_icon('back.png',api_xml_http_response_encode(get_lang('ComposeMessage'))).'</a>'; |
|
287 | + $social_right_content .= '<a href="'.api_get_path(WEB_PATH).'main/messages/new_message.php?group_id='.$group_id.'">'. |
|
288 | + Display::return_icon('message_new.png',api_xml_http_response_encode(get_lang('ComposeMessage'))).'</a>'; |
|
289 | + $social_right_content .= '</div>'; |
|
290 | 290 | } else { |
291 | - if ($socialToolIsActive) { |
|
292 | - } else { |
|
293 | - $social_right_content .= '<div class=actions>'; |
|
294 | - if (api_get_setting('allow_social_tool') === 'true' && api_get_setting('allow_message_tool') === 'true') { |
|
295 | - $social_right_content .= '<a href="'.api_get_path(WEB_PATH).'main/social/profile.php">'. |
|
291 | + if ($socialToolIsActive) { |
|
292 | + } else { |
|
293 | + $social_right_content .= '<div class=actions>'; |
|
294 | + if (api_get_setting('allow_social_tool') === 'true' && api_get_setting('allow_message_tool') === 'true') { |
|
295 | + $social_right_content .= '<a href="'.api_get_path(WEB_PATH).'main/social/profile.php">'. |
|
296 | 296 | Display::return_icon('shared_profile.png', get_lang('ViewSharedProfile')).'</a>'; |
297 | - } |
|
298 | - if (api_get_setting('allow_message_tool') === 'true') { |
|
299 | - $social_right_content .= '<a href="'.api_get_path(WEB_PATH).'main/messages/new_message.php">'. |
|
297 | + } |
|
298 | + if (api_get_setting('allow_message_tool') === 'true') { |
|
299 | + $social_right_content .= '<a href="'.api_get_path(WEB_PATH).'main/messages/new_message.php">'. |
|
300 | 300 | Display::return_icon('message_new.png',get_lang('ComposeMessage')).'</a>'; |
301 | - $social_right_content .= '<a href="'.api_get_path(WEB_PATH).'main/messages/inbox.php">'. |
|
301 | + $social_right_content .= '<a href="'.api_get_path(WEB_PATH).'main/messages/inbox.php">'. |
|
302 | 302 | Display::return_icon('inbox.png',get_lang('Inbox')).'</a>'; |
303 | 303 | $social_right_content .= '<a href="'.api_get_path(WEB_PATH).'main/messages/outbox.php">'. |
304 | 304 | Display::return_icon('outbox.png',get_lang('Outbox')).'</a>'; |
305 | - } |
|
306 | - $social_right_content .= '</div>'; |
|
307 | - } |
|
305 | + } |
|
306 | + $social_right_content .= '</div>'; |
|
307 | + } |
|
308 | 308 | } |
309 | 309 | |
310 | 310 | // LEFT COLUMN |
@@ -290,8 +290,8 @@ discard block |
||
290 | 290 | } |
291 | 291 | } |
292 | 292 | |
293 | - //This query will show all registered users. Only for dev purposes. |
|
294 | - /*$query = "SELECT DISTINCT u.id as login_user_id, login_date FROM ".$track_online_table ." e , $table_user u |
|
293 | + //This query will show all registered users. Only for dev purposes. |
|
294 | + /*$query = "SELECT DISTINCT u.id as login_user_id, login_date FROM ".$track_online_table ." e , $table_user u |
|
295 | 295 | GROUP by u.id |
296 | 296 | ORDER BY $column $direction |
297 | 297 | LIMIT $from, $number_of_items";*/ |
@@ -317,15 +317,15 @@ discard block |
||
317 | 317 | } else { |
318 | 318 | $time_limit = intval($time_limit); |
319 | 319 | } |
320 | - $track_online_table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ONLINE); |
|
321 | - $friend_user_table = Database::get_main_table(TABLE_MAIN_USER_REL_USER); |
|
322 | - $table_user = Database::get_main_table(TABLE_MAIN_USER); |
|
323 | - $online_time = time() - $time_limit * 60; |
|
324 | - $current_date = api_get_utc_datetime($online_time); |
|
325 | - |
|
326 | - if ($friends) { |
|
327 | - // who friends from social network is online |
|
328 | - $query = "SELECT DISTINCT count(login_user_id) as count |
|
320 | + $track_online_table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ONLINE); |
|
321 | + $friend_user_table = Database::get_main_table(TABLE_MAIN_USER_REL_USER); |
|
322 | + $table_user = Database::get_main_table(TABLE_MAIN_USER); |
|
323 | + $online_time = time() - $time_limit * 60; |
|
324 | + $current_date = api_get_utc_datetime($online_time); |
|
325 | + |
|
326 | + if ($friends) { |
|
327 | + // who friends from social network is online |
|
328 | + $query = "SELECT DISTINCT count(login_user_id) as count |
|
329 | 329 | FROM $track_online_table INNER JOIN $friend_user_table |
330 | 330 | ON (friend_user_id = login_user_id) |
331 | 331 | WHERE |
@@ -333,20 +333,20 @@ discard block |
||
333 | 333 | friend_user_id <> '".api_get_user_id()."' AND |
334 | 334 | relation_type='".USER_RELATION_TYPE_FRIEND."' AND |
335 | 335 | user_id = '".api_get_user_id()."' "; |
336 | - } else { |
|
337 | - // All users online |
|
338 | - $query = "SELECT count(login_id) as count |
|
336 | + } else { |
|
337 | + // All users online |
|
338 | + $query = "SELECT count(login_id) as count |
|
339 | 339 | FROM $track_online_table track INNER JOIN $table_user u |
340 | 340 | ON (u.id=track.login_user_id) |
341 | 341 | WHERE u.status != ".ANONYMOUS." AND login_date >= '$current_date' "; |
342 | - } |
|
343 | - |
|
344 | - if (api_get_multiple_access_url()) { |
|
345 | - $access_url_id = api_get_current_access_url_id(); |
|
346 | - if ($access_url_id != -1) { |
|
347 | - if ($friends) { |
|
348 | - // friends from social network is online |
|
349 | - $query = "SELECT DISTINCT count(login_user_id) as count |
|
342 | + } |
|
343 | + |
|
344 | + if (api_get_multiple_access_url()) { |
|
345 | + $access_url_id = api_get_current_access_url_id(); |
|
346 | + if ($access_url_id != -1) { |
|
347 | + if ($friends) { |
|
348 | + // friends from social network is online |
|
349 | + $query = "SELECT DISTINCT count(login_user_id) as count |
|
350 | 350 | FROM $track_online_table track |
351 | 351 | INNER JOIN $friend_user_table ON (friend_user_id = login_user_id) |
352 | 352 | WHERE |
@@ -354,29 +354,29 @@ discard block |
||
354 | 354 | login_date >= '".$current_date."' AND |
355 | 355 | friend_user_id <> '".api_get_user_id()."' AND |
356 | 356 | relation_type='".USER_RELATION_TYPE_FRIEND."' "; |
357 | - } else { |
|
358 | - // all users online |
|
359 | - $query = "SELECT count(login_id) as count FROM $track_online_table track |
|
357 | + } else { |
|
358 | + // all users online |
|
359 | + $query = "SELECT count(login_id) as count FROM $track_online_table track |
|
360 | 360 | INNER JOIN $table_user u ON (u.id=track.login_user_id) |
361 | 361 | WHERE |
362 | 362 | u.status != ".ANONYMOUS." AND |
363 | 363 | track.access_url_id = $access_url_id AND |
364 | 364 | login_date >= '$current_date' "; |
365 | - } |
|
366 | - } |
|
367 | - } |
|
365 | + } |
|
366 | + } |
|
367 | + } |
|
368 | 368 | |
369 | 369 | // Dev purposes show all users online |
370 | 370 | /*$table_user = Database::get_main_table(TABLE_MAIN_USER); |
371 | 371 | $query = "SELECT count(*) as count FROM ".$table_user;*/ |
372 | 372 | |
373 | - $result = Database::query($query); |
|
374 | - if (Database::num_rows($result) > 0) { |
|
375 | - $row = Database::fetch_array($result); |
|
376 | - return $row['count']; |
|
377 | - } else { |
|
378 | - return false; |
|
379 | - } |
|
373 | + $result = Database::query($query); |
|
374 | + if (Database::num_rows($result) > 0) { |
|
375 | + $row = Database::fetch_array($result); |
|
376 | + return $row['count']; |
|
377 | + } else { |
|
378 | + return false; |
|
379 | + } |
|
380 | 380 | } |
381 | 381 | |
382 | 382 | |
@@ -404,52 +404,52 @@ discard block |
||
404 | 404 | $track_online_table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ONLINE); |
405 | 405 | $course_code = Database::escape_string($course_code); |
406 | 406 | $courseInfo = api_get_course_info($course_code); |
407 | - $courseId = $courseInfo['real_id']; |
|
407 | + $courseId = $courseInfo['real_id']; |
|
408 | 408 | |
409 | 409 | $from = intval($from); |
410 | 410 | $number_of_items = intval($number_of_items); |
411 | 411 | |
412 | - $query = "SELECT login_user_id, login_date FROM $track_online_table |
|
412 | + $query = "SELECT login_user_id, login_date FROM $track_online_table |
|
413 | 413 | WHERE login_user_id <> 2 AND c_id = $courseId AND login_date >= '$current_date' |
414 | 414 | LIMIT $from, $number_of_items "; |
415 | 415 | |
416 | - $result = Database::query($query); |
|
417 | - if ($result) { |
|
418 | - $users_online = array(); |
|
416 | + $result = Database::query($query); |
|
417 | + if ($result) { |
|
418 | + $users_online = array(); |
|
419 | 419 | |
420 | - while(list($login_user_id, $login_date) = Database::fetch_row($result)) { |
|
420 | + while(list($login_user_id, $login_date) = Database::fetch_row($result)) { |
|
421 | 421 | $users_online[] = $login_user_id; |
422 | - } |
|
423 | - return $users_online; |
|
424 | - } else { |
|
425 | - return false; |
|
426 | - } |
|
422 | + } |
|
423 | + return $users_online; |
|
424 | + } else { |
|
425 | + return false; |
|
426 | + } |
|
427 | 427 | } |
428 | 428 | |
429 | 429 | function who_is_online_in_this_course_count($uid, $time_limit, $coursecode=null) |
430 | 430 | { |
431 | - if (empty($coursecode)) { |
|
432 | - return false; |
|
433 | - } |
|
434 | - $track_online_table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ONLINE); |
|
435 | - $time_limit = Database::escape_string($time_limit); |
|
431 | + if (empty($coursecode)) { |
|
432 | + return false; |
|
433 | + } |
|
434 | + $track_online_table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ONLINE); |
|
435 | + $time_limit = Database::escape_string($time_limit); |
|
436 | 436 | |
437 | 437 | $online_time = time() - $time_limit * 60; |
438 | 438 | $current_date = api_get_utc_datetime($online_time); |
439 | - $courseId = api_get_course_int_id($coursecode); |
|
439 | + $courseId = api_get_course_int_id($coursecode); |
|
440 | 440 | |
441 | - if (empty($courseId)) { |
|
442 | - return false; |
|
443 | - } |
|
441 | + if (empty($courseId)) { |
|
442 | + return false; |
|
443 | + } |
|
444 | 444 | |
445 | - $query = "SELECT count(login_user_id) as count |
|
445 | + $query = "SELECT count(login_user_id) as count |
|
446 | 446 | FROM $track_online_table |
447 | 447 | WHERE login_user_id <> 2 AND c_id = $courseId AND login_date >= '$current_date' "; |
448 | - $result = Database::query($query); |
|
449 | - if (Database::num_rows($result) > 0) { |
|
450 | - $row = Database::fetch_array($result); |
|
451 | - return $row['count']; |
|
452 | - } else { |
|
453 | - return false; |
|
454 | - } |
|
448 | + $result = Database::query($query); |
|
449 | + if (Database::num_rows($result) > 0) { |
|
450 | + $row = Database::fetch_array($result); |
|
451 | + return $row['count']; |
|
452 | + } else { |
|
453 | + return false; |
|
454 | + } |
|
455 | 455 | } |
@@ -10,12 +10,12 @@ discard block |
||
10 | 10 | CONST VISIBLE_STUDENT = 2; |
11 | 11 | CONST VISIBLE_TEACHER = 3; |
12 | 12 | |
13 | - /** |
|
14 | - * Displays all announcements |
|
15 | - * @param int $visible VISIBLE_GUEST, VISIBLE_STUDENT or VISIBLE_TEACHER |
|
16 | - * @param int $id The identifier of the announcement to display |
|
17 | - */ |
|
18 | - public static function display_announcements($visible, $id = -1) |
|
13 | + /** |
|
14 | + * Displays all announcements |
|
15 | + * @param int $visible VISIBLE_GUEST, VISIBLE_STUDENT or VISIBLE_TEACHER |
|
16 | + * @param int $id The identifier of the announcement to display |
|
17 | + */ |
|
18 | + public static function display_announcements($visible, $id = -1) |
|
19 | 19 | { |
20 | 20 | $user_selected_language = api_get_interface_language(); |
21 | 21 | $db_table = Database :: get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS); |
@@ -425,10 +425,10 @@ discard block |
||
425 | 425 | } |
426 | 426 | |
427 | 427 | /** |
428 | - * Makes the announcement id visible only for groups in groups_array |
|
429 | - * @param int $announcement_id |
|
430 | - * @param array $group_array array of group id |
|
431 | - **/ |
|
428 | + * Makes the announcement id visible only for groups in groups_array |
|
429 | + * @param int $announcement_id |
|
430 | + * @param array $group_array array of group id |
|
431 | + **/ |
|
432 | 432 | public static function announcement_for_groups($announcement_id, $group_array) |
433 | 433 | { |
434 | 434 | $tbl_announcement_group = Database:: get_main_table( |
@@ -461,10 +461,10 @@ discard block |
||
461 | 461 | } |
462 | 462 | |
463 | 463 | /** |
464 | - * Gets the groups of this announce |
|
465 | - * @param int announcement id |
|
466 | - * @return array array of group id |
|
467 | - **/ |
|
464 | + * Gets the groups of this announce |
|
465 | + * @param int announcement id |
|
466 | + * @return array array of group id |
|
467 | + **/ |
|
468 | 468 | public static function get_announcement_groups($announcement_id) |
469 | 469 | { |
470 | 470 | $tbl_announcement_group = Database :: get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS_GROUPS); |
@@ -484,15 +484,15 @@ discard block |
||
484 | 484 | return $groups; |
485 | 485 | } |
486 | 486 | |
487 | - /** |
|
488 | - * Updates an announcement to the database |
|
489 | - * @param integer $id : id of the announcement |
|
490 | - * @param string $title : title of the announcement |
|
491 | - * @param string $content : content of the announcement |
|
492 | - * @param array $date_start: start date of announcement (0 => day ; 1 => month ; 2 => year ; 3 => hour ; 4 => minute) |
|
493 | - * @param array $date_end : end date of announcement (0 => day ; 1 => month ; 2 => year ; 3 => hour ; 4 => minute) |
|
494 | - * @return bool True on success, false on failure |
|
495 | - */ |
|
487 | + /** |
|
488 | + * Updates an announcement to the database |
|
489 | + * @param integer $id : id of the announcement |
|
490 | + * @param string $title : title of the announcement |
|
491 | + * @param string $content : content of the announcement |
|
492 | + * @param array $date_start: start date of announcement (0 => day ; 1 => month ; 2 => year ; 3 => hour ; 4 => minute) |
|
493 | + * @param array $date_end : end date of announcement (0 => day ; 1 => month ; 2 => year ; 3 => hour ; 4 => minute) |
|
494 | + * @return bool True on success, false on failure |
|
495 | + */ |
|
496 | 496 | public static function update_announcement( |
497 | 497 | $id, |
498 | 498 | $title, |
@@ -507,12 +507,12 @@ discard block |
||
507 | 507 | $sendEmailTest = false |
508 | 508 | ) { |
509 | 509 | $em = Database::getManager(); |
510 | - $announcement = $em->find('ChamiloCoreBundle:SysAnnouncement', $id); |
|
510 | + $announcement = $em->find('ChamiloCoreBundle:SysAnnouncement', $id); |
|
511 | 511 | |
512 | - if (!$announcement) { |
|
512 | + if (!$announcement) { |
|
513 | 513 | |
514 | - return false; |
|
515 | - } |
|
514 | + return false; |
|
515 | + } |
|
516 | 516 | |
517 | 517 | $a_dateS = explode(' ', $date_start); |
518 | 518 | $a_arraySD = explode('-', $a_dateS[0]); |
@@ -532,28 +532,28 @@ discard block |
||
532 | 532 | return false; |
533 | 533 | } |
534 | 534 | |
535 | - if (($date_end_to_compare[1] || |
|
535 | + if (($date_end_to_compare[1] || |
|
536 | 536 | $date_end_to_compare[2] || |
537 | 537 | $date_end_to_compare[0]) && |
538 | 538 | !checkdate($date_end_to_compare[1], $date_end_to_compare[2], $date_end_to_compare[0]) |
539 | 539 | ) { |
540 | - Display :: display_normal_message(get_lang('InvalidEndDate')); |
|
540 | + Display :: display_normal_message(get_lang('InvalidEndDate')); |
|
541 | 541 | |
542 | - return false; |
|
543 | - } |
|
542 | + return false; |
|
543 | + } |
|
544 | 544 | |
545 | - if (strlen(trim($title)) == 0) { |
|
546 | - Display::display_normal_message(get_lang('InvalidTitle')); |
|
545 | + if (strlen(trim($title)) == 0) { |
|
546 | + Display::display_normal_message(get_lang('InvalidTitle')); |
|
547 | 547 | |
548 | - return false; |
|
549 | - } |
|
548 | + return false; |
|
549 | + } |
|
550 | 550 | |
551 | - $start = api_get_utc_datetime($date_start); |
|
551 | + $start = api_get_utc_datetime($date_start); |
|
552 | 552 | $end = api_get_utc_datetime($date_end); |
553 | 553 | |
554 | - //Fixing urls that are sent by email |
|
555 | - //$content = str_replace('src=\"/home/', 'src=\"'.api_get_path(WEB_PATH).'home/', $content); |
|
556 | - //$content = str_replace('file=/home/', 'file='.api_get_path(WEB_PATH).'home/', $content); |
|
554 | + //Fixing urls that are sent by email |
|
555 | + //$content = str_replace('src=\"/home/', 'src=\"'.api_get_path(WEB_PATH).'home/', $content); |
|
556 | + //$content = str_replace('file=/home/', 'file='.api_get_path(WEB_PATH).'home/', $content); |
|
557 | 557 | $content = str_replace('src=\"'.api_get_path(REL_HOME_PATH), 'src=\"'.api_get_path(WEB_PATH).api_get_path(REL_HOME_PATH), $content); |
558 | 558 | $content = str_replace('file='.api_get_path(REL_HOME_PATH), 'file='.api_get_path(WEB_PATH).api_get_path(REL_HOME_PATH), $content); |
559 | 559 | |
@@ -595,82 +595,82 @@ discard block |
||
595 | 595 | $em->merge($announcement); |
596 | 596 | $em->flush(); |
597 | 597 | |
598 | - return true; |
|
599 | - } |
|
598 | + return true; |
|
599 | + } |
|
600 | 600 | |
601 | - /** |
|
602 | - * Deletes an announcement |
|
603 | - * @param int $id The identifier of the announcement that should be |
|
604 | - * @return bool True on success, false on failure |
|
605 | - */ |
|
606 | - public static function delete_announcement($id) |
|
601 | + /** |
|
602 | + * Deletes an announcement |
|
603 | + * @param int $id The identifier of the announcement that should be |
|
604 | + * @return bool True on success, false on failure |
|
605 | + */ |
|
606 | + public static function delete_announcement($id) |
|
607 | 607 | { |
608 | - $db_table = Database :: get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS); |
|
609 | - $id = intval($id); |
|
610 | - $sql = "DELETE FROM ".$db_table." WHERE id =".$id; |
|
611 | - $res = Database::query($sql); |
|
612 | - if ($res === false) { |
|
613 | - |
|
614 | - return false; |
|
615 | - } |
|
616 | - return true; |
|
617 | - } |
|
618 | - |
|
619 | - /** |
|
620 | - * Gets an announcement |
|
621 | - * @param int $id The identifier of the announcement that should be |
|
622 | - * @return object Object of class StdClass or the required class, containing the query result row |
|
623 | - */ |
|
624 | - public static function get_announcement($id) |
|
608 | + $db_table = Database :: get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS); |
|
609 | + $id = intval($id); |
|
610 | + $sql = "DELETE FROM ".$db_table." WHERE id =".$id; |
|
611 | + $res = Database::query($sql); |
|
612 | + if ($res === false) { |
|
613 | + |
|
614 | + return false; |
|
615 | + } |
|
616 | + return true; |
|
617 | + } |
|
618 | + |
|
619 | + /** |
|
620 | + * Gets an announcement |
|
621 | + * @param int $id The identifier of the announcement that should be |
|
622 | + * @return object Object of class StdClass or the required class, containing the query result row |
|
623 | + */ |
|
624 | + public static function get_announcement($id) |
|
625 | 625 | { |
626 | - $db_table = Database :: get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS); |
|
627 | - $id = intval($id); |
|
628 | - $sql = "SELECT * FROM ".$db_table." WHERE id = ".$id; |
|
629 | - $announcement = Database::fetch_object(Database::query($sql)); |
|
630 | - |
|
631 | - return $announcement; |
|
632 | - } |
|
633 | - |
|
634 | - /** |
|
635 | - * Change the visibility of an announcement |
|
636 | - * @param int $announcement_id |
|
637 | - * @param int $user For who should the visibility be changed |
|
626 | + $db_table = Database :: get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS); |
|
627 | + $id = intval($id); |
|
628 | + $sql = "SELECT * FROM ".$db_table." WHERE id = ".$id; |
|
629 | + $announcement = Database::fetch_object(Database::query($sql)); |
|
630 | + |
|
631 | + return $announcement; |
|
632 | + } |
|
633 | + |
|
634 | + /** |
|
635 | + * Change the visibility of an announcement |
|
636 | + * @param int $announcement_id |
|
637 | + * @param int $user For who should the visibility be changed |
|
638 | 638 | * (possible values are VISIBLE_TEACHER, VISIBLE_STUDENT, VISIBLE_GUEST) |
639 | - * @return bool True on success, false on failure |
|
640 | - */ |
|
641 | - public static function set_visibility($announcement_id, $user, $visible) |
|
639 | + * @return bool True on success, false on failure |
|
640 | + */ |
|
641 | + public static function set_visibility($announcement_id, $user, $visible) |
|
642 | 642 | { |
643 | - $db_table = Database::get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS); |
|
644 | - $visible = intval($visible); |
|
645 | - $announcement_id = intval($announcement_id); |
|
643 | + $db_table = Database::get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS); |
|
644 | + $visible = intval($visible); |
|
645 | + $announcement_id = intval($announcement_id); |
|
646 | 646 | |
647 | 647 | if (!in_array($user, array(self::VISIBLE_GUEST, self::VISIBLE_STUDENT, self::VISIBLE_TEACHER))) { |
648 | 648 | return false; |
649 | 649 | } |
650 | 650 | |
651 | - $field = ($user == self::VISIBLE_TEACHER ? 'visible_teacher' : ($user == self::VISIBLE_STUDENT ? 'visible_student' : 'visible_guest')); |
|
651 | + $field = ($user == self::VISIBLE_TEACHER ? 'visible_teacher' : ($user == self::VISIBLE_STUDENT ? 'visible_student' : 'visible_guest')); |
|
652 | 652 | |
653 | - $sql = "UPDATE ".$db_table." SET ".$field." = '".$visible."' |
|
653 | + $sql = "UPDATE ".$db_table." SET ".$field." = '".$visible."' |
|
654 | 654 | WHERE id='".$announcement_id."'"; |
655 | - $res = Database::query($sql); |
|
656 | - |
|
657 | - if ($res === false) { |
|
658 | - return false; |
|
659 | - } |
|
660 | - |
|
661 | - return true; |
|
662 | - } |
|
663 | - |
|
664 | - /** |
|
665 | - * Send a system announcement by e-mail to all teachers/students depending on parameters |
|
666 | - * @param string $title |
|
667 | - * @param string $content |
|
668 | - * @param int $teacher Whether to send to all teachers (1) or not (0) |
|
669 | - * @param int $student Whether to send to all students (1) or not (0) |
|
670 | - * @param string $language Language (optional, considered for all languages if left empty) |
|
655 | + $res = Database::query($sql); |
|
656 | + |
|
657 | + if ($res === false) { |
|
658 | + return false; |
|
659 | + } |
|
660 | + |
|
661 | + return true; |
|
662 | + } |
|
663 | + |
|
664 | + /** |
|
665 | + * Send a system announcement by e-mail to all teachers/students depending on parameters |
|
666 | + * @param string $title |
|
667 | + * @param string $content |
|
668 | + * @param int $teacher Whether to send to all teachers (1) or not (0) |
|
669 | + * @param int $student Whether to send to all students (1) or not (0) |
|
670 | + * @param string $language Language (optional, considered for all languages if left empty) |
|
671 | 671 | * @param bool $sendEmailTest |
672 | 672 | * @return bool True if the message was sent or there was no destination matching. False on database or e-mail sending error. |
673 | - */ |
|
673 | + */ |
|
674 | 674 | public static function send_system_announcement_by_email( |
675 | 675 | $title, |
676 | 676 | $content, |
@@ -696,26 +696,26 @@ discard block |
||
696 | 696 | } |
697 | 697 | |
698 | 698 | if ($teacher <> 0 && $student == 0) { |
699 | - $sql = "SELECT DISTINCT u.user_id FROM $user_table u $url_condition |
|
699 | + $sql = "SELECT DISTINCT u.user_id FROM $user_table u $url_condition |
|
700 | 700 | WHERE status = '1' "; |
701 | - } |
|
701 | + } |
|
702 | 702 | |
703 | - if ($teacher == 0 && $student <> 0) { |
|
704 | - $sql = "SELECT DISTINCT u.user_id FROM $user_table u $url_condition |
|
703 | + if ($teacher == 0 && $student <> 0) { |
|
704 | + $sql = "SELECT DISTINCT u.user_id FROM $user_table u $url_condition |
|
705 | 705 | WHERE status = '5' "; |
706 | - } |
|
706 | + } |
|
707 | 707 | |
708 | - if ($teacher<> 0 && $student <> 0) { |
|
709 | - $sql = "SELECT DISTINCT u.user_id FROM $user_table u $url_condition |
|
708 | + if ($teacher<> 0 && $student <> 0) { |
|
709 | + $sql = "SELECT DISTINCT u.user_id FROM $user_table u $url_condition |
|
710 | 710 | WHERE 1 = 1 "; |
711 | - } |
|
711 | + } |
|
712 | 712 | |
713 | - if (!empty($language)) { |
|
714 | - //special condition because language was already treated for SQL insert before |
|
715 | - $sql .= " AND language = '".Database::escape_string($language)."' "; |
|
716 | - } |
|
713 | + if (!empty($language)) { |
|
714 | + //special condition because language was already treated for SQL insert before |
|
715 | + $sql .= " AND language = '".Database::escape_string($language)."' "; |
|
716 | + } |
|
717 | 717 | |
718 | - if (api_is_multiple_url_enabled()) { |
|
718 | + if (api_is_multiple_url_enabled()) { |
|
719 | 719 | $sql .= " AND access_url_id = '".$current_access_url_id."' "; |
720 | 720 | } |
721 | 721 | |
@@ -725,28 +725,28 @@ discard block |
||
725 | 725 | // Expiration date |
726 | 726 | $sql .= " AND (expiration_date = '' OR expiration_date IS NULL OR expiration_date > '$now') "; |
727 | 727 | |
728 | - if ((empty($teacher) || $teacher == '0') && (empty($student) || $student == '0')) { |
|
728 | + if ((empty($teacher) || $teacher == '0') && (empty($student) || $student == '0')) { |
|
729 | 729 | |
730 | - return true; |
|
731 | - } |
|
730 | + return true; |
|
731 | + } |
|
732 | 732 | |
733 | - $result = Database::query($sql); |
|
734 | - if ($result === false) { |
|
733 | + $result = Database::query($sql); |
|
734 | + if ($result === false) { |
|
735 | 735 | |
736 | - return false; |
|
737 | - } |
|
736 | + return false; |
|
737 | + } |
|
738 | 738 | |
739 | 739 | $message_sent = false; |
740 | 740 | |
741 | - while ($row = Database::fetch_array($result,'ASSOC')) { |
|
741 | + while ($row = Database::fetch_array($result,'ASSOC')) { |
|
742 | 742 | MessageManager::send_message_simple($row['user_id'], $title, $content); |
743 | 743 | $message_sent = true; |
744 | - } |
|
744 | + } |
|
745 | 745 | |
746 | - return $message_sent; //true if at least one e-mail was sent |
|
747 | - } |
|
746 | + return $message_sent; //true if at least one e-mail was sent |
|
747 | + } |
|
748 | 748 | |
749 | - /** |
|
749 | + /** |
|
750 | 750 | * Displays announcements as an slideshow |
751 | 751 | * @param int $visible VISIBLE_GUEST, VISIBLE_STUDENT or VISIBLE_TEACHER |
752 | 752 | * @param int $id The identifier of the announcement to display |
@@ -37,8 +37,8 @@ discard block |
||
37 | 37 | public $new_destination; // id of the next question if feedback option is set to Directfeedback |
38 | 38 | public $course; //Course information |
39 | 39 | public $iid; |
40 | - public $questionJSId; |
|
41 | - public $standalone; |
|
40 | + public $questionJSId; |
|
41 | + public $standalone; |
|
42 | 42 | |
43 | 43 | /** |
44 | 44 | * constructor of the class |
@@ -159,12 +159,12 @@ discard block |
||
159 | 159 | return []; |
160 | 160 | } |
161 | 161 | |
162 | - /** |
|
163 | - * returns all answer ids from this question Id |
|
164 | - * |
|
165 | - * @author Yoselyn Castillo |
|
166 | - * @return array - $id (answer ids) |
|
167 | - */ |
|
162 | + /** |
|
163 | + * returns all answer ids from this question Id |
|
164 | + * |
|
165 | + * @author Yoselyn Castillo |
|
166 | + * @return array - $id (answer ids) |
|
167 | + */ |
|
168 | 168 | public function selectAnswerId() |
169 | 169 | { |
170 | 170 | $TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER); |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | } |
185 | 185 | |
186 | 186 | return $id; |
187 | - } |
|
187 | + } |
|
188 | 188 | |
189 | 189 | /** |
190 | 190 | * Reads answer information from the data base ordered by parameter |
@@ -195,23 +195,23 @@ discard block |
||
195 | 195 | */ |
196 | 196 | public function readOrderedBy($field, $order='ASC') |
197 | 197 | { |
198 | - $field = Database::escape_string($field); |
|
199 | - if (empty($field)) { |
|
200 | - $field = 'position'; |
|
201 | - } |
|
198 | + $field = Database::escape_string($field); |
|
199 | + if (empty($field)) { |
|
200 | + $field = 'position'; |
|
201 | + } |
|
202 | 202 | |
203 | - if ($order != 'ASC' && $order!='DESC') { |
|
204 | - $order = 'ASC'; |
|
205 | - } |
|
203 | + if ($order != 'ASC' && $order!='DESC') { |
|
204 | + $order = 'ASC'; |
|
205 | + } |
|
206 | 206 | |
207 | - $TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER); |
|
208 | - $TBL_QUIZ = Database::get_course_table(TABLE_QUIZ_QUESTION); |
|
209 | - $questionId = intval($this->questionId); |
|
207 | + $TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER); |
|
208 | + $TBL_QUIZ = Database::get_course_table(TABLE_QUIZ_QUESTION); |
|
209 | + $questionId = intval($this->questionId); |
|
210 | 210 | |
211 | - $sql = "SELECT type FROM $TBL_QUIZ |
|
211 | + $sql = "SELECT type FROM $TBL_QUIZ |
|
212 | 212 | WHERE c_id = {$this->course_id} AND id = $questionId"; |
213 | - $result_question = Database::query($sql); |
|
214 | - $questionType = Database::fetch_array($result_question); |
|
213 | + $result_question = Database::query($sql); |
|
214 | + $questionType = Database::fetch_array($result_question); |
|
215 | 215 | |
216 | 216 | if ($questionType['type'] == DRAGGABLE) { |
217 | 217 | // Random is done by submit.js.tpl |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | return true; |
221 | 221 | } |
222 | 222 | |
223 | - $sql = "SELECT |
|
223 | + $sql = "SELECT |
|
224 | 224 | answer, |
225 | 225 | correct, |
226 | 226 | comment, |
@@ -236,16 +236,16 @@ discard block |
||
236 | 236 | c_id = {$this->course_id} AND |
237 | 237 | question_id='".$questionId."' |
238 | 238 | ORDER BY $field $order"; |
239 | - $result=Database::query($sql); |
|
240 | - |
|
241 | - $i = 1; |
|
242 | - // while a record is found |
|
243 | - $doubt_data = null; |
|
244 | - while ($object = Database::fetch_object($result)) { |
|
245 | - if ($questionType['type'] == UNIQUE_ANSWER_NO_OPTION && $object->position == 666) { |
|
246 | - $doubt_data = $object; |
|
239 | + $result=Database::query($sql); |
|
240 | + |
|
241 | + $i = 1; |
|
242 | + // while a record is found |
|
243 | + $doubt_data = null; |
|
244 | + while ($object = Database::fetch_object($result)) { |
|
245 | + if ($questionType['type'] == UNIQUE_ANSWER_NO_OPTION && $object->position == 666) { |
|
246 | + $doubt_data = $object; |
|
247 | 247 | continue; |
248 | - } |
|
248 | + } |
|
249 | 249 | $this->answer[$i] = $object->answer; |
250 | 250 | $this->correct[$i] = $object->correct; |
251 | 251 | $this->comment[$i] = $object->comment; |
@@ -257,9 +257,9 @@ discard block |
||
257 | 257 | $this->autoId[$i] = $object->id_auto; |
258 | 258 | $this->iid[$i] = $object->iid; |
259 | 259 | $i++; |
260 | - } |
|
260 | + } |
|
261 | 261 | |
262 | - if ($questionType['type'] == UNIQUE_ANSWER_NO_OPTION && !empty($doubt_data)) { |
|
262 | + if ($questionType['type'] == UNIQUE_ANSWER_NO_OPTION && !empty($doubt_data)) { |
|
263 | 263 | $this->answer[$i] = $doubt_data->answer; |
264 | 264 | $this->correct[$i] = $doubt_data->correct; |
265 | 265 | $this->comment[$i] = $doubt_data->comment; |
@@ -271,88 +271,88 @@ discard block |
||
271 | 271 | $this->autoId[$i] = $doubt_data->id_auto; |
272 | 272 | $this->iid[$i] = $doubt_data->iid; |
273 | 273 | $i++; |
274 | - } |
|
274 | + } |
|
275 | 275 | $this->nbrAnswers = $i-1; |
276 | - } |
|
277 | - |
|
278 | - /** |
|
279 | - * returns the autoincrement id identificator |
|
280 | - * |
|
281 | - * @author Juan Carlos Ra�a |
|
282 | - * @return integer - answer num |
|
283 | - */ |
|
276 | + } |
|
277 | + |
|
278 | + /** |
|
279 | + * returns the autoincrement id identificator |
|
280 | + * |
|
281 | + * @author Juan Carlos Ra�a |
|
282 | + * @return integer - answer num |
|
283 | + */ |
|
284 | 284 | public function selectAutoId($id) |
285 | 285 | { |
286 | - return isset($this->autoId[$id]) ? $this->autoId[$id] : 0; |
|
287 | - } |
|
288 | - |
|
289 | - /** |
|
290 | - * returns the number of answers in this question |
|
291 | - * |
|
292 | - * @author Olivier Brouckaert |
|
293 | - * @return integer - number of answers |
|
294 | - */ |
|
295 | - public function selectNbrAnswers() |
|
286 | + return isset($this->autoId[$id]) ? $this->autoId[$id] : 0; |
|
287 | + } |
|
288 | + |
|
289 | + /** |
|
290 | + * returns the number of answers in this question |
|
291 | + * |
|
292 | + * @author Olivier Brouckaert |
|
293 | + * @return integer - number of answers |
|
294 | + */ |
|
295 | + public function selectNbrAnswers() |
|
296 | 296 | { |
297 | - return $this->nbrAnswers; |
|
298 | - } |
|
299 | - |
|
300 | - /** |
|
301 | - * returns the question ID which the answers belong to |
|
302 | - * |
|
303 | - * @author Olivier Brouckaert |
|
304 | - * @return integer - the question ID |
|
305 | - */ |
|
306 | - public function selectQuestionId() |
|
297 | + return $this->nbrAnswers; |
|
298 | + } |
|
299 | + |
|
300 | + /** |
|
301 | + * returns the question ID which the answers belong to |
|
302 | + * |
|
303 | + * @author Olivier Brouckaert |
|
304 | + * @return integer - the question ID |
|
305 | + */ |
|
306 | + public function selectQuestionId() |
|
307 | 307 | { |
308 | - return $this->questionId; |
|
309 | - } |
|
310 | - |
|
311 | - /** |
|
312 | - * returns the question ID of the destination question |
|
313 | - * |
|
314 | - * @author Julio Montoya |
|
315 | - * @param integer $id |
|
316 | - * @return integer - the question ID |
|
317 | - */ |
|
318 | - public function selectDestination($id) |
|
308 | + return $this->questionId; |
|
309 | + } |
|
310 | + |
|
311 | + /** |
|
312 | + * returns the question ID of the destination question |
|
313 | + * |
|
314 | + * @author Julio Montoya |
|
315 | + * @param integer $id |
|
316 | + * @return integer - the question ID |
|
317 | + */ |
|
318 | + public function selectDestination($id) |
|
319 | 319 | { |
320 | - return isset($this->destination[$id]) ? $this->destination[$id] : null; |
|
321 | - } |
|
320 | + return isset($this->destination[$id]) ? $this->destination[$id] : null; |
|
321 | + } |
|
322 | 322 | |
323 | 323 | /** |
324 | - * returns the answer title |
|
325 | - * |
|
326 | - * @author Olivier Brouckaert |
|
327 | - * @param - integer $id - answer ID |
|
328 | - * @return string - answer title |
|
329 | - */ |
|
330 | - public function selectAnswer($id) |
|
331 | - { |
|
332 | - return isset($this->answer[$id]) ? $this->answer[$id] : null; |
|
333 | - } |
|
334 | - |
|
335 | - /** |
|
336 | - * return array answer by id else return a bool |
|
337 | - * @param integer $auto_id |
|
338 | - */ |
|
339 | - public function selectAnswerByAutoId($auto_id) |
|
340 | - { |
|
341 | - $TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER); |
|
342 | - |
|
343 | - $auto_id = intval($auto_id); |
|
344 | - $sql = "SELECT id, answer, id_auto FROM $TBL_ANSWER |
|
324 | + * returns the answer title |
|
325 | + * |
|
326 | + * @author Olivier Brouckaert |
|
327 | + * @param - integer $id - answer ID |
|
328 | + * @return string - answer title |
|
329 | + */ |
|
330 | + public function selectAnswer($id) |
|
331 | + { |
|
332 | + return isset($this->answer[$id]) ? $this->answer[$id] : null; |
|
333 | + } |
|
334 | + |
|
335 | + /** |
|
336 | + * return array answer by id else return a bool |
|
337 | + * @param integer $auto_id |
|
338 | + */ |
|
339 | + public function selectAnswerByAutoId($auto_id) |
|
340 | + { |
|
341 | + $TBL_ANSWER = Database::get_course_table(TABLE_QUIZ_ANSWER); |
|
342 | + |
|
343 | + $auto_id = intval($auto_id); |
|
344 | + $sql = "SELECT id, answer, id_auto FROM $TBL_ANSWER |
|
345 | 345 | WHERE c_id = {$this->course_id} AND id_auto='$auto_id'"; |
346 | - $rs = Database::query($sql); |
|
346 | + $rs = Database::query($sql); |
|
347 | 347 | |
348 | - if (Database::num_rows($rs) > 0) { |
|
349 | - $row = Database::fetch_array($rs, 'ASSOC'); |
|
348 | + if (Database::num_rows($rs) > 0) { |
|
349 | + $row = Database::fetch_array($rs, 'ASSOC'); |
|
350 | 350 | |
351 | - return $row; |
|
352 | - } |
|
351 | + return $row; |
|
352 | + } |
|
353 | 353 | |
354 | - return false; |
|
355 | - } |
|
354 | + return false; |
|
355 | + } |
|
356 | 356 | |
357 | 357 | /** |
358 | 358 | * returns the answer title from an answer's position |
@@ -361,18 +361,18 @@ discard block |
||
361 | 361 | * @param - integer $id - answer ID |
362 | 362 | * @return bool - answer title |
363 | 363 | */ |
364 | - public function selectAnswerIdByPosition($pos) |
|
365 | - { |
|
366 | - foreach ($this->position as $k => $v) { |
|
367 | - if ($v != $pos) { |
|
368 | - continue; |
|
369 | - } |
|
364 | + public function selectAnswerIdByPosition($pos) |
|
365 | + { |
|
366 | + foreach ($this->position as $k => $v) { |
|
367 | + if ($v != $pos) { |
|
368 | + continue; |
|
369 | + } |
|
370 | 370 | |
371 | - return $k; |
|
372 | - } |
|
371 | + return $k; |
|
372 | + } |
|
373 | 373 | |
374 | - return false; |
|
375 | - } |
|
374 | + return false; |
|
375 | + } |
|
376 | 376 | |
377 | 377 | /** |
378 | 378 | * Returns a list of answers |
@@ -381,18 +381,18 @@ discard block |
||
381 | 381 | * of (id, answer, comment, grade) and grade=weighting |
382 | 382 | */ |
383 | 383 | public function getAnswersList($decode = false) |
384 | - { |
|
385 | - $list = array(); |
|
386 | - for ($i = 1; $i <= $this->nbrAnswers; $i++) { |
|
387 | - if (!empty($this->answer[$i])) { |
|
388 | - |
|
389 | - //Avoid problems when parsing elements with accents |
|
390 | - if ($decode) { |
|
391 | - $this->answer[$i] = api_html_entity_decode($this->answer[$i], ENT_QUOTES, api_get_system_encoding()); |
|
392 | - $this->comment[$i] = api_html_entity_decode($this->comment[$i], ENT_QUOTES, api_get_system_encoding()); |
|
393 | - } |
|
394 | - |
|
395 | - $list[] = array( |
|
384 | + { |
|
385 | + $list = array(); |
|
386 | + for ($i = 1; $i <= $this->nbrAnswers; $i++) { |
|
387 | + if (!empty($this->answer[$i])) { |
|
388 | + |
|
389 | + //Avoid problems when parsing elements with accents |
|
390 | + if ($decode) { |
|
391 | + $this->answer[$i] = api_html_entity_decode($this->answer[$i], ENT_QUOTES, api_get_system_encoding()); |
|
392 | + $this->comment[$i] = api_html_entity_decode($this->comment[$i], ENT_QUOTES, api_get_system_encoding()); |
|
393 | + } |
|
394 | + |
|
395 | + $list[] = array( |
|
396 | 396 | 'id' => $i, |
397 | 397 | 'answer' => $this->answer[$i], |
398 | 398 | 'comment' => $this->comment[$i], |
@@ -401,137 +401,137 @@ discard block |
||
401 | 401 | 'hotspot_type' => $this->hotspot_type[$i], |
402 | 402 | 'correct' => $this->correct[$i], |
403 | 403 | 'destination' => $this->destination[$i] |
404 | - ); |
|
404 | + ); |
|
405 | + } |
|
405 | 406 | } |
406 | - } |
|
407 | 407 | |
408 | - return $list; |
|
409 | - } |
|
408 | + return $list; |
|
409 | + } |
|
410 | 410 | |
411 | - /** |
|
412 | - * Returns a list of grades |
|
413 | - * @author Yannick Warnier <[email protected]> |
|
414 | - * @return array List of grades where grade=weighting (?) |
|
415 | - */ |
|
411 | + /** |
|
412 | + * Returns a list of grades |
|
413 | + * @author Yannick Warnier <[email protected]> |
|
414 | + * @return array List of grades where grade=weighting (?) |
|
415 | + */ |
|
416 | 416 | public function getGradesList() |
417 | - { |
|
418 | - $list = array(); |
|
419 | - for ($i = 0; $i<$this->nbrAnswers;$i++){ |
|
420 | - if(!empty($this->answer[$i])){ |
|
421 | - $list[$i] = $this->weighting[$i]; |
|
422 | - } |
|
423 | - } |
|
424 | - return $list; |
|
425 | - } |
|
426 | - |
|
427 | - /** |
|
428 | - * Returns the question type |
|
429 | - * @author Yannick Warnier <[email protected]> |
|
430 | - * @return integer The type of the question this answer is bound to |
|
431 | - */ |
|
417 | + { |
|
418 | + $list = array(); |
|
419 | + for ($i = 0; $i<$this->nbrAnswers;$i++){ |
|
420 | + if(!empty($this->answer[$i])){ |
|
421 | + $list[$i] = $this->weighting[$i]; |
|
422 | + } |
|
423 | + } |
|
424 | + return $list; |
|
425 | + } |
|
426 | + |
|
427 | + /** |
|
428 | + * Returns the question type |
|
429 | + * @author Yannick Warnier <[email protected]> |
|
430 | + * @return integer The type of the question this answer is bound to |
|
431 | + */ |
|
432 | 432 | public function getQuestionType() |
433 | - { |
|
434 | - $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION); |
|
435 | - $sql = "SELECT type FROM $TBL_QUESTIONS |
|
433 | + { |
|
434 | + $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION); |
|
435 | + $sql = "SELECT type FROM $TBL_QUESTIONS |
|
436 | 436 | WHERE c_id = {$this->course_id} AND id = '".$this->questionId."'"; |
437 | - $res = Database::query($sql); |
|
438 | - if (Database::num_rows($res)<=0){ |
|
439 | - return null; |
|
440 | - } |
|
441 | - $row = Database::fetch_array($res); |
|
442 | - |
|
443 | - return $row['type']; |
|
444 | - } |
|
445 | - |
|
446 | - |
|
447 | - /** |
|
448 | - * tells if answer is correct or not |
|
449 | - * |
|
450 | - * @author Olivier Brouckaert |
|
451 | - * @param - integer $id - answer ID |
|
452 | - * @return integer - 0 if bad answer, not 0 if good answer |
|
453 | - */ |
|
437 | + $res = Database::query($sql); |
|
438 | + if (Database::num_rows($res)<=0){ |
|
439 | + return null; |
|
440 | + } |
|
441 | + $row = Database::fetch_array($res); |
|
442 | + |
|
443 | + return $row['type']; |
|
444 | + } |
|
445 | + |
|
446 | + |
|
447 | + /** |
|
448 | + * tells if answer is correct or not |
|
449 | + * |
|
450 | + * @author Olivier Brouckaert |
|
451 | + * @param - integer $id - answer ID |
|
452 | + * @return integer - 0 if bad answer, not 0 if good answer |
|
453 | + */ |
|
454 | 454 | public function isCorrect($id) |
455 | - { |
|
456 | - return isset($this->correct[$id]) ? $this->correct[$id] : null; |
|
457 | - } |
|
458 | - |
|
459 | - /** |
|
460 | - * returns answer comment |
|
461 | - * |
|
462 | - * @author Olivier Brouckaert |
|
463 | - * @param - integer $id - answer ID |
|
464 | - * @return string - answer comment |
|
465 | - */ |
|
455 | + { |
|
456 | + return isset($this->correct[$id]) ? $this->correct[$id] : null; |
|
457 | + } |
|
458 | + |
|
459 | + /** |
|
460 | + * returns answer comment |
|
461 | + * |
|
462 | + * @author Olivier Brouckaert |
|
463 | + * @param - integer $id - answer ID |
|
464 | + * @return string - answer comment |
|
465 | + */ |
|
466 | 466 | public function selectComment($id) |
467 | - { |
|
467 | + { |
|
468 | 468 | return isset($this->comment[$id]) ? $this->comment[$id] : null; |
469 | - } |
|
470 | - |
|
471 | - /** |
|
472 | - * returns answer weighting |
|
473 | - * |
|
474 | - * @author Olivier Brouckaert |
|
475 | - * @param - integer $id - answer ID |
|
476 | - * @param integer $id |
|
477 | - * @return integer - answer weighting |
|
478 | - */ |
|
469 | + } |
|
470 | + |
|
471 | + /** |
|
472 | + * returns answer weighting |
|
473 | + * |
|
474 | + * @author Olivier Brouckaert |
|
475 | + * @param - integer $id - answer ID |
|
476 | + * @param integer $id |
|
477 | + * @return integer - answer weighting |
|
478 | + */ |
|
479 | 479 | public function selectWeighting($id) |
480 | - { |
|
481 | - return isset($this->weighting[$id]) ? $this->weighting[$id] : null; |
|
482 | - } |
|
483 | - |
|
484 | - /** |
|
485 | - * returns answer position |
|
486 | - * |
|
487 | - * @author Olivier Brouckaert |
|
488 | - * @param - integer $id - answer ID |
|
489 | - * @return integer - answer position |
|
490 | - */ |
|
491 | - function selectPosition($id) |
|
492 | - { |
|
493 | - return isset($this->position[$id]) ? $this->position[$id] : null; |
|
494 | - } |
|
495 | - |
|
496 | - /** |
|
497 | - * returns answer hotspot coordinates |
|
498 | - * |
|
499 | - * @author Olivier Brouckaert |
|
500 | - * @param integer Answer ID |
|
501 | - * @param integer $id |
|
502 | - * @return integer Answer position |
|
503 | - */ |
|
480 | + { |
|
481 | + return isset($this->weighting[$id]) ? $this->weighting[$id] : null; |
|
482 | + } |
|
483 | + |
|
484 | + /** |
|
485 | + * returns answer position |
|
486 | + * |
|
487 | + * @author Olivier Brouckaert |
|
488 | + * @param - integer $id - answer ID |
|
489 | + * @return integer - answer position |
|
490 | + */ |
|
491 | + function selectPosition($id) |
|
492 | + { |
|
493 | + return isset($this->position[$id]) ? $this->position[$id] : null; |
|
494 | + } |
|
495 | + |
|
496 | + /** |
|
497 | + * returns answer hotspot coordinates |
|
498 | + * |
|
499 | + * @author Olivier Brouckaert |
|
500 | + * @param integer Answer ID |
|
501 | + * @param integer $id |
|
502 | + * @return integer Answer position |
|
503 | + */ |
|
504 | 504 | public function selectHotspotCoordinates($id) |
505 | - { |
|
506 | - return isset($this->hotspot_coordinates[$id]) ? $this->hotspot_coordinates[$id] : null; |
|
507 | - } |
|
508 | - |
|
509 | - /** |
|
510 | - * returns answer hotspot type |
|
511 | - * |
|
512 | - * @author Toon Keppens |
|
513 | - * @param integer Answer ID |
|
514 | - * @param integer $id |
|
515 | - * @return integer Answer position |
|
516 | - */ |
|
505 | + { |
|
506 | + return isset($this->hotspot_coordinates[$id]) ? $this->hotspot_coordinates[$id] : null; |
|
507 | + } |
|
508 | + |
|
509 | + /** |
|
510 | + * returns answer hotspot type |
|
511 | + * |
|
512 | + * @author Toon Keppens |
|
513 | + * @param integer Answer ID |
|
514 | + * @param integer $id |
|
515 | + * @return integer Answer position |
|
516 | + */ |
|
517 | 517 | public function selectHotspotType($id) |
518 | - { |
|
519 | - return isset($this->hotspot_type[$id]) ? $this->hotspot_type[$id] : null; |
|
520 | - } |
|
521 | - |
|
522 | - /** |
|
523 | - * Creates a new answer |
|
524 | - * |
|
525 | - * @author Olivier Brouckaert |
|
526 | - * @param string $answer answer title |
|
527 | - * @param integer $correct 0 if bad answer, not 0 if good answer |
|
528 | - * @param string $comment answer comment |
|
529 | - * @param integer $weighting answer weighting |
|
530 | - * @param integer $position answer position |
|
531 | - * @param array $new_hotspot_coordinates Coordinates for hotspot exercises (optional) |
|
532 | - * @param integer $new_hotspot_type Type for hotspot exercises (optional) |
|
518 | + { |
|
519 | + return isset($this->hotspot_type[$id]) ? $this->hotspot_type[$id] : null; |
|
520 | + } |
|
521 | + |
|
522 | + /** |
|
523 | + * Creates a new answer |
|
524 | + * |
|
525 | + * @author Olivier Brouckaert |
|
526 | + * @param string $answer answer title |
|
527 | + * @param integer $correct 0 if bad answer, not 0 if good answer |
|
528 | + * @param string $comment answer comment |
|
529 | + * @param integer $weighting answer weighting |
|
530 | + * @param integer $position answer position |
|
531 | + * @param array $new_hotspot_coordinates Coordinates for hotspot exercises (optional) |
|
532 | + * @param integer $new_hotspot_type Type for hotspot exercises (optional) |
|
533 | 533 | * @param string $destination |
534 | - */ |
|
534 | + */ |
|
535 | 535 | public function createAnswer( |
536 | 536 | $answer, |
537 | 537 | $correct, |
@@ -542,7 +542,7 @@ discard block |
||
542 | 542 | $new_hotspot_type = null, |
543 | 543 | $destination = '' |
544 | 544 | ) { |
545 | - $this->new_nbrAnswers++; |
|
545 | + $this->new_nbrAnswers++; |
|
546 | 546 | $id = $this->new_nbrAnswers; |
547 | 547 | $this->new_answer[$id] = $answer; |
548 | 548 | $this->new_correct[$id] = $correct; |
@@ -552,7 +552,7 @@ discard block |
||
552 | 552 | $this->new_hotspot_coordinates[$id] = $new_hotspot_coordinates; |
553 | 553 | $this->new_hotspot_type[$id] = $new_hotspot_type; |
554 | 554 | $this->new_destination[$id] = $destination; |
555 | - } |
|
555 | + } |
|
556 | 556 | |
557 | 557 | /** |
558 | 558 | * Updates an answer |
@@ -593,31 +593,31 @@ discard block |
||
593 | 593 | ]; |
594 | 594 | |
595 | 595 | Database::update($answerTable, $params, ['iid = ?' => intval($iid)]); |
596 | - } |
|
596 | + } |
|
597 | 597 | |
598 | - /** |
|
599 | - * Records answers into the data base |
|
600 | - * |
|
601 | - * @author Olivier Brouckaert |
|
602 | - */ |
|
598 | + /** |
|
599 | + * Records answers into the data base |
|
600 | + * |
|
601 | + * @author Olivier Brouckaert |
|
602 | + */ |
|
603 | 603 | public function save() |
604 | 604 | { |
605 | - $answerTable = Database::get_course_table(TABLE_QUIZ_ANSWER); |
|
606 | - $questionId = intval($this->questionId); |
|
605 | + $answerTable = Database::get_course_table(TABLE_QUIZ_ANSWER); |
|
606 | + $questionId = intval($this->questionId); |
|
607 | 607 | |
608 | - $c_id = $this->course['real_id']; |
|
608 | + $c_id = $this->course['real_id']; |
|
609 | 609 | $correctList = []; |
610 | 610 | $answerList = []; |
611 | 611 | |
612 | - for ($i=1; $i <= $this->new_nbrAnswers; $i++) { |
|
613 | - $answer = $this->new_answer[$i]; |
|
614 | - $correct = isset($this->new_correct[$i]) ? $this->new_correct[$i] : ''; |
|
615 | - $comment = isset($this->new_comment[$i]) ? $this->new_comment[$i] : ''; |
|
616 | - $weighting = isset($this->new_weighting[$i]) ? $this->new_weighting[$i] : ''; |
|
617 | - $position = isset($this->new_position[$i]) ? $this->new_position[$i] : ''; |
|
618 | - $hotspot_coordinates = isset($this->new_hotspot_coordinates[$i]) ? $this->new_hotspot_coordinates[$i] : ''; |
|
619 | - $hotspot_type = isset($this->new_hotspot_type[$i]) ? $this->new_hotspot_type[$i] : ''; |
|
620 | - $destination = isset($this->new_destination[$i]) ? $this->new_destination[$i] : ''; |
|
612 | + for ($i=1; $i <= $this->new_nbrAnswers; $i++) { |
|
613 | + $answer = $this->new_answer[$i]; |
|
614 | + $correct = isset($this->new_correct[$i]) ? $this->new_correct[$i] : ''; |
|
615 | + $comment = isset($this->new_comment[$i]) ? $this->new_comment[$i] : ''; |
|
616 | + $weighting = isset($this->new_weighting[$i]) ? $this->new_weighting[$i] : ''; |
|
617 | + $position = isset($this->new_position[$i]) ? $this->new_position[$i] : ''; |
|
618 | + $hotspot_coordinates = isset($this->new_hotspot_coordinates[$i]) ? $this->new_hotspot_coordinates[$i] : ''; |
|
619 | + $hotspot_type = isset($this->new_hotspot_type[$i]) ? $this->new_hotspot_type[$i] : ''; |
|
620 | + $destination = isset($this->new_destination[$i]) ? $this->new_destination[$i] : ''; |
|
621 | 621 | $autoId = $this->selectAutoId($i); |
622 | 622 | $iid = isset($this->iid[$i]) ? $this->iid[$i] : 0; |
623 | 623 | |
@@ -651,11 +651,11 @@ discard block |
||
651 | 651 | |
652 | 652 | $correctAnswerId = $answer->selectAnswerIdByPosition($correct); |
653 | 653 | |
654 | - // Continue to avoid matching question bug if $correctAnswerId returns false |
|
655 | - // See : https://support.chamilo.org/issues/8334 |
|
656 | - if ($questionType == MATCHING && !$correctAnswerId) { |
|
657 | - continue; |
|
658 | - } |
|
654 | + // Continue to avoid matching question bug if $correctAnswerId returns false |
|
655 | + // See : https://support.chamilo.org/issues/8334 |
|
656 | + if ($questionType == MATCHING && !$correctAnswerId) { |
|
657 | + continue; |
|
658 | + } |
|
659 | 659 | |
660 | 660 | $correctAnswerAutoId = $answer->selectAutoId($correct); |
661 | 661 | |
@@ -723,35 +723,35 @@ discard block |
||
723 | 723 | } |
724 | 724 | } |
725 | 725 | |
726 | - // moves $new_* arrays |
|
727 | - $this->answer = $this->new_answer; |
|
728 | - $this->correct = $this->new_correct; |
|
729 | - $this->comment = $this->new_comment; |
|
730 | - $this->weighting = $this->new_weighting; |
|
731 | - $this->position = $this->new_position; |
|
732 | - $this->hotspot_coordinates = $this->new_hotspot_coordinates; |
|
733 | - $this->hotspot_type = $this->new_hotspot_type; |
|
734 | - $this->nbrAnswers = $this->new_nbrAnswers; |
|
735 | - $this->destination = $this->new_destination; |
|
736 | - |
|
737 | - $this->cancel(); |
|
738 | - } |
|
739 | - |
|
740 | - /** |
|
741 | - * Duplicates answers by copying them into another question |
|
742 | - * |
|
743 | - * @author Olivier Brouckaert |
|
744 | - * @param int question id |
|
726 | + // moves $new_* arrays |
|
727 | + $this->answer = $this->new_answer; |
|
728 | + $this->correct = $this->new_correct; |
|
729 | + $this->comment = $this->new_comment; |
|
730 | + $this->weighting = $this->new_weighting; |
|
731 | + $this->position = $this->new_position; |
|
732 | + $this->hotspot_coordinates = $this->new_hotspot_coordinates; |
|
733 | + $this->hotspot_type = $this->new_hotspot_type; |
|
734 | + $this->nbrAnswers = $this->new_nbrAnswers; |
|
735 | + $this->destination = $this->new_destination; |
|
736 | + |
|
737 | + $this->cancel(); |
|
738 | + } |
|
739 | + |
|
740 | + /** |
|
741 | + * Duplicates answers by copying them into another question |
|
742 | + * |
|
743 | + * @author Olivier Brouckaert |
|
744 | + * @param int question id |
|
745 | 745 | * @param array destination course info (result of the function api_get_course_info() ) |
746 | 746 | * @param string $newQuestionId |
747 | - */ |
|
747 | + */ |
|
748 | 748 | public function duplicate($newQuestionId, $course_info = null) |
749 | 749 | { |
750 | 750 | if (empty($course_info)) { |
751 | 751 | $course_info = $this->course; |
752 | 752 | } |
753 | 753 | |
754 | - $TBL_REPONSES = Database :: get_course_table(TABLE_QUIZ_ANSWER); |
|
754 | + $TBL_REPONSES = Database :: get_course_table(TABLE_QUIZ_ANSWER); |
|
755 | 755 | $fixed_list = array(); |
756 | 756 | |
757 | 757 | if (self::getQuestionType() == MULTIPLE_ANSWER_TRUE_FALSE || |
@@ -765,7 +765,7 @@ discard block |
||
765 | 765 | |
766 | 766 | if (!empty($origin_options)) { |
767 | 767 | foreach ($origin_options as $item) { |
768 | - $new_option_list[] = $item['id']; |
|
768 | + $new_option_list[] = $item['id']; |
|
769 | 769 | } |
770 | 770 | } |
771 | 771 | |
@@ -779,12 +779,12 @@ discard block |
||
779 | 779 | } |
780 | 780 | } |
781 | 781 | |
782 | - // if at least one answer |
|
783 | - if ($this->nbrAnswers) { |
|
784 | - // inserts new answers into data base |
|
785 | - $c_id = $course_info['real_id']; |
|
782 | + // if at least one answer |
|
783 | + if ($this->nbrAnswers) { |
|
784 | + // inserts new answers into data base |
|
785 | + $c_id = $course_info['real_id']; |
|
786 | 786 | |
787 | - for ($i=1;$i <= $this->nbrAnswers;$i++) { |
|
787 | + for ($i=1;$i <= $this->nbrAnswers;$i++) { |
|
788 | 788 | if ($this->course['id'] != $course_info['id']) { |
789 | 789 | $this->answer[$i] = DocumentManager::replace_urls_inside_content_html_from_copy_course( |
790 | 790 | $this->answer[$i], |
@@ -798,8 +798,8 @@ discard block |
||
798 | 798 | ); |
799 | 799 | } |
800 | 800 | |
801 | - $answer = $this->answer[$i]; |
|
802 | - $correct = $this->correct[$i]; |
|
801 | + $answer = $this->answer[$i]; |
|
802 | + $correct = $this->correct[$i]; |
|
803 | 803 | |
804 | 804 | if (self::getQuestionType() == MULTIPLE_ANSWER_TRUE_FALSE || |
805 | 805 | self::getQuestionType() == MULTIPLE_ANSWER_TRUE_FALSE |
@@ -807,12 +807,12 @@ discard block |
||
807 | 807 | $correct = $fixed_list[intval($correct)]; |
808 | 808 | } |
809 | 809 | |
810 | - $comment = $this->comment[$i]; |
|
811 | - $weighting = $this->weighting[$i]; |
|
812 | - $position = $this->position[$i]; |
|
813 | - $hotspot_coordinates = $this->hotspot_coordinates[$i]; |
|
814 | - $hotspot_type = $this->hotspot_type[$i]; |
|
815 | - $destination = $this->destination[$i]; |
|
810 | + $comment = $this->comment[$i]; |
|
811 | + $weighting = $this->weighting[$i]; |
|
812 | + $position = $this->position[$i]; |
|
813 | + $hotspot_coordinates = $this->hotspot_coordinates[$i]; |
|
814 | + $hotspot_type = $this->hotspot_type[$i]; |
|
815 | + $destination = $this->destination[$i]; |
|
816 | 816 | |
817 | 817 | $params = [ |
818 | 818 | 'c_id' => $c_id, |
@@ -832,9 +832,9 @@ discard block |
||
832 | 832 | $sql = "UPDATE $TBL_REPONSES SET id = iid, id_auto = iid WHERE iid = $id"; |
833 | 833 | Database::query($sql); |
834 | 834 | } |
835 | - } |
|
835 | + } |
|
836 | 836 | } |
837 | - } |
|
837 | + } |
|
838 | 838 | |
839 | 839 | /** |
840 | 840 | * Get the necessary JavaScript for some answers |
@@ -852,25 +852,25 @@ discard block |
||
852 | 852 | </script>"; |
853 | 853 | } |
854 | 854 | |
855 | - /** |
|
856 | - * Check if a answer is correct by an answer auto id |
|
857 | - * @param $needle int The answer auto id |
|
858 | - * @return bool |
|
859 | - */ |
|
860 | - public function isCorrectByAutoId($needle) |
|
861 | - { |
|
862 | - $key = 0; |
|
863 | - |
|
864 | - foreach ($this->autoId as $autoIdKey => $autoId) { |
|
865 | - if ($autoId == $needle) { |
|
866 | - $key = $autoIdKey; |
|
867 | - } |
|
868 | - } |
|
869 | - |
|
870 | - if (!$key) { |
|
871 | - return false; |
|
872 | - } |
|
873 | - |
|
874 | - return $this->isCorrect($key) ? true : false; |
|
875 | - } |
|
855 | + /** |
|
856 | + * Check if a answer is correct by an answer auto id |
|
857 | + * @param $needle int The answer auto id |
|
858 | + * @return bool |
|
859 | + */ |
|
860 | + public function isCorrectByAutoId($needle) |
|
861 | + { |
|
862 | + $key = 0; |
|
863 | + |
|
864 | + foreach ($this->autoId as $autoIdKey => $autoId) { |
|
865 | + if ($autoId == $needle) { |
|
866 | + $key = $autoIdKey; |
|
867 | + } |
|
868 | + } |
|
869 | + |
|
870 | + if (!$key) { |
|
871 | + return false; |
|
872 | + } |
|
873 | + |
|
874 | + return $this->isCorrect($key) ? true : false; |
|
875 | + } |
|
876 | 876 | } |