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

News Collection Service orchestrates all news-related operations and provides a high-level API for the news service. More...

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

Public Member Functions

 __construct (private readonly NewsRepository $repository, private readonly NewsCache $cache, private readonly UserContextResolver $user_context_resolver, private readonly \ilObjectDataCache $object_data, private readonly \ilAccessHandler $access,)
 
 getNewsForUser (\ilObjUser $user, NewsCriteria $criteria, bool $lazy=false)
 
 getNewsForContext (NewsContext $context, NewsCriteria $criteria, bool $lazy=false)
 
 invalidateCache (int $user_id)
 

Private Member Functions

 getNewsForContexts (array $contexts, NewsCriteria $criteria, bool $lazy)
 
 fetchContextData (array $contexts)
 
 filterByAccess (array $contexts, NewsCriteria $criteria)
 
 applyFinalProcessing (NewsCollection $collection, NewsCriteria $criteria)
 Apply the last steps of the news collection processing pipeline: Exclude, Limit. More...
 

Detailed Description

News Collection Service orchestrates all news-related operations and provides a high-level API for the news service.

Definition at line 35 of file NewsCollectionService.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\News\Domain\NewsCollectionService::__construct ( private readonly NewsRepository  $repository,
private readonly NewsCache  $cache,
private readonly UserContextResolver  $user_context_resolver,
private readonly \ilObjectDataCache  $object_data,
private readonly \ilAccessHandler  $access 
)

Definition at line 37 of file NewsCollectionService.php.

43 {
44 }

Member Function Documentation

◆ applyFinalProcessing()

ILIAS\News\Domain\NewsCollectionService::applyFinalProcessing ( NewsCollection  $collection,
NewsCriteria  $criteria 
)
private

Apply the last steps of the news collection processing pipeline: Exclude, Limit.

Definition at line 180 of file NewsCollectionService.php.

181 {
182 return $collection->exclude($criteria->getExcludedNewsIds())->limit($criteria->getLimit());
183 }
Optimized News Collection with memory-efficient data structures to support large news feeds.
exclude(array $news_ids)
Returns a new collection with only the news items that are not in the provided list.

References ILIAS\News\Data\NewsCollection\exclude(), ILIAS\News\Data\NewsCriteria\getExcludedNewsIds(), and ILIAS\News\Data\NewsCriteria\getLimit().

Referenced by ILIAS\News\Domain\NewsCollectionService\getNewsForContext(), and ILIAS\News\Domain\NewsCollectionService\getNewsForUser().

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

◆ fetchContextData()

ILIAS\News\Domain\NewsCollectionService::fetchContextData ( array  $contexts)
private
Parameters
NewsContext[]$contexts
Returns
NewsContext[]

Definition at line 132 of file NewsCollectionService.php.

132 : array
133 {
134 // Batch loads object_data and object_references using preloading
135 $obj_ids = array_filter(array_map(fn($context) => $context->getObjId(), $contexts));
136 $this->object_data->preloadObjectCache($obj_ids);
137
138 for ($i = 0; $i < count($contexts); $i++) {
139 $context = $contexts[$i];
140
141 if ($context->getObjId() === null) {
142 $context->setObjId($this->object_data->lookupObjId($context->getRefId()));
143 }
144
145 if ($context->getObjType() === null) {
146 $context->setObjType($this->object_data->lookupType($context->getObjId()));
147 }
148
149 $contexts[$i] = $context;
150 }
151
152 return $contexts;
153 }
$context
Definition: webdav.php:31

References $context.

Referenced by ILIAS\News\Domain\NewsCollectionService\getNewsForContexts().

+ Here is the caller graph for this function:

◆ filterByAccess()

ILIAS\News\Domain\NewsCollectionService::filterByAccess ( array  $contexts,
NewsCriteria  $criteria 
)
private
Parameters
NewsContext[]$contexts
Returns
NewsContext[]

Definition at line 159 of file NewsCollectionService.php.

159 : array
160 {
161 if ($criteria->isOnlyPublic()) {
162 return $contexts;
163 }
164
165 // Preload activation cache which is used in access handler
166 \ilObjectActivation::preloadData(array_map(fn($context) => $context->getRefId(), $contexts));
167
168 $filtered = [];
169 foreach ($contexts as $context) {
170 if ($this->access->checkAccess('read', '', $context->getRefId())) {
171 $filtered[] = $context;
172 }
173 }
174 return $filtered;
175 }
static preloadData(array $ref_ids)
Preload data to internal cache.

References $context, ILIAS\Repository\access(), ILIAS\News\Data\NewsCriteria\isOnlyPublic(), and ilObjectActivation\preloadData().

Referenced by ILIAS\News\Domain\NewsCollectionService\getNewsForContexts().

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

◆ getNewsForContext()

ILIAS\News\Domain\NewsCollectionService::getNewsForContext ( NewsContext  $context,
NewsCriteria  $criteria,
bool  $lazy = false 
)

Definition at line 86 of file NewsCollectionService.php.

87 {
88 return $this->applyFinalProcessing($this->getNewsForContexts([$context], $criteria, $lazy), $criteria);
89 }
applyFinalProcessing(NewsCollection $collection, NewsCriteria $criteria)
Apply the last steps of the news collection processing pipeline: Exclude, Limit.
getNewsForContexts(array $contexts, NewsCriteria $criteria, bool $lazy)

References ILIAS\News\Domain\NewsCollectionService\applyFinalProcessing(), and ILIAS\News\Domain\NewsCollectionService\getNewsForContexts().

+ Here is the call graph for this function:

◆ getNewsForContexts()

ILIAS\News\Domain\NewsCollectionService::getNewsForContexts ( array  $contexts,
NewsCriteria  $criteria,
bool  $lazy 
)
private
Parameters
NewsContext[]$contexts

Definition at line 99 of file NewsCollectionService.php.

100 {
101 // 1. Try context cache first (L1)
102 $cached = $this->cache->getAggregatedContexts($contexts);
103 $hits = $cached['hit'];
104
105 if (!empty($cached['missing'])) {
106 // 2. Batch load missing context object information [DPL 2]
107 $remaining = $this->fetchContextData($cached['missing']);
108
109 // 3. Perform aggregation [DPL 3]
110 if (!$criteria->isPreventNesting()) {
111 $aggregated = (new NewsAggregator())->aggregate($remaining);
112 $this->cache->storeAggregatedContexts($remaining, $aggregated);
113 $hits = array_merge($hits, $aggregated);
114 } else {
115 $hits = array_merge($hits, $remaining);
116 }
117 }
118
119 // 4. Perform access checks [DPL 3]
120 $aggregated = $this->filterByAccess($hits, $criteria);
121
122 // 5. Batch load news from the database [DPL 4]
123 return $lazy
124 ? $this->repository->findByContextsBatchLazy($aggregated, $criteria)
125 : $this->repository->findByContextsBatch($aggregated, $criteria);
126 }
filterByAccess(array $contexts, NewsCriteria $criteria)

References ILIAS\News\Domain\NewsCollectionService\fetchContextData(), ILIAS\News\Domain\NewsCollectionService\filterByAccess(), ILIAS\News\Data\NewsCriteria\isPreventNesting(), and ILIAS\UI\examples\Deck\repository().

Referenced by ILIAS\News\Domain\NewsCollectionService\getNewsForContext(), and ILIAS\News\Domain\NewsCollectionService\getNewsForUser().

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

◆ getNewsForUser()

ILIAS\News\Domain\NewsCollectionService::getNewsForUser ( \ilObjUser  $user,
NewsCriteria  $criteria,
bool  $lazy = false 
)

Definition at line 46 of file NewsCollectionService.php.

47 {
48 // 1. Try user cache first
49 $cached_news = $this->cache->getNewsForUser($user->getId(), $criteria);
50 if ($cached_news !== null) {
51 // Transform the lazy collection to a normal collection if needed
52 if (!$lazy) {
53 $news_collection = new NewsCollection($this->repository->findByIds($cached_news->pluck('id')));
54 } else {
55 $news_collection = $cached_news->withFetchCallback(
56 fn(...$args) => $this->repository->loadLazyItems(...$args)
57 );
58 }
59
60 // Apply request-specific filtering [DPL 5]
61 return $this->applyFinalProcessing($news_collection, $criteria);
62 }
63
64 // 2. Add missing criteria and validate it
65 if ($criteria->isIncludeReadStatus() && $criteria->getReadUserId() === null) {
66 $criteria = $criteria->withReadUserId($user->getId());
67 }
68 $criteria->validate();
69
70 // 3. Get user accessible contexts [DPL 1]
71 $user_contexts = $this->user_context_resolver->getAccessibleContexts($user, $criteria);
72 if (empty($user_contexts)) {
73 return new NewsCollection();
74 }
75
76 // 4. Query news for resolved contexts [DPL 2-4]
77 $news_collection = $this->getNewsForContexts($user_contexts, $criteria, $lazy);
78
79 // 5. Store in cache
80 $this->cache->storeNewsForUser($user->getId(), $criteria, $news_collection);
81
82 // 6. Apply request-specific filtering [DPL 5]
83 return $this->applyFinalProcessing($news_collection, $criteria);
84 }
validate()
Validate criteria parameters.
withReadUserId(?int $read_user_id)

References ILIAS\News\Domain\NewsCollectionService\applyFinalProcessing(), ilObject\getId(), ILIAS\News\Domain\NewsCollectionService\getNewsForContexts(), ILIAS\News\Data\NewsCriteria\getReadUserId(), ILIAS\News\Data\NewsCriteria\isIncludeReadStatus(), ILIAS\UI\examples\Deck\repository(), ILIAS\News\Data\NewsCriteria\validate(), and ILIAS\News\Data\NewsCriteria\withReadUserId().

+ Here is the call graph for this function:

◆ invalidateCache()

ILIAS\News\Domain\NewsCollectionService::invalidateCache ( int  $user_id)

Definition at line 91 of file NewsCollectionService.php.

91 : void
92 {
93 $this->cache->invalidateNewsForUser($user_id, new NewsCriteria());
94 }
News Criteria DTO for querying news items supports caching, JSON serialization, and validation.

References $user_id.


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