Source for file tracks.php
Documentation is available at tracks.php
* @package Joomla.Administrator
* @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
* Methods supporting a list of tracks.
* @package Joomla.Administrator
* @subpackage com_banners
* @param array An optional associative array of configuration settings.
if (empty($config['filter_fields']))
$config['filter_fields'] =
array(
'cl.name', 'client_name',
'cat.title', 'category_title',
'track_type', 'a.track_type',
'track_date', 'a.track_date',
* Method to auto-populate the model state.
* Note. Calling getState in this method will result in recursion.
protected function populateState($ordering =
null, $direction =
null)
// Load the filter state.
$this->setState('filter.begin', $begin);
$this->setState('filter.category_id', $categoryId);
$this->setState('filter.client_id', $clientId);
// List state information.
* Build an SQL query to load the list data.
require_once JPATH_COMPONENT .
'/helpers/banners.php';
// Create a new query object.
$query =
$db->getQuery(true);
// Select the required fields from the table.
'a.track_date as track_date,'
.
'a.track_type as track_type,'
.
$db->quoteName('a.count') .
' as ' .
$db->quoteName('count')
$query->from($db->quoteName('#__banner_tracks') .
' AS a');
$query->join('LEFT', $db->quoteName('#__banners') .
' as b ON b.id=a.banner_id')
->select('b.name as name');
$query->join('LEFT', $db->quoteName('#__banner_clients') .
' as cl ON cl.id=b.cid')
->select('cl.name as client_name');
// Join with the category
$query->join('LEFT', $db->quoteName('#__categories') .
' as cat ON cat.id=b.catid')
->select('cat.title as category_title');
$query->where('a.track_type = ' . (int)
$type);
$clientId =
$this->getState('filter.client_id');
$query->where('b.cid = ' . (int)
$clientId);
$catedoryId =
$this->getState('filter.category_id');
$query->where('b.catid = ' . (int)
$catedoryId);
$begin =
$this->getState('filter.begin');
$query->where('a.track_date >= ' .
$db->quote($begin));
$query->where('a.track_date <= ' .
$db->quote($end));
// Add the list ordering clause.
$orderCol =
$this->getState('list.ordering', 'name');
$query->order($db->escape($orderCol) .
' ' .
$db->escape($this->getState('list.direction', 'ASC')));
* @param array An array of item ids.
* @return boolean Returns true on success, false on failure.
$categoryId =
$this->getState('category_id');
$allow =
$user->authorise('core.delete', 'com_banners.category.' . (int)
$categoryId);
$allow =
$user->authorise('core.delete', 'com_banners');
// Delete tracks from this banner
$query =
$db->getQuery(true)
->delete($db->quoteName('#__banner_tracks'));
$query->where('track_type = ' . (int)
$type);
$begin =
$this->getState('filter.begin');
$query->where('track_date >= ' .
$db->quote($begin));
$query->where('track_date <= ' .
$db->quote($end));
$clientId =
$this->getState('filter.client_id');
$where .=
' AND cid = ' . (int)
$clientId;
$where .=
' AND catid = ' . (int)
$categoryId;
$query->where('banner_id IN (SELECT id FROM ' .
$db->quoteName('#__banners') .
' WHERE ' .
$where .
')');
catch
(RuntimeException $e)
* @return string The file name
$basename =
$this->getState('basename');
$basename =
str_replace('__SITE__', $app->getCfg('sitename'), $basename);
$categoryId =
$this->getState('filter.category_id');
$basename =
str_replace('__CATID__', $categoryId, $basename);
$basename =
str_replace('__CATNAME__', $categoryName, $basename);
$clientId =
$this->getState('filter.client_id');
$basename =
str_replace('__CLIENTID__', $clientId, $basename);
$basename =
str_replace('__CLIENTID__', '', $basename);
$basename =
str_replace('__CLIENTNAME__', $clientName, $basename);
$basename =
str_replace('__CLIENTID__', '', $basename);
$basename =
str_replace('__CLIENTNAME__', '', $basename);
$typeName =
JText::_('COM_BANNERS_TYPE' .
$type);
$basename =
str_replace('__TYPENAME__', $typeName, $basename);
$basename =
str_replace('__TYPENAME__', '', $basename);
$begin =
$this->getState('filter.begin');
$basename =
str_replace('__BEGIN__', $begin, $basename);
* @return string The category name
$categoryId =
$this->getState('filter.category_id');
$query =
$db->getQuery(true)
->from($db->quoteName('#__categories'))
->where($db->quoteName('id') .
'=' .
$db->quote($categoryId));
$name =
$db->loadResult();
catch
(RuntimeException $e)
$name =
JText::_('COM_BANNERS_NOCATEGORYNAME');
* @return string The category name.
$clientId =
$this->getState('filter.client_id');
$query =
$db->getQuery(true)
->from($db->quoteName('#__banner_clients'))
->where($db->quoteName('id') .
'=' .
$db->quote($clientId));
$name =
$db->loadResult();
catch
(RuntimeException $e)
$name =
JText::_('COM_BANNERS_NOCLIENTNAME');
* @return string The file type
return $this->getState('compressed') ?
'zip' :
'csv';
* @return string The mime type.
return $this->getState('compressed') ?
'application/zip' :
'text/csv';
* @return string The content.
if (!isset
($this->content))
str_replace('"', '""', $item->category_title) .
'","' .
str_replace('"', '""', ($item->track_type ==
1 ?
JText::_('COM_BANNERS_IMPRESSION') :
JText::_('COM_BANNERS_CLICK'))) .
'","' .
str_replace('"', '""', $item->track_date) .
'"' .
"\n";
$files['track'] =
array();
$files['track']['name'] =
$this->getBasename() .
'.csv';
$files['track']['data'] =
$this->content;
$files['track']['time'] =
time();
$ziproot =
$app->getCfg('tmp_path') .
'/' .
uniqid('banners_tracks_') .
'.zip';
jimport('joomla.filesystem.folder');
$delete =
JFolder::files($app->getCfg('tmp_path') .
'/', uniqid('banners_tracks_'), false, true);
// JFile::delete throws an error
elseif (!$packager->create($ziproot, $files))
Documentation generated on Tue, 19 Nov 2013 15:15:58 +0100 by phpDocumentor 1.4.3