From 4d1481fcfb5534bf21ae183f8d24c9e8b6aca229 Mon Sep 17 00:00:00 2001 From: Michel Date: Tue, 12 Nov 2024 19:38:47 +0100 Subject: [PATCH 1/2] BUG: Improves Game Imports usage --- src/php/Entities/Games/Game.php | 15 +++++++++++- src/php/Importer/GameImporter.php | 39 ++++++++++++++++++++++++++----- 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/src/php/Entities/Games/Game.php b/src/php/Entities/Games/Game.php index 90ed9be..c6d954d 100644 --- a/src/php/Entities/Games/Game.php +++ b/src/php/Entities/Games/Game.php @@ -15,6 +15,8 @@ class Game private int|null $id; #[ORM\Column] private string $name; + #[ORM\Column(nullable: true)] + private string|null $internalName; public function getName(): string { @@ -25,12 +27,23 @@ class Game { return $this->id; } + + public function getInternalName(): string + { + return $this->internalName ?? $this->name; + } + + public function setInternalName(string $internalName): void + { + $this->internalName = $internalName; + } /** * @param string $name */ - public function __construct(string $name) + public function __construct(string $internalName, string $name) { + $this->internalName = $internalName; $this->name = $name; } } \ No newline at end of file diff --git a/src/php/Importer/GameImporter.php b/src/php/Importer/GameImporter.php index dd275db..965cbf3 100644 --- a/src/php/Importer/GameImporter.php +++ b/src/php/Importer/GameImporter.php @@ -3,14 +3,17 @@ declare(strict_types=1); namespace GamesShop\Importer; +use Doctrine\Common\Collections\Criteria; use Doctrine\ORM\EntityManagerInterface; use Exception; +use GamesShop\ContainerHandler; use GamesShop\Entities\Account\User; use GamesShop\Entities\Games\Game; use GamesShop\Entities\Games\Key; use GamesShop\Entities\Games\KeyAttribute; use GamesShop\Entities\Games\Store; use GamesShop\Entities\GamesList; +use Monolog\Logger; use PhpOffice\PhpSpreadsheet\IOFactory; final class GameImporter @@ -127,19 +130,27 @@ final class GameImporter continue; } - $game = array_key_exists($values['name'], $foundGames) ? $foundGames[$values['name']] : null; + $internalName = $this->prepareGameName($values['name']); + $game = array_key_exists($internalName, $foundGames) ? $foundGames[$internalName] : null; + + ContainerHandler::get(Logger::class)->debug('importing game ' . $internalName); if ($game === null) { - $game = $this->entityManager->getRepository(Game::class)->findOneBy([ 'name' => $values['name'] ]); + $game = $this->entityManager->getRepository(Game::class)->matching( + Criteria::create() + ->where(Criteria::expr()->eq('name', $values['name'])) + ->orWhere(Criteria::expr()->eq('internalName', $internalName)) + )->first(); } - if ($game === null) { - $game = new Game($values['name']); + if ($game === false) { + $game = new Game($internalName, $values['name']); $this->entityManager->persist($game); } - $foundGames[$values['name']] = $game; - + $foundGames[$internalName] = $game; + $game->setInternalName($internalName); + $key = new Key( $game, $list, @@ -174,4 +185,20 @@ final class GameImporter return Store::EXTERNAL; } + + private function prepareGameName(string $name): string + { + $replacements = [ + ':' => '', + '-' => '', + ',' => '', + '!' => '', + '?' => '', + ' ' => ' ', + ' ' => '_', + ]; + + $name = strtoupper($name); + return str_replace(array_keys($replacements), array_values($replacements), $name); + } } \ No newline at end of file -- 2.45.2 From 0b3eae20a608086a86615eb5a88e5177a61d193c Mon Sep 17 00:00:00 2001 From: Michel Date: Tue, 12 Nov 2024 20:04:10 +0100 Subject: [PATCH 2/2] FEAT: Adds git messages on the bottom of the website --- src/templates/layout/main.php | 11 +++++++++++ src/templates/layout/navbar.php | 23 +++++++++++------------ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/templates/layout/main.php b/src/templates/layout/main.php index c1cb854..0ad21c9 100644 --- a/src/templates/layout/main.php +++ b/src/templates/layout/main.php @@ -45,5 +45,16 @@ $resource = $resources->getResource($resourceEntry); PROTOTYPE / POC + + diff --git a/src/templates/layout/navbar.php b/src/templates/layout/navbar.php index e16c5ba..6477edb 100644 --- a/src/templates/layout/navbar.php +++ b/src/templates/layout/navbar.php @@ -29,25 +29,24 @@ $currentPermission = $activeUser === null ? UserPermission::NONE : $activeUser-> } ?> - +
+ + + +
insert('layout/accountDisplay'); ?> -
- - - -
\ No newline at end of file -- 2.45.2