fix: Refactors question processing logic

Updates the question handling mechanism to use question usages
and attempts, replacing the previous reliance on question states
and attempt steps. This change enhances the accuracy of response
and grading information by aligning with the current database
structure.

Improves performance and maintainability by streamlining data
retrieval from the database.
This commit is contained in:
Kumi 2024-11-21 20:38:23 +01:00
parent afb5e818ad
commit d983f550bf
Signed by: kumi
GPG key ID: ECBCC9082395383F

View file

@ -55,13 +55,16 @@ if ($mform->is_cancelled()) {
$attempt_table = new html_table();
$attempt_table->head = array(get_string('question', 'report_usergrades'), get_string('response', 'report_usergrades'), get_string('grade', 'report_usergrades'));
foreach ($quiz_questions as $quiz_question) {
$question = $questions[$quiz_question->question];
$question_usages = $DB->get_records('question_usages', array('id' => $quiz_attempt->uniqueid));
foreach ($question_usages as $question_usage) {
$question_attempt = $DB->get_record('question_attempts', array('questionusageid' => $question_usage->id));
$question = $questions[$question_attempt->questionid];
$response = $question_attempt->responsesummary;
$response = $DB->get_record('question_states', array('attempt' => $attempt->id, 'question' => $question->id));
$grade = $DB->get_record('question_attempt_steps', array('questionattemptid' => $response->id));
$question_grade = $DB->get_record('question_attempt_steps', array('questionattemptid' => $question_attempt->id));
$attempt_table->data[] = array($question->name, $response->answer, $grade->fraction);
$attempt_table->data[] = array($question->name, $response, $question_grade->fraction);
}
echo html_writer::table($attempt_table);