WEB: Add Director demos page, model and template

This commit is contained in:
mataniko
2021-08-23 22:17:58 -04:00
parent de958780bd
commit 43e117fdf2
3 changed files with 128 additions and 0 deletions
+44
View File
@@ -0,0 +1,44 @@
<?php
namespace ScummVM\Models;
use ScummVM\OrmObjects\DirectorDemoQuery;
/**
* The DirectorDemosModel class will generate DirectorDemos objects.
*/
class DirectorDemosModel extends BasicModel
{
/* Get all the groups and their respective demos. */
public function getAllGroupsAndDemos()
{
$groupedData = $this->getFromCache();
if (is_null($groupedData)) {
$demos = DirectorDemoQuery::create()
->orderByVersion()
->orderByTitle()
->find();
$groupedData = $this->createGroups($demos);
$this->saveToCache($groupedData);
}
return $groupedData;
}
private function createGroups($demos)
{
$groups = [];
foreach ($demos as $demo) {
$version = $demo->getVersion();
if (!isset($groups[$version])) {
$groups[$version] = [
'name' => "Version $version Demos",
'href' => $version,
'demos' => []
];
}
$groups[$version]['demos'][] = $demo;
}
return $groups;
}
}
+31
View File
@@ -0,0 +1,31 @@
<?php
namespace ScummVM\Pages;
use ScummVM\Controller;
use ScummVM\Models\DirectorDemosModel;
class DirectorDemosPage extends Controller
{
private $gameDemosModel;
/* Constructor. */
public function __construct()
{
parent::__construct();
$this->template = 'pages/director_demos.tpl';
$this->gameDemosModel = new DirectorDemosModel();
}
/* Display the index page. */
public function index()
{
$demos = $this->gameDemosModel->getAllGroupsAndDemos();
return $this->renderPage(
array(
'title' => $this->getConfigVars('directorDemosTitle'),
'content_title' => $this->getConfigVars('directorDemosContentTitle'),
'demos' => $demos,
)
);
}
}
+53
View File
@@ -0,0 +1,53 @@
<script type="text/javascript" src="/js/game_demos.js"></script>
{capture "intro"}
<div class="row">
<div class="navigation col-1-2 col-md-1">
<h4 class="subhead">{#gamesDemosHeading#}</h4>
<ul>
{foreach $demos $group}
<li><a href="{'/demos/director'|lang}#{$group.href}">{$group.name}</a></li>
{/foreach}
</ul>
</div>
<div class="text col-1-2 col-md-1">
<p>
{#gamesDemosContentP1#}
</p>
</div>
</div>
{/capture}
{capture "content"}
{foreach $demos as $group}
<div class="chart-wrapper" id="{$group.href}"><span>{$group.name}</span>
<table class="chart color4 gameDemos">
<thead>
<tr class="color4">
<th>{#gamesDemosH1#}</th>
<th class="gameTarget">{#gamesDemosH2#}</th>
</tr>
</thead>
<tbody>
{foreach $group.demos as $i => $demo}
{if $demo@first}
{$collapse = ''}
{elseif $group.demos[$i]->getId() == $group.demos[$i-1]->getId()}
{$collapse = 'collapse'}
{else}
{$collapse = ''}
{/if}
<tr class="{if $collapse}{$collapse} sub{else}{cycle values="color2, color0"}{/if}">
<td>
<a href="{$demo->getURL()|download}">{$demo->getTitle()} ({\locale_get_display_language($demo->getLang(), $lang)}/{$demo->getPlatform()->getName()})</a>
</td>
<td class="gameTarget">{$demo->getId()}</td>
</tr>
{/foreach}
</tbody>
</table>
</div>
{/foreach}
{/capture}
{include file="components/box.tpl" head=$content_title intro=$smarty.capture.intro content=$smarty.capture.content}