Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improved activity in news article experience #1897

Merged
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
33 changes: 18 additions & 15 deletions module/Frontpage/src/Service/Frontpage.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
use function abs;
use function array_merge;
use function array_slice;
use function count;
use function shuffle;
use function usort;

/**
Expand Down Expand Up @@ -88,7 +90,7 @@ public function getHomePageData(): array
$poll = $this->pollService->getNewestPoll();
$pollDetails = $this->pollService->getPollDetails($poll);
$pollDetails['poll'] = $poll;
$news = $this->getNewsItems();
$news = $this->getNewsItems($activities);
$companyBanner = $this->companyService->getCurrentBanner();

return [
Expand Down Expand Up @@ -145,31 +147,32 @@ public function getBirthdayInfo(): array
* Returns a mixed array of news items and activities to display in the
* news section.
*
* @param ActivityModel[] $activities
*
* @return array<array-key, ActivityModel|NewsItemModel>
*/
public function getNewsItems(): array
public function getNewsItems(array $activities): array
{
$count = $this->frontpageConfig['news_count'];
$activities = $this->getUpcomingActivities();
$newsItems = $this->newsService->getLatestNewsItems($count);
$news = array_merge($activities, $newsItems);
usort($news, function ($a, $b) {
if (($a instanceof NewsItemModel) && ($b instanceof NewsItemModel)) {
if ($a->getPinned() === $b->getPinned()) {
return $this->getItemTimestamp($a) - $this->getItemTimestamp($b);
}

return $a->getPinned() ? -1 : 1;
}

if (($a instanceof ActivityModel) && ($b instanceof ActivityModel)) {
usort($newsItems, function ($a, $b) {
if ($a->getPinned() === $b->getPinned()) {
return $this->getItemTimestamp($a) - $this->getItemTimestamp($b);
}

return $a instanceof ActivityModel ? 1 : -1;
return $a->getPinned() ? -1 : 1;
});

return array_slice($news, 0, $count);
$newsCount = count($newsItems);

if ($newsCount < $count) {
$remainingCount = $count - $newsCount;
shuffle($activities);
$newsItems = array_merge($newsItems, array_slice($activities, 0, $remainingCount));
}

return $newsItems;
}

/**
Expand Down
10 changes: 9 additions & 1 deletion module/Frontpage/view/frontpage/frontpage/home.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,15 @@ $lang = $this->plugin('translate')->getTranslator()->getLocale();
}
?>
<article class="content-article">
<h3><?= $this->escapeHtml($title) ?></h3>
<?php if ($item instanceof ActivityModel): ?>
<h3>
<a href="<?= $this->url('activity/view', ['id' => $item->getId()]) ?>">
<?= $this->escapeHtml($title) ?>
</a>
</h3>
<?php else: ?>
<h3><?= $this->escapeHtml($title) ?></h3>
<?php endif; ?>
<div style="position: relative; overflow: hidden;">
<div class="reveal reveal-10 markdown">
<?= $content ?>
Expand Down
Loading