system/modules/sg-history/modules/SgModuleHistoryList.php line 58

Open in your IDE?
  1. <?php
  2. /**
  3.  * Contao Open Source CMS
  4.  *
  5.  * Copyright (c) 2005-2015 Leo Feyer
  6.  *
  7.  * @package   SgHistory
  8.  * @author    Sg-Medien GmbH <info@sg-medien.com>
  9.  * @license   EULA
  10.  * @copyright Sg-Medien GmbH 2015
  11.  */
  12. /**
  13.  * Set custom namespace
  14.  */
  15. namespace SgM;
  16. /**
  17.  * Class SgModuleHistoryList
  18.  *
  19.  * Frontend module "history list".
  20.  *
  21.  * @package   SgHistory
  22.  * @author    Sg-Medien GmbH <info@sg-medien.com>
  23.  * @copyright Sg-Medien GmbH 2015
  24.  */
  25. class SgModuleHistoryList extends \SgModuleHistory
  26. {
  27.     /**
  28.      * Template
  29.      * @var string
  30.      */
  31.     protected $strTemplate 'mod_history_list';
  32.     /**
  33.      * Display a wildcard in the backend
  34.      * @return string
  35.      */
  36.     public function generate()
  37.     {
  38.         if (TL_MODE == 'BE') {
  39.             $objTemplate = new \BackendTemplate('be_wildcard');
  40.             $objTemplate->wildcard '### ' utf8_strtoupper($GLOBALS['TL_LANG']['FMD']['history_list'][0]) . ' ###';
  41.             $objTemplate->title $this->headline;
  42.             $objTemplate->id $this->id;
  43.             $objTemplate->link $this->name;
  44.             $objTemplate->href 'contao/main.php?do=themes&amp;table=tl_module&amp;act=edit&amp;id=' $this->id;
  45.             return $objTemplate->parse();
  46.         }
  47.         $this->history_categories deserialize($this->history_categories);
  48.         // return if there are no history categories
  49.         if (!is_array($this->history_categories) || empty($this->history_categories)) {
  50.             return '';
  51.         }
  52.         return parent::generate();
  53.     }
  54.     /**
  55.      * Generate the module
  56.      */
  57.     protected function compile()
  58.     {
  59.         global $objPage;
  60.         // sorting
  61.         $arrAvailableSort \SgHistory::getAvailableSorts();
  62.         $arrSqlOptions['order'] = ($this->history_sortDefault AND isset($arrAvailableSort) AND isset($arrAvailableSort[$this->history_sortDefault])) ? $arrAvailableSort[$this->history_sortDefault] : '%t.date DESC';
  63.         // get history items
  64.         $objItems \SgHistoryModel::findAllOrByPids($this->history_categories$arrSqlOptions);
  65.         // add the items
  66.         $items = array();
  67.         if ($objItems !== null) {
  68.             while ($objItems->next()) {
  69.                 // add image
  70.                 $image false;
  71.                 if ($objItems->addImage AND $objItems->singleSRC != '') {
  72.                     $objModel \FilesModel::findByUuid($objItems->singleSRC);
  73.                     if ($objModel !== null) {
  74.                         $objFile = new \File($objModel->pathtrue);
  75.                         if (!$objFile->isImage) {
  76.                             continue;
  77.                         }
  78.                         $arrMeta $this->getMetaData($objModel->meta$objPage->language);
  79.                         if (!empty($arrMeta)) {
  80.                             if ($objPage->rootFallbackLanguage !== null) {
  81.                                 $arrMeta $this->getMetaData($objModel->meta$objPage->rootFallbackLanguage);
  82.                             }
  83.                         }
  84.                         // use the file name as title if none is given
  85.                         if ($arrMeta['title'] == '') {
  86.                             $arrMeta['title'] = specialchars($objFile->basename);
  87.                         }
  88.                         // add the image
  89.                         $objImg = new \stdClass();
  90.                         $this->addImageToTemplate($objImg, array
  91.                         (
  92.                             'id' => $objModel->id,
  93.                             'uuid' => $objModel->uuid,
  94.                             'name' => $objFile->basename,
  95.                             'singleSRC' => $objModel->path,
  96.                             'alt' => $arrMeta['title'],
  97.                             'imageUrl' => $arrMeta['link'],
  98.                             'caption' => $arrMeta['caption'],
  99.                             'size' => $this->imgSize
  100.                         ), floor(\Config::get('maxImageWidth')));
  101.                         $image $objImg;
  102.                     }
  103.                 }
  104.                 // add item
  105.                 $items[] = array_merge($objItems->row(), array('image' => $image));
  106.             }
  107.         }
  108.         //add all to template
  109.         $this->Template->items $items;
  110.     }
  111. }