40 if (self::$instance ===
null)
42 Loader::includeModule(
'ui');
43 self::$instance = ServiceLocator::getInstance()->get(
'ui.entityform.scope');
53 public function getUserScopes(
string $entityTypeId, ?
string $moduleId =
null): array
56 $key = $entityTypeId .
'-' . $moduleId;
58 if (!isset($results[$key]))
61 $scopeIds = $this->getScopesIdByUser($moduleId);
64 if (!empty($scopeIds))
66 $scopes = EntityFormConfigTable::getList([
70 'ACCESS_CODE' =>
'\Bitrix\Ui\EntityForm\EntityFormConfigAcTable:CONFIG.ACCESS_CODE'
74 '@ENTITY_TYPE_ID' => $entityTypeIds
77 foreach ($scopes as $scope)
79 $result[$scope[
'ID']][
'NAME'] = HtmlFilter::encode($scope[
'NAME']);
80 if (!isset($result[$scope[
'ID']][
'ACCESS_CODES'][$scope[
'ACCESS_CODE']]))
82 $accessCode =
new AccessCode($scope[
'ACCESS_CODE']);
83 $member = (
new DataProvider())->getEntity($accessCode->getEntityType(),
84 $accessCode->getEntityId());
85 $result[$scope[
'ID']][
'ACCESS_CODES'][$scope[
'ACCESS_CODE']] = $scope[
'ACCESS_CODE'];
86 $result[$scope[
'ID']][
'MEMBERS'][$scope[
'ACCESS_CODE']] = $member->getMetaData();
90 $results[$key] = $result;
93 return $results[$key];
99 'lead_details' => [
'lead_details',
'returning_lead_details'],
100 'returning_lead_details' => [
'lead_details',
'returning_lead_details'],
110 return in_array($scopeId, $this->getScopesIdByUser());
118 if ($this->user ===
null)
126 private function getScopesIdByUser(?
string $moduleId =
null): array
128 $accessCodes = $this->
getUser()->GetAccessCodes();
142 && !$scopeAccess->isAdmin()
146 $params[
'filter'] = [
'@ACCESS_CODE' => $accessCodes];
149 $scopes = EntityFormConfigAcTable::getList($params)->fetchAll();
154 foreach ($scopes as $scope)
156 $result[] = $scope[
'CONFIG_ID'];
160 return array_unique($result);
165 $accessCodes = array_filter($accessCodes,
static fn($code) => mb_strpos($code,
'CHAT') !== 0);
167 foreach ($accessCodes as &$accessCode)
169 $accessCode = preg_replace(
'|^(SG\d*?)(_[K,A,M])$|',
'$1', $accessCode);
180 if ($row = EntityFormConfigTable::getRowById($scopeId))
182 return (is_array($row[
'CONFIG']) ? $row[
'CONFIG'] :
null);
193 return EntityFormConfigTable::getRowById($scopeId);
202 foreach ($ids as $id)
204 $this->removeById($id);
214 $this->removeScopeMembers($id);
215 return EntityFormConfigTable::delete($id);
225 public function setScope(
string $categoryName,
string $guid,
string $scope,
int $userScopeId = 0): void
227 $this->
setScopeToUser($categoryName, $guid, $scope, $userScopeId);
232 string $entityTypeId,
243 if (empty($accessCodes))
254 $result = EntityFormConfigTable::add([
255 'CATEGORY' => $category,
256 'ENTITY_TYPE_ID' => $entityTypeId,
259 'COMMON' => ($params[
'common'] ??
'Y'),
262 if ($result->isSuccess())
264 $configId = $result->getId();
265 foreach ($accessCodes as $ac)
267 EntityFormConfigAcTable::add([
268 'ACCESS_CODE' => $ac[
'id'],
269 'CONFIG_ID' => $configId,
273 $forceSetToUsers = ($params[
'forceSetToUsers'] ??
false);
274 if (mb_strtoupper($forceSetToUsers) ===
'FALSE')
276 $forceSetToUsers =
false;
280 'forceSetToUsers' => $forceSetToUsers,
281 'categoryName' => ($params[
'categoryName'] ??
''),
282 'entityTypeId' => $entityTypeId,
283 'configId' => $configId,
289 return $result->getErrors();
297 foreach ($accessCodes as $key => $item)
299 if ($item[
'entityId'] === self::TYPE_USER)
301 $accessCodes[$key][
'id'] = self::CODE_USER . (int)$accessCodes[$key][
'id'];
303 elseif ($item[
'entityId'] === self::TYPE_DEPARTMENT)
305 $accessCodes[$key][
'id'] = self::CODE_DEPARTMENT . (int)$accessCodes[$key][
'id'];
307 elseif ($item[
'entityId'] === self::TYPE_PROJECT)
309 $accessCodes[$key][
'id'] = self::CODE_PROJECT . (int)$accessCodes[$key][
'id'];
312 unset($accessCodes[$key]);
323 if ($params[
'forceSetToUsers'] && $params[
'categoryName'])
325 $userIdPattern =
'/^U(\d+)$/';
326 foreach ($accessCodes as $ac)
329 if (preg_match($userIdPattern, $ac[
'id'], $matches))
332 $params[
'categoryName'],
333 $params[
'entityTypeId'],
351 string $categoryName,
366 'userScopeId' => $userScopeId
374 $userId = ($userId ??
false);
375 CUserOptions::SetOption($categoryName,
"{$guid}_scope", $value,
false, $userId);
381 return EntityFormConfigTable::update($id, [
388 return EntityFormConfigTable::update($id, [
400 $this->removeScopeMembers($configId);
402 foreach ($accessCodes as $ac => $type)
404 EntityFormConfigAcTable::add([
405 'ACCESS_CODE' => $ac,
406 'CONFIG_ID' => $configId,
419 $accessCodes = EntityFormConfigAcTable::getList([
420 'select' => [
'ACCESS_CODE'],
421 'filter' => [
'=CONFIG_ID' => $configId]
424 if (count($accessCodes))
426 foreach ($accessCodes as $accessCodeEntity)
428 $accessCode =
new AccessCode($accessCodeEntity[
'ACCESS_CODE']);
429 $member = (
new DataProvider())->getEntity($accessCode->getEntityType(), $accessCode->getEntityId());
430 $result[$accessCodeEntity[
'ACCESS_CODE']] = $member->getMetaData();
439 private function removeScopeMembers(
int $configId): void
441 $entity = EntityFormConfigAcTable::getEntity();
442 $connection = $entity->getConnection();
444 $filter = [
'CONFIG_ID' => $configId];
446 $connection->query(sprintf(
447 'DELETE FROM %s WHERE %s',
448 $connection->getSqlHelper()->quote($entity->getDBTableName()),
449 Query::buildFilterSql($entity, $filter)
static getMessage($code, $replace=null, $language=null)