Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
scopeaccess.php
1<?php
2
4
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}
static getInstance(string $moduleId, int $userId=null)
__construct(string $moduleId=null, int $userId=null)