372 lines
8.1 KiB
PHP
372 lines
8.1 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 Model;
|
|
|
|
|
|
use Helper\Database;
|
|
use Helper\Registry;
|
|
|
|
class NavigationModel extends Database
|
|
{
|
|
|
|
const TBL_NAME = TBL_FRONT_NAVIGATION;
|
|
|
|
const PRIMARY_KEY = 'navID';
|
|
|
|
const ORDER_BY = 'ORDER BY navSort ASC';
|
|
|
|
static $filter = 'navActive = "yes"';
|
|
|
|
protected static $navigationPath = array();
|
|
|
|
protected static $activeNavID = 0;
|
|
|
|
protected static $title = '';
|
|
|
|
protected static $keyVisual = array();
|
|
|
|
protected static $headline = '';
|
|
|
|
protected static $contents = array();
|
|
|
|
|
|
/**
|
|
* Setzt später benötigte Variablen für den FrontendController, so dass die Datenmodelle und die Views instanziiert werden können
|
|
* @author Christian Steinle
|
|
*
|
|
* @param array $routeParts
|
|
* @param bool $isEditable
|
|
*/
|
|
public static function init(array $routeParts, $isEditable = false)
|
|
{
|
|
self::getIndex();
|
|
if ($isEditable)
|
|
{
|
|
self::initBackend($routeParts[0], false);
|
|
}
|
|
else
|
|
{
|
|
self::initFrontend($routeParts);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* Initialisierung für das Backend ohne ModRewrite
|
|
* @author Christian Steinle
|
|
*
|
|
* @param int $siteID
|
|
* @param int $depth
|
|
*/
|
|
protected static function initBackend($siteID, $depth)
|
|
{
|
|
foreach (self::$data as $navID => $navItem)
|
|
{
|
|
if ($navID == $siteID && $depth === false)
|
|
{
|
|
self::$activeNavID = $navItem['navID'];
|
|
self::$title = $navItem['navTitle'];
|
|
self::$headline = $navItem['navHeadline'];
|
|
self::initKeyVisual($navItem['navKeyVisual']);
|
|
self::initContent($navItem['navContent']);
|
|
self::buildNavigationPath();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Umbau der Datenbank-Tabellenwerte in ein Mehrdimensionales Array
|
|
* @author Christian Steinle
|
|
*
|
|
* @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);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Umbau der Datenbank-Tabellenwerte in ein Mehrdimensionales Array
|
|
* @author Christian Steinle
|
|
*
|
|
* @param string $navContents
|
|
*/
|
|
protected static function initContent($navContents)
|
|
{
|
|
if (is_null($navContents))
|
|
{
|
|
return;
|
|
}
|
|
if (is_array(json_decode($navContents, true)))
|
|
{
|
|
self::$contents = json_decode($navContents, true);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* Baut den Navigationspfad als Array
|
|
* @author Christian Steinle
|
|
*/
|
|
protected static function buildNavigationPath()
|
|
{
|
|
$navStart = $navStartPath[] = self::$activeNavID;
|
|
while ($navStart !== '0' && !is_null($navStart))
|
|
{
|
|
$navStart = $navStartPath[] = self::$data[$navStart]['navStart'];
|
|
}
|
|
$navStartPath[] = '0';
|
|
array_pop($navStartPath);
|
|
self::$navigationPath = array_reverse($navStartPath);
|
|
}
|
|
|
|
|
|
/**
|
|
* Initialisiert das Frontend unter Verwendung des ModRewrites
|
|
* @author Christian Steinle
|
|
*
|
|
* @param array $routeParts
|
|
*/
|
|
protected static function initFrontend(array $routeParts)
|
|
{
|
|
$navStart = 0;
|
|
self::$navigationPath[] = 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']);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* Liefert den Navigationspfad als Array
|
|
*
|
|
* @return array
|
|
*/
|
|
public static function getNavigationPath()
|
|
{
|
|
return self::$navigationPath;
|
|
}
|
|
|
|
|
|
/**
|
|
* Liefert die NavigationsID des aktuellen gewählten Menüpunkts
|
|
*
|
|
* @return int
|
|
*/
|
|
public static function getActiveNavID()
|
|
{
|
|
return self::$activeNavID;
|
|
}
|
|
|
|
|
|
/**
|
|
* Liefert den Seiten-Titel
|
|
* @return string
|
|
*/
|
|
public static function getTitle()
|
|
{
|
|
return self::$title;
|
|
}
|
|
|
|
|
|
/**
|
|
* Liefert das Array für das KeyVisual
|
|
* @return array
|
|
*/
|
|
public static function getKeyVisual()
|
|
{
|
|
return self::$keyVisual;
|
|
}
|
|
|
|
|
|
/**
|
|
* Liefert die Überschrift der Seite
|
|
* @return string
|
|
*/
|
|
public static function getHeadline()
|
|
{
|
|
return self::$headline;
|
|
}
|
|
|
|
|
|
/**
|
|
* Liefert die Seiteninhalte
|
|
* @return array
|
|
*/
|
|
public static function getContents()
|
|
{
|
|
return self::$contents;
|
|
}
|
|
|
|
|
|
/**
|
|
* Liefert die Navigationsdaten als flaches Array
|
|
* @return array
|
|
*/
|
|
public static function getData()
|
|
{
|
|
return self::$data;
|
|
}
|
|
|
|
|
|
/**
|
|
* Liefert die Navigationsdaten, sortiert nach ihrem Elternknoten
|
|
* @return array
|
|
*/
|
|
public static function getStructuredIndex()
|
|
{
|
|
$tmpData = self::getIndex();
|
|
$structuredData = array();
|
|
foreach ($tmpData as $navID => $navData)
|
|
{
|
|
$structuredData['navStart_' . $navData['navStart']]['navID_' . $navID] = $navData;
|
|
}
|
|
return $structuredData;
|
|
}
|
|
|
|
|
|
/**
|
|
* Liefert einen Link, der innerhalb des NavStarts unique ist
|
|
* @author Christian Steinle
|
|
*
|
|
* @param int $navStart
|
|
* @param string $navName
|
|
* @return string
|
|
*/
|
|
public static function getUniqueNavLink($navStart, $navName)
|
|
{
|
|
$commonReplacements = array('ä' => 'ae', 'ö' => 'oe', 'ü' => 'ue', 'ß' => 'ss', ' ' => '_', '"', '', '\'' => '');
|
|
$registry = Registry::getInstance();
|
|
$replacements = $registry->editorConfig['linkReplacements'];
|
|
$navLink = trim(str_replace($replacements, '', $navName));
|
|
$navLink = mb_convert_case($navLink, MB_CASE_LOWER);
|
|
$navLink = str_replace(array_keys($commonReplacements), array_values($commonReplacements), $navLink);
|
|
|
|
self::$filter = 'navStart = ' . $navStart;
|
|
$existingNavLinks = 0;
|
|
$tmpData = self::getIndex();
|
|
|
|
foreach ($tmpData as $navPoint)
|
|
{
|
|
if ($navPoint['navLink'] == $navLink)
|
|
{
|
|
++$existingNavLinks;
|
|
}
|
|
}
|
|
|
|
if ($existingNavLinks === 0)
|
|
{
|
|
return $navLink;
|
|
}
|
|
return $navLink . '_' . $existingNavLinks;
|
|
}
|
|
|
|
|
|
/**
|
|
* Sortiert die Navigationspunkte eines übergebenen Elternelements
|
|
* @author Christian Steinle
|
|
*
|
|
* @param array $navPointData
|
|
* @return int
|
|
*/
|
|
public static function updateSortAfterInsert(array $navPointData)
|
|
{
|
|
if (!isset($navPointData['navStart']) || $navPointData['navStart'] === '')
|
|
{
|
|
return -1;
|
|
}
|
|
|
|
self::$filter = 'navStart = ' . $navPointData['navStart'];
|
|
$sortOrder = $navPointData['navSort'];
|
|
$tmpData = self::getIndex();
|
|
unset($tmpData[$navPointData['navID']]);
|
|
if ($sortOrder != 0)
|
|
{
|
|
array_splice($tmpData, 0, $sortOrder);
|
|
}
|
|
|
|
foreach($tmpData as $navData)
|
|
{
|
|
++$sortOrder;
|
|
self::update(array('navID' => $navData['navID'], 'navSort' => $sortOrder));
|
|
}
|
|
|
|
return 1;
|
|
}
|
|
|
|
|
|
/**
|
|
* Sortiert die Navigationspunkte eines Elternelements um
|
|
* @author Christian Steinle
|
|
*
|
|
* @param $sortData
|
|
* @return int
|
|
*/
|
|
public static function updateSort($sortData)
|
|
{
|
|
foreach($sortData as $navSort => $navID)
|
|
{
|
|
self::update(array('navID' => $navID, 'navSort' => $navSort));
|
|
}
|
|
|
|
return 1;
|
|
}
|
|
|
|
|
|
/**
|
|
* Legt die Bilddaten des Keyvisuals an, und liefert den passenden JSON-String für den Eintrag in die Datenbank-Tabelle
|
|
* @author Christian Steinle
|
|
*
|
|
* @param array $request
|
|
*/
|
|
protected static function beforeInsert(&$request)
|
|
{
|
|
$registry = Registry::getInstance();
|
|
$imageData = $registry->editorConfig['imageDimension']['keyVisual'];
|
|
$standardImagePath = substr(str_replace(PATH_PREFIX, '', PATH_ROOT), 0, -1) . $imageData['standardImage'];
|
|
|
|
$filename = end(explode('/', $standardImagePath));
|
|
$fileArray = ImageModel::filenameToArray($filename);
|
|
$imageData = array();
|
|
$imageData['imageOrigName'] = $fileArray['filename'];
|
|
$imageData['imageExtension'] = $fileArray['extension'];
|
|
$imageData['imageName'] = $fileArray['filename'];
|
|
$imageData['imageTitle'] = $fileArray['filename'];
|
|
list($width, $height) = getimagesize($standardImagePath);
|
|
$imageData['imageTop'] = 0;
|
|
$imageData['imageLeft'] = 0;
|
|
$imageData['imageHeight'] = $height;
|
|
$imageData['imageWidth'] = $width;
|
|
|
|
$imageID = ImageModel::insert($imageData);
|
|
$request['navKeyVisual'] = json_encode(array('Controller' => 'KeyVisual', 'Type' => 'Single', 'IDs' => array($imageID)));
|
|
}
|
|
} |