From 6dc0b6f258f76652f02b2501494e840ade3d60d6 Mon Sep 17 00:00:00 2001 From: Michael Spall Date: Wed, 17 Nov 2021 22:28:16 +0000 Subject: [PATCH] Issue 36: Add filter threshold Add filter threshold. Courses with an activity count over the threshold will default to the first activity type. Add a threshold setting that defaults to 40. Add a warning that a large number of activities will cause the page to take a long time to display. Append number of activities to the all activities option. --- form.php | 3 +++ index.php | 16 ++++++++++++++++ lang/en/report_editdates.php | 3 +++ settings.php | 5 +++++ 4 files changed, 27 insertions(+) diff --git a/form.php b/form.php index aa6a258..ee796cb 100644 --- a/form.php +++ b/form.php @@ -58,6 +58,9 @@ public function definition() { $mform->addElement('hidden', 'activitytype', $activitytype); $mform->setType('activitytype', PARAM_PLUGIN); + // Add number activities warning + $mform->addElement('html', '

' . get_string('numactivitieswarning', 'report_editdates') . '

'); + // Invisible static element. Used as the holder for a validation message sometimes. $mform->addElement('static', 'topvalidationsite', '', ''); diff --git a/index.php b/index.php index 8b9da01..9878eef 100644 --- a/index.php +++ b/index.php @@ -26,6 +26,8 @@ require_once(dirname(__FILE__) . '/../../config.php'); require_once(dirname(__FILE__) . '/form.php'); +$enablefilterthreshold = get_config('report_editdates', 'enablefilterthreshold'); + $id = required_param('id', PARAM_INT); $activitytype = optional_param('activitytype', '', PARAM_PLUGIN); @@ -75,6 +77,20 @@ } core_collator::asort($activitytypes); +// Append number of activities to the all activities option +$activitytypes["all"] .= (' (' . $activitiesdisplayed . ')'); + +// If activity count is above the threshold, activate the filter controls. +if (!$activitytype && $activitiesdisplayed > $enablefilterthreshold) { + if (count($activitytypes) > 1) { + $activitytypekey = array_keys($activitytypes)[1]; + } else { + $activitytypekey = array_keys($activitytypes)[0]; + } + redirect(new moodle_url('/report/editdates/index.php', + array('id' => $id, 'activitytype' => $activitytypekey))); +} + // Creating the form. $baseurl = new moodle_url('/report/editdates/index.php', array('id' => $id)); $mform = new report_editdates_form($baseurl, array('modinfo' => $modinfo, diff --git a/lang/en/report_editdates.php b/lang/en/report_editdates.php index 8970b88..f1a3ddb 100644 --- a/lang/en/report_editdates.php +++ b/lang/en/report_editdates.php @@ -40,6 +40,9 @@ $string['editdates'] = 'Dates'; $string['editdates:view'] = 'View edit dates course report'; $string['editend'] = 'Prevent editing from cannot be less than Allow editing from'; +$string['enablefilterthreshold'] = 'Enable filter threshold'; +$string['enablefilterthresholddesc'] = 'Maximum number of activities before enabling filter.'; +$string['numactivitieswarning'] = 'With a large number of activites, this form may take a long time to display.'; $string['page-report-editdates-index'] = 'Edit course dates'; $string['pluginname'] = 'Dates'; $string['timeclose'] = 'Time Close cannot be less than Time Open'; diff --git a/settings.php b/settings.php index 2a1b517..f95063f 100644 --- a/settings.php +++ b/settings.php @@ -39,4 +39,9 @@ get_string('timelinemaxdesc', 'report_editdates'), 3, $options)); + $settings->add(new admin_setting_configtext('report_editdates/enablefilterthreshold', + get_string('enablefilterthreshold', 'report_editdates'), + get_string('enablefilterthresholddesc', 'report_editdates'), + 40, + PARAM_INT)); }