1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
entityeditorconfiguration.php
См. документацию.
1<?php
2namespace Bitrix\UI\Form;
3
4use Bitrix\Main;
5use Bitrix\Ui\EntityForm\Scope;
6
8{
9 protected $categoryName;
10 protected int $userId;
11
12 public static function canEditOtherSettings(): bool
13 {
14 return Main\Engine\CurrentUser::get()->canDoOperation('edit_other_settings');
15 }
16
17 public function __construct(string $categoryName = null, ?int $userId = null)
18 {
19 $this->categoryName = $categoryName;
20 $this->userId = $userId ?? (($GLOBALS['USER'] instanceof \CUser) ? $GLOBALS['USER']->getId() : 0);
21 }
22
23 protected function getCategoryName(): string
24 {
25 if(empty($this->categoryName))
26 {
27 return 'ui.form.editor';
28 }
29
31 }
32
33 protected function prepareName(string $configID, string $scope): string
34 {
36 {
37 return "{$configID}_common";
38 }
39
40 return $configID;
41 }
42
43 protected function prepareScopeName(string $configID): string
44 {
45 return "{$configID}_scope";
46 }
47
48 public static function prepareOptionsName(string $configID, string $scope, int $userScopeId = 0): string
49 {
50 $configID = mb_strtolower($configID);
52 {
53 return "{$configID}_common_opts";
54 }
56 {
57 return "{$configID}_custom_opts_" . $userScopeId;
58 }
59 return "{$configID}_opts";
60 }
61
62 public function getScope($configID)
63 {
64 if (!$this->userId)
65 {
67 }
68
69 return \CUserOptions::GetOption(
70 $this->getCategoryName(),
71 $this->prepareScopeName($configID),
73 $this->userId
74 );
75 }
76
77 public function get($configID, $scope)
78 {
80 {
81 return null;
82 }
83
84 if (!$this->userId)
85 {
86 return null;
87 }
88
89 return \CUserOptions::GetOption(
90 $this->getCategoryName(),
91 $this->prepareName($configID, $scope),
92 null,
93 $scope === EntityEditorConfigScope::COMMON ? 0 : $this->userId
94 );
95 }
96
97 public function set($configID, array $config, array $params)
98 {
100
101 $scope = isset($params['scope'])? mb_strtoupper($params['scope']) : EntityEditorConfigScope::UNDEFINED;
103 {
105 }
106
107 $userScopeId = (int)($params['userScopeId'] ?? 0);
108
109 $forAllUsers = isset($params['forAllUsers'])
110 && $params['forAllUsers'] === 'Y'
112 ;
113
114 if($forAllUsers)
115 {
116 if(isset($params['delete']) && $params['delete'] === 'Y')
117 {
118 \CUserOptions::DeleteOptionsByName($categoryName, $configID);
119 }
120 \CUserOptions::SetOption($categoryName, $configID, $config, true);
121 }
122
124 {
125 \CUserOptions::SetOption(
127 $this->prepareName($configID, $scope),
128 $config,
129 true
130 );
131 }
133 {
134 if ($this->userId)
135 {
136 \CUserOptions::SetOption($categoryName, $configID, $config, false, $this->userId);
137 }
138
139 }
140 elseif($userScopeId > 0)
141 {
142 Scope::getInstance()->updateScopeConfig(
143 $userScopeId,
144 $config
145 );
146 }
147
148 $options = $params['options'] ?? null;
149 if(is_array($options))
150 {
151 $optionName = static::prepareOptionsName($configID, $scope, $userScopeId);
153 {
154 \CUserOptions::SetOption(
157 $options,
158 true
159 );
160 }
161 else
162 {
163 if($forAllUsers)
164 {
165 if(isset($params['delete']) && $params['delete'] === 'Y')
166 {
167 \CUserOptions::DeleteOptionsByName($categoryName, $optionName);
168 }
169 \CUserOptions::SetOption($categoryName, $optionName, $options, true);
170 }
171 if ($this->userId)
172 {
173 \CUserOptions::SetOption($categoryName, $optionName, $options, false, $this->userId);
174 }
175 }
176 //todo check what to do with options for custom scopes
177 }
178 }
179 public function reset($configID, array $params)
180 {
182
183 $scope = isset($params['scope'])? mb_strtoupper($params['scope']) : EntityEditorConfigScope::UNDEFINED;
185 {
187 }
188
189 $forAllUsers = self::canEditOtherSettings()
190 && isset($params['forAllUsers'])
191 && $params['forAllUsers'] === 'Y';
192
194 {
195 \CUserOptions::DeleteOption(
197 $this->prepareName($configID, $scope),
198 true,
199 0
200 );
201 \CUserOptions::DeleteOption(
203 static::prepareOptionsName($configID, $scope),
204 true,
205 0
206 );
207 }
208 else
209 {
210 if($forAllUsers)
211 {
212 \CUserOptions::DeleteOptionsByName($categoryName, $this->prepareName($configID, $scope));
213 \CUserOptions::DeleteOptionsByName($categoryName, static::prepareOptionsName($configID, $scope));
214 \CUserOptions::DeleteOptionsByName($categoryName, $this->prepareScopeName($configID));
215 }
216 elseif ($this->userId)
217 {
218 \CUserOptions::DeleteOption($categoryName, $this->prepareName($configID, $scope), false, $this->userId);
219 \CUserOptions::DeleteOption($categoryName, static::prepareOptionsName($configID, $scope), false, $this->userId);
220
221 \CUserOptions::SetOption(
223 $this->prepareScopeName($configID),
225 false,
226 $this->userId
227 );
228 }
229 }
230
231 }
232 public function setScope($configID, $scope)
233 {
235 {
237 }
238
239 if ($this->userId)
240 {
241 \CUserOptions::SetOption($this->getCategoryName(), $this->prepareScopeName($configID), $scope, false, $this->userId);
242 }
243 }
244 public function forceCommonScopeForAll($configID)
245 {
246 if(!self::canEditOtherSettings())
247 {
248 return;
249 }
250
252
253 \CUserOptions::DeleteOptionsByName(
256 );
257 \CUserOptions::DeleteOptionsByName($categoryName, $this->prepareScopeName($configID));
258 }
259}
static get()
Определения currentuser.php:33
static isDefined(string $scope)
Определения entityeditorconfigscope.php:16
reset($configID, array $params)
Определения entityeditorconfiguration.php:179
static prepareOptionsName(string $configID, string $scope, int $userScopeId=0)
Определения entityeditorconfiguration.php:48
prepareName(string $configID, string $scope)
Определения entityeditorconfiguration.php:33
__construct(string $categoryName=null, ?int $userId=null)
Определения entityeditorconfiguration.php:17
$options
Определения commerceml2.php:49
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$GLOBALS['____1690880296']
Определения license.php:1
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$config
Определения quickway.php:69
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$optionName
Определения options.php:1735