Skip to content

Commit

Permalink
Exercise: Add differentiation option to display user answer or score …
Browse files Browse the repository at this point in the history
…in questions report - refs BT#20366
  • Loading branch information
cfasanando committed Jan 10, 2023
1 parent e1a3099 commit 4d27191
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion main/inc/lib/exercise.lib.php
Expand Up @@ -1946,6 +1946,7 @@ public static function getTrackExerciseAttemptsTable(Exercise $objExercise)

$extraField = new ExtraField('user');
$extraFieldValue = new ExtraFieldValue('user');
$extraFieldQuestion = new ExtraFieldValue('question');

$extraFields = $extraField->get_all(['filter = ?' => 1]);
$userExtraFields = [];
Expand Down Expand Up @@ -2013,8 +2014,30 @@ public static function getTrackExerciseAttemptsTable(Exercise $objExercise)
false,
$objExercise->selectPropagateNeg()
);

$displayValue = $questionResult['score'];
$differentiation = $extraFieldQuestion->get_values_by_handler_and_field_variable($questionId, 'differentiation');
if (!empty($differentiation['value'])) {
$answerType = $questionObj->selectType();
$objAnswerTmp = new Answer($questionId, api_get_course_int_id());
$userChoice = [];
if (!empty($questionResult['correct_answer_id']) && HOT_SPOT_DELINEATION != $answerType) {
foreach ($questionResult['correct_answer_id'] as $answerId) {
$answer = $objAnswerTmp->getAnswerByAutoId($answerId);
if (!empty($answer)) {
$userChoice[] = $answer['answer'];
} else {
$answer = $objAnswerTmp->selectAnswer($answerId);
$userChoice[] = $answer;
}
}
}
if (!empty($userChoice)) {
$displayValue = implode('|', $userChoice);
}
}
$questionModalUrl = api_get_path(WEB_AJAX_PATH).'exercise.ajax.php?'.api_get_cidreq().'&a=show_question_attempt&exercise='.$exerciseId.'&question='.$questionId.'&exe_id='.$row['exe_id'];
$data[$x][$questionId] = '<a href="'.$questionModalUrl.'" class="ajax" data-title="'.$questionName.'" title="'.get_lang('ClicToSeeDetails').'">'.$questionResult['score'].'</a>';
$data[$x][$questionId] = '<a href="'.$questionModalUrl.'" class="ajax" data-title="'.$questionName.'" title="'.get_lang('ClicToSeeDetails').'">'.$displayValue.'</a>';
}
}
$x++;
Expand Down

0 comments on commit 4d27191

Please sign in to comment.