Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
projectuserprovider.php
1<?php
2
4
6use Bitrix\Main\Entity\Query;
13
15{
16 protected function prepareOptions(array $options = []): void
17 {
18 parent::prepareOptions($options);
19 $this->options['projectId'] = (int)($options['projectId'] ?? null);
20 }
21
26 protected static function getQuery(array $options = []): Query
27 {
28 $projectId = $options['projectId'];
29 if ($projectId <= 0 || !static::isMember($projectId))
30 {
31 return static::getEmptyQuery();
32 }
33
34 return parent::getQuery($options)->registerRuntimeField(
35 'GROUP_MEMBERS',
36 new Reference(
37 'USER_TO_GROUP',
38 UserToGroupTable::getEntity(),
39 Join::on('this.ID', 'ref.USER_ID')
40 ->where('ref.GROUP_ID', $projectId)
41 ->whereIn('ref.ROLE', UserToGroupTable::getRolesMember()),
42 ['join_type' => Join::TYPE_INNER]
43 )
44 );
45 }
46
47 protected static function getExtranetUsersQuery(int $currentUserId): ?Query
48 {
49 // return null because static::getQuery() adds the necessary conditions
50 return null;
51 }
52
53 private static function isMember(int $projectId): bool
54 {
55 $permissions = Workgroup::getPermissions([
56 'groupId' => $projectId,
57 'userId' => static::getCurrentUserId(),
58 ]);
59
60 return $permissions['UserIsMember'] ?? false;
61 }
62
67 private static function getEmptyQuery(): Query
68 {
69 return UserTable::query()->setSelect(['ID'])->where('ID', 0);
70 }
71}
setSelect(array $select)
Definition query.php:338
static getPermissions(array $params=[])