Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
entityeditorconfiguration.php
1<?php
2namespace Bitrix\UI\Form;
3
6
8{
9 protected $categoryName;
10
11 public static function canEditOtherSettings(): bool
12 {
13 return Main\Engine\CurrentUser::get()->canDoOperation('edit_other_settings');
14 }
15
16 public function __construct(string $categoryName = null)
17 {
18 $this->categoryName = $categoryName;
19 }
20
21 protected function getCategoryName(): string
22 {
23 if(empty($this->categoryName))
24 {
25 return 'ui.form.editor';
26 }
27
29 }
30
31 protected function prepareName(string $configID, string $scope): string
32 {
34 {
35 return "{$configID}_common";
36 }
37
38 return $configID;
39 }
40
41 protected function prepareScopeName(string $configID): string
42 {
43 return "{$configID}_scope";
44 }
45
46 public static function prepareOptionsName(string $configID, string $scope, int $userScopeId = 0): string
47 {
48 $configID = mb_strtolower($configID);
50 {
51 return "{$configID}_common_opts";
52 }
54 {
55 return "{$configID}_custom_opts_" . $userScopeId;
56 }
57 return "{$configID}_opts";
58 }
59
60 public function getScope($configID)
61 {
62 return \CUserOptions::GetOption(
63 $this->getCategoryName(),
64 $this->prepareScopeName($configID),
66 );
67 }
68
69 public function get($configID, $scope)
70 {
72 {
73 return null;
74 }
75
76 return \CUserOptions::GetOption(
77 $this->getCategoryName(),
78 $this->prepareName($configID, $scope),
79 null,
80 $scope === EntityEditorConfigScope::COMMON ? 0 : false
81 );
82 }
83
84 public function set($configID, array $config, array $params)
85 {
87
88 $scope = isset($params['scope'])? mb_strtoupper($params['scope']) : EntityEditorConfigScope::UNDEFINED;
90 {
92 }
93
94 $userScopeId = $params['userScopeId'] ?? 0;
95
96 $forAllUsers = self::canEditOtherSettings()
97 && isset($params['forAllUsers'])
98 && $params['forAllUsers'] === 'Y';
99
100 if($forAllUsers)
101 {
102 if(isset($params['delete']) && $params['delete'] === 'Y')
103 {
104 \CUserOptions::DeleteOptionsByName($categoryName, $configID);
105 }
106 \CUserOptions::SetOption($categoryName, $configID, $config, true);
107 }
108
110 {
111 \CUserOptions::SetOption(
113 $this->prepareName($configID, $scope),
114 $config,
115 true
116 );
117 }
118 elseif($scope === EntityEditorConfigScope::PERSONAL)
119 {
120 \CUserOptions::SetOption($categoryName, $configID, $config);
121 }
122 elseif($userScopeId > 0)
123 {
124 Scope::getInstance()->updateScopeConfig(
125 $userScopeId,
126 $config
127 );
128 }
129
130 $options = isset($params['options']) && is_array($params['options']) ? $params['options'] : array();
131 if(!empty($options))
132 {
133 $optionName = static::prepareOptionsName($configID, $scope, $userScopeId);
135 {
136 \CUserOptions::SetOption(
138 $optionName,
139 $options,
140 true
141 );
142 }
143 else
144 {
145 if($forAllUsers)
146 {
147 if(isset($params['delete']) && $params['delete'] === 'Y')
148 {
149 \CUserOptions::DeleteOptionsByName($categoryName, $optionName);
150 }
151 \CUserOptions::SetOption($categoryName, $optionName, $options, true);
152 }
153 \CUserOptions::SetOption($categoryName, $optionName, $options);
154 }
155 //todo check what to do with options for custom scopes
156 }
157 }
158 public function reset($configID, array $params)
159 {
161
162 $scope = isset($params['scope'])? mb_strtoupper($params['scope']) : EntityEditorConfigScope::UNDEFINED;
164 {
166 }
167
168 $forAllUsers = self::canEditOtherSettings()
169 && isset($params['forAllUsers'])
170 && $params['forAllUsers'] === 'Y';
171
173 {
174 \CUserOptions::DeleteOption(
176 $this->prepareName($configID, $scope),
177 true,
178 0
179 );
180 \CUserOptions::DeleteOption(
182 static::prepareOptionsName($configID, $scope),
183 true,
184 0
185 );
186 }
187 else
188 {
189 if($forAllUsers)
190 {
191 \CUserOptions::DeleteOptionsByName($categoryName, $this->prepareName($configID, $scope));
192 \CUserOptions::DeleteOptionsByName($categoryName, static::prepareOptionsName($configID, $scope));
193 \CUserOptions::DeleteOptionsByName($categoryName, $this->prepareScopeName($configID));
194 }
195 else
196 {
197 \CUserOptions::DeleteOption($categoryName, $this->prepareName($configID, $scope));
198 \CUserOptions::DeleteOption($categoryName, static::prepareOptionsName($configID, $scope));
199
200 \CUserOptions::SetOption(
202 $this->prepareScopeName($configID),
204 );
205 }
206 }
207
208 }
209 public function setScope($configID, $scope)
210 {
212 {
214 }
215
216 \CUserOptions::SetOption($this->getCategoryName(), $this->prepareScopeName($configID), $scope);
217 }
218 public function forceCommonScopeForAll($configID)
219 {
220 if(!self::canEditOtherSettings())
221 {
222 return;
223 }
224
226
227 \CUserOptions::DeleteOptionsByName(
230 );
231 \CUserOptions::DeleteOptionsByName($categoryName, $this->prepareScopeName($configID));
232 }
233}
static prepareOptionsName(string $configID, string $scope, int $userScopeId=0)