1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
Composition.php
См. документацию.
1<?php
2
4
17use Exception;
18
20{
21 public const FILTER = 'MODULE_ID';
22 public const CACHE_ID = 'socialnetwork-toolbar-composition-';
23
24 private CompositionItemCollection $collection;
25 private Cache $cache;
26
27 public function __construct(private int $userId, private int $spaceId = 0)
28 {
29 $this->init();
30 }
31
32 public function setDefaultSettings(): Result
33 {
34 $result = new Result();
35 try
36 {
37 if (!SpaceCompositionTable::isDataFilled($this->userId, $this->spaceId))
38 {
39 $result = $this->setSettings($this->getDefaultSettings());
40 }
41 }
42 catch (Exception $exception)
43 {
44 $result->addError(Error::createFromThrowable($exception));
45 }
46
47 return $result;
48 }
49
51 {
52 $result = new Result();
53 $collection = CompositionItemCollection::createFromModuleIds($settings)->fillBoundItems();
54 try
55 {
56 $composition = SpaceCompositionTable::getByIds($this->userId, $this->spaceId);
57 if (is_null($composition))
58 {
59 $result = SpaceCompositionTable::fill($this->userId, $this->spaceId, $collection->toArray());
60 }
61 else
62 {
63 $result = $composition
64 ->setSettings($collection->toArray())
65 ->save();
66 }
67 }
68 catch (Exception $exception)
69 {
70 $result->addError(Error::createFromThrowable($exception));
71 }
72
73 if ($result->isSuccess())
74 {
75 $this->cache->store($result->getData()['SETTINGS']);
76 }
77
78 return $result;
79 }
80
81 public function getDefaultSettings(bool $withHidden = true): array
82 {
83 $items = [];
84 foreach ($this->collection as $item)
85 {
87 if ($item->isHidden() && !$withHidden)
88 {
89 continue;
90 }
91
92 $items[] = $item->getModuleId();
93 }
94
95 return $items;
96 }
97
98 public function getSettings(bool $withHidden = true): array
99 {
100 if ($data = $this->cache->get())
101 {
103 !$withHidden && $collection->hideItems();
104
105 return $collection->toArray();
106 }
107
108 try
109 {
110 $composition = SpaceCompositionTable::getByIds($this->userId, $this->spaceId);
112 $cacheCollection = clone $collection;
113
114 !$withHidden && $collection->hideItems();
115
116 $this->cache->store(
117 $cacheCollection
118 ->fillBoundItems()
119 ->hideItems()
120 ->toArray()
121 );
122
123 return $collection->toArray();
124 }
125 catch (Exception)
126 {
127 return $this->getDefaultSettings();
128 }
129 }
130
131 public function getDeselectedSettings(bool $withHidden = true, bool $withDisabled = true): array
132 {
133 $deselectedSettings = array_diff($this->getDefaultSettings($withHidden), $this->getSettings());
134
135 return $withDisabled
136 ? array_merge($deselectedSettings, $this->getDisabledSettings())
137 : $deselectedSettings;
138 }
139
140 public function getDisabledSettings(): array
141 {
142 // disable all crm events in spaces
143 return [
144 (new Crm())->getModuleId(),
145 ];
146 }
147
148 private function init(): void
149 {
150 $this->cache = new Cache($this->userId, $this->spaceId);
151
152 $this->collection = (new CompositionItemCollection())
153 ->addItem(new Task())
154 ->addItem(new CalendarEvent())
155 ->addItem(new Message())
156 ->addItem(new BusinessProcess())
157 ->addItem(new ListElement());
158 }
159
160 private function getCacheId(): string
161 {
162 return static::CACHE_ID . $this->userId . '-' . $this->spaceId;
163 }
164}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
Определения error.php:15
static fill(int $userId, int $spaceId, array $settings)
Определения spacecompositiontable.php:90
getSettings(bool $withHidden=true)
Определения Composition.php:98
setSettings(array $settings)
Определения Composition.php:50
__construct(private int $userId, private int $spaceId=0)
Определения Composition.php:27
getDeselectedSettings(bool $withHidden=true, bool $withDisabled=true)
Определения Composition.php:131
$data['IS_AVAILABLE']
Определения .description.php:13
</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
$settings
Определения product_settings.php:43
$items
Определения template.php:224