Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
limiter.php
1<?php
10
13use Bitrix\Bitrix24\MailCounter as B24MailCounter;
14
19
20Loc::loadMessages(__FILE__);
21
27{
29 protected static $limiters;
30
36 public static function getList()
37 {
38 if (!Service::isCloud())
39 {
40 return array();
41 }
42
43 if (empty(self::$limiters))
44 {
45 self::$limiters = array(
46 self::getMonthly(),
47 self::getDaily(),
48 );
49 }
50
51 return self::$limiters;
52 }
53
59 public static function getMonthlyLimitPercentage()
60 {
61 $value = (int) Option::get('sender', '~mail_month_limit_percent', 90);
62 $value = $value < 10 ? 10 : $value;
63 $value = $value > 100 ? 100 : $value;
64
65 return $value;
66 }
67
74 public static function setMonthlyLimitPercentage($value)
75 {
76 $value = (int) $value;
77 $value = $value < 10 ? 10 : $value;
78 $value = $value > 100 ? 100 : $value;
79
80 Option::set('sender', '~mail_month_limit_percent', $value);
81 }
82
88 public static function getMonthly()
89 {
90 $counter = new B24MailCounter();
91 $limiter = Transport\CountLimiter::create()
92 ->withName('mail_per_month')
93 ->withLimit($counter->getLimit())
94 ->withUnit("1 " . Transport\iLimiter::MONTHS)
95 ->withCurrent(
96 function () use ($counter)
97 {
98 return $counter->getMonthly();
99 }
100 )
101 ->setParameter(
102 'globalHelpUri',
103 'javascript:top.BX.Helper.show("redirect=detail&code=6904325")'
104 )
105 ->setParameter('percentage', self::getMonthlyLimitPercentage());
106
108 {
109 $limiter->setParameter('setupUri', 'javascript: top.BX.Sender.B24License.showMailLimitPopup();');
110 }
111
112 return $limiter;
113 }
114
120 public static function getEmailMonthly($email)
121 {
122 $counter = new SenderSendCounter();
123 $limiter = Transport\CountLimiter::create()
124 ->withName('mail_per_email_per_day')
125 ->withLimit(Sender::getEmailLimit($email))
126 ->withUnit("1 " . Transport\iLimiter::DAYS)
127 ->withCurrent(
128 function () use ($counter, $email)
129 {
130 return Sender::getEmailLimit($email) === null ? -1 : $counter->get($email);
131 }
132 )
133 ->setHidden(true)
134 ->setParameter(
135 'globalHelpUri',
136 'javascript:top.BX.Helper.show("redirect=detail&code=6904325")'
137 );
138
140 {
141 $limiter->setParameter('setupUri', 'javascript: top.BX.Sender.B24License.showMailLimitPopup();');
142 }
143
144 return $limiter;
145 }
146
152 protected static function getDaily()
153 {
154 $counter = new DailyLimit();
155 return Transport\CountLimiter::create()
156 ->withName('mail_per_day')
157 ->withLimit($counter->getLimit())
158 ->withUnit("1 " . Transport\iLimiter::DAYS)
159 ->withCurrent(
160 function () use ($counter)
161 {
162 return $counter->getCurrent();
163 }
164 )
165 ->setParameter('setupUri', 'javascript:top.BX.Helper.show("redirect=detail&code=6846227")')
166 ->setParameter('setupCaption', Loc::getMessage('SENDER_INTEGRATION_BITRIX24_LIMITER_DAILY_DETAILS'));
167 }
168
169
170 public static function getPortalVerification(): Transport\iLimiter
171 {
172 $verify = new PortalVerifyLimit();
173 return Transport\CountLimiter::create()
174 ->withName('portal_verify')
175 ->withLimit($verify->getLimit())
176 // ->withUnit("1 " . Transport\iLimiter::DAYS)
177 ->setHidden(true)
178 ->withCurrent(
179 function () use ($verify)
180 {
181 return $verify->getCurrent();
182 }
183 )
184 ->setParameter('setupUri', 'javascript:top.BX.Helper.show("redirect=detail&code=14406430")')
185 ->setParameter('setupCaption', Loc::getMessage('SENDER_INTEGRATION_BITRIX24_LIMITER_DAILY_DETAILS'));
186 }
187}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29