Skip to content

Commit

Permalink
Merge branch 'MDL-73140' of https://github.com/timhunt/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
sarjona committed Dec 1, 2021
2 parents 216f36a + e1b28a7 commit ca8f2de
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 23 deletions.
15 changes: 2 additions & 13 deletions grade/report/history/classes/filter_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public function definition() {
$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);
Expand Down Expand Up @@ -79,16 +80,4 @@ public function definition() {
// 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'));
}
}

}
3 changes: 2 additions & 1 deletion grade/report/history/classes/output/tablelog.php
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,8 @@ public function get_selected_users() {

$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;
Expand Down
8 changes: 5 additions & 3 deletions grade/report/history/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@

$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()) {
Expand All @@ -85,7 +86,7 @@
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);
Expand All @@ -94,7 +95,8 @@
$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);

Expand Down
17 changes: 14 additions & 3 deletions grade/report/history/tests/behat/basic_functionality.feature
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,22 @@ Feature: A teacher checks the grade history report in a course
| Student 1 | student1@example.com | apple | Rewarding assignment | 60.00 | 80.00 | Teacher 2 |
| Student 2 | student2@example.com | orange | The greatest assignment ever | 50.00 | 70.00 | Teacher 2 |
| Student 2 | student2@example.com | orange | 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:
Expand Down
5 changes: 3 additions & 2 deletions grade/report/history/users_ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,17 @@
$newuser->userid = $user->id;
$newuser->picture = $OUTPUT->user_picture($user, $useroptions);
$newuser->fullname = fullname($user);
$fieldvalues = [];
foreach ($extrafields as $field) {
if ($user->{$field}) {
$newuser->extrafields[] = $user->{$field};
$fieldvalues[] = $user->{$field};
}
}
$newuser->extrafields = implode(', ', $fieldvalues);
$outcome->response['users'][] = $newuser;
}

$outcome->success = true;

echo $OUTPUT->header();
echo json_encode($outcome);
echo $OUTPUT->footer();
2 changes: 1 addition & 1 deletion lib/datalib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []) {
Expand Down

0 comments on commit ca8f2de

Please sign in to comment.