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();