Back to FormController class

Method batch

public bool
batch
(mixed $model)
Method to run batch operations.
Parameters
  • \Joomla\CMS\MVC\Model\BaseDatabaseModel $model The model of the component being processed.
Returns
  • bool True if successful, false otherwise and internal error is set.
Since
  • 1.7

Method batch - Source code

/**
 * Method to run batch operations.
 *
 * @param   BaseDatabaseModel  $model  The model of the component being processed.
 *
 * @return	boolean	 True if successful, false otherwise and internal error is set.
 *
 * @since	1.7
 */
public function batch($model)
{
    $vars = $this->input->post->get('batch', array(), 'array');
    $cid = (array) $this->input->post->get('cid', array(), 'int');
    // Remove zero values resulting from input filter
    $cid = array_filter($cid);
    // Build an array of item contexts to check
    $contexts = array();
    $option = $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(Text::_('JLIB_APPLICATION_SUCCESS_BATCH'));
        return true;
    } else {
        $this->setMessage(Text::sprintf('JLIB_APPLICATION_ERROR_BATCH_FAILED', $model->getError()), 'warning');
        return false;
    }
}