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

This commit is contained in:
Eric Merrill 2016-10-10 09:03:11 -04:00
parent d9520bc04e
commit ca2cb90fed
9 changed files with 307 additions and 5 deletions

View File

@ -29,9 +29,16 @@ require_once $CFG->dirroot.'/grade/report/user/lib.php';
$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 @@ if (has_capability('moodle/grade:viewall', $context)) { //Teachers will see all
$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 @@ if (has_capability('moodle/grade:viewall', $context)) { //Teachers will see all
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 @@ if (has_capability('moodle/grade:viewall', $context)) { //Teachers will see all
}
$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 @@ if (has_capability('moodle/grade:viewall', $context)) { //Teachers will see all
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 {

View File

@ -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';

View File

@ -30,6 +30,9 @@ define("GRADE_REPORT_USER_HIDE_HIDDEN", 0);
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

View File

@ -43,4 +43,29 @@ class gradereport_user_renderer extends plugin_renderer_base {
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;
}
}

View File

@ -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;
}

View File

@ -0,0 +1,218 @@
@core @core_grades @gradereport_user
Feature: View the user report as the student will see it
In order to know what grades students will see
As a teacher
I need to be able to view the user report as that other user
Background:
Given the following "courses" exist:
| fullname | shortname | category | groupmode |
| Course 1 | C1 | 0 | 1 |
And the following "users" exist:
| username | firstname | lastname | email | idnumber |
| teacher1 | Teacher | 1 | teacher1@example.com | t1 |
| student1 | Student | 1 | student1@example.com | s1 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
And the following "grade categories" exist:
| fullname | course |
| Sub category 1 | C1 |
| Sub category 2 | C1 |
And the following "activities" exist:
| activity | course | idnumber | name | intro | gradecategory| grade |
| assign | C1 | a1 | Test assignment one | Submit something! | Sub category 1 | 100 |
| assign | C1 | a2 | Test assignment two | Submit something! | Sub category 1 | 100 |
| assign | C1 | a3 | Test assignment three | Submit something! | Sub category 2 | 100 |
| assign | C1 | a4 | Test assignment four | Submit something! | Sub category 2 | 100 |
And the following "activities" exist:
| activity | course | idnumber | name | intro | grade |
| assign | C1 | a5 | Test assignment five | Submit something! | 100 |
| assign | C1 | a6 | Test assignment six | Submit something! | 100 |
And I log in as "teacher1"
And I follow "Course 1"
And I navigate to "Gradebook setup" node in "Course administration"
And I hide the grade item "Test assignment six"
And I hide the grade item "Sub category 2"
And I navigate to "Grades" node in "Course administration"
And I turn editing mode on
And I change window size to "large"
And I give the grade "80.00" to the user "Student 1" for the grade item "Test assignment one"
And I give the grade "35.00" to the user "Student 1" for the grade item "Test assignment two"
And I give the grade "100.00" to the user "Student 1" for the grade item "Test assignment three"
And I give the grade "50.00" to the user "Student 1" for the grade item "Test assignment four"
And I give the grade "21.00" to the user "Student 1" for the grade item "Test assignment five"
And I give the grade "97.00" to the user "Student 1" for the grade item "Test assignment six"
And I press "Save changes"
And I change window size to "medium"
Scenario: View the report as the teacher themselves
When I navigate to "User report" node in "Grade administration"
And I select "Student 1" from the "Select all or one user" singleselect
And I select "Myself" from the "View report as" singleselect
Then the following should exist in the "user-grade" table:
| Grade item | Calculated weight | Grade | Range | Percentage | Contribution to course total |
| Test assignment one | 50.00 % | 80.00 | 0100 | 80.00 % | 13.33 % |
| Test assignment two | 50.00 % | 35.00 | 0100 | 35.00 % | 5.83 % |
| Sub category 1 total | 33.33 % | 115.00 | 0200 | 57.50 % | - |
| Test assignment three | 50.00 % | 100.00 | 0100 | 100.00 % | 16.67 % |
| Test assignment four | 50.00 % | 50.00 | 0100 | 50.00 % | 8.33 % |
| Sub category 2 total | 33.33 % | 150.00 | 0200 | 75.00 % | - |
| Test assignment five | 16.67 % | 21.00 | 0100 | 21.00 % | 3.50 % |
| Test assignment six | 16.67 % | 97.00 | 0100 | 97.00 % | 16.17 % |
| Course total | - | 383.00 | 0600 | 63.83 % | - |
Scenario: View the report as the student from both the teachers and students perspective
When I navigate to "User report" node in "Grade administration"
And I select "Student 1" from the "Select all or one user" singleselect
And I select "User" from the "View report as" singleselect
Then the following should exist in the "user-grade" table:
| Grade item | Calculated weight | Grade | Range | Percentage | Contribution to course total |
| Test assignment one | - | 80.00 | 0100 | 80.00 % | - |
| Test assignment two | - | 35.00 | 0100 | 35.00 % | - |
| Sub category 1 total | 33.33 % | - | 0200 | - | - |
| Test assignment five | - | 21.00 | 0100 | 21.00 % | - |
| Course total | - | - | 0600 | - | - |
And the following should not exist in the "user-grade" table:
| Grade item |
| Test assignment three |
| Test assignment four |
| Sub category 2 total |
| Test assignment six |
And I log out
And I log in as "student1"
And I follow "Course 1"
And I navigate to "Grades" node in "Course administration"
Then the following should exist in the "user-grade" table:
| Grade item | Calculated weight | Grade | Range | Percentage | Contribution to course total |
| Test assignment one | - | 80.00 | 0100 | 80.00 % | - |
| Test assignment two | - | 35.00 | 0100 | 35.00 % | - |
| Sub category 1 total | 33.33 % | - | 0200 | - | - |
| Test assignment five | - | 21.00 | 0100 | 21.00 % | - |
| Course total | - | - | 0600 | - | - |
And the following should not exist in the "user-grade" table:
| Grade item |
| Test assignment three |
| Test assignment four |
| Sub category 2 total |
| Test assignment six |
Scenario: View the report as the student from both the teachers and students perspective with totals excluding hidden
Given I navigate to "Course grade settings" node in "Grade administration > Setup"
And I set the field with xpath "//select[@name='report_user_showtotalsifcontainhidden']" to "Show totals excluding hidden items"
And I press "Save changes"
And I navigate to "User report" node in "Grade administration"
When I select "Student 1" from the "Select all or one user" singleselect
And I select "User" from the "View report as" singleselect
Then the following should exist in the "user-grade" table:
| Grade item | Calculated weight | Grade | Range | Percentage | Contribution to course total |
| Test assignment one | 50.00 % | 80.00 | 0100 | 80.00 % | 26.67 % |
| Test assignment two | 50.00 % | 35.00 | 0100 | 35.00 % | 11.67 % |
| Sub category 1 total | 66.67 % | 115.00 | 0200 | 57.50 | - |
| Test assignment five | 33.33 % | 21.00 | 0100 | 21.00 % | 7.00 % |
| Course total | - | 136.00 | 0300 | 45.33 % | - |
And the following should not exist in the "user-grade" table:
| Grade item |
| Test assignment three |
| Test assignment four |
| Sub category 2 total |
| Test assignment six |
And I log out
And I log in as "student1"
And I follow "Course 1"
And I navigate to "Grades" node in "Course administration"
Then the following should exist in the "user-grade" table:
| Grade item | Calculated weight | Grade | Range | Percentage | Contribution to course total |
| Test assignment one | 50.00 % | 80.00 | 0100 | 80.00 % | 26.67 % |
| Test assignment two | 50.00 % | 35.00 | 0100 | 35.00 % | 11.67 % |
| Sub category 1 total | 66.67 % | 115.00 | 0200 | 57.50 | - |
| Test assignment five | 33.33 % | 21.00 | 0100 | 21.00 % | 7.00 % |
| Course total | - | 136.00 | 0300 | 45.33 % | - |
And the following should not exist in the "user-grade" table:
| Grade item |
| Test assignment three |
| Test assignment four |
| Sub category 2 total |
| Test assignment six |
Scenario: View the report as the student from both the teachers and students perspective with totals including hidden
Given I navigate to "Course grade settings" node in "Grade administration > Setup"
And I set the field with xpath "//select[@name='report_user_showtotalsifcontainhidden']" to "Show totals including hidden items"
And I press "Save changes"
And I navigate to "User report" node in "Grade administration"
When I select "Student 1" from the "Select all or one user" singleselect
And I select "User" from the "View report as" singleselect
Then the following should exist in the "user-grade" table:
| Grade item | Calculated weight | Grade | Range | Percentage | Contribution to course total |
| Test assignment one | 50.00 % | 80.00 | 0100 | 80.00 % | 13.33 % |
| Test assignment two | 50.00 % | 35.00 | 0100 | 35.00 % | 5.83 % |
| Sub category 1 total | 33.33 % | 115.00 | 0200 | 57.50 % | - |
| Test assignment five | 16.67 % | 21.00 | 0100 | 21.00 % | 3.50 % |
| Course total | - | 383.00 | 0600 | 63.83 % | - |
And the following should not exist in the "user-grade" table:
| Grade item |
| Test assignment three |
| Test assignment four |
| Sub category 2 total |
| Test assignment six |
And I log out
And I log in as "student1"
And I follow "Course 1"
And I navigate to "Grades" node in "Course administration"
Then the following should exist in the "user-grade" table:
| Grade item | Calculated weight | Grade | Range | Percentage | Contribution to course total |
| Test assignment one | 50.00 % | 80.00 | 0100 | 80.00 % | 13.33 % |
| Test assignment two | 50.00 % | 35.00 | 0100 | 35.00 % | 5.83 % |
| Sub category 1 total | 33.33 % | 115.00 | 0200 | 57.50 % | - |
| Test assignment five | 16.67 % | 21.00 | 0100 | 21.00 % | 3.50 % |
| Course total | - | 383.00 | 0600 | 63.83 % | - |
And the following should not exist in the "user-grade" table:
| Grade item |
| Test assignment three |
| Test assignment four |
| Sub category 2 total |
| Test assignment six |
Scenario: View the report as the student from both the teachers and students perspective when the student can view hidden
Given I log out
And I log in as "admin"
And I set the following system permissions of "Student" role:
| capability | permission |
| moodle/grade:viewhidden | Allow |
And I log out
And I log in as "teacher1"
And I follow "Course 1"
And I navigate to "Gradebook setup" node in "Course administration"
And I navigate to "Course grade settings" node in "Grade administration > Setup"
And I set the field with xpath "//select[@name='report_user_showtotalsifcontainhidden']" to "Show totals excluding hidden items"
And I press "Save changes"
And I navigate to "User report" node in "Grade administration"
When I select "Student 1" from the "Select all or one user" singleselect
And I select "User" from the "View report as" singleselect
Then the following should exist in the "user-grade" table:
| Grade item | Calculated weight | Grade | Range | Percentage | Contribution to course total |
| Test assignment one | 50.00 % | 80.00 | 0100 | 80.00 % | 13.33 % |
| Test assignment two | 50.00 % | 35.00 | 0100 | 35.00 % | 5.83 % |
| Sub category 1 total | 33.33 % | 115.00 | 0200 | 57.50 % | - |
| Test assignment three | 50.00 % | 100.00 | 0100 | 100.00 % | 16.67 % |
| Test assignment four | 50.00 % | 50.00 | 0100 | 50.00 % | 8.33 % |
| Sub category 2 total | 33.33 % | 150.00 | 0200 | 75.00 % | - |
| Test assignment five | 16.67 % | 21.00 | 0100 | 21.00 % | 3.50 % |
| Test assignment six | 16.67 % | 97.00 | 0100 | 97.00 % | 16.17 % |
| Course total | - | 383.00 | 0600 | 63.83 % | - |
And I log out
And I log in as "student1"
And I follow "Course 1"
And I navigate to "Grades" node in "Course administration"
Then the following should exist in the "user-grade" table:
| Grade item | Calculated weight | Grade | Range | Percentage | Contribution to course total |
| Test assignment one | 50.00 % | 80.00 | 0100 | 80.00 % | 13.33 % |
| Test assignment two | 50.00 % | 35.00 | 0100 | 35.00 % | 5.83 % |
| Sub category 1 total | 33.33 % | 115.00 | 0200 | 57.50 % | - |
| Test assignment three | 50.00 % | 100.00 | 0100 | 100.00 % | 16.67 % |
| Test assignment four | 50.00 % | 50.00 | 0100 | 50.00 % | 8.33 % |
| Sub category 2 total | 33.33 % | 150.00 | 0200 | 75.00 % | - |
| Test assignment five | 16.67 % | 21.00 | 0100 | 21.00 % | 3.50 % |
| Test assignment six | 16.67 % | 97.00 | 0100 | 97.00 % | 16.17 % |
| Course total | - | 383.00 | 0600 | 63.83 % | - |

View File

@ -91,6 +91,31 @@ class behat_grade extends behat_base {
$this->execute('behat_forms::press_button', $this->escape($savechanges));
}
/**
* Hids a grade item or category.
*
* Teacher must be either on the grade setup page or on the Grader report page with editing mode turned on.
*
* @Given /^I hide the grade item "(?P<grade_item_string>(?:[^"]|\\")*)"$/
* @param string $gradeitem
*/
public function i_hide_the_grade_item($gradeitem) {
$gradeitem = behat_context_helper::escape($gradeitem);
if ($this->running_javascript()) {
$xpath = "//tr[contains(.,$gradeitem)]//*[contains(@class,'moodle-actionmenu')]//a[contains(@class,'toggle-display')]";
if ($this->getSession()->getPage()->findAll('xpath', $xpath)) {
$this->execute("behat_general::i_click_on", array($this->escape($xpath), "xpath_element"));
}
}
$hide = behat_context_helper::escape(get_string('hide') . ' ');
$linkxpath = "//a[./img[starts-with(@title,$hide) and contains(@title,$gradeitem)]]";
$this->execute("behat_general::i_click_on", array($this->escape($linkxpath), "xpath_element"));
}
/**
* Sets a calculated manual grade item. Needs a table with item name - idnumber relation.
* The step requires you to be in the 'Gradebook setup' page.

View File

@ -345,6 +345,7 @@ Feature: We can use calculated grade totals
And I set the field "Show weightings" to "Show"
And I press "Save changes"
And I select "User report" from the "Grade report" singleselect
And I select "Myself" from the "View report as" singleselect
And I select "Student 1" from the "Select all or one user" singleselect
And the following should exist in the "user-grade" table:
| Grade item | Calculated weight | Grade | Range | Contribution to course total |
@ -534,6 +535,7 @@ Feature: We can use calculated grade totals
And I press "Save changes"
Then I should see "75.00 (16.85 %)" in the ".course" "css_element"
And I select "User report" from the "Grade report" singleselect
And I select "Myself" from the "View report as" singleselect
And I select "Student 1" from the "Select all or one user" singleselect
And the following should exist in the "user-grade" table:
| Grade item | Calculated weight | Grade | Contribution to course total |

View File

@ -46,6 +46,7 @@ Feature: Student and teacher's view of aggregated grade items is consistent when
And I follow "Course 1"
And I navigate to "Grades" node in "Course administration"
And I select "User report" from the "Grade report" singleselect
And I select "Myself" from the "View report as" singleselect
And I select "Student 1" from the "Select all or one user" singleselect
Then the following should exist in the "user-grade" table:
| Grade item | Calculated weight | Grade | Range | Percentage | Contribution to course total |