system/modules/sg-history/models/SgHistoryModel.php line 66

Open in your IDE?
  1. <?php
  2. /**
  3.  * Contao Open Source CMS
  4.  *
  5.  * Copyright (c) 2005-2015 Leo Feyer
  6.  *
  7.  * @package   Sg-History
  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 SgHistoryModel
  18.  *
  19.  * Reads and writes history.
  20.  *
  21.  * @package   SgHistory
  22.  * @author    Sg-Medien GmbH <info@sg-medien.com>
  23.  * @copyright Sg-Medien GmbH 2015
  24.  */
  25. class SgHistoryModel extends \Model
  26. {
  27.     /**
  28.      * Table name
  29.      * @var string
  30.      */
  31.     protected static $strTable 'tl_sg_history';
  32.     /**
  33.      * Find all history elements (optional by their parent IDs)
  34.      *
  35.      * @param array $arrPids An optional array of history category IDs
  36.      * @param array $arrOptions An optional options array
  37.      *
  38.      * @return \Model\Collection|null A collection of models or null if there are no history elements
  39.      */
  40.     public static function findAllOrByPids(array $arrPids = array(), array $arrOptions = array())
  41.     {
  42.         $t = static::$strTable;
  43.         $arrColumns = (is_array($arrPids) AND !empty($arrPids)) ? array("$t.pid IN(" implode(','array_map('intval'$arrPids)) . ")") : array("$t.pid!=0");
  44.         if (!BE_USER_LOGGED_IN) {
  45.             $time time();
  46.             $arrColumns[] = "($t.start='' OR $t.start<$time) AND ($t.stop='' OR $t.stop>$time) AND $t.invisible='' AND $t.tstamp <= $time";
  47.         }
  48.         if (isset($arrOptions['order'])) {
  49.             $arrOptions['order'] = str_replace('%t'$t$arrOptions['order']);
  50.         }
  51.         if (!isset($arrOptions['order'])) {
  52.             $arrOptions['order'] = "$t.date DESC";
  53.         }
  54.         return static::findBy($arrColumnsnull$arrOptions);
  55.     }
  56. }