1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
createcodeitem.php
См. документацию.
1
<?php
2
3
namespace
Bitrix\Iblock\Grid\Row\Actions\Item;
4
5
use Bitrix\Iblock\ElementTable;
6
use Bitrix\Iblock\Grid\Helpers\CodeTranslator;
7
use Bitrix\Iblock\Grid\RowType;
8
use Bitrix\Iblock\SectionTable;
9
use Bitrix\Main\Error;
10
use Bitrix\Main\HttpRequest;
11
use Bitrix\Main\Localization\Loc;
12
use Bitrix\Main\Result;
13
use CIBlockElement;
14
use CIBlockSection;
15
use CUtil;
16
17
final
class
CreateCodeItem
extends
BaseItem
18
{
19
use CodeTranslator;
20
21
public
static
function
getId
(): string
22
{
23
return
'code_translit'
;
24
}
25
26
protected
function
getText
(): string
27
{
28
return
Loc::getMessage(
'IBLOCK_GRID_ROW_ACTIONS_CREATE_CODE_NAME_MSGVER_1'
);
29
}
30
31
public
function
getControl
(
array
$rawFields): ?
array
32
{
33
if
(empty($rawFields[
'ID'
]))
34
{
35
return
null
;
36
}
37
38
$rowId = (int)$rawFields[
'ID'
];
39
$rowType = (string)($rawFields[
'ROW_TYPE'
] ??
RowType::ELEMENT
);
40
41
if
($rowType ===
RowType::SECTION
)
42
{
43
if
(
44
empty($this->getSectionTranslitSettings())
45
|| !$this->
getIblockRightsChecker
()->canEditSection($rowId)
46
)
47
{
48
return
null
;
49
}
50
}
51
elseif
($rowType ===
RowType::ELEMENT
)
52
{
53
if
(
54
empty($this->getElementTranslitSettings())
55
|| !$this->
getIblockRightsChecker
()->canEditElement($rowId)
56
)
57
{
58
return
null
;
59
}
60
}
61
else
62
{
63
// unknown type
64
return
null
;
65
}
66
67
$actionId =
self::getId
();
68
$data
= CUtil::PhpToJSObject([
69
'id'
=>
RowType::getIndex
($rowType, $rowId),
70
]);
71
72
if
($rowType ===
RowType::SECTION
)
73
{
74
$confirmMessageTitle = \CUtil::JSEscape(Loc::getMessage(
'IBLOCK_GRID_ROW_ACTIONS_CREATE_CODE_SECTION_CONFIRM_TITLE'
));
75
$confirmMessageContent = \CUtil::JSEscape(Loc::getMessage(
'IBLOCK_GRID_ROW_ACTIONS_CREATE_CODE_SECTION_CONFIRM_CONTENT'
));
76
}
77
else
78
{
79
$confirmMessageTitle = \CUtil::JSEscape(Loc::getMessage(
'IBLOCK_GRID_ROW_ACTIONS_CREATE_CODE_ELEMENT_CONFIRM_TITLE'
));
80
$confirmMessageContent = \CUtil::JSEscape(Loc::getMessage(
'IBLOCK_GRID_ROW_ACTIONS_CREATE_CODE_ELEMENT_CONFIRM_CONTENT'
));
81
}
82
83
$confirmButtonMessage = \CUtil::JSEscape(
84
Loc::getMessage(
'IBLOCK_GRID_ROW_ACTIONS_CREATE_CODE_CONFIRM_BUTTON'
)
85
);
86
$backButtonMessage = \CUtil::JSEscape(
87
Loc::getMessage(
'IBLOCK_GRID_ROW_ACTIONS_CREATE_CODE_BACK_BUTTON'
)
88
);
89
90
$this->onclick =
"IblockGridInstance.sendMediumPopupWithConfirm("
91
.
"'{$actionId}', "
92
.
"{$data}, "
93
.
"'{$confirmMessageTitle}', "
94
.
"'{$confirmMessageContent}', "
95
.
"'{$confirmButtonMessage}', "
96
.
"'{$backButtonMessage}')"
;
97
98
return
parent::getControl($rawFields);
99
}
100
101
public
function
processRequest
(
HttpRequest
$request
): ?
Result
102
{
103
$result
=
new
Result
();
104
105
$rowIndex = (string)
$request
->get(
'id'
);
106
if
(empty($rowIndex))
107
{
108
return
$result
;
109
}
110
111
$index =
RowType::parseIndex
($rowIndex);
112
if
($index ===
null
)
113
{
114
return
$result
;
115
}
116
[
$type
, $id] = $index;
117
118
if
(
$type
===
RowType::SECTION
)
119
{
120
$result
->addErrors(
121
$this->processCodeTranslitSection($id)->
getErrors
()
122
);
123
}
124
elseif
(
$type
===
RowType::ELEMENT
)
125
{
126
$result
->addErrors(
127
$this->processCodeTranslitElement($id)->
getErrors
()
128
);
129
}
130
131
return
$result
;
132
}
133
139
private
function
processCodeTranslitElement(
int
$id):
Result
140
{
141
$result
=
new
Result
();
142
143
if
(!$this->
getIblockRightsChecker
()->canEditElement($id))
144
{
145
$message
= Loc::getMessage(
'IBLOCK_GRID_ROW_ACTIONS_CREATE_CODE_ERROR_ACCESS_DENIED_ELEMENT'
, [
146
'#ID#'
=> $id,
147
]);
148
$result
->addError(
149
new
Error
(
$message
)
150
);
151
152
return
$result
;
153
}
154
155
$row =
ElementTable::getRow
([
156
'select'
=> [
157
'ID'
,
158
'NAME'
,
159
],
160
'filter'
=> [
161
'=ID'
=> $id,
162
'=IBLOCK_ID'
=> $this->
getIblockId
(),
163
],
164
]);
165
if
(empty($row))
166
{
167
return
$result
;
168
}
169
170
$entity
=
new
CIBlockElement
();
171
$translitSettings = $this->getElementTranslitSettings();
172
173
$fields
= [
174
'CODE'
=> CUtil::translit(
175
$row[
'NAME'
],
176
LANGUAGE_ID,
177
$translitSettings
178
),
179
];
180
$updateResult =
$entity
->Update($id,
$fields
);
181
if
(!$updateResult &&
$entity
->getLastError())
182
{
183
$result
->addError(
184
new
Error
(
$entity
->getLastError())
185
);
186
}
187
188
return
$result
;
189
}
190
196
private
function
processCodeTranslitSection(
int
$id):
Result
197
{
198
$result
=
new
Result
();
199
200
if
(!$this->
getIblockRightsChecker
()->canEditSection($id))
201
{
202
$message
= Loc::getMessage(
'IBLOCK_GRID_ROW_ACTIONS_CREATE_CODE_ERROR_ACCESS_DENIED_SECTION'
, [
203
'#ID#'
=> $id,
204
]);
205
$result
->addError(
206
new
Error
(
$message
)
207
);
208
209
return
$result
;
210
}
211
212
$row =
SectionTable::getRow
([
213
'select'
=> [
214
'ID'
,
215
'NAME'
,
216
],
217
'filter'
=> [
218
'=ID'
=> $id,
219
'=IBLOCK_ID'
=> $this->
getIblockId
(),
220
],
221
]);
222
if
(empty($row))
223
{
224
return
$result
;
225
}
226
227
$entity
=
new
CIBlockSection();
228
$translitSettings = $this->getSectionTranslitSettings();
229
230
$fields
= [
231
'CODE'
=> CUtil::translit(
232
$row[
'NAME'
],
233
LANGUAGE_ID,
234
$translitSettings
235
),
236
];
237
$updateResult =
$entity
->Update($id,
$fields
);
238
if
(!$updateResult &&
$entity
->getLastError())
239
{
240
$result
->addError(
241
new
Error(
$entity
->getLastError())
242
);
243
}
244
245
return
$result
;
246
}
247
}
$type
$type
Определения
options.php:106
$request
if(!Loader::includeModule('catalog')) if(!AccessController::getCurrent() ->check(ActionDictionary::ACTION_PRICE_EDIT)) if(!check_bitrix_sessid()) $request
Определения
catalog_reindex.php:36
Bitrix\Iblock\Grid\Row\Actions\Item\BaseItem
Определения
baseitem.php:8
Bitrix\Iblock\Grid\Row\Actions\Item\BaseItem\getIblockId
getIblockId()
Определения
baseitem.php:18
Bitrix\Iblock\Grid\Row\Actions\Item\BaseItem\getIblockRightsChecker
getIblockRightsChecker()
Определения
baseitem.php:23
Bitrix\Iblock\Grid\Row\Actions\Item\CreateCodeItem
Определения
createcodeitem.php:18
Bitrix\Iblock\Grid\Row\Actions\Item\CreateCodeItem\getControl
getControl(array $rawFields)
Определения
createcodeitem.php:31
Bitrix\Iblock\Grid\Row\Actions\Item\CreateCodeItem\getText
getText()
Определения
createcodeitem.php:26
Bitrix\Iblock\Grid\Row\Actions\Item\CreateCodeItem\getId
static getId()
Определения
createcodeitem.php:21
Bitrix\Iblock\Grid\Row\Actions\Item\CreateCodeItem\processRequest
processRequest(HttpRequest $request)
Определения
createcodeitem.php:101
Bitrix\Iblock\Grid\RowType\ELEMENT
const ELEMENT
Определения
rowtype.php:7
Bitrix\Iblock\Grid\RowType\getIndex
static getIndex(string $type, string|int $id)
Определения
rowtype.php:15
Bitrix\Iblock\Grid\RowType\SECTION
const SECTION
Определения
rowtype.php:8
Bitrix\Iblock\Grid\RowType\parseIndex
static parseIndex(string $index)
Определения
rowtype.php:25
Bitrix\Main\Error
Определения
error.php:15
Bitrix\Main\HttpRequest
Определения
httprequest.php:20
Bitrix\Main\ORM\Data\DataManager\getRow
static getRow(array $parameters)
Определения
datamanager.php:398
Bitrix\Main\ORM\Data\Result
Определения
result.php:16
CIBlockElement
Определения
iblockelement.php:9
$data
$data['IS_AVAILABLE']
Определения
.description.php:13
array
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения
file_new.php:804
$result
$result
Определения
get_property_values.php:14
$entity
$entity
Определения
group_bizproc_workflow_delete.php:17
Bitrix\Main\getErrors
getErrors()
Определения
errorableimplementation.php:34
$message
$message
Определения
payment.php:8
elseif
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения
prolog_main_admin.php:393
$fields
$fields
Определения
yandex_run.php:501
bitrix
modules
iblock
lib
grid
row
actions
item
createcodeitem.php
Создано системой
1.14.0