Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
toolavailabilitymanager.php
1<?php
2
4
5use Bitrix\Intranet\Settings\Tools\ToolsManager;
7use CUtil;
8
9
11{
12 private bool $canUseIntranetToolsManager;
13 private const INVENTORY_MANAGEMENT_TOOL_ID = 'inventory_management';
14 public const INVENTORY_MANAGEMENT_SLIDER_CODE = 'limit_store_inventory_management_off';
15
16 public function __construct()
17 {
18 $this->canUseIntranetToolsManager = (
19 Loader::includeModule('intranet')
20 && class_exists('\Bitrix\Intranet\Settings\Tools\ToolsManager')
21 );
22 }
23
24 public static function getInstance(): self
25 {
26 return new self();
27 }
28
30 {
31 return $this->check(self::INVENTORY_MANAGEMENT_TOOL_ID);
32 }
33
34 private function check(string $toolId): bool
35 {
36 if ($this->canUseIntranetToolsManager)
37 {
38 return ToolsManager::getInstance()->checkAvailabilityByToolId($toolId);
39 }
40
41 return true;
42 }
43
44 public function getInventoryManagementStubContent(): string
45 {
46 return $this->getStubComponentContent([
47 'sliderCode' => self::INVENTORY_MANAGEMENT_SLIDER_CODE,
48 ]);
49 }
50
51 public function getInventoryManagementStubJs(): string
52 {
53 return $this->getJs(self::INVENTORY_MANAGEMENT_SLIDER_CODE);
54 }
55
56 private function getStubComponentContent(array $data = []): string
57 {
58 $params = [];
59
60 if (!empty($data['sliderCode']))
61 {
62 $params['SLIDER_CODE'] = $data['sliderCode'];
63 }
64
65 ob_start();
66 global $APPLICATION;
67 $APPLICATION->IncludeComponent(
68 'bitrix:intranet.tool.inaccessibility',
69 '',
70 $params,
71 null,
72 ['HIDE_ICONS' => 'Y'],
73 );
74
75 return ob_get_clean();
76 }
77
78 private function getJs(string $id): string
79 {
80 if (!Loader::includeModule('ui'))
81 {
82 return '';
83 }
84
85 return '
86 top && top.BX.loadExt("ui.info-helper").then(() => {
87 top.BX.UI.InfoHelper.show("' . CUtil::JSEscape($id) . '");
88 });
89 ';
90 }
91}