From bf7c844e941df51d3bfd4768f24ca4ee8a72e6fe Mon Sep 17 00:00:00 2001 From: Tony Butler Date: Wed, 18 Mar 2015 16:33:41 +0000 Subject: [PATCH] MDL-49582 core_lib: Add button to allow user to reset table preferences --- lang/en/moodle.php | 1 + lib/tablelib.php | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/lang/en/moodle.php b/lang/en/moodle.php index e0f5cd09d0398..78468c78c7e9a 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -1530,6 +1530,7 @@ $string['resetrecordexpired'] = 'The password reset link you used is more than {$a} minutes old and has expired. Please initiate a new password reset.'; $string['resetstartdate'] = 'Reset start date'; $string['resetstatus'] = 'Status'; +$string['resettable'] = 'Reset table preferences'; $string['resettask'] = 'Task'; $string['resettodefaults'] = 'Reset to defaults'; $string['resortsubcategoriesby'] = 'Sort subcategories by {$a} ascending'; diff --git a/lib/tablelib.php b/lib/tablelib.php index cbf66ac17a366..39afa90c2e43a 100644 --- a/lib/tablelib.php +++ b/lib/tablelib.php @@ -34,6 +34,7 @@ define('TABLE_VAR_IFIRST', 4); define('TABLE_VAR_ILAST', 5); define('TABLE_VAR_PAGE', 6); +define('TABLE_VAR_RESET', 7); /**#@-*/ /**#@+ @@ -138,6 +139,7 @@ function __construct($uniqueid) { TABLE_VAR_IFIRST => 'tifirst', TABLE_VAR_ILAST => 'tilast', TABLE_VAR_PAGE => 'page', + TABLE_VAR_RESET => 'treset' ); } @@ -508,6 +510,17 @@ function setup() { $this->prefs['i_first'] = $ifirst; } + // Allow user to reset table preferences. + if (optional_param($this->request[TABLE_VAR_RESET], 0, PARAM_BOOL) === 1) { + $this->prefs = array( + 'collapse' => array(), + 'sortby' => array(), + 'i_first' => '', + 'i_last' => '', + 'textsort' => $this->column_textsort, + ); + } + // Save user preferences if they have changed. if ($this->prefs != $oldprefs) { if ($this->persistent) { @@ -971,6 +984,10 @@ function print_initials_bar() { */ function print_nothing_to_display() { global $OUTPUT; + + // Render button to allow user to reset table preferences. + echo $this->render_reset_button(); + $this->print_initials_bar(); echo $OUTPUT->heading(get_string('nothingtodisplay')); @@ -1325,6 +1342,10 @@ protected function sort_link($text, $column, $isprimary, $order) { */ function start_html() { global $OUTPUT; + + // Render button to allow user to reset table preferences. + echo $this->render_reset_button(); + // Do we need to print initial bars? $this->print_initials_bar(); @@ -1363,6 +1384,21 @@ function make_styles_string($styles) { } return $string; } + + /** + * Generate the HTML for the table preferences reset button. + * + * @return string HTML fragment. + */ + private function render_reset_button() { + $url = $this->baseurl->out(false, array($this->request[TABLE_VAR_RESET] => 1)); + + $html = html_writer::start_div('mdl-right'); + $html .= html_writer::link($url, get_string('resettable')); + $html .= html_writer::end_div(); + + return $html; + } }