MDL-66372 forumreport_summary: Tidy up per page and bulk ops handling
This commit is contained in:
@@ -50,11 +50,14 @@ class summary_table extends table_sql {
|
||||
/** Table to store summary data extracted from the log table */
|
||||
const LOG_SUMMARY_TEMP_TABLE = 'forum_report_summary_counts';
|
||||
|
||||
/** Default number of rows to display per page */
|
||||
const DEFAULT_PER_PAGE = 50;
|
||||
|
||||
/** @var \stdClass The various SQL segments that will be combined to form queries to fetch various information. */
|
||||
public $sql;
|
||||
|
||||
/** @var int The number of rows to be displayed per page. */
|
||||
protected $perpage = 50;
|
||||
protected $perpage = self::DEFAULT_PER_PAGE;
|
||||
|
||||
/** @var array The values available for pagination size per page. */
|
||||
protected $perpageoptions = [50, 100, 200];
|
||||
@@ -79,7 +82,7 @@ class summary_table extends table_sql {
|
||||
protected $context = null;
|
||||
|
||||
/** @var bool Whether the user has the capability/capabilities to perform bulk operations. */
|
||||
protected $bulkoperations = false;
|
||||
protected $allowbulkoperations = false;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
@@ -96,11 +99,11 @@ class summary_table extends table_sql {
|
||||
*
|
||||
* @param int $courseid The ID of the course the forum(s) exist within.
|
||||
* @param array $filters Report filters in the format 'type' => [values].
|
||||
* @param bool $bulkoperations Is the user allowed to perform bulk operations?
|
||||
* @param bool $allowbulkoperations Is the user allowed to perform bulk operations?
|
||||
* @param bool $canseeprivatereplies Whether the user can see all private replies or not.
|
||||
* @param int $perpage The number of rows to display per page.
|
||||
*/
|
||||
public function __construct(int $courseid, array $filters, bool $bulkoperations, bool $canseeprivatereplies, int $perpage) {
|
||||
public function __construct(int $courseid, array $filters, bool $allowbulkoperations, bool $canseeprivatereplies, int $perpage) {
|
||||
global $USER, $OUTPUT;
|
||||
|
||||
$forumid = $filters['forums'][0];
|
||||
@@ -109,6 +112,7 @@ class summary_table extends table_sql {
|
||||
|
||||
$this->cm = get_coursemodule_from_instance('forum', $forumid, $courseid);
|
||||
$this->context = \context_module::instance($this->cm->id);
|
||||
$this->allowbulkoperations = $allowbulkoperations;
|
||||
$this->canseeprivatereplies = $canseeprivatereplies;
|
||||
$this->perpage = $perpage;
|
||||
|
||||
@@ -119,7 +123,7 @@ class summary_table extends table_sql {
|
||||
|
||||
$columnheaders = [];
|
||||
|
||||
if ($bulkoperations) {
|
||||
if ($allowbulkoperations) {
|
||||
$mastercheckbox = new \core\output\checkbox_toggleall('summaryreport-table', true, [
|
||||
'id' => 'select-all-users',
|
||||
'name' => 'select-all-users',
|
||||
@@ -803,25 +807,6 @@ class summary_table extends table_sql {
|
||||
return $this->showwordcharcounts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether the user has the capability/capabilities to perform bulk operations.
|
||||
*
|
||||
* @param bool $allowbulkoperations Whether the user has the relevant capability/capabilities.
|
||||
* @return void
|
||||
*/
|
||||
public function set_bulkoperations(bool $allowbulkoperations): void {
|
||||
$this->bulkoperations = $allowbulkoperations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch whether the user has the capability/capabilities to perform bulk operations.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function get_bulkoperations(): bool {
|
||||
return $this->bulkoperations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the number of items to be displayed per page.
|
||||
*
|
||||
@@ -840,7 +825,7 @@ class summary_table extends table_sql {
|
||||
global $OUTPUT;
|
||||
|
||||
$data = new \stdClass();
|
||||
$data->showbulkactions = $this->get_bulkoperations();
|
||||
$data->showbulkactions = $this->allowbulkoperations;
|
||||
|
||||
if ($data->showbulkactions) {
|
||||
$data->id = 'formactionid';
|
||||
@@ -875,9 +860,9 @@ class summary_table extends table_sql {
|
||||
$selected = in_array($this->perpage, $this->perpageoptions) ? $this->perpage : $this->perpageoptions[0];
|
||||
$perpageselect = new \single_select(new \moodle_url(''), 'perpage',
|
||||
$perpageoptions, $selected, null, 'selectperpage');
|
||||
$perpageselect->label = get_string('perpage', 'moodle');
|
||||
$perpageselect->set_label(get_string('perpage', 'moodle'));
|
||||
|
||||
$data->perpage = $OUTPUT->render($perpageselect);
|
||||
$data->perpage = $perpageselect->export_for_template($OUTPUT);
|
||||
|
||||
echo $OUTPUT->render_from_template('forumreport_summary/bulk_action_menu', $data);
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ if (isguestuser()) {
|
||||
|
||||
$courseid = required_param('courseid', PARAM_INT);
|
||||
$forumid = required_param('forumid', PARAM_INT);
|
||||
$perpage = optional_param('perpage', 50, PARAM_INT);
|
||||
$perpage = optional_param('perpage', \forumreport_summary\summary_table::DEFAULT_PER_PAGE, PARAM_INT);
|
||||
$filters = [];
|
||||
|
||||
// Establish filter values.
|
||||
@@ -78,10 +78,10 @@ $PAGE->set_heading($course->fullname);
|
||||
$PAGE->navbar->add(get_string('nodetitle', "forumreport_summary"));
|
||||
|
||||
// Prepare and display the report.
|
||||
$bulkoperations = !$download && !empty($CFG->messaging) && has_capability('moodle/course:bulkmessaging', $context);
|
||||
$allowbulkoperations = !$download && !empty($CFG->messaging) && has_capability('moodle/course:bulkmessaging', $context);
|
||||
$canseeprivatereplies = has_capability('mod/forum:readprivatereplies', $context);
|
||||
|
||||
$table = new \forumreport_summary\summary_table($courseid, $filters, $bulkoperations, $canseeprivatereplies, $perpage);
|
||||
$table = new \forumreport_summary\summary_table($courseid, $filters, $allowbulkoperations, $canseeprivatereplies, $perpage);
|
||||
$table->baseurl = $url;
|
||||
|
||||
if ($download) {
|
||||
@@ -99,6 +99,6 @@ if ($download) {
|
||||
|
||||
echo $renderer->render_filters_form($cm, $url, $filters);
|
||||
$table->show_download_buttons_at(array(TABLE_P_BOTTOM));
|
||||
echo $renderer->render_summary_table($table, $bulkoperations);
|
||||
echo $renderer->render_summary_table($table);
|
||||
echo $OUTPUT->footer();
|
||||
}
|
||||
|
||||
@@ -53,15 +53,12 @@ class forumreport_summary_renderer extends plugin_renderer_base {
|
||||
* Render the summary report table.
|
||||
*
|
||||
* @param summary_table $table The summary table to be rendered.
|
||||
* @param int $bulkoperations Whether the user has bulk operations capability/capabilities.
|
||||
* @return string The report table HTML.
|
||||
*/
|
||||
public function render_summary_table(summary_table $table, bool $bulkoperations): string {
|
||||
public function render_summary_table(summary_table $table): string {
|
||||
// Buffer so calling script can output the report as required.
|
||||
ob_start();
|
||||
|
||||
$table->set_bulkoperations($bulkoperations);
|
||||
|
||||
// Render table.
|
||||
$table->out($table->get_perpage(), false);
|
||||
|
||||
|
||||
@@ -67,7 +67,9 @@
|
||||
</div>
|
||||
{{/showbulkactions}}
|
||||
<div class="float-right">
|
||||
{{{perpage}}}
|
||||
{{#perpage}}
|
||||
{{> core/single_select}}
|
||||
{{/perpage}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user