Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
removeactionsitem.php
1<?php
2
4
7use Bitrix\Iblock\Grid\Panel\UI\Actions\Helpers\ItemFinder;
14use CIBlockElement;
15use CIBlockSection;
16use CMain;
17
19{
20 use ItemFinder;
21
22 private int $iblockId;
23 private IblockRightsChecker $rights;
24 private string $listMode;
25
26 public static function getId(): string
27 {
28 return ActionType::DELETE;
29 }
30
31 public function __construct(int $iblockId, IblockRightsChecker $rights, string $listMode)
32 {
33 $this->iblockId = $iblockId;
34 $this->rights = $rights;
35 $this->listMode = $listMode;
36 }
37
38 final protected function getIblockId(): int
39 {
40 return $this->iblockId;
41 }
42
43 final protected function getListMode(): string
44 {
45 return $this->listMode;
46 }
47
48 public function processRequest(HttpRequest $request, bool $isSelectedAllRows, ?Filter $filter = null): ?Result
49 {
50 $result = new Result();
51
52 [$elementIds, $sectionIds] = $this->prepareItemIds($request, $isSelectedAllRows, $filter);
53
54 if ($elementIds)
55 {
56 $result->addErrors(
57 $this->removeElements($elementIds)->getErrors()
58 );
59 }
60
61 if ($sectionIds)
62 {
63 $result->addErrors(
64 $this->removeSections($sectionIds)->getErrors()
65 );
66 }
67
68 return $result;
69 }
70
71 private function removeElements(array $ids): Result
72 {
76 global $APPLICATION;
77
78 $result = new Result();
79
80 foreach ($ids as $id)
81 {
82 if (!$this->rights->canDeleteElement($id))
83 {
84 $message = Loc::getMessage('IBLOCK_GRID_PANEL_UI_REMOVE_ACTIONS_ITEM_ACCESS_DENIED', [
85 '#ID#' => $id,
86 ]);
87 $result->addError(
88 new Error($message)
89 );
90
91 continue;
92 }
93
94 if (!CIBlockElement::Delete($id))
95 {
96 $ex = $APPLICATION->GetException();
97 if ($ex)
98 {
99 $result->addError(new Error(
100 $ex->GetString()
101 ));
102 }
103 else
104 {
105 $result->addError(new Error(
107 'IBLOCK_GRID_PANEL_UI_ACTIONS_ITEM_REMOVE_ERROR_DELETE',
108 [
109 '#ID#' => $id,
110 ]
111 )
112 ));
113 }
114 unset($ex);
115 }
116 }
117
118 return $result;
119 }
120
121 private function removeSections(array $ids): Result
122 {
126 global $APPLICATION;
127
128 $result = new Result();
129
130 foreach ($ids as $id)
131 {
132 if (!$this->rights->canDeleteSection($id))
133 {
134 $message = Loc::getMessage('IBLOCK_GRID_PANEL_UI_REMOVE_ACTIONS_ITEM_ACCESS_DENIED', [
135 '#ID#' => $id,
136 ]);
137 $result->addError(
138 new Error($message)
139 );
140
141 continue;
142 }
143
144 if (!CIBlockSection::Delete($id))
145 {
146 $ex = $APPLICATION->GetException();
147 if ($ex)
148 {
149 $result->addError(new Error(
150 $ex->GetString()
151 ));
152 }
153 else
154 {
155 $result->addError(new Error(
157 'IBLOCK_GRID_PANEL_UI_ACTIONS_ITEM_REMOVE_ERROR_DELETE',
158 [
159 '#ID#' => $id,
160 ]
161 )
162 ));
163 }
164 unset($ex);
165 }
166 }
167
168 return $result;
169 }
170}
processRequest(HttpRequest $request, bool $isSelectedAllRows, ?Filter $filter=null)
__construct(int $iblockId, IblockRightsChecker $rights, string $listMode)
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29