lp_ajax_last_update_status.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. // Name of the language file that needs to be included.
  28. $language_file[] = 'learnpath';
  29. require_once 'back_compat.inc.php';
  30. /**
  31. * Writes an item's new values into the database and returns the operation result
  32. * @param integer Learnpath ID
  33. * @param integer User ID
  34. * @param integer View ID
  35. * @param integer Item ID
  36. * @return string JavaScript operations to execute as soon as returned
  37. */
  38. function last_update_status($lp_id, $user_id, $view_id, $item_id) {
  39. error_log(__LINE__);
  40. global $_configuration;
  41. $debug = 0;
  42. $return = '';
  43. if ($debug > 0) { error_log('In last_update_status('.$lp_id.','.$user_id.','.$view_id.','.$item_id.')', 0); }
  44. require_once 'learnpath.class.php';
  45. require_once 'scorm.class.php';
  46. require_once 'learnpathItem.class.php';
  47. require_once 'scormItem.class.php';
  48. $mylp = learnpath::getLpFromSession(api_get_course_id(), $lp_id, $user_id);
  49. // This function should only be used for SCORM paths.
  50. if ($mylp->get_type() != 2) {
  51. return;
  52. }
  53. $prereq_check = $mylp->prerequisites_match($item_id);
  54. $mystatus = '';
  55. if ($prereq_check === true) {
  56. error_log(__LINE__);
  57. // Launch the prerequisites check and set error if needed.
  58. $mylpi =& $mylp->items[$item_id];
  59. $mystatus_in_db = $mylpi->get_status(true);
  60. error_log($mystatus_in_db);
  61. if ($mystatus_in_db == 'not attempted' or $mystatus_in_db == '') {
  62. error_log(__LINE__);
  63. $mystatus = 'completed';
  64. $mastery_score = $mylpi->get_mastery_score();
  65. if ($mastery_score != -1) {
  66. error_log(__LINE__);
  67. $score = $mylpi->get_score();
  68. if ($score != 0 && $score >= $mastery_score) {
  69. error_log(__LINE__);
  70. $mystatus = 'passed';
  71. } else {
  72. error_log(__LINE__);
  73. $mystatus = 'failed';
  74. }
  75. }
  76. error_log(__LINE__);
  77. $mylpi->set_status($mystatus);
  78. $mylp->save_item($item_id, false);
  79. } else {
  80. error_log(__LINE__);
  81. return $return;
  82. }
  83. } else {
  84. error_log(__LINE__);
  85. return $return;
  86. }
  87. error_log(__LINE__);
  88. $mytotal = $mylp->get_total_items_count_without_chapters();
  89. $mycomplete = $mylp->get_complete_items_count();
  90. $myprogress_mode = $mylp->get_progress_bar_mode();
  91. $myprogress_mode = ($myprogress_mode==''?'%':$myprogress_mode);
  92. $return .= "update_toc('".$mystatus."','".$item_id."','no');";
  93. error_log('Return is now '.$return);
  94. $update_list = $mylp->get_update_queue();
  95. foreach ($update_list as $my_upd_id => $my_upd_status) {
  96. 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.
  97. $return .= "update_toc('".$my_upd_status."','".$my_upd_id."','no');";
  98. }
  99. }
  100. $return .= "update_progress_bar('$mycomplete','$mytotal','$myprogress_mode');";
  101. $return .="update_stats();";
  102. return $return;
  103. //return $objResponse;
  104. }
  105. error_log(__LINE__);
  106. echo last_update_status(
  107. $_REQUEST['lid'],
  108. $_REQUEST['uid'],
  109. $_REQUEST['vid'],
  110. $_REQUEST['iid']);