Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
group.php
1<?php
3
11
12class Group implements Feature
13{
14 const MODULE_ID = "landing";
15 const QUEUE_OPTION = "LandingGroupQueue";
16 const CHECKER_OPTION = "LandingGroupChecker_";
17 const STEPPER_OPTION = "LandingGroupStepper_";
18 const STEPPER_CLASS = GroupStepper::class;
19 const ERROR_OPTION = "LandingGroupError_";
20
21 private $executiveUserId;
22 private $features = [];
23
24 public function __construct($executiveUserId = 0, array $features = [])
25 {
26 $this->executiveUserId = $executiveUserId;
27 $this->features = $features;
28 }
29
36 public function copy($groupId, $copiedGroupId)
37 {
39 Landing\Site\Type::setScope(Landing\Site\Type::SCOPE_CODE_GROUP);
40 $binder = Landing\Connector\SocialNetwork::getBindingRow($groupId);
41 if (!$binder)
42 {
43 return;
44 }
45
46 $siteId = (int) $binder['ENTITY_ID'];
47
48 $addSiteResult = Landing\Site::copy($siteId);
49 if (!$addSiteResult->isSuccess())
50 {
51 return;
52 }
54 $copiedSiteId = (int) $addSiteResult->getId();
55
56 // copy folders
57 $folderMapIds = [];
58 Landing\Site::copyFolders($siteId, $copiedSiteId, $folderMapIds);
59
60 $folderIndexIds = [];
61 $res = Folder::getList([
62 'select' => [
63 'ID', 'INDEX_ID'
64 ],
65 'filter' => [
66 'SITE_ID' => $siteId,
67 '!INDEX_ID' => null
68 ]
69 ]);
70 while ($row = $res->fetch())
71 {
72 $folderIndexIds[$row['ID']] = $row['INDEX_ID'];
73 }
74
75 $this->addToQueue($copiedGroupId);
76
77 Option::set(self::MODULE_ID, self::CHECKER_OPTION.$copiedGroupId, "Y");
78
79 $dataToCopy = [
80 "executiveUserId" => $this->executiveUserId,
81 "groupId" => $groupId,
82 "copiedGroupId" => $copiedGroupId,
83 "siteId" => $siteId,
84 "copiedSiteId" => $copiedSiteId,
85 "folderMapIds" => $folderMapIds,
86 "folderIndexIds" => $folderIndexIds
87 ];
88 Option::set(self::MODULE_ID, self::STEPPER_OPTION.$copiedGroupId, serialize($dataToCopy));
89
90 GroupStepper::bind(1);
91
92 $binder = new Landing\Binding\Group($copiedGroupId);
93 if (!$binder->isForbiddenBindingAction())
94 {
95 $binder->bindSite($copiedSiteId);
96 }
97 }
98
99 private function addToQueue(int $copiedGroupId)
100 {
101 $option = Option::get(self::MODULE_ID, self::QUEUE_OPTION, "");
102 $option = ($option !== "" ? unserialize($option, ['allowed_classes' => false]) : []);
103 $option = (is_array($option) ? $option : []);
104
105 $option[] = $copiedGroupId;
106 Option::set(self::MODULE_ID, self::QUEUE_OPTION, serialize($option));
107 }
108}
__construct($executiveUserId=0, array $features=[])
Definition group.php:24
static setEditMode(bool $mode=true)
Definition hook.php:232