Back to AdminModel class

Method batchTag

protected bool
batchTag
(mixed $value, mixed $pks, mixed $contexts)
Batch tag a list of item.
Parameters
  • int $value The value of the new tag.
  • 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
  • 3.1
Class: AdminModel
Project: Joomla

Method batchTag - Source code

/**
 * Batch tag a list of item.
 *
 * @param   integer  $value     The value of the new tag.
 * @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   3.1
 */
protected function batchTag($value, $pks, $contexts)
{
    // Initialize re-usable member properties, and re-usable local variables
    $this->initBatch();
    $tags = array($value);
    foreach ($pks as $pk) {
        if ($this->user->authorise('core.edit', $contexts[$pk])) {
            $this->table->reset();
            $this->table->load($pk);
            $setTagsEvent = \Joomla\CMS\Event\AbstractEvent::create('onTableSetNewTags', array('subject' => $this->table, 'newTags' => $tags, 'replaceTags' => false));
            try {
                $this->table->getDispatcher()->dispatch('onTableSetNewTags', $setTagsEvent);
            } catch (\RuntimeException $e) {
                $this->setError($e->getMessage());
                return false;
            }
        } else {
            $this->setError(Text::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_EDIT'));
            return false;
        }
    }
    // Clean the cache
    $this->cleanCache();
    return true;
}