123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- <?php
- /* For licensing terms, see /license.txt */
- use Chamilo\CoreBundle\Entity\TrackEExercises;
- require_once __DIR__.'/../inc/global.inc.php';
- api_protect_course_script(true);
- $isAllowedToEdit = api_is_allowed_to_edit(true, true);
- if (!$isAllowedToEdit) {
- exit;
- }
- if (!isset($_REQUEST['user'], $_REQUEST['exercise'], $_REQUEST['id'])) {
- exit;
- }
- $courseId = api_get_course_int_id();
- $sessionId = api_get_session_id();
- $em = Database::getManager();
- /** @var TrackEExercises $trackedExercise */
- $trackedExercise = $em->getRepository('ChamiloCoreBundle:TrackEExercises')->find($_REQUEST['id']);
- if (empty($trackedExercise)) {
- exit;
- }
- $studentId = $trackedExercise->getExeUserId();
- $exerciseId = $trackedExercise->getExeExoId();
- $exeId = $trackedExercise->getExeId();
- if ($studentId != intval($_REQUEST['user']) ||
- $exerciseId != intval($_REQUEST['exercise'])
- ) {
- exit;
- }
- $questionList = $trackedExercise->getDataTracking();
- if (empty($questionList)) {
- exit;
- }
- $questionList = explode(',', $questionList);
- $exercise = new Exercise($courseId);
- $exercise->read($exerciseId);
- $totalScore = 0;
- $totalWeight = 0;
- $useEvaluationPlugin = false;
- $pluginEvaluation = QuestionOptionsEvaluationPlugin::create();
- if ('true' === $pluginEvaluation->get(QuestionOptionsEvaluationPlugin::SETTING_ENABLE)) {
- $formula = $pluginEvaluation->getFormulaForExercise($exerciseId);
- if (!empty($formula)) {
- $useEvaluationPlugin = true;
- }
- }
- if (!$useEvaluationPlugin) {
- foreach ($questionList as $questionId) {
- $question = Question::read($questionId, api_get_course_info());
- $totalWeight += $question->selectWeighting();
- // We're inside *one* question. Go through each possible answer for this question
- if ($question->type === MULTIPLE_ANSWER_TRUE_FALSE_DEGREE_CERTAINTY) {
- $result = $exercise->manage_answer(
- $exeId,
- $questionId,
- [],
- 'exercise_result',
- [],
- false,
- true,
- false,
- $exercise->selectPropagateNeg(),
- [],
- [],
- true
- );
- } else {
- $result = $exercise->manage_answer(
- $exeId,
- $questionId,
- [],
- 'exercise_result',
- [],
- false,
- true,
- false,
- $exercise->selectPropagateNeg(),
- [],
- [],
- true
- );
- }
- // Adding the new score.
- $totalScore += $result['score'];
- }
- $remindList = $trackedExercise->getQuestionsToCheck();
- if (!empty($remindList)) {
- $remindList = explode(',', $remindList);
- }
- } else {
- $totalScore = $pluginEvaluation->getResultWithFormula($exeId, $formula);
- $totalWeight = $pluginEvaluation->getMaxScore();
- }
- $table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
- $sql = "UPDATE $table SET
- exe_result = '$totalScore',
- exe_weighting = '$totalWeight'
- WHERE exe_id = $exeId";
- Database::query($sql);
- echo $totalScore.'/'.$totalWeight;
|