Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Add docs type smartmenu item, resolves: #657 #685

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 44 additions & 3 deletions classes/smartmenu_item.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ class smartmenu_item {
*/
const TYPEDYNAMIC = 2;

/**
* Represents the type of a dynamic element.
* @var int
*/
const TYPEDOCS = 3;

/**
* Represents the completion status of an item where the status is 'enrolled'.
* @var int
Expand Down Expand Up @@ -771,6 +777,23 @@ protected function generate_dynamic_item() {
return $items;
}

/**
* Generate a node data for doc link item. Use get_docs_url to get the link and generate the data.
*
* @return array
*/
protected function generate_docs_item() {
global $PAGE;
$path = page_get_doc_link_path($PAGE);
$docurl = get_docs_url($path);
return $this->generate_node_data(
$this->item->title,
$docurl,
null,
$this->item->tooltip,
);
}

/**
* Given some text and an ideal length, this function truncates the text based on words count.
*
Expand Down Expand Up @@ -1052,7 +1075,12 @@ public function build() {
// Add classes for item title placement on card.
$class[] = $this->get_textposition_class();
// Menu item class.
$types = [self::TYPESTATIC => 'static', self::TYPEDYNAMIC => 'dynamic', self::TYPEHEADING => 'heading'];
$types = [
self::TYPESTATIC => 'static',
self::TYPEDYNAMIC => 'dynamic',
self::TYPEHEADING => 'heading',
self::TYPEDOCS => 'docs',
];
$class[] = 'menu-item-'.($types[$this->item->type] ?? '');
// Add classes to item data.
$this->item->classes = $class;
Expand All @@ -1068,23 +1096,35 @@ public function build() {
$static = $this->generate_static_item();
$result = [$static]; // Return the result as recursive array for merge with dynamic items.
$type = 'static';
$cacheable = true;
break;

case self::TYPEDYNAMIC:
$result = $this->generate_dynamic_item();
$type = 'dynamic';
$cacheable = true;
break;

case self::TYPEDOCS:
$docs = $this->generate_docs_item();
$result = [$docs]; // Return the result as recursive array useful to merge with dynamic items.
$type = 'docs';
$cacheable = false;
break;

case self::TYPEHEADING:
default:
$heading = $this->generate_heading();
$result = [$heading]; // Return the result as recursive array useful to merge with dynamic items.
$type = 'heading';
$cacheable = true;

endswitch;

// Save the items cache.
$this->cache->set($cachekey, $result);
// If cachable save the items cache.
if ($cacheable) {
$this->cache->set($cachekey, $result);
}

return $result;
}
Expand Down Expand Up @@ -1321,6 +1361,7 @@ public static function load_custom_field_config(&$mform) {
public static function get_types(?int $type = null) {
$types = [
self::TYPESTATIC => get_string('smartmenusmenuitemtypestatic', 'theme_boost_union'),
self::TYPEDOCS => get_string('smartmenusmenuitemtypedocs', 'theme_boost_union'),
self::TYPEHEADING => get_string('smartmenusmenuitemtypeheading', 'theme_boost_union'),
self::TYPEDYNAMIC => get_string('smartmenusmenuitemtypedynamiccourses', 'theme_boost_union'),
];
Expand Down
3 changes: 2 additions & 1 deletion lang/en/theme_boost_union.php
Original file line number Diff line number Diff line change
Expand Up @@ -1197,10 +1197,11 @@
$string['smartmenusmenuitemtooltip'] = 'Tooltip';
$string['smartmenusmenuitemtooltip_help'] = 'The tooltip which will be displayed when the user hovers over the menu item.';
$string['smartmenusmenuitemtype'] = 'Menu item type';
$string['smartmenusmenuitemtype_help'] = '<p>Select the type of menu item you want to create, choosing between static, heading and dynamic courses.</p><ul><li>Static: A static menu item is simply a link to a fixed URL that does not change.</li><li>Heading: A heading menu item is used to group related menu items together under a common heading. It does not have a link and is not clickable.</li><li>Dynamic courses: A dynamic courses menu item is used to display a list of courses based on certain criteria, such as course category, course enrolment role, course completion status or date range. The content displayed in a dynamic courses menu item will update automatically as the criteria changes.</li></ul>';
$string['smartmenusmenuitemtype_help'] = '<p>Select the type of menu item you want to create, choosing between static, heading, moodle documentation and dynamic courses.</p><ul><li>Static: A static menu item is simply a link to a fixed URL that does not change.</li><li>Heading: A heading menu item is used to group related menu items together under a common heading. It does not have a link and is not clickable.</li><li>Dynamic courses: A dynamic courses menu item is used to display a list of courses based on certain criteria, such as course category, course enrolment role, course completion status or date range. The content displayed in a dynamic courses menu item will update automatically as the criteria changes.</li></ul>';
$string['smartmenusmenuitemtypedynamiccourses'] = 'Dynamic courses';
$string['smartmenusmenuitemtypeheading'] = 'Heading';
$string['smartmenusmenuitemtypestatic'] = 'Static';
$string['smartmenusmenuitemtypedocs'] = 'Moodle Documentation';
$string['smartmenusmenuitemurl'] = 'Menu item URL';
$string['smartmenusmenuitemurl_help'] = 'The static URL for the menu item. This is the link that will be followed when the menu item is clicked.';
$string['smartmenusmenulocation'] = 'Menu location(s)';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@theme @theme_boost_union @theme_boost_union_smartmenusettings @theme_boost_union_smartmenusettings_menuitems @theme_boost_union_smartmenusettings_menuitems_docslink
Feature: Configuring the theme_boost_union plugin on the "Smart menus" page, using a dynamic documentationn link item
In order to use the features
As admin
I need to be able to configure the theme Boost Union plugin

Background:
Given I log in as "admin"
And I create smart menu with the following fields to these values:
| Title | Quick links |
| Menu location(s) | Main, Menu, User, Bottom |

@javascript
Scenario: Smartmenus: Menu items: Documentation Link - Add a smart menu documentation link item in smart menu
When I log in as "admin"
And I set "Quick links" smart menu items with the following fields to these values:
| Title | Documentation |
| Menu item type | Moodle Documentation |
And I should see smart menu "Quick links" item "Documentation" in location "Main, Menu, User, Bottom"
And the "href" attribute of "//div[@class='primary-navigation']//a[contains(normalize-space(.), 'Documentation')]" "xpath_element" should contain "/en/theme/boost_union/smartmenus/items"
And I go to the courses management page
And I should see smart menu "Quick links" item "Documentation" in location "Main, Menu, User, Bottom"
And the "href" attribute of "//div[@class='primary-navigation']//a[contains(normalize-space(.), 'Documentation')]" "xpath_element" should contain "en/course/management"
Loading