lp_ajax_last_update_status.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This script contains the server part of the xajax interaction process. The
  5. * client part is located in lp_api.php or other api's.
  6. * This script exists exclusively to comply with the SCORM 1.2 rules notes that
  7. * say that if the SCO doesn't give a status throughout its execution, then the
  8. * status should be automatically set to 'completed', then the score should be
  9. * evaluated against mastery_score and, if a raw score and mastery_score value
  10. * are set, assign the final status based on that.
  11. * As such, this script will:
  12. * 1 - check the current status for the given element is still 'not attempted'
  13. * 2 - check if there is a mastery score
  14. * 3 - check if there is a raw score
  15. * 4 - if 2 or 3 are false, change the status to 'completed', else compare
  16. * whether the raw score is higher than the mastery score. If not, the status
  17. * will be set to 'failed', if yes, the status will be set to 'passed'
  18. * 5 - update the status in the table of contents
  19. * @package chamilo.learnpath
  20. * @author Yannick Warnier <yannick.warnier@beeznest.com>
  21. */
  22. /**
  23. * Code
  24. */
  25. // Flag to allow for anonymous user - needs to be set before global.inc.php'
  26. $use_anonymous = true;
  27. require_once '../inc/global.inc.php';
  28. /**
  29. * Writes an item's new values into the database and returns the operation result
  30. * @param integer Learnpath ID
  31. * @param integer User ID
  32. * @param integer View ID
  33. * @param integer Item ID
  34. * @return string JavaScript operations to execute as soon as returned
  35. */
  36. function last_update_status($lp_id, $user_id, $view_id, $item_id) {
  37. error_log(__LINE__);
  38. global $_configuration;
  39. $debug = 0;
  40. $return = '';
  41. if ($debug > 0) { error_log('In last_update_status('.$lp_id.','.$user_id.','.$view_id.','.$item_id.')', 0); }
  42. $mylp = learnpath::getLpFromSession(api_get_course_id(), $lp_id, $user_id);
  43. // This function should only be used for SCORM paths.
  44. if ($mylp->get_type() != 2) {
  45. return;
  46. }
  47. $prereq_check = $mylp->prerequisites_match($item_id);
  48. $mystatus = '';
  49. if ($prereq_check === true) {
  50. error_log(__LINE__);
  51. // Launch the prerequisites check and set error if needed.
  52. $mylpi =& $mylp->items[$item_id];
  53. $mystatus_in_db = $mylpi->get_status(true);
  54. error_log($mystatus_in_db);
  55. if ($mystatus_in_db == 'not attempted' or $mystatus_in_db == '') {
  56. error_log(__LINE__);
  57. $mystatus = 'completed';
  58. $mastery_score = $mylpi->get_mastery_score();
  59. if ($mastery_score != -1) {
  60. error_log(__LINE__);
  61. $score = $mylpi->get_score();
  62. if ($score != 0 && $score >= $mastery_score) {
  63. error_log(__LINE__);
  64. $mystatus = 'passed';
  65. } else {
  66. error_log(__LINE__);
  67. $mystatus = 'failed';
  68. }
  69. }
  70. error_log(__LINE__);
  71. $mylpi->set_status($mystatus);
  72. $mylp->save_item($item_id, false);
  73. } else {
  74. error_log(__LINE__);
  75. return $return;
  76. }
  77. } else {
  78. error_log(__LINE__);
  79. return $return;
  80. }
  81. error_log(__LINE__);
  82. $mytotal = $mylp->get_total_items_count_without_chapters();
  83. $mycomplete = $mylp->get_complete_items_count();
  84. $myprogress_mode = $mylp->get_progress_bar_mode();
  85. $myprogress_mode = ($myprogress_mode==''?'%':$myprogress_mode);
  86. $return .= "update_toc('".$mystatus."','".$item_id."','no');";
  87. error_log('Return is now '.$return);
  88. $update_list = $mylp->get_update_queue();
  89. foreach ($update_list as $my_upd_id => $my_upd_status) {
  90. if ($my_upd_id != $item_id) { // Only update the status from other items (i.e. parents and brothers), do not update current as we just did it already.
  91. $return .= "update_toc('".$my_upd_status."','".$my_upd_id."','no');";
  92. }
  93. }
  94. $return .= "update_progress_bar('$mycomplete','$mytotal','$myprogress_mode');";
  95. $return .="update_stats();";
  96. return $return;
  97. //return $objResponse;
  98. }
  99. error_log(__LINE__);
  100. echo last_update_status(
  101. $_REQUEST['lid'],
  102. $_REQUEST['uid'],
  103. $_REQUEST['vid'],
  104. $_REQUEST['iid']);