164 lines
3.7 KiB
PHP
164 lines
3.7 KiB
PHP
<?php
|
|
/**
|
|
* Created by CS medien- & kommunikationssysteme.
|
|
* @author Christian Steinle
|
|
* @date 03.08.2016
|
|
*
|
|
* @copyright CS medien- & kommunikationssysteme (http://www.steinle-computer.de)
|
|
*/
|
|
|
|
namespace View;
|
|
|
|
|
|
use Helper\Registry;
|
|
|
|
class NavigationView
|
|
{
|
|
/**
|
|
* Die flache Navigation
|
|
* @var array
|
|
*/
|
|
protected $navigationParts = array();
|
|
|
|
/**
|
|
* Array der aktiven Navigations-Elemente
|
|
* @var array
|
|
*/
|
|
protected $navigationPath = array();
|
|
|
|
/**
|
|
* Die strukturierte Navigation nach navStart
|
|
* @var array
|
|
*/
|
|
protected $orderedNavigation = array();
|
|
|
|
/**
|
|
* Ist die Navigation editierbar oder nicht
|
|
* @var bool
|
|
*/
|
|
protected $isEditable = false;
|
|
|
|
/**
|
|
* Das Html der kompletten Navigation
|
|
* @var string
|
|
*/
|
|
protected $navigationHtml = '';
|
|
|
|
|
|
/**
|
|
* NavigationView constructor.
|
|
*
|
|
* @param array $navigationParts
|
|
* @param array $navigationPath
|
|
*/
|
|
public function __construct(array $navigationParts, array $navigationPath)
|
|
{
|
|
$this->navigationParts = $navigationParts;
|
|
$this->navigationPath = $navigationPath;
|
|
}
|
|
|
|
|
|
/**
|
|
* Setter für die Editierbarkeit des Inhalts
|
|
*
|
|
* @param bool $isEditable
|
|
*/
|
|
public function setEditable($isEditable)
|
|
{
|
|
$this->isEditable = $isEditable;
|
|
}
|
|
|
|
|
|
public function init()
|
|
{
|
|
$this->buildOrderedNavigation();
|
|
if ($this->isEditable)
|
|
{
|
|
$registry = Registry::getInstance();
|
|
$this->buildNavigation(0, $registry->editorConfig['backendPrefix']);
|
|
}
|
|
else
|
|
{
|
|
$this->buildNavigation(0);
|
|
}
|
|
}
|
|
|
|
|
|
private function buildOrderedNavigation()
|
|
{
|
|
$orderedNavigation = array();
|
|
foreach ($this->navigationParts as $navID => $navItem)
|
|
{
|
|
$orderedNavigation[$navItem['navStart']][$navID] = $navItem;
|
|
}
|
|
$this->orderedNavigation = $orderedNavigation;
|
|
}
|
|
|
|
|
|
private function buildNavigation($navStart, $linkPrefix = PATH_PREFIX, $depth = 0)
|
|
{
|
|
$tmpNavigation = $this->orderedNavigation[$navStart];
|
|
|
|
if ($depth === 0)
|
|
{
|
|
$editableHtml = ($this->isEditable) ? ' data-editor="Navigation" data-id="' . end($this->navigationPath) . '" data-element="Navigation_' . end($this->navigationPath) . '"' : '';
|
|
$this->navigationHtml .= '<ul class="nav navbar-nav navbar-inverse navbar-collapse collapse" id="main-navbar" aria-expanded="false"' . $editableHtml . '>';
|
|
}
|
|
else
|
|
{
|
|
$this->navigationHtml .= '<ul class="dropdown-menu' . (($depth > 1) ? ' pull-left' : '') . '">';
|
|
}
|
|
|
|
foreach ($tmpNavigation as $navID => $navItem)
|
|
{
|
|
$liClasses = array();
|
|
$aClass = '';
|
|
$span = '';
|
|
|
|
if (in_array($navItem['navID'], $this->navigationPath))
|
|
{
|
|
$liClasses[] = 'active';
|
|
}
|
|
if (isset($this->orderedNavigation[$navItem['navID']]))
|
|
{
|
|
$liClasses[] = 'dropdown-submenu';
|
|
$aClass = 'class="dropdown-toggle" ';
|
|
$span = ' <span class="caret' . (($depth > 0) ? ' rotate-left' : '') . '"></span>';
|
|
}
|
|
$liClass = (empty($liClasses)) ? '' : ' class="' . implode(' ', $liClasses) . '"';
|
|
|
|
if ($this->isEditable)
|
|
{
|
|
$this->navigationHtml .= '<li' . $liClass . '><a ' . $aClass . 'href="' . $linkPrefix . '/index.php?siteID=' . $navItem['navID'] . '">' . $navItem['navName'] . $span . '</a>';
|
|
}
|
|
else
|
|
{
|
|
$this->navigationHtml .= '<li' . $liClass . '><a ' . $aClass . 'href="' . $linkPrefix . '/' . $navItem['navLink'] . '">' . $navItem['navName'] . $span . '</a>';
|
|
}
|
|
if (isset($this->orderedNavigation[$navItem['navID']]))
|
|
{
|
|
if ($this->isEditable)
|
|
{
|
|
$this->buildNavigation($navItem['navID'], $linkPrefix, ($depth + 1));
|
|
}
|
|
else
|
|
{
|
|
$this->buildNavigation($navItem['navID'], $linkPrefix . '/' . $navItem['navLink'], ($depth + 1));
|
|
}
|
|
}
|
|
$this->navigationHtml .= '</li>';
|
|
}
|
|
|
|
$this->navigationHtml .= '</ul>';
|
|
if ($depth === 0)
|
|
{
|
|
//$this->navigationHtml .= '</nav>';
|
|
}
|
|
}
|
|
|
|
|
|
public function render()
|
|
{
|
|
return $this->navigationHtml;
|
|
}
|
|
} |