Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
iblock.php
1<?
3
6use Bitrix\Lists\Copy\Implement\Iblock as IblockImplementer;
12
13class Iblock extends Entity
14{
15 public function copyAction()
16 {
17 $param = $this->getParamFromRequest();
18 $params = $param->getParams();
19
20 $this->checkPermission($param, IblockRight::EDIT);
21 if ($this->getErrors())
22 {
23 return null;
24 }
25
26 $manager = new Manager($params["IBLOCK_TYPE_ID"], [$params["IBLOCK_ID"]], $params["SOCNET_GROUP_ID"]);
27
28 $manager->setIblockImplementer(new IblockImplementer());
29 $manager->setFieldImplementer(new Field());
30
31 $dictionary = new Dictionary([
32 "LIST_ELEMENT_URL" => ($params["LIST_ELEMENT_URL"] ? $params["LIST_ELEMENT_URL"] : "")
33 ]);
34 $manager->setDictionary($dictionary);
35
36 $result = $manager->startCopy();
37
38 if ($result->getErrors())
39 {
40 $this->addErrors($result->getErrors());
41 return null;
42 }
43
44 $mapIdsCopiedIblock = $manager->getMapIdsCopiedEntity();
45
46 if (array_key_exists($params["IBLOCK_ID"], $mapIdsCopiedIblock))
47 {
48 return $mapIdsCopiedIblock[$params["IBLOCK_ID"]];
49 }
50 else
51 {
52 return null;
53 }
54 }
55
56 private function checkPermission(Param $param, $permission)
57 {
58 global $USER;
59 $rightParam = new RightParam($param);
60 $rightParam->setUser($USER);
61
62 $right = new Right($rightParam, new IblockRight($rightParam));
63 $right->checkPermission($permission);
64 if ($right->hasErrors())
65 {
66 $this->addErrors($right->getErrors());
67 }
68 }
69}