Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
Base.php
1
<?php
2
3
namespace
Bitrix\MessageService\Restriction
;
4
5
use
Bitrix\Main\Application
;
6
use
Bitrix\Main\Config\Option
;
7
use
Bitrix\Main\Engine\CurrentUser
;
8
use
Bitrix\MessageService\Internal\Entity\RestrictionTable
;
9
use
Bitrix\MessageService\Message
;
10
11
abstract
class
Base
12
{
13
abstract
public
function
getEntityId
(): string;
14
abstract
protected
function
getOptionLimitName
(): string;
15
abstract
protected
function
getEntity
(): string;
16
abstract
protected
function
getDefaultLimit
(): int;
17
18
protected
Message
$message
;
19
protected
int
$counter
;
20
protected
int
$limit
= 0;
22
protected
array
$additionalParams
= [];
23
24
25
public
function
__construct
(
Message
$message
)
26
{
27
$this->message =
$message
;
28
$this->limit = $this->initLimit();
29
}
30
31
public
function
setCounter
(
int
$counter
):
Base
32
{
33
$this->counter =
$counter
;
34
35
return
$this;
36
}
37
42
public
function
setAdditionalParams
(array
$additionalParams
):
Base
43
{
44
$this->additionalParams =
$additionalParams
;
45
46
return
$this;
47
}
48
49
public
function
canUse
(): bool
50
{
51
return
$this->limit > 0;
52
}
53
54
public
function
lock
(): void
55
{
56
Application::getConnection
()->lock($this->
getEntityId
(), 60);
57
}
58
59
public
function
unlock
(): void
60
{
61
Application::getConnection
()->unlock($this->
getEntityId
());
62
}
63
64
public
function
isCanSend
(): bool
65
{
66
if
(isset($this->counter))
67
{
68
return
$this->counter <
$this->limit
;
69
}
70
71
return
true
;
72
}
73
74
public
function
increase
(): bool
75
{
76
if
(isset($this->counter))
77
{
78
return
$this->
updateCounter
();
79
}
80
81
$this->
insertCounter
();
82
83
return
true
;
84
}
85
86
protected
function
updateCounter
(): bool
87
{
88
return
RestrictionTable::updateCounter($this->
getEntityId
(), $this->limit);
89
}
90
91
protected
function
insertCounter
(): void
92
{
93
RestrictionTable::insertCounter($this->
getEntityId
());
94
}
95
96
private
function
initLimit(): int
97
{
98
return
(
int
)Option::get(
'messageservice'
, $this->
getOptionLimitName
(), $this->
getDefaultLimit
());
99
}
100
101
public
function
log
()
102
{
103
if
(Option::get(
'messageservice'
,
'event_log_message_send'
,
'N'
) ===
'Y'
)
104
{
105
$restrictionType = mb_strtoupper($this->
getOptionLimitName
());
106
$userId = CurrentUser::get()->getId() ?: $this->message->getAuthorId();
107
$phone = $this->message->getTo();
108
109
$description =
"Restriction: $restrictionType. Phone: $phone. CurrentCounter: $this->counter. Limit: $this->limit."
;
110
111
\CEventLog::Log(
112
'INFO'
,
113
'MESSAGE_BLOCK'
,
114
'messageservice'
,
115
$userId,
116
$description
117
);
118
}
119
}
120
121
}
Bitrix\Main\Application
Definition
application.php:28
Bitrix\Main\Application\getConnection
static getConnection($name="")
Definition
application.php:611
Bitrix\Main\Config\Option
Definition
option.php:15
Bitrix\Main\Engine\CurrentUser
Definition
currentuser.php:8
Bitrix\MessageService\Internal\Entity\RestrictionTable
Definition
restrictiontable.php:31
Bitrix\MessageService\Message
Definition
message.php:18
Bitrix\MessageService\Restriction\Base
Definition
Base.php:12
Bitrix\MessageService\Restriction\Base\getEntityId
getEntityId()
Bitrix\MessageService\Restriction\Base\insertCounter
insertCounter()
Definition
Base.php:91
Bitrix\MessageService\Restriction\Base\$limit
int $limit
Definition
Base.php:20
Bitrix\MessageService\Restriction\Base\getEntity
getEntity()
Bitrix\MessageService\Restriction\Base\getDefaultLimit
getDefaultLimit()
Bitrix\MessageService\Restriction\Base\lock
lock()
Definition
Base.php:54
Bitrix\MessageService\Restriction\Base\increase
increase()
Definition
Base.php:74
Bitrix\MessageService\Restriction\Base\getOptionLimitName
getOptionLimitName()
Bitrix\MessageService\Restriction\Base\canUse
canUse()
Definition
Base.php:49
Bitrix\MessageService\Restriction\Base\log
log()
Definition
Base.php:101
Bitrix\MessageService\Restriction\Base\__construct
__construct(Message $message)
Definition
Base.php:25
Bitrix\MessageService\Restriction\Base\$additionalParams
array $additionalParams
Definition
Base.php:22
Bitrix\MessageService\Restriction\Base\isCanSend
isCanSend()
Definition
Base.php:64
Bitrix\MessageService\Restriction\Base\setAdditionalParams
setAdditionalParams(array $additionalParams)
Definition
Base.php:42
Bitrix\MessageService\Restriction\Base\$message
Message $message
Definition
Base.php:18
Bitrix\MessageService\Restriction\Base\updateCounter
updateCounter()
Definition
Base.php:86
Bitrix\MessageService\Restriction\Base\$counter
int $counter
Definition
Base.php:19
Bitrix\MessageService\Restriction\Base\unlock
unlock()
Definition
Base.php:59
Bitrix\MessageService\Restriction\Base\setCounter
setCounter(int $counter)
Definition
Base.php:31
Bitrix\MessageService\Restriction
Definition
Base.php:3
modules
messageservice
lib
Restriction
Base.php
Создано системой
1.10.0