Skip to content

Commit 8493365

Browse files
usoxHuxinator
authored andcommitted
Move partner sites into config
Instead of using database items for a handful of static items, move 'em to the config
1 parent b231e41 commit 8493365

File tree

6 files changed

+118
-28
lines changed

6 files changed

+118
-28
lines changed

config.dist.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,8 @@
8989
"discord": {
9090
"url": "https://chat.change.me"
9191
},
92-
"partner_banner_path": "sites/"
92+
"partner_sites": {
93+
"banner_path": "sites/",
94+
"items": []
95+
}
9396
}

src/Module/Index/View/ShowPartnerSites/ShowPartnerSites.php

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,50 @@
44

55
namespace Stu\Module\Index\View\ShowPartnerSites;
66

7+
use Noodlehaus\ConfigInterface;
78
use Stu\Module\Control\GameControllerInterface;
89
use Stu\Module\Control\ViewControllerInterface;
9-
use Stu\Orm\Repository\PartnerSiteRepositoryInterface;
1010

11+
/**
12+
* Shows all partner site items from the config
13+
*/
1114
final class ShowPartnerSites implements ViewControllerInterface
1215
{
1316
public const VIEW_IDENTIFIER = 'SHOW_PARTNER_SITES';
1417

15-
private PartnerSiteRepositoryInterface $partnerSiteRepository;
18+
private ConfigInterface $config;
1619

1720
public function __construct(
18-
PartnerSiteRepositoryInterface $partnerSiteRepository
21+
ConfigInterface $config
1922
) {
20-
$this->partnerSiteRepository = $partnerSiteRepository;
23+
$this->config = $config;
2124
}
2225

2326
public function handle(GameControllerInterface $game): void
2427
{
25-
$game->setPageTitle(_('Partnerseiten - Star Trek Universe'));
28+
$game->setPageTitle('Partnerseiten - Star Trek Universe');
2629
$game->setTemplateFile('html/index_partner_sites.xhtml');
2730

28-
$game->setTemplateVar('PARTNERSITES', $this->partnerSiteRepository->getOrdered());
31+
$game->setTemplateVar('PARTNERSITES', $this->getPartnerSites());
32+
}
33+
34+
/**
35+
* @return array<array{name: string, description: string, url: string, banner_path: string}>
36+
*/
37+
private function getPartnerSites(): array {
38+
$baseBannerPath = $this->config->get('partner_sites.banner_path');
39+
40+
return array_map(
41+
function (array $item) use ($baseBannerPath): array {
42+
/** @var array{name: string, description: string, url: string, banner_path: string} $item */
43+
$item['banner_path'] = sprintf(
44+
'/%s/%s.png',
45+
$baseBannerPath,
46+
$item['banner_path']
47+
);
48+
return $item;
49+
},
50+
$this->config->get('partner_sites.items', [])
51+
);
2952
}
3053
}

src/Orm/Entity/PartnerSite.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use Doctrine\ORM\Mapping\GeneratedValue;
1010
use Doctrine\ORM\Mapping\Id;
1111
use Doctrine\ORM\Mapping\Table;
12-
use Noodlehaus\ConfigInterface;
1312

1413
/**
1514
* @Entity(repositoryClass="Stu\Orm\Repository\PartnerSiteRepository")
@@ -82,18 +81,4 @@ public function getBanner(): string
8281
{
8382
return $this->banner;
8483
}
85-
86-
public function getFullBannerPath(): string
87-
{
88-
// @todo refactor
89-
global $container;
90-
91-
$config = $container->get(ConfigInterface::class);
92-
93-
return sprintf(
94-
'/%s/%s.png',
95-
$config->get('partner_banner_path'),
96-
$this->getBanner()
97-
);
98-
}
9984
}

src/Orm/Entity/PartnerSiteInterface.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,4 @@ public function getUrl(): string;
1313
public function getText(): string;
1414

1515
public function getBanner(): string;
16-
17-
public function getFullBannerPath(): string;
1816
}

src/html/index_partner_sites.xhtml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
</div>
88
<tal:block tal:repeat="site PARTNERSITES">
99
<div style="width: 100%;">
10-
<h4>${site/getName}</h4>
11-
${site/getText}<br />
12-
<a href="${site/getUrl}">
13-
<img tal:attributes="src site/getFullBannerPath" />
10+
<h4 tal:content="site/name">NAME</h4>
11+
<div tal:content="site/description">DESCRIPTION</div>
12+
<a tal:attributes="href site/url">
13+
<img tal:attributes="src site/banner_path; alt site/name; title site/name" />
1414
</a>
1515
<br />
1616
</div>
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Stu\Module\Index\View\ShowPartnerSites;
6+
7+
use Generator;
8+
use Mockery;
9+
use Mockery\MockInterface;
10+
use Noodlehaus\ConfigInterface;
11+
use Stu\Module\Control\GameControllerInterface;
12+
use Stu\StuTestCase;
13+
14+
class ShowPartnerSitesTest extends StuTestCase
15+
{
16+
/** @var MockInterface&ConfigInterface */
17+
private MockInterface $config;
18+
19+
private ShowPartnerSites $subject;
20+
21+
protected function setUp(): void
22+
{
23+
$this->config = $this->mock(ConfigInterface::class);
24+
25+
$this->subject = new ShowPartnerSites(
26+
$this->config
27+
);
28+
}
29+
30+
public function testHandleShowsSites(): void
31+
{
32+
$game = $this->mock(GameControllerInterface::class);
33+
34+
$baseBannerPath = 'some-base-banner-path';
35+
$siteName = 'some-site';
36+
$siteDescription = 'some-fancy-site';
37+
$siteUrl = 'some-url';
38+
$siteBannerPath = 'some-banner-path';
39+
$computedBannerPath = sprintf(
40+
'/%s/%s.png',
41+
$baseBannerPath,
42+
$siteBannerPath
43+
);
44+
45+
$game->shouldReceive('setPageTitle')
46+
->with('Partnerseiten - Star Trek Universe')
47+
->once();
48+
$game->shouldReceive('setTemplateFile')
49+
->with('html/index_partner_sites.xhtml')
50+
->once();
51+
$game->shouldReceive('setTemplateVar')
52+
->with(
53+
'PARTNERSITES',
54+
Mockery::on(fn (array $items): bool =>
55+
$items === [[
56+
'name' => $siteName,
57+
'description' => $siteDescription,
58+
'url' => $siteUrl,
59+
'banner_path' => $computedBannerPath,
60+
]]
61+
)
62+
)
63+
->once();
64+
65+
$this->config->shouldReceive('get')
66+
->with('partner_sites.items', [])
67+
->once()
68+
->andReturn([[
69+
'name' => $siteName,
70+
'description' => $siteDescription,
71+
'url' => $siteUrl,
72+
'banner_path' => $siteBannerPath,
73+
]]);
74+
$this->config->shouldReceive('get')
75+
->with('partner_sites.banner_path')
76+
->once()
77+
->andReturn($baseBannerPath);
78+
79+
$this->subject->handle($game);
80+
}
81+
}

0 commit comments

Comments
 (0)