recalculate_scores.php 1.2 KB

123456789101112131415161718192021222324252627282930
  1. <?php
  2. $exerciseId = $app['request']->get('exerciseId');
  3. $exercise = new Exercise();
  4. $exercise->read($exerciseId);
  5. $examResults = get_all_exercise_results($exerciseId, api_get_course_int_id(), api_get_session_id(), true);
  6. foreach ($examResults as $exerciseAttempt) {
  7. $exeId = $exerciseAttempt['exe_id'];
  8. $questionList = $exerciseAttempt['question_list'];
  9. // Cleaning total result in order to recalculate:
  10. $stat_table = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  11. $sql = 'UPDATE '.$stat_table.' SET exe_result = 0, exe_weighting = 0 WHERE exe_id = '.$exeId;
  12. Database::query($sql);
  13. $totalWeight = 0;
  14. foreach ($questionList as $questionId => $questionAttempt) {
  15. $result = $exercise->manageAnswers($exeId, $questionId, $questionAttempt['answer'], 'exercise_show', array(), true, true, false, array(), true);
  16. $totalWeight += floatval($result['weight']);
  17. }
  18. $sql = 'UPDATE '.$stat_table.' SET exe_weighting = '.$totalWeight.' WHERE exe_id = '.$exeId;
  19. Database::query($sql);
  20. }
  21. $urlMainExercise = api_get_path(WEB_CODE_PATH).'exercice/';
  22. header('Location: '.$urlMainExercise.'exercise_report.php?exerciseId='.$exerciseId.'&'.api_get_cidreq());
  23. exit;