Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
channel.php
1<?php
2
4
7
8class Channel
9{
10 protected $id;
11 protected $userId;
12 protected $privateId;
13 protected $publicId;
14 protected $type = \CPullChannel::TYPE_PRIVATE;
15 protected $dateCreate;
16
17 public static function createWithTag(string $tag): Channel
18 {
19 $instance = new static();
20 $instance->privateId = \CPullChannel::GetNewChannelIdByTag($tag);
21 $instance->publicId = \CPullChannel::GetNewChannelIdByTag($tag,'public');
22 $instance->dateCreate = new DateTime();
23
24 return $instance;
25 }
26
27 public static function createRandom(): Channel
28 {
29 $instance = new static();
30 $instance->privateId = \CPullChannel::GetNewChannelId();
31 $instance->publicId = \CPullChannel::GetNewChannelId('public');
32 $instance->dateCreate = new DateTime();
33
34 return $instance;
35 }
36
42 public static function getShared(): Channel
43 {
44 $fields = \CPullChannel::GetShared();
45 if (!$fields)
46 {
47 throw new SystemException("Public channel is empty");
48 }
49
50 return static::createWithFields($fields);
51 }
52
53 public static function createWithFields(array $fields): Channel
54 {
55 $instance = new static();
56 if (isset($fields['CHANNEL_ID']))
57 {
58 $instance->privateId = $fields['CHANNEL_ID'];
59 }
60 if (isset($fields['CHANNEL_PUBLIC_ID']))
61 {
62 $instance->publicId = $fields['CHANNEL_PUBLIC_ID'];
63 }
64 if (isset($fields['CHANNEL_TYPE']))
65 {
66 $instance->type = $fields['CHANNEL_TYPE'];
67 }
68 if (isset($fields['CHANNEL_DT']))
69 {
70 $instance->dateCreate = DateTime::createFromTimestamp($fields['CHANNEL_DT']);
71 }
72
73 return $instance;
74 }
75
76 public function getId(): ?int
77 {
78 return $this->id;
79 }
80
81 public function getUserId(): ?int
82 {
83 return $this->userId;
84 }
85
86 public function getPrivateId(): string
87 {
88 return $this->privateId;
89 }
90
91 public function getPublicId(): string
92 {
93 return $this->publicId;
94 }
95
96 public function getSignedPublicId(): string
97 {
98 return \CPullChannel::SignPublicChannel($this->publicId);
99 }
100
101 public function getType(): string
102 {
103 return $this->type;
104 }
105
106 public function getDateCreate(): DateTime
107 {
108 return $this->dateCreate;
109 }
110}
static createFromTimestamp($timestamp)
Definition datetime.php:246
static createWithFields(array $fields)
Definition channel.php:53
static createWithTag(string $tag)
Definition channel.php:17