1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
CallFactory.php
См. документацию.
1<?php
2
3namespace Bitrix\Im\V2\Call;
4
5use Bitrix\Im\Call\Call;
6use Bitrix\Im\Model\CallTable;
7use Bitrix\Call\Call\PlainCall;
8use Bitrix\Call\Call\BitrixCall;
9use Bitrix\Call\Call\ConferenceCall;
10use Bitrix\Main\Type\DateTime;
11
13{
17 protected static function getProviderClass(string $provider, int $type)
18 {
20
21 return match (true)
22 {
23 $type === Call::TYPE_PERMANENT => ConferenceCall::class,
24 $provider === Call::PROVIDER_BITRIX => BitrixCall::class,
25 $provider === Call::PROVIDER_PLAIN => PlainCall::class,
26 default => Call::class
27 };
28 }
29
33 public static function createWithEntity(
34 int $type,
35 string $provider,
36 string $entityType,
37 string $entityId,
38 int $initiatorId,
39 ?string $callUuid = null,
40 ?int $scheme = null
41 ): Call
42 {
43 $providerClass = self::getProviderClass($provider, $type);
44 return $providerClass::createWithEntity($type, $provider, $entityType, $entityId, $initiatorId, $callUuid, $scheme);
45 }
46
50 public static function createWithArray(string $provider, array $fields): Call
51 {
52 $type = (int)($fields['TYPE'] ?? Call::TYPE_INSTANT);
53 $providerClass = self::getProviderClass($provider, $type);
54 return $providerClass::createWithArray($fields);
55 }
56
60 public static function getCallInstance(string $provider, array $fields): Call
61 {
62 $type = (int)($fields['TYPE'] ?? Call::TYPE_INSTANT);
63 $providerClass = self::getProviderClass($provider, $type);
64 return $providerClass::createCallInstance($fields);
65 }
66
70 public static function searchActive(int $type, string $provider, string $entityType, string $entityId): ?Call
71 {
73 if ($fields)
74 {
76
77 if ($instance->hasActiveUsers(false))
78 {
79 return $instance;
80 }
81 }
82
83 return null;
84 }
85
89 public static function searchActiveCall(int $type, string $provider, string $entityType, string $entityId): ?Call
90 {
92 if ($fields)
93 {
95
96 if ($instance->hasActiveUsers(false))
97 {
98 return $instance;
99 }
100 }
101
102 return null;
103 }
104
108 public static function searchActiveByUuid(string $provider, string $uuid): ?Call
109 {
111 if ($fields)
112 {
114 }
115
116 return null;
117 }
118
123 public static function getUserActiveCalls(int $userId, int $depthHours = 12): array
124 {
125 $date = (new DateTime())->add("-{$depthHours} hour");
126
127 $query = CallTable::query()
128 ->addSelect('*')
129 ->whereIn('STATE', [\Bitrix\Im\Call\Call::STATE_NEW, \Bitrix\Im\Call\Call::STATE_INVITING])
130 ->where('START_DATE', '>=', $date)
131 ->where('CALL_USER.USER_ID', $userId)
132 ;
133 $activeCalls = $query->exec()->fetchAll();
134
135 return $activeCalls ?: [];
136 }
137
142 public static function hasUserActiveCalls(int $userId, int $depthHours = 12): bool
143 {
144 $date = (new DateTime())->add("-{$depthHours} hour");
145
146 $query = CallTable::query()
147 ->addSelect('ID')
148 ->whereIn('STATE', [\Bitrix\Im\Call\Call::STATE_NEW, \Bitrix\Im\Call\Call::STATE_INVITING])
149 ->where('START_DATE', '>=', $date)
150 ->where('CALL_USER.USER_ID', $userId)
151 ->whereIn('CALL_USER.STATE', [\Bitrix\Im\Call\CallUser::STATE_READY, \Bitrix\Im\Call\CallUser::STATE_CALLING])
152 ->setLimit(1)
153 ;
154 $activeCall = $query->exec()->fetchAll();
155
156 return (bool)$activeCall;
157 }
158
166 protected static function search(int $type, string $provider, string $entityType, string $entityId): ?array
167 {
168 $query = CallTable::query()
169 ->addSelect('*')
170 ->where('TYPE', $type)
171 ->where('PROVIDER', $provider)
172 ->where('ENTITY_TYPE', $entityType)
173 ->where('ENTITY_ID', $entityId)
174 ->whereNot('STATE', Call::STATE_FINISHED)
175 ->whereNull('END_DATE')
176 ->addFilter('>START_DATE', (new DateTime)->add('-12 hours'))
177 ->setOrder(['ID' => 'DESC'])
178 ->setLimit(1)
179 ;
180
181 $callFields = $query->exec()->fetch();
182
183 return $callFields ?: null;
184 }
185
186 protected static function searchByUuid(string $uuid): ?array
187 {
188 $callFields = CallTable::query()
189 ->addSelect("*")
190 ->where("UUID", $uuid)
191 ->setLimit(1)
192 ->exec()
193 ->fetch()
194 ;
195
196 return $callFields ?: null;
197 }
198}
$type
Определения options.php:106
if(!Loader::includeModule('messageservice')) $provider
Определения callback_ednaruimhpx.php:21
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
Определения call.php:24
static searchActiveCall(int $type, string $provider, string $entityType, string $entityId)
Определения CallFactory.php:89
static hasUserActiveCalls(int $userId, int $depthHours=12)
Определения CallFactory.php:142
static getCallInstance(string $provider, array $fields)
Определения CallFactory.php:60
static createWithEntity(int $type, string $provider, string $entityType, string $entityId, int $initiatorId, ?string $callUuid=null, ?int $scheme=null)
Определения CallFactory.php:33
static getProviderClass(string $provider, int $type)
Определения CallFactory.php:17
static search(int $type, string $provider, string $entityType, string $entityId)
Определения CallFactory.php:166
static createWithArray(string $provider, array $fields)
Определения CallFactory.php:50
static searchActiveByUuid(string $provider, string $uuid)
Определения CallFactory.php:108
static searchActive(int $type, string $provider, string $entityType, string $entityId)
Определения CallFactory.php:70
static getUserActiveCalls(int $userId, int $depthHours=12)
Определения CallFactory.php:123
static searchByUuid(string $uuid)
Определения CallFactory.php:186
static includeModule($moduleName)
Определения loader.php:67
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$query
Определения get_search.php:11
$entityId
Определения payment.php:4
$instance
Определения ps_b24_final.php:14
$fields
Определения yandex_run.php:501