diff --git a/Changes.md b/Changes.md index 255dfda..647f844 100644 --- a/Changes.md +++ b/Changes.md @@ -5,6 +5,7 @@ Version 401.1.5 - TBR -------------------------- 1. Swap over user name and icon in navbar. In line with a design style of other online applications. 2. Add 'activitynavigationenabled' setting to enable / disable activity navigation. +3. Add 'activitynavigationmodulenames' setting to show the activity module names in the navigation or previous / next if unset. Version 401.1.4 - 11/03/24 -------------------------- diff --git a/classes/output/core_course/output/activity_navigation.php b/classes/output/core_course/output/activity_navigation.php new file mode 100644 index 0000000..f88093f --- /dev/null +++ b/classes/output/core_course/output/activity_navigation.php @@ -0,0 +1,98 @@ +. + +/** + * Foundation theme. + * + * @package theme_foundation + * @copyright 2024 G J Barnard. + * @author G J Barnard - + * {@link https://moodle.org/user/profile.php?id=442195} + * {@link https://gjbarnard.co.uk} + * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later. + */ + +namespace theme_foundation\output\core_course\output; + +use url_select; + +/** + * The class activity navigation renderable. + */ +class activity_navigation extends \core_course\output\activity_navigation { + + /** + * Constructor. + * + * @param \cm_info|null $prevmod The previous module to display, null if none. + * @param \cm_info|null $nextmod The next module to display, null if none. + * @param array $activitylist The list of activity URLs (as key) and names (as value) for the activity dropdown menu. + */ + public function __construct($prevmod, $nextmod, $activitylist = []) { + global $OUTPUT; + + // Enabled? + $toolbox = \theme_foundation\toolbox::get_instance(); + $activitynavigationmodulenames = $toolbox->get_setting('activitynavigationmodulenames'); + + // Check if there is a previous module to display. + if ($prevmod) { + $linkurl = new \moodle_url($prevmod->url, array('forceview' => 1)); + + if ($activitynavigationmodulenames) { + $linkname = $prevmod->get_formatted_name(); + } else { + $linkname = get_string('previous'); + } + if (!$prevmod->visible) { + $linkname .= ' ' . get_string('hiddenwithbrackets'); + } + + $attributes = [ + 'class' => 'btn btn-link', + 'id' => 'prev-activity-link', + ]; + $this->prevlink = new \action_link($linkurl, $OUTPUT->larrow() . ' ' . $linkname, null, $attributes); + } + + // Check if there is a next module to display. + if ($nextmod) { + $linkurl = new \moodle_url($nextmod->url, array('forceview' => 1)); + if ($activitynavigationmodulenames) { + $linkname = $nextmod->get_formatted_name(); + } else { + $linkname = get_string('next'); + } + if (!$nextmod->visible) { + $linkname .= ' ' . get_string('hiddenwithbrackets'); + } + + $attributes = [ + 'class' => 'btn btn-link', + 'id' => 'next-activity-link', + ]; + $this->nextlink = new \action_link($linkurl, $linkname . ' ' . $OUTPUT->rarrow(), null, $attributes); + } + + // Render the activity list dropdown menu if available. + if (!empty($activitylist)) { + $select = new url_select($activitylist, '', array('' => get_string('jumpto'))); + $select->set_label(get_string('jumpto'), array('class' => 'sr-only')); + $select->attributes = array('id' => 'jump-to-activity'); + $this->activitylist = $select; + } + } +} diff --git a/classes/output/core_renderer_toolbox.php b/classes/output/core_renderer_toolbox.php index 28d09ce..5cc8719 100644 --- a/classes/output/core_renderer_toolbox.php +++ b/classes/output/core_renderer_toolbox.php @@ -603,7 +603,7 @@ public function activity_navigation() { $nextmod = $mods[$modids[$position + 1]]; } - $activitynav = new \core_course\output\activity_navigation($prevmod, $nextmod, $activitylist); + $activitynav = new \theme_foundation\output\core_course\output\activity_navigation($prevmod, $nextmod, $activitylist); $renderer = $this->page->get_renderer('core', 'course'); return $renderer->render($activitynav); } diff --git a/classes/toolbox.php b/classes/toolbox.php index 1d2645c..b84bddc 100644 --- a/classes/toolbox.php +++ b/classes/toolbox.php @@ -515,6 +515,14 @@ public function add_settings() { $setting = new \admin_setting_configcheckbox($name, $title, $description, $default, true, false); $settingspages['course'][self::SETTINGPAGE]->add($setting); + // Course activity navigation module names. + $name = 'theme_foundation/activitynavigationmodulenames'; + $title = get_string('activitynavigationmodulenames', 'theme_foundation'); + $description = get_string('activitynavigationmodulenamesdesc', 'theme_foundation'); + $default = true; + $setting = new \admin_setting_configcheckbox($name, $title, $description, $default, true, false); + $settingspages['course'][self::SETTINGPAGE]->add($setting); + // H5P settings. $settingspages['hvp'][self::SETTINGPAGE]->add( new \admin_setting_heading( diff --git a/lang/en/theme_foundation.php b/lang/en/theme_foundation.php index 552480d..15b288b 100644 --- a/lang/en/theme_foundation.php +++ b/lang/en/theme_foundation.php @@ -127,6 +127,9 @@ $string['activitynavigationenabled'] = 'Activity navigation'; $string['activitynavigationenableddesc'] = 'Enabled?'; +$string['activitynavigationmodulenames'] = 'Activity navigation module names'; +$string['activitynavigationmodulenamesdesc'] = 'Show the module names, set, or previous / next if unset.'; + // H5P. $string['hvpheading'] = 'H5P'; $string['hvpheadingsub'] = 'H5P settings';