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
39 changes: 10 additions & 29 deletions components/ILIAS/News/Dashboard/class.DashboardNewsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,47 +74,28 @@ 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;
}

/**
* @return array<int,string>
*/
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
4 changes: 2 additions & 2 deletions components/ILIAS/News/Dashboard/class.InternalGUIService.php
Original file line number Diff line number Diff line change
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
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
5 changes: 5 additions & 0 deletions components/ILIAS/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/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
10 changes: 10 additions & 0 deletions components/ILIAS/News/src/Domain/NewsCollectionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ public function getNewsForContext(
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);
Expand Down
Loading