mirror of
https://github.com/scummvm/scummvm-web.git
synced 2026-05-21 05:40:47 +00:00
69 lines
2.4 KiB
PHP
69 lines
2.4 KiB
PHP
<?php
|
|
namespace ScummVM\Models;
|
|
|
|
use ScummVM\Objects\DownloadsSection;
|
|
use ScummVM\OrmObjects\GameDownloadQuery;
|
|
|
|
/**
|
|
* The GameDownloadsModel will produce DownloadsSection objects.
|
|
*/
|
|
class GameDownloadsModel extends BasicModel
|
|
{
|
|
/* Get all download entries. */
|
|
public function getAllDownloads()
|
|
{
|
|
$sections = $this->getFromCache();
|
|
if (is_null($sections)) {
|
|
$sections = [];
|
|
$sectionsData = $this->getSectionData();
|
|
$categories = GameDownloadQuery::create()
|
|
->select('category')
|
|
->distinct()
|
|
->find();
|
|
|
|
foreach ($categories as $category) {
|
|
$sections[$category] = new DownloadsSection([
|
|
'anchor' => $category,
|
|
'title' => $sectionsData[$category]['title'],
|
|
'notes' => $sectionsData[$category]['notes'] ?? null
|
|
]);
|
|
}
|
|
|
|
$gameDownloads = GameDownloadQuery::create()
|
|
->joinGame()
|
|
->find();
|
|
foreach ($gameDownloads as $gameDownload) {
|
|
// Create Sections
|
|
$category = $gameDownload->getCategory();
|
|
$gameId = $gameDownload->getGameId();
|
|
$gameName = $gameDownload->getGame()->getName();
|
|
|
|
// Create Subsections
|
|
if (!isset($sections[$category]->getSubSections()[$gameId])) {
|
|
$sections[$category]->addSubsection(new DownloadsSection([
|
|
'anchor' => $gameId,
|
|
'title' => $gameName,
|
|
'notes' => $sectionsData[$gameId]['notes'] ?? null
|
|
]));
|
|
}
|
|
|
|
// Add Download to subsection
|
|
$gameDownload->setName($gameName . " - " . $gameDownload->getName());
|
|
$sections[$category]->getSubsections()[$gameId]->addItem($gameDownload);
|
|
}
|
|
$this->saveToCache($sections);
|
|
}
|
|
return $sections;
|
|
}
|
|
|
|
private function getSectionData()
|
|
{
|
|
return [
|
|
"games"=>["title"=>"{#gamesXMLTitle#} {#downloadsXMLVersion#}"],
|
|
"addons"=>["title"=>"{#gamesXMLAddons#} {#downloadsXMLVersion#}"],
|
|
"sword1"=>["notes"=>"{#sword1AddonsNote#}"],
|
|
"sword2"=>["notes"=>"{#sword2AddonsNote#}"],
|
|
];
|
|
}
|
|
}
|