8namespace Bitrix\Sender\Transport;
10use Bitrix\Main\ArgumentException;
11use Bitrix\Main\Config\Option;
12use Bitrix\Main\SystemException;
13use Bitrix\Main\Type\DateTime;
14use Bitrix\Main\Localization\Loc;
16Loc::loadMessages(__FILE__);
31 private $parameters =
array();
48 private $hidden =
false;
60 private static function parseUnit($unit)
62 $unit = explode(
' ', $unit);
63 $num = (int) $unit[0];
64 $unit = $unit[1] ??
'';
80 $parsed = self::parseUnit($unit);
82 switch ($parsed[
'unit'])
93 $interval = 86400 * 31;
102 return $interval * $parsed[
'num'];
132 $this->caption = $caption;
144 $this->limit = (int) $limit;
156 $this->interval = (int) $interval;
181 $this->unitName = $unitName;
194 if (!is_callable($callable))
199 $this->current = $callable;
220 $limit = (int) $this->limit;
222 if ($percentage > 0 && $percentage <= 100)
224 $limit *= $percentage / 100;
249 return $this->unitName;
252 $parsed = self::parseUnit($this->unit);
253 switch ($parsed[
'unit'])
274 $formatted =
\FormatDate($format, $this->getCurrentTimestamp() - $this->interval);
275 if (mb_substr($formatted, 0, 2) ==
'1 ')
277 $formatted = mb_substr($formatted, 2);
280 return Loc::getMessage(
'SENDER_TRANSPORT_COUNT_LIMIT_UNIT_DATE_AT') .
' ' . $formatted;
290 return $this->caption;
310 return Loc::getMessage(
311 'SENDER_TRANSPORT_COUNT_LIMIT_TEXT_MONTHLY',
313 '%current%' => number_format($this->
getAvailable(), 0,
'.',
' '),
314 '%limit%' => number_format($this->
getLimit(), 0,
'.',
' '),
316 '%setupCaption%' => $this->
getParameter(
'setupCaption'),
329 return isset($this->parameters[$name]) ? $this->parameters[$name] :
null;
341 $this->parameters[$name] = $value;
356 $isNewPeriod = ($this->getCurrentTimestamp() - $this->
getTimestamp()) >= $this->interval;
366 $this->setCurrent(0);
367 $this->setTimestamp($this->getCurrentTimestamp());
374 'SENDER_TRANSPORT_COUNT_LIMIT_EXCEEDED',
381 $this->setCurrent($current);
395 return (!$available || $available < 0) ? 0 : $available;
405 if (is_callable($this->current))
407 return call_user_func($this->current);
410 return (
int) Option::get(
'main', $this->getCounterOptionName(), 0);
419 private function setCurrent($value)
421 Option::set(
'main', $this->getCounterOptionName(), $value);
431 private function setTimestamp($value)
433 Option::set(
'main', $this->getDateOptionName(), $value);
444 return (
int) Option::get(
'main', $this->getDateOptionName(), 0);
447 private function getCurrentTimestamp()
450 return $dateTime->getTimestamp();
453 private function getCounterOptionName()
458 private function getDateOptionName()
470 $this->hidden = $hidden;
478 return $this->hidden;
setParameter($name, $value)
static getUnitInterval($unit)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
FormatDate($format="", $timestamp=false, $now=false, ?string $languageId=null)
if(!function_exists("bx_hmac")) $amount