Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down
8 changes: 4 additions & 4 deletions components/ILIAS/News/Dashboard/class.InternalGUIService.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(strict_types=1);

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
Expand All @@ -18,6 +16,8 @@
*
*********************************************************************/

declare(strict_types=1);

namespace ILIAS\News\Dashboard;

use ILIAS\DI\Container;
Expand Down Expand Up @@ -71,15 +71,15 @@ 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;
}

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 {
Expand Down
5 changes: 5 additions & 0 deletions components/ILIAS/News/News/src/Data/LazyNewsCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
16 changes: 16 additions & 0 deletions components/ILIAS/News/News/src/Data/NewsCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 11 additions & 1 deletion components/ILIAS/News/News/src/Domain/NewsCollectionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -121,6 +121,16 @@ public function getNewsForContainer(
return $this->applyFinalProcessing($this->getNewsForContexts([$context], $criteria, $user_id, $lazy), $criteria);
}

/**
* @return list<array{0: NewsContext, 1: int}>
*/
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());
Expand Down
10 changes: 7 additions & 3 deletions components/ILIAS/News/classes/class.ilNewsTimelineGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand Down
Loading