Skip to content
Permalink
Browse files

MDL-30179 gradereport_user: Add ability to view report as other user

  • Loading branch information...
merrill-oakland committed Oct 10, 2016
1 parent d9520bc commit ca2cb90fedc2e4a633d96787c80a4b3c38f62ba9
@@ -29,9 +29,16 @@
$courseid = required_param('id', PARAM_INT);
$userid = optional_param('userid', $USER->id, PARAM_INT);
$userview = optional_param('userview', 0, PARAM_INT);
$PAGE->set_url(new moodle_url('/grade/report/user/index.php', array('id'=>$courseid)));
if ($userview == 0) {
$userview = get_user_preferences('gradereport_user_view_user', GRADE_REPORT_USER_VIEW_USER);
} else {
set_user_preference('gradereport_user_view_user', $userview);
}
/// basic access checks
if (!$course = $DB->get_record('course', array('id' => $courseid))) {
print_error('nocourseid');
@@ -103,6 +110,15 @@
$defaultgradeshowactiveenrol = !empty($CFG->grade_report_showonlyactiveenrol);
$showonlyactiveenrol = get_user_preferences('grade_report_showonlyactiveenrol', $defaultgradeshowactiveenrol);
$showonlyactiveenrol = $showonlyactiveenrol || !has_capability('moodle/course:viewsuspendedusers', $context);
$renderer = $PAGE->get_renderer('gradereport_user');
if ($userview == GRADE_REPORT_USER_VIEW_USER) {
$viewasuser = true;
} else {
$viewasuser = false;
}
if (empty($userid)) {
$gui = new graded_users_iterator($course, null, $currentgroup);
$gui->require_active_enrolment($showonlyactiveenrol);
@@ -112,13 +128,14 @@
groups_print_course_menu($course, $gpr->get_return_url('index.php?id='.$courseid, array('userid'=>0)));
if ($user_selector) {
$renderer = $PAGE->get_renderer('gradereport_user');
echo $renderer->graded_users_selector('user', $course, $userid, $currentgroup, true);
}
echo $renderer->view_user_selector($userid, $userview);
while ($userdata = $gui->next_user()) {
$user = $userdata->user;
$report = new grade_report_user($courseid, $gpr, $context, $user->id);
$report = new grade_report_user($courseid, $gpr, $context, $user->id, $viewasuser);
$studentnamelink = html_writer::link(new moodle_url('/user/view.php', array('id' => $report->user->id, 'course' => $courseid)), fullname($report->user));
echo $OUTPUT->heading(get_string('pluginname', 'gradereport_user') . ' - ' . $studentnamelink);
@@ -130,7 +147,7 @@
}
$gui->close();
} else { // Only show one user's report
$report = new grade_report_user($courseid, $gpr, $context, $userid);
$report = new grade_report_user($courseid, $gpr, $context, $userid, $viewasuser);
$studentnamelink = html_writer::link(new moodle_url('/user/view.php', array('id' => $report->user->id, 'course' => $courseid)), fullname($report->user));
print_grade_page_head($courseid, 'report', 'user', get_string('pluginname', 'gradereport_user') . ' - ' . $studentnamelink,
@@ -139,11 +156,12 @@
groups_print_course_menu($course, $gpr->get_return_url('index.php?id='.$courseid, array('userid'=>0)));
if ($user_selector) {
$renderer = $PAGE->get_renderer('gradereport_user');
$showallusersoptions = true;
echo $renderer->graded_users_selector('user', $course, $userid, $currentgroup, $showallusersoptions);
}
echo $renderer->view_user_selector($userid, $userview);
if ($currentgroup and !groups_is_member($currentgroup, $userid)) {
echo $OUTPUT->notification(get_string('groupusernotmember', 'error'));
} else {
@@ -25,4 +25,7 @@
$string['eventgradereportviewed'] = 'Grade user report viewed';
$string['pluginname'] = 'User report';
$string['user:view'] = 'View your own grade report';
$string['myself'] = 'Myself';
$string['otheruser'] = 'User';
$string['tablesummary'] = 'The table is arranged as a list of graded items including categories of graded items. When items are in a category they will be indicated as such.';
$string['viewas'] = 'View report as';
@@ -30,6 +30,9 @@
define("GRADE_REPORT_USER_HIDE_UNTIL", 1);
define("GRADE_REPORT_USER_SHOW_HIDDEN", 2);
define("GRADE_REPORT_USER_VIEW_SELF", 1);
define("GRADE_REPORT_USER_VIEW_USER", 2);
/**
* Class providing an API for the user report building and displaying.
* @uses grade_report
@@ -43,4 +43,29 @@ public function graded_users_selector($report, $course, $userid, $groupid, $incl
return $output;
}
/**
* Creates and renders the single select box for the user view.
*
* @param int $userid The selected userid
* @param int $userview The current view user setting constant
* @return string
*/
public function view_user_selector($userid, $userview) {
global $PAGE, $USER;
$url = $PAGE->url;
if ($userid != $USER->id) {
$url->param('userid', $userid);
}
$options = array(GRADE_REPORT_USER_VIEW_USER => get_string('otheruser', 'gradereport_user'),
GRADE_REPORT_USER_VIEW_SELF => get_string('myself', 'gradereport_user'));
$select = new single_select($url, 'userview', $options, $userview, null);
$select->label = get_string('viewas', 'gradereport_user');
$output = html_writer::tag('div', $this->output->render($select), array('class' => 'view_users_selector'));
return $output;
}
}
@@ -3,7 +3,14 @@
margin-bottom: 5px;
}

.path-grade-report-user #graded_users_selector .singleselect label {
.path-grade-report-user .view_users_selector {
clear: both;
float: right;
margin-bottom: 5px;
}

.path-grade-report-user #graded_users_selector .singleselect label,
.path-grade-report-user .view_users_selector .singleselect label {
display: inline-block;
}

0 comments on commit ca2cb90

Please sign in to comment.
You can’t perform that action at this time.