From b4121975b12bf5c2bdecac90c5d00606687bb3a8 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 b6ba36886b045..e7d9bf97865e2 100644 --- a/admin/settings/courses.php +++ b/admin/settings/courses.php @@ -184,6 +184,7 @@ // 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 @@ ] ) ); + + // 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 fe3e80b290d06..8b7e46c737a62 100644 --- a/course/externallib.php +++ b/course/externallib.php @@ -4368,15 +4368,10 @@ public static function get_activity_chooser_footer(int $courseid, int $sectionid $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 7408941ffefbf..f8bd18954d8c1 100644 --- a/course/lib.php +++ b/course/lib.php @@ -68,6 +68,9 @@ /** 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 0a19d434cff6c..156ebabad6108 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';