Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
maileventhandler.php
1<?php
9namespace Bitrix\Sender;
10
14
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}
static prevent($eventName, array $filter)
static isPreventable($eventName, array $fields)