feat: Add user grades report functionality
Introduces a new report to display grades for selected users. Includes a user selection form and grade display logic. Sets up plugin metadata and localization strings. Enables administrators to view a user's grades across courses. Includes default plugin settings and version information.
This commit is contained in:
commit
f89cf45a8e
4 changed files with 90 additions and 0 deletions
71
index.php
Normal file
71
index.php
Normal file
|
@ -0,0 +1,71 @@
|
|||
<?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');
|
||||
|
||||
// Set up the page context and other configurations
|
||||
admin_externalpage_setup('report_usergrades');
|
||||
|
||||
/**
|
||||
* Form class for user selection
|
||||
*/
|
||||
class usergrades_form extends moodleform {
|
||||
public function definition() {
|
||||
$mform = $this->_form;
|
||||
|
||||
// User selector
|
||||
$user_selector = new user_selector('userid', array('multiselect' => false));
|
||||
$user_selector->set_label(get_string('user'));
|
||||
$user_selector->get_view($mform);
|
||||
|
||||
// Add form action buttons
|
||||
$this->add_action_buttons(false, get_string('showgrades', 'report_usergrades'));
|
||||
}
|
||||
}
|
||||
|
||||
// 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 ($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);
|
||||
|
||||
$table = new flexible_table('user-grades-report');
|
||||
$table->define_baseurl($CFG->wwwroot.'/report/usergrades/index.php');
|
||||
$table->define_columns(array('course', 'activity', 'grade'));
|
||||
$table->define_headers(array('Course', 'Activity', 'Grade'));
|
||||
|
||||
$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();
|
||||
$grade_display = $grade ? $grade->str_grade : '-';
|
||||
|
||||
$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();
|
5
lang/en/report_usergrades.php
Normal file
5
lang/en/report_usergrades.php
Normal file
|
@ -0,0 +1,5 @@
|
|||
$string['pluginname'] = 'User Grades Report';
|
||||
$string['usergradesreport'] = 'User Grades Report';
|
||||
$string['nouserselected'] = 'No user selected. Please select a user to view their grades.';
|
||||
$string['showgrades'] = 'Show Grades';
|
||||
$string['user'] = 'User';
|
6
settings.php
Normal file
6
settings.php
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?php
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
if ($hassiteconfig) { // Needs this condition or there is error on login page
|
||||
$ADMIN->add('reports', new admin_externalpage('report_usergrades', get_string('pluginname', 'report_usergrades'), "$CFG->wwwroot/report/usergrades/index.php"));
|
||||
}
|
8
version.php
Normal file
8
version.php
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->component = 'report_usergrades';
|
||||
$plugin->version = 2024111900;
|
||||
$plugin->requires = 2022041900;
|
||||
$plugin->maturity = MATURITY_ALPHA;
|
||||
$plugin->release = 'v1.0';
|
Loading…
Reference in a new issue