/**
* Method to add tag rows to mapping table.
*
* @param integer $ucmId ID of the #__ucm_content item being tagged
* @param TableInterface $table Table object being tagged
* @param array $tags Array of tags to be applied.
*
* @return boolean true on success, otherwise false.
*
* @since 3.1
*/
public function addTagMapping($ucmId, TableInterface $table, $tags = array())
{
$db = $table->getDbo();
$key = $table->getKeyName();
$item = $table->{$key};
$ucm = new UCMType($this->typeAlias, $db);
$typeId = $ucm->getTypeId();
// Insert the new tag maps
if (strpos('#', implode(',', $tags)) === false) {
$tags = self::createTagsFromField($tags);
}
// Prevent saving duplicate tags
$tags = array_values(array_unique($tags));
if (!$tags) {
return true;
}
$query = $db->getQuery(true);
$query->insert('#__contentitem_tag_map');
$query->columns([$db->quoteName('core_content_id'), $db->quoteName('content_item_id'), $db->quoteName('tag_id'), $db->quoteName('type_id'), $db->quoteName('type_alias'), $db->quoteName('tag_date')]);
foreach ($tags as $tag) {
$query->values(implode(',', array_merge($query->bindArray([(int) $ucmId, (int) $item, (int) $tag, (int) $typeId]), $query->bindArray([$this->typeAlias], ParameterType::STRING), [$query->currentTimestamp()])));
}
$db->setQuery($query);
return (bool) $db->execute();
}