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