Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
clearcountergroupchild.php
1<?php
2
4
6use Bitrix\Iblock\Grid\Panel\UI\Actions\Helpers\ItemFinder;
16use CIBlockElement;
17
22{
23 use ItemFinder;
24
25 public static function getId(): string
26 {
28 }
29
30 public function getName(): string
31 {
32 return Loc::getMessage('IBLOCK_GRID_PANEL_UI_ACTIONS_ELEMENT_GROUP_CLEAR_COUNTER_NAME');
33 }
34
35 public function processRequest(HttpRequest $request, bool $isSelectedAllRows, ?Filter $filter = null): ?Result
36 {
37 $result = new Result();
38
39 if ($isSelectedAllRows)
40 {
41 $elementIds = $this->getElementIdsByFilter($filter);
42 }
43 else
44 {
45 $ids = $this->getRequestRows($request);
46 if (empty($ids))
47 {
48 return null;
49 }
50
51 [$elementIds,] = RowType::parseIndexList($ids);
52 $elementIds = $this->validateElementIds($elementIds);
53 }
54 if ($elementIds)
55 {
56 $result->addErrors(
57 $this->processClearCounterElements($elementIds)->getErrors()
58 );
59 }
60
61 return $result;
62 }
63
64 protected function getOnchange(): Onchange
65 {
66 return new Onchange([
67 [
68 'ACTION' => Actions::RESET_CONTROLS,
69 ],
70 [
71 'ACTION' => Actions::CREATE,
72 'DATA' => [
73 (new Snippet)->getSendSelectedButton(),
74 ],
75 ],
76 ]);
77 }
78
79 private function processClearCounterElements(array $ids): Result
80 {
81 $result = new Result();
82 $entity = new CIBlockElement();
83
84 foreach ($ids as $id)
85 {
86 if (!$this->getIblockRightsChecker()->canEditElement($id))
87 {
88 $message = Loc::getMessage('IBLOCK_GRID_PANEL_ELEMENT_ACTION_PANEL_ERROR_ACCESS_DENIED', [
89 '#ID#' => $id,
90 ]);
91 $result->addError(
92 new Error($message)
93 );
94
95 continue;
96 }
97
98 $fields = [
99 'SHOW_COUNTER' => false,
100 'SHOW_COUNTER_START' => false,
101 ];
102 $updateResult = $entity->Update($id, $fields);
103 if (!$updateResult && $entity->getLastError())
104 {
105 $result->addError(
106 new Error($entity->getLastError())
107 );
108 }
109 }
110
111 return $result;
112 }
113}
processRequest(HttpRequest $request, bool $isSelectedAllRows, ?Filter $filter=null)
static parseIndexList(array $ids)
Definition rowtype.php:52
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29