Documentation

CMenuBuilder
in package

Class CMenuBuilder

A service dedicated to building and preparing navigation menus. It encapsulates all database interactions and business logic related to menus.

Table of Contents

Properties

$logger  : ILogger|null
$menu  : array<string|int, mixed>
$cache  : ICache|null
$dbms_type  : string
$request  : CRequest
$user  : CUser

Methods

__construct()  : mixed
CMenuBuilder constructor.
GetAvailableModules()  : array<string|int, mixed>
Returns a list of all modules, using cache.
GetMenu()  : array<string|int, mixed>
Gets the fully prepared menu structure for the current user against a specific URL.
BuildMenuTree()  : bool
Creates the navigation menu tree recursively by querying the database.
PostProcessMenu()  : void
Recursively traverses a menu array to add state flags (is_active, is_external).

Properties

$menu

protected array<string|int, mixed> $menu = []

The built menu structure

$dbms_type

private string $dbms_type

The database management system type

Methods

__construct()

CMenuBuilder constructor.

public __construct(CUser $user, CRequest $request[, ICache|null $cache = null ][, ILogger|null $logger = null ]) : mixed
Parameters
$user : CUser

The current user object, used to determine roles.

$request : CRequest

The current request, used for route information.

$cache : ICache|null = null

An optional cache handler

$logger : ILogger|null = null

Optional logger instance

GetAvailableModules()

Returns a list of all modules, using cache.

public GetAvailableModules() : array<string|int, mixed>
Return values
array<string|int, mixed> —

The array of module data

GetMenu()

Gets the fully prepared menu structure for the current user against a specific URL.

public GetMenu([string $current_url = '/' ]) : array<string|int, mixed>
Parameters
$current_url : string = '/'

The URL of the current page to determine active states.

Return values
array<string|int, mixed> —

The complete menu array, with state flags (is_active, is_external) already set.

BuildMenuTree()

Creates the navigation menu tree recursively by querying the database.

private BuildMenuTree(array<string|int, mixed> &$menu[, CSqlComposer|null $sql = null ][, int $level = 1 ]) : bool
Parameters
$menu : array<string|int, mixed>

The result menu array.

$sql : CSqlComposer|null = null

The SQL Composer object for sub-menus.

$level : int = 1

The current recursion level.

Return values
bool —

True on success.

PostProcessMenu()

Recursively traverses a menu array to add state flags (is_active, is_external).

private PostProcessMenu(array<string|int, mixed> &$menu_level, string $current_url) : void
Parameters
$menu_level : array<string|int, mixed>

The current level of the menu to process.

$current_url : string

The current page URL to check against.


        
On this page

Search results