1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
entityeditorconfiguration.php
См. документацию.
1
<?php
2
namespace
Bitrix\UI\Form;
3
4
use Bitrix\Main;
5
use Bitrix\Ui\EntityForm\Scope;
6
7
class
EntityEditorConfiguration
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
30
return
$this->categoryName
;
31
}
32
33
protected
function
prepareName
(
string
$configID,
string
$scope): string
34
{
35
if
($scope ===
EntityEditorConfigScope::COMMON
)
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);
51
if
($scope ===
EntityEditorConfigScope::COMMON
)
52
{
53
return
"{$configID}_common_opts"
;
54
}
55
if
($scope ===
EntityEditorConfigScope::CUSTOM
)
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
{
66
return
EntityEditorConfigScope::UNDEFINED
;
67
}
68
69
return \CUserOptions::GetOption(
70
$this->
getCategoryName
(),
71
$this->
prepareScopeName
($configID),
72
EntityEditorConfigScope::UNDEFINED
,
73
$this->userId
74
);
75
}
76
77
public
function
get
($configID, $scope)
78
{
79
if
(!
EntityEditorConfigScope::isDefined
($scope))
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
{
99
$categoryName
= $this->
getCategoryName
();
100
101
$scope = isset(
$params
[
'scope'
])? mb_strtoupper(
$params
[
'scope'
]) :
EntityEditorConfigScope::UNDEFINED
;
102
if
(!
EntityEditorConfigScope::isDefined
($scope))
103
{
104
$scope =
EntityEditorConfigScope::PERSONAL
;
105
}
106
107
$userScopeId = (int)(
$params
[
'userScopeId'
] ?? 0);
108
109
$forAllUsers = isset(
$params
[
'forAllUsers'
])
110
&&
$params
[
'forAllUsers'
] ===
'Y'
111
&&
self::canEditOtherSettings
()
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
123
if
($scope ===
EntityEditorConfigScope::COMMON
)
124
{
125
\CUserOptions::SetOption(
126
$categoryName
,
127
$this->
prepareName
($configID, $scope),
128
$config
,
129
true
130
);
131
}
132
elseif
($scope ===
EntityEditorConfigScope::PERSONAL
)
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);
152
if
($scope ===
EntityEditorConfigScope::COMMON
)
153
{
154
\CUserOptions::SetOption(
155
$categoryName
,
156
$optionName
,
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
{
181
$categoryName
= $this->
getCategoryName
();
182
183
$scope = isset(
$params
[
'scope'
])? mb_strtoupper(
$params
[
'scope'
]) :
EntityEditorConfigScope::UNDEFINED
;
184
if
(!
EntityEditorConfigScope::isDefined
($scope))
185
{
186
$scope =
EntityEditorConfigScope::PERSONAL
;
187
}
188
189
$forAllUsers =
self::canEditOtherSettings
()
190
&& isset(
$params
[
'forAllUsers'
])
191
&&
$params
[
'forAllUsers'
] ===
'Y'
;
192
193
if
($scope ===
EntityEditorConfigScope::COMMON
)
194
{
195
\CUserOptions::DeleteOption(
196
$categoryName
,
197
$this->
prepareName
($configID, $scope),
198
true
,
199
0
200
);
201
\CUserOptions::DeleteOption(
202
$categoryName
,
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(
222
$categoryName
,
223
$this->
prepareScopeName
($configID),
224
EntityEditorConfigScope::PERSONAL
,
225
false
,
226
$this->userId
227
);
228
}
229
}
230
231
}
232
public
function
setScope
($configID, $scope)
233
{
234
if
(!
EntityEditorConfigScope::isDefined
($scope))
235
{
236
$scope =
EntityEditorConfigScope::PERSONAL
;
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
251
$categoryName
= $this->
getCategoryName
();
252
253
\CUserOptions::DeleteOptionsByName(
254
$categoryName
,
255
$this->
prepareName
($configID,
EntityEditorConfigScope::PERSONAL
)
256
);
257
\CUserOptions::DeleteOptionsByName(
$categoryName
, $this->
prepareScopeName
($configID));
258
}
259
}
Bitrix\Main\Engine\CurrentUser\get
static get()
Определения
currentuser.php:33
Bitrix\UI\Form\EntityEditorConfigScope\PERSONAL
const PERSONAL
Определения
entityeditorconfigscope.php:10
Bitrix\UI\Form\EntityEditorConfigScope\CUSTOM
const CUSTOM
Определения
entityeditorconfigscope.php:12
Bitrix\UI\Form\EntityEditorConfigScope\isDefined
static isDefined(string $scope)
Определения
entityeditorconfigscope.php:16
Bitrix\UI\Form\EntityEditorConfigScope\UNDEFINED
const UNDEFINED
Определения
entityeditorconfigscope.php:9
Bitrix\UI\Form\EntityEditorConfigScope\COMMON
const COMMON
Определения
entityeditorconfigscope.php:11
Bitrix\UI\Form\EntityEditorConfiguration
Определения
entityeditorconfiguration.php:8
Bitrix\UI\Form\EntityEditorConfiguration\reset
reset($configID, array $params)
Определения
entityeditorconfiguration.php:179
Bitrix\UI\Form\EntityEditorConfiguration\setScope
setScope($configID, $scope)
Определения
entityeditorconfiguration.php:232
Bitrix\UI\Form\EntityEditorConfiguration\prepareOptionsName
static prepareOptionsName(string $configID, string $scope, int $userScopeId=0)
Определения
entityeditorconfiguration.php:48
Bitrix\UI\Form\EntityEditorConfiguration\prepareScopeName
prepareScopeName(string $configID)
Определения
entityeditorconfiguration.php:43
Bitrix\UI\Form\EntityEditorConfiguration\getCategoryName
getCategoryName()
Определения
entityeditorconfiguration.php:23
Bitrix\UI\Form\EntityEditorConfiguration\getScope
getScope($configID)
Определения
entityeditorconfiguration.php:62
Bitrix\UI\Form\EntityEditorConfiguration\$userId
int $userId
Определения
entityeditorconfiguration.php:10
Bitrix\UI\Form\EntityEditorConfiguration\$categoryName
$categoryName
Определения
entityeditorconfiguration.php:9
Bitrix\UI\Form\EntityEditorConfiguration\canEditOtherSettings
static canEditOtherSettings()
Определения
entityeditorconfiguration.php:12
Bitrix\UI\Form\EntityEditorConfiguration\prepareName
prepareName(string $configID, string $scope)
Определения
entityeditorconfiguration.php:33
Bitrix\UI\Form\EntityEditorConfiguration\forceCommonScopeForAll
forceCommonScopeForAll($configID)
Определения
entityeditorconfiguration.php:244
Bitrix\UI\Form\EntityEditorConfiguration\__construct
__construct(string $categoryName=null, ?int $userId=null)
Определения
entityeditorconfiguration.php:17
$options
$options
Определения
commerceml2.php:49
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
Bitrix\Main\$GLOBALS
$GLOBALS['____1690880296']
Определения
license.php:1
elseif
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения
prolog_main_admin.php:393
$config
$config
Определения
quickway.php:69
$params
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения
template.php:799
$optionName
$optionName
Определения
options.php:1735
bitrix
modules
ui
lib
form
entityeditorconfiguration.php
Создано системой
1.14.0