From fbbfe9aa006e6d6b428cc2496949260b89a06a40 Mon Sep 17 00:00:00 2001 From: Mathew May Date: Fri, 7 Aug 2020 16:27:24 +0800 Subject: [PATCH] MDL-68928 core_course: Select activity chooser footer --- admin/settings/courses.php | 26 ++++++++++++++++++++++++++ course/externallib.php | 13 ++++--------- course/lib.php | 3 +++ lang/en/course.php | 3 +++ 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/admin/settings/courses.php b/admin/settings/courses.php index b6ba36886b0..e7d9bf97865 100644 --- a/admin/settings/courses.php +++ b/admin/settings/courses.php @@ -184,6 +184,7 @@ if ($hassiteconfig or has_any_capability($capabilities, $systemcontext)) { // Add a category for the Activity Chooser. $ADMIN->add('courses', new admin_category('activitychooser', new lang_string('activitychoosercategory', 'course'))); $temp = new admin_settingpage('activitychoosersettings', new lang_string('activitychoosersettings', 'course')); + // Tab mode for the activity chooser. $temp->add( new admin_setting_configselect( 'activitychoosertabmode', @@ -197,6 +198,31 @@ if ($hassiteconfig or has_any_capability($capabilities, $systemcontext)) { ] ) ); + + // Build a list of plugins that use the footer callback. + $pluginswithfunction = get_plugins_with_function('custom_chooser_footer', 'lib.php'); + $pluginsoptions = []; + $pluginsoptions[COURSE_CHOOSER_FOOTER_NONE] = get_string('activitychooserhidefooter', 'course'); + if ($pluginswithfunction) { + foreach ($pluginswithfunction as $plugintype => $plugins) { + foreach ($plugins as $pluginname => $pluginfunction) { + $plugin = $plugintype.'_'.$pluginname; + $pluginsoptions[$plugin] = get_string('pluginname', $plugin); + } + } + } + + // Select what plugin to show in the footer. + $temp->add( + new admin_setting_configselect( + 'activitychooseractivefooter', + new lang_string('activitychooseractivefooter', 'course'), + new lang_string('activitychooseractivefooter_desc', 'course'), + COURSE_CHOOSER_FOOTER_NONE, + $pluginsoptions + ) + ); + $ADMIN->add('activitychooser', $temp); $ADMIN->add('activitychooser', new admin_externalpage('activitychooserrecommended', new lang_string('activitychooserrecommendations', 'course'), diff --git a/course/externallib.php b/course/externallib.php index 74fa9871cd6..5a896e7f2bf 100644 --- a/course/externallib.php +++ b/course/externallib.php @@ -4381,15 +4381,10 @@ class core_course_external extends external_api { $coursecontext = context_course::instance($courseid); self::validate_context($coursecontext); - $pluginswithfunction = get_plugins_with_function('custom_chooser_footer', 'lib.php'); - if ($pluginswithfunction) { - foreach ($pluginswithfunction as $plugintype => $plugins) { - foreach ($plugins as $pluginfunction) { - $footerdata = $pluginfunction($courseid, $sectionid); - break; // Only a single plugin can modify the footer. - } - break; // Only a single plugin can modify the footer. - } + $activeplugin = get_config('core', 'activitychooseractivefooter'); + + if ($activeplugin !== COURSE_CHOOSER_FOOTER_NONE) { + $footerdata = component_callback($activeplugin, 'custom_chooser_footer', [$courseid, $sectionid]); return [ 'footer' => true, 'customfooterjs' => $footerdata->get_footer_js_file(), diff --git a/course/lib.php b/course/lib.php index 7408941ffef..f8bd18954d8 100644 --- a/course/lib.php +++ b/course/lib.php @@ -68,6 +68,9 @@ define('COURSE_DB_QUERY_LIMIT', 1000); /** Searching for all courses that have no value for the specified custom field. */ define('COURSE_CUSTOMFIELD_EMPTY', -1); +// Course activity chooser footer default display option. +define('COURSE_CHOOSER_FOOTER_NONE', 'hidden'); + function make_log_url($module, $url) { switch ($module) { case 'course': diff --git a/lang/en/course.php b/lang/en/course.php index 0a19d434cff..156ebabad61 100644 --- a/lang/en/course.php +++ b/lang/en/course.php @@ -25,6 +25,9 @@ $string['activitychoosercategory'] = 'Activity chooser'; $string['activitychooserrecommendations'] = 'Recommended activities'; $string['activitychoosersettings'] = 'Activity chooser settings'; +$string['activitychooseractivefooter'] = 'Activity chooser footer'; +$string['activitychooseractivefooter_desc'] = 'The activity chooser can support plugins that add items to the footer.'; +$string['activitychooserhidefooter'] = 'No footer'; $string['activitychoosertabmode'] = 'Activity chooser tabs'; $string['activitychoosertabmode_desc'] = "The activity chooser enables a teacher to easily select activities and resources to add to their course. This setting determines which tabs should be displayed in it. Note that the starred tab is only displayed for a user if they have starred one or more activities and the recommended tab is only displayed if a site administrator has specified some recommended activities."; $string['activitychoosertabmodeone'] = 'Starred, All, Activities, Resources, Recommended';