Skip to content

Commit

Permalink
Add 'activitynavigationmodulenames' setting to show the activity modu…
Browse files Browse the repository at this point in the history
…le names in the navigation or previous / next if unset.
  • Loading branch information
gjb2048 committed Jul 12, 2024
1 parent d4e7208 commit 6b8df41
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 1 deletion.
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------------------------
Expand Down
98 changes: 98 additions & 0 deletions classes/output/core_course/output/activity_navigation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?php
// This file is part of The Bootstrap Moodle theme
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* 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;
}
}
}
2 changes: 1 addition & 1 deletion classes/output/core_renderer_toolbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
8 changes: 8 additions & 0 deletions classes/toolbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 3 additions & 0 deletions lang/en/theme_foundation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit 6b8df41

Please sign in to comment.