MDL-68454 table: Move filterset functionality to flexible_table
authorAndrew Nicols <andrew@nicols.co.uk>
Thu, 23 Apr 2020 01:24:56 +0000 (09:24 +0800)
committerAndrew Nicols <andrew@nicols.co.uk>
Mon, 4 May 2020 03:52:19 +0000 (11:52 +0800)
lib/table/classes/dynamic.php
lib/tablelib.php
user/classes/table/participants.php

index fa07700..e545d78 100644 (file)
@@ -30,7 +30,6 @@ namespace core_table;
 defined('MOODLE_INTERNAL') || die();
 
 use moodle_url;
-use core_table\local\filter\filterset;
 
 /**
  * Interface dynamic.
@@ -45,19 +44,4 @@ interface dynamic {
      * @return moodle_url
      */
     public function get_base_url(): moodle_url;
-
-    /**
-     * Set the filterset filters build table object.
-     *
-     * @param filterset $filterset The filterset object to get the filters from.
-     * @return void
-     */
-    public function set_filterset(filterset $filterset): void;
-
-    /**
-     * Get the currently defined filterset.
-     *
-     * @return filterset
-     */
-    public function get_filterset(): ?filterset;
 }
index 0c1c486..fe70942 100644 (file)
@@ -46,6 +46,7 @@ define('TABLE_P_TOP',    1);
 define('TABLE_P_BOTTOM', 2);
 /**#@-*/
 
+use core_table\local\filter\filterset;
 
 /**
  * @package   moodlecore
@@ -157,6 +158,12 @@ class flexible_table {
     /** @var array $hiddencolumns List of hidden columns. */
     protected $hiddencolumns;
 
+    /**
+     * @var filterset The currently applied filerset
+     * This is required for dynamic tables, but can be used by other tables too if desired.
+     */
+    protected $filterset = null;
+
     /**
      * Constructor
      * @param string $uniqueid all tables have to have a unique id, this is used
@@ -1711,6 +1718,26 @@ class flexible_table {
 
         return $PAGE->context;
     }
+
+    /**
+     * Set the filterset in the table class.
+     *
+     * The use of filtersets is a requirement for dynamic tables, but can be used by other tables too if desired.
+     *
+     * @param filterset $filterset The filterset object to get filters and table parameters from
+     */
+    public function set_filterset(filterset $filterset): void {
+        $this->filterset = $filterset;
+    }
+
+    /**
+     * Get the currently defined filterset.
+     *
+     * @return filterset
+     */
+    public function get_filterset(): ?filterset {
+        return $this->filterset;
+    }
 }
 
 
index 23fe817..be164ac 100644 (file)
@@ -495,8 +495,7 @@ class participants extends \table_sql implements dynamic_table {
      * @param filterset $filterset The filterset object to get the filters from.
      */
     public function set_filterset(filterset $filterset): void {
-        // Store the filterset for later.
-        $this->filterset = $filterset;
+        parent::set_filterset($filterset);
 
         // Get the context.
         $this->courseid = $filterset->get_filter('courseid')->current();
@@ -560,13 +559,4 @@ class participants extends \table_sql implements dynamic_table {
     public function get_context(): context {
         return $this->context;
     }
-
-    /**
-     * Get the currently defined filterset.
-     *
-     * @return filterset
-     */
-    public function get_filterset(): ?filterset {
-        return $this->filterset;
-    }
 }