1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
scopeaccess.php
См. документацию.
1<?php
2
3namespace Bitrix\Ui\EntityForm;
4
5use Bitrix\Main\Config\Configuration;
6use Bitrix\Main\Engine\CurrentUser;
7use Bitrix\Main\Loader;
8use Bitrix\Main\ObjectNotFoundException;
9use Bitrix\Main\UserField\UserFieldAccess;
10use Bitrix\Main\UserFieldTable;
11
13{
14 public const SETTINGS_ENTITYFORM_SCOPE_KEY = 'entityFormScope';
15 public const SETTINGS_ACCESS_CLASS_KEY = 'access';
16
17 protected $userId;
18 protected $moduleId;
19
20 public function __construct(string $moduleId = null, int $userId = null)
21 {
22 if($userId === null)
23 {
24 $userId = $this->getDefaultUserId();
25 }
26
27 $this->userId = $userId;
28 $this->moduleId = $moduleId;
29 }
30
31 protected function getDefaultUserId(): int
32 {
33 global $USER;
34 if($USER instanceof \CUser)
35 {
36 return (int) CurrentUser::get()->getId();
37 }
38
39 return 0;
40 }
41
42 public static function getInstance(string $moduleId, int $userId = null): ScopeAccess
43 {
44 $configuration = Configuration::getInstance($moduleId);
45
46 $value = $configuration->get(static::SETTINGS_ENTITYFORM_SCOPE_KEY);
47 if (
48 is_array($value)
49 && isset($value[static::SETTINGS_ACCESS_CLASS_KEY])
50 && Loader::includeModule($moduleId)
51 && is_a($value[static::SETTINGS_ACCESS_CLASS_KEY], self::class, true)
52 )
53 {
54 return new $value[static::SETTINGS_ACCESS_CLASS_KEY]($moduleId, $userId);
55 }
56
57 throw new ObjectNotFoundException('No settings for ScopeAccess');
58 }
59
60 public function canRead(int $scopeId): bool
61 {
62 return true;
63 }
64
65 public function canAdd(): bool
66 {
67 return true;
68 }
69
70 public function canUpdate(int $scopeId): bool
71 {
72 return $this->canAdd();
73 }
74
75 public function canDelete($scopeIds): bool
76 {
77 return $this->canUpdate($scopeIds);
78 }
79
80 public function isAdmin(): bool
81 {
82 return true;
83 }
84
85 public function isAdminForEntityTypeId(string $entityTypeId): bool
86 {
87 return $this->isAdmin();
88 }
89
90 public function canAddByEntityTypeId(string $entityTypeId): bool
91 {
92 return $this->canAdd();
93 }
94}
const SETTINGS_ENTITYFORM_SCOPE_KEY
Определения scopeaccess.php:14
canRead(int $scopeId)
Определения scopeaccess.php:60
isAdminForEntityTypeId(string $entityTypeId)
Определения scopeaccess.php:85
static getInstance(string $moduleId, int $userId=null)
Определения scopeaccess.php:42
const SETTINGS_ACCESS_CLASS_KEY
Определения scopeaccess.php:15
__construct(string $moduleId=null, int $userId=null)
Определения scopeaccess.php:20
canAddByEntityTypeId(string $entityTypeId)
Определения scopeaccess.php:90
canUpdate(int $scopeId)
Определения scopeaccess.php:70
canDelete($scopeIds)
Определения scopeaccess.php:75
global $USER
Определения csv_new_run.php:40