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 6e85e96fcabf..13bcd9f5f20c 100755 --- a/components/ILIAS/News/Dashboard/class.InternalGUIService.php +++ b/components/ILIAS/News/Dashboard/class.InternalGUIService.php @@ -1,7 +1,5 @@ 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/News/src/Data/LazyNewsCollection.php b/components/ILIAS/News/News/src/Data/LazyNewsCollection.php index a87b9ef2f795..f08fe9161cda 100644 --- a/components/ILIAS/News/News/src/Data/LazyNewsCollection.php +++ b/components/ILIAS/News/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/News/src/Data/NewsCollection.php b/components/ILIAS/News/News/src/Data/NewsCollection.php index e05fe0415f61..1785d6e68534 100644 --- a/components/ILIAS/News/News/src/Data/NewsCollection.php +++ b/components/ILIAS/News/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/News/src/Domain/NewsCollectionService.php b/components/ILIAS/News/News/src/Domain/NewsCollectionService.php index c3984d57073b..0728ea231f52 100644 --- a/components/ILIAS/News/News/src/Domain/NewsCollectionService.php +++ b/components/ILIAS/News/News/src/Domain/NewsCollectionService.php @@ -104,7 +104,7 @@ public function getNewsForContainer( if (!\ilContainer::_lookupContainerSetting($context_obj_id, 'cont_use_news', '1') || ( !\ilContainer::_lookupContainerSetting($context_obj_id, 'cont_use_news', '1') - && !\ilContainer::_lookupContainerSetting($context_obj_id, 'news_timeline') + && !\ilContainer::_lookupContainerSetting($context_obj_id, 'news_timeline') )) { return new NewsCollection(); } @@ -121,6 +121,16 @@ public function getNewsForContainer( 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, new NewsCriteria()); diff --git a/components/ILIAS/News/classes/class.ilNewsTimelineGUI.php b/components/ILIAS/News/classes/class.ilNewsTimelineGUI.php index f6e958a0dd3a..256ad2e4a305 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