Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
maileventhandler.php
1
<?php
9
namespace
Bitrix\Sender
;
10
11
use
Bitrix\Main\EventManager
;
12
use
Bitrix\Main\Event
;
13
use
Bitrix\Main\EventResult
;
14
15
class
MailEventHandler
16
{
17
private
static
$list = array();
18
23
public
static
function
handleEvent
(
Event
$event)
24
{
25
$eventData = $event->
getParameters
();
26
$eventData = $eventData[0];
27
28
$eventName = $eventData[
'EVENT_NAME'
];
29
$fields = is_array($eventData[
'C_FIELDS'
]) ? $eventData[
'C_FIELDS'
] : array();
30
31
if
(static::isPreventable($eventName, $fields))
32
{
33
// error
34
$result =
new
EventResult
(EventResult::ERROR);
35
}
36
else
37
{
38
// success
39
$result =
new
EventResult
(EventResult::SUCCESS);
40
}
41
42
return
$result;
43
}
44
45
public
static
function
prevent
($eventName, array $filter)
46
{
47
if
(empty(static::$list[$eventName]))
48
{
49
EventManager::getInstance()->addEventHandler(
'main'
,
'OnBeforeMailEventAdd'
, array(__CLASS__,
'handleEvent'
),
false
, 1);
50
}
51
52
static::$list[$eventName][] = $filter;
53
}
54
55
public
static
function
isPreventable
($eventName, array $fields)
56
{
57
if
(empty(static::$list[$eventName]))
58
return
false
;
59
60
$prevent =
false
;
61
62
// check each filter
63
foreach
(static::$list[$eventName] as $filter)
64
{
65
foreach
($filter as $key => $value)
66
{
67
$prevent =
true
;
68
if
(!isset($fields[$key]) || $fields[$key] != $value)
69
{
70
$prevent =
false
;
71
break
;
72
}
73
}
74
75
if
($prevent)
76
break
;
77
}
78
79
return
$prevent;
80
}
81
}
Bitrix\Main\Access\Event\EventResult
Definition
eventresult.php:13
Bitrix\Main\Event
Definition
event.php:5
Bitrix\Main\Event\getParameters
getParameters()
Definition
event.php:66
Bitrix\Main\EventManager
Definition
eventmanager.php:15
Bitrix\Main\EventResult
Definition
eventresult.php:5
Bitrix\Sender\MailEventHandler
Definition
maileventhandler.php:16
Bitrix\Sender\MailEventHandler\prevent
static prevent($eventName, array $filter)
Definition
maileventhandler.php:45
Bitrix\Sender\MailEventHandler\isPreventable
static isPreventable($eventName, array $fields)
Definition
maileventhandler.php:55
Bitrix\Sender\MailEventHandler\handleEvent
static handleEvent(Event $event)
Definition
maileventhandler.php:23
Bitrix\Sender
modules
sender
lib
maileventhandler.php
Создано системой
1.10.0