Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
group.php
1<?php
3
6
7class Group implements Feature
8{
9 private $executiveUserId;
10 private $features = [];
11
12 const MODULE_ID = "lists";
13 const QUEUE_OPTION = "ListsGroupQueue";
14 const CHECKER_OPTION = "ListsGroupChecker_";
15 const STEPPER_OPTION = "ListsGroupStepper_";
16 const STEPPER_CLASS = GroupStepper::class;
17 const ERROR_OPTION = "ListsGroupError_";
18
19 public function __construct($executiveUserId = 0, array $features = [])
20 {
21 $this->executiveUserId = $executiveUserId;
22 $this->features = $features;
23 }
24
31 public function copy($groupId, $copiedGroupId)
32 {
33 $iblockTypeId = "lists_socnet";
34
35 $iblockIds = $this->getIblockIdsToCopy($iblockTypeId, $groupId);
36 if (!$iblockIds)
37 {
38 return;
39 }
40
41 $this->addToQueue($copiedGroupId);
42
43 Option::set(self::MODULE_ID, self::CHECKER_OPTION.$copiedGroupId, "Y");
44
45 $queueOption = [
46 "iblockTypeId" => $iblockTypeId,
47 "groupId" => $groupId,
48 "copiedGroupId" => $copiedGroupId,
49 "features" => $this->features
50 ];
51 Option::set(self::MODULE_ID, self::STEPPER_OPTION.$copiedGroupId, serialize($queueOption));
52
53 $agent = \CAgent::getList([], [
54 "MODULE_ID" => self::MODULE_ID,
55 "NAME" => GroupStepper::class."::execAgent();"
56 ])->fetch();
57 if (!$agent)
58 {
59 GroupStepper::bind(1);
60 }
61 }
62
63 private function getIblockIdsToCopy($iblockTypeId, $groupId)
64 {
65 $iblockIds = [];
66
67 $filter = [
68 "ACTIVE" => "Y",
69 "TYPE" => $iblockTypeId,
70 "CHECK_PERMISSIONS" => "N",
71 "=SOCNET_GROUP_ID" => $groupId
72 ];
73
74 $queryObject = \CIBlock::getList([], $filter);
75 while ($iblock = $queryObject->fetch())
76 {
77 $iblockIds[] = $iblock["ID"];
78 }
79
80 return $iblockIds;
81 }
82
83 private function addToQueue(int $copiedGroupId)
84 {
85 $option = Option::get(self::MODULE_ID, self::QUEUE_OPTION, "");
86 $option = ($option !== "" ? unserialize($option) : []);
87 $option = (is_array($option) ? $option : []);
88
89 $option[] = $copiedGroupId;
90 Option::set(self::MODULE_ID, self::QUEUE_OPTION, serialize($option));
91 }
92}
__construct($executiveUserId=0, array $features=[])
Definition group.php:19
copy($groupId, $copiedGroupId)
Definition group.php:31