Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
basepush.php
1<?php
2
4
5abstract class BasePush
6{
7 public const EVENT_ADDED = 'ADDED';
8 public const EVENT_UPDATED = 'UPDATED';
9 public const EVENT_DELETED = 'DELETED';
10
11 abstract protected static function getCommand(): string;
12
13 public static function subscribeUser(int $userId): void
14 {
15 (new PushWorker())->subscribe($userId, static::getCommand());
16 }
17
18 public static function pushAdded(mixed $itemId, ...$userIds): void
19 {
20 static::pushLastEvent(static::EVENT_ADDED, $itemId, $userIds);
21 }
22
23 public static function pushUpdated(mixed $itemId, ...$userIds): void
24 {
25 static::pushLastEvent(static::EVENT_UPDATED, $itemId, $userIds);
26 }
27
28 public static function pushDeleted(mixed $itemId, ...$userIds): void
29 {
30 static::pushLastEvent(static::EVENT_DELETED, $itemId, $userIds);
31 }
32
33 public static function pushLastEvent(string $eventName, mixed $itemId, array $userIds): void
34 {
35 $userIds = array_unique(\CBPHelper::flatten($userIds));
36 if (empty($userIds))
37 {
38 return;
39 }
40
41 $command = static::getCommand();
42
43 $push = new PushWorker();
44 $push->sendLast(
45 "{$command}-{$itemId}-{$eventName}",
46 $command,
47 [
48 'eventName' => $eventName,
49 'items' => [
50 [
51 'id' => $itemId,
52 ],
53 ],
54 ],
55 $userIds,
56 );
57 }
58}
static pushDeleted(mixed $itemId,... $userIds)
Definition basepush.php:28
static pushLastEvent(string $eventName, mixed $itemId, array $userIds)
Definition basepush.php:33
static pushAdded(mixed $itemId,... $userIds)
Definition basepush.php:18
static pushUpdated(mixed $itemId,... $userIds)
Definition basepush.php:23