Erweiterung der Funktionalität, erste Anbindung an Editoren, Einbinden von JS-Bibliotheken

This commit is contained in:
2016-10-05 15:27:09 +00:00
parent 5a1dd25023
commit f65b4db286
26 changed files with 31969 additions and 140 deletions

View File

@@ -11,13 +11,15 @@ namespace Controller;
use Helper\Database;
use Model\NavigationModel;
use View\StandardView;
use View\NavigationView;
use View\StandardView;
class FrontendController
{
protected $route = '';
protected $isEditable = false;
protected $request = array();
protected $contents = array();
@@ -27,52 +29,96 @@ class FrontendController
$this->route = $route;
$this->routeParts = explode('/', $route);
$this->request = $request;
$this->init();
}
private function init()
public function setEditable($isEditable)
{
NavigationModel::init($this->routeParts);
$navigation = new NavigationView(NavigationModel::getData(), $this->routeParts);
$this->isEditable = $isEditable;
}
$this->contents['title'] = 'AHD Allradhaus';
$this->contents['navigation'] = $navigation->getHtml();
public function init()
{
NavigationModel::init($this->routeParts, $this->isEditable);
$navigation = new NavigationView(NavigationModel::getData(), NavigationModel::getNavigationPath());
$navigation->setEditable($this->isEditable);
$navigation->init();
$this->contents['title'] = NavigationModel::getTitle();
$this->contents['navigation'] = $navigation->render();
$this->contents['headline'] = NavigationModel::getHeadline();
$this->contents['navID'] = NavigationModel::getActiveNavID();
$this->contents['content'] = '';
$tmpContents = NavigationModel::getContents();
$this->contents['keyVisual'] = '';
$tmpKeyVisual = NavigationModel::getKeyVisual();
foreach ($tmpKeyVisual as $data)
{
$this->contents['keyVisual'] .= $this->buildContents($data);
}
$tmpContents = NavigationModel::getContents();
/**
* @var Database $modelClass
*/
foreach ($tmpContents as $key => $data)
foreach ($tmpContents as $data)
{
$modelClass = 'Model\\' . $data['Controller'] . 'Model';
$viewClass = 'View\\' . $data['Controller'] . 'View';
if (class_exists($modelClass, true))
{
$modelData = $modelClass::getItem($data['ID']);
}
else
{
/**
* TODO: ErrorHandler bauen
*/
return;
}
if (class_exists($viewClass, true))
{
$dataView = new $viewClass($modelData, $data['Controller']);
}
else
{
$dataView = new StandardView($modelData, $data['Controller']);
}
$this->contents['content'] .= $dataView->render();
$this->contents['content'] .= $this->buildContents($data);
}
$pageView = new StandardView($this->contents, 'index');
$pageView->setEditable($this->isEditable);
echo $pageView->render();
}
/**
* @param array $data
* @return string
*/
protected function buildContents(array $data)
{
/**
* @var Database $modelClass
*/
$modelClass = 'Model\\' . $data['Controller'] . 'Model';
$viewClass = 'View\\' . $data['Controller'] . 'View';
if (class_exists($modelClass, true))
{
if (isset($data['ID']))
{
$modelData = $modelClass::getItem($data['ID']);
}
if (isset($data['IDs']))
{
$tmpModelData = $data;
unset($tmpModelData['Controller']);
unset($tmpModelData['IDs']);
$modelClass::setFilter($data['IDs']);
$modelData = $modelClass::getIndex();
$modelData = array_merge($modelData, $tmpModelData);
$modelData['navID'] = $this->contents['navID'];
}
}
else
{
/**
* TODO: ErrorHandler bauen
*/
return '';
}
if (class_exists($viewClass, true))
{
$dataView = new $viewClass($modelData, $data['Controller']);
}
else
{
$dataView = new StandardView($modelData, $data['Controller']);
}
$dataView->setEditable($this->isEditable);
return $dataView->render();
}
}

View File

@@ -0,0 +1,23 @@
<?php
/**
* Created by CS medien- & kommunikationssysteme.
* @author Christian Steinle
* @date 05.10.2016
*
* @copyright CS medien- & kommunikationssysteme (http://www.steinle-computer.de)
*/
namespace Model;
use Helper\Database;
class ImageModel extends Database
{
const TBL_NAME = TBL_IMAGE;
const PRIMARY_KEY = 'ID';
const ORDER_BY = '';
}

View File

@@ -0,0 +1,20 @@
<?php
/**
* Created by CS medien- & kommunikationssysteme.
* @author Christian Steinle
* @date 05.10.2016
*
* @copyright CS medien- & kommunikationssysteme (http://www.steinle-computer.de)
*/
namespace Model;
class KeyVisualModel extends ImageModel
{
public static function setFilter(array $IDs)
{
$filter = static::PRIMARY_KEY . ' = ' . implode(' OR ' . static::PRIMARY_KEY . ' = ', $IDs);
static::$filter = $filter;
}
}

View File

@@ -28,7 +28,9 @@ class NavigationModel extends Database
protected static $activeNavID = 0;
protected static $header = '';
protected static $title = '';
protected static $keyVisual = array();
protected static $headline = '';
@@ -38,28 +40,53 @@ class NavigationModel extends Database
/**
* Setzt später benötigte Variablen für den FrontendController, so dass die Datenmodelle und die Views instanziiert werden können
* @param array $routeParts
* @param bool $isEditable
*/
public static function init(array $routeParts)
public static function init(array $routeParts, $isEditable = false)
{
self::getIndex();
$nav = self::$data;
$navStart = 0;
foreach ($routeParts as $navLink)
if ($isEditable)
{
foreach ($nav as $navID => $navItem)
self::initBackend($routeParts[0], false);
}
else
{
self::initFrontend($routeParts);
}
}
protected static function initBackend($siteID, $depth)
{
foreach (self::$data as $navID => $navItem)
{
if ($navID == $siteID && $depth === false)
{
if ($navItem['navStart'] == $navStart && $navItem['navLink'] == $navLink)
{
$navStart = $navItem['navID'];
self::$navigationPath[] = self::$activeNavID = $navItem['navID'];
self::$header = $navItem['navHeader'];
self::$headline = $navItem['navHeadline'];
self::initContent($navItem['navContent']);
}
self::$activeNavID = $navItem['navID'];
self::$title = $navItem['navTitle'];
self::$headline = $navItem['navHeadline'];
self::initKeyVisual($navItem['navKeyVisual']);
self::initContent($navItem['navContent']);
self::buildNavigationPath();
break;
}
}
}
/**
* @param string $navKeyVisual
*/
protected static function initKeyVisual($navKeyVisual)
{
if (is_null($navKeyVisual))
{
return;
}
if (is_array(json_decode($navKeyVisual, true)))
{
self::$keyVisual = json_decode($navKeyVisual, true);
}
}
/**
* @param string $navContents
@@ -76,6 +103,36 @@ class NavigationModel extends Database
}
}
protected static function buildNavigationPath()
{
$navStart = $navStartPath[] = self::$activeNavID;
while ($navStart !== '0' && !is_null($navStart))
{
$navStart = $navStartPath[] = self::$data[$navStart]['navStart'];
}
array_pop($navStartPath);
self::$navigationPath = array_reverse($navStartPath);
}
protected static function initFrontend(array $routeParts)
{
$navStart = 0;
foreach ($routeParts as $navLink)
{
foreach (self::$data as $navID => $navItem)
{
if ($navItem['navStart'] == $navStart && $navItem['navLink'] == $navLink)
{
$navStart = $navItem['navID'];
self::$navigationPath[] = self::$activeNavID = $navItem['navID'];
self::$title = $navItem['navTitle'];
self::initKeyVisual($navItem['navKeyVisual']);
self::$headline = $navItem['navHeadline'];
self::initContent($navItem['navContent']);
}
}
}
}
/**
* @return array
@@ -98,9 +155,18 @@ class NavigationModel extends Database
/**
* @return string
*/
public static function getHeader()
public static function getTitle()
{
return self::$header;
return self::$title;
}
/**
* @return array
*/
public static function getKeyVisual()
{
return self::$keyVisual;
}

View File

@@ -30,21 +30,25 @@ class FrontendRoute
*/
protected $request = array();
/**
* @var FrontendController|null
*/
protected $controller = null;
protected $action = '';
/**
* FrontendRoute constructor.
* @param string $route
* @param bool $editable
* @param array $request
*/
public function __construct($route, array $request = array())
public function __construct($route, $editable = false, array $request = array())
{
$this->setRoute($route);
$this->request = $request;
$this->controller = new FrontendController($this->route, $request);
$this->controller->setEditable($editable);
$this->controller->init();
}
@@ -56,7 +60,4 @@ class FrontendRoute
$this->route = trim($route, " \t\n\r\0\x0B/");
$this->routeParts = explode('/', $this->route);
}
}

View File

@@ -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;
}

View File

@@ -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;
}
}