Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
limiter.php
1
<?php
9
namespace
Bitrix\Sender\Integration\Bitrix24\Limitation
;
10
11
use
Bitrix\Main\Config\Option
;
12
use
Bitrix\Main\Localization\Loc
;
13
use Bitrix\Bitrix24\MailCounter as B24MailCounter;
14
15
use
Bitrix\Main\Mail\Sender
;
16
use
Bitrix\Main\Mail\SenderSendCounter
;
17
use
Bitrix\Sender\Integration\Bitrix24\Service
;
18
use
Bitrix\Sender\Transport
;
19
20
Loc::loadMessages
(__FILE__);
21
26
class
Limiter
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
107
if
(!
Service::isLicenceTop
())
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
139
if
(!
Service::isLicenceTop
())
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
}
Bitrix\Main\Config\Option
Definition
option.php:15
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\loadMessages
static loadMessages($file)
Definition
loc.php:64
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Main\Mail\Sender
Definition
sender.php:13
Bitrix\Main\Mail\SenderSendCounter
Definition
sendersendcounter.php:14
Bitrix\Sender\Integration\Bitrix24\Limitation\DailyLimit
Definition
dailylimit.php:21
Bitrix\Sender\Integration\Bitrix24\Limitation\Limiter
Definition
limiter.php:27
Bitrix\Sender\Integration\Bitrix24\Limitation\Limiter\setMonthlyLimitPercentage
static setMonthlyLimitPercentage($value)
Definition
limiter.php:74
Bitrix\Sender\Integration\Bitrix24\Limitation\Limiter\getMonthly
static getMonthly()
Definition
limiter.php:88
Bitrix\Sender\Integration\Bitrix24\Limitation\Limiter\$limiters
static $limiters
Definition
limiter.php:29
Bitrix\Sender\Integration\Bitrix24\Limitation\Limiter\getEmailMonthly
static getEmailMonthly($email)
Definition
limiter.php:120
Bitrix\Sender\Integration\Bitrix24\Limitation\Limiter\getDaily
static getDaily()
Definition
limiter.php:152
Bitrix\Sender\Integration\Bitrix24\Limitation\Limiter\getMonthlyLimitPercentage
static getMonthlyLimitPercentage()
Definition
limiter.php:59
Bitrix\Sender\Integration\Bitrix24\Limitation\Limiter\getPortalVerification
static getPortalVerification()
Definition
limiter.php:170
Bitrix\Sender\Integration\Bitrix24\Limitation\Limiter\getList
static getList()
Definition
limiter.php:36
Bitrix\Sender\Integration\Bitrix24\Limitation\PortalVerifyLimit
Definition
portalverifylimit.php:5
Bitrix\Sender\Integration\Bitrix24\Service
Definition
service.php:30
Bitrix\Sender\Integration\Bitrix24\Service\isCloud
static isCloud()
Definition
service.php:308
Bitrix\Sender\Integration\Bitrix24\Service\isLicenceTop
static isLicenceTop()
Definition
service.php:390
Bitrix\Sender\Transport\iLimiter
Definition
ilimiter.php:16
Bitrix\Sender\Transport\iLimiter\MONTHS
const MONTHS
Definition
ilimiter.php:17
Bitrix\Sender\Transport\iLimiter\DAYS
const DAYS
Definition
ilimiter.php:18
Bitrix\Sender\Integration\Bitrix24\Limitation
Definition
dailylimit.php:9
Bitrix\Sender\Transport
Definition
adapter.php:9
modules
sender
lib
integration
bitrix24
limitation
limiter.php
Создано системой
1.10.0