17 private const DEFAULT_ORDER = 50;
18 private const SETTING_NAME =
'im_placement';
22 $context = (
new Context())->setUserId($userId);
24 $this->setContext($context);
32 $orderList = $this->getOrderList();
34 foreach ($this->generateApplicationList() as $application)
36 if ($this->isApplicationAvailable($application))
38 $application->order = $orderList[$application->id] ?? self::DEFAULT_ORDER;
39 $result[] = $application;
48 $url =
'/bitrix/components/bitrix/app.layout/lazyload.ajax.php?' . bitrix_sessid_get();
52 ->addParams([
'site' => SITE_ID])
59 $orderList = $this->getOrderList();
60 $orderList[$applicationsId] = $order;
61 $orderList = $this->filterDeletedApplications($orderList);
63 return $this->setOrderList($orderList);
66 private function getOrderList(): array
68 return \CUserOptions::GetOption(
'im', self::SETTING_NAME, []);
71 private function setOrderList(array $orderList):
Result
74 $isSuccess = \CUserOptions::SetOption(
'im', self::SETTING_NAME, $orderList);
78 $result->addError(
new Error(
'Error writing the parameter order',
'SERVER_ERROR'));
84 private function isApplicationAvailable(Application\Entity $application): bool
87 $this->checkRole($application->options[
'role'])
88 && $this->checkExtranet($application->options[
'extranet'])
92 private function checkExtranet(
string $extranetOption): bool
94 if ($this->getContext()->getUser()->isExtranet())
96 return $extranetOption ===
'Y';
102 private function checkRole(
string $roleOptions): bool
104 if (!$this->
getContext()->getUser()->isAdmin())
106 return mb_strtoupper($roleOptions) === Role::USER;
112 private function filterDeletedApplications(array $userApplications): array
114 $applicationIdList = $this->getApplicationIdList();
117 foreach ($userApplications as $applicationId => $order)
119 if (in_array($applicationId, $applicationIdList,
true))
121 $result[$applicationId] = $order;
131 private function generateApplicationList(): \Iterator
135 foreach (PlacementTable::getHandlersList($placement) as $handler)
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'],
148 private function getApplicationIdList(): array
151 foreach ($this->generateApplicationList() as $application)
153 if ($this->isApplicationAvailable($application))
155 $result[] = $application->id;
164 return 'placementApplications';
170 'items' => array_map(
171 static fn ($appEntity) => $appEntity->toRestFormat(),
172 $this->getApplications()