Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
ChatTypeFilter.php
1<?php
2
4
9
10class ChatTypeFilter extends Base
11{
12 private array $types;
13 private bool $isAllowed;
14
15 public function __construct(array $types, bool $isAllowed = true)
16 {
17 parent::__construct();
18 $this->types = $types;
19 $this->isAllowed = $isAllowed;
20 }
21
22 public function onBeforeAction(Event $event)
23 {
24 $chat = $this->getAction()->getArguments()['chat'] ?? null;
25 if ($this->isAllowed)
26 {
27 foreach ($this->types as $type)
28 {
29 if ($chat instanceof $type)
30 {
31 return null;
32 }
33 }
34
36
37 return new EventResult(EventResult::ERROR, null, null, $this);
38 }
39
40 foreach ($this->types as $type)
41 {
42 if ($chat instanceof $type)
43 {
45
46 return new EventResult(EventResult::ERROR, null, null, $this);
47 }
48 }
49
50 return null;
51 }
52}
__construct(array $types, bool $isAllowed=true)