Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
changeactivehandler.php
1<?php
2
4
10use CIBlockElement;
11
12trait ChangeActiveHandler
13{
14 abstract protected function getSetActiveValue(): string;
15
16 abstract protected function getIblockRightsChecker(): IblockRightsChecker;
17
18 public function processRequest(HttpRequest $request): ?Result
19 {
20 $id = $request->getPost('id');
21 if (empty($id) || !is_numeric($id))
22 {
23 return null;
24 }
25 $id = (int)$id;
26
27 if (!$this->getIblockRightsChecker()->canEditElement($id))
28 {
29 throw new AccessDeniedException('Cant edit element');
30 }
31
32 $result = new Result();
33
34 $entity = new CIBlockElement();
35 $updateResult = $entity->Update($id, [
36 'ACTIVE' => $this->getSetActiveValue(),
37 ]);
38 if (!$updateResult)
39 {
40 $message = $entity->getLastError() ?: 'Cant update element';
41 $result->addError(new Error($message));
42 }
43
44 return $result;
45 }
46}