Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
groupmanager.php
1<?php
3
10use Bitrix\Socialnetwork\Copy\UserToGroup as UserToGroupCopier;
11use Bitrix\Socialnetwork\Copy\Implement\Group as GroupImplementer;
13
15{
16 private $executiveUserId;
17 private $groupIdsToCopy = [];
18
19 private $changedFields = [];
20
24 private $features = [];
25
26 private $ufIgnoreList = [];
27
28 private $projectTerm = [];
29
30 private $markerUsers = true;
31
32 private $result;
33 private $mapIdsCopiedGroups = [];
34
35 public function __construct($executiveUserId, array $groupIdsToCopy)
36 {
37 $this->executiveUserId = $executiveUserId;
38 $this->groupIdsToCopy = $groupIdsToCopy;
39
40 $this->result = new Result();
41 }
42
48 public function setFeature(Feature $feature)
49 {
50 $this->features[] = $feature;
51 }
52
58 public function setUfIgnoreList(array $ufIgnoreList): void
59 {
60 $this->ufIgnoreList = $ufIgnoreList;
61 }
62
68 public function setProjectTerm(array $projectTerm)
69 {
70 $this->projectTerm = $projectTerm;
71 }
72
73 public function setMarkerUsers(bool $markerUsers): void
74 {
75 $this->markerUsers = $markerUsers;
76 }
77
78 public function setChangedFields($changedFields)
79 {
80 $this->changedFields = array_merge($this->changedFields, $changedFields);
81 }
82
83 public function startCopy()
84 {
85 $containerCollection = $this->getContainerCollection();
86
87 $groupImplementer = $this->getGroupImplementer();
88 $groupCopier = $this->getGroupCopier($groupImplementer);
89
90 if ($this->markerUsers)
91 {
92 $userToGroupImplementer = $this->getUserToGroupImplementer();
93 $groupCopier->addEntityToCopy($this->getUserToGroupCopier($userToGroupImplementer));
94 }
95
96 $this->result = $groupCopier->copy($containerCollection);
97 $this->mapIdsCopiedGroups = $groupCopier->getMapIdsCopiedEntity();
98
99 return $this->result;
100 }
101
107 public function getMapIdsCopiedGroups(): array
108 {
109 return $this->mapIdsCopiedGroups;
110 }
111
112 private function getContainerCollection()
113 {
114 $containerCollection = new ContainerCollection();
115
116 foreach ($this->groupIdsToCopy as $groupId)
117 {
118 $containerCollection[] = new Container($groupId);
119 }
120
121 return $containerCollection;
122 }
123
124 private function getGroupImplementer()
125 {
126 global $USER_FIELD_MANAGER;
127
128 //todo application to implementer for get errors
129 $groupImplementer = new GroupImplementer($this->executiveUserId);
130 $groupImplementer->setChangedFields($this->changedFields);
131 $groupImplementer->setUserFieldManager($USER_FIELD_MANAGER);
132 $groupImplementer->setUfIgnoreList($this->ufIgnoreList);
133 $groupImplementer->setExecutiveUserId($this->executiveUserId);
134 $groupImplementer->setProjectTerm($this->projectTerm);
135
136 if (!$this->markerUsers && $this->changedFields["MODERATORS"])
137 {
138 $userGroupHelper = new UserGroupHelper($this->executiveUserId, $this->changedFields["MODERATORS"]);
139 $groupImplementer->setUserGroupHelper($userGroupHelper);
140 }
141
142 foreach ($this->features as $feature)
143 {
144 $groupImplementer->setFeature($feature);
145 }
146
147 return $groupImplementer;
148 }
149
150 private function getGroupCopier($groupImplementer)
151 {
152 return new EntityCopier($groupImplementer);
153 }
154
155 private function getUserToGroupImplementer()
156 {
157 $userGroupImplementer = new UserToGroup();
158 $userGroupImplementer->setUfIgnoreList($this->ufIgnoreList);
159 if ($this->changedFields["MODERATORS"])
160 {
161 $userGroupHelper = new UserGroupHelper($this->executiveUserId, $this->changedFields["MODERATORS"]);
162 $userGroupImplementer->setUserGroupHelper($userGroupHelper);
163 }
164 return $userGroupImplementer;
165 }
166
167 private function getUserToGroupCopier($userToGroupImplementer)
168 {
169 return new UserToGroupCopier($userToGroupImplementer);
170 }
171}
__construct($executiveUserId, array $groupIdsToCopy)