2024-11-19 15:06:49 +00:00
|
|
|
<?php
|
|
|
|
require_once('../../config.php');
|
2024-11-20 14:10:57 +00:00
|
|
|
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');
|
2024-11-21 18:59:07 +00:00
|
|
|
require_once('classes/user_selector.php');
|
|
|
|
require_once('classes/usergrades_form.php');
|
2024-11-19 15:06:49 +00:00
|
|
|
|
|
|
|
// Set up the page context and other configurations
|
2024-11-20 16:38:16 +00:00
|
|
|
admin_externalpage_setup('report_usergrades', '', null, '', array('capability' => 'report/usergrades:view'));
|
2024-11-19 15:06:49 +00:00
|
|
|
|
|
|
|
// 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
|
2024-11-20 14:10:57 +00:00
|
|
|
if ($mform->is_cancelled()) {
|
|
|
|
// Handle form cancellation, if necessary
|
|
|
|
redirect(new moodle_url('/admin/report.php'));
|
|
|
|
} else if ($data = $mform->get_data()) {
|
2024-11-19 15:06:49 +00:00
|
|
|
$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);
|
|
|
|
|
|
|
|
$table = new flexible_table('user-grades-report');
|
2024-11-20 14:10:57 +00:00
|
|
|
$table->define_baseurl($CFG->wwwroot . '/report/usergrades/index.php');
|
2024-11-19 15:06:49 +00:00
|
|
|
$table->define_columns(array('course', 'activity', 'grade'));
|
2024-11-20 14:10:57 +00:00
|
|
|
$table->define_headers(array(get_string('course'), get_string('activity'), get_string('grade', 'report_usergrades')));
|
2024-11-19 15:06:49 +00:00
|
|
|
|
|
|
|
$table->setup();
|
|
|
|
|
|
|
|
foreach ($courses as $course) {
|
|
|
|
$grade_items = grade_item::fetch_all(array('courseid' => $course->id));
|
|
|
|
|
|
|
|
foreach ($grade_items as $item) {
|
|
|
|
$grade = grade_grade::fetch(array('itemid' => $item->id, 'userid' => $user->id));
|
|
|
|
$gradename = $item->get_name();
|
2024-11-20 14:10:57 +00:00
|
|
|
$grade_display = $grade ? $grade->finalgrade . ' / ' . $grade->rawgrademax : '-';
|
2024-11-19 15:06:49 +00:00
|
|
|
|
|
|
|
$table->add_data(array(format_string($course->fullname), format_string($gradename), $grade_display));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$table->finish_output();
|
|
|
|
} else {
|
|
|
|
echo $OUTPUT->notification(get_string('nouserselected', 'report_usergrades'), 'notifyproblem');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Display form if no data is submitted
|
|
|
|
$mform->display();
|
|
|
|
}
|
|
|
|
|
|
|
|
echo $OUTPUT->footer();
|