MDL-68454 table: Move get_context from dynamic to flexible
This commit is contained in:
@@ -30,7 +30,6 @@ namespace core_table;
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use moodle_url;
|
||||
use context;
|
||||
use core_table\local\filter\filterset;
|
||||
|
||||
/**
|
||||
@@ -61,13 +60,4 @@ interface dynamic {
|
||||
* @return filterset
|
||||
*/
|
||||
public function get_filterset(): ?filterset;
|
||||
|
||||
/**
|
||||
* Get the context of the current table.
|
||||
*
|
||||
* Note: This function should not be called until after the filterset has been provided.
|
||||
*
|
||||
* @return context
|
||||
*/
|
||||
public function get_context(): ?context;
|
||||
}
|
||||
|
||||
+22
-4
@@ -831,9 +831,9 @@ class flexible_table {
|
||||
* @return string contents of cell in column 'fullname', for this row.
|
||||
*/
|
||||
function col_fullname($row) {
|
||||
global $PAGE, $COURSE;
|
||||
global $COURSE;
|
||||
|
||||
$name = fullname($row, has_capability('moodle/site:viewfullnames', $PAGE->context));
|
||||
$name = fullname($row, has_capability('moodle/site:viewfullnames', $this->get_context()));
|
||||
if ($this->download) {
|
||||
return $name;
|
||||
}
|
||||
@@ -1211,7 +1211,7 @@ class flexible_table {
|
||||
* This function is not part of the public api.
|
||||
*/
|
||||
function print_headers() {
|
||||
global $CFG, $OUTPUT, $PAGE;
|
||||
global $CFG, $OUTPUT;
|
||||
|
||||
echo html_writer::start_tag('thead');
|
||||
echo html_writer::start_tag('tr');
|
||||
@@ -1233,7 +1233,7 @@ class flexible_table {
|
||||
|
||||
case 'fullname':
|
||||
// Check the full name display for sortable fields.
|
||||
if (has_capability('moodle/site:viewfullnames', $PAGE->context)) {
|
||||
if (has_capability('moodle/site:viewfullnames', $this->get_context())) {
|
||||
$nameformat = $CFG->alternativefullnameformat;
|
||||
} else {
|
||||
$nameformat = $CFG->fullnamedisplay;
|
||||
@@ -1693,6 +1693,24 @@ class flexible_table {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the context for the table.
|
||||
*
|
||||
* Note: This function _must_ be overridden by dynamic tables to ensure that the context is correctly determined
|
||||
* from the filterset parameters.
|
||||
*
|
||||
* @return context
|
||||
*/
|
||||
public function get_context(): context {
|
||||
global $PAGE;
|
||||
|
||||
if (is_a($this, \core_table\dynamic::class)) {
|
||||
throw new coding_exception('The get_context function must be defined for a dynamic table');
|
||||
}
|
||||
|
||||
return $PAGE->context;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -557,7 +557,7 @@ class participants extends \table_sql implements dynamic_table {
|
||||
*
|
||||
* @return context
|
||||
*/
|
||||
public function get_context(): ?context {
|
||||
public function get_context(): context {
|
||||
return $this->context;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user