protected function getUserGroupWithStorage() { if (!\CBXFeatures::isFeatureEnabled("Workgroups")) { return array(); } if (!Loader::includeModule('socialnetwork')) { return array(); } $userId = $this->getUser()->getId(); $currentPossibleUserGroups = $currentUserGroups = array(); $cache = Cache::createInstance(); $cacheTtl = defined('BX_COMP_MANAGED_CACHE') ? 3153600 : 3600 * 4; $cachePath = "/disk/uf/{$userId}"; if ($cache->initCache($cacheTtl, 'group_storage_list_' . SITE_ID . '_' . $userId, $cachePath)) { list($currentUserGroups) = $cache->getVars(); } else { $cache->startDataCache(); $taggedCache = Application::getInstance()->getTaggedCache(); $taggedCache->startTagCache($cachePath); $diskSecurityContext = new DiskSecurityContext($userId); $storages = Storage::getReadableList($diskSecurityContext, array('filter' => array('STORAGE.ENTITY_TYPE' => ProxyType\Group::className()))); foreach ($storages as $storage) { $currentPossibleUserGroups[$storage->getEntityId()] = $storage; } unset($storage); $query = \CSocNetUserToGroup::getList(array('GROUP_NAME' => 'ASC'), array('USER_ID' => $userId, 'GROUP_ID' => array_keys($currentPossibleUserGroups)), false, false, array('GROUP_ID', 'GROUP_NAME', 'GROUP_ACTIVE', 'GROUP_CLOSED', 'ROLE')); while ($row = $query->getNext()) { if ($row['GROUP_ACTIVE'] == 'Y' && $row['GROUP_CLOSED'] == 'N' && $row['ROLE'] != SONET_ROLES_BAN && $row['ROLE'] != SONET_ROLES_REQUEST && isset($currentPossibleUserGroups[$row['GROUP_ID']])) { $taggedCache->registerTag("sonet_features_G_{$row['GROUP_ID']}"); $taggedCache->registerTag("sonet_group_{$row['GROUP_ID']}"); $currentUserGroups[$row['GROUP_ID']] = array('STORAGE' => $currentPossibleUserGroups[$row['GROUP_ID']], 'NAME' => $row['GROUP_NAME']); } } $taggedCache->registerTag("sonet_user2group_U{$userId}"); $taggedCache->endTagCache(); $cache->endDataCache(array($currentUserGroups)); } return $currentUserGroups; }
protected function getUserGroupWithStorage() { if (!\CBXFeatures::isFeatureEnabled("Workgroups")) { return array(); } if (!Loader::includeModule('socialnetwork')) { return array(); } $userId = $this->getUser()->getId(); $currentPossibleUserGroups = $currentUserGroups = array(); $diskSecurityContext = new DiskSecurityContext($this->getUser()->getId()); $storages = Storage::getReadableList($diskSecurityContext, array('filter' => array('STORAGE.ENTITY_TYPE' => ProxyType\Group::className()))); foreach ($storages as $storage) { $currentPossibleUserGroups[$storage->getEntityId()] = $storage; } unset($storage); $query = \CSocNetUserToGroup::getList(array('GROUP_NAME' => 'ASC'), array('USER_ID' => $userId, 'GROUP_ID' => array_keys($currentPossibleUserGroups)), false, false, array('GROUP_ID', 'GROUP_NAME', 'GROUP_ACTIVE', 'GROUP_CLOSED', 'ROLE')); while ($row = $query->getNext()) { if ($row['GROUP_ACTIVE'] == 'Y' && $row['GROUP_CLOSED'] == 'N' && $row['ROLE'] != SONET_ROLES_BAN && $row['ROLE'] != SONET_ROLES_REQUEST && isset($currentPossibleUserGroups[$row['GROUP_ID']])) { $currentUserGroups[$row['GROUP_ID']] = array('STORAGE' => $currentPossibleUserGroups[$row['GROUP_ID']], 'NAME' => $row['GROUP_NAME']); } } return $currentUserGroups; }
public static function getUsersFromUserGroup($group, $documentId) { if (substr($documentId, 0, 8) == "STORAGE_") { $storageId = self::getStorageIdByType($documentId); } else { if (is_array($documentId)) { $documentId = intval($documentId[2]); } /** @var File $file */ $file = File::loadById($documentId); if (!$file) { return array(); } $storageId = $file->getStorageId(); } if (strtolower($group) == "author") { $documentId = intval($documentId); if ($documentId <= 0) { return array(); } /** @var File $file */ $file = File::loadById($documentId); if (!$file) { return array(); } return array($file->getCreatedBy()); } if ($storageId) { $storage = Storage::loadById($storageId, array('ROOT_OBJECT')); if ($storage->getProxyType() instanceof ProxyType\Group) { $entityId = $storage->getEntityId(); $group = strtoupper($group); if (Loader::includeModule("socialnetwork")) { $listUserGroup = array(); if ($group == SONET_ROLES_OWNER) { $listGroup = \CSocNetGroup::getByID($entityId); if ($listGroup) { $listUserGroup[] = $listGroup["OWNER_ID"]; } } elseif ($group == SONET_ROLES_MODERATOR) { $dbRes = \CSocNetUserToGroup::getList(array(), array("GROUP_ID" => $entityId, "<=ROLE" => SONET_ROLES_MODERATOR, "USER_ACTIVE" => "Y"), false, false, array("USER_ID")); while ($res = $dbRes->fetch()) { $listUserGroup[] = $res["USER_ID"]; } } elseif ($group == SONET_ROLES_USER) { $dbRes = \CSocNetUserToGroup::getList(array(), array("GROUP_ID" => $entityId, "<=ROLE" => SONET_ROLES_USER, "USER_ACTIVE" => "Y"), false, false, array("USER_ID")); while ($res = $dbRes->fetch()) { $listUserGroup[] = $res["USER_ID"]; } } return $listUserGroup; } } } $group = intval($group); if ($group <= 0) { return array(); } $userIds = array(); $filter = array("ACTIVE" => "Y"); if ($group != 2) { $filter["GROUPS_ID"] = $group; } $query = \CUser::getList($b = "ID", $o = "ASC", $filter); while ($user = $query->fetch()) { $userIds[] = $user["ID"]; } return $userIds; }
public static function onSocNetUserToGroupAdd($id, $fields) { if (isset($fields['ROLE']) && isset($fields['USER_ID']) && ($fields['ROLE'] == SONET_ROLES_USER || $fields['ROLE'] == SONET_ROLES_MODERATOR || $fields['ROLE'] == SONET_ROLES_OWNER)) { if (!isset($fields['GROUP_ID'])) { $query = \CSocNetUserToGroup::getList(array(), array('ID' => $id), false, false, array('GROUP_ID', 'INITIATED_BY_USER_ID')); if ($query) { $row = $query->fetch(); if ($row) { $groupId = $row['GROUP_ID']; } } } else { $groupId = $fields['GROUP_ID']; } /** @noinspection PhpDynamicAsStaticMethodCallInspection */ if (!empty($groupId) && \CSocNetFeatures::isActiveFeature(SONET_ENTITY_GROUP, $groupId, 'files')) { $storage = Driver::getInstance()->getStorageByGroupId($groupId); if (!$storage) { return; } $rootObject = $storage->getRootObject(); if (!$rootObject->canRead($storage->getSecurityContext($fields['USER_ID']))) { return; } $errorCollection = new ErrorCollection(); Sharing::connectToUserStorage($fields['USER_ID'], array('CREATED_BY' => empty($fields['INITIATED_BY_USER_ID']) ? $fields['USER_ID'] : $fields['INITIATED_BY_USER_ID'], 'REAL_OBJECT' => $storage->getRootObject()), $errorCollection); } } }