Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
channel.php
1<?php
2namespace Bitrix\Pull;
3
4
5class Channel
6{
7 const TYPE_PRIVATE = 'private';
8 const USER_SELF = null;
9
10 public static function getPublicId($params)
11 {
12 $config['USERS'] = $params['USER_ID'] ?? self::USER_SELF;
13 $config['TYPE'] = $params['TYPE'] ?? self::TYPE_PRIVATE;
14 $config['JSON'] = isset($params['JSON']) && $params['JSON'] == 'Y';
15
16 $result = self::getPublicIds($config);
17 if ($result)
18 {
19 $result = array_shift($result);
20 }
21
22 return $result;
23 }
24
25 public static function getPublicIds($params = [])
26 {
27 if (!\CPullOptions::GetQueueServerStatus() || \CPullOptions::GetQueueServerVersion() < 4)
28 return false;
29
30 $users = $params['USERS'] ?? self::USER_SELF;
31 $type = $params['TYPE'] ?? self::TYPE_PRIVATE;
32 $returnJson = $params['JSON']? true: false;
33
34 $userList = [];
35 if (is_array($users))
36 {
37 foreach ($users as $userId)
38 {
39 $userId = intval($userId);
40 if ($userId > 0)
41 {
42 $userList[$userId] = $userId;
43 }
44 }
45 }
46 else
47 {
48 if ($users == self::USER_SELF)
49 {
50 global $USER;
51 $userId = $USER->GetID();
52 }
53 else
54 {
55 $userId = intval($users);
56 }
57 if ($userId <= 0)
58 {
59 return false;
60 }
61 $userList[] = $userId;
62 }
63
64 $config = [];
65 foreach ($userList as $userId)
66 {
67 $privateChannel = \CPullChannel::Get($userId, true, false, $type);
68
69 $config[$userId] = Array(
70 'USER_ID' => (int)$userId,
71 'PUBLIC_ID' => $privateChannel["CHANNEL_PUBLIC_ID"],
72 'SIGNATURE' => \CPullChannel::GetPublicSignature($privateChannel["CHANNEL_PUBLIC_ID"]),
73 'START' => $privateChannel['CHANNEL_DT'],
74 'END' => $privateChannel['CHANNEL_DT'] + \CPullChannel::CHANNEL_TTL,
75 );
76 }
77
78 if ($returnJson)
79 {
80 foreach ($config as $userId => $userConfig)
81 {
82 $userConfig = array_change_key_case($userConfig, CASE_LOWER);
83 $userConfig['start'] = date('c', $userConfig['start']);
84 $userConfig['end'] = date('c', $userConfig['end']);
85 $config[$userId] = $userConfig;
86 }
87 }
88
89 return $config;
90 }
91}
static getPublicId($params)
Definition channel.php:10
static getPublicIds($params=[])
Definition channel.php:25