Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
abstractentity.php
1<?php
2
4
6
7abstract class AbstractEntity
8{
9 protected $entityId;
10 protected $initiatorId;
12 protected $call;
13
14 public function __construct(Call $call, $entityId)
15 {
16 $this->call = $call;
17 $this->entityId = $entityId;
18 $this->initiatorId = $call->getInitiatorId();
19 }
20
21 public function getEntityId($currentUserId = 0)
22 {
23 return $this->entityId;
24 }
25
29 public function getCall()
30 {
31 return $this->call;
32 }
33
37 public function setCall(Call $call)
38 {
39 $this->call = $call;
40 }
41
42 abstract public function getEntityType();
43
44 abstract public function canStartCall(int $userId): bool;
45
46 abstract public function checkAccess(int $userId): bool;
47
48 abstract public function getChatId();
49
50 abstract public function getUsers();
51
52 abstract public function getName($currentUserId);
53
54 // todo: remove when the calls are supported in the mobile
55 abstract public function onCallCreate(): bool;
56
57 abstract public function onUserAdd($userId): bool;
58
59 abstract public function onExistingUserInvite($userId): bool;
60
61 abstract public function onStateChange($state, $prevState);
62
63 public function toArray($currentUserId = 0)
64 {
65 if($currentUserId == 0)
66 {
67 $currentUserId = $this->initiatorId;
68 }
69 return [
70 'type' => $this->getEntityType(),
71 'id' => $this->getEntityId($currentUserId),
72 'name' => $this->getName($currentUserId)
73 ];
74 }
75
76 protected function getCurrentUserId()
77 {
78 global $USER;
79
80 return (int)$USER->getId();
81 }
82}