124 lines
2.8 KiB
PHP
124 lines
2.8 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 Controller;
|
|
|
|
use Helper\Database;
|
|
use Model\NavigationModel;
|
|
use View\NavigationView;
|
|
use View\StandardView;
|
|
|
|
class FrontendController
|
|
{
|
|
protected $route = '';
|
|
|
|
protected $isEditable = false;
|
|
|
|
protected $request = array();
|
|
|
|
protected $contents = array();
|
|
|
|
public function __construct($route, array $request)
|
|
{
|
|
$this->route = $route;
|
|
$this->routeParts = explode('/', $route);
|
|
$this->request = $request;
|
|
}
|
|
|
|
|
|
public function setEditable($isEditable)
|
|
{
|
|
$this->isEditable = $isEditable;
|
|
}
|
|
|
|
|
|
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'] = '';
|
|
$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 $data)
|
|
{
|
|
$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();
|
|
}
|
|
} |