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