19declare(strict_types=1);
48 $cached_news = $this->cache->getNewsForUser($user->
getId(), $criteria);
49 if ($cached_news !==
null) {
54 $news_collection = $cached_news->withFetchCallback(
55 fn(...$args) => $this->
repository->loadLazyItems(...$args)
70 $user_contexts = $this->user_context_resolver->getAccessibleContexts($user, $criteria);
71 if (empty($user_contexts)) {
79 $this->cache->storeNewsForUser($user->
getId(), $criteria, $news_collection);
96 $this->cache->invalidateNewsForUser(
$user_id);
105 $cached = $this->cache->getAggregatedContexts($contexts);
106 $hits = $cached[
'hit'];
108 if (!empty($cached[
'missing'])) {
110 $remaining = $this->fetchContextData($cached[
'missing']);
115 $this->cache->storeAggregatedContexts($remaining, $aggregated);
116 $hits = array_merge($hits, $aggregated);
118 $hits = array_merge($hits, $remaining);
123 $criteria = $this->appendStartDateFilter($hits, $criteria);
126 $aggregated = $this->filterByAccess($hits, $criteria,
$user_id);
130 ? $this->
repository->findByContextsBatchLazy($aggregated, $criteria)
131 : $this->
repository->findByContextsBatch($aggregated, $criteria);
141 $obj_ids = array_filter(array_map(fn($context) => $context->getObjId(), $contexts));
142 $this->object_data->preloadObjectCache($obj_ids);
144 for ($i = 0; $i < count($contexts); $i++) {
145 $context = $contexts[$i];
147 if ($context->getObjId() ===
null) {
148 $context->setObjId($this->object_data->lookupObjId($context->getRefId()));
151 if ($context->getObjType() ===
null) {
152 $context->setObjType($this->object_data->lookupType($context->getObjId()));
155 $contexts[$i] = $context;
172 $contexts = $this->
repository->filterContext($contexts, $criteria);
175 $this->
rbac->preloadRbacPaCache(array_map(fn($context) => $context->getRefId(), $contexts),
$user_id);
178 usort($contexts, fn(
$a,
$b) =>
$a->getLevel() <=>
$b->getLevel());
182 foreach ($contexts as $context) {
184 if (isset($ac_result[$context->getParentRefId()]) && !$ac_result[$context->getParentRefId()]) {
188 $ac_result[$context->getRefId()] = $this->
rbac->checkAccess(
190 $context->getRefId(),
191 $context->getObjType(),
194 if ($ac_result[$context->getRefId()]) {
195 $filtered[] = $context;
208 foreach ($contexts as $context) {
210 !in_array($context->getObjType(), [
'grp',
'crs']) ||
217 if (empty($hide_date)) {
221 $date_filter[$context->getObjId()] = new \DateTimeImmutable($hide_date);
News Aggregator aggregates related contexts for a news context using a layer-wise Batching BFS to agg...
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.
News Context DTO represents a context where news items can be associated with.
News Criteria DTO for querying news items supports caching, JSON serialization, and validation.
validate()
Validate criteria parameters.
withReadUserId(?int $read_user_id)
withStartDates(array $start_dates)
News Collection Service orchestrates all news-related operations and provides a high-level API for th...
__construct(private readonly NewsRepository $repository, private readonly NewsCache $cache, private readonly UserContextResolver $user_context_resolver, private readonly \ilObjectDataCache $object_data, private readonly \ilRbacSystem $rbac)
applyFinalProcessing(NewsCollection $collection, NewsCriteria $criteria)
Apply the last steps of the news collection processing pipeline: Exclude, Limit.
fetchContextData(array $contexts)
getNewsForContext(NewsContext $context, NewsCriteria $criteria, int $user_id, bool $lazy=false)
appendStartDateFilter(array $contexts, NewsCriteria $criteria)
filterByAccess(array $contexts, NewsCriteria $criteria, int $user_id)
getNewsForUser(\ilObjUser $user, NewsCriteria $criteria, bool $lazy=false)
invalidateCache(int $user_id)
getNewsForContexts(array $contexts, NewsCriteria $criteria, int $user_id, bool $lazy)
User Context Resolver resolves which contexts a user can access for news operations.
Multi-Level News Cache Implementation:
News Repository provides basic CRUD operations and optimized database access for news operations with...
static _lookup(string $a_type, string $a_setting, int $a_user=0, int $a_block_id=0)
Lookup setting from database.
class ilRbacSystem system function like checkAccess, addActiveRole ... Supporting system functions ar...
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples