25 private $changedFields = [];
30 private $features = [];
32 private $projectTerm = [];
37 private $userGroupHelper =
null;
41 parent::__construct();
53 $this->features[] = $feature;
63 $this->projectTerm = $projectTerm;
68 $this->changedFields = array_merge($this->changedFields, $changedFields);
78 $this->userGroupHelper = $userGroupHelper;
84 $groupModel = GroupModel::createFromArray([
'siteIds' =>
$fields[
'SITE_ID']]);
91 $groupId = \CSocNetGroup::createGroup($this->executiveUserId,
$fields,
false);
97 $this->result->addError(
103 self::GROUP_COPY_ERROR
111 if (isset(
$fields[
"OWNER_ID"]))
113 if (\CSocNetUserToGroup::setOwner(
$fields[
"OWNER_ID"], $groupId))
117 $dictionary[
"NEW_OWNER_ID"] =
$fields[
"OWNER_ID"];
123 if ($this->userGroupHelper)
125 $this->userGroupHelper->changeModerators($groupId);
136 $queryObject = \CSocNetGroup::getList(
137 [
"ID" =>
"DESC"], [
"ID" => (
int)
$entityId],
false,
false, [
"*"]);
138 while ($group = $queryObject->fetch())
140 if ($group[
"IMAGE_ID"] > 0)
142 $group[
"IMAGE_ID"] = \CFile::makeFileArray($group[
"IMAGE_ID"]);
144 if (!empty($group[
'NAME']))
146 $group[
'NAME'] = Emoji::decode($group[
'NAME']);
148 if (!empty($group[
'DESCRIPTION']))
150 $group[
'DESCRIPTION'] = Emoji::decode($group[
'DESCRIPTION']);
153 $fields[
"SITE_ID"] = $this->getSiteIds($group[
"ID"]);
163 if (!empty($this->changedFields))
168 if (
$fields[
"PROJECT"] ==
"Y" && $this->projectTerm)
170 if (!empty($this->projectTerm[
"start_point"]) && !empty($this->projectTerm[
"end_point"]))
174 elseif (!empty($this->projectTerm[
"start_point"]))
176 $fields = $this->getRecountFieldsProjectTerm(
$fields, $this->projectTerm[
"start_point"]);
185 unset(
$fields[
"DATE_ACTIVITY"]);
200 $copiedGroupId = (int) $copiedGroupId;
206 $this->
copyUfFields($groupId, $copiedGroupId,
"SONET_GROUP");
208 foreach ($this->features as $feature)
212 if (method_exists($feature,
"setProjectTerm"))
214 $feature->setProjectTerm($this->projectTerm);
216 $feature->copy($groupId, $copiedGroupId);
219 $this->copyFeatures($groupId, $copiedGroupId);
226 foreach ($this->changedFields as $fieldId => $fieldValue)
228 if (array_key_exists($fieldId,
$fields))
230 $fields[$fieldId] = $fieldValue;
237 private function getFieldsProjectTerm(
$fields)
245 $startPoint = $this->projectTerm[
"start_point"];
246 $endPoint = $this->projectTerm[
"end_point"];
250 $newDateStart = new \DateTime($startPoint);
251 $fields[
"PROJECT_DATE_START"] = $newDateStart->format($phpDateFormat);
253 $newDateEnd = new \DateTime($endPoint);
254 $fields[
"PROJECT_DATE_FINISH"] = $newDateEnd->format($phpDateFormat);
256 $projectTerm[
"start_point"] =
$fields[
"PROJECT_DATE_START"];
257 $projectTerm[
"end_point"] =
$fields[
"PROJECT_DATE_FINISH"];
261 catch (\Exception $exception)
263 $fields[
"PROJECT_DATE_FINISH"] =
"";
264 $this->result->addError(
new Error($exception->getMessage()));
270 private function getRecountFieldsProjectTerm(
$fields, $startPoint)
276 "old_start_point" =>
$fields[
"PROJECT_DATE_START"]
279 $oldDateStart = new \DateTime(
$fields[
"PROJECT_DATE_START"]);
281 $phpDateFormat = \Bitrix\Main\Type\DateTime::convertFormatToPhp(
FORMAT_DATE);
283 $newDateStart = new \DateTime($startPoint);
284 $fields[
"PROJECT_DATE_START"] = $newDateStart->format($phpDateFormat);
286 if (!empty(
$fields[
"PROJECT_DATE_FINISH"]))
288 $dateFinish = new \DateTime(
$fields[
"PROJECT_DATE_FINISH"]);
289 $interval = new \DateInterval(
"PT".($dateFinish->getTimestamp()-$oldDateStart->getTimestamp()).
"S");
290 $newDateStart->add($interval);
291 $fields[
"PROJECT_DATE_FINISH"] = $newDateStart->format($phpDateFormat);
294 $projectTerm[
"start_point"] =
$fields[
"PROJECT_DATE_START"];
295 $projectTerm[
"end_point"] =
$fields[
"PROJECT_DATE_FINISH"];
299 catch (\Exception $exception)
301 $fields[
"PROJECT_DATE_FINISH"] =
"";
302 $this->result->addError(
new Error($exception->getMessage()));
310 if (!Loader::includeModule(
'extranet'))
315 $isAllowCreateExtranetGroup = $this->isAllowCreateExtranetGroup();
316 $existsExtranetSiteId = $this->isExtranetSite(
$fields[
'SITE_ID']);
318 if ($isAllowCreateExtranetGroup)
320 $wantedExtranetGroup = $this->changedFields[
'IS_EXTRANET_GROUP'] ===
'Y';
322 if ($wantedExtranetGroup && !$existsExtranetSiteId)
324 $fields[
'SITE_ID'][] = \CExtranet::getExtranetSiteID();
329 elseif ($existsExtranetSiteId)
333 $extranetSiteId = \CExtranet::getExtranetSiteID();
339 throw new \InvalidArgumentException(
'Site id cannot be empty');
345 private function isAllowCreateExtranetGroup(): bool
347 $isExtranetForGroupsEnabled = (bool)Option::get(
'socialnetwork',
'enable_extranet_for_groups', 0);
349 return Loader::includeModule(
'extranet') && $isExtranetForGroupsEnabled;
352 private function getSiteIds(
int $groupId):
array
356 $queryObject = WorkgroupSiteTable::getList([
358 "GROUP_ID" => $groupId
360 "select" => [
"SITE_ID"]
362 while ($workGroupSite = $queryObject->fetch())
364 $siteIds[] = $workGroupSite[
"SITE_ID"];
366 $siteIds = array_unique($siteIds);
371 private function isExtranetSite(
array $siteIds): bool
375 if (\CExtranet::isExtranetSite(
$siteId))
384 private function copyFeatures(
int $groupId,
int $copiedGroupId): void
386 $featuresMapIds = [];
388 $queryObject = \CSocNetFeatures::getList(
391 "ENTITY_ID" => $groupId,
395 while ($feature = $queryObject->fetch())
397 $copiedFeatureId = \CSocNetFeatures::setFeature(
401 ($feature[
"ACTIVE"] ==
"Y"),
405 if (is_numeric($copiedFeatureId))
407 $featuresMapIds[$feature[
"ID"]] = $copiedFeatureId;
413 $this->copyFeaturesPerms($groupId, $featuresMapIds);
417 private function copyFeaturesPerms(
int $groupId,
array $featuresMapIds): void
419 $queryObject = \CSocNetFeaturesPerms::getList(
422 'FEATURE_ENTITY_ID' => $groupId,
425 while ($permFields = $queryObject->fetch())
427 if (array_key_exists($permFields[
'FEATURE_ID'], $featuresMapIds))
429 \CSocNetFeaturesPerms::setPerm(
430 $featuresMapIds[$permFields[
'FEATURE_ID']],
431 $permFields[
'OPERATION_ID'],
setDictionary(Dictionary $dictionary)
copyUfFields(int $entityId, int $copiedEntityId, string $ufObject)
getResult(array $results=[])
static convertFormatToPhp($format)
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)