diff --git a/grade/report/history/classes/filter_form.php b/grade/report/history/classes/filter_form.php index 2eead9f4899..9b1bdf4cb20 100644 --- a/grade/report/history/classes/filter_form.php +++ b/grade/report/history/classes/filter_form.php @@ -50,7 +50,8 @@ class filter_form extends \moodleform { $itemids = $this->_customdata['itemids']; $graders = $this->_customdata['graders']; $userbutton = $this->_customdata['userbutton']; - $names = \html_writer::span('', 'selectednames'); + $userfullnames = $this->_customdata['userfullnames']; + $names = \html_writer::span($userfullnames, 'selectednames'); $mform->addElement('static', 'userselect', get_string('selectusers', 'gradereport_history'), $userbutton); $mform->addElement('static', 'selectednames', get_string('selectedusers', 'gradereport_history'), $names); @@ -79,16 +80,4 @@ class filter_form extends \moodleform { // Add a submit button. $mform->addElement('submit', 'submitbutton', get_string('submit')); } - - /** - * This method implements changes to the form that need to be made once the form data is set. - */ - public function definition_after_data() { - $mform = $this->_form; - - if ($userfullnames = $mform->getElementValue('userfullnames')) { - $mform->getElement('selectednames')->setValue(\html_writer::span($userfullnames, 'selectednames')); - } - } - } diff --git a/grade/report/history/classes/output/tablelog.php b/grade/report/history/classes/output/tablelog.php index 663e29488f8..b90caba85f2 100644 --- a/grade/report/history/classes/output/tablelog.php +++ b/grade/report/history/classes/output/tablelog.php @@ -519,7 +519,8 @@ class tablelog extends \table_sql implements \renderable { $idlist = explode(',', $this->filters->userids); list($where, $params) = $DB->get_in_or_equal($idlist); - return $DB->get_records_select('user', "id $where", $params); + [$order] = users_order_by_sql(); + return $DB->get_records_select('user', "id $where", $params, $order); } return $idlist; diff --git a/grade/report/history/index.php b/grade/report/history/index.php index 127e106aadf..cb8fec8e77e 100644 --- a/grade/report/history/index.php +++ b/grade/report/history/index.php @@ -58,7 +58,8 @@ $itemids = array(0 => get_string('allgradeitems', 'gradereport_history')) + $ite $output = $PAGE->get_renderer('gradereport_history'); $graders = \gradereport_history\helper::get_graders($course->id); -$params = array('course' => $course, 'itemids' => $itemids, 'graders' => $graders, 'userbutton' => null); +$params = ['course' => $course, 'itemids' => $itemids, 'graders' => $graders, + 'userbutton' => null, 'userfullnames' => '']; $mform = new \gradereport_history\filter_form(null, $params); $filters = array(); if ($data = $mform->get_data()) { @@ -85,7 +86,7 @@ $names = array(); foreach ($table->get_selected_users() as $key => $user) { $names[$key] = fullname($user); } -$filters['userfullnames'] = implode(',', $names); +$userfullnames = implode(', ', $names); // Set up js. \gradereport_history\helper::init_js($course->id, $names); @@ -94,7 +95,8 @@ $filters['userfullnames'] = implode(',', $names); $button = new \gradereport_history\output\user_button($PAGE->url, get_string('selectusers', 'gradereport_history'), 'get'); $userbutton = $output->render($button); -$params = array('course' => $course, 'itemids' => $itemids, 'graders' => $graders, 'userbutton' => $userbutton); +$params = ['course' => $course, 'itemids' => $itemids, 'graders' => $graders, + 'userbutton' => $userbutton, 'userfullnames' => $userfullnames]; $mform = new \gradereport_history\filter_form(null, $params); $mform->set_data($filters); diff --git a/grade/report/history/tests/behat/basic_functionality.feature b/grade/report/history/tests/behat/basic_functionality.feature index 1b1326a05d8..55dd5dc54e3 100644 --- a/grade/report/history/tests/behat/basic_functionality.feature +++ b/grade/report/history/tests/behat/basic_functionality.feature @@ -58,11 +58,22 @@ Feature: A teacher checks the grade history report in a course | Student 1 | Rewarding assignment | 60.00 | 80.00 | Teacher 2 | | Student 2 | The greatest assignment ever | 50.00 | 70.00 | Teacher 2 | | Student 2 | Rewarding assignment | 60.00 | 80.00 | Teacher 2 | + # Test filtering by student - display of several users. + And I press "Select users" + And I click on "Student 1" "checkbox" + And I click on "Student 2" "checkbox" + And I press "Finish selecting users" + And I should see "Student 1, Student 2" + And I press "Submit" + And I should see "Student 1, Student 2" # Test filtering by student. And I press "Select users" - And I set the field with xpath "//form/input[@class='usp-search-field']" to "Student 1" - And I click on "Search" "button" in the "//div[@class='usp-search']" "xpath_element" - And I set the field with xpath "//div[@class='usp-checkbox']/input" to "1" + And I set the field with xpath "//form/input[@class='usp-search-field']" to "Student 2" + And I click on "Search" "button" in the "Select users" "dialogue" + And I should see "Student 2" in the "Select users" "dialogue" + And I should not see "Student 1" in the "Select users" "dialogue" + # Deselect. + And I click on "Student 2" "checkbox" And I press "Finish selecting users" And I press "Submit" And the following should exist in the "gradereport_history" table: diff --git a/grade/report/history/users_ajax.php b/grade/report/history/users_ajax.php index 038cf0274d4..15f2b62ff5e 100644 --- a/grade/report/history/users_ajax.php +++ b/grade/report/history/users_ajax.php @@ -70,7 +70,6 @@ foreach ($users as $user) { } $outcome->success = true; - echo $OUTPUT->header(); echo json_encode($outcome); echo $OUTPUT->footer(); diff --git a/lib/datalib.php b/lib/datalib.php index b8f61119a42..aded6e4152a 100644 --- a/lib/datalib.php +++ b/lib/datalib.php @@ -341,7 +341,7 @@ function users_search_sql(string $search, string $u = 'u', bool $searchanywhere * @param array $customfieldmappings associative array of mappings for custom fields returned by \core_user\fields::get_sql. * @return array with two elements: * string SQL fragment to use in the ORDER BY clause. For example, "firstname, lastname". - * array of parameters used in the SQL fragment. + * array of parameters used in the SQL fragment. If $search is not given, this is guaranteed to be an empty array. */ function users_order_by_sql(string $usertablealias = '', string $search = null, context $context = null, array $customfieldmappings = []) {