MDL-55906 table: Update user preferences table when reset preferences
authorIlya Tregubov <ilya@catalyst-au.net>
Tue, 6 Dec 2016 03:35:00 +0000 (14:35 +1100)
committerIlya Tregubov <ilya@catalyst-au.net>
Thu, 8 Dec 2016 04:02:04 +0000 (15:02 +1100)
lib/tablelib.php

index 246916e..ca252da 100644 (file)
@@ -449,8 +449,10 @@ class flexible_table {
         // Load any existing user preferences.
         if ($this->persistent) {
             $this->prefs = json_decode(get_user_preferences('flextable_' . $this->uniqueid), true);
+            $oldprefs = $this->prefs;
         } else if (isset($SESSION->flextable[$this->uniqueid])) {
             $this->prefs = $SESSION->flextable[$this->uniqueid];
+            $oldprefs = $this->prefs;
         }
 
         // Set up default preferences if needed.
@@ -463,7 +465,10 @@ class flexible_table {
                 'textsort' => $this->column_textsort,
             );
         }
-        $oldprefs = $this->prefs;
+
+        if (!isset($oldprefs)) {
+            $oldprefs = $this->prefs;
+        }
 
         if (($showcol = optional_param($this->request[TABLE_VAR_SHOW], '', PARAM_ALPHANUMEXT)) &&
                 isset($this->columns[$showcol])) {