1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
sharinggroup.php
См. документацию.
1<?php
2
3namespace Bitrix\Calendar\Sharing;
4
5use Bitrix\Calendar\Sharing\Link\Factory;
6use Bitrix\Calendar\Sharing\Link\GroupLink;
7use Bitrix\Calendar\Sharing\Link\GroupLinkMapper;
8use Bitrix\Main\Error;
9use Bitrix\Main\Result;
10
11final class SharingGroup
12{
13 private int $groupId;
14 private int $userId;
15
16 public function __construct(int $groupId, int $userId)
17 {
18 $this->groupId = $groupId;
19 $this->userId = $userId;
20 }
21
22 public function enable(): Result
23 {
24 $result = new Result();
25
26 if (!$this->isEnabled())
27 {
28 Factory::getInstance()->createGroupLink($this->groupId, $this->userId);
29 }
30 else
31 {
32 $result->addError(new Error('Sharing is already enabled', 100010));
33 }
34
35 return $result;
36 }
37
38 public function disable(): Result
39 {
40 $result = new Result();
41
42 if ($this->isEnabled())
43 {
44 $groupLinks = $this->getAllGroupLinks();
45 if (!empty($groupLinks))
46 {
47 $groupLinkMapper = new GroupLinkMapper();
48 foreach ($groupLinks as $groupLink)
49 {
50 $groupLinkMapper->delete($groupLink);
51 }
52 }
53 }
54 else
55 {
56 $result->addError(new Error('Sharing is already disabled', 100020));
57 }
58
59 return $result;
60 }
61
62 public function isEnabled(): bool
63 {
64 return (bool)$this->getActiveLinkUrl();
65 }
66
67 public function getActiveLinkUrl(): ?string
68 {
69 $groupLink = $this->getGroupLink();
70
71 return $groupLink && $groupLink->isActive() ? $groupLink->getUrl() : null;
72 }
73
74 public function getGroupLink(): ?GroupLink
75 {
76 return $this->getGroupLinkByGroupId($this->groupId, $this->userId);
77 }
78
79 public function getLinkInfo(): array
80 {
81 $linkRuleMapper = new Link\Rule\Mapper();
82 $groupLink = $this->getGroupLink();
83 if (is_null($groupLink))
84 {
85 $linkObjectRule = new Link\Rule\GroupRule($this->groupId);
86 $sharingRule = $linkRuleMapper->getFromLinkObjectRule($linkObjectRule);
87 $sharingHash = null;
88 $url = null;
89 }
90 else
91 {
92 $sharingRule = $groupLink->getSharingRule();
93 $sharingHash = $groupLink->getHash();
94 $url = Helper::getShortUrl($groupLink->getUrl());
95 }
96
97 return [
98 'url' => $url,
99 'hash' => $sharingHash,
100 'rule' => $linkRuleMapper->convertToArray($sharingRule),
101 ];
102 }
103
104 public function generateGroupJointLink(array $memberIds): Result
105 {
106 $result = new Result();
107
108 if (!$this->isEnabled())
109 {
110 $result->addError(new Error('Sharing is disabled', 100050));
111 }
112
113 if ($result->isSuccess())
114 {
116 $groupJointLink = Factory::getInstance()->createGroupJointLink($this->groupId, $memberIds);
117
118 $linkArray = (new GroupLinkMapper())->convertToArray($groupJointLink);
119
120 $result->setData([
121 'url' => $linkArray['shortUrl'],
122 'link' => $linkArray,
123 ]);
124 }
125
126 return $result;
127 }
128
129 protected function getAllGroupLinks(): array
130 {
131 return Factory::getInstance()->getGroupLinks($this->groupId, $this->userId);
132 }
133
134 protected function getGroupLinkByGroupId(int $groupId, int $userId): ?GroupLink
135 {
136 $groupLinks = Factory::getInstance()->getGroupLinks($groupId, $userId);
137
138 return !empty($groupLinks) ? array_shift($groupLinks) : null;
139 }
140}
getGroupLinkByGroupId(int $groupId, int $userId)
Определения sharinggroup.php:134
__construct(int $groupId, int $userId)
Определения sharinggroup.php:16
Определения error.php:15
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$url
Определения iframe.php:7