20 private $changedFields = [];
25 private $features = [];
27 private $projectTerm = [];
32 private $userGroupHelper =
null;
36 parent::__construct();
48 $this->features[] = $feature;
58 $this->projectTerm = $projectTerm;
63 $this->changedFields = array_merge($this->changedFields, $changedFields);
73 $this->userGroupHelper = $userGroupHelper;
78 $groupId = \CSocNetGroup::createGroup($this->executiveUserId, $fields,
false);
84 $this->result->addError(
86 $APPLICATION->GetException()
87 ? $APPLICATION->GetException()->GetString()
96 \CSocNetFeatures::setFeature(SONET_ENTITY_GROUP, $groupId,
"files",
true,
false);
98 if (isset($fields[
"OWNER_ID"]))
100 if (\CSocNetUserToGroup::setOwner($fields[
"OWNER_ID"], $groupId))
104 $dictionary[
"NEW_OWNER_ID"] = $fields[
"OWNER_ID"];
110 if ($this->userGroupHelper)
112 $this->userGroupHelper->changeModerators($groupId);
123 $queryObject = \CSocNetGroup::getList(
124 [
"ID" =>
"DESC"], [
"ID" => (
int) $entityId],
false,
false, [
"*"]);
125 while ($group = $queryObject->fetch())
127 if ($group[
"IMAGE_ID"] > 0)
129 $group[
"IMAGE_ID"] = \CFile::makeFileArray($group[
"IMAGE_ID"]);
131 if (!empty($group[
'NAME']))
135 if (!empty($group[
'DESCRIPTION']))
137 $group[
'DESCRIPTION'] =
Emoji::decode($group[
'DESCRIPTION']);
140 $fields[
"SITE_ID"] = $this->getSiteIds($group[
"ID"]);
150 if (!empty($this->changedFields))
152 $fields = $this->changeFields($fields);
155 if ($fields[
"PROJECT"] ==
"Y" && $this->projectTerm)
157 if (!empty($this->projectTerm[
"start_point"]) && !empty($this->projectTerm[
"end_point"]))
159 $fields = $this->getFieldsProjectTerm($fields);
161 elseif (!empty($this->projectTerm[
"start_point"]))
163 $fields = $this->getRecountFieldsProjectTerm($fields, $this->projectTerm[
"start_point"]);
167 $fields = $this->prepareExtranetFields($fields);
169 unset($fields[
"ID"]);
170 unset($fields[
"DATE_CREATE"]);
171 unset($fields[
"DATE_UPDATE"]);
172 unset($fields[
"DATE_ACTIVITY"]);
187 $copiedGroupId = (int) $copiedGroupId;
193 $this->
copyUfFields($groupId, $copiedGroupId,
"SONET_GROUP");
195 foreach ($this->features as $feature)
199 if (method_exists($feature,
"setProjectTerm"))
201 $feature->setProjectTerm($this->projectTerm);
203 $feature->copy($groupId, $copiedGroupId);
206 $this->copyFeatures($groupId, $copiedGroupId);
211 private function changeFields(array $fields)
213 foreach ($this->changedFields as $fieldId => $fieldValue)
215 if (array_key_exists($fieldId, $fields))
217 $fields[$fieldId] = $fieldValue;
224 private function getFieldsProjectTerm($fields)
232 $startPoint = $this->projectTerm[
"start_point"];
233 $endPoint = $this->projectTerm[
"end_point"];
235 $phpDateFormat = \Bitrix\Main\Type\DateTime::convertFormatToPhp(FORMAT_DATE);
237 $newDateStart = new \DateTime($startPoint);
238 $fields[
"PROJECT_DATE_START"] = $newDateStart->format($phpDateFormat);
240 $newDateEnd = new \DateTime($endPoint);
241 $fields[
"PROJECT_DATE_FINISH"] = $newDateEnd->format($phpDateFormat);
243 $projectTerm[
"start_point"] = $fields[
"PROJECT_DATE_START"];
244 $projectTerm[
"end_point"] = $fields[
"PROJECT_DATE_FINISH"];
248 catch (\Exception $exception)
250 $fields[
"PROJECT_DATE_FINISH"] =
"";
251 $this->result->addError(
new Error($exception->getMessage()));
257 private function getRecountFieldsProjectTerm($fields, $startPoint)
263 "old_start_point" => $fields[
"PROJECT_DATE_START"]
266 $oldDateStart = new \DateTime($fields[
"PROJECT_DATE_START"]);
268 $phpDateFormat = \Bitrix\Main\Type\DateTime::convertFormatToPhp(FORMAT_DATE);
270 $newDateStart = new \DateTime($startPoint);
271 $fields[
"PROJECT_DATE_START"] = $newDateStart->format($phpDateFormat);
273 if (!empty($fields[
"PROJECT_DATE_FINISH"]))
275 $dateFinish = new \DateTime($fields[
"PROJECT_DATE_FINISH"]);
276 $interval = new \DateInterval(
"PT".($dateFinish->getTimestamp()-$oldDateStart->getTimestamp()).
"S");
277 $newDateStart->add($interval);
278 $fields[
"PROJECT_DATE_FINISH"] = $newDateStart->format($phpDateFormat);
281 $projectTerm[
"start_point"] = $fields[
"PROJECT_DATE_START"];
282 $projectTerm[
"end_point"] = $fields[
"PROJECT_DATE_FINISH"];
286 catch (\Exception $exception)
288 $fields[
"PROJECT_DATE_FINISH"] =
"";
289 $this->result->addError(
new Error($exception->getMessage()));
295 private function prepareExtranetFields(array $fields)
297 if (!Loader::includeModule(
"extranet") || !$this->isExtranetSite($fields[
"SITE_ID"]))
300 Loader::includeModule(
"extranet") &&
301 !$this->isExtranetSite($fields[
"SITE_ID"]) &&
302 $this->changedFields[
"IS_EXTRANET_GROUP"] ==
"Y"
305 $fields[
"SITE_ID"][] = \CExtranet::getExtranetSiteID();
306 $fields[
"VISIBLE"] =
"N";
307 $fields[
"OPENED"] =
"N";
310 elseif (Loader::includeModule(
"extranet") && $this->isExtranetSite($fields[
"SITE_ID"]))
312 $fields[
"SITE_ID"] = $this->getSiteIds($fields[
"ID"]);
318 private function getSiteIds(
int $groupId): array
322 $queryObject = WorkgroupSiteTable::getList([
324 "GROUP_ID" => $groupId
326 "select" => [
"SITE_ID"]
328 while ($workGroupSite = $queryObject->fetch())
330 $siteIds[] = $workGroupSite[
"SITE_ID"];
332 $siteIds = array_unique($siteIds);
337 private function isExtranetSite(array $siteIds): bool
339 foreach ($siteIds as $siteId)
341 if (\CExtranet::isExtranetSite($siteId))
350 private function copyFeatures(
int $groupId,
int $copiedGroupId): void
352 $featuresMapIds = [];
354 $queryObject = \CSocNetFeatures::getList(
357 "ENTITY_ID" => $groupId,
358 "ENTITY_TYPE" => SONET_ENTITY_GROUP
361 while ($feature = $queryObject->fetch())
363 $copiedFeatureId = \CSocNetFeatures::setFeature(
367 ($feature[
"ACTIVE"] ==
"Y"),
371 if (is_numeric($copiedFeatureId))
373 $featuresMapIds[$feature[
"ID"]] = $copiedFeatureId;
379 $this->copyFeaturesPerms($groupId, $featuresMapIds);
383 private function copyFeaturesPerms(
int $groupId, array $featuresMapIds): void
385 $queryObject = \CSocNetFeaturesPerms::getList(
388 'FEATURE_ENTITY_ID' => $groupId,
391 while ($permFields = $queryObject->fetch())
393 if (array_key_exists($permFields[
'FEATURE_ID'], $featuresMapIds))
395 \CSocNetFeaturesPerms::setPerm(
396 $featuresMapIds[$permFields[
'FEATURE_ID']],
397 $permFields[
'OPERATION_ID'],
setDictionary(Dictionary $dictionary)
copyUfFields(int $entityId, int $copiedEntityId, string $ufObject)