Source for file banners.php
Documentation is available at banners.php
* @subpackage com_banners
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* Banners model for the Joomla Banners component.
* @subpackage com_banners
* Method to get a store id based on model configuration state.
* This is necessary because the model is used by the component and
* different modules that might need different sets of data or different
* @param string $id A prefix for the store id.
* @return string A store id.
$id .=
':' .
$this->getState('filter.search');
$id .=
':' .
$this->getState('filter.tag_search');
$id .=
':' .
$this->getState('filter.client_id');
* @return array An array of banner objects.
$query =
$db->getQuery(true);
$ordering =
$this->getState('filter.ordering');
$tagSearch =
$this->getState('filter.tag_search');
$cid =
$this->getState('filter.client_id');
$categoryId =
$this->getState('filter.category_id');
$keywords =
$this->getState('filter.keywords');
$randomise =
($ordering ==
'random');
$nullDate =
$db->quote($db->getNullDate());
'a.clickurl as clickurl,' .
'a.custombannercode as custombannercode,' .
'a.track_impressions as track_impressions,' .
'cl.track_impressions as client_track_impressions'
->from('#__banners as a')
->join('LEFT', '#__banner_clients AS cl ON cl.id = a.cid')
->where('(' .
$query->currentTimestamp() .
' >= a.publish_up OR a.publish_up = ' .
$nullDate .
')')
->where('(' .
$query->currentTimestamp() .
' <= a.publish_down OR a.publish_down = ' .
$nullDate .
')')
->where('(a.imptotal = 0 OR a.impmade <= a.imptotal)');
$query->join('LEFT', '#__categories as cat ON a.catid = cat.id')
->where('a.cid = ' . (int)
$cid)
// Filter by a single or group of categories
$type =
$this->getState('filter.category_id.include', true) ?
'= ' :
'<> ';
$includeSubcategories =
$this->getState('filter.subcategories', false);
$categoryEquals =
'a.catid ' .
$type . (int)
$categoryId;
if ($includeSubcategories)
$levels = (int)
$this->getState('filter.max_category_levels', '1');
// Create a subquery for the subcategory list
$subQuery =
$db->getQuery(true);
$subQuery->select('sub.id')
->from('#__categories as sub')
->join('INNER', '#__categories as this ON sub.lft > this.lft AND sub.rgt < this.rgt')
->where('this.id = ' . (int)
$categoryId)
->where('sub.level <= this.level + ' .
$levels);
// Add the subquery to the main query
$query->where('(' .
$categoryEquals .
' OR a.catid IN (' .
$subQuery->__toString() .
'))');
$query->where($categoryEquals);
$categoryId =
implode(',', $categoryId);
$type =
$this->getState('filter.category_id.include', true) ?
'IN' :
'NOT IN';
$query->where('a.catid ' .
$type .
' (' .
$categoryId .
')');
if (count($keywords) ==
0)
$prefix =
$config->get('metakey_prefix');
foreach ($keywords as $keyword)
$keyword =
trim($keyword);
$condition1 =
"a.own_prefix=1 AND a.metakey_prefix=SUBSTRING(" .
$db->quote($keyword) .
",1,LENGTH( a.metakey_prefix)) OR a.own_prefix=0 AND cl.own_prefix=1 AND cl.metakey_prefix=SUBSTRING(" .
$db->quote($keyword) .
",1,LENGTH(cl.metakey_prefix)) OR a.own_prefix=0 AND cl.own_prefix=0 AND " .
($prefix ==
substr($keyword, 0, strlen($prefix)) ?
'1' :
'0');
$condition2 =
"a.metakey REGEXP '[[:<:]]" .
$db->escape($keyword) .
"[[:>:]]'";
$condition2 .=
" OR cl.metakey REGEXP '[[:<:]]" .
$db->escape($keyword) .
"[[:>:]]'";
$condition2 .=
" OR cat.metakey REGEXP '[[:<:]]" .
$db->escape($keyword) .
"[[:>:]]'";
$temp[] =
"($condition1) AND ($condition2)";
$query->where('(' .
implode(' OR ', $temp) .
')');
$query->where('a.language in (' .
$db->quote(JFactory::getLanguage()->getTag()) .
',' .
$db->quote('*') .
')');
$query->order('a.sticky DESC,' .
($randomise ?
'RAND()' :
'a.ordering'));
if (!isset
($this->cache['items']))
foreach ($this->cache['items'] as &$item)
$parameters->loadString($item->params);
$item->params =
$parameters;
return $this->cache['items'];
* Makes impressions on a list of banners
$query =
$db->getQuery(true);
foreach ($items as $item)
// Increment impression made
->set('impmade = (impmade + 1)')
->where('id = ' . (int)
$id);
catch
(RuntimeException $e)
$trackImpressions =
$item->track_impressions;
if ($trackImpressions <
0 &&
$item->cid)
$trackImpressions =
$item->client_track_impressions;
if ($trackImpressions <
0)
$trackImpressions =
$config->get('track_impressions');
if ($trackImpressions >
0)
// is track already created ?
->select($db->quoteName('count'))
->from('#__banner_tracks')
->where('banner_id=' . (int)
$id)
->where('track_date=' .
$db->quote($trackDate));
catch
(RuntimeException $e)
$count =
$db->loadResult();
$query->update('#__banner_tracks')
->set($db->quoteName('count') .
' = (' .
$db->quote('count') .
' + 1)')
->where('banner_id=' . (int)
$id)
->where('track_date=' .
$db->quote($trackDate));
$query->insert('#__banner_tracks')
$db->quoteName('count'), $db->quoteName('track_type'),
$db->quoteName('banner_id'), $db->quoteName('track_date')
->values('1, 1, ' . (int)
$id .
', ' .
$db->quote($trackDate));
catch
(RuntimeException $e)
Documentation generated on Tue, 19 Nov 2013 14:54:21 +0100 by phpDocumentor 1.4.3