- Модуль: tasks
- Путь к файлу: ~/bitrix/modules/tasks/lib/integration/forum/task/comment.php
- Класс: BitrixTasksIntegrationForumTaskComment
- Вызов: Comment::add
static function add($taskId, array $data)
{
$result = new Result();
if (!self::includeModule())
{
$result->addError('NO_MODULE', 'No forum module installed');
return $result;
}
CounterCounterService::getInstance()->collectData((int)$taskId);
if (!array_key_exists('AUTHOR_ID', $data))
{
$data['AUTHOR_ID'] = User::getId();
}
if (!array_key_exists('USE_SMILES', $data))
{
$data['USE_SMILES'] = 'Y';
}
if(
$data['POST_MESSAGE'] !== ''
&& array_key_exists('UF_TASK_COMMENT_TYPE', $data)
)
{
if (empty($data['AUX_DATA']))
{
$data['AUX_DATA'] = [
'auxData' => $data['UF_TASK_COMMENT_TYPE'],
'text' => $data['POST_MESSAGE'],
];
}
$data['SERVICE_TYPE'] = ForumCommentsServiceManager::TYPE_TASK_INFO;
if (defined(ForumCommentsServiceManager::class . '::TYPE_FORUM_DEFAULT'))
{
$data['SERVICE_DATA'] = Json::encode($data['AUX_DATA']);
$data['POST_MESSAGE'] = ForumCommentsServiceManager::find([
'SERVICE_TYPE' => ForumCommentsServiceManager::TYPE_TASK_INFO,
])->getText($data['SERVICE_DATA']);
}
else
{
$data['POST_MESSAGE'] = Json::encode($data['AUX_DATA']);
}
}
$feed = new ForumCommentsFeed(
self::getForumId(),
[
'type' => 'TK',
'id' => $taskId,
'xml_id' => "TASK_{$taskId}",
],
$data['AUTHOR_ID']
);
// $feed->add() works with global-defined user fields
foreach ($data as $key => $value)
{
if (UtilUserField::isUFKey($key))
{
$GLOBALS[$key] = $value;
}
}
// remove attachments from system comments
$sourceValues = [];
if (array_key_exists('AUX', $data))
{
foreach ($GLOBALS as $key => $value)
{
if (strpos($key, 'UF_FORUM_MESSAGE_') === 0)
{
$sourceValues[$key] = $GLOBALS[$key];
unset($GLOBALS[$key]);
}
}
}
$addResult = $feed->add($data);
if ($addResult)
{
$result->setData($addResult);
if (isset($data['AUX']) && $data['AUX'] === 'Y' && method_exists($feed, 'send'))
{
$skipUserRead = 'N';
if ($data['UF_TASK_COMMENT_TYPE'] === CommentsInternalsComment::TYPE_EXPIRED_SOON)
{
$taskData = CTaskItem::getInstance($taskId, $data['AUTHOR_ID']);
$responsibleId = (int)$taskData['RESPONSIBLE_ID'];
$accomplices = $taskData['ACCOMPLICES'];
$accomplices = (is_array($accomplices) ? $accomplices : $accomplices->export());
$accomplices = array_map('intval', $accomplices);
if (in_array($data['AUTHOR_ID'], array_merge([$responsibleId], $accomplices), true))
{
$skipUserRead = 'Y';
}
}
$feed->send(
$addResult["ID"],
[
'URL_TEMPLATES_PROFILE_VIEW' => Option::get('socialnetwork', 'user_page', '/company/personal/') . 'user/#user_id#/',
'SKIP_USER_READ' => $skipUserRead,
'AUX_LIVE_PARAMS' => ($data['AUX_LIVE_PARAMS'] ?? []),
]
);
}
}
elseif (is_array($errors = $feed->getErrors()))
{
$resultErrors = $result->getErrors();
foreach ($errors as $error)
{
$resultErrors && $resultErrors->add(
'ACTION_FAILED_REASON',
$error->getMessage(),
Error::TYPE_FATAL,
['CODE' => $error->getCode()]
);
}
}
// restore attachments
foreach ($sourceValues as $k => $v)
{
$GLOBALS[$k] = $v;
}
return $result;
}