Source for file banner.php
Documentation is available at banner.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
* @package Joomla.Administrator
* @subpackage com_banners
* @var string The prefix to use with controller messages.
* The type alias for this content type.
* 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.
public function batch($commands, $pks, $contexts)
// Remove any values of zero.
if (!empty($commands['category_id']))
$result =
$this->batchCopy($commands['category_id'], $pks, $contexts);
elseif ($cmd ==
'm' &&
!$this->batchMove($commands['category_id'], $pks, $contexts))
if (strlen($commands['client_id']) >
0)
if (!$this->batchClient($commands['client_id'], $pks, $contexts))
if (!empty($commands['language_id']))
if (!$this->batchLanguage($commands['language_id'], $pks, $contexts))
$this->setError(JText::_('JLIB_APPLICATION_ERROR_INSUFFICIENT_BATCH_INFORMATION'));
* 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.
protected function batchClient($value, $pks, $contexts)
if ($user->authorise('core.edit', $contexts[$pk]))
$table->cid = (int)
$value;
$this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_EDIT'));
* 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.
protected function batchCopy($value, $pks, $contexts)
$categoryId = (int)
$value;
// Check that the category exists
if (!$categoryTable->load($categoryId))
if ($error =
$categoryTable->getError())
$this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_MOVE_CATEGORY_NOT_FOUND'));
$this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_MOVE_CATEGORY_NOT_FOUND'));
// Check that the user has create permission for the component
if (!$user->authorise('core.create', 'com_banners.category.' .
$categoryId))
$this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_CREATE'));
// Parent exists so we let's proceed
// Pop the first ID off the stack
// Check that the row actually exists
if ($error =
$table->getError())
// Alter the title & alias
$table->name =
$data['0'];
$table->alias =
$data['1'];
// Reset the ID because we are making a copy
$table->catid =
$categoryId;
// TODO: Deal with ordering?
$newId =
$table->get('id');
// Add the new ID to the array
* 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.
if ($record->state != -
2)
if (!empty($record->catid))
return $user->authorise('core.delete', 'com_banners.category.' . (int)
$record->catid);
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.
// 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.
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
public function getTable($type =
'Banner', $prefix =
'BannersTable', $config =
array())
* 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
public function getForm($data =
array(), $loadData =
true)
$form =
$this->loadForm('com_banners.banner', 'banner', array('control' =>
'jform', 'load_data' =>
$loadData));
// Determine correct permissions to check.
// Existing record. Can only edit in selected categories.
$form->setFieldAttribute('catid', 'action', 'core.edit');
// New record. Can only create in selected categories.
$form->setFieldAttribute('catid', 'action', 'core.create');
// Modify the form based on access controls.
// 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');
* Method to get the data that should be injected in the form.
* @return mixed The data for the form.
// Check the session for previously entered form data.
$data =
$app->getUserState('com_banners.edit.banner.data', array());
// Prime some default values.
$data->set('catid', $app->input->getInt('catid', $app->getUserState('com_banners.banners.filter.category_id')));
* 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.
public function stick(&$pks, $value =
1)
foreach ($pks as $i =>
$pk)
// Prune items that you can't change.
// Attempt to change the state of the records.
if (!$table->stick($pks, $value, $user->get('id')))
* 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.
$condition[] =
'catid = '. (int)
$table->catid;
$condition[] =
'state >= 0';
$table->created =
$date->toSql();
// Set ordering to the last item if not set
if (empty($table->ordering))
$query =
$db->getQuery(true)
->select('MAX(ordering)')
$max =
$db->loadResult();
$table->ordering =
$max +
1;
$table->modified =
$date->toSql();
$table->modified_by =
$user->get('id');
// Increment the content version number.
* Method to save the form data.
* @param array The form data.
* @return boolean True on success.
public function save($data)
// Alter the name for save as copy
if ($app->input->get('task') ==
'save2copy')
list
($name, $alias) =
$this->generateNewTitle($data['catid'], $data['alias'], $data['name']);
Documentation generated on Tue, 19 Nov 2013 14:54:14 +0100 by phpDocumentor 1.4.3