Skip to content
Code-Schnipsel Gruppen Projekte
SidebarDropDownMenu.php 4,1 KiB
Newer Older
<?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
        $this->setAttribute('class', 'quiqqer-sidebar-dropdown-navigation');
    }

    /**
     * (non-PHPdoc)
     *
     * @see \QUI\Control::create()
     */
    public function getBody()
    {
Henning Leutz's avatar
Henning Leutz committed
        $Engine   = QUI::getTemplateManager()->getEngine();
        $Project  = $this->getProject();
        $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();
        }


        // active site
        $ActiveSite = QUI::getRewrite()->getSite();

        if ($ActiveSite && $ActiveSite->getProject() === $Project) {
            $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';
                break;

            case 'advanced':
                $css      = dirname(__FILE__).'/SidebarDropDownMenu.Advanced.css';
                $template = dirname(__FILE__).'/SidebarDropDownMenu.Advanced.html';
            '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')
        $this->addCSSFile($css);

        $html = $Engine->fetch($template);
        $html = '<nav>'.$html.'</nav>';

    public function getChildren(QUI\Projects\Site $Site)
    {
        if (!$this->getAttribute('showAllChildren')) {
            return $Site->getNavigation();
        }

        return $Site->getChildren();
    }