43 private static function getAllowedSelectFields(): array
46 'ID',
'ACTIVE',
'SUBJECT_ID',
'NAME',
'DESCRIPTION',
'KEYWORDS',
47 'CLOSED',
'VISIBLE',
'OPENED',
'PROJECT',
'LANDING',
48 'DATE_CREATE',
'DATE_UPDATE',
'DATE_ACTIVITY',
49 'IMAGE_ID',
'AVATAR_TYPE',
51 'NUMBER_OF_MEMBERS',
'NUMBER_OF_MODERATORS',
53 'PROJECT_DATE_START',
'PROJECT_DATE_FINISH',
54 'SCRUM_OWNER_ID',
'SCRUM_MASTER_ID',
'SCRUM_SPRINT_DURATION',
'SCRUM_TASK_RESPONSIBLE',
58 public function getAction(array $params = []): ?array
60 $groupId = (int)($params[
'groupId'] ?? 0);
64 $this->addEmptyGroupIdError();
68 $select = ($params[
'select'] ?? []);
69 $filter = ($params[
'filter'] ?? []);
70 $filter[
'ID'] = $groupId;
72 if (!\CSocNetUser::isCurrentUserModuleAdmin(SITE_ID,
false))
74 $filter[
'CHECK_PERMISSIONS'] = $this->getCurrentUser()->getId();
77 $result = \CSocNetGroup::getList([], $filter,
false,
false, [
'ID']);
78 if ($group = $result->fetch())
80 $groupItem = \Bitrix\Socialnetwork\Item\Workgroup::getById($group[
'ID']);
81 $groupFields = $groupItem->getFields();
83 if (in_array(
'AVATAR', $select,
true))
85 $groupFields[
'AVATAR'] = File::getFileSource((
int)$groupFields[
'IMAGE_ID'], 100, 100);
87 if (in_array(
'AVATAR_TYPES', $select,
true))
89 $groupFields[
'AVATAR_TYPES'] = Helper\Workgroup::getAvatarTypes();
91 if (in_array(
'AVATAR_DATA', $select,
true))
93 $imageId = (int) $groupFields[
'IMAGE_ID'];
94 $avatarType = $groupFields[
'AVATAR_TYPE'] ??
'';
95 $groupFields[
'AVATAR_DATA'] = $this->getAvatarData($imageId, $avatarType);
97 if (in_array(
'OWNER_DATA', $select,
true))
99 $groupFields[
'OWNER_DATA'] = $this->getOwnerData($groupFields[
'OWNER_ID']);
101 if (in_array(
'SUBJECT_DATA', $select,
true))
103 $groupFields[
'SUBJECT_DATA'] = $this->getSubjectData($groupFields[
'SUBJECT_ID']);
105 if (in_array(
'TAGS', $select,
true))
107 $groupFields[
'TAGS'] = $this->getTags($groupId);
109 if (in_array(
'THEME_DATA', $select,
true))
111 $groupFields[
'THEME_DATA'] = $this->getThemeData($groupId);
113 if (in_array(
'ACTIONS', $select,
true))
115 $groupFields[
'ACTIONS'] = $this->getActions($groupId);
117 if (in_array(
'USER_DATA', $select,
true))
119 $groupFields[
'USER_DATA'] = $this->getUserData($groupId);
121 if (in_array(
'DEPARTMENTS', $select,
true))
123 $groupFields[
'DEPARTMENTS'] = $this->getDepartments($groupFields[
'UF_SG_DEPT'][
'VALUE']);
125 if (in_array(
'PIN', $select,
true))
127 $groupFields[
'IS_PIN'] = $this->isPin($groupId, $this->getCurrentUser()->getId());
129 if (in_array(
'PRIVACY_TYPE', $select,
true))
131 $groupFields[
'PRIVACY_CODE'] = Helper\Workgroup::getConfidentialityTypeCodeByParams([
133 'OPENED' => $groupFields[
'OPENED'],
134 'VISIBLE' => $groupFields[
'VISIBLE'],
138 if (in_array(
'LIST_OF_MEMBERS', $select,
true))
140 $groupFields[
'LIST_OF_MEMBERS'] = $this->getListOfMembers(
142 $groupItem->getScrumMaster()
146 $needListOfAwaiting = in_array(
'LIST_OF_MEMBERS_AWAITING_INVITE', $select,
true);
147 $needMembersList = in_array(
'GROUP_MEMBERS_LIST', $select,
true);
148 if ($needListOfAwaiting || $needMembersList)
150 $permissions = Helper\Workgroup::getPermissions(
151 [
'groupId' => $groupId],
154 if ($needListOfAwaiting)
156 $groupFields[
'LIST_OF_MEMBERS_AWAITING_INVITE'] = [];
157 if ($permissions[
'UserCanModifyGroup'] || $permissions[
'UserCanInitiate'])
159 $groupFields[
'LIST_OF_MEMBERS_AWAITING_INVITE'] = $this->getListOfAwaitingMembers($groupId);
162 if ($needMembersList)
164 $groupFields[
'GROUP_MEMBERS_LIST'] = [];
165 if ($permissions[
'UserCanModifyGroup'] || $permissions[
'UserCanInitiate'])
168 $groupFields[
'GROUP_MEMBERS_LIST'] = $membersManager->getGroupMembersList($groupId);
172 if (in_array(
'COUNTERS', $select,
true))
174 $groupFields[
'COUNTERS'] = $this->getCounters($groupId);
177 if ($groupFields[
'NUMBER_OF_MEMBERS'])
179 $groupFields[
'NUMBER_OF_MEMBERS_PLURAL'] =
Loc::getPluralForm($groupFields[
'NUMBER_OF_MEMBERS']);
181 if ($groupFields[
'PROJECT_DATE_START'] || $groupFields[
'PROJECT_DATE_FINISH'])
184 $format = $culture->getDayMonthFormat();
187 $dateStart = $groupFields[
'PROJECT_DATE_START'];
189 $dateFinish = $groupFields[
'PROJECT_DATE_FINISH'];
193 $groupFields[
'FORMATTED_PROJECT_DATE_START'] = FormatDate(
200 $groupFields[
'FORMATTED_PROJECT_DATE_FINISH'] = FormatDate(
208 isset($params[
'mode'])
209 && $params[
'mode'] ===
'mobile'
212 $additionalData = Helper\Workgroup::getAdditionalData([
213 'ids' => [ $groupId ],
214 'features' => ($params[
'features'] ?? []),
215 'mandatoryFeatures' => ($params[
'mandatoryFeatures'] ?? []),
216 'currentUserId' => (
int)$this->getCurrentUser()->getId(),
219 $groupFields[
'ADDITIONAL_DATA'] = ($additionalData[$groupId] ?? []) ;
228 'SONET_CONTROLLER_WORKGROUP_NOT_FOUND'
245 || !is_array($select)
251 if (!in_array(
'ID', $select,
true))
256 $originalSelect = $select;
259 $params[
'IS_ADMIN'] ===
'Y'
260 && !\CSocNetUser::isCurrentUserModuleAdmin(SITE_ID,
false)
263 unset($params[
'IS_ADMIN']);
266 if ($params[
'IS_ADMIN'] !==
'Y')
268 $filter[
'CHECK_PERMISSIONS'] = $this->getCurrentUser()->getId();
271 $extranetSiteId = \CSocNetLogRestService::getExtranetSiteId();
275 && $params[
'IS_ADMIN'] !==
'Y'
276 && \CSocNetLogRestService::getCurrentUserType() ===
'extranet'
279 $filter[
'SITE_ID'] = $extranetSiteId;
283 $filter[
'SITE_ID'] = (string)($params[
'siteId'] ?? SITE_ID);
286 if (($key = array_search(
'AVATAR', $select,
true)) !==
false)
288 $select[] =
'IMAGE_ID';
289 $select[] =
'AVATAR_TYPE';
290 unset($select[$key]);
298 $res = \CSocNetGroup::getList([], $filter,
false,
false, [
'ID' ]);
299 while ($groupFields = $res->fetch())
301 $queryIdFilter[] = (int)$groupFields[
'ID'];
304 if (!empty($queryIdFilter))
306 $select = $this->prepareSelect($select);
308 $query = WorkgroupTable::query();
312 ->setOffset($pageNavigation->
getOffset())
313 ->setLimit(($pageNavigation->
getLimit()))
315 'ID' => $queryIdFilter,
319 $res = $query->exec();
321 $avatarTypes = Helper\Workgroup::getAvatarTypes();
323 while ($groupFields = $res->fetch())
325 if (in_array(
'AVATAR', $originalSelect,
true))
327 if ((
int)$groupFields[
'IMAGE_ID'] > 0)
329 $groupFields[
'AVATAR'] = File::getFileSource((
int)$groupFields[
'IMAGE_ID'], 100, 100);
332 !empty($groupFields[
'AVATAR_TYPE'])
333 && isset($params[
'mode'])
334 && $params[
'mode'] ===
'mobile'
337 $groupFields[
'AVATAR'] = $avatarTypes[$groupFields[
'AVATAR_TYPE']][
'mobileUrl'];
341 $groupFields[
'AVATAR'] =
'';
345 $workgroups[(int)$groupFields[
'ID']] = $groupFields;
348 $count = $res->getCount();
351 $ids = array_keys($workgroups);
354 isset($params[
'mode'])
355 && $params[
'mode'] ===
'mobile'
358 $additionalData = Helper\Workgroup::getAdditionalData([
360 'features' => ($params[
'features'] ?? []),
361 'mandatoryFeatures' => ($params[
'mandatoryFeatures'] ?? []),
362 'currentUserId' => (
int)$this->getCurrentUser()->getId(),
365 foreach (array_keys($workgroups) as $id)
367 if (!isset($additionalData[$id]))
372 $workgroups[$id][
'ADDITIONAL_DATA'] = ($additionalData[$id] ?? []) ;
376 $workgroups = $this->convertKeysToCamelCase($workgroups);
381 private function prepareSelect(array $select = []): array
383 return array_filter($select,
static function ($key) {
384 return in_array(mb_strtoupper($key), static::getAllowedSelectFields(),
true);
388 private function getAvatarData(
int $imageId,
string $avatarType): array
390 $avatarManager =
new AvatarManager();
394 $avatarData = $avatarManager->getImageAvatar($imageId)->toArray();
398 $avatarData = $avatarManager->getIconAvatar($avatarType)->toArray();
404 private function getOwnerData(
int $ownerId): array
406 $owner = UserTable::getList([
407 'select' => [
'NAME',
'LAST_NAME',
'SECOND_NAME',
'LOGIN',
'PERSONAL_PHOTO'],
408 'filter' => [
'ID' => $ownerId],
413 'PHOTO' => ($owner[
'PERSONAL_PHOTO'] ? File::getFileSource($owner[
'PERSONAL_PHOTO']) : null),
414 'FORMATTED_NAME' => htmlspecialcharsback(
416 \CSite::getNameFormat(),
418 'NAME' => $owner[
'NAME'],
419 'LAST_NAME' => $owner[
'LAST_NAME'],
420 'SECOND_NAME' => $owner[
'SECOND_NAME'],
421 'LOGIN' => $owner[
'LOGIN'],
429 private function getSubjectData(
int $subjectId): array
431 $subject = WorkgroupSubjectTable::getList([
432 'select' => [
'NAME'],
433 'filter' => [
'ID' => $subjectId],
438 'NAME' => $subject[
'NAME'],
442 private function getTags(
int $groupId): array
444 $tags = WorkgroupTagTable::getList([
445 'select' => [
'NAME'],
446 'filter' => [
'GROUP_ID' => $groupId],
450 static function($tag) {
451 return htmlspecialcharsback($tag);
453 array_column($tags,
'NAME')
457 private function getThemeData(
int $groupId): ?array
459 if (!Loader::includeModule(
'intranet'))
464 $themePicker =
new ThemePicker(
467 $this->getCurrentUser()->getId(),
468 ThemePicker::ENTITY_TYPE_SONET_GROUP,
472 $themeUserId =
false;
473 $themeId = $themePicker->getCurrentThemeId();
476 $res = ThemeTable::getList([
477 'select' => [
'USER_ID'],
479 '=ENTITY_TYPE' => $themePicker->getEntityType(),
480 'ENTITY_ID' => $themePicker->getEntityId(),
481 '=CONTEXT' => $themePicker->getContext(),
484 if (($themeFields = $res->fetch()) && (
int)$themeFields[
'USER_ID'] > 0)
486 $themeUserId = (int)$themeFields[
'USER_ID'];
490 return $themePicker->getTheme($themeId, $themeUserId);
493 private function getActions(
int $groupId): array
495 $permissions = Helper\Workgroup::getPermissions([
'groupId' => $groupId]);
498 'EDIT' => $permissions[
'UserCanModifyGroup'],
499 'DELETE' => $permissions[
'UserCanModifyGroup'],
500 'INVITE' => $permissions[
'UserCanInitiate'],
502 !$permissions[
'UserIsMember']
503 && !$permissions[
'UserRole']
506 $permissions[
'UserIsMember']
507 && !$permissions[
'UserIsAutoMember']
508 && !$permissions[
'UserIsOwner']
509 && !$permissions[
'UserIsScrumMaster']
514 private function getUserData(
int $groupId): array
516 $permissions = Helper\Workgroup::getPermissions([
'groupId' => $groupId]);
519 'ROLE' => $permissions[
'UserRole'],
520 'INITIATED_BY_TYPE' => $permissions[
'InitiatedByType'],
523 && \CSocNetSubscription::isUserSubscribed($this->getCurrentUser()->getId(),
'SG' . $groupId)
528 private function getDepartments($ufDepartments): array
533 empty($ufDepartments)
534 || !is_array($ufDepartments)
535 || !Loader::includeModule(
'intranet')
541 $departmentsList = \CIntranetUtils::getDepartmentsData($ufDepartments);
542 if (empty($departmentsList))
547 foreach ($departmentsList as $id => $name)
549 if (($id = (
int)$id) <= 0)
563 private function isPin(
int $groupId,
int $currentUserId,
string $context =
''): bool
565 $query =
new Query(WorkgroupPinTable::getEntity());
573 ->where(
'GROUP_ID', $groupId)
574 ->where(
'USER_ID', $currentUserId)
578 $query = $query->where(Query::filter()
580 ->whereNull(
'CONTEXT')
581 ->where(
'CONTEXT',
'')
586 $query = $query->where(
'CONTEXT', $context);
589 $pin = $query->setLimit(1)->exec()->fetchObject();
594 private function getListOfMembers(
int $groupId,
int $scrumMasterId): array
598 $records = UserToGroupTable::query()
605 'NAME' =>
'USER.NAME',
606 'LAST_NAME' =>
'USER.LAST_NAME',
607 'SECOND_NAME' =>
'USER.SECOND_NAME',
608 'LOGIN' =>
'USER.LOGIN',
609 'PERSONAL_PHOTO' =>
'USER.PERSONAL_PHOTO',
611 ->whereIn(
'GROUP_ID', $groupId)
613 ->exec()->fetchCollection()
618 foreach ($records as $record)
620 $user = $record->get(
'USER');
621 $imageIdList[$record->get(
'USER_ID')] = $user->get(
'PERSONAL_PHOTO');
622 $members[] = $record;
624 $imageIdList = array_filter(
626 static function ($id) {
627 return (
int) $id > 0;
630 $avatars = $this->getUserAvatars($imageIdList);
632 foreach ($members as $member)
634 $memberId = (int) $member[
'USER_ID'];
638 $isScrumMaster = ($scrumMasterId === $memberId);
642 'isOwner' => $isOwner,
643 'isModerator' => $isModerator,
644 'isScrumMaster' => $isScrumMaster,
645 'isAutoMember' => $member[
'AUTO_MEMBER'],
646 'photo' => ($avatars[($imageIdList[$memberId] ??
'')] ??
''),
653 private function getListOfAwaitingMembers(
int $groupId,
int $limit = 10,
int $offset = 0): array
657 $records = UserToGroupTable::query()
663 'NAME' =>
'USER.NAME',
664 'LAST_NAME' =>
'USER.LAST_NAME',
665 'SECOND_NAME' =>
'USER.SECOND_NAME',
666 'LOGIN' =>
'USER.LOGIN',
667 'PERSONAL_PHOTO' =>
'USER.PERSONAL_PHOTO',
669 ->whereIn(
'GROUP_ID', $groupId)
674 ->exec()->fetchCollection()
679 foreach ($records as $record)
681 $user = $record->get(
'USER');
682 $imageIdList[$record->get(
'USER_ID')] = $user->get(
'PERSONAL_PHOTO');
684 $members[] = $record;
686 $imageIdList = array_filter(
688 static function ($id) {
689 return (
int) $id > 0;
692 $avatars = $this->getUserAvatars($imageIdList);
694 foreach ($members as $member)
696 $memberId = (int) $member[
'USER_ID'];
698 $userNameFormatted = \CUser::formatName(\CSite::getNameFormat(), [
699 'NAME' => $member->get(
'USER')->get(
'NAME'),
700 'LAST_NAME' => $member->get(
'USER')->get(
'LAST_NAME'),
701 'SECOND_NAME' => $member->get(
'USER')->get(
'SECOND_NAME'),
702 'LOGIN' => $member->get(
'USER')->get(
'LOGIN'),
703 ], ModuleManager::isModuleInstalled(
'intranet'));
707 'name' => $userNameFormatted,
708 'photo' => ($avatars[($imageIdList[$memberId] ??
'')] ??
''),
715 private function getCounters(
int $groupId): array
719 $counterProvider = Counter::getInstance($this->getCurrentUser()->getId());
721 $availableCounters = [
722 CounterDictionary::COUNTER_WORKGROUP_REQUESTS_OUT,
723 CounterDictionary::COUNTER_WORKGROUP_REQUESTS_IN,
725 foreach ($availableCounters as $counter)
727 $counters[$counter] = $counterProvider->get($counter, $groupId)[
'all'];
736 'groupId' => $groupId,
740 $this->addEmptyGroupIdError();
752 foreach ($fields as $key => $value)
754 if (!in_array($key, $whiteList,
true))
756 unset($fields[$key]);
766 'SONET_CONTROLLER_WORKGROUP_ACTION_FAILED')
773 $result = \CSocNetGroup::update($groupId, $fields);
785 'SONET_CONTROLLER_WORKGROUP_ACTION_FAILED')
797 'groupId' => $groupId,
802 $this->addEmptyGroupIdError();
809 $deleteResult = \CSocNetGroup::Delete($groupId);
810 if (!$deleteResult && ($e = $APPLICATION->GetException()))
812 return $e->GetString();
820 return Helper\Workgroup::getAvatarTypes();
825 foreach ($departmentIds as $id)
827 Helper\Workgroup::disconnectDepartment([
828 'groupId' => $groupId,
829 'departmentId' => $id,
836 $groupId = (int)($params[
'groupId'] ?? 0);
837 $getAdditionalResultData = (bool)($params[
'getAdditionalResultData'] ??
false);
841 $this->addEmptyGroupIdError();
847 $this->addIncorrectValueError();
854 'GROUP_ID' => $groupId,
855 'USER_ID' => $this->getCurrentUser()->getId(),
856 'VALUE' => $params[
'value'],
873 'RESULT' => $params[
'value'],
876 if ($getAdditionalResultData)
878 $groupItem = \Bitrix\Socialnetwork\Item\Workgroup::getById($groupId);
879 $groupFields = $groupItem->getFields();
880 $groupUrlData = $groupItem->getGroupUrlData([
881 'USER_ID' => $this->getCurrentUser()->getId(),
885 $resSite = WorkgroupSiteTable::getList([
887 '=GROUP_ID' => $groupId
889 'select' => [
'SITE_ID' ],
891 while ($groupSite = $resSite->fetch())
893 $groupSiteList[] = $groupSite[
'SITE_ID'];
896 $result[
'NAME'] = $groupFields[
'NAME'];
897 $result[
'URL'] = $groupUrlData[
"URL"];
898 $result[
'EXTRANET'] = (
899 Loader::includeModule(
'extranet')
900 && CExtranet::isIntranetUser()
901 && in_array(CExtranet::getExtranetSiteId(), $groupSiteList,
true)
907 $this->sendPush(PushEventDictionary::EVENT_WORKGROUP_FAVORITES_CHANGED, [
'GROUP_ID' => $groupId]);
914 $groupId = (int)($params[
'groupId'] ?? 0);
917 $this->addEmptyGroupIdError();
921 if (!in_array($params[
'value'] ??
null, Subscription::AVAILABLE_VALUES,
true))
923 $this->addIncorrectValueError();
929 $result = Subscription::set([
930 'GROUP_ID' => $groupId,
931 'USER_ID' => $this->getCurrentUser()->getId(),
932 'VALUE' => $params[
'value'],
941 $this->sendPush(PushEventDictionary::EVENT_WORKGROUP_SUBSCRIBE_CHANGED, [
'GROUP_ID' => $groupId]);
944 'RESULT' => $result ?
'Y' :
'N',
950 $groupName = $this->getRequest()->get(
'groupName');
951 $viewMode = $this->getRequest()->get(
'viewMode');
952 $groupImage = $this->getRequest()->getFile(
'groupImage');
953 $avatarColor = $this->getRequest()->get(
'avatarColor');
957 return [
'groupId' => 0];
960 $ownerId = $this->getCurrentUser()->getId();
963 'SITE_ID' => [SITE_ID],
964 'NAME' => $groupName,
965 'SUBJECT_ID' => $this->getDefaultSubjectId(),
966 'INITIATE_PERMS' => SONET_ROLES_USER,
967 'SPAM_PERMS' => SONET_ROLES_USER,
968 'VISIBLE' => $viewMode !==
'secret' ?
'Y' :
'N',
969 'OPENED' => $viewMode ===
'open' ?
'Y' :
'N',
972 if (is_array($groupImage))
977 $result = $avatarManager->loadAvatar($groupImage);
978 $groupParams[
'IMAGE_ID'] = $avatarManager->getAvatar($result[
'fileId']);
980 catch (\RuntimeException)
982 unset($groupParams[
'IMAGE_ID']);
986 if (!isset($groupParams[
'IMAGE_ID']))
988 $groupParams[
'AVATAR_TYPE'] = $this->getColoredDefaultAvatar($avatarColor);
991 $groupId = (int)\CSocNetGroup::createGroup($ownerId, $groupParams);
994 if ($e = $APPLICATION->GetException())
1000 $this->setDefaultGroupFeatures($groupId);
1003 'groupId' => $groupId,
1007 private function getColoredDefaultAvatar(
string $color): string
1009 if (in_array($color,
Helper\Workgroup::getAvatarColors(),
true))
1011 return "space_$color";
1014 return array_rand(Helper\Workgroup::getColoredAvatarTypes());
1017 private function setDefaultGroupFeatures(
int $groupId): void
1019 $allowedFeatures = array_keys(\CSocNetAllowed::getAllowedFeatures());
1020 $inactiveFeaturesList = [
'forum',
'photo',
'search',
'group_lists',
'wiki'];
1023 foreach ($allowedFeatures as $featureName)
1025 $features[$featureName] = !in_array($featureName, $inactiveFeaturesList,
true);
1028 foreach ($features as $featureName => $isActive)
1030 \CSocNetFeatures::setFeature(
1039 private function getDefaultSubjectId(): int
1041 $subject = \CSocNetGroupSubject::GetList(
1042 [
"SORT"=>
"ASC",
"NAME" =>
"ASC"],
1043 [
"SITE_ID" => SITE_ID],
1049 return (
int)($subject[
'ID'] ?? 0);
1054 return Helper\Workgroup\Access::canCreate([
1063 if (!$membersManager->canInviteUsers($spaceId))
1068 $membersManager->updateInvitedUsers($spaceId, array_map(
static fn($userId) => (
int)$userId, $users));
1075 string $componentName =
'',
1076 string $signedParameters =
''
1082 'groupId' => $groupId,
1087 $this->addEmptyGroupIdError();
1091 $unsignedParameters = [];
1093 $componentName !==
''
1094 && $signedParameters !==
''
1097 $unsignedParameters = \Bitrix\Main\Component\ParameterSigner::unsignParameters(
1101 if (!is_array($unsignedParameters))
1103 $unsignedParameters = [];
1127 $query = UserToGroupTable::query();
1134 'INITIATED_BY_TYPE',
1136 'NAME' =>
'USER.NAME',
1137 'LAST_NAME' =>
'USER.LAST_NAME',
1138 'SECOND_NAME' =>
'USER.SECOND_NAME',
1139 'LOGIN' =>
'USER.LOGIN',
1140 'PERSONAL_PHOTO' =>
'USER.PERSONAL_PHOTO',
1142 ->where(
'GROUP_ID', $groupId)
1143 ->whereIn(
'ROLE', $rolesMap[$type])
1145 ->setOffset(($page - 1) * $limit)
1146 ->exec()->fetchCollection();
1148 $isScrumMembers = ($type ===
'scrumTeam');
1149 if ($isScrumMembers)
1151 $query->addSelect(
'GROUP.SCRUM_MASTER_ID',
'SCRUM_MASTER_ID');
1155 $resultMembers = [];
1157 foreach ($records as $member)
1159 $imageIds[$member->get(
'USER_ID')] = $member->get(
'USER')->get(
'PERSONAL_PHOTO');
1160 $resultMembers[] = $member;
1163 $imageIds = array_filter(
1165 static function ($id) {
return (
int)$id > 0; }
1167 $avatars = Helper\UI\Grid\Workgroup\Members::getUserAvatars($imageIds);
1168 $pathToUser = ($unsignedParameters[
'PATH_TO_USER'] ?? Helper\Path::get(
'user_profile'));
1169 $userNameTemplate = ($unsignedParameters[
'NAME_TEMPLATE'] ?? \CSite::getNameFormat());
1170 $isIntranetInstalled = ModuleManager::isModuleInstalled(
'intranet');
1174 foreach ($resultMembers as $member)
1176 $id = $member->get(
'USER_ID');
1177 $userNameFormatted = \CUser::formatName($userNameTemplate, [
1178 'NAME' => $member->get(
'USER')->get(
'NAME'),
1179 'LAST_NAME' => $member->get(
'USER')->get(
'LAST_NAME'),
1180 'SECOND_NAME' => $member->get(
'USER')->get(
'SECOND_NAME'),
1181 'LOGIN' => $member->get(
'USER')->get(
'LOGIN'),
1182 ], $isIntranetInstalled);
1184 $userUrl = \CComponentEngine::makePathFromTemplate($pathToUser, [
1191 'PHOTO' => $avatars[$imageIds[$id] ??
null] ??
'',
1193 'FORMATTED_NAME' => $userNameFormatted,
1194 'ROLE' => ($isScrumMembers ? $this->getScrumRole($member) : $member->get(
'ROLE')),
1197 if ($isScrumMembers)
1201 && $member->get(
'USER_ID') === $member->get(
'GROUP')->get(
'SCRUM_MASTER_ID')
1206 'PHOTO' => $avatars[$imageIds[$id] ??
null] ??
'',
1208 'FORMATTED_NAME' => $userNameFormatted,
1218 private function getScrumRole(EO_UserToGroup $member): string
1221 $member->get(
'USER_ID') === $member->get(
'GROUP')->get(
'SCRUM_MASTER_ID')
1228 return $member->get(
'ROLE');
1237 string $componentName =
'',
1238 string $signedParameters =
''
1241 $unsignedParameters = [];
1243 $componentName !==
''
1244 && $signedParameters !==
''
1247 $unsignedParameters = \Bitrix\Main\Component\ParameterSigner::unsignParameters($componentName, $signedParameters);
1248 if (!is_array($unsignedParameters))
1250 $unsignedParameters = [];
1254 $mode = ($unsignedParameters[
'MODE'] ??
'');
1258 foreach ($groupIdList as $groupId)
1260 $groupId = (int)$groupId;
1265 'groupId' => $groupId,
1274 $pin =
new Pin($this->userId, $groupId, $mode);
1275 $result = $pin->switch();
1277 if (!$result->isSuccess())
1279 $this->addErrors($result->getErrors());
1283 $this->sendPush(PushEventDictionary::EVENT_WORKGROUP_PIN_CHANGED, [
1284 'GROUP_ID' => $groupId,
1285 'ACTION' => $action,
1292 $this->addEmptyGroupIdError();
1305 foreach ($userIds as $userId)
1307 $result[$userId] = Helper\Workgroup::acceptIncomingRequest([
1308 'groupId' => $groupId,
1309 'userId' => $userId,
1316 EventDictionary::EVENT_WORKGROUP_MEMBER_REQUEST_CONFIRM,
1318 'GROUP_ID' => $groupId,
1319 'RECEPIENTS' => array_map(
function ($row) {
return $row[
'USER_ID']; }, $moderators),
1339 foreach ($userIds as $userId)
1341 $result[$userId] = Helper\Workgroup::rejectIncomingRequest([
1342 'groupId' => $groupId,
1343 'userId' => $userId,
1350 EventDictionary::EVENT_WORKGROUP_MEMBER_REQUEST_CONFIRM,
1352 'GROUP_ID' => $groupId,
1353 'RECEPIENTS' => array_map(
function ($row) {
return $row[
'USER_ID']; }, $moderators),
1369 $permissions = Helper\Workgroup::getPermissions(
1370 [
'groupId' => $groupId]
1372 if (!$permissions[
'UserCanModifyGroup'] && !$permissions[
'UserCanInitiate'])
1380 $offset = ($pageNum - 1) * $limit;
1382 return $this->getListOfAwaitingMembers($groupId, $limit, $offset);
1389 if (!Loader::includeModule(
'im'))
1394 $chatData = \Bitrix\Socialnetwork\Integration\Im\Chat\Workgroup::getChatData(
1396 'group_id' => $groupId,
1397 'skipAvailabilityCheck' =>
true,
1400 if (!empty($chatData[$groupId]) && intval($chatData[$groupId]) > 0)
1402 $chatId = $chatData[$groupId];
1406 $chatId = \Bitrix\Socialnetwork\Integration\Im\Chat\Workgroup::createChat(
1408 'group_id' => $groupId,
1416 private function getUserAvatars(array $imageIds): array
1419 if (empty($imageIds))
1424 $result = array_fill_keys($imageIds,
'');
1426 $res = \CFile::getList([], [
'@ID' => implode(
',', $imageIds)]);
1427 while ($file = $res->fetch())
1429 $file[
'SRC'] = \CFile::getFileSRC($file);
1430 $fileInfo = \CFile::resizeImageGet(
1436 BX_RESIZE_IMAGE_EXACT,
1442 $result[$file[
'ID']] = $fileInfo[
'src'];
1448 private function sendPush(
string $command, array $parameters = []): void
1450 $parameters[
'USER_ID'] = $this->userId;
1451 PushService::addEvent(
1454 'module_id' =>
'socialnetwork',
1455 'command' => $command,
1456 'params' => $parameters,
1461 private function addEmptyGroupIdError(): void
1466 'SONET_CONTROLLER_WORKGROUP_EMPTY'
1471 private function addIncorrectValueError(): void
1474 'SONET_CONTROLLER_WORKGROUP_INCORRECT_VALUE',
1475 'SONET_CONTROLLER_WORKGROUP_INCORRECT_VALUE'