• Модуль: tasks
  • Путь к файлу: ~/bitrix/modules/tasks/lib/rest/controllers/task/result.php
  • Класс: BitrixTasksRestControllersTaskResult
  • Вызов: Result::addFromCommentAction
public function addFromCommentAction(int $commentId)
{
	if (!$commentId)
	{
		$this->errorCollection->add([new Error('Comment not found.')]);
		return null;
	}

	$userId = $this->getUserId();
	if (!$userId)
	{
		$this->errorCollection->add([new Error('Access denied.')]);
		return null;
	}

	if (
		!Loader::includeModule('tasks')
		|| !Loader::includeModule('forum')
	)
	{
		$this->errorCollection->add([new Error('Module not loaded.')]);
		return null;
	}

	$comment = BitrixForumMessageTable::getById($commentId)->fetchObject();
	if (!$comment)
	{
		$this->errorCollection->add([new Error('Comment not found.')]);
		return null;
	}

	$taskId = (int) str_replace('TASK_', '', $comment->getXmlId());

	if (
		(
			!UserModel::createFromId($userId)->isAdmin()
			&& $comment->getAuthorId() !== $userId
		)
		|| !TaskAccessController::can($userId, ActionDictionary::ACTION_TASK_READ, $taskId)
	)
	{
		$this->errorCollection->add([new Error('Access denied.')]);
		return null;
	}

	$isExists = ResultTable::GetList([
		'filter' => [
			'=COMMENT_ID' => $commentId,
			'=STATUS' => ResultTable::STATUS_OPENED,
		],
		'limit' => 1,
	])->fetchObject();

	if ($isExists)
	{
		$this->errorCollection->add([new Error('Result already exists.')]);
		return null;
	}

	$result = (new ResultManager($userId))->createFromComment($commentId, false);
	return $result->toArray();
}