Skip to content

Commit

Permalink
MDL-60828 user: Reset current page when filtering/searching users
Browse files Browse the repository at this point in the history
Added baseurl parameter to core_user\output\unified_filter to let specify
different URL, instead of using always $PAGE->url.
  • Loading branch information
sarjona committed Mar 9, 2018
1 parent 1287039 commit bb4a792
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
15 changes: 13 additions & 2 deletions user/classes/output/unified_filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
namespace core_user\output;

use moodle_url;
use renderable;
use renderer_base;
use stdClass;
Expand All @@ -44,15 +45,22 @@ class unified_filter implements renderable, templatable {
/** @var array $selectedoptions The list of selected filter option values. */
protected $selectedoptions;

/** @var moodle_url|string $baseurl The url with params needed to call up this page. */
protected $baseurl;

/**
* unified_filter constructor.
*
* @param array $filteroptions The filter options.
* @param array $selectedoptions The list of selected filter option values.
* @param string|moodle_url $baseurl The url with params needed to call up this page.
*/
public function __construct($filteroptions, $selectedoptions) {
public function __construct($filteroptions, $selectedoptions, $baseurl = null) {
$this->filteroptions = $filteroptions;
$this->selectedoptions = $selectedoptions;
if (!empty($baseurl)) {
$this->baseurl = new moodle_url($baseurl);
}
}

/**
Expand All @@ -64,7 +72,10 @@ public function __construct($filteroptions, $selectedoptions) {
public function export_for_template(renderer_base $output) {
global $PAGE;
$data = new stdClass();
$data->action = $PAGE->url->out(false);
if (empty($this->baseurl)) {
$this->baseurl = $PAGE->url;
}
$data->action = $this->baseurl->out(false);

foreach ($this->selectedoptions as $option) {
if (!isset($this->filteroptions[$option])) {
Expand Down
12 changes: 6 additions & 6 deletions user/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,18 +213,18 @@
}
echo html_writer::div($enrolbuttonsout, 'pull-right');

// Render the unified filter.
$renderer = $PAGE->get_renderer('core_user');
echo $renderer->unified_filter($course, $context, $filtersapplied);

echo '<div class="userlist">';

// Should use this variable so that we don't break stuff every time a variable is added or changed.
$baseurl = new moodle_url('/user/index.php', array(
'contextid' => $context->id,
'id' => $course->id,
'perpage' => $perpage));

// Render the unified filter.
$renderer = $PAGE->get_renderer('core_user');
echo $renderer->unified_filter($course, $context, $filtersapplied, $baseurl);

echo '<div class="userlist">';

$participanttable = new \core_user\participants_table($course->id, $groupid, $lastaccess, $roleid, $enrolid, $status,
$searchkeywords, $bulkoperations, $selectall);
$participanttable->define_baseurl($baseurl);
Expand Down
5 changes: 3 additions & 2 deletions user/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,10 @@ public function user_list($userlist, $exclusivemode) {
* @param stdClass $course The course object.
* @param context $context The context object.
* @param array $filtersapplied Array of currently applied filters.
* @param string|moodle_url $baseurl The url with params needed to call up this page.
* @return bool|string
*/
public function unified_filter($course, $context, $filtersapplied) {
public function unified_filter($course, $context, $filtersapplied, $baseurl = null) {
global $CFG, $DB, $USER;

require_once($CFG->dirroot . '/enrol/locallib.php');
Expand Down Expand Up @@ -248,7 +249,7 @@ public function unified_filter($course, $context, $filtersapplied) {
// Add missing applied filters to the filter options.
$filteroptions = $this->handle_missing_applied_filters($filtersapplied, $filteroptions);

$indexpage = new \core_user\output\unified_filter($filteroptions, $filtersapplied);
$indexpage = new \core_user\output\unified_filter($filteroptions, $filtersapplied, $baseurl);
$context = $indexpage->export_for_template($this->output);

return $this->output->render_from_template('core_user/unified_filter', $context);
Expand Down

0 comments on commit bb4a792

Please sign in to comment.