• Модуль: imopenlines
  • Путь к файлу: ~/bitrix/modules/imopenlines/lib/controller/session/groupactions.php
  • Класс: BitrixImOpenLinesControllerSessionGroupActions
  • Вызов: GroupActions::close
protected function close($fields, $spam = false): array
{
	$result = [];

	$this->startTimer();

	$sessions = $this->getAccessSession($fields);

	// from previous step
	if (isset($fields['totalItems']))
	{
		$this->declareTotalItems((int)$fields['totalItems']);
	}
	else
	{
		$this->declareTotalItems(count($sessions));
	}
	if (isset($fields['processedItems']))
	{
		$this->declareProcessedItems((int)$fields['processedItems']);
	}

	if (!empty($sessions))
	{
		$currentUserId = SecurityHelper::getCurrentUserId();

		foreach ($sessions as $session)
		{
			$chat = new Chat($session['CHAT_ID']);
			if($spam === true)
			{
				$resultFinishChat = $chat->markSpamAndFinish($currentUserId);
			}
			else
			{
				$resultFinishChat = $chat->finish($currentUserId);
			}

			if ($resultFinishChat->isSuccess())
			{
				$result[] = $session['ID'];
			}

			if ($this->hasTimeLimitReached())
			{
				break;
			}
		}
	}

	$this->incrementProcessedItems(count($result));

	if (!$this->hasTimeLimitReached() || empty($sessions))
	{
		$this->declareProcessDone();
	}

	return $this->preformProcessAnswer([
		'sessions' => $result,
	]);
}