Erweiterung der Funktionalität, erste Anbindung an Editoren, Einbinden von JS-Bibliotheken
This commit is contained in:
@@ -10,6 +10,8 @@
|
||||
namespace View;
|
||||
|
||||
|
||||
use Helper\Registry;
|
||||
|
||||
class NavigationView
|
||||
{
|
||||
/**
|
||||
@@ -30,6 +32,12 @@ class NavigationView
|
||||
*/
|
||||
protected $orderedNavigation = array();
|
||||
|
||||
/**
|
||||
* Ist die Navigation editierbar oder nicht
|
||||
* @var bool
|
||||
*/
|
||||
protected $isEditable = false;
|
||||
|
||||
/**
|
||||
* Das Html der kompletten Navigation
|
||||
* @var string
|
||||
@@ -37,12 +45,42 @@ class NavigationView
|
||||
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();
|
||||
$this->buildNavigation(0);
|
||||
if ($this->isEditable)
|
||||
{
|
||||
$registry = Registry::getInstance();
|
||||
$this->buildNavigation(0, $registry->editorConfig['backendPrefix']);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->buildNavigation(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -60,11 +98,12 @@ class NavigationView
|
||||
private function buildNavigation($navStart, $linkPrefix = PATH_PREFIX, $depth = 0)
|
||||
{
|
||||
$tmpNavigation = $this->orderedNavigation[$navStart];
|
||||
$activePath = PATH_PREFIX . '/' . implode('/', $this->navigationPath);
|
||||
|
||||
if ($depth === 0)
|
||||
{
|
||||
$this->navigationHtml .= '<div class="" id="bs-example-navbar-collapse-1"><ul class="nav navbar-nav">';
|
||||
$editableHtml = ($this->isEditable) ? ' data-editor="navigation" data-id="' . end($this->navigationPath) . '" data-element="navigation_' . end($this->navigationPath) . '"' : '';
|
||||
//$this->navigationHtml .= '<nav class="navbar-collapse collapse" id="main-navbar" aria-expanded="false">';
|
||||
$this->navigationHtml .= '<ul class="nav navbar-nav navbar-inverse navbar-collapse collapse" id="main-navbar" aria-expanded="false"' . $editableHtml . '>';
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -77,7 +116,7 @@ class NavigationView
|
||||
$aClass = '';
|
||||
$span = '';
|
||||
|
||||
if (strpos($activePath, $linkPrefix . '/' . $navItem['navLink']) === 0)
|
||||
if (in_array($navItem['navID'], $this->navigationPath))
|
||||
{
|
||||
$liClasses[] = 'active';
|
||||
}
|
||||
@@ -89,10 +128,24 @@ class NavigationView
|
||||
}
|
||||
$liClass = (empty($liClasses)) ? '' : ' class="' . implode(' ', $liClasses) . '"';
|
||||
|
||||
$this->navigationHtml .= '<li' . $liClass . '><a ' . $aClass . 'href="' . $linkPrefix . '/' . $navItem['navLink'] . '">' . $navItem['navName'] . $span . '</a>';
|
||||
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']]))
|
||||
{
|
||||
$this->buildNavigation($navItem['navID'], $linkPrefix . '/' . $navItem['navLink'], ($depth + 1));
|
||||
if ($this->isEditable)
|
||||
{
|
||||
$this->buildNavigation($navItem['navID'], $linkPrefix, ($depth + 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->buildNavigation($navItem['navID'], $linkPrefix . '/' . $navItem['navLink'], ($depth + 1));
|
||||
}
|
||||
}
|
||||
$this->navigationHtml .= '</li>';
|
||||
}
|
||||
@@ -100,12 +153,12 @@ class NavigationView
|
||||
$this->navigationHtml .= '</ul>';
|
||||
if ($depth === 0)
|
||||
{
|
||||
$this->navigationHtml .= '</div>';
|
||||
//$this->navigationHtml .= '</nav>';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getHtml()
|
||||
public function render()
|
||||
{
|
||||
return $this->navigationHtml;
|
||||
}
|
||||
|
||||
@@ -9,15 +9,37 @@
|
||||
|
||||
namespace View;
|
||||
|
||||
use \Helper\Registry;
|
||||
|
||||
|
||||
class StandardView
|
||||
{
|
||||
const TPL_PATH = PATH_TPL;
|
||||
|
||||
/**
|
||||
* Pfad zur Template Datei
|
||||
* @var string
|
||||
*/
|
||||
protected $template = '';
|
||||
|
||||
/**
|
||||
* Das Daten-Array, das in die Inhaltsbereiche des Templates gerendert wird
|
||||
* @var array
|
||||
*/
|
||||
protected $data = array();
|
||||
|
||||
/**
|
||||
* Ist der Inhalt bearbeitbar
|
||||
* @var bool
|
||||
*/
|
||||
protected $isEditable = false;
|
||||
|
||||
|
||||
/**
|
||||
* StandardView constructor.
|
||||
* Setzt den Pfad zum Template und die Daten
|
||||
*
|
||||
* @param array $data
|
||||
* @param $template
|
||||
*/
|
||||
public function __construct(array $data, $template)
|
||||
{
|
||||
$this->setTemplate($template);
|
||||
@@ -25,22 +47,46 @@ class StandardView
|
||||
}
|
||||
|
||||
|
||||
private function setTemplate($template)
|
||||
/**
|
||||
* @param $isEditable
|
||||
*/
|
||||
public function setEditable($isEditable)
|
||||
{
|
||||
if (file_exists(static::TPL_PATH . mb_strtolower($template) . '.phtml'))
|
||||
{
|
||||
$this->template = static::TPL_PATH . mb_strtolower($template) . '.phtml';
|
||||
}
|
||||
$this->isEditable = $isEditable;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Setzt den Pfad zum Template
|
||||
*
|
||||
* @param $template
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function setTemplate($template)
|
||||
{
|
||||
$templateFile = PATH_TPL . mb_strtolower($template) . '.phtml';
|
||||
if (!file_exists($templateFile))
|
||||
{
|
||||
throw new \Exception('Template file "' . $templateFile . '" does not exist!');
|
||||
}
|
||||
$this->template = $templateFile;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gibt das befüllte Template als HTML zurück
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
ob_start();
|
||||
include($this->template);
|
||||
$pageContent = ob_get_contents();
|
||||
include_once($this->template);
|
||||
|
||||
$templateContent = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
return $pageContent;
|
||||
return $templateContent;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user