Newer
Older
Michael
committed
<?php
/**
* This file contains \QUI\Menu\SidebarDropDownMenu
*/
namespace QUI\Menu;
use QUI;
use QUI\Projects\Site\Utils;
/**
* Class SidebarDropDownMenu
* Creates on Sidebar Drop Down Menu
*
* @package QUI\Menu
* @author www.pcsg.de (Michael Danielczok, Henning Leutz)
*/
class SidebarDropDownMenu extends QUI\Control
{
/**
* @param array $attributes
*/
public function __construct($attributes = array())
{
// defaults values
$this->setAttributes(array(
'startId' => 1, // id or site link
'parentLink' => false,
'levels' => 0,
'onlyFirstLevelIcons' => false,
'listType' => 'fontAwesome',
'homeIcon' => 'fa-home',
'listIcon' => 'fa-angle-right',
'levelIcon' => 'fa-angle-double-right',
'qui-class' => 'package/quiqqer/menu/bin/SidebarDropDownMenu',
'display' => 'simple',
'showAllChildren' => false
Michael
committed
));
parent::__construct($attributes);
$this->setAttribute('class', 'quiqqer-sidebar-dropdown-navigation');
Michael
committed
}
/**
* (non-PHPdoc)
*
* @see \QUI\Control::create()
*/
public function getBody()
{
$Engine = QUI::getTemplateManager()->getEngine();
$Project = $this->getProject();
Michael
committed
$activeId = false;
// start
try {
$startId = $this->getAttribute('startId');
if (Utils::isSiteLink($startId)) {
$Site = Utils::getSiteByLink($startId);
} else {
$Site = $Project->get((int)$startId);
}
} catch (QUI\Exception $Exception) {
QUI\System\Log::addWarning($Exception->getMessage());
return '';
}
if ($Site->getId() != 1) {
$FirstPage = $Site->getParent();
} else {
$FirstPage = $this->getProject()->firstChild();
}
Michael
committed
// active site
$ActiveSite = QUI::getRewrite()->getSite();
if ($ActiveSite && $ActiveSite->getProject() === $Project) {
Michael
committed
$activeId = $ActiveSite->getId();
}
// settings
$levels = (int)$this->getAttribute('levels');
if ($levels <= 0 || $this->getAttribute('levels') === false) {
$levels = false;
}
switch ($this->getAttribute('display')) {
default:
case 'simple':
$css = dirname(__FILE__).'/SidebarDropDownMenu.Simple.css';
$template = dirname(__FILE__).'/SidebarDropDownMenu.Simple.html';
$css = dirname(__FILE__).'/SidebarDropDownMenu.Advanced.css';
$template = dirname(__FILE__).'/SidebarDropDownMenu.Advanced.html';
Michael
committed
$Engine->assign(array(
'this' => $this,
'Project' => $this->getProject(),
'Site' => $Site,
'FirstPage' => $FirstPage,
'listType' => $this->getAttribute('listType'),
'parentLink' => $this->getAttribute('parentLink'),
'activeId' => $activeId,
'navTemplate' => $template,
'levels' => $levels,
'Rewrite' => QUI::getRewrite(),
'parentIcon' => $this->getAttribute('parentIcon'),
'listIcon' => $this->getAttribute('listIcon'),
'levelIcon' => $this->getAttribute('levelIcon'),
'onlyFirstLevelIcons' => $this->getAttribute('onlyFirstLevelIcons')
Michael
committed
));
$this->addCSSFile($css);
$html = $Engine->fetch($template);
Michael
committed
return $html;
}
public function getChildren(QUI\Projects\Site $Site)
{
if (!$this->getAttribute('showAllChildren')) {
return $Site->getNavigation();
}
return $Site->getChildren();
}