diff --git a/administrator/components/com_banners/controllers/banner.php b/administrator/components/com_banners/controllers/banner.php
index 88c3e1f2db603..8279164223551 100644
--- a/administrator/components/com_banners/controllers/banner.php
+++ b/administrator/components/com_banners/controllers/banner.php
@@ -1,8 +1,10 @@
authorise('core.create', $this->option.'.category.'.$categoryId);
+ $allow = $user->authorise('core.create', $this->option . '.category.' . $categoryId);
}
- if ($allow === null) {
- // In the absense of better information, revert to the component permissions.
+ if ($allow === null)
+ {
+ // In the absence of better information, revert to the component permissions.
return parent::allowAdd($data);
- } else {
+ }
+ else
+ {
return $allow;
}
}
@@ -56,11 +63,12 @@ protected function allowAdd($data = array())
/**
* Method override to check if you can edit an existing record.
*
- * @param array $data An array of input data.
- * @param string $key The name of the key for the primary key.
+ * @param array $data An array of input data.
+ * @param string $key The name of the key for the primary key.
*
- * @return boolean
- * @since 1.6
+ * @return boolean
+ *
+ * @since 1.6
*/
protected function allowEdit($data = array(), $key = 'id')
{
@@ -69,16 +77,43 @@ protected function allowEdit($data = array(), $key = 'id')
$recordId = (int) isset($data[$key]) ? $data[$key] : 0;
$categoryId = 0;
- if ($recordId) {
+ if ($recordId)
+ {
$categoryId = (int) $this->getModel()->getItem($recordId)->catid;
}
- if ($categoryId) {
+ if ($categoryId)
+ {
// The category has been set. Check the category permissions.
- return $user->authorise('core.edit', $this->option.'.category.'.$categoryId);
- } else {
+ return $user->authorise('core.edit', $this->option . '.category.' . $categoryId);
+ }
+ else
+ {
// Since there is no asset tracking, revert to the component permissions.
return parent::allowEdit($data, $key);
}
}
+
+ /**
+ * Method to run batch operations.
+ *
+ * @param string $model The model
+ *
+ * @return boolean True on success.
+ *
+ * @since 2.5
+ */
+ public function batch($model = null)
+ {
+ JRequest::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
+
+ // Set the model
+ $model = $this->getModel('Banner', '', array());
+
+ // Preset the redirect
+ $this->setRedirect(JRoute::_('index.php?option=com_banners&view=banners' . $this->getRedirectToListAppend(), false));
+
+ return parent::batch($model);
+ }
+
}
diff --git a/administrator/components/com_banners/helpers/html/banner.php b/administrator/components/com_banners/helpers/html/banner.php
new file mode 100644
index 0000000000000..7d6498d67def4
--- /dev/null
+++ b/administrator/components/com_banners/helpers/html/banner.php
@@ -0,0 +1,72 @@
+',
+ JText::_('COM_BANNERS_BATCH_CLIENT_LABEL'),
+ '',
+ ''
+ );
+
+ return implode("\n", $lines);
+ }
+
+ /**
+ * Method to get the field options.
+ *
+ * @return array The field option objects.
+ * @since 1.6
+ */
+ public static function clientlist()
+ {
+ $db = JFactory::getDbo();
+ $query = $db->getQuery(true);
+
+ $query->select('id As value, name As text');
+ $query->from('#__banner_clients AS a');
+ $query->order('a.name');
+
+ // Get the options.
+ $db->setQuery($query);
+
+ $options = $db->loadObjectList();
+
+ // Check for a database error.
+ if ($db->getErrorNum()) {
+ JError::raiseWarning(500, $db->getErrorMsg());
+ }
+
+ return $options;
+ }
+}
diff --git a/administrator/components/com_banners/helpers/html/index.html b/administrator/components/com_banners/helpers/html/index.html
new file mode 100644
index 0000000000000..2efb97f319a35
--- /dev/null
+++ b/administrator/components/com_banners/helpers/html/index.html
@@ -0,0 +1 @@
+
diff --git a/administrator/components/com_banners/models/banner.php b/administrator/components/com_banners/models/banner.php
index 2d8b525a67a9e..6e133b37db767 100644
--- a/administrator/components/com_banners/models/banner.php
+++ b/administrator/components/com_banners/models/banner.php
@@ -1,8 +1,10 @@
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 A record object.
- * @return boolean True if allowed to delete the record. Defaults to the permission set in the component.
- * @since 1.6
+ * @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 ;
+ 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);
+ if (!empty($record->catid))
+ {
+ return $user->authorise('core.delete', 'com_banners.category.' . (int) $record->catid);
}
- else {
+ else
+ {
return parent::canDelete($record);
}
}
@@ -52,32 +309,38 @@ protected function canDelete($record)
/**
* Method to test whether a record can have its state changed.
*
- * @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
+ * @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);
+ 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 {
+ else
+ {
return parent::canEditState($record);
}
}
/**
- * Returns a reference to the a Table object, always creating it.
+ * 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]
*
- * @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
+ * @return JTable A database object
+ *
+ * @since 1.6
*/
public function getTable($type = 'Banner', $prefix = 'BannersTable', $config = array())
{
@@ -87,30 +350,37 @@ public function getTable($type = 'Banner', $prefix = 'BannersTable', $config = a
/**
* 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
+ * @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)) {
+ if (empty($form))
+ {
return false;
}
// Determine correct permissions to check.
- if ($this->getState('banner.id')) {
+ if ($this->getState('banner.id'))
+ {
// Existing record. Can only edit in selected categories.
$form->setFieldAttribute('catid', 'action', 'core.edit');
- } else {
+ }
+ 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)) {
+ if (!$this->canEditState((object) $data))
+ {
// Disable fields for display.
$form->setFieldAttribute('ordering', 'disabled', 'true');
$form->setFieldAttribute('publish_up', 'disabled', 'true');
@@ -133,19 +403,22 @@ public function getForm($data = array(), $loadData = true)
/**
* Method to get the data that should be injected in the form.
*
- * @return mixed The data for the form.
- * @since 1.6
+ * @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.banner.data', array());
- if (empty($data)) {
+ if (empty($data))
+ {
$data = $this->getItem();
// Prime some default values.
- if ($this->getState('banner.id') == 0) {
+ if ($this->getState('banner.id') == 0)
+ {
$app = JFactory::getApplication();
$data->set('catid', JRequest::getInt('catid', $app->getUserState('com_banners.banners.filter.category_id')));
}
@@ -157,22 +430,27 @@ protected function loadFormData()
/**
* Method to stick records.
*
- * @param array The ids of the items to publish.
- * @param int The value of the published state
+ * @param array &$pks The ids of the items to publish.
+ * @param integer $value The value of the published state
+ *
+ * @return boolean True on success.
*
- * @return boolean True on success.
+ * @since 1.6
*/
function stick(&$pks, $value = 1)
{
// Initialise variables.
- $user = JFactory::getUser();
- $table = $this->getTable();
- $pks = (array) $pks;
+ $user = JFactory::getUser();
+ $table = $this->getTable();
+ $pks = (array) $pks;
// Access checks.
- foreach ($pks as $i => $pk) {
- if ($table->load($pk)) {
- if (!$this->canEditState($table)) {
+ 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'));
@@ -181,7 +459,8 @@ function stick(&$pks, $value = 1)
}
// Attempt to change the state of the records.
- if (!$table->stick($pks, $value, $user->get('id'))) {
+ if (!$table->stick($pks, $value, $user->get('id')))
+ {
$this->setError($table->getError());
return false;
}
@@ -192,9 +471,11 @@ function stick(&$pks, $value = 1)
/**
* A protected method to get a set of ordering conditions.
*
- * @param object A record object.
- * @return array An array of conditions to add to add to ordering queries.
- * @since 1.6
+ * @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)
{
diff --git a/administrator/components/com_banners/views/banners/tmpl/default.php b/administrator/components/com_banners/views/banners/tmpl/default.php
index 8a8a2e594fb3b..bcc2dd91893e2 100644
--- a/administrator/components/com_banners/views/banners/tmpl/default.php
+++ b/administrator/components/com_banners/views/banners/tmpl/default.php
@@ -1,10 +1,10 @@
+
+ loadTemplate('batch'); ?>
+
diff --git a/administrator/components/com_banners/views/banners/tmpl/default_batch.php b/administrator/components/com_banners/views/banners/tmpl/default_batch.php
new file mode 100644
index 0000000000000..b16936564883b
--- /dev/null
+++ b/administrator/components/com_banners/views/banners/tmpl/default_batch.php
@@ -0,0 +1,31 @@
+state->get('filter.published');
+?>
+
diff --git a/administrator/components/com_banners/views/banners/view.html.php b/administrator/components/com_banners/views/banners/view.html.php
index c7b5e90f1ed09..a183d4b84e934 100644
--- a/administrator/components/com_banners/views/banners/view.html.php
+++ b/administrator/components/com_banners/views/banners/view.html.php
@@ -1,8 +1,10 @@
state = $this->get('State');
// Check for errors.
- if (count($errors = $this->get('Errors'))) {
+ if (count($errors = $this->get('Errors')))
+ {
JError::raiseError(500, implode("\n", $errors));
return false;
}
$this->addToolbar();
- require_once JPATH_COMPONENT .'/models/fields/bannerclient.php';
+ require_once JPATH_COMPONENT . '/models/fields/bannerclient.php';
+ // Include the component HTML helpers.
+ JHtml::addIncludePath(JPATH_COMPONENT . '/helpers/html');
+
parent::display($tpl);
}
/**
* Add the page title and toolbar.
*
- * @since 1.6
+ * @return void
+ *
+ * @since 1.6
*/
protected function addToolbar()
{
- require_once JPATH_COMPONENT.'/helpers/banners.php';
+ require_once JPATH_COMPONENT . '/helpers/banners.php';
- $canDo = BannersHelper::getActions($this->state->get('filter.category_id'));
- $user = JFactory::getUser();
+ $canDo = BannersHelper::getActions($this->state->get('filter.category_id'));
+ $user = JFactory::getUser();
JToolBarHelper::title(JText::_('COM_BANNERS_MANAGER_BANNERS'), 'banners.png');
- if (count($user->getAuthorisedCategories('com_banners', 'core.create')) > 0) {
+ if (count($user->getAuthorisedCategories('com_banners', 'core.create')) > 0)
+ {
JToolBarHelper::addNew('banner.add');
}
- if (($canDo->get('core.edit'))) {
+ if (($canDo->get('core.edit')))
+ {
JToolBarHelper::editList('banner.edit');
}
- if ($canDo->get('core.edit.state')) {
- if ($this->state->get('filter.state') != 2){
+ if ($canDo->get('core.edit.state'))
+ {
+ if ($this->state->get('filter.state') != 2)
+ {
JToolBarHelper::divider();
JToolBarHelper::publish('banners.publish', 'JTOOLBAR_PUBLISH', true);
JToolBarHelper::unpublish('banners.unpublish', 'JTOOLBAR_UNPUBLISH', true);
}
- if ($this->state->get('filter.state') != -1 ) {
+ if ($this->state->get('filter.state') != -1)
+ {
JToolBarHelper::divider();
- if ($this->state->get('filter.state') != 2) {
+ if ($this->state->get('filter.state') != 2)
+ {
JToolBarHelper::archiveList('banners.archive');
}
- elseif ($this->state->get('filter.state') == 2) {
+ elseif ($this->state->get('filter.state') == 2)
+ {
JToolBarHelper::unarchiveList('banners.publish');
}
}
}
- if ($canDo->get('core.edit.state')) {
+ if ($canDo->get('core.edit.state'))
+ {
JToolBarHelper::checkin('banners.checkin');
}
-
- if ($this->state->get('filter.state') == -2 && $canDo->get('core.delete')) {
+ if ($this->state->get('filter.state') == -2 && $canDo->get('core.delete'))
+ {
JToolBarHelper::deleteList('', 'banners.delete', 'JTOOLBAR_EMPTY_TRASH');
JToolBarHelper::divider();
- } elseif ($canDo->get('core.edit.state')) {
+ }
+ elseif ($canDo->get('core.edit.state'))
+ {
JToolBarHelper::trash('banners.trash');
JToolBarHelper::divider();
}
- if ($canDo->get('core.admin')) {
+ if ($canDo->get('core.admin'))
+ {
JToolBarHelper::preferences('com_banners');
JToolBarHelper::divider();
}
diff --git a/administrator/components/com_categories/controllers/category.php b/administrator/components/com_categories/controllers/category.php
index 8c02b62c03e41..c570d2e8b38ab 100644
--- a/administrator/components/com_categories/controllers/category.php
+++ b/administrator/components/com_categories/controllers/category.php
@@ -1,8 +1,10 @@
extension)) {
+ if (empty($this->extension))
+ {
$this->extension = JRequest::getCmd('extension', 'com_content');
}
}
@@ -44,12 +50,11 @@ public function __construct($config = array())
/**
* Method to check if you can add a new record.
*
- * Extended classes can override this if necessary.
+ * @param array $data An array of input data.
*
- * @param array An array of input data.
+ * @return boolean
*
- * @return boolean
- * @since 1.6
+ * @since 1.6
*/
protected function allowAdd($data = array())
{
@@ -59,41 +64,45 @@ protected function allowAdd($data = array())
/**
* Method to check if you can edit a record.
*
- * Extended classes can override this if necessary.
+ * @param array $data An array of input data.
+ * @param string $key The name of the key for the primary key.
*
- * @param array An array of input data.
- * @param string The name of the key for the primary key.
+ * @return boolean
*
- * @return boolean
- * @since 1.6
+ * @since 1.6
*/
protected function allowEdit($data = array(), $key = 'parent_id')
{
// Initialise variables.
- $recordId = (int) isset($data[$key]) ? $data[$key] : 0;
- $user = JFactory::getUser();
- $userId = $user->get('id');
+ $recordId = (int) isset($data[$key]) ? $data[$key] : 0;
+ $user = JFactory::getUser();
+ $userId = $user->get('id');
// Check general edit permission first.
- if ($user->authorise('core.edit', $this->extension)) {
+ if ($user->authorise('core.edit', $this->extension))
+ {
return true;
}
// Check specific edit permission.
- if ($user->authorise('core.edit', $this->extension.'.category.'.$recordId)) {
+ if ($user->authorise('core.edit', $this->extension . '.category.' . $recordId))
+ {
return true;
}
// Fallback on edit.own.
// First test if the permission is available.
- if ($user->authorise('core.edit.own', $this->extension.'.category.'.$recordId) || $user->authorise('core.edit.own', $this->extension)) {
+ if ($user->authorise('core.edit.own', $this->extension . '.category.' . $recordId) || $user->authorise('core.edit.own', $this->extension))
+ {
// Now test the owner is the user.
- $ownerId = (int) isset($data['created_user_id']) ? $data['created_user_id'] : 0;
- if (empty($ownerId) && $recordId) {
+ $ownerId = (int) isset($data['created_user_id']) ? $data['created_user_id'] : 0;
+ if (empty($ownerId) && $recordId)
+ {
// Need to do a lookup from the model.
- $record = $this->getModel()->getItem($recordId);
+ $record = $this->getModel()->getItem($recordId);
- if (empty($record)) {
+ if (empty($record))
+ {
return false;
}
@@ -101,32 +110,32 @@ protected function allowEdit($data = array(), $key = 'parent_id')
}
// If the owner matches 'me' then do the test.
- if ($ownerId == $userId) {
+ if ($ownerId == $userId)
+ {
return true;
}
}
return false;
- }
+ }
/**
- * Method to run batch opterations.
+ * Method to run batch operations.
+ *
+ * @param object $model The model.
*
- * @return void
+ * @return boolean True if successful, false otherwise and internal error is set.
+ *
+ * @since 1.6
*/
- public function batch($model)
+ public function batch($model = null)
{
JRequest::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
// Set the model
- $model = $this->getModel('Category');
-
- $extension = JRequest::getCmd('extension', '');
- if ($extension) {
- $extension = '&extension='.$extension;
- }
+ $model = $this->getModel('Category');
// Preset the redirect
- $this->setRedirect('index.php?option=com_categories&view=categories'.$extension);
+ $this->setRedirect('index.php?option=com_categories&view=categories&extension=' . $this->extension);
return parent::batch($model);
}
@@ -134,15 +143,17 @@ public function batch($model)
/**
* Gets the URL arguments to append to an item redirect.
*
- * @param int $recordId The primary key id for the item.
+ * @param integer $recordId The primary key id for the item.
+ * @param string $urlVar The name of the URL variable for the id.
*
- * @return string The arguments to append to the redirect URL.
- * @since 1.6
+ * @return string The arguments to append to the redirect URL.
+ *
+ * @since 1.6
*/
protected function getRedirectToItemAppend($recordId = null, $urlVar = 'id')
{
$append = parent::getRedirectToItemAppend($recordId);
- $append .= '&extension='.$this->extension;
+ $append .= '&extension=' . $this->extension;
return $append;
}
@@ -150,13 +161,14 @@ protected function getRedirectToItemAppend($recordId = null, $urlVar = 'id')
/**
* Gets the URL arguments to append to a list redirect.
*
- * @return string The arguments to append to the redirect URL.
- * @since 1.6
+ * @return string The arguments to append to the redirect URL.
+ *
+ * @since 1.6
*/
protected function getRedirectToListAppend()
{
$append = parent::getRedirectToListAppend();
- $append .= '&extension='.$this->extension;
+ $append .= '&extension=' . $this->extension;
return $append;
}
diff --git a/administrator/components/com_categories/models/category.php b/administrator/components/com_categories/models/category.php
index f6e87cfd542ca..1afcdbc700a42 100644
--- a/administrator/components/com_categories/models/category.php
+++ b/administrator/components/com_categories/models/category.php
@@ -1,8 +1,10 @@
id)) {
- if ($record->published != -2) {
- return ;
+ if (!empty($record->id))
+ {
+ if ($record->published != -2)
+ {
+ return;
}
$user = JFactory::getUser();
- return $user->authorise('core.delete', $record->extension.'.category.'.(int) $record->id);
-
+ return $user->authorise('core.delete', $record->extension . '.category.' . (int) $record->id);
}
}
/**
- * Method to test whether a record can be deleted.
+ * Method to test whether a record can have its state changed.
*
- * @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
+ * @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 for existing category.
- if (!empty($record->id)) {
- return $user->authorise('core.edit.state', $record->extension.'.category.'.(int) $record->id);
+ if (!empty($record->id))
+ {
+ return $user->authorise('core.edit.state', $record->extension . '.category.' . (int) $record->id);
}
// New category, so check against the parent.
- elseif (!empty($record->parent_id)) {
- return $user->authorise('core.edit.state', $record->extension.'.category.'.(int) $record->parent_id);
+ elseif (!empty($record->parent_id))
+ {
+ return $user->authorise('core.edit.state', $record->extension . '.category.' . (int) $record->parent_id);
}
// Default to component settings if neither category nor parent known.
- else {
+ else
+ {
return $user->authorise('core.edit.state', $record->extension);
}
}
/**
- * Returns a Table object, always creating it
+ * Method to get a table object, load it if necessary.
*
- * @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
+ * @param string $type The table name. Optional.
+ * @param string $prefix The class prefix. Optional.
+ * @param array $config Configuration array for model. Optional.
+ *
+ * @return JTable A JTable object
+ *
+ * @since 1.6
*/
public function getTable($type = 'Category', $prefix = 'CategoriesTable', $config = array())
{
@@ -89,7 +101,9 @@ public function getTable($type = 'Category', $prefix = 'CategoriesTable', $confi
*
* Note. Calling getState in this method will result in recursion.
*
- * @since 1.6
+ * @return void
+ *
+ * @since 1.6
*/
protected function populateState()
{
@@ -100,38 +114,42 @@ protected function populateState()
// Load the User state.
$pk = (int) JRequest::getInt('id');
- $this->setState($this->getName().'.id', $pk);
+ $this->setState($this->getName() . '.id', $pk);
$extension = JRequest::getCmd('extension', 'com_content');
$this->setState('category.extension', $extension);
- $parts = explode('.',$extension);
+ $parts = explode('.', $extension);
// Extract the component name
$this->setState('category.component', $parts[0]);
// Extract the optional section name
- $this->setState('category.section', (count($parts)>1)?$parts[1]:null);
+ $this->setState('category.section', (count($parts) > 1) ? $parts[1] : null);
// Load the parameters.
- $params = JComponentHelper::getParams('com_categories');
+ $params = JComponentHelper::getParams('com_categories');
$this->setState('params', $params);
}
/**
* Method to get a category.
*
- * @param integer An optional id of the object to get, otherwise the id from the model state is used.
- * @return mixed Category data object on success, false on failure.
- * @since 1.6
+ * @param integer $pk An optional id of the object to get, otherwise the id from the model state is used.
+ *
+ * @return mixed Category data object on success, false on failure.
+ *
+ * @since 1.6
*/
public function getItem($pk = null)
{
- if ($result = parent::getItem($pk)) {
+ if ($result = parent::getItem($pk))
+ {
// Prime required properties.
- if (empty($result->id)) {
- $result->parent_id = $this->getState('category.parent_id');
- $result->extension = $this->getState('category.extension');
+ if (empty($result->id))
+ {
+ $result->parent_id = $this->getState('category.parent_id');
+ $result->extension = $this->getState('category.extension');
}
// Convert the metadata field to an array.
@@ -141,23 +159,27 @@ public function getItem($pk = null)
// Convert the created and modified dates to local user time for display in the form.
jimport('joomla.utilities.date');
- $tz = new DateTimeZone(JFactory::getApplication()->getCfg('offset'));
+ $tz = new DateTimeZone(JFactory::getApplication()->getCfg('offset'));
- if (intval($result->created_time)) {
+ if (intval($result->created_time))
+ {
$date = new JDate($result->created_time);
$date->setTimezone($tz);
$result->created_time = $date->toSql(true);
}
- else {
+ else
+ {
$result->created_time = null;
}
- if (intval($result->modified_time)) {
+ if (intval($result->modified_time))
+ {
$date = new JDate($result->modified_time);
$date->setTimezone($tz);
$result->modified_time = $date->toSql(true);
}
- else {
+ else
+ {
$result->modified_time = null;
}
}
@@ -168,39 +190,44 @@ public function getItem($pk = null)
/**
* Method to get the row 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
+ * @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)
{
// Initialise variables.
- $extension = $this->getState('category.extension');
+ $extension = $this->getState('category.extension');
// A workaround to get the extension into the model for save requests.
- if (empty($extension) && isset($data['extension'])) {
- $extension = $data['extension'];
- $parts = explode('.',$extension);
+ if (empty($extension) && isset($data['extension']))
+ {
+ $extension = $data['extension'];
+ $parts = explode('.', $extension);
- $this->setState('category.extension', $extension);
- $this->setState('category.component', $parts[0]);
- $this->setState('category.section', @$parts[1]);
+ $this->setState('category.extension', $extension);
+ $this->setState('category.component', $parts[0]);
+ $this->setState('category.section', @$parts[1]);
}
// Get the form.
- $form = $this->loadForm('com_categories.category'.$extension, 'category', array('control' => 'jform', 'load_data' => $loadData));
- if (empty($form)) {
+ $form = $this->loadForm('com_categories.category' . $extension, 'category', array('control' => 'jform', 'load_data' => $loadData));
+ if (empty($form))
+ {
return false;
}
// Modify the form based on Edit State access controls.
- if (empty($data['extension'])) {
+ if (empty($data['extension']))
+ {
$data['extension'] = $extension;
}
-
- if (!$this->canEditState((object) $data)) {
+ if (!$this->canEditState((object) $data))
+ {
// Disable fields for display.
$form->setFieldAttribute('ordering', 'disabled', 'true');
$form->setFieldAttribute('published', 'disabled', 'true');
@@ -218,10 +245,11 @@ public function getForm($data = array(), $loadData = true)
* A protected method to get the where clause for the reorder
* This ensures that the row will be moved relative to a row with the same extension
*
- * @param JCategoryTable current table instance
+ * @param JCategoryTable $table Current table instance
*
- * @return array An array of conditions to add to add to ordering queries.
- * @since 1.6
+ * @return array An array of conditions to add to add to ordering queries.
+ *
+ * @since 1.6
*/
protected function getReorderConditions($table)
{
@@ -231,15 +259,17 @@ protected function getReorderConditions($table)
/**
* Method to get the data that should be injected in the form.
*
- * @return mixed The data for the form.
- * @since 1.6
+ * @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_categories.edit.'.$this->getName().'.data', array());
+ $data = JFactory::getApplication()->getUserState('com_categories.edit.' . $this->getName() . '.data', array());
- if (empty($data)) {
+ if (empty($data))
+ {
$data = $this->getItem();
}
@@ -247,59 +277,69 @@ protected function loadFormData()
}
/**
- * @param object A form object.
- * @param mixed The data expected for the form.
- * @throws Exception if there is an error loading the form.
- * @since 1.6
+ * Method to preprocess the form.
+ *
+ * @param JForm $form A JForm object.
+ * @param mixed $data The data expected for the form.
+ * @param string $groups The name of the plugin group to import.
+ *
+ * @return void
+ *
+ * @see JFormField
+ * @since 1.6
+ * @throws Exception if there is an error in the form event.
*/
protected function preprocessForm(JForm $form, $data, $groups = '')
{
jimport('joomla.filesystem.path');
// Initialise variables.
- $lang = JFactory::getLanguage();
- $extension = $this->getState('category.extension');
- $component = $this->getState('category.component');
- $section = $this->getState('category.section');
+ $lang = JFactory::getLanguage();
+ $extension = $this->getState('category.extension');
+ $component = $this->getState('category.component');
+ $section = $this->getState('category.section');
// Get the component form if it exists
jimport('joomla.filesystem.path');
- $name = 'category'.($section ? ('.'.$section):'');
+ $name = 'category' . ($section ? ('.' . $section) : '');
// Looking first in the component models/forms folder
- $path = JPath::clean(JPATH_ADMINISTRATOR."/components/$component/models/forms/$name.xml");
+ $path = JPath::clean(JPATH_ADMINISTRATOR . "/components/$component/models/forms/$name.xml");
// Old way: looking in the component folder
- if (!file_exists($path)) {
- $path = JPath::clean(JPATH_ADMINISTRATOR."/components/$component/$name.xml");
+ if (!file_exists($path))
+ {
+ $path = JPath::clean(JPATH_ADMINISTRATOR . "/components/$component/$name.xml");
}
- if (file_exists($path)) {
+ if (file_exists($path))
+ {
$lang->load($component, JPATH_BASE, null, false, false);
$lang->load($component, JPATH_BASE, $lang->getDefault(), false, false);
- if (!$form->loadFile($path, false)) {
+ if (!$form->loadFile($path, false))
+ {
throw new Exception(JText::_('JERROR_LOADFILE_FAILED'));
}
}
// Try to find the component helper.
- $eName = str_replace('com_', '', $component);
- $path = JPath::clean(JPATH_ADMINISTRATOR."/components/$component/helpers/category.php");
+ $eName = str_replace('com_', '', $component);
+ $path = JPath::clean(JPATH_ADMINISTRATOR . "/components/$component/helpers/category.php");
- if (file_exists($path)) {
+ if (file_exists($path))
+ {
require_once $path;
- $cName = ucfirst($eName).ucfirst($section).'HelperCategory';
+ $cName = ucfirst($eName) . ucfirst($section) . 'HelperCategory';
- if (class_exists($cName) && is_callable(array($cName, 'onPrepareForm'))) {
- $lang->load($component, JPATH_BASE, null, false, false)
- || $lang->load($component, JPATH_BASE . '/components/' . $component, null, false, false)
- || $lang->load($component, JPATH_BASE, $lang->getDefault(), false, false)
- || $lang->load($component, JPATH_BASE . '/components/' . $component, $lang->getDefault(), false, false);
+ if (class_exists($cName) && is_callable(array($cName, 'onPrepareForm')))
+ {
+ $lang->load($component, JPATH_BASE, null, false, false) || $lang->load($component, JPATH_BASE . '/components/' . $component, null, false, false) || $lang->load($component, JPATH_BASE, $lang->getDefault(), false, false) || $lang->load($component, JPATH_BASE . '/components/' . $component, $lang->getDefault(), false, false);
call_user_func_array(array($cName, 'onPrepareForm'), array(&$form));
// Check for an error.
- if ($form instanceof Exception) {
+ if ($form instanceof Exception)
+ {
$this->setError($form->getMessage());
return false;
}
@@ -307,8 +347,8 @@ protected function preprocessForm(JForm $form, $data, $groups = '')
}
// Set the access control rules field component value.
- $form->setFieldAttribute('rules', 'component', $component);
- $form->setFieldAttribute('rules', 'section', $name);
+ $form->setFieldAttribute('rules', 'component', $component);
+ $form->setFieldAttribute('rules', 'section', $name);
// Trigger the default form events.
parent::preprocessForm($form, $data);
@@ -317,86 +357,98 @@ protected function preprocessForm(JForm $form, $data, $groups = '')
/**
* Method to save the form data.
*
- * @param array The form data.
- * @return boolean True on success.
- * @since 1.6
+ * @param array $data The form data.
+ *
+ * @return boolean True on success.
+ *
+ * @since 1.6
*/
public function save($data)
{
// Initialise variables;
$dispatcher = JDispatcher::getInstance();
- $table = $this->getTable();
- $pk = (!empty($data['id'])) ? $data['id'] : (int)$this->getState($this->getName().'.id');
- $isNew = true;
+ $table = $this->getTable();
+ $pk = (!empty($data['id'])) ? $data['id'] : (int) $this->getState($this->getName() . '.id');
+ $isNew = true;
// Include the content plugins for the on save events.
JPluginHelper::importPlugin('content');
// Load the row if saving an existing category.
- if ($pk > 0) {
+ if ($pk > 0)
+ {
$table->load($pk);
$isNew = false;
}
// Set the new parent id if parent id not matched OR while New/Save as Copy .
- if ($table->parent_id != $data['parent_id'] || $data['id'] == 0) {
+ if ($table->parent_id != $data['parent_id'] || $data['id'] == 0)
+ {
$table->setLocation($data['parent_id'], 'last-child');
}
// Alter the title for save as copy
- if (JRequest::getVar('task') == 'save2copy') {
- list($title,$alias) = $this->generateNewTitle($data['parent_id'], $data['alias'], $data['title']);
- $data['title'] = $title;
- $data['alias'] = $alias;
+ if (JRequest::getVar('task') == 'save2copy')
+ {
+ list($title, $alias) = $this->generateNewTitle($data['parent_id'], $data['alias'], $data['title']);
+ $data['title'] = $title;
+ $data['alias'] = $alias;
}
// Bind the data.
- if (!$table->bind($data)) {
+ if (!$table->bind($data))
+ {
$this->setError($table->getError());
return false;
}
// Bind the rules.
- if (isset($data['rules'])) {
+ if (isset($data['rules']))
+ {
$rules = new JAccessRules($data['rules']);
$table->setRules($rules);
}
// Check the data.
- if (!$table->check()) {
+ if (!$table->check())
+ {
$this->setError($table->getError());
return false;
}
// Trigger the onContentBeforeSave event.
- $result = $dispatcher->trigger($this->event_before_save, array($this->option.'.'.$this->name, &$table, $isNew));
- if (in_array(false, $result, true)) {
+ $result = $dispatcher->trigger($this->event_before_save, array($this->option . '.' . $this->name, &$table, $isNew));
+ if (in_array(false, $result, true))
+ {
$this->setError($table->getError());
return false;
}
// Store the data.
- if (!$table->store()) {
+ if (!$table->store())
+ {
$this->setError($table->getError());
return false;
}
// Trigger the onContentAfterSave event.
- $dispatcher->trigger($this->event_after_save, array($this->option.'.'.$this->name, &$table, $isNew));
+ $dispatcher->trigger($this->event_after_save, array($this->option . '.' . $this->name, &$table, $isNew));
// Rebuild the path for the category:
- if (!$table->rebuildPath($table->id)) {
+ if (!$table->rebuildPath($table->id))
+ {
$this->setError($table->getError());
return false;
}
// Rebuild the paths of the category's children:
- if (!$table->rebuild($table->id, $table->lft, $table->level, $table->path)) {
+ if (!$table->rebuild($table->id, $table->lft, $table->level, $table->path))
+ {
$this->setError($table->getError());
return false;
}
- $this->setState($this->getName().'.id', $table->id);
+ $this->setState($this->getName() . '.id', $table->id);
// Clear the cache
$this->cleanCache();
@@ -434,15 +486,17 @@ function publish(&$pks, $value = 1)
/**
* Method rebuild the entire nested set tree.
*
- * @return boolean False on failure or error, true otherwise.
- * @since 1.6
+ * @return boolean False on failure or error, true otherwise.
+ *
+ * @since 1.6
*/
public function rebuild()
{
- // Get an instance of the table obejct.
+ // Get an instance of the table object.
$table = $this->getTable();
- if (!$table->rebuild()) {
+ if (!$table->rebuild())
+ {
$this->setError($table->getError());
return false;
}
@@ -458,15 +512,20 @@ public function rebuild()
* First we save the new order values in the lft values of the changed ids.
* Then we invoke the table rebuild to implement the new ordering.
*
- * @return boolean false on failuer or error, true otherwise
- * @since 1.6
+ * @param array $idArray An array of primary key ids.
+ * @param integer $lft_array The lft value
+ *
+ * @return boolean False on failure or error, True otherwise
+ *
+ * @since 1.6
*/
public function saveorder($idArray = null, $lft_array = null)
{
// Get an instance of the table object.
$table = $this->getTable();
- if (!$table->saveorder($idArray, $lft_array)) {
+ if (!$table->saveorder($idArray, $lft_array))
+ {
$this->setError($table->getError());
return false;
}
@@ -474,84 +533,54 @@ public function saveorder($idArray = null, $lft_array = null)
// Clear the cache
$this->cleanCache();
- return true;
-
- }
-
- /**
- * Batch access level changes for a group of rows.
- *
- * @param int The new value matching an Asset Group ID.
- * @param array An array of row IDs.
- * @return booelan True if successful, false otherwise and internal error is set.
- * @since 1.6
- */
- protected function batchAccess($value, $pks)
- {
- // Check that user has edit permission for every category being changed
- // Note that the entire batch operation fails if any category lacks edit permission
- $user = JFactory::getUser();
- $extension = JRequest::getWord('extension');
- foreach ($pks as $pk) {
- if (!$user->authorise('core.edit', $extension.'.category.'.$pk)) {
- // Error since user cannot edit this category
- $this->setError(JText::_('COM_CATEGORIES_BATCH_CANNOT_EDIT'));
- return false;
- }
- }
- $table = $this->getTable();
- foreach ($pks as $pk) {
- $table->reset();
- $table->load($pk);
- $table->access = (int) $value;
- if (!$table->store()) {
- $this->setError($table->getError());
- return false;
- }
- }
-
return true;
}
/**
* Batch copy categories to a new category.
*
- * @param int $value The new category or sub-item.
- * @param array $pks An array of row IDs.
+ * @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 1.6
+ * @return mixed An array of new IDs on success, boolean false on failure.
+ *
+ * @since 1.6
*/
- protected function batchCopy($value, $pks)
+ protected function batchCopy($value, $pks, $contexts)
{
// $value comes as {parent_id}.{extension}
- $parts = explode('.', $value);
- $parentId = (int) JArrayHelper::getValue($parts, 0, 1);
+ $parts = explode('.', $value);
+ $parentId = (int) JArrayHelper::getValue($parts, 0, 1);
- $table = $this->getTable();
- $db = $this->getDbo();
- $user = JFactory::getUser();
- $extension = JRequest::getWord('extension');
- $i = 0;
+ $table = $this->getTable();
+ $db = $this->getDbo();
+ $user = JFactory::getUser();
+ $extension = JFactory::getApplication()->input->get('extension', '', 'word');
+ $i = 0;
// Check that the parent exists
- if ($parentId) {
- if (!$table->load($parentId)) {
- if ($error = $table->getError()) {
+ if ($parentId)
+ {
+ if (!$table->load($parentId))
+ {
+ if ($error = $table->getError())
+ {
// Fatal error
$this->setError($error);
return false;
}
- else {
+ else
+ {
// Non-fatal error
$this->setError(JText::_('JGLOBAL_BATCH_MOVE_PARENT_NOT_FOUND'));
$parentId = 0;
}
}
// Check that user has create permission for parent category
- $canCreate = ($parentId == $table->getRootId()) ? $user->authorise('core.create', $extension) :
- $user->authorise('core.create', $extension.'.category.'.$parentId);
- if (!$canCreate) {
+ $canCreate = ($parentId == $table->getRootId()) ? $user->authorise('core.create', $extension) : $user->authorise('core.create', $extension . '.category.' . $parentId);
+ if (!$canCreate)
+ {
// Error since user cannot create in parent category
$this->setError(JText::_('COM_CATEGORIES_BATCH_CANNOT_CREATE'));
return false;
@@ -559,13 +588,16 @@ protected function batchCopy($value, $pks)
}
// If the parent is 0, set it to the ID of the root item in the tree
- if (empty($parentId)) {
- if (!$parentId = $table->getRootId()) {
+ if (empty($parentId))
+ {
+ if (!$parentId = $table->getRootId())
+ {
$this->setError($db->getErrorMsg());
return false;
}
// Make sure we can create in root
- elseif (!$user->authorise('core.create', $extension)) {
+ elseif (!$user->authorise('core.create', $extension))
+ {
$this->setError(JText::_('COM_CATEGORIES_BATCH_CANNOT_CREATE'));
return false;
}
@@ -575,13 +607,14 @@ protected function batchCopy($value, $pks)
$parents = array();
// Calculate the emergency stop count as a precaution against a runaway loop bug
- $db->setQuery(
- 'SELECT COUNT(id)' .
- ' FROM #__categories'
- );
+ $query = $db->getQuery(true);
+ $query->select('COUNT(id)');
+ $query->from($db->quoteName('#__categories'));
+ $db->setQuery($query);
$count = $db->loadResult();
- if ($error = $db->getErrorMsg()) {
+ if ($error = $db->getErrorMsg())
+ {
$this->setError($error);
return false;
}
@@ -595,13 +628,16 @@ protected function batchCopy($value, $pks)
$table->reset();
// Check that the row actually exists
- if (!$table->load($pk)) {
- if ($error = $table->getError()) {
+ if (!$table->load($pk))
+ {
+ if ($error = $table->getError())
+ {
// Fatal error
$this->setError($error);
return false;
}
- else {
+ else
+ {
// Not fatal error
$this->setError(JText::sprintf('JGLOBAL_BATCH_MOVE_ROW_NOT_FOUND', $pk));
continue;
@@ -609,49 +645,52 @@ protected function batchCopy($value, $pks)
}
// Copy is a bit tricky, because we also need to copy the children
- $db->setQuery(
- 'SELECT id' .
- ' FROM #__categories' .
- ' WHERE lft > '.(int) $table->lft.' AND rgt < '.(int) $table->rgt
- );
- $childIds = $db->loadResultArray();
+ $query->clear();
+ $query->select('id');
+ $query->from($db->quoteName('#__categories'));
+ $query->where('lft > ' . (int) $table->lft);
+ $query->where('rgt < ' . (int) $table->rgt);
+ $db->setQuery($query);
+ $childIds = $db->loadColumn();
// Add child ID's to the array only if they aren't already there.
foreach ($childIds as $childId)
{
- if (!in_array($childId, $pks)) {
+ if (!in_array($childId, $pks))
+ {
array_push($pks, $childId);
}
}
// Make a copy of the old ID and Parent ID
- $oldId = $table->id;
- $oldParentId = $table->parent_id;
+ $oldId = $table->id;
+ $oldParentId = $table->parent_id;
// Reset the id because we are making a copy.
- $table->id = 0;
+ $table->id = 0;
// If we a copying children, the Old ID will turn up in the parents list
// otherwise it's a new top level item
- $table->parent_id = isset($parents[$oldParentId]) ? $parents[$oldParentId] : $parentId;
+ $table->parent_id = isset($parents[$oldParentId]) ? $parents[$oldParentId] : $parentId;
// Set the new location in the tree for the node.
$table->setLocation($table->parent_id, 'last-child');
// TODO: Deal with ordering?
//$table->ordering = 1;
- $table->level = null;
- $table->asset_id = null;
- $table->lft = null;
- $table->rgt = null;
+ $table->level = null;
+ $table->asset_id = null;
+ $table->lft = null;
+ $table->rgt = null;
// Alter the title & alias
- list($title,$alias) = $this->generateNewTitle($table->parent_id, $table->alias, $table->title);
- $table->title = $title;
- $table->alias = $alias;
+ list($title, $alias) = $this->generateNewTitle($table->parent_id, $table->alias, $table->title);
+ $table->title = $title;
+ $table->alias = $alias;
// Store the row.
- if (!$table->store()) {
+ if (!$table->store())
+ {
$this->setError($table->getError());
return false;
}
@@ -660,7 +699,7 @@ protected function batchCopy($value, $pks)
$newId = $table->get('id');
// Add the new ID to the array
- $newIds[$i] = $newId;
+ $newIds[$i] = $newId;
$i++;
// Now we log the old 'parent' to the new 'parent'
@@ -669,13 +708,15 @@ protected function batchCopy($value, $pks)
}
// Rebuild the hierarchy.
- if (!$table->rebuild()) {
+ if (!$table->rebuild())
+ {
$this->setError($table->getError());
return false;
}
// Rebuild the tree path.
- if (!$table->rebuildPath($table->id)) {
+ if (!$table->rebuildPath($table->id))
+ {
$this->setError($table->getError());
return false;
}
@@ -686,40 +727,47 @@ protected function batchCopy($value, $pks)
/**
* Batch move categories to a new category.
*
- * @param int $value The new category or sub-item.
- * @param array $pks An array of row IDs.
+ * @param integer $value The new category ID.
+ * @param array $pks An array of row IDs.
+ * @param array $contexts An array of item contexts.
*
- * @return booelan True if successful, false otherwise and internal error is set.
- * @since 1.6
+ * @return boolean True on success.
+ *
+ * @since 1.6
*/
- protected function batchMove($value, $pks)
+ protected function batchMove($value, $pks, $contexts)
{
- $parentId = (int) $value;
+ $parentId = (int) $value;
- $table = $this->getTable();
- $db = $this->getDbo();
- $user = JFactory::getUser();
- $extension = JRequest::getWord('extension');
+ $table = $this->getTable();
+ $db = $this->getDbo();
+ $query = $db->getQuery(true);
+ $user = JFactory::getUser();
+ $extension = JFactory::getApplication()->input->get('extension', '', 'word');
// Check that the parent exists.
- if ($parentId) {
- if (!$table->load($parentId)) {
- if ($error = $table->getError()) {
+ if ($parentId)
+ {
+ if (!$table->load($parentId))
+ {
+ if ($error = $table->getError())
+ {
// Fatal error
$this->setError($error);
return false;
}
- else {
+ else
+ {
// Non-fatal error
$this->setError(JText::_('JGLOBAL_BATCH_MOVE_PARENT_NOT_FOUND'));
$parentId = 0;
}
}
// Check that user has create permission for parent category
- $canCreate = ($parentId == $table->getRootId()) ? $user->authorise('core.create', $extension) :
- $user->authorise('core.create', $extension.'.category.'.$parentId);
- if (!$canCreate) {
+ $canCreate = ($parentId == $table->getRootId()) ? $user->authorise('core.create', $extension) : $user->authorise('core.create', $extension . '.category.' . $parentId);
+ if (!$canCreate)
+ {
// Error since user cannot create in parent category
$this->setError(JText::_('COM_CATEGORIES_BATCH_CANNOT_CREATE'));
return false;
@@ -727,8 +775,10 @@ protected function batchMove($value, $pks)
// Check that user has edit permission for every category being moved
// Note that the entire batch operation fails if any category lacks edit permission
- foreach ($pks as $pk) {
- if (!$user->authorise('core.edit', $extension.'.category.'.$pk)) {
+ foreach ($pks as $pk)
+ {
+ if (!$user->authorise('core.edit', $extension . '.category.' . $pk))
+ {
// Error since user cannot edit this category
$this->setError(JText::_('COM_CATEGORIES_BATCH_CANNOT_EDIT'));
return false;
@@ -736,7 +786,6 @@ protected function batchMove($value, $pks)
}
}
-
// We are going to store all the children and just move the category
$children = array();
@@ -744,13 +793,16 @@ protected function batchMove($value, $pks)
foreach ($pks as $pk)
{
// Check that the row actually exists
- if (!$table->load($pk)) {
- if ($error = $table->getError()) {
+ if (!$table->load($pk))
+ {
+ if ($error = $table->getError())
+ {
// Fatal error
$this->setError($error);
return false;
}
- else {
+ else
+ {
// Not fatal error
$this->setError(JText::sprintf('JGLOBAL_BATCH_MOVE_ROW_NOT_FOUND', $pk));
continue;
@@ -761,36 +813,42 @@ protected function batchMove($value, $pks)
$table->setLocation($parentId, 'last-child');
// Check if we are moving to a different parent
- if ($parentId != $table->parent_id) {
+ if ($parentId != $table->parent_id)
+ {
// Add the child node ids to the children array.
- $db->setQuery(
- 'SELECT '.$db->quoteName(id).' .
- FROM '.$db->quoteName("#__categories").' WHERE $db->quoteName(lft) BETWEEN '.(int) $table->lft.' AND '.(int) $table->rgt
- );
- $children = array_merge($children, (array) $db->loadResultArray());
+ $query->clear();
+ $query->select('id');
+ $query->from($db->quoteName('#__categories'));
+ $query->where($db->quoteName('lft' ) .' BETWEEN ' . (int) $table->lft . ' AND ' . (int) $table->rgt);
+ $db->setQuery($query);
+ $children = array_merge($children, (array) $db->loadColumn());
}
// Store the row.
- if (!$table->store()) {
+ if (!$table->store())
+ {
$this->setError($table->getError());
return false;
}
// Rebuild the tree path.
- if (!$table->rebuildPath()) {
+ if (!$table->rebuildPath())
+ {
$this->setError($table->getError());
return false;
}
}
// Process the child rows
- if (!empty($children)) {
+ if (!empty($children))
+ {
// Remove any duplicates and sanitize ids.
$children = array_unique($children);
JArrayHelper::toInteger($children);
// Check for a database error.
- if ($db->getErrorNum()) {
+ if ($db->getErrorNum())
+ {
$this->setError($db->getErrorMsg());
return false;
}
@@ -827,11 +885,12 @@ protected function cleanCache($group = null, $client_id = 0)
/**
* Method to change the title & alias.
*
- * @param int The value of the parent category ID.
- * @param string The value of the category alias.
- * @param string The value of the category title.
+ * @param integer $parent_id The id of the parent.
+ * @param string $alias The alias.
+ * @param string $title The title.
+ *
+ * @return array Contains the modified title and alias.
*
- * @return array Contains title and alias.
* @since 1.7
*/
protected function generateNewTitle($parent_id, $alias, $title)
diff --git a/administrator/components/com_contact/controllers/contact.php b/administrator/components/com_contact/controllers/contact.php
index 1686881c58891..30c8eab0503af 100644
--- a/administrator/components/com_contact/controllers/contact.php
+++ b/administrator/components/com_contact/controllers/contact.php
@@ -1,10 +1,10 @@
authorise('core.create', $this->option.'.category.'.$categoryId);
+ $allow = $user->authorise('core.create', $this->option . '.category.' . $categoryId);
}
- if ($allow === null) {
+ if ($allow === null)
+ {
// In the absense of better information, revert to the component permissions.
return parent::allowAdd($data);
}
- else {
+ else
+ {
return $allow;
}
}
@@ -51,35 +55,40 @@ protected function allowAdd($data = array())
/**
* Method override to check if you can edit an existing record.
*
- * @param array $data An array of input data.
- * @param string $key The name of the key for the primary key.
+ * @param array $data An array of input data.
+ * @param string $key The name of the key for the primary key.
+ *
+ * @return boolean
*
- * @return boolean
- * @since 1.6
+ * @since 1.6
*/
protected function allowEdit($data = array(), $key = 'id')
{
// Initialise variables.
- $recordId = (int) isset($data[$key]) ? $data[$key] : 0;
- $user = JFactory::getUser();
- $userId = $user->get('id');
- $categoryId = (int) isset($data['catid']) ? $data['catid'] : 0;
+ $recordId = (int) isset($data[$key]) ? $data[$key] : 0;
+ $user = JFactory::getUser();
+ $userId = $user->get('id');
+ $categoryId = (int) isset($data['catid']) ? $data['catid'] : 0;
// Check general edit permission first.
- if ($user->authorise('core.edit', $this->option.'.category.'.$categoryId)) {
+ if ($user->authorise('core.edit', $this->option . '.category.' . $categoryId))
+ {
return true;
}
// Fallback on edit.own.
// First test if the permission is available.
- if ($user->authorise('core.edit.own', $this->option.'.category.'.$categoryId)) {
+ if ($user->authorise('core.edit.own', $this->option . '.category.' . $categoryId))
+ {
// Now test the owner is the user.
- $ownerId = (int) isset($data['created_by']) ? $data['created_by'] : 0;
- if (empty($ownerId) && $recordId) {
+ $ownerId = (int) isset($data['created_by']) ? $data['created_by'] : 0;
+ if (empty($ownerId) && $recordId)
+ {
// Need to do a lookup from the model.
- $record = $this->getModel()->getItem($recordId);
+ $record = $this->getModel()->getItem($recordId);
- if (empty($record)) {
+ if (empty($record))
+ {
return false;
}
@@ -87,7 +96,8 @@ protected function allowEdit($data = array(), $key = 'id')
}
// If the owner matches 'me' then do the test.
- if ($ownerId == $userId) {
+ if ($ownerId == $userId)
+ {
return true;
}
}
@@ -95,4 +105,26 @@ protected function allowEdit($data = array(), $key = 'id')
// Since there is no asset tracking, revert to the component permissions.
return parent::allowEdit($data, $key);
}
+
+ /**
+ * Method to run batch operations.
+ *
+ * @param object $model The model.
+ *
+ * @return boolean True if successful, false otherwise and internal error is set.
+ *
+ * @since 2.5
+ */
+ public function batch($model = null)
+ {
+ JRequest::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
+
+ // Set the model
+ $model = $this->getModel('Contact', '', array());
+
+ // Preset the redirect
+ $this->setRedirect(JRoute::_('index.php?option=com_contact&view=contacts' . $this->getRedirectToListAppend(), false));
+
+ return parent::batch($model);
+ }
}
diff --git a/administrator/components/com_contact/models/contact.php b/administrator/components/com_contact/models/contact.php
index 5233a2371ac3e..a22b9c50800e3 100644
--- a/administrator/components/com_contact/models/contact.php
+++ b/administrator/components/com_contact/models/contact.php
@@ -21,6 +21,265 @@
*/
class ContactModelContact extends JModelAdmin
{
+ /**
+ * 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 (!empty($commands['assetgroup_id']))
+ {
+ if (!$this->batchAccess($commands['assetgroup_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 (strlen($commands['user_id']) > 0)
+ {
+ if (!$this->batchUser($commands['user_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 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 11.1
+ */
+ 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_contact.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;
+ }
+
+ /**
+ * Batch change a linked user.
+ *
+ * @param integer $value The new value matching a User ID.
+ * @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 batchUser($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->user_id = (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;
+ }
+
/**
* Method to test whether a record can be deleted.
*
diff --git a/administrator/components/com_contact/views/contacts/tmpl/default.php b/administrator/components/com_contact/views/contacts/tmpl/default.php
index cdeef23816c07..53953a8d6630a 100644
--- a/administrator/components/com_contact/views/contacts/tmpl/default.php
+++ b/administrator/components/com_contact/views/contacts/tmpl/default.php
@@ -1,10 +1,10 @@
+
+ loadTemplate('batch'); ?>
+
diff --git a/administrator/components/com_contact/views/contacts/tmpl/default_batch.php b/administrator/components/com_contact/views/contacts/tmpl/default_batch.php
new file mode 100644
index 0000000000000..6dbda45847c01
--- /dev/null
+++ b/administrator/components/com_contact/views/contacts/tmpl/default_batch.php
@@ -0,0 +1,32 @@
+state->get('filter.published');
+?>
+
diff --git a/administrator/components/com_content/controllers/article.php b/administrator/components/com_content/controllers/article.php
index 2ee454a112aab..6a8ae1a3e82f2 100644
--- a/administrator/components/com_content/controllers/article.php
+++ b/administrator/components/com_content/controllers/article.php
@@ -1,10 +1,10 @@
view_list = 'featured';
$this->view_item = 'article&return=featured';
}
@@ -42,28 +42,32 @@ function __construct($config = array())
/**
* Method override to check if you can add a new record.
*
- * @param array An array of input data.
+ * @param array $data An array of input data.
*
- * @return boolean
- * @since 1.6
+ * @return boolean
+ *
+ * @since 1.6
*/
protected function allowAdd($data = array())
{
// Initialise variables.
- $user = JFactory::getUser();
- $categoryId = JArrayHelper::getValue($data, 'catid', JRequest::getInt('filter_category_id'), 'int');
- $allow = null;
+ $user = JFactory::getUser();
+ $categoryId = JArrayHelper::getValue($data, 'catid', JRequest::getInt('filter_category_id'), 'int');
+ $allow = null;
- if ($categoryId) {
+ if ($categoryId)
+ {
// If the category has been passed in the data or URL check it.
- $allow = $user->authorise('core.create', 'com_content.category.'.$categoryId);
+ $allow = $user->authorise('core.create', 'com_content.category.' . $categoryId);
}
- if ($allow === null) {
+ if ($allow === null)
+ {
// In the absense of better information, revert to the component permissions.
return parent::allowAdd();
}
- else {
+ else
+ {
return $allow;
}
}
@@ -71,34 +75,39 @@ protected function allowAdd($data = array())
/**
* Method override to check if you can edit an existing record.
*
- * @param array $data An array of input data.
- * @param string $key The name of the key for the primary key.
+ * @param array $data An array of input data.
+ * @param string $key The name of the key for the primary key.
*
- * @return boolean
- * @since 1.6
+ * @return boolean
+ *
+ * @since 1.6
*/
protected function allowEdit($data = array(), $key = 'id')
{
// Initialise variables.
- $recordId = (int) isset($data[$key]) ? $data[$key] : 0;
- $user = JFactory::getUser();
- $userId = $user->get('id');
+ $recordId = (int) isset($data[$key]) ? $data[$key] : 0;
+ $user = JFactory::getUser();
+ $userId = $user->get('id');
// Check general edit permission first.
- if ($user->authorise('core.edit', 'com_content.article.'.$recordId)) {
+ if ($user->authorise('core.edit', 'com_content.article.' . $recordId))
+ {
return true;
}
// Fallback on edit.own.
// First test if the permission is available.
- if ($user->authorise('core.edit.own', 'com_content.article.'.$recordId)) {
+ if ($user->authorise('core.edit.own', 'com_content.article.' . $recordId))
+ {
// Now test the owner is the user.
- $ownerId = (int) isset($data['created_by']) ? $data['created_by'] : 0;
- if (empty($ownerId) && $recordId) {
+ $ownerId = (int) isset($data['created_by']) ? $data['created_by'] : 0;
+ if (empty($ownerId) && $recordId)
+ {
// Need to do a lookup from the model.
- $record = $this->getModel()->getItem($recordId);
+ $record = $this->getModel()->getItem($recordId);
- if (empty($record)) {
+ if (empty($record))
+ {
return false;
}
@@ -106,7 +115,8 @@ protected function allowEdit($data = array(), $key = 'id')
}
// If the owner matches 'me' then do the test.
- if ($ownerId == $userId) {
+ if ($ownerId == $userId)
+ {
return true;
}
}
@@ -118,18 +128,21 @@ protected function allowEdit($data = array(), $key = 'id')
/**
* Method to run batch operations.
*
- * @return void
- * @since 1.6
+ * @param object $model The model.
+ *
+ * @return boolean True if successful, false otherwise and internal error is set.
+ *
+ * @since 1.6
*/
- public function batch($model)
+ public function batch($model = null)
{
JRequest::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
// Set the model
- $model = $this->getModel('Article', '', array());
+ $model = $this->getModel('Article', '', array());
// Preset the redirect
- $this->setRedirect(JRoute::_('index.php?option=com_content&view=articles'.$this->getRedirectToListAppend(), false));
+ $this->setRedirect(JRoute::_('index.php?option=com_content&view=articles' . $this->getRedirectToListAppend(), false));
return parent::batch($model);
}
diff --git a/administrator/components/com_content/models/article.php b/administrator/components/com_content/models/article.php
index e36b8b0ea7560..4c307950e141e 100644
--- a/administrator/components/com_content/models/article.php
+++ b/administrator/components/com_content/models/article.php
@@ -29,6 +29,140 @@ class ContentModelArticle extends JModelAdmin
*/
protected $text_prefix = 'COM_CONTENT';
+ /**
+ * 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 11.1
+ */
+ 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
+ $extension = JFactory::getApplication()->input->get('option', '');
+ $user = JFactory::getUser();
+ if (!$user->authorise('core.create', $extension . '.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->title);
+ $table->title = $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;
+
+ // Get the featured state
+ $featured = $table->featured;
+
+ // 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++;
+
+ // Check if the article was featured and update the #__content_frontpage table
+ if ($featured == 1)
+ {
+ $db = $this->getDbo();
+ $query = $db->getQuery(true);
+ $query->insert($db->quoteName('#__content_frontpage'));
+ $query->values($newId . ', 0');
+ $db->setQuery($query);
+ $db->query();
+ }
+ }
+
+ // Clean the cache
+ $this->cleanCache();
+
+ return $newIds;
+ }
+
/**
* Method to test whether a record can be deleted.
*
diff --git a/administrator/components/com_content/views/articles/tmpl/default_batch.php b/administrator/components/com_content/views/articles/tmpl/default_batch.php
index deb23652334e0..ec0d4f5bc33a3 100644
--- a/administrator/components/com_content/views/articles/tmpl/default_batch.php
+++ b/administrator/components/com_content/views/articles/tmpl/default_batch.php
@@ -1,10 +1,10 @@
= 0) : ?>
-
+