From 04298671e5d1615da2a9edadaeef6dc4cc1cc154 Mon Sep 17 00:00:00 2001 From: Mikhail Golenkov Date: Thu, 21 Jan 2021 14:36:01 +1100 Subject: [PATCH] MDL-69631 assign: Add 'Draft' filter for grading table --- mod/assign/gradingoptionsform.php | 1 + mod/assign/gradingtable.php | 4 ++ mod/assign/lang/en/assign.php | 1 + mod/assign/locallib.php | 4 +- mod/assign/tests/behat/filter_drafts.feature | 68 ++++++++++++++++++++ mod/assign/tests/locallib_test.php | 2 +- 6 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 mod/assign/tests/behat/filter_drafts.feature diff --git a/mod/assign/gradingoptionsform.php b/mod/assign/gradingoptionsform.php index 0804647c58e..db15a86f84a 100644 --- a/mod/assign/gradingoptionsform.php +++ b/mod/assign/gradingoptionsform.php @@ -59,6 +59,7 @@ class mod_assign_grading_options_form extends moodleform { $mform->addElement('select', 'perpage', get_string('assignmentsperpage', 'assign'), $options, $dirtyclass); $options = array('' => get_string('filternone', 'assign'), ASSIGN_FILTER_NOT_SUBMITTED => get_string('filternotsubmitted', 'assign'), + ASSIGN_FILTER_DRAFT => get_string('filterdraft', 'assign'), ASSIGN_FILTER_SUBMITTED => get_string('filtersubmitted', 'assign'), ASSIGN_FILTER_REQUIRE_GRADING => get_string('filterrequiregrading', 'assign'), ASSIGN_FILTER_GRANTED_EXTENSION => get_string('filtergrantedextension', 'assign')); diff --git a/mod/assign/gradingtable.php b/mod/assign/gradingtable.php index 4a9962d8db1..926ef2881c2 100644 --- a/mod/assign/gradingtable.php +++ b/mod/assign/gradingtable.php @@ -327,6 +327,10 @@ class assign_grading_table extends table_sql implements renderable { $userfilter = (int) array_pop(explode('=', $filter)); $where .= ' AND (u.id = :userid)'; $params['userid'] = $userfilter; + } else if ($filter == ASSIGN_FILTER_DRAFT) { + $where .= ' AND (s.timemodified IS NOT NULL AND + s.status = :draft) '; + $params['draft'] = ASSIGN_SUBMISSION_STATUS_DRAFT; } } diff --git a/mod/assign/lang/en/assign.php b/mod/assign/lang/en/assign.php index a9305a0fe18..a7eee1bfcf0 100644 --- a/mod/assign/lang/en/assign.php +++ b/mod/assign/lang/en/assign.php @@ -259,6 +259,7 @@ $string['feedbacksettings'] = 'Feedback settings'; $string['feedbacktypes'] = 'Feedback types'; $string['filesubmissions'] = 'File submissions'; $string['filter'] = 'Filter'; +$string['filterdraft'] = 'Draft'; $string['filtergrantedextension'] = 'Granted extension'; $string['filternone'] = 'No filter'; $string['filternotsubmitted'] = 'Not submitted'; diff --git a/mod/assign/locallib.php b/mod/assign/locallib.php index 0697d541d13..8e01a7dcb5e 100644 --- a/mod/assign/locallib.php +++ b/mod/assign/locallib.php @@ -39,6 +39,7 @@ define('ASSIGN_FILTER_NOT_SUBMITTED', 'notsubmitted'); define('ASSIGN_FILTER_SINGLE_USER', 'singleuser'); define('ASSIGN_FILTER_REQUIRE_GRADING', 'requiregrading'); define('ASSIGN_FILTER_GRANTED_EXTENSION', 'grantedextension'); +define('ASSIGN_FILTER_DRAFT', 'draft'); // Marker filter for grading page. define('ASSIGN_MARKER_FILTER_NO_MARKER', -1); @@ -9346,8 +9347,9 @@ class assign { */ public function get_filters() { $filterkeys = [ - ASSIGN_FILTER_SUBMITTED, ASSIGN_FILTER_NOT_SUBMITTED, + ASSIGN_FILTER_DRAFT, + ASSIGN_FILTER_SUBMITTED, ASSIGN_FILTER_REQUIRE_GRADING, ASSIGN_FILTER_GRANTED_EXTENSION ]; diff --git a/mod/assign/tests/behat/filter_drafts.feature b/mod/assign/tests/behat/filter_drafts.feature new file mode 100644 index 00000000000..46e57b1f07d --- /dev/null +++ b/mod/assign/tests/behat/filter_drafts.feature @@ -0,0 +1,68 @@ +@mod @mod_assign +Feature: In an assignment, teachers can filter displayed submissions and see drafts + In order to manage submissions more easily + As a teacher + I need to view submissions with draft status. + + Background: + Given the following "courses" exist: + | fullname | shortname | category | + | Course 1 | C1 | 0 | + And the following "users" exist: + | username | firstname | lastname | email | + | teacher1 | Teacher | 1 | teacher1@example.com | + | student1 | Student | 1 | student1@example.com | + | student2 | Student | 2 | student2@example.com | + | student3 | Student | 3 | student3@example.com | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + | student1 | C1 | student | + | student2 | C1 | student | + | student3 | C1 | student | + And the following "activities" exist: + | activity | course | idnumber | name | assignsubmission_onlinetext_enabled | submissiondrafts | + | assign | C1 | assign1 | Test assignment | 1 | 1 | + And I log in as "student1" + And I am on "Course 1" course homepage + And I follow "Test assignment" + And I press "Add submission" + And I set the following fields to these values: + | Online text | This submission is submitted | + And I press "Save changes" + And I press "Submit assignment" + And I press "Continue" + And I log out + And I log in as "student2" + And I am on "Course 1" course homepage + And I follow "Test assignment" + And I press "Add submission" + And I set the following fields to these values: + | Online text | This submission is NOT submitted | + And I press "Save changes" + And I log out + + @javascript + Scenario: View assignments with draft status on the view all submissions page + Given I log in as "teacher1" + And I am on "Course 1" course homepage + And I follow "Test assignment" + And I navigate to "View all submissions" in current page administration + When I set the field "Filter" to "Draft" + Then I should see "Student 2" + And I should not see "Student 1" + And I should not see "Student 3" + + @javascript + Scenario: View assignments with draft status in the grader + Given I log in as "teacher1" + And I am on "Course 1" course homepage + And I follow "Test assignment" + And I navigate to "View all submissions" in current page administration + And I click on "Grade" "link" in the "Student 1" "table_row" + When I click on "[data-region=user-filters]" "css_element" + And I set the field "filter" to "Draft" + Then I should see "1 of 1" + And I should see "Student 2" + And I should not see "Student 1" + And I should not see "Student 3" diff --git a/mod/assign/tests/locallib_test.php b/mod/assign/tests/locallib_test.php index 0d5af67cdc5..fd5151c0d92 100644 --- a/mod/assign/tests/locallib_test.php +++ b/mod/assign/tests/locallib_test.php @@ -3988,7 +3988,7 @@ Anchor link 2:Link text $assign = $this->create_instance($course); $valid = $assign->get_filters(); - $this->assertEquals(count($valid), 5); + $this->assertEquals(count($valid), 6); } /**