From 3ec7d374f3ee5ffb4f862bd73f900d0df6bd474a Mon Sep 17 00:00:00 2001 From: Lukas Eichenauer Date: Fri, 17 Apr 2026 11:08:00 +0200 Subject: [PATCH 1/2] News: Fix News Context Filter See: https://mantis.ilias.de/view.php?id=47631 --- .../Dashboard/class.DashboardNewsManager.php | 8 +++----- .../News/Dashboard/class.InternalGUIService.php | 4 ++-- .../News/classes/class.ilNewsTimelineGUI.php | 10 +++++++--- .../ILIAS/News/src/Data/LazyNewsCollection.php | 5 +++++ .../ILIAS/News/src/Data/NewsCollection.php | 16 ++++++++++++++++ .../News/src/Domain/NewsCollectionService.php | 10 ++++++++++ 6 files changed, 43 insertions(+), 10 deletions(-) diff --git a/components/ILIAS/News/Dashboard/class.DashboardNewsManager.php b/components/ILIAS/News/Dashboard/class.DashboardNewsManager.php index cfbfce82b0a9..51488af22791 100755 --- a/components/ILIAS/News/Dashboard/class.DashboardNewsManager.php +++ b/components/ILIAS/News/Dashboard/class.DashboardNewsManager.php @@ -110,11 +110,9 @@ public function getPeriodOptions(): array */ public function getContextOptions(): array { - $context_count = $this->repo->news()->countByContextsBatch( - $this->domain->resolver()->getAccessibleContexts( - $this->domain->user(), - new NewsCriteria(period: $this->getDashboardNewsPeriod(), only_public: false) - ) + $context_count = $this->domain->collection()->countNewsByContext( + $this->domain->user(), + new NewsCriteria(period: $this->getDashboardNewsPeriod(), only_public: false) ); $options = []; diff --git a/components/ILIAS/News/Dashboard/class.InternalGUIService.php b/components/ILIAS/News/Dashboard/class.InternalGUIService.php index bf147c459868..13bcd9f5f20c 100755 --- a/components/ILIAS/News/Dashboard/class.InternalGUIService.php +++ b/components/ILIAS/News/Dashboard/class.InternalGUIService.php @@ -71,7 +71,7 @@ public function getFilter($force_re_init = false): FilterAdapterGUI (string) $this->manager->getDashboardNewsPeriod(), true ) - ->select("news_ref_id", $lng->txt("context"), $context_options, true, null, true); + ->select("news_ref_id", $lng->txt("context"), $context_options, true, "0", true); } return $this->filter; } @@ -79,7 +79,7 @@ public function getFilter($force_re_init = false): FilterAdapterGUI public function getTimelineGUI(): \ilNewsTimelineGUI { $ctrl = $this->gui->ctrl(); - if ($ctrl->isAsynch() && ! $this->gui->standardRequest()->getFilterOff()) { + if ($ctrl->isAsynch() && !$this->gui->standardRequest()->getFilterOff()) { $period = $this->manager->getDashboardNewsPeriod(); $news_ref_id = $this->manager->getDashboardSelectedRefId(); } else { diff --git a/components/ILIAS/News/classes/class.ilNewsTimelineGUI.php b/components/ILIAS/News/classes/class.ilNewsTimelineGUI.php index aec8b675410b..e1a7970b245f 100755 --- a/components/ILIAS/News/classes/class.ilNewsTimelineGUI.php +++ b/components/ILIAS/News/classes/class.ilNewsTimelineGUI.php @@ -45,6 +45,7 @@ class ilNewsTimelineGUI protected ilToolbarGUI $toolbar; protected ilObjUser $user; protected ilAccessHandler $access; + protected ilObjectDataCache $object_data_cache; protected static int $items_per_load = 20; protected bool $user_edit_all = false; protected StandardGUIRequest $std_request; @@ -67,6 +68,7 @@ protected function __construct( $this->access = $DIC->access(); $this->http = $DIC->http(); $this->notes = $DIC->notes(); + $this->object_data_cache = $DIC['ilObjDataCache']; $this->std_request = $DIC->news() ->internal() @@ -182,15 +184,17 @@ public function show(?ilPropertyFormGUI $form = null): void protected function readNewsData($excluded = []): void { + $context_obj_id = $this->object_data_cache->lookupObjId($this->ref_id); + $this->news_collection = $this->manager->getNewsData( $this->ref_id, - $this->ctrl->getContextObjId(), - $this->ctrl->getContextObjType(), + $context_obj_id, + $this->object_data_cache->lookupType($context_obj_id), $this->period, $this->include_auto_entries, self::$items_per_load, $excluded - ); + )->orderByDate(); } public function getHTML(?ilPropertyFormGUI $form = null): string diff --git a/components/ILIAS/News/src/Data/LazyNewsCollection.php b/components/ILIAS/News/src/Data/LazyNewsCollection.php index a87b9ef2f795..f08fe9161cda 100644 --- a/components/ILIAS/News/src/Data/LazyNewsCollection.php +++ b/components/ILIAS/News/src/Data/LazyNewsCollection.php @@ -248,4 +248,9 @@ public function limit(?int $limit): static { return parent::limit($limit)->withFetchCallback($this->fetch_callback); } + + public function orderByDate(): static + { + return parent::orderByDate()->withFetchCallback($this->fetch_callback); + } } diff --git a/components/ILIAS/News/src/Data/NewsCollection.php b/components/ILIAS/News/src/Data/NewsCollection.php index b3bd9507e577..4630ce467cee 100644 --- a/components/ILIAS/News/src/Data/NewsCollection.php +++ b/components/ILIAS/News/src/Data/NewsCollection.php @@ -432,6 +432,22 @@ public function exclude(array $news_ids): static return $filtered; } + /** + * Returns a new collection with news items ordered by creation date + */ + public function orderByDate(): static + { + $ordered = new static(); + $ordered->addNewsItems($this->news_items); + + uasort( + $ordered->news_items, + fn(NewsItem $a, NewsItem $b): int => $a->getCreationDate() <=> $b->getCreationDate() + ); + + return $ordered; + } + public function load(array $news_ids = []): static { return $this; diff --git a/components/ILIAS/News/src/Domain/NewsCollectionService.php b/components/ILIAS/News/src/Domain/NewsCollectionService.php index 198e8fde42ed..5d2bb7040d6f 100644 --- a/components/ILIAS/News/src/Domain/NewsCollectionService.php +++ b/components/ILIAS/News/src/Domain/NewsCollectionService.php @@ -91,6 +91,16 @@ public function getNewsForContext( return $this->applyFinalProcessing($this->getNewsForContexts([$context], $criteria, $user_id, $lazy), $criteria); } + /** + * @return list + */ + public function countNewsByContext(\ilObjUser $user_id, NewsCriteria $criteria): array + { + $contexts = $this->user_context_resolver->getAccessibleContexts($user_id, $criteria); + $contexts = $this->fetchContextData($contexts); + return $this->repository->countByContextsBatch($contexts); + } + public function invalidateCache(int $user_id): void { $this->cache->invalidateNewsForUser($user_id); From 0f1f91b1423b2538e300a06cb0f04923f32d1d84 Mon Sep 17 00:00:00 2001 From: Lukas Eichenauer Date: Fri, 5 Jun 2026 09:31:13 +0200 Subject: [PATCH 2/2] News: Fix News Context Filter See: https://mantis.ilias.de/view.php?id=47631 --- .../Dashboard/class.DashboardNewsManager.php | 31 +++++-------------- 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/components/ILIAS/News/Dashboard/class.DashboardNewsManager.php b/components/ILIAS/News/Dashboard/class.DashboardNewsManager.php index 51488af22791..8c63eb086ccc 100755 --- a/components/ILIAS/News/Dashboard/class.DashboardNewsManager.php +++ b/components/ILIAS/News/Dashboard/class.DashboardNewsManager.php @@ -74,35 +74,18 @@ public function saveFilterData(?array $data): void */ public function getPeriodOptions(): array { - $lng = $this->domain->lng(); - $news_set = new \ilSetting("news"); - $allow_shorter_periods = $news_set->get("allow_shorter_periods"); - $allow_longer_periods = $news_set->get("allow_longer_periods"); - $default_per = \ilNewsItem::_lookupDefaultPDPeriod(); - $options = [ - "7" => $lng->txt("news_period_1_week"), - "30" => $lng->txt("news_period_1_month"), - "366" => $lng->txt("news_period_1_year") + 7 => $this->domain->lng()->txt('news_period_1_week'), + 30 => $this->domain->lng()->txt('news_period_1_month'), + 366 => $this->domain->lng()->txt('news_period_1_year') ]; - return $options; - - /* - $unset = []; - foreach ($options as $k => $opt) { - if (!$allow_shorter_periods && ($k < $default_per)) { - $unset[$k] = $k; - } - if (!$allow_longer_periods && ($k > $default_per)) { - $unset[$k] = $k; - } - } - foreach ($unset as $k) { - unset($options[$k]); + $dash_period = $this->getDashboardNewsPeriod(); + if (!isset($options[$dash_period])) { + $options[$dash_period] = sprintf($this->domain->lng()->txt('news_period_x_days'), $dash_period); } - return $options;*/ + return $options; } /**