2024-11-21 18:59:07 +00:00
|
|
|
<?php
|
|
|
|
require_once('../../config.php');
|
|
|
|
require_once($CFG->libdir . '/adminlib.php');
|
|
|
|
require_once($CFG->libdir . '/gradelib.php');
|
|
|
|
require_once($CFG->libdir . '/tablelib.php');
|
|
|
|
require_once($CFG->libdir . '/formslib.php');
|
|
|
|
require_once($CFG->dirroot . '/user/selector/lib.php');
|
|
|
|
require_once('classes/user_selector.php');
|
|
|
|
require_once('classes/usergrades_form.php');
|
|
|
|
|
|
|
|
// Set up the page context and other configurations
|
|
|
|
admin_externalpage_setup('report_usergrades_details', '', null, '', array('capability' => 'report/usergrades:view'));
|
|
|
|
|
|
|
|
// Instantiate the form
|
|
|
|
$mform = new usergrades_form();
|
|
|
|
echo $OUTPUT->header();
|
|
|
|
echo $OUTPUT->heading(get_string('usergradesreport', 'report_usergrades'));
|
|
|
|
|
|
|
|
// Form processing and displaying is done here
|
|
|
|
if ($mform->is_cancelled()) {
|
|
|
|
// Handle form cancellation, if necessary
|
|
|
|
redirect(new moodle_url('/admin/report.php'));
|
|
|
|
} else if ($data = $mform->get_data()) {
|
|
|
|
$userid = $data->userid;
|
|
|
|
|
|
|
|
// Fetch and display user grades if a user is selected
|
|
|
|
if (!empty($userid)) {
|
|
|
|
$user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
|
|
|
|
$courses = enrol_get_users_courses($user->id, true);
|
2024-11-21 19:02:34 +00:00
|
|
|
$questions = $DB->get_records('question');
|
2024-11-21 18:59:07 +00:00
|
|
|
|
2024-11-21 19:57:29 +00:00
|
|
|
// User details
|
|
|
|
|
|
|
|
echo $OUTPUT->heading(get_string('userdetails', 'report_usergrades'), 3);
|
|
|
|
|
|
|
|
$user_table = new html_table();
|
|
|
|
$user_table->head = array(get_string('field'), get_string('value'));
|
|
|
|
|
2024-11-21 19:59:02 +00:00
|
|
|
$user_table->data[] = array(get_string('username', 'report_usergrades'), $user->username);
|
|
|
|
$user_table->data[] = array(get_string('firstname', 'report_usergrades'), $user->firstname);
|
|
|
|
$user_table->data[] = array(get_string('lastname', 'report_usergrades'), $user->lastname);
|
|
|
|
$user_table->data[] = array(get_string('email', 'report_usergrades'), $user->email);
|
2024-11-21 19:57:29 +00:00
|
|
|
|
2024-11-21 18:59:07 +00:00
|
|
|
foreach ($courses as $course) {
|
|
|
|
echo $OUTPUT->heading($course->fullname, 3);
|
|
|
|
|
|
|
|
$quizzes = $DB->get_records('quiz', array('course' => $course->id));
|
|
|
|
|
|
|
|
if ($quizzes) {
|
|
|
|
echo $OUTPUT->heading(get_string('quizzes', 'report_usergrades'), 4);
|
|
|
|
|
|
|
|
foreach ($quizzes as $quiz) {
|
2024-11-21 19:08:44 +00:00
|
|
|
$quiz_questions = $DB->get_records('quiz_slots', array('quizid' => $quiz->id));
|
2024-11-21 18:59:07 +00:00
|
|
|
$quiz_attempts = $DB->get_records('quiz_attempts', array('quiz' => $quiz->id, 'userid' => $user->id));
|
|
|
|
|
|
|
|
if ($quiz_attempts) {
|
|
|
|
echo $OUTPUT->heading($quiz->name, 5);
|
|
|
|
|
|
|
|
foreach ($quiz_attempts as $attempt) {
|
|
|
|
echo $OUTPUT->heading(get_string('attempt', 'report_usergrades') . ' ' . $attempt->attempt, 6);
|
|
|
|
|
|
|
|
$attempt_table = new html_table();
|
|
|
|
$attempt_table->head = array(get_string('question', 'report_usergrades'), get_string('response', 'report_usergrades'), get_string('grade', 'report_usergrades'));
|
|
|
|
|
2024-11-21 19:44:27 +00:00
|
|
|
$question_usages = $DB->get_records('question_usages', array('id' => $attempt->uniqueid));
|
2024-11-21 19:54:21 +00:00
|
|
|
|
2024-11-21 19:38:23 +00:00
|
|
|
foreach ($question_usages as $question_usage) {
|
2024-11-21 19:45:58 +00:00
|
|
|
$question_attempts = $DB->get_records('question_attempts', array('questionusageid' => $question_usage->id));
|
2024-11-21 18:59:07 +00:00
|
|
|
|
2024-11-21 19:45:58 +00:00
|
|
|
foreach ($question_attempts as $question_attempt) {
|
|
|
|
$question = $questions[$question_attempt->questionid];
|
|
|
|
$response = $question_attempt->responsesummary;
|
2024-11-21 18:59:07 +00:00
|
|
|
|
2024-11-21 19:51:24 +00:00
|
|
|
$question_grades = $DB->get_records('question_attempt_steps', array('questionattemptid' => $question_attempt->id));
|
2024-11-21 19:45:58 +00:00
|
|
|
|
2024-11-21 19:48:10 +00:00
|
|
|
foreach ($question_grades as $question_grade) {
|
2024-11-21 19:52:40 +00:00
|
|
|
if ($question_grade->fraction) {
|
2024-11-21 19:54:21 +00:00
|
|
|
$attempt_table->data[] = array($question->name . ': ' . $question->questiontext, $response, $question_grade->fraction);
|
2024-11-21 19:52:40 +00:00
|
|
|
}
|
2024-11-21 19:48:10 +00:00
|
|
|
}
|
2024-11-21 19:45:58 +00:00
|
|
|
}
|
2024-11-21 18:59:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
echo html_writer::table($attempt_table);
|
|
|
|
|
|
|
|
$total_grade = $DB->get_record('quiz_grades', array('quiz' => $quiz->id, 'userid' => $user->id));
|
|
|
|
|
2024-11-21 19:44:27 +00:00
|
|
|
echo $OUTPUT->heading(get_string('totalgrade', 'report_usergrades') . ': ' . $total_grade->grade . ' / ' . $quiz->grade, 6);
|
2024-11-21 18:59:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
echo $OUTPUT->notification(get_string('nouserselected', 'report_usergrades'), 'notifyproblem');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Display form if no data is submitted
|
|
|
|
$mform->display();
|
|
|
|
}
|
|
|
|
|
|
|
|
echo $OUTPUT->footer();
|