34 $this->fields = array();
42 public static function getById($groupId = 0, $useCache =
true)
44 global $USER_FIELD_MANAGER;
46 static $cachedFields = [];
49 $groupId = (int)$groupId;
56 if ($useCache && isset($cachedFields[$groupId]))
58 $groupFields = $cachedFields[$groupId];
62 $res = WorkgroupTable::getList(array(
63 'filter' => array(
'=ID' => $groupId)
65 if ($fields = $res->fetch())
67 $groupFields = $fields;
71 $groupFields[
'DATE_CREATE'] = $groupFields[
'DATE_CREATE']->toString();
75 $groupFields[
'DATE_UPDATE'] = $groupFields[
'DATE_UPDATE']->toString();
79 $groupFields[
'DATE_ACTIVITY'] = $groupFields[
'DATE_ACTIVITY']->toString();
82 $uf = $USER_FIELD_MANAGER->getUserFields(self::UF_ENTITY_ID, $groupId,
false, 0);
85 $groupFields = array_merge($groupFields, $uf);
89 $cachedFields[$groupId] = $groupFields;
92 $groupItem->setFields($groupFields);
100 $this->fields = $fields;
105 return $this->fields;
111 isset($this->fields[
'PROJECT'])
112 && $this->fields[
'PROJECT'] ===
'Y'
118 return (!empty($this->fields[
'SCRUM_MASTER_ID']));
123 return ($this->fields[
'SCRUM_SPRINT_DURATION'] ? : 0);
128 return ($this->fields[
'SCRUM_MASTER_ID'] ? : 0);
133 if ($this->fields[
'SCRUM_TASK_RESPONSIBLE'])
135 $scrumTaskResponsible = $this->fields[
'SCRUM_TASK_RESPONSIBLE'];
136 $availableResponsibleTypes = [
'A',
'M'];
138 in_array($scrumTaskResponsible, $availableResponsibleTypes,
true) ? $scrumTaskResponsible :
'A'
149 if (!ModuleManager::isModuleInstalled(
'intranet'))
158 || empty($groupFields[
"ID"])
165 isset($groupFields[
'UF_SG_DEPT'][
'VALUE'])
166 && Loader::includeModule(
'intranet')
169 $workgroupsToSync = Option::get(
'socialnetwork',
'workgroupsToSync',
"");
170 $workgroupsToSync = ($workgroupsToSync !==
"" ? @unserialize($workgroupsToSync, [
'allowed_classes' =>
false ]) : []);
171 if (!is_array($workgroupsToSync))
173 $workgroupsToSync = [];
175 $workgroupsToSync[] = array(
176 'groupId' => $groupFields[
"ID"],
177 'initiatorId' => (is_object($USER) ? $USER->getId() : $groupFields[
'OWNER_ID']),
178 'exclude' => $exclude
180 $workgroupsToSync = $this->reduceSyncList($workgroupsToSync);
181 Option::set(
'socialnetwork',
'workgroupsToSync', serialize($workgroupsToSync));
182 \Bitrix\Socialnetwork\Update\WorkgroupDeptSync::bind(1);
188 static $cache = array();
191 $userId = (int)($params[
'USER_ID'] ?? 0);
195 && !empty($cache[$groupFields[
"ID"]])
198 $groupUrlTemplate = $cache[$groupFields[
'ID']][
'URL_TEMPLATE'];
199 $groupSiteId = $cache[$groupFields[
'ID']][
'SITE_ID'];
203 $groupSiteId = \CSocNetGroup::getDefaultSiteId($groupFields[
"ID"], $groupFields[
"SITE_ID"]);
204 $workgroupsPage = Option::get(
"socialnetwork",
"workgroups_page",
"/workgroups/", SITE_ID);
205 $groupUrlTemplate = Helper\Path::get(
'group_path_template');
206 $groupUrlTemplate =
"#GROUPS_PATH#".mb_substr($groupUrlTemplate, mb_strlen($workgroupsPage), mb_strlen($groupUrlTemplate) - mb_strlen($workgroupsPage));
208 $cache[$groupFields[
"ID"]] = array(
209 'URL_TEMPLATE' => $groupUrlTemplate ,
210 'SITE_ID' => $groupSiteId
214 $groupUrl = str_replace(array(
"#group_id#",
"#GROUP_ID#"), $groupFields[
"ID"], $groupUrlTemplate);
215 $serverName = $domainName =
'';
219 $tmp = \CSocNetLogTools::processPath(
221 'GROUP_URL' => $groupUrl,
227 $groupUrl = $tmp[
"URLS"][
"GROUP_URL"];
228 $serverName = (mb_strpos($groupUrl,
"http://") === 0 || mb_strpos($groupUrl,
"https://") === 0 ?
"" : $tmp[
"SERVER_NAME"]);
229 $domainName = (mb_strpos($groupUrl,
"http://") === 0 || mb_strpos($groupUrl,
"https://") === 0 ?
"" : (isset($tmp[
"DOMAIN"]) && !empty($tmp[
"DOMAIN"]) ?
"//".$tmp[
"DOMAIN"] :
""));
234 'SERVER_NAME' => $serverName,
235 'DOMAIN' => $domainName
242 !isset($section[
'ID'], $section[
'IBLOCK_ID'])
243 || (
int)$section[
'ID'] <= 0
244 || (
int)$section[
'IBLOCK_ID'] <= 0
246 isset($section[
'ACTIVE'])
247 && $section[
'ACTIVE'] ===
'N'
249 || (
int)$section[
'IBLOCK_ID'] !== (
int)Option::get(
'intranet',
'iblock_structure', 0)
255 $rootSectionIdList = [];
256 $res = \CIBlockSection::getNavChain($section[
'IBLOCK_ID'], $section[
'ID'], array(
'ID'));
257 while ($rootSection = $res->fetch())
259 if ((
int)$rootSection[
'ID'] !== (
int)$section[
'ID'])
261 $rootSectionIdList[] = $rootSection[
'ID'];
265 if (!empty($rootSectionIdList))
267 $groupList = UserToGroup::getConnectedGroups($rootSectionIdList);
268 self::$groupsIdToCheckList = array_merge(self::$groupsIdToCheckList, $groupList);
277 !isset($section[
'ID'], $section[
'IBLOCK_ID'])
278 || (
int)$section[
'ID'] <= 0
279 || (
int)$section[
'IBLOCK_ID'] <= 0
280 || (
int)$section[
'IBLOCK_ID'] !== (
int)Option::get(
'intranet',
'iblock_structure', 0)
286 $oldGroupsIdToCheckList = self::$groupsIdToCheckList;
287 $newGroupsIdToCheckList = [];
290 isset($section[
'ACTIVE'])
291 && $section[
'ACTIVE'] ===
'N'
294 self::disconnectSection($section[
'ID']);
298 $res = \CIBlockSection::getNavChain($section[
'IBLOCK_ID'], $section[
'ID'], array(
'ID'));
299 while ($rootSection = $res->fetch())
301 if ((
int)$rootSection[
'ID'] !== (
int)$section[
'ID'])
303 $rootSectionIdList[] = $rootSection[
'ID'];
307 if (!empty($rootSectionIdList))
309 $newGroupsIdToCheckList = UserToGroup::getConnectedGroups($rootSectionIdList);
313 if (!empty($oldGroupsIdToCheckList))
315 $oldGroupsIdToCheckList = array_unique($oldGroupsIdToCheckList);
316 foreach($oldGroupsIdToCheckList as $groupId)
318 $groupItem = self::getById($groupId,
false);
319 $groupItem->syncDeptConnection(
true);
323 if (!empty($newGroupsIdToCheckList))
325 $newGroupsIdToCheckList = array_unique($newGroupsIdToCheckList);
326 foreach($newGroupsIdToCheckList as $groupId)
328 $groupItem = self::getById($groupId,
false);
329 $groupItem->syncDeptConnection();
338 if ((
int)$sectionId <= 0)
343 $res = \CIBlockSection::getList(
345 [
'ID' => $sectionId ],
347 [
'ID',
'IBLOCK_ID' ]
350 !($section = $res->fetch())
351 || !isset($section[
'IBLOCK_ID'])
352 || (
int)$section[
'IBLOCK_ID'] <= 0
354 isset($section[
'ACTIVE'])
355 && $section[
'ACTIVE'] ===
'N'
357 || (
int)$section[
'IBLOCK_ID'] !== (
int)Option::get(
'intranet',
'iblock_structure', 0)
363 $rootSectionIdList = [];
364 $res = \CIBlockSection::getNavChain($section[
'IBLOCK_ID'], $section[
'ID'], array(
'ID'));
365 while ($rootSection = $res->fetch())
367 if ((
int)$rootSection[
'ID'] !== (
int)$section[
'ID'])
369 $rootSectionIdList[] = $rootSection[
'ID'];
373 if (!empty($rootSectionIdList))
375 $groupList = UserToGroup::getConnectedGroups($rootSectionIdList);
376 self::$groupsIdToCheckList = array_merge(self::$groupsIdToCheckList, $groupList);
385 !isset($section[
'ID'], $section[
'IBLOCK_ID'])
386 || (
int)$section[
'ID'] <= 0
387 || (
int)$section[
'IBLOCK_ID'] <= 0
388 || (
int)$section[
'IBLOCK_ID'] !== (
int)Option::get(
'intranet',
'iblock_structure', 0)
394 self::disconnectSection($section[
'ID']);
396 if (!empty(self::$groupsIdToCheckList))
398 $groupsToCheck = array_unique(self::$groupsIdToCheckList);
399 foreach($groupsToCheck as $groupId)
401 $groupItem = self::getById($groupId,
false);
402 $groupItem->syncDeptConnection();
409 private static function disconnectSection($sectionId): void
411 $groupList = array();
412 $res = WorkgroupTable::getList(array(
414 '=UF_SG_DEPT' => $sectionId
416 'select' => array(
'ID',
'UF_SG_DEPT')
418 while($group = $res->fetch())
420 $groupList[] = $group;
423 foreach($groupList as $group)
425 $departmentListOld = array_map(
'intval', $group[
'UF_SG_DEPT']);
426 $departmentListNew = array_diff($departmentListOld, array($sectionId));
428 \CSocNetGroup::update($group[
'ID'], array(
429 'UF_SG_DEPT' => $departmentListNew
432 $groupItem = self::getById($group[
'ID'],
false);
433 $groupItem->syncDeptConnection(
true);
437 public static function getTypes($params = []): array
439 return Helper\Workgroup::getTypes($params);
444 return Helper\Workgroup::getPresets($params);
447 private static function getGroupContent($params = array()): string
449 static $fieldsList =
null;;
453 $groupId = (int)($params[
'id'] ?? 0);
460 if ($fieldsList ===
null)
462 $fieldsList = self::getContentFieldsList();
466 isset($params[
'fields'])
467 && is_array($params[
'fields'])
468 && ($diff = array_diff($fieldsList, array_keys($params[
'fields'])))
472 $groupFieldsList = $params[
'fields'];
476 $res = WorkgroupTable::getList(array(
480 'select' => $fieldsList
482 $groupFieldsList = $res->fetch();
485 if (!empty($groupFieldsList))
487 $content .= $groupFieldsList[
'NAME'];
488 if (!empty($groupFieldsList[
'DESCRIPTION']))
490 $content .=
' '.$groupFieldsList[
'DESCRIPTION'];
493 if (!empty($groupFieldsList[
'KEYWORDS']))
495 $keywordList = explode(
",", $groupFieldsList[
"KEYWORDS"]);
497 foreach($keywordList as $keyword)
499 $tagList[] = trim($keyword);
500 $tagList[] =
'#'.trim($keyword);
502 if (!empty($tagList))
504 $content .=
' '.implode(
' ', $tagList);
509 !empty($groupFieldsList[
'OWNER_ID'])
510 && (
int)$groupFieldsList[
'OWNER_ID'] > 0
513 $res = Main\UserTable::getList(array(
515 'ID' => (
int)$groupFieldsList[
'OWNER_ID']
517 'select' => array(
'ID',
'NAME',
'LAST_NAME',
'SECOND_NAME',
'LOGIN',
'EMAIL')
519 if ($userFields = $res->fetch())
521 $content .=
' '.\CUser::formatName(\CSite::getNameFormat(
null, $groupFieldsList[
'SITE_ID']), $userFields,
true);
529 public static function setIndex($params = array()): void
533 static $connection =
null;
535 if (!is_array($params))
540 $fields = (isset($params[
'fields']) ? $params[
'fields'] : array());
550 $groupId = (isset($fields[
'ID']) ? intval($fields[
'ID']) : 0);
557 $content = self::getGroupContent(array(
562 $content = self::prepareToken($content);
566 'onWorkgroupIndexGetContent',
568 'groupId' => $groupId,
573 foreach($event->getResults() as $eventResult)
575 if ($eventResult->getType() == \
Bitrix\Main\EventResult::SUCCESS)
577 $eventParams = $eventResult->getParameters();
580 is_array($eventParams)
581 && isset($eventParams[
'content'])
584 $eventContent = $eventParams[
'content'];
585 if (Main\Loader::includeModule(
'search'))
587 $eventContent = \CSearch::killTags($eventContent);
589 $eventContent = trim(str_replace(
590 array(
"\r",
"\n",
"\t"),
595 $eventContent = self::prepareToken($eventContent);
596 if (!empty($eventContent))
598 $content .=
' '.$eventContent;
604 if (!empty($content))
606 if ($connection ===
null)
608 $connection = \Bitrix\Main\Application::getConnection();
611 $value = $DB->forSql($content);
612 $encryptedValue = sha1($content);
614 $connection->query(
"UPDATE ".
WorkgroupTable::getTableName().
" SET SEARCH_INDEX = IF(SHA1(SEARCH_INDEX) = '{$encryptedValue}', SEARCH_INDEX, '{$value}') WHERE ID = {$groupId}");
620 return [
'NAME',
'DESCRIPTION',
'OWNER_ID',
'KEYWORDS',
'SITE_ID' ];
625 return str_rot13($str);
630 $ownerValue =
Loc::getMessage(
'SOCIALNETWORK_ITEM_WORKGROUP_IP_OWNER');
631 $moderatorsValue =
Loc::getMessage(
'SOCIALNETWORK_ITEM_WORKGROUP_IP_MOD');
635 isset($params[
'scrum'])
639 $ownerValue =
Loc::getMessage(
'SOCIALNETWORK_ITEM_WORKGROUP_IP_OWNER_SCRUM2');
640 $moderatorsValue =
Loc::getMessage(
'SOCIALNETWORK_ITEM_WORKGROUP_IP_MOD_SCRUM2');
641 $userValue =
Loc::getMessage(
'SOCIALNETWORK_ITEM_WORKGROUP_IP_USER_SCRUM');
644 isset($params[
'project'])
645 && $params[
'project']
648 $ownerValue =
Loc::getMessage(
'SOCIALNETWORK_ITEM_WORKGROUP_IP_OWNER_PROJECT');
649 $moderatorsValue =
Loc::getMessage(
'SOCIALNETWORK_ITEM_WORKGROUP_IP_MOD_PROJECT');
650 $userValue =
Loc::getMessage(
'SOCIALNETWORK_ITEM_WORKGROUP_IP_USER_PROJECT');
666 SONET_ROLES_ALL =>
Loc::getMessage(
'SOCIALNETWORK_ITEM_WORKGROUP_IP_ALL'),
677 return Helper\Workgroup::getByFeatureOperation($params);
682 return Helper\Workgroup::getListSprintDuration();
687 return Helper\Workgroup::getScrumTaskResponsibleList();
692 return Helper\Workgroup::getTypeCodeByParams($params);
697 return Helper\Workgroup::getTypeByCode($params);
702 return Helper\Workgroup::getEditFeaturesAvailability();
707 static $optionValue =
null;
708 if ($optionValue ===
null)
710 $optionValue = Option::get(
'socialnetwork',
'work_with_closed_groups',
'N');
713 return ($optionValue ===
'Y');
716 private function reduceSyncList(array $workgroupsToSync = []): array
720 foreach ($workgroupsToSync as $workgroupData)
722 $workgroupId = (int) $workgroupData[
'groupId'];
723 $result[$workgroupId] = $workgroupData;
726 return array_values($result);
static loadMessages($file)
static getMessage($code, $replace=null, $language=null)