MDL-68454 table: Move guessing of base URL to flexible
This commit is contained in:
@@ -29,19 +29,10 @@ namespace core_table;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use moodle_url;
|
||||
|
||||
/**
|
||||
* Interface dynamic.
|
||||
*
|
||||
* @package core_table
|
||||
*/
|
||||
interface dynamic {
|
||||
|
||||
/**
|
||||
* Get the base url.
|
||||
*
|
||||
* @return moodle_url
|
||||
*/
|
||||
public function get_base_url(): moodle_url;
|
||||
}
|
||||
|
||||
+2
-4
@@ -214,6 +214,8 @@ class fetch extends external_api {
|
||||
|
||||
$instance = new $tableclass($uniqueid);
|
||||
$instance->set_filterset($filterset);
|
||||
self::validate_context($instance->get_context());
|
||||
|
||||
$instance->set_sorting($sortby, $sortorder);
|
||||
|
||||
if ($firstinitial !== null) {
|
||||
@@ -236,10 +238,6 @@ class fetch extends external_api {
|
||||
$instance->set_hidden_columns($hiddencolumns);
|
||||
}
|
||||
|
||||
$context = $instance->get_context();
|
||||
self::validate_context($context);
|
||||
$PAGE->set_url($instance->get_base_url());
|
||||
|
||||
ob_start();
|
||||
$instance->out($pagesize, true);
|
||||
$tablehtml = ob_get_contents();
|
||||
|
||||
@@ -1728,6 +1728,8 @@ class flexible_table {
|
||||
*/
|
||||
public function set_filterset(filterset $filterset): void {
|
||||
$this->filterset = $filterset;
|
||||
|
||||
$this->guess_base_url();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1738,6 +1740,15 @@ class flexible_table {
|
||||
public function get_filterset(): ?filterset {
|
||||
return $this->filterset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to guess the base URL.
|
||||
*/
|
||||
public function guess_base_url(): void {
|
||||
if (is_a($this, \core_table\dynamic::class)) {
|
||||
throw new coding_exception('The guess_base_url function must be defined for a dynamic table');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -495,8 +495,6 @@ 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 {
|
||||
parent::set_filterset($filterset);
|
||||
|
||||
// Get the context.
|
||||
$this->courseid = $filterset->get_filter('courseid')->current();
|
||||
$this->course = get_course($this->courseid);
|
||||
@@ -533,20 +531,14 @@ class participants extends \table_sql implements dynamic_table {
|
||||
$this->search = $filterset->get_filter('keywords')->get_filter_values();
|
||||
}
|
||||
|
||||
$this->define_baseurl($this->get_base_url());
|
||||
parent::set_filterset($filterset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the base url for the participants table.
|
||||
*
|
||||
* @return moodle_url
|
||||
* Guess the base url for the participants table.
|
||||
*/
|
||||
public function get_base_url(): moodle_url {
|
||||
if ($this->baseurl === null) {
|
||||
return new moodle_url('/user/index.php', ['id' => $this->courseid]);
|
||||
}
|
||||
|
||||
return $this->baseurl;
|
||||
public function guess_base_url(): void {
|
||||
$this->baseurl = new moodle_url('/user/index.php', ['id' => $this->courseid]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user