Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
intranet.php
1<?php
3
4use \Bitrix\Landing\Rights;
5use \Bitrix\Main\Localization\Loc;
6use \Bitrix\Landing\Binding;
7use \Bitrix\Intranet\Binding\Menu;
8
9Loc::loadMessages(__FILE__);
10
12{
16 const PATH_SERVICE_LIST = 'kb/binding/menu/';
17
23 protected static function getMenuItemBind(string $bindCode): array
24 {
25 $setItems = [];
26 if (Rights::hasAdditionalRight('extension', null, false, true))
27 {
28 $setItems[] = [
29 'id' => 'landing_bind',
30 'system' => true,
31 'text' => Loc::getMessage('LANDING_CONNECTOR_INTRANET_MENU_BIND_TITLE'),
32 'onclick' => 'BX.SidePanel.Instance.open(\'' . SITE_DIR . self::PATH_SERVICE_LIST .
33 '?menuId=' . $bindCode . '\', {allowChangeHistory: false});'
34 ];
35 if (Rights::hasAdditionalRight('create', null, false, true))
36 {
37 $setItems[] = [
38 'id' => 'landing_create',
39 'system' => true,
40 'text' => Loc::getMessage('LANDING_CONNECTOR_INTRANET_MENU_BIND_CREATE_TITLE'),
41 'onclick' => 'BX.SidePanel.Instance.open(\'' . SITE_DIR . self::PATH_SERVICE_LIST .
42 '?menuId=' . $bindCode . '&create=Y\', {allowChangeHistory: false});'
43 ];
44 }
45 }
46 return $setItems;
47 }
48
56 protected static function getMenuItemUnbind(string $bindCode, string $entityId, string $title): array
57 {
58 return [
59 'id' => 'landing_unbind_' . $entityId,
60 'system' => true,
61 'text' => $title,
62 'onclick' => 'BX.Landing.Connector.Intranet.unbindMenuItem("' . $bindCode . '", "' . $entityId . '", "' . \CUtil::JSEscape($title) . '");'
63 ];
64 }
65
71 public static function onBuildBindingMenu(\Bitrix\Main\Event $event): array
72 {
73 \CJSCore::init('sidepanel');
74 \Bitrix\Landing\Site\Type::setScope(
75 \Bitrix\Landing\Site\Type::SCOPE_CODE_KNOWLEDGE
76 );
77
78 $bindings = Binding\Menu::getList(null);
79
80 // associate different bindings
81 $bindingsAssoc = [];
82 foreach ($bindings as $binding)
83 {
84 if (!isset($bindingsAssoc[$binding['BINDING_ID']]))
85 {
86 $bindingsAssoc[$binding['BINDING_ID']] = [];
87 }
88 $bindingsAssoc[$binding['BINDING_ID']][] = $binding;
89 }
90 $bindings = $bindingsAssoc;
91 unset($bindingsAssoc);
92
93 // init vars
94 $items = [];
95 $bindingMap = Menu::getMap();
96
97 // build binding map
98 foreach ($bindingMap as $sectionCode => $bindingSection)
99 {
100 foreach ($bindingSection['items'] as $itemCode => $foo)
101 {
102 $menuItems = [];
103 $unbindItems = [];
104 $bindingCode = $sectionCode . ':' . $itemCode;
105 if (isset($bindings[$bindingCode]))
106 {
107 foreach ($bindings[$bindingCode] as $bindingItem)
108 {
109 $menuItems[] = [
110 'id' => 'landing_' . $bindingItem['ENTITY_TYPE'] . $bindingItem['ENTITY_ID'],
111 'text' => \htmlspecialcharsbx($bindingItem['TITLE']),
112 'href' => $bindingItem['PUBLIC_URL'],
113 'sectionCode' => Menu::SECTIONS['knowledge']
114 ];
115 $unbindItems[] = self::getMenuItemUnbind(
116 $bindingCode,
117 $bindingItem['ENTITY_TYPE'] . '_' . $bindingItem['ENTITY_ID'],
118 $bindingItem['TITLE']
119 );
120 }
121 }
122 $menuItems = array_merge(
123 $menuItems,
124 self::getMenuItemBind($bindingCode)
125 );
126 if (isset($bindings[$bindingCode]) && Rights::hasAdditionalRight('extension', null, false, true))
127 {
128 $menuItems[] = [
129 'id' => 'landing_unbind',
130 'extension' => 'landing.connector.intranet',
131 'text' => Loc::getMessage('LANDING_CONNECTOR_INTRANET_MENU_HIDE_TITLE'),
132 'items' => $unbindItems
133 ];
134 }
135 $items[] = [
136 'bindings' => [
137 $sectionCode => [
138 'include' => [
139 $itemCode
140 ]
141 ]
142 ],
143 'items' => $menuItems
144 ];
145 }
146 }
147
148 \Bitrix\Landing\Site\Type::clearScope();
149
150 return $items;
151 }
152}
static onBuildBindingMenu(\Bitrix\Main\Event $event)
Definition intranet.php:71
static getMenuItemUnbind(string $bindCode, string $entityId, string $title)
Definition intranet.php:56
static getMenuItemBind(string $bindCode)
Definition intranet.php:23
static hasAdditionalRight($code, $type=null, bool $checkExtraRights=false, bool $strict=false)
Definition rights.php:1025
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29