LimeSurvey API - Master branch

SideMenuActiveItemMapper extends WhSelect2
in package

Maps and identifies active menu items in the survey side menu.

This class determines whether a menu item should be marked as active by comparing URLs and checking against defined patterns and sub-items.

Table of Contents

Properties

$currentUrl  : string
$menutype  : string
$surveyid  : int

Methods

getAllowedSubItems()  : array<string|int, mixed>
Returns the configuration of allowed sub-items for each menu type.
match()  : bool
Determines if a menu item URL matches the current page.
matchSubItems()  : bool
Checks if the current URL matches any sub-items for the current menu type.
normalizeUrl()  : string
Normalizes a URL by removing index.php and trailing slashes.

Properties

Methods

getAllowedSubItems()

Returns the configuration of allowed sub-items for each menu type.

public getAllowedSubItems() : array<string|int, mixed>

Sub-items are additional pages that belong to a main menu category but have different URLs than the main menu item URL. Each menu type can define specific URLs and/or URL patterns for matching.

Pattern matching uses strpos() to check if the pattern appears at the start of the URL (position 0), so patterns must match the beginning of URLs.

Return values
array<string|int, mixed>

Associative array of menu types with their patterns and URLs. Structure: [ 'menutype' => [ 'pattern' => string, // URL pattern to match (from start) 'urls' => array // Specific URLs to match ] ]

match()

Determines if a menu item URL matches the current page.

public match(string $menuItemUrl, string $menutype, int $surveyid) : bool

This method checks if the provided menu item URL matches the current URL either directly or through sub-item matching.

Parameters
$menuItemUrl : string

The URL of the menu item to check.

$menutype : string

The type of menu (e.g., 'statistics', 'responses').

$surveyid : int

The ID of the current survey.

Return values
bool

True if the menu item matches the current page, false otherwise.

matchSubItems()

Checks if the current URL matches any sub-items for the current menu type.

public matchSubItems() : bool

This method compares the current URL against both specific URLs and patterns defined for the menu type's sub-items.

Return values
bool

True if a sub-item match is found, false otherwise.

normalizeUrl()

Normalizes a URL by removing index.php and trailing slashes.

private normalizeUrl(string $url) : string

This method standardizes URLs for comparison by removing the "/index.php" segment and any trailing slashes, ensuring consistent URL matching.

Parameters
$url : string

The URL to normalize.

Return values
string

The normalized URL without "/index.php" and trailing slashes.


        
On this page

Search results