MDL-76445 gradereport_singleview: Usability fixes

This commit is contained in:
Mihail Geshoski
2023-06-13 15:14:21 +08:00
parent 40d2a8cb93
commit 3415229bf1
2 changed files with 197 additions and 38 deletions
+91 -37
View File
@@ -33,32 +33,15 @@ $groupid = optional_param('group', null, PARAM_INT);
// Making this work with profile reports.
$userid = optional_param('userid', null, PARAM_INT);
$defaulttype = $userid ? 'user' : 'select';
$itemid = optional_param('itemid', null, PARAM_INT);
$itemtype = optional_param('item', $defaulttype, PARAM_TEXT);
$itemtype = optional_param('item', null, PARAM_TEXT);
$page = optional_param('page', 0, PARAM_INT);
$perpage = optional_param('perpage', 100, PARAM_INT);
$edit = optional_param('edit', -1, PARAM_BOOL); // Sticky editing mode.
if (empty($itemid) && ($itemtype !== 'user_select' && $itemtype !== 'grade_select')) {
$itemid = $userid;
$itemtype = $defaulttype;
}
$courseparams = ['id' => $courseid];
$pageparams = [
'id' => $courseid,
'group' => $groupid,
'userid' => $userid,
'itemid' => $itemid,
'item' => $itemtype,
'page' => $page,
'perpage' => $perpage,
];
$PAGE->set_url(new moodle_url('/grade/report/singleview/index.php', $pageparams));
$PAGE->set_pagelayout('report');
$PAGE->set_other_editing_capability('moodle/grade:edit');
@@ -68,10 +51,6 @@ if (!$course = $DB->get_record('course', $courseparams)) {
require_login($course);
if (!in_array($itemtype, gradereport_singleview\report\singleview::valid_screens())) {
throw new \moodle_exception('notvalid', 'gradereport_singleview', '', $itemtype);
}
$context = context_course::instance($course->id);
// This is the normal requirements.
@@ -85,6 +64,90 @@ $gpr = new grade_plugin_return([
'courseid' => $courseid
]);
// Last selected report session tracking.
if (!isset($USER->grade_last_report)) {
$USER->grade_last_report = [];
}
$USER->grade_last_report[$course->id] = 'singleview';
// If the item type is not explicitly defined or not valid, try to use the last viewed one (obtain in from the session)
// or fallback to the user select (zero) state.
if (!$itemtype || !in_array($itemtype, \gradereport_singleview\report\singleview::valid_screens())) {
$itemtype = isset($SESSION->gradereport_singleview["itemtype-{$context->id}"]) ?
$SESSION->gradereport_singleview["itemtype-{$context->id}"] : 'user_select';
}
$currentgroup = $gpr->groupid;
// To make some other functions work better later.
if (!$currentgroup) {
$currentgroup = null;
}
$lastvieweduseritemid = $SESSION->gradereport_singleview["useritem-{$context->id}"] ?? null;
$lastviewedgradeitemid = $SESSION->gradereport_singleview["gradeitem-{$context->id}"] ?? null;
switch ($itemtype) {
case 'user_select':
// If there is a stored user item (last viewed) in a session variable, bypass the user select zero state
// and display this user item. Also, make sure that the stored last viewed user is part of the current
// list of gradable users in this course.
if ($lastvieweduseritemid && array_key_exists($lastvieweduseritemid, get_gradable_users($courseid, $currentgroup))) {
$itemtype = 'user';
$itemid = $lastvieweduseritemid;
} else {
$itemid = null;
}
break;
case 'user':
if (is_null($itemid)) {
$itemid = $userid ?? $lastvieweduseritemid;
}
// If the item id (user id) cannot be defined or the user id is not part of the list of gradable users,
// display the user select zero state.
if (is_null($itemid) || !array_key_exists($itemid, get_gradable_users($courseid, $currentgroup))) {
$itemtype = 'user_select';
}
break;
case 'grade_select':
// If there is a stored grade item (last viewed) in a session variable, bypass the grade item select zero state
// and display this grade item.
if ($lastviewedgradeitemid) {
$itemtype = 'grade';
$itemid = $lastviewedgradeitemid;
} else {
$itemid = null;
}
break;
case 'grade':
// If there is a stored grade item (last viewed) in a session variable, use it.
if (is_null($itemid) && $lastviewedgradeitemid) {
$itemid = $lastviewedgradeitemid;
}
$gtree = new grade_tree($courseid, false, false, null, !$CFG->enableoutcomes);
$gradeableitems = $gtree->get_items();
// The item id (grade item id) cannot be defined, display the grade select zero state.
if (is_null($itemid) || !array_key_exists($itemid, $gtree->get_items())) {
$itemtype = 'grade_select';
}
break;
}
$report = new gradereport_singleview\report\singleview($courseid, $gpr, $context, $itemtype, $itemid);
$pageparams = [
'id' => $courseid,
'userid' => $userid,
'itemid' => $itemid,
'item' => $itemtype,
'page' => $page,
'perpage' => $perpage,
];
if (!is_null($groupid)) {
$pageparams['group'] = $groupid;
}
$PAGE->set_url(new moodle_url('/grade/report/singleview/index.php', $pageparams));
// Build editing on/off button for themes that need it.
$button = '';
if ($PAGE->user_allowed_editing() && !$PAGE->theme->haseditswitch) {
@@ -97,14 +160,6 @@ if ($PAGE->user_allowed_editing() && !$PAGE->theme->haseditswitch) {
$button = $OUTPUT->edit_button(new moodle_url($PAGE->url, $options), 'get');
}
// Last selected report session tracking.
if (!isset($USER->grade_last_report)) {
$USER->grade_last_report = [];
}
$USER->grade_last_report[$course->id] = 'singleview';
$report = new gradereport_singleview\report\singleview($courseid, $gpr, $context, $itemtype, $itemid);
$reportname = $report->screen->heading();
if ($itemtype == 'user' || $itemtype == 'user_select') {
@@ -149,6 +204,11 @@ if ($data = data_submitted()) {
grade_regrade_final_grades_if_required($course);
echo $report->output();
// Save the screen state in a session variable as last viewed state.
$SESSION->gradereport_singleview["itemtype-{$context->id}"] = $itemtype;
if ($itemid) {
$SESSION->gradereport_singleview["{$itemtype}item-{$context->id}"] = $itemid;
}
if (($itemtype !== 'select') && ($itemtype !== 'grade_select') &&($itemtype !== 'user_select')) {
$item = (isset($userid)) ? $userid : $itemid;
@@ -157,12 +217,6 @@ if (($itemtype !== 'select') && ($itemtype !== 'grade_select') &&($itemtype !==
$showonlyactiveenrol = get_user_preferences('grade_report_showonlyactiveenrol', $defaultgradeshowactiveenrol);
$showonlyactiveenrol = $showonlyactiveenrol || !has_capability('moodle/course:viewsuspendedusers', $context);
$currentgroup = $gpr->groupid;
// To make some other functions work better later.
if (!$currentgroup) {
$currentgroup = null;
}
$gui = new graded_users_iterator($course, null, $currentgroup);
$gui->require_active_enrolment($showonlyactiveenrol);
$gui->init();
@@ -7,11 +7,12 @@ Feature: We can use Single view
Background:
Given the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
| Course 1 | C1 | 0 |
And the following "users" exist:
| username | firstname | lastname | email | idnumber | middlename | alternatename | firstnamephonetic | lastnamephonetic |
| teacher1 | Teacher | 1 | teacher1@example.com | t1 | | fred | | |
| teacher2 | No edit | 1 | teacher2@example.com | t2 | | nick | | |
| teacher3 | Teacher | 3 | teacher3@example.com | t3 | | jack | | |
| student1 | Grainne | Beauchamp | student1@example.com | s1 | Ann | Jill | Gronya | Beecham |
| student2 | Niamh | Cholmondely | student2@example.com | s2 | Jane | Nina | Nee | Chumlee |
| student3 | Siobhan | Desforges | student3@example.com | s3 | Sarah | Sev | Shevon | De-forjay |
@@ -29,6 +30,7 @@ Feature: We can use Single view
| user | course | role |
| teacher1 | C1 | editingteacher |
| teacher2 | C1 | teacher |
| teacher3 | C1 | teacher |
| student1 | C1 | student |
| student2 | C1 | student |
| student3 | C1 | student |
@@ -171,3 +173,106 @@ Feature: We can use Single view
And "new grade item 1" "link" should not exist in the "//tbody//tr[position()=1]//td[position()=2]" "xpath_element"
Then "Category total" "link" should not exist in the "//tbody//tr[position()=2]//td[position()=2]" "xpath_element"
And "Course total" "link" should not exist in the "//tbody//tr[position()=last()]//td[position()=2]" "xpath_element"
Scenario: Teacher sees his last viewed singleview report type when navigating back to the gradebook singleview report.
Given I navigate to "View > Single view" in the course gradebook
And I should see "Select a user above to view all their grades" in the "region-main" "region"
And I click on "Grade items" "link"
And I should see "Select a grade item above" in the "region-main" "region"
And I am on "Course 1" course homepage
When I navigate to "View > Single view" in the course gradebook
Then I should see "Select a grade item above" in the "region-main" "region"
And I log out
And I log in as "teacher3"
And I am on "Course 1" course homepage
And I navigate to "View > Single view" in the course gradebook
And I should see "Select a user above to view all their grades" in the "region-main" "region"
Scenario: Teacher sees his last viewed user report when navigating back to the gradebook singleview report.
Given I navigate to "View > Single view" in the course gradebook
And I click on "Gronya,Beecham" in the "user" search widget
And I should see "Gronya,Beecham" in the "region-main" "region"
And I am on "Course 1" course homepage
When I navigate to "View > Single view" in the course gradebook
Then I should not see "Select a user above to view all their grades" in the "region-main" "region"
And I should see "Gronya,Beecham" in the "region-main" "region"
And I log out
And I log in as "teacher3"
And I am on "Course 1" course homepage
And I navigate to "View > Single view" in the course gradebook
And I should see "Select a user above to view all their grades" in the "region-main" "region"
Scenario: Teacher sees his last viewed grade item report when navigating back to the gradebook singleview report.
Given I navigate to "View > Single view" in the course gradebook
And I click on "Grade items" "link"
And I click on "Test assignment one" in the "grade" search widget
And I should see "Test assignment one" in the "region-main" "region"
And I am on "Course 1" course homepage
When I navigate to "View > Single view" in the course gradebook
Then I should not see "Select a grade item above" in the "region-main" "region"
And I should see "Test assignment one" in the "region-main" "region"
And I log out
And I log in as "teacher3"
And I am on "Course 1" course homepage
And I navigate to "View > Single view" in the course gradebook
And I should see "Select a user above to view all their grades" in the "region-main" "region"
Scenario: Teacher sees his last viewed user report if the user is a part of the the current group.
Given the following "groups" exist:
| name | course | idnumber | participation |
| Group 1 | C1 | G1 | 1 |
And the following "group members" exist:
| user | group |
| student2 | G1 |
And I am on the "Course 1" "course editing" page
And I expand all fieldsets
And I set the field "Group mode" to "Visible groups"
And I press "Save and display"
And I navigate to "View > Single view" in the course gradebook
And I click on "Nee,Chumlee" in the "user" search widget
And I navigate to "View > Grader report" in the course gradebook
And I click on "Group 1" in the "group" search widget
When I navigate to "View > Single view" in the course gradebook
Then I should see "Nee,Chumlee" in the "region-main" "region"
And I should not see "Select a user above to view all their grades" in the "region-main" "region"
Scenario: Teacher does not see his last viewed user report if the user is not a part of the the current group.
Given the following "groups" exist:
| name | course | idnumber | participation |
| Group 1 | C1 | G1 | 1 |
And the following "group members" exist:
| user | group |
| student2 | G1 |
And I am on "Course 1" course homepage
And I navigate to "Settings" in current page administration
And I expand all fieldsets
And I set the field "Group mode" to "Visible groups"
And I press "Save and display"
And I navigate to "View > Single view" in the course gradebook
And I click on "Gronya,Beecham" in the "user" search widget
And I navigate to "View > Grader report" in the course gradebook
And I click on "Group 1" in the "group" search widget
When I navigate to "View > Single view" in the course gradebook
Then I should see "Select a user above to view all their grades" in the "region-main" "region"
And I should not see "Gronya,Beecham" in the "region-main" "region"
Scenario: Teacher does not see his last viewed user report if that user is no longer enrolled in the course.
Given I navigate to "View > Single view" in the course gradebook
And I click on "Gronya,Beecham" in the "user" search widget
And I navigate to course participants
And I click on "Unenrol" "icon" in the "Gronya,Beecham" "table_row"
And I click on "Unenrol" "button" in the "Unenrol" "dialogue"
When I navigate to "View > Single view" in the course gradebook
Then I should see "Select a user above to view all their grades" in the "region-main" "region"
And I should not see "Gronya,Beecham" in the "region-main" "region"
Scenario: Teacher does not see his last viewed grade item report if the item no longer exists in the course.
Given I navigate to "View > Single view" in the course gradebook
And I click on "Grade items" "link"
And I click on "Test assignment four" in the "grade" search widget
And I am on "Course 1" course homepage with editing mode on
And I delete "Test assignment four" activity
And I run all adhoc tasks
When I navigate to "View > Single view" in the course gradebook
Then I should see "Select a grade item above" in the "region-main" "region"
And I should not see "Test grade item" in the "region-main" "region"