Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
changeactivehandler.php
1<?php
2
4
12use CIBlockElement;
13use CIBlockSection;
14
15trait ChangeActiveHandler
16{
17 use ItemFinder;
18
19 abstract protected function getIblockRightsChecker(): IblockRightsChecker;
20
21 protected function processSetActive(HttpRequest $request, bool $isSelectedAllRows, ?Filter $filter, bool $isActivate): ?Result
22 {
23 $result = new Result();
24
25 [$elementIds, $sectionIds] = $this->prepareItemIds($request, $isSelectedAllRows, $filter);
26
27 if ($elementIds)
28 {
29 $result->addErrors(
30 $this->processSetActiveElements($elementIds, $isActivate)->getErrors()
31 );
32 }
33
34 if ($sectionIds)
35 {
36 $result->addErrors(
37 $this->processSetActiveSections($sectionIds, $isActivate)->getErrors()
38 );
39 }
40
41 return $result;
42 }
43
44 private function processSetActiveElements(array $ids, bool $isActivate): Result
45 {
46 $result = new Result();
47 $entity = new CIBlockElement();
48
49 foreach ($ids as $id)
50 {
51 if (!$this->getIblockRightsChecker()->canEditElement($id))
52 {
53 $message = Loc::getMessage('IBLOCK_GRID_PANEL_UI_CHANGE_ACTIVE_HANDLER_ACCESS_DENIED_ELEMENT', [
54 '#ID#' => $id,
55 ]);
56 $result->addError(
57 new Error($message)
58 );
59
60 continue;
61 }
62
63 $updateResult = $entity->Update($id, [
64 'ACTIVE' => $isActivate ? 'Y' : 'N',
65 ]);
66 if (!$updateResult && $entity->getLastError())
67 {
68 $result->addError(
69 new Error($entity->getLastError())
70 );
71 }
72 }
73
74 return $result;
75 }
76
77 private function processSetActiveSections(array $ids, bool $isActivate): Result
78 {
79 $result = new Result();
80 $entity = new CIBlockSection();
81
82 foreach ($ids as $id)
83 {
84 if (!$this->getIblockRightsChecker()->canEditSection($id))
85 {
86 $message = Loc::getMessage('IBLOCK_GRID_PANEL_UI_CHANGE_ACTIVE_HANDLER_ACCESS_DENIED_SECTION', [
87 '#ID#' => $id,
88 ]);
89 $result->addError(
90 new Error($message)
91 );
92
93 continue;
94 }
95
96 $updateResult = $entity->Update($id, [
97 'ACTIVE' => $isActivate ? 'Y' : 'N',
98 ]);
99 if (!$updateResult && $entity->getLastError())
100 {
101 $result->addError(
102 new Error($entity->getLastError())
103 );
104 }
105 }
106
107 return $result;
108 }
109}
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
processSetActive(HttpRequest $request, bool $isSelectedAllRows, ?Filter $filter, bool $isActivate)
prepareItemIds(HttpRequest $request, bool $isSelectedAllRows, ?Filter $filter=null)