<?php
/**
* Contao Open Source CMS
*
* Copyright (c) 2005-2015 Leo Feyer
*
* @package SgHistory
* @author Sg-Medien GmbH <info@sg-medien.com>
* @license EULA
* @copyright Sg-Medien GmbH 2015
*/
/**
* Set custom namespace
*/
namespace SgM;
/**
* Class SgModuleHistoryList
*
* Frontend module "history list".
*
* @package SgHistory
* @author Sg-Medien GmbH <info@sg-medien.com>
* @copyright Sg-Medien GmbH 2015
*/
class SgModuleHistoryList extends \SgModuleHistory
{
/**
* Template
* @var string
*/
protected $strTemplate = 'mod_history_list';
/**
* Display a wildcard in the backend
* @return string
*/
public function generate()
{
if (TL_MODE == 'BE') {
$objTemplate = new \BackendTemplate('be_wildcard');
$objTemplate->wildcard = '### ' . utf8_strtoupper($GLOBALS['TL_LANG']['FMD']['history_list'][0]) . ' ###';
$objTemplate->title = $this->headline;
$objTemplate->id = $this->id;
$objTemplate->link = $this->name;
$objTemplate->href = 'contao/main.php?do=themes&table=tl_module&act=edit&id=' . $this->id;
return $objTemplate->parse();
}
$this->history_categories = deserialize($this->history_categories);
// return if there are no history categories
if (!is_array($this->history_categories) || empty($this->history_categories)) {
return '';
}
return parent::generate();
}
/**
* Generate the module
*/
protected function compile()
{
global $objPage;
// sorting
$arrAvailableSort = \SgHistory::getAvailableSorts();
$arrSqlOptions['order'] = ($this->history_sortDefault AND isset($arrAvailableSort) AND isset($arrAvailableSort[$this->history_sortDefault])) ? $arrAvailableSort[$this->history_sortDefault] : '%t.date DESC';
// get history items
$objItems = \SgHistoryModel::findAllOrByPids($this->history_categories, $arrSqlOptions);
// add the items
$items = array();
if ($objItems !== null) {
while ($objItems->next()) {
// add image
$image = false;
if ($objItems->addImage AND $objItems->singleSRC != '') {
$objModel = \FilesModel::findByUuid($objItems->singleSRC);
if ($objModel !== null) {
$objFile = new \File($objModel->path, true);
if (!$objFile->isImage) {
continue;
}
$arrMeta = $this->getMetaData($objModel->meta, $objPage->language);
if (!empty($arrMeta)) {
if ($objPage->rootFallbackLanguage !== null) {
$arrMeta = $this->getMetaData($objModel->meta, $objPage->rootFallbackLanguage);
}
}
// use the file name as title if none is given
if ($arrMeta['title'] == '') {
$arrMeta['title'] = specialchars($objFile->basename);
}
// add the image
$objImg = new \stdClass();
$this->addImageToTemplate($objImg, array
(
'id' => $objModel->id,
'uuid' => $objModel->uuid,
'name' => $objFile->basename,
'singleSRC' => $objModel->path,
'alt' => $arrMeta['title'],
'imageUrl' => $arrMeta['link'],
'caption' => $arrMeta['caption'],
'size' => $this->imgSize
), floor(\Config::get('maxImageWidth')));
$image = $objImg;
}
}
// add item
$items[] = array_merge($objItems->row(), array('image' => $image));
}
}
//add all to template
$this->Template->items = $items;
}
}