• Модуль: tasks
  • Путь к файлу: ~/bitrix/modules/tasks/lib/comments/task/commentposter.php
  • Класс: BitrixTasksCommentsTaskCommentPoster
  • Вызов: CommentPoster::prepareStatusComments
private function prepareStatusComments(array $oldFields, array $newFields, array $changes): array
{
	$statusComments = [];

	if (!array_key_exists('STATUS', $changes))
	{
		return $statusComments;
	}

	$creatorId = (isset($newFields['CREATED_BY']) ? (int)$newFields['CREATED_BY'] : (int)$oldFields['CREATED_BY']);
	$newStatus = (int)$newFields['STATUS'];
	$oldStatus = (int)$oldFields['REAL_STATUS'];
	$newStatus = ($newStatus === Status::NEW ? Status::PENDING : $newStatus);
	$oldStatus = ($oldStatus === Status::NEW ? Status::PENDING : $oldStatus);

	$validNewStatuses = [Status::PENDING, Status::SUPPOSEDLY_COMPLETED, Status::COMPLETED];
	if (!in_array($newStatus, $validNewStatuses, true))
	{
		return $statusComments;
	}

	$userToLinkFunction = function (int $userId) {
		return $this->parseUserToLinked($userId);
	};
	$messageKey = "COMMENT_POSTER_COMMENT_TASK_UPDATE_STATUS_{$newStatus}";
	$replace = ['#CREATOR#' => $userToLinkFunction($creatorId)];
	$liveParams = $this->prepareStatusCommentLiveParams(array_merge($oldFields, $newFields));

	if ($newStatus === Status::PENDING)
	{
		$validOldStatuses = [Status::SUPPOSEDLY_COMPLETED, Status::COMPLETED];
		if (!in_array($oldStatus, $validOldStatuses, true))
		{
			return $statusComments;
		}

		$messageKey = "{$messageKey}_RENEW";
		$taskData = [
			'CREATED_BY' => $creatorId,
			'RESPONSIBLE_ID' => (
				isset($newFields['RESPONSIBLE_ID'])
					? (int)$newFields['RESPONSIBLE_ID']
					: (int)$oldFields['RESPONSIBLE_ID']
			),
			'ACCOMPLICES' => (
				isset($newFields['ACCOMPLICES'])
					? (array)$newFields['ACCOMPLICES']
					: (array)$oldFields['ACCOMPLICES']
			),
		];
		$members = $this->getMembersForExpiredMessages($taskData);
		if (empty($members))
		{
			$messageKey = "{$messageKey}_NO_MEMBERS";
		}
		else
		{
			$replace['#MEMBERS#'] = implode(', ', array_map($userToLinkFunction, $members));
		}
	}
	else if ($newStatus === Status::COMPLETED && $oldStatus === Status::SUPPOSEDLY_COMPLETED)
	{
		$messageKey = "{$messageKey}_APPROVE";
	}
	$messageKey = $this->getLastVersionedMessageKey($messageKey);

	$statusComments[] = new Comment(
		Loc::getMessage($messageKey, $replace),
		$this->authorId,
		Comment::TYPE_STATUS,
		[[$messageKey, array_merge($replace, $liveParams)]]
	);

	return $statusComments;
}