diff --git a/form.php b/form.php index 30c6c47..ba42700 100644 --- a/form.php +++ b/form.php @@ -56,6 +56,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 87e8ef5..3ba4452 100644 --- a/index.php +++ b/index.php @@ -27,6 +27,8 @@ require_once(dirname(__FILE__) . '/form.php'); use core\report_helper; +$enablefilterthreshold = get_config('report_editdates', 'enablefilterthreshold'); + $id = required_param('id', PARAM_INT); $activitytype = optional_param('activitytype', '', PARAM_PLUGIN); @@ -76,6 +78,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', ['id' => $id]); $mform = new report_editdates_form( diff --git a/lang/en/report_editdates.php b/lang/en/report_editdates.php index 1b621c3..7c17a9c 100644 --- a/lang/en/report_editdates.php +++ b/lang/en/report_editdates.php @@ -41,6 +41,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['editrestrictedaccess'] = 'Edit restricted access (opens a new window)'; $string['event:reportviewed'] = 'Edit dates report viewed'; $string['hasrestrictedaccess'] = '{$a} has restricted date access settings'; 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)); }