<?php
/**
* Contao Open Source CMS
*
* Copyright (c) 2005-2015 Leo Feyer
*
* @package Sg-History
* @author Sg-Medien GmbH <info@sg-medien.com>
* @license EULA
* @copyright Sg-Medien GmbH 2015
*/
/**
* Set custom namespace
*/
namespace SgM;
/**
* Class SgHistoryModel
*
* Reads and writes history.
*
* @package SgHistory
* @author Sg-Medien GmbH <info@sg-medien.com>
* @copyright Sg-Medien GmbH 2015
*/
class SgHistoryModel extends \Model
{
/**
* Table name
* @var string
*/
protected static $strTable = 'tl_sg_history';
/**
* Find all history elements (optional by their parent IDs)
*
* @param array $arrPids An optional array of history category IDs
* @param array $arrOptions An optional options array
*
* @return \Model\Collection|null A collection of models or null if there are no history elements
*/
public static function findAllOrByPids(array $arrPids = array(), array $arrOptions = array())
{
$t = static::$strTable;
$arrColumns = (is_array($arrPids) AND !empty($arrPids)) ? array("$t.pid IN(" . implode(',', array_map('intval', $arrPids)) . ")") : array("$t.pid!=0");
if (!BE_USER_LOGGED_IN) {
$time = time();
$arrColumns[] = "($t.start='' OR $t.start<$time) AND ($t.stop='' OR $t.stop>$time) AND $t.invisible='' AND $t.tstamp <= $time";
}
if (isset($arrOptions['order'])) {
$arrOptions['order'] = str_replace('%t', $t, $arrOptions['order']);
}
if (!isset($arrOptions['order'])) {
$arrOptions['order'] = "$t.date DESC";
}
return static::findBy($arrColumns, null, $arrOptions);
}
}