1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
userregistry.php
См. документацию.
1<?php
2
3namespace Bitrix\Socialnetwork\Internals\Registry;
4
5
6use Bitrix\Main\Application;
7use Bitrix\Main\ORM\Fields\Relations\Reference;
8use Bitrix\Main\ORM\Query\Join;
9use Bitrix\Socialnetwork\Item\Workgroup\Type;
10use Bitrix\Socialnetwork\UserToGroupTable;
11use Bitrix\Socialnetwork\WorkgroupTable;
12use Bitrix\Main\Data\Cache;
13
15{
16 private const CACHE_PREFIX = 'sonet_user2group_U';
17 private const CACHE_DIR = '/sonet/userregistry';
18 private const CACHE_TTL = 3 * 60 * 60;
19
20 public const MODE_GROUP_ALL = 'all';
21 public const MODE_GROUP = 'group';
22 public const MODE_PROJECT = 'project';
23 public const MODE_SCRUM = 'scrum';
24 public const MODE_COLLAB = 'collab';
25 public const MODE_EXCLUDE_SCRAM = 'ex_scram';
26
27 private static array $instance = [];
28
29 private int $userId;
30 private array $userGroups = [];
31 private array $userProjects = [];
32 private array $userWorkgroups = [];
33 private array $userScrum = [];
34 private array $userCollabs = [];
35
36 public static function getInstance(int $userId): self
37 {
38 if (!array_key_exists($userId, self::$instance))
39 {
40 self::$instance[$userId] = new self($userId);
41 }
42 return self::$instance[$userId];
43 }
44
45 public function getUserGroups(string $mode = self::MODE_GROUP_ALL): array
46 {
47 switch ($mode)
48 {
49 case self::MODE_GROUP:
50 $groups = $this->userWorkgroups;
51 break;
52 case self::MODE_PROJECT:
53 $groups = $this->userProjects;
54 break;
55 case self::MODE_SCRUM:
56 $groups = $this->userScrum;
57 break;
58 case self::MODE_COLLAB:
59 $groups = $this->userCollabs;
60 break;
61 case self::MODE_EXCLUDE_SCRAM:
62 $groups = array_replace($this->userProjects, $this->userWorkgroups);
63 break;
64 default:
65 $groups = $this->userGroups;
66 }
67
68 return $groups;
69 }
70
71 public function invalidate(int $userId): static
72 {
73 Cache::createInstance()->cleanDir($this->getCacheDir($userId));
74
75 $this->loadGroupInfo();
76
77 return $this;
78 }
79
80 private function __construct(int $userId)
81 {
82 $this->userId = $userId;
83 $this->loadGroupInfo();
84 }
85
86 private function loadGroupInfo(): void
87 {
88 $cache = Cache::createInstance();
89
90 if ($cache->initCache(self::CACHE_TTL, $this->getCacheTag(), $this->getCacheDir()))
91 {
92 $res = $cache->getVars();
93 }
94 else
95 {
96 $res = UserToGroupTable::query()
97 ->addSelect('GROUP_ID')
98 ->addSelect('ROLE')
99 ->addSelect('WORKGROUP.PROJECT', 'PROJECT')
100 ->addSelect('WORKGROUP.TYPE', 'TYPE')
101 ->addSelect('WORKGROUP.SCRUM_MASTER_ID', 'SCRUM_MASTER')
102 ->registerRuntimeField(
103 new Reference(
104 'WORKGROUP',
105 WorkgroupTable::class,
106 Join::on('this.GROUP_ID', 'ref.ID'),
107 ['join_type' => 'LEFT']
108 )
109 )
110 ->setFilter([
111 '=USER_ID' => $this->userId,
113 ])
114 ->fetchAll();
115
116 $taggedCache = Application::getInstance()->getTaggedCache();
117 $taggedCache->StartTagCache($this->getCacheDir());
118 $taggedCache->RegisterTag($this->getCacheTag());
119
120 $cache->startDataCache();
121 $cache->endDataCache($res);
122 $taggedCache->EndTagCache();
123 }
124
125 foreach ($res as $row)
126 {
127 $this->userGroups[$row['GROUP_ID']] = $row['ROLE'];
128 if ((int)$row['SCRUM_MASTER'] > 0)
129 {
130 $this->userScrum[$row['GROUP_ID']] = $row['ROLE'];
131 }
132 elseif ($row['PROJECT'] === 'Y')
133 {
134 $this->userProjects[$row['GROUP_ID']] = $row['ROLE'];
135 }
136 elseif ($row['TYPE'] === Type::Collab->value)
137 {
138 $this->userCollabs[$row['GROUP_ID']] = $row['ROLE'];
139 }
140 else
141 {
142 $this->userWorkgroups[$row['GROUP_ID']] = $row['ROLE'];
143 }
144 }
145 }
146
147 private function getCacheTag(): string
148 {
149 return self::CACHE_PREFIX . $this->userId;
150 }
151
152 private function getCacheDir(?int $userId = null): string
153 {
154 return self::CACHE_DIR . '/' . substr(md5($userId ?? $this->userId),2,2) . '/';
155 }
156}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
getUserGroups(string $mode=self::MODE_GROUP_ALL)
Определения userregistry.php:45
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$groups
Определения options.php:30
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393