Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
clearcounteritem.php
1
<?php
2
3
namespace
Bitrix\Iblock\Grid\Row\Actions\Item
;
4
5
use
Bitrix\Main\AccessDeniedException
;
6
use
Bitrix\Main\Error
;
7
use
Bitrix\Main\HttpRequest
;
8
use
Bitrix\Main\Localization\Loc
;
9
use
Bitrix\Main\Result
;
10
use CIBlockElement;
11
use CUtil;
12
13
final
class
ClearCounterItem
extends
BaseItem
14
{
15
public
static
function
getId
(): ?string
16
{
17
return
'clear_counter'
;
18
}
19
20
protected
function
getText
(): string
21
{
22
return
Loc::getMessage
(
'IBLOCK_GRID_ROW_ACTIONS_CLEAR_COUNTER_NAME'
);
23
}
24
25
public
function
getControl
(array $rawFields): ?array
26
{
27
$id = (int)($rawFields[
'ID'
] ?? 0);
28
if
($id <= 0)
29
{
30
return
null
;
31
}
32
33
$actionId =
self::getId
();
34
$data = CUtil::PhpToJSObject([
35
'id'
=> $id,
36
]);
37
38
$this->onclick =
"IblockGridInstance.sendRowAction('{$actionId}', {$data})"
;
39
40
return
parent::getControl($rawFields);
41
}
42
43
public
function
processRequest
(
HttpRequest
$request): ?
Result
44
{
45
$id = $request->getPost(
'id'
);
46
if
(empty($id) || !is_numeric($id))
47
{
48
return
null
;
49
}
50
$id = (int)$id;
51
52
if
(!$this->
getIblockRightsChecker
()->canEditElement($id))
53
{
54
throw
new
AccessDeniedException
(
'Cannot edit element'
);
55
}
56
57
$result =
new
Result
();
58
59
$entity =
new
CIBlockElement();
60
$updateResult = $entity->Update($id, [
61
'SHOW_COUNTER'
=>
false
,
62
'SHOW_COUNTER_START'
=>
false
,
63
]);
64
if
(!$updateResult)
65
{
66
$message = $entity->getLastError() ?:
'Cannot update element'
;
67
$result->addError(
new
Error
($message));
68
}
69
70
return
$result;
71
}
72
}
Bitrix\Iblock\Grid\Row\Actions\Item\BaseItem
Definition
baseitem.php:8
Bitrix\Iblock\Grid\Row\Actions\Item\BaseItem\getIblockRightsChecker
getIblockRightsChecker()
Definition
baseitem.php:23
Bitrix\Iblock\Grid\Row\Actions\Item\ClearCounterItem
Definition
clearcounteritem.php:14
Bitrix\Iblock\Grid\Row\Actions\Item\ClearCounterItem\getControl
getControl(array $rawFields)
Definition
clearcounteritem.php:25
Bitrix\Iblock\Grid\Row\Actions\Item\ClearCounterItem\getText
getText()
Definition
clearcounteritem.php:20
Bitrix\Iblock\Grid\Row\Actions\Item\ClearCounterItem\getId
static getId()
Definition
clearcounteritem.php:15
Bitrix\Iblock\Grid\Row\Actions\Item\ClearCounterItem\processRequest
processRequest(HttpRequest $request)
Definition
clearcounteritem.php:43
Bitrix\Main\AccessDeniedException
Definition
exception.php:214
Bitrix\Main\Error
Definition
error.php:14
Bitrix\Main\HttpRequest
Definition
httprequest.php:20
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Definition
loc.php:29
Bitrix\Main\ORM\Data\Result
Definition
result.php:16
Bitrix\Main\Result
Definition
result.php:14
Bitrix\Iblock\Grid\Row\Actions\Item
Definition
activateelementitem.php:3
modules
iblock
lib
grid
row
actions
item
clearcounteritem.php
Создано системой
1.10.0