Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
clearcounteritem.php
1<?php
2
4
10use CIBlockElement;
11use CUtil;
12
13final 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}
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29