Newer
Older
michael.daniel
committed
<?php
/**
* This file contains QUI\Timeline\Controls\Timeline
*/
namespace QUI\Timeline\Controls;
use QUI;
use QUI\Projects\Site\Utils;
/**
* Class Timeline
*
* @package quiqqer/timeline
*/
class Timeline extends QUI\Control
{
/**
* constructor
*
* @param array $attributes
*/
public function __construct(array $attributes = [])
michael.daniel
committed
{
// default options
$this->setAttributes([
'nodeName' => 'section',
'class' => 'timeline-section',
'order' => 'c_date ASC',
michael.daniel
committed
'parentInputList' => false, //todo später für brick
'showLinks' => true,
'display' => 'VerticalBothSides',
'limit' => 10,
'imageFillMode' => 'cover', // cover / contain
michael.daniel
committed
// Custom children template (path to html file); overwrites "display"
'displayTemplate' => false,
// Custom children template css (path to css file); overwrites "display"
'displayCss' => false,
'itemtype' => 'http://schema.org/ItemList',
'child-itemtype' => 'https://schema.org/ListItem',
'child-itemprop' => 'itemListElement'
]);
michael.daniel
committed
parent::__construct($attributes);
}
/**
* Return the inner body of the element
* Can be overwritten
*
* @return String
*/
michael.daniel
committed
{
$Engine = QUI::getTemplateManager()->getEngine();
$Site = $this->getSite();
michael.daniel
committed
$Project = $this->getProject();
michael.daniel
committed
if (!$Site && !$this->getAttribute('parentInputList')) {
return '';
}
michael.daniel
committed
$parents = $this->getAttribute('parentInputList');
if (!$parents) {
$parents = $Site->getId();
}
// only active sites
$where['active'] = 1;
if ($this->getAttribute('parentInputList')) {
// for bricks
$children = Utils::getSitesByInputList($Project, $parents, [
michael.daniel
committed
'where' => $where,
'order' => $this->getAttribute('order'),
'limit' => $limit,
michael.daniel
committed
} else {
// for site types
michael.daniel
committed
'where' => $where,
'order' => $this->getAttribute('order'),
'limit' => $limit,
michael.daniel
committed
}
$Engine->assign([
'this' => $this,
'Site' => $Site,
'Project' => $this->getProject(),
'children' => $children,
'showLinks' => $this->getAttribute('showLinks'),
'imageFit' => $this->getAttribute('imageFillMode')
michael.daniel
committed
// load custom template (if set)
if (
$this->getAttribute('displayTemplate')
michael.daniel
committed
&& file_exists($this->getAttribute('displayTemplate'))
) {
if (
$this->getAttribute('displayCss')
michael.daniel
committed
&& file_exists($this->getAttribute('displayCss'))
) {
$this->addCSSFile($this->getAttribute('displayCss'));
}
return $Engine->fetch($this->getAttribute('displayTemplate'));
}
// template
$css = dirname(__FILE__) . '/Timeline.' . $this->getAttribute('display') . '.css';
michael.daniel
committed
$template = dirname(__FILE__) . '/Timeline.' . $this->getAttribute('display') . '.html';
michael.daniel
committed
$this->addCSSFile($css);
return $Engine->fetch($template);
}
/**
michael.daniel
committed
*/
protected function getSite(): ?QUI\Interfaces\Projects\Site
michael.daniel
committed
{
if ($this->getAttribute('Site')) {
return $this->getAttribute('Site');
}
$Site = QUI::getRewrite()->getSite();
$this->setAttribute('Site', $Site);
return $Site;
}
}