Form Controller

It is a method to run batch operations.

  • param \JModelLegacy $model - The model of the component being processed.
  • return boolean - True if successful, false otherwise and internal error is set.
public function batch($model)
{
$vars = $this->input->post->get('batch', array(), 'array');
$cid = $this->input->post->get('cid', array(), 'array');

// Build an array of item contexts to check
$contexts = array();

$option = isset($this->extension) ? $this->extension : $this->option;

foreach ($cid as $id)
{
// If we're coming from com_categories, we need to use extension vs. option
$contexts[$id] = $option . '.' . $this->context . '.' . $id;
}

// Attempt to run the batch operation.
if ($model->batch($vars, $cid, $contexts))
{
$this->setMessage(\JText::_('JLIB_APPLICATION_SUCCESS_BATCH'));

return true;
}
else
{
$this->setMessage(\JText::sprintf('JLIB_APPLICATION_ERROR_BATCH_FAILED', $model->getError()), 'warning');

return false;
}
}