controller =& $controller;
$this->modx =& $controller->modx;
$this->showDescriptions = (boolean) $this->modx->getOption('topmenu_show_descriptions', null, true);
}
/**
* Build the top menu
*
* @return void
*/
public function render()
{
// First assign most variables so they could be used within menus
$this->setPlaceholders();
// Then process menu "containers"
$mainNav = $this->modx->smarty->getTemplateVars('navb');
if (empty($mainNav)) {
$this->buildMenu(
$this->modx->getOption('main_nav_parent', null, 'topnav', true),
'navb'
);
}
$userNav = $this->modx->smarty->getTemplateVars('userNav');
if (empty($userNav)) {
$this->buildMenu(
$this->modx->getOption('user_nav_parent', null, 'usernav', true),
'userNav'
);
}
}
/**
* Set a bunch of placeholders to be used within Smarty templates
*
* @return void
*/
public function setPlaceholders()
{
$username = '';
if ($this->modx->getOption('manager_use_fullname') == true) {
$userProfile = $this->modx->user->getOne('Profile');
$username = $userProfile->get('fullname');
}
if (empty($username)) {
$username = $this->modx->getLoginUserName();
}
$placeholders = array(
'username' => $username,
'userImage' => $this->getUserImage(),
);
$this->controller->setPlaceholders($placeholders);
}
/**
* Retrieve/compute the user picture profile
*
* @return string The HTML output
*/
public function getUserImage()
{
// Default to FontAwesome
$output = ' ';
$img = $this->modx->user->getPhoto(128, 128);
if (!empty($img)) {
$output = '';
}
return $output;
}
/**
* Build the requested menu "container" and set it as a placeholder
*
* @param string $name The container name (topnav, usernav)
* @param string $placeholder The placeholder to display the built menu to
*
* @return void
*/
public function buildMenu($name, $placeholder)
{
if (!$placeholder) {
$placeholder = $name;
}
// Grab the menus to process
$menus = $this->getCache($name);
// Iterate
foreach ($menus as $menu) {
$this->childrenCt = 0;
if (!$this->hasPermission($menu['permissions'])) {
continue;
}
$description = '';
if ($this->showDescriptions && !empty($menu['description'])) {
$description = ''.$menu['description'].''."\n";
}
$label = $menu['text'];
$title = ' title="' . $menu['description'] .'"';
$icon = false;
if (!empty($menu['icon'])) {
$icon = true;
// Use the icon as label
$label = $menu['icon'];
// Reset the description (which is set as text in $title)
$description = '';
}
$top = (!empty($menu['children'])) ? ' class="top"' : '';
$menuTpl = '