1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
Application.php
См. документацию.
1<?php
2
4
13
15{
16 use ContextCustomer;
17 private const DEFAULT_ORDER = 50;
18 private const SETTING_NAME = 'im_placement';
19
20 public function __construct(?int $userId = null)
21 {
22 $context = (new Context())->setUserId($userId);
23
24 $this->setContext($context);
25 }
26
30 public function getApplications(?array $placementList = null): array
31 {
32 $orderList = $this->getOrderList();
33 $result = [];
34 foreach ($this->generateApplicationList($placementList) as $application)
35 {
36 if ($this->isApplicationAvailable($application))
37 {
38 $application->order = $orderList[$application->id] ?? self::DEFAULT_ORDER;
40 }
41 }
42
43 return $result;
44 }
45
46 public function getLoadUri(): string
47 {
48 $url = '/bitrix/components/bitrix/app.layout/lazyload.ajax.php?' . bitrix_sessid_get();
49
50 return
51 (new Uri($url))
52 ->addParams(['site' => SITE_ID])
53 ->getUri()
54 ;
55 }
56
57 public function setOrder(int $applicationsId, int $order): Result
58 {
59 $orderList = $this->getOrderList();
60 $orderList[$applicationsId] = $order;
61 $orderList = $this->filterDeletedApplications($orderList);
62
63 return $this->setOrderList($orderList);
64 }
65
66 private function getOrderList(): array
67 {
68 return \CUserOptions::GetOption('im', self::SETTING_NAME, []);
69 }
70
71 private function setOrderList(array $orderList): Result
72 {
73 $result = new Result();
74 $isSuccess = \CUserOptions::SetOption('im', self::SETTING_NAME, $orderList);
75
76 if (!$isSuccess)
77 {
78 $result->addError(new Error('Error writing the parameter order', 'SERVER_ERROR'));
79 }
80
81 return $result;
82 }
83
84 private function isApplicationAvailable(Application\Entity $application): bool
85 {
86 return
87 $this->checkRole($application->options['role'])
88 && $this->checkExtranet($application->options['extranet'])
89 ;
90 }
91
92 private function checkExtranet(string $extranetOption): bool
93 {
94 if ($this->getContext()->getUser()->isExtranet())
95 {
96 return $extranetOption === 'Y';
97 }
98
99 return true;
100 }
101
102 private function checkRole(string $roleOptions): bool
103 {
104 if (!$this->getContext()->getUser()->isAdmin())
105 {
106 return mb_strtoupper($roleOptions) === Role::USER;
107 }
108
109 return true;
110 }
111
112 private function filterDeletedApplications(array $userApplications): array
113 {
114 $applicationIdList = $this->getApplicationIdList();
115
116 $result = [];
117 foreach ($userApplications as $applicationId => $order)
118 {
119 if (in_array($applicationId, $applicationIdList, true))
120 {
121 $result[$applicationId] = $order;
122 }
123 }
124
125 return $result;
126 }
127
131 private function generateApplicationList(?array $placementList = null): \Iterator
132 {
133 foreach ($placementList ?? Placement::getPlacementList() as $placement)
134 {
135 foreach (PlacementTable::getHandlersList($placement) as $handler)
136 {
137 yield new Application\Entity([
138 'id' => $handler['ID'],
139 'placement' => $placement,
140 'options' => $handler['OPTIONS'],
141 'restApplicationId' => $handler['APP_ID'],
142 'title' => $handler['TITLE'],
143 ]);
144 }
145 }
146 }
147
148 private function getApplicationIdList(): array
149 {
150 $result = [];
151 foreach ($this->generateApplicationList() as $application)
152 {
153 if ($this->isApplicationAvailable($application))
154 {
155 $result[] = $application->id;
156 }
157 }
158
159 return $result;
160 }
161
162 public static function getRestEntityName(): string
163 {
164 return 'placementApplications';
165 }
166
167 public function toRestFormat(array $option = []): array
168 {
169 return [
170 'items' => array_map(
171 static fn ($appEntity) => $appEntity->toRestFormat(),
172 $this->getApplications()
173 ),
174 'links' => [
175 'load' => $this->getLoadUri(),
176 ],
177 ];
178 }
179}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
__construct(?int $userId=null)
Определения Application.php:20
static getRestEntityName()
Определения Application.php:162
toRestFormat(array $option=[])
Определения Application.php:167
setOrder(int $applicationsId, int $order)
Определения Application.php:57
getApplications(?array $placementList=null)
Определения Application.php:30
static getPlacementList()
Определения Placement.php:13
Определения result.php:20
Определения error.php:15
Определения uri.php:17
</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
$context
Определения csv_new_setup.php:223
$application
Определения bitrix.php:23
bitrix_sessid_get($varname='sessid')
Определения tools.php:4695
trait ContextCustomer
Определения ContextCustomer.php:12
Определения culture.php:9
$order
Определения payment.php:8
$option
Определения options.php:1711
const SITE_ID
Определения sonet_set_content_view.php:12
$url
Определения iframe.php:7