1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
LinkManager.php
См. документацию.
1<?php
2
3declare(strict_types=1);
4
6
10
11final class LinkManager
12{
13 use InstanceTrait;
14
15 private LinkType $type;
16 private LinkParts $linkParts;
17 private User $user;
18
19 public function get(LinkType $type, LinkParts $linkParts): string
20 {
21 $this->type = $type;
22 $this->linkParts = $linkParts;
23 $this->user = new User($this->linkParts->userId);
24
25 $parts = $this->getParts();
26
27 $baseLink = match ($this->type)
28 {
29 LinkType::Tasks, LinkType::Calendar, LinkType::Disk, => implode('/', $parts) . '/',
30 };
31
32 if ($this->linkParts->entityId === null)
33 {
34 return $baseLink;
35 }
36
37 return $this->getEntityLink($baseLink);
38 }
39
40 private function getEntityLink(string $baseLink): string
41 {
42 $parts = $this->getEntityParts();
43
44 return match ($this->type)
45 {
46 LinkType::Tasks => $baseLink . implode('/', $parts) . '/',
47 default => $baseLink,
48 };
49 }
50
51 private function getParts(): array
52 {
53 $sitePart = $this->getSitePart();
54 if (empty($sitePart))
55 {
56 return [$this->getCollabPart(), $this->getEntityPart()];
57 }
58
59 return [$this->getSitePart(), $this->getCollabPart(), $this->getEntityPart()];
60 }
61
62 private function getEntityParts(): array
63 {
64 if (empty($this->linkParts->view))
65 {
66 return [$this->linkParts->entityId];
67 }
68
69 $entityType = $this->getEntityType();
70 if (empty($entityType))
71 {
72 return [$this->linkParts->view, $this->linkParts->entityId];
73 }
74
75 return [$entityType, $this->linkParts->view, $this->linkParts->entityId];
76 }
77
78 private function getSitePart(): string
79 {
80 if ($this->user->isExtranet())
81 {
82 return Extranet::getSiteName();
83 }
84
85 return '';
86 }
87
88 private function getCollabPart(): string
89 {
90 return 'workgroups/group/' . $this->linkParts->collabId;
91 }
92
93 private function getEntityPart(): string
94 {
95 return match ($this->type)
96 {
97 LinkType::Tasks => 'tasks',
98 LinkType::Calendar => 'calendar',
99 LinkType::Disk => 'disk/path',
100 };
101 }
102
103 private function getEntityType(): string
104 {
105 return match ($this->type)
106 {
107 LinkType::Tasks => 'task',
108 default => '',
109 };
110 }
111}
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
trait InstanceTrait
Определения instancetrait.php:8