- Модуль: tasks
- Путь к файлу: ~/bitrix/modules/tasks/lib/control/tag.php
- Класс: BitrixTasksControlTag
- Вызов: Tag::addToGroupTask
public function addToGroupTask(int $taskId, int $groupId, array $tagsForAdd): void
{
if (empty($tagsForAdd))
{
return;
}
$idList = [];
$addToGroup = [];
foreach ($tagsForAdd as $tag)
{
$tagId = $this->getIdByGroup($groupId, $tag);
$isExistsInCurrentPull = $this->isExistsInCurrentPull($tag['NAME'], $addToGroup);
if ($tagId === 0)
{
if ($isExistsInCurrentPull)
{
continue;
}
$addToGroup[] = [
'GROUP_ID' => $groupId,
'NAME' => $tag['NAME'],
];
continue;
}
if (!$isExistsInCurrentPull)
{
$idList[] = $tagId;
}
}
$idList = array_merge($this->addToGroup($groupId, $addToGroup), $idList);
if (empty($idList))
{
return;
}
$implode = [];
foreach ($idList as $id)
{
$implode [] = "({$taskId}, {$id})";
}
$implode = implode(',', $implode);
$sql = 'INSERT IGNORE INTO ' . LabelTable::getRelationTable() . " (`TASK_ID`, `TAG_ID`) VALUES {$implode}";
Application::getConnection()->query($sql);
}