recalculate.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CoreBundle\Entity\TrackEExercises;
  4. require_once __DIR__.'/../inc/global.inc.php';
  5. api_protect_course_script(true);
  6. $isAllowedToEdit = api_is_allowed_to_edit(true, true);
  7. if (!$isAllowedToEdit) {
  8. exit;
  9. }
  10. if (!isset($_REQUEST['user'], $_REQUEST['exercise'], $_REQUEST['id'])) {
  11. exit;
  12. }
  13. $courseId = api_get_course_int_id();
  14. $sessionId = api_get_session_id();
  15. $em = Database::getManager();
  16. /** @var TrackEExercises $trackedExercise */
  17. $trackedExercise = $em->getRepository('ChamiloCoreBundle:TrackEExercises')->find($_REQUEST['id']);
  18. if (empty($trackedExercise)) {
  19. exit;
  20. }
  21. $studentId = $trackedExercise->getExeUserId();
  22. $exerciseId = $trackedExercise->getExeExoId();
  23. $exeId = $trackedExercise->getExeId();
  24. if ($studentId != intval($_REQUEST['user']) ||
  25. $exerciseId != intval($_REQUEST['exercise'])
  26. ) {
  27. exit;
  28. }
  29. $questionList = $trackedExercise->getDataTracking();
  30. if (empty($questionList)) {
  31. exit;
  32. }
  33. $questionList = explode(',', $questionList);
  34. $exercise = new Exercise($courseId);
  35. $exercise->read($exerciseId);
  36. $totalScore = 0;
  37. $totalWeight = 0;
  38. $useEvaluationPlugin = false;
  39. $pluginEvaluation = QuestionOptionsEvaluationPlugin::create();
  40. if ('true' === $pluginEvaluation->get(QuestionOptionsEvaluationPlugin::SETTING_ENABLE)) {
  41. $formula = $pluginEvaluation->getFormulaForExercise($exerciseId);
  42. if (!empty($formula)) {
  43. $useEvaluationPlugin = true;
  44. }
  45. }
  46. if (!$useEvaluationPlugin) {
  47. foreach ($questionList as $questionId) {
  48. $question = Question::read($questionId, api_get_course_info());
  49. $totalWeight += $question->selectWeighting();
  50. // We're inside *one* question. Go through each possible answer for this question
  51. if ($question->type === MULTIPLE_ANSWER_TRUE_FALSE_DEGREE_CERTAINTY) {
  52. $result = $exercise->manage_answer(
  53. $exeId,
  54. $questionId,
  55. [],
  56. 'exercise_result',
  57. [],
  58. false,
  59. true,
  60. false,
  61. $exercise->selectPropagateNeg(),
  62. [],
  63. [],
  64. true
  65. );
  66. } else {
  67. $result = $exercise->manage_answer(
  68. $exeId,
  69. $questionId,
  70. [],
  71. 'exercise_result',
  72. [],
  73. false,
  74. true,
  75. false,
  76. $exercise->selectPropagateNeg(),
  77. [],
  78. [],
  79. true
  80. );
  81. }
  82. // Adding the new score.
  83. $totalScore += $result['score'];
  84. }
  85. $remindList = $trackedExercise->getQuestionsToCheck();
  86. if (!empty($remindList)) {
  87. $remindList = explode(',', $remindList);
  88. }
  89. } else {
  90. $totalScore = $pluginEvaluation->getResultWithFormula($exeId, $formula);
  91. $totalWeight = $pluginEvaluation->getMaxScore();
  92. }
  93. $table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
  94. $sql = "UPDATE $table SET
  95. exe_result = '$totalScore',
  96. exe_weighting = '$totalWeight'
  97. WHERE exe_id = $exeId";
  98. Database::query($sql);
  99. echo $totalScore.'/'.$totalWeight;