parent
acd5199c7a
commit
592ec636bb
@ -1,69 +1,106 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
use Chamilo\CoreBundle\Entity\TrackEExercises; |
||||
|
||||
require_once __DIR__.'/../inc/global.inc.php'; |
||||
|
||||
$isAllowedToEdit = api_is_allowed_to_edit(true, true); |
||||
|
||||
if (!$isAllowedToEdit) { |
||||
api_not_allowed(true); |
||||
exit; |
||||
} |
||||
|
||||
if (!isset($_REQUEST['user'], $_REQUEST['exercise'], $_REQUEST['id'])) { |
||||
api_not_allowed(true); |
||||
exit; |
||||
} |
||||
|
||||
$courseId = api_get_course_int_id(); |
||||
$sessionId = api_get_session_id(); |
||||
$em = Database::getManager(); |
||||
|
||||
$trackedExercise = $em |
||||
->getRepository('ChamiloCoreBundle:TrackEExercises') |
||||
->find(intval($_REQUEST['id'])); |
||||
/** @var TrackEExercises $trackedExercise */ |
||||
$trackedExercise = $em->getRepository('ChamiloCoreBundle:TrackEExercises')->find($_REQUEST['id']); |
||||
|
||||
if ($trackedExercise->getExeUserId() != intval($_REQUEST['user']) || |
||||
$trackedExercise->getExeExoId() != intval($_REQUEST['exercise']) |
||||
) { |
||||
api_not_allowed(true); |
||||
if (empty($trackedExercise)) { |
||||
exit; |
||||
} |
||||
|
||||
$attempts = $em->getRepository('ChamiloCoreBundle:TrackEAttempt') |
||||
->findBy([ |
||||
'exeId' => $trackedExercise->getExeId(), |
||||
'userId' => $trackedExercise->getExeUserId(), |
||||
]); |
||||
$studentId = $trackedExercise->getExeUserId(); |
||||
$exerciseId = $trackedExercise->getExeExoId(); |
||||
$exeId = $trackedExercise->getExeId(); |
||||
|
||||
$newResult = 0; |
||||
/** @var \Chamilo\CoreBundle\Entity\TrackEAttempt $attempt */ |
||||
foreach ($attempts as $attempt) { |
||||
$questionId = $attempt->getQuestionId(); |
||||
|
||||
$question = $em->find('ChamiloCourseBundle:CQuizQuestion', $questionId); |
||||
if ($studentId != intval($_REQUEST['user']) || |
||||
$exerciseId != intval($_REQUEST['exercise']) |
||||
) { |
||||
exit; |
||||
} |
||||
|
||||
if (!$question) { |
||||
continue; |
||||
} |
||||
$questionList = $trackedExercise->getDataTracking(); |
||||
|
||||
$answers = $em->getRepository('ChamiloCourseBundle:CQuizAnswer')->findBy([ |
||||
'questionId' => $questionId, |
||||
'correct' => 1, |
||||
]); |
||||
if (empty($questionList)) { |
||||
exit; |
||||
} |
||||
|
||||
$newMarks = 0; |
||||
foreach ($answers as $answer) { |
||||
if ($answer->getId() != $attempt->getAnswer()) { |
||||
continue; |
||||
} |
||||
$newMarks += $answer->getPonderation(); |
||||
$questionList = explode(',', $questionList); |
||||
|
||||
$exercise = new Exercise($courseId); |
||||
$exercise->read($exerciseId); |
||||
$totalScore = 0; |
||||
$totalWeight = 0; |
||||
|
||||
foreach ($questionList as $questionId) { |
||||
$question = Question::read($questionId, $courseId); |
||||
$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 |
||||
); |
||||
} |
||||
|
||||
$newResult += $newMarks; |
||||
$attempt->setMarks($newMarks); |
||||
$em->merge($attempt); |
||||
// Adding the new score. |
||||
$totalScore += $result['score']; |
||||
} |
||||
|
||||
$trackedExercise->setExeResult($newResult); |
||||
$remindList = $trackedExercise->getQuestionsToCheck(); |
||||
if (!empty($remindList)) { |
||||
$remindList = explode(',', $remindList); |
||||
} |
||||
|
||||
$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); |
||||
|
||||
$em->merge($trackedExercise); |
||||
$em->flush(); |
||||
echo $totalScore.'/'.$totalWeight; |
||||
Loading…
Reference in new issue