TransportSms::getLimiters

  1. Bitrix24 API (v. 23.675.0)
  2. sender
  3. TransportSms
  4. getLimiters
  • Модуль: sender
  • Путь к файлу: ~/bitrix/modules/sender/lib/integration/messageservice/sms/transportsms.php
  • Класс: Bitrix\Sender\Integration\MessageService\Sms\TransportSms
  • Вызов: TransportSms::getLimiters
public function getLimiters(Message\iBase $message = null)
{
	if (!empty($this->limiters))
	{
		$this->limiters[] = Transport\TimeLimiter::create()
			->withLetter($message);

		return $this->limiters;
	}

	/** @var MessageSms $message */
	$smsSender = null;
	if ($message)
	{
		if ($message instanceof Message\Adapter)
		{
			$smsSender = $message->getConfiguration()->getOption('SENDER')->getValue();
		}
		else
		{
			$smsSender = $message->getSmsSender();
		}
	}

	$this->limiters = [];
	$limitList = Service::getDailyLimits();
	$senderNames = Service::getSenderNames();
	foreach ($limitList as $limitSender => $limitData)
	{
		if ($smsSender && $smsSender !== $limitSender)
		{
			continue;
		}
		if (empty($limitData['limit']))
		{
			continue;
		}

		$this->limiters[] = Transport\CountLimiter::create()
			->withName('sms_per_day_' . $limitSender)
			->withCaption($senderNames[$limitSender])
			->withLimit($limitData['limit'])
			->withCurrent(
				function () use ($limitSender)
				{
					$limitList = Service::getDailyLimits();
					if (!isset($limitList[$limitSender]))
					{
						return 0;
					}

					if (!isset($limitList[$limitSender]['current']))
					{
						return 0;
					}

					return $limitList[$limitSender]['current'];
				}

			)
			->withUnit("1 " . Transport\iLimiter::DAYS)
			->setParameter('setupUri', Service::getLimitsUrl());
	}

	$this->limiters[] = Transport\TimeLimiter::create()
		->withLetter($message);

	return $this->limiters;
}

Добавить комментарий