Files
scummvm-web/include/Pages/NewsPage.php
T
Le Philousophe cc9fa80181 WEB: Add typing
2025-08-24 12:32:47 +02:00

93 lines
2.7 KiB
PHP

<?php
namespace ScummVM\Pages;
use ScummVM\Controller;
use ScummVM\Models\NewsModel;
use ScummVM\Models\ScreenshotsModel;
class NewsPage extends Controller
{
private NewsModel $newsModel;
private ScreenshotsModel $screenshotModels;
/* Constructor. */
public function __construct()
{
parent::__construct();
$this->template = 'pages/news.tpl';
$this->newsModel = new NewsModel();
$this->screenshotModels = new ScreenshotsModel();
}
/**
* Display the index page.
*
* @param array{'date'?: string} $args
*/
public function index(array $args): void
{
$filename = $args['date'] ?? null;
if ($filename === null) {
$this->getNewsIntro();
return;
}
if (strtolower($filename) == 'archive' || $filename == '') {
$filename = null;
}
$this->getNews($filename);
}
/* Display a specific news item, or all news items. */
public function getNews(?string $filename = null): void
{
if ($filename == null) {
$news_items = $this->newsModel->getAllNews();
$subtitle = null;
$description = $this->getConfigVars('introHeaderContentP1');
} else {
$news_items = array($this->newsModel->getOneByFilename($filename));
$subtitle = $news_items[0]->getTitle();
$description = htmlentities($this->getHeadline($news_items[0]->getContent()));
}
$this->renderPage(
array(
'title' => $this->getConfigVars('newsTitle'),
'subtitle' => $subtitle,
'description' => $description,
'content_title' => $this->getConfigVars('newsContentTitle'),
'show_intro' => false,
'news_items' => $news_items,
'news_archive_link' => false,
)
);
}
/* Display the main page with limited news items and intro text. */
public function getNewsIntro(): void
{
$news_items = $this->newsModel->getLatestNews(NEWS_ITEMS);
$random_shot = $this->screenshotModels->getRandomScreenshot();
$this->addJSFiles(
array(
'baguetteBox.min.js'
)
);
$this->renderPage(
array(
'title' => $this->getConfigVars('homeTitle'),
'description' => $this->getConfigVars('introHeaderContentP1'),
'content_title' => $this->getConfigVars('newsContentTitle'),
'show_intro' => true,
'news_items' => $news_items,
'news_archive_link' => true,
'random_shot' => $random_shot,
)
);
}
}