1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
sectionbuilderfromdatamanager.php
См. документацию.
1<?php
2
3namespace Bitrix\Calendar\Core\Builders;
4
5use Bitrix\Calendar\Core\Base\BaseException;
6use Bitrix\Calendar\Core\Event\Tools\Dictionary;
7use Bitrix\Calendar\Core\Role\Helper;
8use Bitrix\Calendar\Core\Role\Role;
9use Bitrix\Calendar\Core\Section\Section;
10use Bitrix\Calendar\Integration\SocialNetwork\Collab;
11use Bitrix\Calendar\Internals\EO_Section;
12
14{
18 private $sectionDM;
19
23 public function __construct(EO_Section $sectionDM)
24 {
25 $this->sectionDM = $sectionDM;
26 }
27
31 public function build(): Section
32 {
33 return (new Section())
34 ->setId($this->getId())
35 ->setName($this->getName())
36 ->setColor($this->getColor())
37 ->setGoogleId($this->getGoogleId())
38 ->setSyncToken($this->getSyncToken())
39 ->setPageToken($this->getPageToken())
40 ->setCalDavConnectionId($this->getCalDavConnectionId())
41 ->setDescription($this->getDescription())
42 ->setExternalType($this->getExternalType())
43 ->setType($this->getType())
44 ->setIsActive($this->getIsActive())
45 ->setXmlId($this->getXmlId())
46 ->setOwner($this->getOwner())
47 ->setCreator($this->getCreator())
48 ->setIsCollab($this->getIsCollab())
49 ;
50 }
51
55 private function getId(): int
56 {
57 return $this->sectionDM->getId();
58 }
59
63 private function getGoogleId(): ?string
64 {
65 return $this->sectionDM->getGapiCalendarId();
66 }
67
71 private function getSyncToken(): ?string
72 {
73 return $this->sectionDM->getSyncToken();
74 }
75
79 private function getPageToken(): ?string
80 {
81 return $this->sectionDM->getPageToken();
82 }
83
87 private function getCalDavConnectionId(): ?int
88 {
89 return (int)$this->sectionDM->getCalDavCon() ?: null;
90 }
91
95 private function getDescription(): ?string
96 {
97 return $this->sectionDM->getDescription();
98 }
99
103 private function getName(): ?string
104 {
105 return $this->sectionDM->getName();
106 }
107
111 private function getColor(): string
112 {
113 return $this->sectionDM->getColor();
114 }
115
119 private function getExternalType(): string
120 {
121 return $this->sectionDM->getExternalType();
122 }
123
127 private function getIsActive(): bool
128 {
129 return $this->sectionDM->getActive();
130 }
131
135 private function getType(): string
136 {
137 return $this->sectionDM->getCalType();
138 }
139
143 private function getXmlId(): string
144 {
145 return $this->sectionDM->getXmlId();
146 }
147
153 private function getOwner(): ?Role
154 {
155 if ($id = $this->sectionDM->getOwnerId())
156 {
157 try
158 {
159 return match ($this->sectionDM->getCalType())
160 {
161 Dictionary::CALENDAR_TYPE['group'] => Helper::getGroupRole($id),
162 Dictionary::CALENDAR_TYPE['company'] => Helper::getCompanyRole($id),
163 default => Helper::getUserRole($id),
164 };
165 }
166 catch (BaseException $e)
167 {
168 return null;
169 }
170 }
171
172 return null;
173 }
174
180 private function getCreator(): ?Role
181 {
182 if ($id = ($this->sectionDM->getCreatedBy() ?? $this->sectionDM->getOwnerId()))
183 {
184 try
185 {
186 return Helper::getUserRole($id);
187 }
188 catch (BaseException $e)
189 {
190 return null;
191 }
192 }
193
194 return null;
195 }
196
197 private function getIsCollab(): bool
198 {
199 if ($this->getType() !== Dictionary::CALENDAR_TYPE['group'])
200 {
201 return false;
202 }
203
204 $groupId = $this->getOwner()?->getId();
205 if (!$groupId)
206 {
207 return false;
208 }
209
210 return (bool)Collab\Collabs::getInstance()->getCollabIfExists($groupId);
211 }
212}