ILIAS  trunk Revision v12.0_alpha-399-g579a087ced2
ILIAS\News\Domain\UserContextResolver Class Reference

User Context Resolver resolves which contexts a user can access for news operations. More...

+ Collaboration diagram for ILIAS\News\Domain\UserContextResolver:

Public Member Functions

 __construct (protected readonly \ilFavouritesDBRepository $favourites_repository, protected readonly \ilAccessHandler $access, protected readonly \ilTree $tree, protected readonly NewsCache $cache)
 
 getAccessibleContexts (\ilObjUser $user, NewsCriteria $criteria)
 

Private Member Functions

 resolveUserContexts (\ilObjUser $user, NewsCriteria $criteria)
 
 shouldIncludePersonalDesktop (\ilObjUser $user)
 
 getPersonalDesktopContexts (\ilObjUser $user)
 
 getMembershipContexts (\ilObjUser $user)
 
 filterContexts (\ilObjUser $user, array $contexts, NewsCriteria $criteria)
 Deduplicate and filter contexts by access. More...
 

Detailed Description

User Context Resolver resolves which contexts a user can access for news operations.

Handles user permissions, favorites, memberships, and access control.

Definition at line 31 of file UserContextResolver.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\News\Domain\UserContextResolver::__construct ( protected readonly \ilFavouritesDBRepository  $favourites_repository,
protected readonly \ilAccessHandler  $access,
protected readonly \ilTree  $tree,
protected readonly NewsCache  $cache 
)

Definition at line 33 of file UserContextResolver.php.

38 {
39 }

Member Function Documentation

◆ filterContexts()

ILIAS\News\Domain\UserContextResolver::filterContexts ( \ilObjUser  $user,
array  $contexts,
NewsCriteria  $criteria 
)
private

Deduplicate and filter contexts by access.

Parameters
NewsContext[]$contexts
Returns
NewsContext[]

Definition at line 121 of file UserContextResolver.php.

121 : array
122 {
123 $unique_contexts = [];
124
125 foreach ($contexts as $context) {
126 if (isset($unique_contexts[$context->getRefId()])) {
127 continue;
128 }
129
130 if (
131 !$criteria->isOnlyPublic() &&
132 !$this->access->checkAccessOfUser($user->getId(), 'read', '', $context->getRefId())
133 ) {
134 continue;
135 }
136
137 $unique_contexts[$context->getRefId()] = $context;
138 }
139
140 return array_values($unique_contexts);
141 }
$context
Definition: webdav.php:31

References $context, ilObject\getId(), and ILIAS\News\Data\NewsCriteria\isOnlyPublic().

Referenced by ILIAS\News\Domain\UserContextResolver\resolveUserContexts().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getAccessibleContexts()

ILIAS\News\Domain\UserContextResolver::getAccessibleContexts ( \ilObjUser  $user,
NewsCriteria  $criteria 
)
Returns
NewsContext[]

Definition at line 44 of file UserContextResolver.php.

44 : array
45 {
46 // 1. Try cache layer
47 $cached_contexts = $this->cache->getUserContextAccess($user->getId(), $criteria);
48 if ($cached_contexts !== null) {
49 return $cached_contexts;
50 }
51
52 // 2. Resolve contexts
53 $contexts = $this->resolveUserContexts($user, $criteria);
54
55 // 3. Cache the result
56 $this->cache->storeUserContextAccess($user->getId(), $criteria, $contexts);
57
58 return $contexts;
59 }
resolveUserContexts(\ilObjUser $user, NewsCriteria $criteria)

References ilObject\getId(), and ILIAS\News\Domain\UserContextResolver\resolveUserContexts().

+ Here is the call graph for this function:

◆ getMembershipContexts()

ILIAS\News\Domain\UserContextResolver::getMembershipContexts ( \ilObjUser  $user)
private
Returns
NewsContext[]

Definition at line 101 of file UserContextResolver.php.

101 : array
102 {
103 $contexts = [];
104 $memberships = \ilParticipants::_getMembershipByType($user->getId(), ['crs', 'grp']);
105
106 foreach ($memberships as $obj_id) {
107 $contexts = array_merge(
108 $contexts,
109 array_map(fn($ref_id) => new NewsContext($ref_id, $obj_id), \ilObject::_getAllReferences($obj_id)),
110 );
111 }
112 return $contexts;
113 }
static _getAllReferences(int $id)
get all reference ids for object ID
static _getMembershipByType(int $a_usr_id, array $a_type, bool $a_only_member_role=false)
get membership by type Get course or group membership
$ref_id
Definition: ltiauth.php:66

References $ref_id, ilObject\_getAllReferences(), ilParticipants\_getMembershipByType(), and ilObject\getId().

Referenced by ILIAS\News\Domain\UserContextResolver\resolveUserContexts().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getPersonalDesktopContexts()

ILIAS\News\Domain\UserContextResolver::getPersonalDesktopContexts ( \ilObjUser  $user)
private
Returns
NewsContext[]

Definition at line 88 of file UserContextResolver.php.

88 : array
89 {
90 $contexts = [];
91
92 foreach ($this->favourites_repository->getFavouritesOfUser($user->getId()) as $item) {
93 $contexts[] = new NewsContext($item['ref_id'], $item['obj_id'], $item['type']);
94 }
95 return $contexts;
96 }

References ilObject\getId().

Referenced by ILIAS\News\Domain\UserContextResolver\resolveUserContexts().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ resolveUserContexts()

ILIAS\News\Domain\UserContextResolver::resolveUserContexts ( \ilObjUser  $user,
NewsCriteria  $criteria 
)
private
Returns
NewsContext[]

Definition at line 64 of file UserContextResolver.php.

64 : array
65 {
66 $contexts = [];
67
68 // Get user's personal desktop items
69 if ($this->shouldIncludePersonalDesktop($user)) {
70 $contexts = array_merge($contexts, $this->getPersonalDesktopContexts($user));
71 }
72
73 // Get user's memberships
74 $contexts = array_merge($contexts, $this->getMembershipContexts($user));
75
76 // Remove duplicates and filter by access
77 return $this->filterContexts($user, $contexts, $criteria);
78 }
filterContexts(\ilObjUser $user, array $contexts, NewsCriteria $criteria)
Deduplicate and filter contexts by access.

References ILIAS\News\Domain\UserContextResolver\filterContexts(), ILIAS\News\Domain\UserContextResolver\getMembershipContexts(), ILIAS\News\Domain\UserContextResolver\getPersonalDesktopContexts(), and ILIAS\News\Domain\UserContextResolver\shouldIncludePersonalDesktop().

Referenced by ILIAS\News\Domain\UserContextResolver\getAccessibleContexts().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ shouldIncludePersonalDesktop()

ILIAS\News\Domain\UserContextResolver::shouldIncludePersonalDesktop ( \ilObjUser  $user)
private

Definition at line 80 of file UserContextResolver.php.

80 : bool
81 {
82 return $user->getPref('pd_items_news') !== 'n';
83 }

References ilObjUser\getPref().

Referenced by ILIAS\News\Domain\UserContextResolver\resolveUserContexts().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: