Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
event.php
1<?php
3
7
8Loc::loadMessages(__FILE__);
9
10class Event extends Main\Event
11{
13 protected $entity = null;
14
15 protected static $catalogHandlerExist = [];
16
17 private static $keys = ['fields', 'external_fields', 'actions'];
18
19 public function __construct(Entity $entity, string $type, array $parameters = [])
20 {
21 $this->entity = $entity;
22
23 parent::__construct('catalog', self::makeEventName(get_class($this->entity), $type), $parameters);
24 }
25
33 public function getErrors(Main\Result $result): bool
34 {
35 $hasErrors = false;
36
38 foreach($this->getResults() as $eventResult)
39 {
40 if ($eventResult->getType() === Main\Entity\EventResult::ERROR)
41 {
42 $hasErrors = true;
43 $result->addErrors($eventResult->getErrors());
44 }
45 }
46 return $hasErrors;
47 }
48
55 public function mergeData(array &$data): void
56 {
58 foreach($this->getResults() as $eventResult)
59 {
60 $removed = $eventResult->getUnset();
61 foreach (self::$keys as $index)
62 {
63 if (empty($removed[$index]))
64 continue;
65 foreach ($removed[$index] as $key)
66 unset($data[$index][$key]);
67 unset($key);
68 }
69 unset($removed);
70 $modified = $eventResult->getModified();
71 foreach (self::$keys as $index)
72 {
73 if (empty($modified[$index]))
74 continue;
75 $data[$index] = array_merge($data[$index], $modified[$index]);
76 }
77 unset($modified);
78 }
79 }
80
88 public static function existEventHandlers(Entity $entity, string $eventName): bool
89 {
90 return static::existEventHandlersById(self::makeEventName(get_class($entity), $eventName));
91 }
92
98 public static function makeEventName(string $class, string $eventName): string
99 {
100 return $class.'::'.$eventName;
101 }
102
109 public static function existEventHandlersById(string $id): bool
110 {
111 if (!isset(self::$catalogHandlerExist[$id]))
112 {
113 $eventManager = Main\EventManager::getInstance();
114 $eventsList = $eventManager->findEventHandlers(
115 'catalog', $id
116 );
117 self::$catalogHandlerExist[$id] = !empty($eventsList);
118 unset($eventsList, $eventManager);
119 }
120 return self::$catalogHandlerExist[$id];
121 }
122}
__construct(Entity $entity, string $type, array $parameters=[])
Definition event.php:19
static makeEventName(string $class, string $eventName)
Definition event.php:98
static existEventHandlersById(string $id)
Definition event.php:109
static existEventHandlers(Entity $entity, string $eventName)
Definition event.php:88
static loadMessages($file)
Definition loc.php:64