Skip to content
21 changes: 20 additions & 1 deletion components/com_banners/src/Model/BannerModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ public function &getItem()
$db = $this->getDatabase();

$loader = function ($id) use ($db) {
$nowDate = Factory::getDate()->toSql();
$query = $db->getQuery(true);

$query->select(
Expand All @@ -184,7 +185,25 @@ public function &getItem()
->from($db->quoteName('#__banners', 'a'))
->join('LEFT', $db->quoteName('#__banner_clients', 'cl'), $db->quoteName('cl.id') . ' = ' . $db->quoteName('a.cid'))
->where($db->quoteName('a.id') . ' = :id')
->bind(':id', $id, ParameterType::INTEGER);
->where($db->quoteName('a.state') . ' = 1')
->extendWhere(
'AND',
[
$db->quoteName('a.publish_up') . ' IS NULL',
$db->quoteName('a.publish_up') . ' <= :nowDate',
],
'OR'
)
->extendWhere(
'AND',
[
$db->quoteName('a.publish_down') . ' IS NULL',
$db->quoteName('a.publish_down') . ' >= :nowDate',
],
'OR'
)
->bind(':id', $id, ParameterType::INTEGER)
->bind(':nowDate', $nowDate);

$db->setQuery($query);

Expand Down
Loading