first commit

This commit is contained in:
alazhar
2020-01-02 22:20:31 +07:00
commit 10eb3340ad
5753 changed files with 631345 additions and 0 deletions

View File

@ -0,0 +1,549 @@
<?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
*/
defined('_JEXEC') or die;
/**
* Banner model.
*
* @package Joomla.Administrator
* @subpackage com_banners
* @since 1.6
*/
class BannersModelBanner extends JModelAdmin
{
/**
* @var string The prefix to use with controller messages.
* @since 1.6
*/
protected $text_prefix = 'COM_BANNERS_BANNER';
/**
* Method to perform batch operations on an item or a set of items.
*
* @param array $commands An array of commands to perform.
* @param array $pks An array of item ids.
* @param array $contexts An array of item contexts.
*
* @return boolean Returns true on success, false on failure.
*
* @since 2.5
*/
public function batch($commands, $pks, $contexts)
{
// Sanitize user ids.
$pks = array_unique($pks);
JArrayHelper::toInteger($pks);
// Remove any values of zero.
if (array_search(0, $pks, true))
{
unset($pks[array_search(0, $pks, true)]);
}
if (empty($pks))
{
$this->setError(JText::_('JGLOBAL_NO_ITEM_SELECTED'));
return false;
}
$done = false;
if (!empty($commands['category_id']))
{
$cmd = JArrayHelper::getValue($commands, 'move_copy', 'c');
if ($cmd == 'c')
{
$result = $this->batchCopy($commands['category_id'], $pks, $contexts);
if (is_array($result))
{
$pks = $result;
}
else
{
return false;
}
}
elseif ($cmd == 'm' && !$this->batchMove($commands['category_id'], $pks, $contexts))
{
return false;
}
$done = true;
}
if (strlen($commands['client_id']) > 0)
{
if (!$this->batchClient($commands['client_id'], $pks, $contexts))
{
return false;
}
$done = true;
}
if (!empty($commands['language_id']))
{
if (!$this->batchLanguage($commands['language_id'], $pks, $contexts))
{
return false;
}
$done = true;
}
if (!$done)
{
$this->setError(JText::_('JLIB_APPLICATION_ERROR_INSUFFICIENT_BATCH_INFORMATION'));
return false;
}
// Clear the cache
$this->cleanCache();
return true;
}
/**
* Batch client changes for a group of banners.
*
* @param string $value The new value matching a client.
* @param array $pks An array of row IDs.
* @param array $contexts An array of item contexts.
*
* @return boolean True if successful, false otherwise and internal error is set.
*
* @since 2.5
*/
protected function batchClient($value, $pks, $contexts)
{
// Set the variables
$user = JFactory::getUser();
$table = $this->getTable();
foreach ($pks as $pk)
{
if ($user->authorise('core.edit', $contexts[$pk]))
{
$table->reset();
$table->load($pk);
$table->cid = (int) $value;
if (!$table->store())
{
$this->setError($table->getError());
return false;
}
}
else
{
$this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_EDIT'));
return false;
}
}
// Clean the cache
$this->cleanCache();
return true;
}
/**
* Batch copy items to a new category or current.
*
* @param integer $value The new category.
* @param array $pks An array of row IDs.
* @param array $contexts An array of item contexts.
*
* @return mixed An array of new IDs on success, boolean false on failure.
*
* @since 2.5
*/
protected function batchCopy($value, $pks, $contexts)
{
$categoryId = (int) $value;
$table = $this->getTable();
$i = 0;
// Check that the category exists
if ($categoryId)
{
$categoryTable = JTable::getInstance('Category');
if (!$categoryTable->load($categoryId))
{
if ($error = $categoryTable->getError())
{
// Fatal error
$this->setError($error);
return false;
}
else
{
$this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_MOVE_CATEGORY_NOT_FOUND'));
return false;
}
}
}
if (empty($categoryId))
{
$this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_MOVE_CATEGORY_NOT_FOUND'));
return false;
}
// Check that the user has create permission for the component
$user = JFactory::getUser();
if (!$user->authorise('core.create', 'com_banners.category.' . $categoryId))
{
$this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_CREATE'));
return false;
}
// Parent exists so we let's proceed
while (!empty($pks))
{
// Pop the first ID off the stack
$pk = array_shift($pks);
$table->reset();
// Check that the row actually exists
if (!$table->load($pk))
{
if ($error = $table->getError())
{
// Fatal error
$this->setError($error);
return false;
}
else
{
// Not fatal error
$this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_BATCH_MOVE_ROW_NOT_FOUND', $pk));
continue;
}
}
// Alter the title & alias
$data = $this->generateNewTitle($categoryId, $table->alias, $table->name);
$table->name = $data['0'];
$table->alias = $data['1'];
// Reset the ID because we are making a copy
$table->id = 0;
// New category ID
$table->catid = $categoryId;
// TODO: Deal with ordering?
//$table->ordering = 1;
// Check the row.
if (!$table->check())
{
$this->setError($table->getError());
return false;
}
// Store the row.
if (!$table->store())
{
$this->setError($table->getError());
return false;
}
// Get the new item ID
$newId = $table->get('id');
// Add the new ID to the array
$newIds[$i] = $newId;
$i++;
}
// Clean the cache
$this->cleanCache();
return $newIds;
}
/**
* Method to test whether a record can be deleted.
*
* @param object $record A record object.
*
* @return boolean True if allowed to delete the record. Defaults to the permission set in the component.
*
* @since 1.6
*/
protected function canDelete($record)
{
if (!empty($record->id))
{
if ($record->state != -2)
{
return;
}
$user = JFactory::getUser();
if (!empty($record->catid))
{
return $user->authorise('core.delete', 'com_banners.category.' . (int) $record->catid);
}
else
{
return parent::canDelete($record);
}
}
}
/**
* Method to test whether a record can have its state changed.
*
* @param object $record A record object.
*
* @return boolean True if allowed to change the state of the record. Defaults to the permission set in the component.
*
* @since 1.6
*/
protected function canEditState($record)
{
$user = JFactory::getUser();
// Check against the category.
if (!empty($record->catid))
{
return $user->authorise('core.edit.state', 'com_banners.category.' . (int) $record->catid);
}
// Default to component settings if category not known.
else
{
return parent::canEditState($record);
}
}
/**
* Returns a JTable object, always creating it.
*
* @param string $type The table type to instantiate. [optional]
* @param string $prefix A prefix for the table class name. [optional]
* @param array $config Configuration array for model. [optional]
*
* @return JTable A database object
*
* @since 1.6
*/
public function getTable($type = 'Banner', $prefix = 'BannersTable', $config = array())
{
return JTable::getInstance($type, $prefix, $config);
}
/**
* Method to get the record form.
*
* @param array $data Data for the form. [optional]
* @param boolean $loadData True if the form is to load its own data (default case), false if not. [optional]
*
* @return mixed A JForm object on success, false on failure
*
* @since 1.6
*/
public function getForm($data = array(), $loadData = true)
{
// Get the form.
$form = $this->loadForm('com_banners.banner', 'banner', array('control' => 'jform', 'load_data' => $loadData));
if (empty($form))
{
return false;
}
// Determine correct permissions to check.
if ($this->getState('banner.id'))
{
// Existing record. Can only edit in selected categories.
$form->setFieldAttribute('catid', 'action', 'core.edit');
}
else
{
// New record. Can only create in selected categories.
$form->setFieldAttribute('catid', 'action', 'core.create');
}
// Modify the form based on access controls.
if (!$this->canEditState((object) $data))
{
// Disable fields for display.
$form->setFieldAttribute('ordering', 'disabled', 'true');
$form->setFieldAttribute('publish_up', 'disabled', 'true');
$form->setFieldAttribute('publish_down', 'disabled', 'true');
$form->setFieldAttribute('state', 'disabled', 'true');
$form->setFieldAttribute('sticky', 'disabled', 'true');
// Disable fields while saving.
// The controller has already verified this is a record you can edit.
$form->setFieldAttribute('ordering', 'filter', 'unset');
$form->setFieldAttribute('publish_up', 'filter', 'unset');
$form->setFieldAttribute('publish_down', 'filter', 'unset');
$form->setFieldAttribute('state', 'filter', 'unset');
$form->setFieldAttribute('sticky', 'filter', 'unset');
}
return $form;
}
/**
* Method to get the data that should be injected in the form.
*
* @return mixed The data for the form.
*
* @since 1.6
*/
protected function loadFormData()
{
// Check the session for previously entered form data.
$app = JFactory::getApplication();
$data = $app->getUserState('com_banners.edit.banner.data', array());
if (empty($data))
{
$data = $this->getItem();
// Prime some default values.
if ($this->getState('banner.id') == 0)
{
$data->set('catid', $app->input->getInt('catid', $app->getUserState('com_banners.banners.filter.category_id')));
}
}
$this->preprocessData('com_banners.banner', $data);
return $data;
}
/**
* Method to stick records.
*
* @param array &$pks The ids of the items to publish.
* @param integer $value The value of the published state
*
* @return boolean True on success.
*
* @since 1.6
*/
public function stick(&$pks, $value = 1)
{
$user = JFactory::getUser();
$table = $this->getTable();
$pks = (array) $pks;
// Access checks.
foreach ($pks as $i => $pk)
{
if ($table->load($pk))
{
if (!$this->canEditState($table))
{
// Prune items that you can't change.
unset($pks[$i]);
JError::raiseWarning(403, JText::_('JLIB_APPLICATION_ERROR_EDITSTATE_NOT_PERMITTED'));
}
}
}
// Attempt to change the state of the records.
if (!$table->stick($pks, $value, $user->get('id')))
{
$this->setError($table->getError());
return false;
}
return true;
}
/**
* A protected method to get a set of ordering conditions.
*
* @param JTable $table A record object.
*
* @return array An array of conditions to add to add to ordering queries.
*
* @since 1.6
*/
protected function getReorderConditions($table)
{
$condition = array();
$condition[] = 'catid = '. (int) $table->catid;
$condition[] = 'state >= 0';
return $condition;
}
/**
* @since 3.0
*/
protected function prepareTable($table)
{
$date = JFactory::getDate();
$user = JFactory::getUser();
if (empty($table->id))
{
// Set the values
$table->created = $date->toSql();
// Set ordering to the last item if not set
if (empty($table->ordering))
{
$db = JFactory::getDbo();
$db->setQuery('SELECT MAX(ordering) FROM #__banners');
$max = $db->loadResult();
$table->ordering = $max + 1;
}
}
else
{
// Set the values
$table->modified = $date->toSql();
$table->modified_by = $user->get('id');
}
// Increment the content version number.
$table->version++;
}
/**
* Method to save the form data.
*
* @param array The form data.
*
* @return boolean True on success.
* @since 1.6
*/
public function save($data)
{
$app = JFactory::getApplication();
// Alter the name for save as copy
if ($app->input->get('task') == 'save2copy')
{
list($name, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['name']);
$data['name'] = $name;
$data['alias'] = $alias;
$data['state'] = 0;
}
if (parent::save($data))
{
return true;
}
return false;
}
}

View File

@ -0,0 +1,252 @@
<?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
*/
defined('_JEXEC') or die;
/**
* Methods supporting a list of banner records.
*
* @package Joomla.Administrator
* @subpackage com_banners
* @since 1.6
*/
class BannersModelBanners extends JModelList
{
/**
* Constructor.
*
* @param array An optional associative array of configuration settings.
* @see JController
* @since 1.6
*/
public function __construct($config = array())
{
if (empty($config['filter_fields']))
{
$config['filter_fields'] = array(
'id', 'a.id',
'cid', 'a.cid', 'client_name',
'name', 'a.name',
'alias', 'a.alias',
'state', 'a.state',
'ordering', 'a.ordering',
'language', 'a.language',
'catid', 'a.catid', 'category_title',
'checked_out', 'a.checked_out',
'checked_out_time', 'a.checked_out_time',
'created', 'a.created',
'impmade', 'a.impmade',
'imptotal', 'a.imptotal',
'clicks', 'a.clicks',
'publish_up', 'a.publish_up',
'publish_down', 'a.publish_down',
'state', 'sticky', 'a.sticky',
);
}
parent::__construct($config);
}
/**
* Method to get the maximum ordering value for each category.
*
* @since 1.6
*/
public function &getCategoryOrders()
{
if (!isset($this->cache['categoryorders']))
{
$db = $this->getDbo();
$query = $db->getQuery(true)
->select('MAX(ordering) as ' . $db->quoteName('max') . ', catid')
->select('catid')
->from('#__banners')
->group('catid');
$db->setQuery($query);
$this->cache['categoryorders'] = $db->loadAssocList('catid', 0);
}
return $this->cache['categoryorders'];
}
/**
* Build an SQL query to load the list data.
*
* @return JDatabaseQuery
* @since 1.6
*/
protected function getListQuery()
{
$db = $this->getDbo();
$query = $db->getQuery(true);
// Select the required fields from the table.
$query->select(
$this->getState(
'list.select',
'a.id AS id, a.name AS name, a.alias AS alias,' .
'a.checked_out AS checked_out,' .
'a.checked_out_time AS checked_out_time, a.catid AS catid,' .
'a.clicks AS clicks, a.metakey AS metakey, a.sticky AS sticky,' .
'a.impmade AS impmade, a.imptotal AS imptotal,' .
'a.state AS state, a.ordering AS ordering,' .
'a.purchase_type as purchase_type,' .
'a.language, a.publish_up, a.publish_down'
)
);
$query->from($db->quoteName('#__banners') . ' AS a');
// Join over the language
$query->select('l.title AS language_title')
->join('LEFT', $db->quoteName('#__languages') . ' AS l ON l.lang_code = a.language');
// Join over the users for the checked out user.
$query->select('uc.name AS editor')
->join('LEFT', '#__users AS uc ON uc.id=a.checked_out');
// Join over the categories.
$query->select('c.title AS category_title')
->join('LEFT', '#__categories AS c ON c.id = a.catid');
// Join over the clients.
$query->select('cl.name AS client_name,cl.purchase_type as client_purchase_type')
->join('LEFT', '#__banner_clients AS cl ON cl.id = a.cid');
// Filter by published state
$published = $this->getState('filter.state');
if (is_numeric($published))
{
$query->where('a.state = ' . (int) $published);
}
elseif ($published === '')
{
$query->where('(a.state IN (0, 1))');
}
// Filter by category.
$categoryId = $this->getState('filter.category_id');
if (is_numeric($categoryId))
{
$query->where('a.catid = ' . (int) $categoryId);
}
// Filter by client.
$clientId = $this->getState('filter.client_id');
if (is_numeric($clientId))
{
$query->where('a.cid = ' . (int) $clientId);
}
// Filter by search in title
$search = $this->getState('filter.search');
if (!empty($search))
{
if (stripos($search, 'id:') === 0)
{
$query->where('a.id = ' . (int) substr($search, 3));
}
else
{
$search = $db->quote('%' . $db->escape($search, true) . '%');
$query->where('(a.name LIKE ' . $search . ' OR a.alias LIKE ' . $search . ')');
}
}
// Filter on the language.
if ($language = $this->getState('filter.language'))
{
$query->where('a.language = ' . $db->quote($language));
}
// Add the list ordering clause.
$orderCol = $this->state->get('list.ordering', 'ordering');
$orderDirn = $this->state->get('list.direction', 'ASC');
if ($orderCol == 'ordering' || $orderCol == 'category_title')
{
$orderCol = 'c.title ' . $orderDirn . ', a.ordering';
}
if ($orderCol == 'client_name')
{
$orderCol = 'cl.name';
}
$query->order($db->escape($orderCol . ' ' . $orderDirn));
//echo nl2br(str_replace('#__','jos_',$query));
return $query;
}
/**
* 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
* ordering requirements.
*
* @param string $id A prefix for the store id.
* @return string A store id.
* @since 1.6
*/
protected function getStoreId($id = '')
{
// Compile the store id.
$id .= ':' . $this->getState('filter.search');
$id .= ':' . $this->getState('filter.access');
$id .= ':' . $this->getState('filter.state');
$id .= ':' . $this->getState('filter.category_id');
$id .= ':' . $this->getState('filter.language');
return parent::getStoreId($id);
}
/**
* Returns a reference to the a Table object, always creating it.
*
* @param type The table type to instantiate
* @param string A prefix for the table class name. Optional.
* @param array Configuration array for model. Optional.
* @return JTable A database object
* @since 1.6
*/
public function getTable($type = 'Banner', $prefix = 'BannersTable', $config = array())
{
return JTable::getInstance($type, $prefix, $config);
}
/**
* Method to auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* @since 1.6
*/
protected function populateState($ordering = null, $direction = null)
{
// Load the filter state.
$search = $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search');
$this->setState('filter.search', $search);
$state = $this->getUserStateFromRequest($this->context . '.filter.state', 'filter_state', '', 'string');
$this->setState('filter.state', $state);
$categoryId = $this->getUserStateFromRequest($this->context . '.filter.category_id', 'filter_category_id', '');
$this->setState('filter.category_id', $categoryId);
$clientId = $this->getUserStateFromRequest($this->context . '.filter.client_id', 'filter_client_id', '');
$this->setState('filter.client_id', $clientId);
$language = $this->getUserStateFromRequest($this->context . '.filter.language', 'filter_language', '');
$this->setState('filter.language', $language);
// Load the parameters.
$params = JComponentHelper::getParams('com_banners');
$this->setState('params', $params);
// List state information.
parent::populateState('a.name', 'asc');
}
}

View File

@ -0,0 +1,134 @@
<?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
*/
defined('_JEXEC') or die;
/**
* Client model.
*
* @package Joomla.Administrator
* @subpackage com_banners
* @since 1.6
*/
class BannersModelClient extends JModelAdmin
{
/**
* Method to test whether a record can be deleted.
*
* @param object A record object.
* @return boolean True if allowed to delete the record. Defaults to the permission set in the component.
* @since 1.6
*/
protected function canDelete($record)
{
if (!empty($record->id))
{
if ($record->state != -2)
{
return;
}
$user = JFactory::getUser();
if (!empty($record->catid))
{
return $user->authorise('core.delete', 'com_banners.category.'.(int) $record->catid);
}
else {
return $user->authorise('core.delete', 'com_banners');
}
}
}
/**
* Method to test whether a record can be deleted.
*
* @param object A record object.
* @return boolean True if allowed to change the state of the record. Defaults to the permission set in the component.
* @since 1.6
*/
protected function canEditState($record)
{
$user = JFactory::getUser();
if (!empty($record->catid))
{
return $user->authorise('core.edit.state', 'com_banners.category.'.(int) $record->catid);
}
else
{
return $user->authorise('core.edit.state', 'com_banners');
}
}
/**
* Returns a reference to the a Table object, always creating it.
*
* @param type The table type to instantiate
* @param string A prefix for the table class name. Optional.
* @param array Configuration array for model. Optional.
* @return JTable A database object
* @since 1.6
*/
public function getTable($type = 'Client', $prefix = 'BannersTable', $config = array())
{
return JTable::getInstance($type, $prefix, $config);
}
/**
* Method to get the record form.
*
* @param array $data Data for the form.
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
* @return mixed A JForm object on success, false on failure
* @since 1.6
*/
public function getForm($data = array(), $loadData = true)
{
// Get the form.
$form = $this->loadForm('com_banners.client', 'client', array('control' => 'jform', 'load_data' => $loadData));
if (empty($form))
{
return false;
}
return $form;
}
/**
* Method to get the data that should be injected in the form.
*
* @return mixed The data for the form.
* @since 1.6
*/
protected function loadFormData()
{
// Check the session for previously entered form data.
$data = JFactory::getApplication()->getUserState('com_banners.edit.client.data', array());
if (empty($data))
{
$data = $this->getItem();
}
$this->preprocessData('com_banners.client', $data);
return $data;
}
/**
* Prepare and sanitise the table data prior to saving.
*
* @param JTable A JTable object.
* @since 1.6
*/
protected function prepareTable($table)
{
$table->name = htmlspecialchars_decode($table->name, ENT_QUOTES);
}
}

View File

@ -0,0 +1,165 @@
<?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
*/
defined('_JEXEC') or die;
/**
* Methods supporting a list of banner records.
*
* @package Joomla.Administrator
* @subpackage com_banners
* @since 1.6
*/
class BannersModelClients extends JModelList
{
/**
* Constructor.
*
* @param array An optional associative array of configuration settings.
* @see JController
* @since 1.6
*/
public function __construct($config = array())
{
if (empty($config['filter_fields']))
{
$config['filter_fields'] = array(
'id', 'a.id',
'name', 'a.name',
'contact', 'a.contact',
'state', 'a.state',
'checked_out', 'a.checked_out',
'checked_out_time', 'a.checked_out_time',
'nbanners',
);
}
parent::__construct($config);
}
/**
* Method to auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* @since 1.6
*/
protected function populateState($ordering = null, $direction = null)
{
// Load the filter state.
$search = $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search');
$this->setState('filter.search', $search);
$state = $this->getUserStateFromRequest($this->context . '.filter.state', 'filter_state', '', 'string');
$this->setState('filter.state', $state);
// Load the parameters.
$params = JComponentHelper::getParams('com_banners');
$this->setState('params', $params);
// List state information.
parent::populateState('a.name', 'asc');
}
/**
* 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
* ordering requirements.
*
* @param string $id A prefix for the store id.
*
* @return string A store id.
*/
protected function getStoreId($id = '')
{
// Compile the store id.
$id .= ':' . $this->getState('filter.search');
$id .= ':' . $this->getState('filter.access');
$id .= ':' . $this->getState('filter.state');
return parent::getStoreId($id);
}
/**
* Build an SQL query to load the list data.
*
* @return JDatabaseQuery
*/
protected function getListQuery()
{
// Create a new query object.
$db = $this->getDbo();
$query = $db->getQuery(true);
// Select the required fields from the table.
$query->select(
$this->getState(
'list.select',
'a.id AS id,' .
'a.name AS name,' .
'a.contact AS contact,' .
'a.checked_out AS checked_out,' .
'a.checked_out_time AS checked_out_time, ' .
'a.state AS state,' .
'a.metakey AS metakey,' .
'a.purchase_type as purchase_type'
)
);
$query->from($db->quoteName('#__banner_clients') . ' AS a');
// Join over the banners for counting
$query->select('COUNT(b.id) as nbanners')
->join('LEFT', '#__banners AS b ON a.id = b.cid');
// Join over the users for the checked out user.
$query->select('uc.name AS editor')
->join('LEFT', '#__users AS uc ON uc.id=a.checked_out');
// Filter by published state
$published = $this->getState('filter.state');
if (is_numeric($published))
{
$query->where('a.state = ' . (int) $published);
}
elseif ($published === '')
{
$query->where('(a.state IN (0, 1))');
}
$query->group('a.id, a.name, a.contact, a.checked_out, a.checked_out_time, a.state, a.metakey, a.purchase_type, uc.name');
// Filter by search in title
$search = $this->getState('filter.search');
if (!empty($search))
{
if (stripos($search, 'id:') === 0)
{
$query->where('a.id = ' . (int) substr($search, 3));
}
else
{
$search = $db->quote('%' . $db->escape($search, true) . '%');
$query->where('a.name LIKE ' . $search);
}
}
$ordering_o = $this->getState('list.ordering', 'ordering');
if ($ordering_o == 'nbanners')
{
$ordering_o = 'COUNT(b.id)';
}
// Add the list ordering clause.
$query->order($db->escape($ordering_o) . ' ' . $db->escape($this->getState('list.direction', 'ASC')));
//echo nl2br(str_replace('#__','jos_',$query));
return $query;
}
}

View File

@ -0,0 +1,79 @@
<?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
*/
defined('_JEXEC') or die;
/**
* Download model.
*
* @package Joomla.Administrator
* @subpackage com_banners
* @since 1.5
*/
class BannersModelDownload extends JModelForm
{
protected $_context = 'com_banners.tracks';
/**
* Method to auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* @since 1.6
*/
protected function populateState()
{
$input = JFactory::getApplication()->input;
$basename = $input->cookie->getString(JApplication::getHash($this->_context.'.basename'), '__SITE__');
$this->setState('basename', $basename);
$compressed = $input->cookie->getInt(JApplication::getHash($this->_context.'.compressed'), 1);
$this->setState('compressed', $compressed);
}
/**
* Method to get the record form.
*
* @param array $data Data for the form.
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
*
* @return mixed A JForm object on success, false on failure
* @since 1.6
*/
public function getForm($data = array(), $loadData = true)
{
// Get the form.
$form = $this->loadForm('com_banners.download', 'download', array('control' => 'jform', 'load_data' => $loadData));
if (empty($form))
{
return false;
}
return $form;
}
/**
* Method to get the data that should be injected in the form.
*
* @return mixed The data for the form.
* @since 1.6
*/
protected function loadFormData()
{
$data = array(
'basename' => $this->getState('basename'),
'compressed' => $this->getState('compressed')
);
$this->preprocessData('com_banners.download', $data);
return $data;
}
}

View File

@ -0,0 +1,43 @@
<?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
*/
defined('JPATH_BASE') or die;
JFormHelper::loadFieldClass('list');
require_once __DIR__ . '/../../helpers/banners.php';
/**
* Bannerclient Field class for the Joomla Framework.
*
* @package Joomla.Administrator
* @subpackage com_banners
* @since 1.6
*/
class JFormFieldBannerClient extends JFormFieldList
{
/**
* The form field type.
*
* @var string
* @since 1.6
*/
protected $type = 'BannerClient';
/**
* Method to get the field options.
*
* @return array The field option objects.
* @since 1.6
*/
public function getOptions()
{
return BannersHelper::getClientOptions();
}
}

View File

@ -0,0 +1,41 @@
<?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
*/
defined('JPATH_BASE') or die;
/**
* Clicks Field class for the Joomla Framework.
*
* @package Joomla.Administrator
* @subpackage com_banners
* @since 1.6
*/
class JFormFieldClicks extends JFormField
{
/**
* The form field type.
*
* @var string
* @since 1.6
*/
protected $type = 'Clicks';
/**
* Method to get the field input markup.
*
* @return string The field input markup.
* @since 1.6
*/
protected function getInput()
{
$onclick = ' onclick="document.id(\''.$this->id.'\').value=\'0\';"';
return '<input class="input-small" type="text" name="' . $this->name . '" id="' . $this->id . '" value="' . htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') . '" readonly="readonly" /> <a class="btn" ' . $onclick . '><i class="icon-refresh"></i> ' . JText::_('COM_BANNERS_RESET_CLICKS') . '</a>';
}
}

View File

@ -0,0 +1,41 @@
<?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
*/
defined('JPATH_BASE') or die;
/**
* Clicks Field class for the Joomla Framework.
*
* @package Joomla.Administrator
* @subpackage com_banners
* @since 1.6
*/
class JFormFieldImpMade extends JFormField
{
/**
* The form field type.
*
* @var string
* @since 1.6
*/
protected $type = 'ImpMade';
/**
* Method to get the field input markup.
*
* @return string The field input markup.
* @since 1.6
*/
protected function getInput()
{
$onclick = ' onclick="document.id(\''.$this->id.'\').value=\'0\';"';
return '<input class="input-small" type="text" name="'.$this->name.'" id="'.$this->id.'" value="'.htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8').'" readonly="readonly" /> <a class="btn" '.$onclick.'><i class="icon-refresh"></i> '.JText::_('COM_BANNERS_RESET_IMPMADE').'</a>';
}
}

View File

@ -0,0 +1,47 @@
<?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
*/
defined('JPATH_BASE') or die;
/**
* Impressions Field class for the Joomla Framework.
*
* @package Joomla.Administrator
* @subpackage com_banners
* @since 1.6
*/
class JFormFieldImpTotal extends JFormField
{
/**
* The form field type.
*
* @var string
* @since 1.6
*/
protected $type = 'ImpTotal';
/**
* Method to get the field input markup.
*
* @return string The field input markup.
* @since 1.6
*/
protected function getInput()
{
$class = ' class="validate-numeric text_area"';
$onchange = ' onchange="document.id(\''.$this->id.'_unlimited\').checked=document.id(\''.$this->id.'\').value==\'\';"';
$onclick = ' onclick="if (document.id(\''.$this->id.'_unlimited\').checked) document.id(\''.$this->id.'\').value=\'\';"';
$value = empty($this->value) ? '' : $this->value;
$checked = empty($this->value) ? ' checked="checked"' : '';
return '<input type="text" name="'.$this->name.'" id="'.$this->id.'" size="9" value="'.htmlspecialchars($value, ENT_COMPAT, 'UTF-8').'" '.$class.$onchange.' />
<fieldset class="checkboxes impunlimited"><input id="'.$this->id.'_unlimited" type="checkbox"'.$checked.$onclick.' />
<label for="'.$this->id.'_unlimited" id="jform-imp" type="text">'.JText::_('COM_BANNERS_UNLIMITED').'</label></fieldset>';
}
}

View File

@ -0,0 +1 @@
<!DOCTYPE html><title></title>

View File

@ -0,0 +1,71 @@
<?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
*/
defined('JPATH_BASE') or die;
/**
* Supports an HTML select list of banners
*
* @package Joomla.Administrator
* @subpackage com_banners
* @since 1.6
*/
class JFormFieldOrdering extends JFormField
{
/**
* The form field type.
*
* @var string
* @since 1.6
*/
protected $type = 'Ordering';
/**
* Method to get the field input markup.
*
* @return string The field input markup.
* @since 1.6
*/
protected function getInput()
{
$html = array();
$attr = '';
// Initialize some field attributes.
$attr .= $this->element['class'] ? ' class="'.(string) $this->element['class'].'"' : '';
$attr .= ((string) $this->element['disabled'] == 'true') ? ' disabled="disabled"' : '';
$attr .= $this->element['size'] ? ' size="'.(int) $this->element['size'].'"' : '';
// Initialize JavaScript field attributes.
$attr .= $this->element['onchange'] ? ' onchange="'.(string) $this->element['onchange'].'"' : '';
// Get some field values from the form.
$bannerId = (int) $this->form->getValue('id');
$categoryId = (int) $this->form->getValue('catid');
// Build the query for the ordering list.
$query = 'SELECT ordering AS value, name AS text' .
' FROM #__banners' .
' WHERE catid = ' . (int) $categoryId .
' ORDER BY ordering';
// Create a read-only list (no name) with a hidden input to store the value.
if ((string) $this->element['readonly'] == 'true')
{
$html[] = JHtml::_('list.ordering', '', $query, trim($attr), $this->value, $bannerId ? 0 : 1);
$html[] = '<input type="hidden" name="'.$this->name.'" value="'.$this->value.'"/>';
}
// Create a regular list.
else {
$html[] = JHtml::_('list.ordering', $this->name, $query, trim($attr), $this->value, $bannerId ? 0 : 1);
}
return implode($html);
}
}

View File

@ -0,0 +1,219 @@
<?xml version="1.0" encoding="utf-8"?>
<form>
<fieldset name="details"
addfieldpath="/administrator/components/com_banners/models/fields"
>
<field name="id" type="text" default="0"
readonly="true" class="readonly"
label="JGLOBAL_FIELD_ID_LABEL" description ="JGLOBAL_FIELD_ID_DESC" />
<field name="name" type="text" class="inputbox"
size="40" label="COM_BANNERS_FIELD_NAME_LABEL"
description="COM_BANNERS_FIELD_NAME_DESC" required="true" />
<field name="alias" type="text" class="inputbox"
size="40" label="JFIELD_ALIAS_LABEL"
description="COM_BANNERS_FIELD_ALIAS_DESC" />
<field name="catid" type="categoryedit" extension="com_banners"
label="JCATEGORY" description="COM_BANNERS_FIELD_CATEGORY_DESC"
class="inputbox" required="true"
addfieldpath="/administrator/components/com_categories/models/fields"
>
>
</field>
<field name="state" type="list"
label="JSTATUS" description="COM_BANNERS_FIELD_STATE_DESC"
class="inputbox span12 small" size="1" default="1" >
<option value="1">JPUBLISHED</option>
<option value="0">JUNPUBLISHED</option>
<option value="2">JARCHIVED</option>
<option value="-2">JTRASHED</option>
</field>
<field name="ordering" type="ordering" class="inputbox"
label="JFIELD_ORDERING_LABEL" description="JFIELD_ORDERING_DESC" />
<field name="language" type="contentlanguage" label="JFIELD_LANGUAGE_LABEL"
description="COM_BANNERS_FIELD_LANGUAGE_DESC" class="inputbox span12 small"
>
<option value="*">JALL</option>
</field>
<field name="description" type="textarea" class="inputbox"
rows="3" cols="30" label="JGLOBAL_DESCRIPTION"
description="COM_BANNERS_FIELD_DESCRIPTION_DESC" />
<field name="type" type="list"
label="COM_BANNERS_FIELD_TYPE_LABEL" description="COM_BANNERS_FIELD_TYPE_DESC"
default="0" class="inputbox"
>
<option value="0">COM_BANNERS_FIELD_VALUE_IMAGE
</option>
<option value="1">COM_BANNERS_FIELD_VALUE_CUSTOM
</option>
</field>
<field name="custombannercode" type="textarea" class="inputbox"
rows="3" cols="30" filter="raw"
label="COM_BANNERS_FIELD_CUSTOMCODE_LABEL" description="COM_BANNERS_FIELD_CUSTOMCODE_DESC" />
<field name="clickurl" type="url" class="inputbox" filter="url"
label="COM_BANNERS_FIELD_CLICKURL_LABEL" description="COM_BANNERS_FIELD_CLICKURL_DESC" />
</fieldset>
<fieldset name="publish"
label="COM_BANNERS_GROUP_LABEL_PUBLISHING_DETAILS"
>
<field name="created" type="calendar"
label="COM_BANNERS_FIELD_CREATED_LABEL" description="COM_BANNERS_FIELD_CREATED_DESC"
class="inputbox" size="22" format="%Y-%m-%d %H:%M:%S"
filter="user_utc" />
<field name="created_by" type="user"
label="COM_BANNERS_FIELD_CREATED_BY_LABEL" description="COM_BANNERS_FIELD_CREATED_BY_DESC" />
<field name="created_by_alias" type="text"
label="COM_BANNERS_FIELD_CREATED_BY_ALIAS_LABEL" description="COM_BANNERS_FIELD_CREATED_BY_ALIAS_DESC"
class="inputbox" size="20" />
<field name="modified" type="calendar" class="readonly"
label="JGLOBAL_FIELD_MODIFIED_LABEL" description="COM_BANNERS_FIELD_MODIFIED_DESC"
size="22" readonly="true" format="%Y-%m-%d %H:%M:%S" filter="user_utc" />
<field name="modified_by" type="user"
label="JGLOBAL_FIELD_MODIFIED_BY_LABEL"
class="readonly"
readonly="true"
filter="unset"
/>
<field name="version" type="text" class="readonly"
label="COM_BANNERS_FIELD_VERSION_LABEL" size="6" description="COM_BANNERS_FIELD_VERSION_DESC"
readonly="true" filter="unset" />
<field name="publish_up" type="calendar"
label="COM_BANNERS_FIELD_PUBLISH_UP_LABEL" description="COM_BANNERS_FIELD_PUBLISH_UP_DESC"
class="inputbox" format="%Y-%m-%d %H:%M:%S" size="22"
filter="user_utc" />
<field name="publish_down" type="calendar"
label="COM_BANNERS_FIELD_PUBLISH_DOWN_LABEL" description="COM_BANNERS_FIELD_PUBLISH_DOWN_DESC"
class="inputbox" format="%Y-%m-%d %H:%M:%S" size="22"
filter="user_utc" />
</fieldset>
<fieldset name="bannerdetails"
label="COM_BANNERS_GROUP_LABEL_BANNER_DETAILS"
>
<field name="sticky" type="list" default="0"
label="COM_BANNERS_FIELD_STICKY_LABEL"
description="COM_BANNERS_FIELD_STICKY_DESC"
class="span12 small"
>
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>
</fieldset>
<fieldset name="otherparams">
<field name="imptotal" type="imptotal" default="0"
label="COM_BANNERS_FIELD_IMPTOTAL_LABEL" description="COM_BANNERS_FIELD_IMPTOTAL_DESC" />
<field name="impmade" type="impmade" default="0"
label="COM_BANNERS_FIELD_IMPMADE_LABEL" description="COM_BANNERS_FIELD_IMPMADE_DESC" />
<field name="clicks" type="clicks" default="0"
label="COM_BANNERS_FIELD_CLICKS_LABEL" description="COM_BANNERS_FIELD_CLICKS_DESC" />
<field name="cid" type="bannerclient"
label="COM_BANNERS_FIELD_CLIENT_LABEL" description="COM_BANNERS_FIELD_CLIENT_DESC" />
<field name="purchase_type" type="list"
label="COM_BANNERS_FIELD_PURCHASETYPE_LABEL" description="COM_BANNERS_FIELD_PURCHASETYPE_DESC"
default="0" class="inputbox"
>
<option value="-1">COM_BANNERS_FIELD_VALUE_USECLIENTDEFAULT
</option>
<option value="1">COM_BANNERS_FIELD_VALUE_1
</option>
<option value="2">COM_BANNERS_FIELD_VALUE_2
</option>
<option value="3">COM_BANNERS_FIELD_VALUE_3
</option>
<option value="4">COM_BANNERS_FIELD_VALUE_4
</option>
<option value="5">COM_BANNERS_FIELD_VALUE_5
</option>
</field>
<field name="track_impressions" type="list" default="0"
label="COM_BANNERS_FIELD_TRACKIMPRESSION_LABEL"
description="COM_BANNERS_FIELD_TRACKIMPRESSION_DESC"
>
<option value="-1">COM_BANNERS_FIELD_VALUE_USECLIENTDEFAULT
</option>
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>
<field name="track_clicks" type="list" default="0"
label="COM_BANNERS_FIELD_TRACKCLICK_LABEL" description="COM_BANNERS_FIELD_TRACKCLICK_DESC"
>
<option value="-1">COM_BANNERS_FIELD_VALUE_USECLIENTDEFAULT
</option>
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>
</fieldset>
<fieldset name="metadata"
label="JGLOBAL_FIELDSET_METADATA_OPTIONS"
>
<field name="metakey" type="textarea" class="inputbox"
rows="3" cols="30" label="JFIELD_META_KEYWORDS_LABEL"
description="COM_BANNERS_FIELD_METAKEYWORDS_DESC" />
<field name="own_prefix" type="radio" class="btn-group"
label="COM_BANNERS_FIELD_BANNEROWNPREFIX_LABEL"
description="COM_BANNERS_FIELD_BANNEROWNPREFIX_DESC"
default="0"
>
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>
<field name="metakey_prefix" type="text"
label="COM_BANNERS_FIELD_METAKEYWORDPREFIX_LABEL"
description="COM_BANNERS_FIELD_METAKEYWORDPREFIX_DESC" />
</fieldset>
<fields name="params">
<fieldset name="image">
<field name="imageurl" type="media" directory="banners"
hide_none="1" label="COM_BANNERS_FIELD_IMAGE_LABEL"
size="40"
description="COM_BANNERS_FIELD_IMAGE_DESC" />
<field name="width" type="text"
class="inputbox validate-numeric" label="COM_BANNERS_FIELD_WIDTH_LABEL"
description="COM_BANNERS_FIELD_WIDTH_DESC" />
<field name="height" type="text"
class="inputbox validate-numeric" label="COM_BANNERS_FIELD_HEIGHT_LABEL"
description="COM_BANNERS_FIELD_HEIGHT_DESC" />
<field name="alt" type="text" class="inputbox"
label="COM_BANNERS_FIELD_ALT_LABEL" description="COM_BANNERS_FIELD_ALT_DESC" />
</fieldset>
</fields>
<fieldset name="custom">
<field name="bannercode" type="textarea" class="inputbox"
rows="3" cols="30" filter="raw"
label="COM_BANNERS_FIELD_CUSTOMCODE_LABEL" description="COM_BANNERS_FIELD_CUSTOMCODE_DESC" />
</fieldset>
</form>

View File

@ -0,0 +1,103 @@
<?xml version="1.0" encoding="utf-8"?>
<form>
<fieldset name="details"
addfieldpath="/administrator/components/com_banners/models/fields"
>
<field name="id" type="text" default="0"
readonly="true" class="readonly"
label="JGLOBAL_FIELD_ID_LABEL" description ="JGLOBAL_FIELD_ID_DESC"/>
<field name="name" type="text" class="inputbox"
size="40" label="COM_BANNERS_FIELD_CLIENT_NAME_LABEL"
description="COM_BANNERS_FIELD_CLIENT_NAME_DESC"
required="true" />
<field name="contact" type="text" class="inputbox"
size="40" label="COM_BANNERS_FIELD_CONTACT_LABEL"
description="COM_BANNERS_FIELD_CONTACT_DESC" required="true" />
<field name="email" type="email" class="inputbox"
size="40" label="COM_BANNERS_FIELD_EMAIL_LABEL"
description="COM_BANNERS_FIELD_EMAIL_DESC" validate="email"
required="true" />
<field name="state" type="list"
label="JSTATUS" description="COM_BANNERS_FIELD_CLIENT_STATE_DESC"
class="inputbox" size="1" default="1"
>
<option value="1">JPUBLISHED</option>
<option value="0">JUNPUBLISHED</option>
<option value="2">JARCHIVED</option>
<option value="-2">JTRASHED</option>
</field>
<field name="purchase_type" type="list"
label="COM_BANNERS_FIELD_PURCHASETYPE_LABEL" description="COM_BANNERS_FIELD_PURCHASETYPE_DESC"
default="0" class="inputbox"
>
<option value="-1">JGLOBAL_USE_GLOBAL
</option>
<option value="1">COM_BANNERS_FIELD_VALUE_1
</option>
<option value="2">COM_BANNERS_FIELD_VALUE_2
</option>
<option value="3">COM_BANNERS_FIELD_VALUE_3
</option>
<option value="4">COM_BANNERS_FIELD_VALUE_4
</option>
<option value="5">COM_BANNERS_FIELD_VALUE_5
</option>
</field>
<field name="track_impressions" type="list" default="0"
label="COM_BANNERS_FIELD_TRACKIMPRESSION_LABEL"
description="COM_BANNERS_FIELD_TRACKIMPRESSION_DESC"
>
<option value="">JGLOBAL_USE_GLOBAL</option>
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>
<field name="track_clicks" type="list" default="0"
label="COM_BANNERS_FIELD_TRACKCLICK_LABEL" description="COM_BANNERS_FIELD_TRACKCLICK_DESC"
>
<option value="">JGLOBAL_USE_GLOBAL</option>
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>
</fieldset>
<fieldset name="metadata"
label="JGLOBAL_FIELDSET_METADATA_OPTIONS"
>
<field name="metakey" type="textarea" class="inputbox"
rows="3" cols="30" label="JFIELD_META_KEYWORDS_LABEL"
description="COM_BANNERS_FIELD_CLIENT_METAKEYWORDS_DESC" />
<field name="own_prefix" type="radio" class="btn-group"
label="COM_BANNERS_FIELD_CLIENTOWNPREFIX_LABEL"
description="COM_BANNERS_FIELD_CLIENTOWNPREFIX_DESC"
default="0"
>
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>
<field name="metakey_prefix" type="text"
label="COM_BANNERS_FIELD_CLIENT_METAKEYWORDPREFIX_LABEL"
description="COM_BANNERS_FIELD_CLIENT_METAKEYWORDPREFIX_DESC" />
</fieldset>
<fieldset name="extra" label="Banners_Extra">
<field name="extrainfo" type="textarea" class="inputbox"
rows="10" cols="40" label="COM_BANNERS_FIELD_EXTRAINFO_LABEL"
description="COM_BANNERS_FIELD_EXTRAINFO_DESC" />
</fieldset>
</form>

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<form>
<fieldset name="details">
<field name="compressed" type="radio" class="btn-group"
label="COM_BANNERS_FIELD_COMPRESSED_LABEL"
description="COM_BANNERS_FIELD_COMPRESSED_DESC"
default="0"
>
<option value="0">JNO</option>
<option value="1">JYES</option>
</field>
<field name="basename" type="text"
class="inputbox" size="40"
label="COM_BANNERS_FIELD_BASENAME_LABEL" description="COM_BANNERS_FIELD_BASENAME_DESC" />
</fieldset>
</form>

View File

@ -0,0 +1 @@
<!DOCTYPE html><title></title>

View File

@ -0,0 +1 @@
<!DOCTYPE html><title></title>

View File

@ -0,0 +1,515 @@
<?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
*/
defined('_JEXEC') or die;
/**
* Methods supporting a list of tracks.
*
* @package Joomla.Administrator
* @subpackage com_banners
* @since 1.6
*/
class BannersModelTracks extends JModelList
{
/**
* Constructor.
*
* @param array An optional associative array of configuration settings.
* @see JController
* @since 1.6
*/
public function __construct($config = array())
{
if (empty($config['filter_fields']))
{
$config['filter_fields'] = array(
'name', 'b.name',
'cl.name', 'client_name',
'cat.title', 'category_title',
'track_type', 'a.track_type',
'count', 'a.count',
'track_date', 'a.track_date',
);
}
parent::__construct($config);
}
/**
* @since 1.6
*/
protected $basename;
/**
* Method to auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* @since 1.6
*/
protected function populateState($ordering = null, $direction = null)
{
// Load the filter state.
$type = $this->getUserStateFromRequest($this->context . '.filter.type', 'filter_type');
$this->setState('filter.type', $type);
$begin = $this->getUserStateFromRequest($this->context . '.filter.begin', 'filter_begin', '', 'string');
$this->setState('filter.begin', $begin);
$end = $this->getUserStateFromRequest($this->context . '.filter.end', 'filter_end', '', 'string');
$this->setState('filter.end', $end);
$categoryId = $this->getUserStateFromRequest($this->context . '.filter.category_id', 'filter_category_id', '');
$this->setState('filter.category_id', $categoryId);
$clientId = $this->getUserStateFromRequest($this->context . '.filter.client_id', 'filter_client_id', '');
$this->setState('filter.client_id', $clientId);
// Load the parameters.
$params = JComponentHelper::getParams('com_banners');
$this->setState('params', $params);
// List state information.
parent::populateState('b.name', 'asc');
}
/**
* Build an SQL query to load the list data.
*
* @return JDatabaseQuery
* @since 1.6
*/
protected function getListQuery()
{
require_once JPATH_COMPONENT . '/helpers/banners.php';
// Create a new query object.
$db = $this->getDbo();
$query = $db->getQuery(true);
// Select the required fields from the table.
$query->select(
'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');
// Join with the banners
$query->join('LEFT', $db->quoteName('#__banners') . ' as b ON b.id=a.banner_id')
->select('b.name as name');
// Join with the client
$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');
// Filter by type
$type = $this->getState('filter.type');
if (!empty($type))
{
$query->where('a.track_type = ' . (int) $type);
}
// Filter by client
$clientId = $this->getState('filter.client_id');
if (is_numeric($clientId))
{
$query->where('b.cid = ' . (int) $clientId);
}
// Filter by category
$catedoryId = $this->getState('filter.category_id');
if (is_numeric($catedoryId))
{
$query->where('b.catid = ' . (int) $catedoryId);
}
// Filter by begin date
$begin = $this->getState('filter.begin');
if (!empty($begin))
{
$query->where('a.track_date >= ' . $db->quote($begin));
}
// Filter by end date
$end = $this->getState('filter.end');
if (!empty($end))
{
$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')));
return $query;
}
/**
* Method to delete rows.
*
* @param array An array of item ids.
*
* @return boolean Returns true on success, false on failure.
*/
public function delete()
{
$user = JFactory::getUser();
$categoryId = $this->getState('category_id');
// Access checks.
if ($categoryId)
{
$allow = $user->authorise('core.delete', 'com_banners.category.' . (int) $categoryId);
}
else
{
$allow = $user->authorise('core.delete', 'com_banners');
}
if ($allow)
{
// Delete tracks from this banner
$db = $this->getDbo();
$query = $db->getQuery(true)
->delete($db->quoteName('#__banner_tracks'));
// Filter by type
$type = $this->getState('filter.type');
if (!empty($type))
{
$query->where('track_type = ' . (int) $type);
}
// Filter by begin date
$begin = $this->getState('filter.begin');
if (!empty($begin))
{
$query->where('track_date >= ' . $db->quote($begin));
}
// Filter by end date
$end = $this->getState('filter.end');
if (!empty($end))
{
$query->where('track_date <= ' . $db->quote($end));
}
$where = '1';
// Filter by client
$clientId = $this->getState('filter.client_id');
if (!empty($clientId))
{
$where .= ' AND cid = ' . (int) $clientId;
}
// Filter by category
if (!empty($categoryId))
{
$where .= ' AND catid = ' . (int) $categoryId;
}
$query->where('banner_id IN (SELECT id FROM ' . $db->quoteName('#__banners') . ' WHERE ' . $where . ')');
$db->setQuery($query);
$this->setError((string) $query);
try
{
$db->execute();
}
catch (RuntimeException $e)
{
$this->setError($e->getMessage());
return false;
}
}
else
{
JError::raiseWarning(403, JText::_('JERROR_CORE_DELETE_NOT_PERMITTED'));
}
return true;
}
/**
* Get file name
*
* @return string The file name
* @since 1.6
*/
public function getBaseName()
{
if (!isset($this->basename))
{
$app = JFactory::getApplication();
$basename = $this->getState('basename');
$basename = str_replace('__SITE__', $app->getCfg('sitename'), $basename);
$categoryId = $this->getState('filter.category_id');
if (is_numeric($categoryId))
{
if ($categoryId > 0)
{
$basename = str_replace('__CATID__', $categoryId, $basename);
}
else
{
$basename = str_replace('__CATID__', '', $basename);
}
$categoryName = $this->getCategoryName();
$basename = str_replace('__CATNAME__', $categoryName, $basename);
}
else
{
$basename = str_replace('__CATID__', '', $basename);
$basename = str_replace('__CATNAME__', '', $basename);
}
$clientId = $this->getState('filter.client_id');
if (is_numeric($clientId))
{
if ($clientId > 0)
{
$basename = str_replace('__CLIENTID__', $clientId, $basename);
}
else
{
$basename = str_replace('__CLIENTID__', '', $basename);
}
$clientName = $this->getClientName();
$basename = str_replace('__CLIENTNAME__', $clientName, $basename);
}
else
{
$basename = str_replace('__CLIENTID__', '', $basename);
$basename = str_replace('__CLIENTNAME__', '', $basename);
}
$type = $this->getState('filter.type');
if ($type > 0)
{
$basename = str_replace('__TYPE__', $type, $basename);
$typeName = JText::_('COM_BANNERS_TYPE' . $type);
$basename = str_replace('__TYPENAME__', $typeName, $basename);
}
else
{
$basename = str_replace('__TYPE__', '', $basename);
$basename = str_replace('__TYPENAME__', '', $basename);
}
$begin = $this->getState('filter.begin');
if (!empty($begin))
{
$basename = str_replace('__BEGIN__', $begin, $basename);
}
else
{
$basename = str_replace('__BEGIN__', '', $basename);
}
$end = $this->getState('filter.end');
if (!empty($end))
{
$basename = str_replace('__END__', $end, $basename);
}
else
{
$basename = str_replace('__END__', '', $basename);
}
$this->basename = $basename;
}
return $this->basename;
}
/**
* Get the category name.
*
* @return string The category name
* @since 1.6
*/
protected function getCategoryName()
{
$categoryId = $this->getState('filter.category_id');
if ($categoryId)
{
$db = $this->getDbo();
$query = $db->getQuery(true)
->select('title')
->from($db->quoteName('#__categories'))
->where($db->quoteName('id') . '=' . $db->quote($categoryId));
$db->setQuery($query);
try
{
$name = $db->loadResult();
}
catch (RuntimeException $e)
{
$this->setError($e->getMessage());
return false;
}
}
else
{
$name = JText::_('COM_BANNERS_NOCATEGORYNAME');
}
return $name;
}
/**
* Get the category name
*
* @return string The category name.
* @since 1.6
*/
protected function getClientName()
{
$clientId = $this->getState('filter.client_id');
if ($clientId)
{
$db = $this->getDbo();
$query = $db->getQuery(true)
->select('name')
->from($db->quoteName('#__banner_clients'))
->where($db->quoteName('id') . '=' . $db->quote($clientId));
$db->setQuery($query);
try
{
$name = $db->loadResult();
}
catch (RuntimeException $e)
{
$this->setError($e->getMessage());
return false;
}
}
else
{
$name = JText::_('COM_BANNERS_NOCLIENTNAME');
}
return $name;
}
/**
* Get the file type.
*
* @return string The file type
* @since 1.6
*/
public function getFileType()
{
return $this->getState('compressed') ? 'zip' : 'csv';
}
/**
* Get the mime type.
*
* @return string The mime type.
* @since 1.6
*/
public function getMimeType()
{
return $this->getState('compressed') ? 'application/zip' : 'text/csv';
}
/**
* Get the content
*
* @return string The content.
* @since 1.6
*/
public function getContent()
{
if (!isset($this->content))
{
$this->content = '';
$this->content .=
'"' . str_replace('"', '""', JText::_('COM_BANNERS_HEADING_NAME')) . '","' .
str_replace('"', '""', JText::_('COM_BANNERS_HEADING_CLIENT')) . '","' .
str_replace('"', '""', JText::_('JCATEGORY')) . '","' .
str_replace('"', '""', JText::_('COM_BANNERS_HEADING_TYPE')) . '","' .
str_replace('"', '""', JText::_('COM_BANNERS_HEADING_COUNT')) . '","' .
str_replace('"', '""', JText::_('JDATE')) . '"' . "\n";
foreach ($this->getItems() as $item)
{
$this->content .=
'"' . str_replace('"', '""', $item->name) . '","' .
str_replace('"', '""', $item->client_name) . '","' .
str_replace('"', '""', $item->category_title) . '","' .
str_replace('"', '""', ($item->track_type == 1 ? JText::_('COM_BANNERS_IMPRESSION') : JText::_('COM_BANNERS_CLICK'))) . '","' .
str_replace('"', '""', $item->count) . '","' .
str_replace('"', '""', $item->track_date) . '"' . "\n";
}
if ($this->getState('compressed'))
{
$app = JFactory::getApplication('administrator');
$files = array();
$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';
// run the packager
jimport('joomla.filesystem.folder');
jimport('joomla.filesystem.file');
$delete = JFolder::files($app->getCfg('tmp_path') . '/', uniqid('banners_tracks_'), false, true);
if (!empty($delete))
{
if (!JFile::delete($delete))
{
// JFile::delete throws an error
$this->setError(JText::_('COM_BANNERS_ERR_ZIP_DELETE_FAILURE'));
return false;
}
}
if (!$packager = JArchive::getAdapter('zip'))
{
$this->setError(JText::_('COM_BANNERS_ERR_ZIP_ADAPTER_FAILURE'));
return false;
}
elseif (!$packager->create($ziproot, $files))
{
$this->setError(JText::_('COM_BANNERS_ERR_ZIP_CREATE_FAILURE'));
return false;
}
$this->content = file_get_contents($ziproot);
}
}
return $this->content;
}
}