/**
* Batch move items to a new category
*
* @param integer $value The new category 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 1.7
*/
protected function batchMove($value, $pks, $contexts)
{
// Initialize re-usable member properties, and re-usable local variables
$this->initBatch();
$categoryId = (int) $value;
if (!$this->checkCategoryId($categoryId)) {
return false;
}
// Parent exists so we proceed
foreach ($pks as $pk) {
if (!$this->user->authorise('core.edit', $contexts[$pk])) {
$this->setError(Text::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_EDIT'));
return false;
}
// Check that the row actually exists
if (!$this->table->load($pk)) {
if ($error = $this->table->getError()) {
// Fatal error
$this->setError($error);
return false;
} else {
// Not fatal error
$this->setError(Text::sprintf('JLIB_APPLICATION_ERROR_BATCH_MOVE_ROW_NOT_FOUND', $pk));
continue;
}
}
// Set the new category ID
$this->table->catid = $categoryId;
$event = new BeforeBatchEvent($this->event_before_batch, ['src' => $this->table, 'type' => 'move']);
$this->dispatchEvent($event);
// Check the row.
if (!$this->table->check()) {
$this->setError($this->table->getError());
return false;
}
// Store the row.
if (!$this->table->store()) {
$this->setError($this->table->getError());
return false;
}
}
// Clean the cache
$this->cleanCache();
return true;
}