• Модуль: tasks
  • Путь к файлу: ~/bitrix/modules/tasks/lib/comments/task/commentposter.php
  • Класс: BitrixTasksCommentsTaskCommentPoster
  • Вызов: CommentPoster::prepareCommentsOnTaskAdd
private function prepareCommentsOnTaskAdd(array $taskData): array
{
	$creatorId = (int)$taskData['CREATED_BY'];
	$responsibleId = (int)$taskData['RESPONSIBLE_ID'];
	$accomplices = (array)$taskData['ACCOMPLICES'];
	$auditors = (array)$taskData['AUDITORS'];

	if (in_array($this->authorId, $accomplices, true))
	{
		unset($accomplices[array_search($this->authorId, $accomplices, true)]);
	}
	if (in_array($this->authorId, $auditors, true))
	{
		unset($auditors[array_search($this->authorId, $auditors, true)]);
	}

	$addComments = [];

	if (
		$this->authorId === $creatorId
		&& $creatorId === $responsibleId
		&& empty($accomplices)
		&& empty($auditors)
	)
	{
		return $addComments;
	}

	if (!($addComment = $this->getCommentByType(Comment::TYPE_ADD)))
	{
		$addComment = new Comment('', $this->authorId, Comment::TYPE_ADD);
		$addComment->deletePart('main');
		$addComments[] = $addComment;
	}

	$userToLinkFunction = function (int $userId) {
		return $this->parseUserToLinked($userId);
	};

	if (
		$creatorId !== $responsibleId
		&&
		(
			$taskData['TASK_CONTROL'] === 'Y'
			|| $taskData['TASK_CONTROL'] === true
		)
	)
	{
		$messageKey = 'COMMENT_POSTER_COMMENT_TASK_UPDATE_CHANGES_CONTROL';
		$messageKey = $this->getLastVersionedMessageKey($messageKey);
		$addComment->addPart('control', Loc::getMessage($messageKey), [[$messageKey, []]]);
	}
	if (!$taskData['DEADLINE'])
	{
		$messageKey = 'COMMENT_POSTER_COMMENT_TASK_UPDATE_CHANGES_DEADLINE';
		$messageKey = $this->getLastVersionedMessageKey($messageKey);
		$addComment->addPart('deadline', Loc::getMessage($messageKey), [[$messageKey, []]]);
	}
	if ($this->authorId !== $creatorId)
	{
		$partName = 'creator';
		$messageKey = 'COMMENT_POSTER_COMMENT_TASK_UPDATE_CHANGES_FIELD_CREATED_BY';
		$messageKey = $this->getLastVersionedMessageKey($messageKey);
		$replace = ['#NEW_VALUE#' => $this->parseUserToLinked($creatorId)];
		$addComment->addPart($partName, Loc::getMessage($messageKey, $replace), [[$messageKey, $replace]]);
	}
	if ($this->authorId !== $responsibleId)
	{
		$partName = 'responsible';
		$messageKey = 'COMMENT_POSTER_COMMENT_TASK_UPDATE_CHANGES_FIELD_RESPONSIBLE_ID';
		$messageKey = $this->getLastVersionedMessageKey($messageKey);
		$replace = ['#NEW_VALUE#' => $this->parseUserToLinked($responsibleId)];
		$addComment->addPart($partName, Loc::getMessage($messageKey, $replace), [[$messageKey, $replace]]);
	}
	if (!empty($accomplices))
	{
		$partName = 'accomplices';
		$messageKey = 'COMMENT_POSTER_COMMENT_TASK_UPDATE_CHANGES_FIELD_ACCOMPLICES';
		$messageKey = $this->getLastVersionedMessageKey($messageKey);
		$replace = ['#NEW_VALUE#' => implode(', ', array_map($userToLinkFunction, $accomplices))];
		$addComment->addPart($partName, Loc::getMessage($messageKey, $replace), [[$messageKey, $replace]]);
	}
	if (!empty($auditors))
	{
		$partName = 'auditors';
		$messageKey = 'COMMENT_POSTER_COMMENT_TASK_UPDATE_CHANGES_FIELD_AUDITORS';
		$messageKey = $this->getLastVersionedMessageKey($messageKey);
		$replace = ['#NEW_VALUE#' => implode(', ', array_map($userToLinkFunction, $auditors))];
		$addComment->addPart($partName, Loc::getMessage($messageKey, $replace), [[$messageKey, $replace]]);
	}

	return $addComments;
}