Back to AdminModel class

Method batchAccess

protected bool
batchAccess
(mixed $value, mixed $pks, mixed $contexts)
Batch access level changes for a group of rows.
Parameters
  • int $value The new value matching an Asset Group ID.
  • array $pks An array of row IDs.
  • array $contexts An array of item contexts.
Returns
  • bool True if successful, false otherwise and internal error is set.
Since
  • 1.7
Class: AdminModel
Project: Joomla

Method batchAccess - Source code

/**
 * Batch access level changes for a group of rows.
 *
 * @param   integer  $value     The new value matching an Asset Group 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 batchAccess($value, $pks, $contexts)
{
    // Initialize re-usable member properties, and re-usable local variables
    $this->initBatch();
    foreach ($pks as $pk) {
        if ($this->user->authorise('core.edit', $contexts[$pk])) {
            $this->table->reset();
            $this->table->load($pk);
            $this->table->access = (int) $value;
            $event = new BeforeBatchEvent($this->event_before_batch, ['src' => $this->table, 'type' => 'access']);
            $this->dispatchEvent($event);
            // Check the row.
            if (!$this->table->check()) {
                $this->setError($this->table->getError());
                return false;
            }
            if (!$this->table->store()) {
                $this->setError($this->table->getError());
                return false;
            }
        } else {
            $this->setError(Text::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_EDIT'));
            return false;
        }
    }
    // Clean the cache
    $this->cleanCache();
    return true;
}