From 725ed65461beb636adddae1ddcae71a73c435935 Mon Sep 17 00:00:00 2001 From: Stefan Topfstedt Date: Sat, 12 Dec 2020 16:39:21 -0800 Subject: [PATCH] adds title attribute to restrictions entity. --- migrations/Version20201213002601.php | 33 ++++++++++++++++++++ src/Command/ActivateRestrictionCommand.php | 4 +-- src/Command/DeactivateRestrictionCommand.php | 4 +-- src/Command/ImportRestrictionsCommand.php | 24 ++++++++++++++ src/Command/ListRestrictionsCommand.php | 3 +- src/Entity/Restriction.php | 28 +++++++++++++++++ src/Entity/RestrictionInterface.php | 10 ++++++ 7 files changed, 99 insertions(+), 7 deletions(-) create mode 100644 migrations/Version20201213002601.php diff --git a/migrations/Version20201213002601.php b/migrations/Version20201213002601.php new file mode 100644 index 00000000..3f874d0b --- /dev/null +++ b/migrations/Version20201213002601.php @@ -0,0 +1,33 @@ +abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); + + $this->addSql('ALTER TABLE restriction ADD title VARCHAR(50) NOT NULL'); + } + + public function down(Schema $schema) : void + { + $this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'mysql', 'Migration can only be executed safely on \'mysql\'.'); + + $this->addSql('ALTER TABLE restriction DROP title'); + } +} diff --git a/src/Command/ActivateRestrictionCommand.php b/src/Command/ActivateRestrictionCommand.php index 6c2da71c..8a26c582 100644 --- a/src/Command/ActivateRestrictionCommand.php +++ b/src/Command/ActivateRestrictionCommand.php @@ -47,9 +47,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int foreach ($restrictions as $restriction) { $map[$restriction->getCode()] = $restriction; - $options[$restriction->getCode()] = $restriction->getIssuer() - . ' (Version: ' . $restriction->getVersion() . ')' - . ', effective on ' . $restriction->getEffectiveOn()->format('Y-m-d'); + $options[$restriction->getCode()] = $restriction->getTitle(); } if (empty($options)) { diff --git a/src/Command/DeactivateRestrictionCommand.php b/src/Command/DeactivateRestrictionCommand.php index e8093dde..d0d0affb 100644 --- a/src/Command/DeactivateRestrictionCommand.php +++ b/src/Command/DeactivateRestrictionCommand.php @@ -47,9 +47,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int foreach ($restrictions as $restriction) { $map[$restriction->getCode()] = $restriction; - $options[$restriction->getCode()] = $restriction->getIssuer() - . ' (Version: ' . $restriction->getVersion() . ')' - . ', effective on ' . $restriction->getEffectiveOn()->format('Y-m-d'); + $options[$restriction->getCode()] = $restriction->getTitle(); } if (empty($options)) { diff --git a/src/Command/ImportRestrictionsCommand.php b/src/Command/ImportRestrictionsCommand.php index 0d97b547..6e5e0fb5 100644 --- a/src/Command/ImportRestrictionsCommand.php +++ b/src/Command/ImportRestrictionsCommand.php @@ -23,6 +23,20 @@ class ImportRestrictionsCommand extends Command { const RESTRICTIONS_FILE_NAME = 'restricted-list.json'; + const ISSUER_FFG = 'Fantasy Flight Games'; + + const ISSUER_CONCLAVE = 'The Conclave'; + + const ISSUER_DESIGN_TEAM = 'Redesigns'; + + const ISSUER_FFG_SHORTNAME = 'FFG'; + + protected array $faqIssuers = [ + self::ISSUER_FFG, + self::ISSUER_CONCLAVE, + self::ISSUER_DESIGN_TEAM + ]; + protected EntityManagerInterface $entityManager; public function __construct(EntityManagerInterface $entityManager) @@ -77,6 +91,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $restriction->setCode($code); $restriction->setActive(false); } + $restriction->setTitle($this->createTitleFromIssuerAndVersion($issuer, $version)); $restriction->setIssuer($issuer); $restriction->setEffectiveOn($effectiveOn); $restriction->setCardSet($cardSet); @@ -173,4 +188,13 @@ protected function buildContents(array $data): array return $rhett; } + + protected function createTitleFromIssuerAndVersion(string $issuer, string $version): string + { + $title = self::ISSUER_FFG === $issuer ? self::ISSUER_FFG_SHORTNAME : $issuer; + if (in_array($issuer, $this->faqIssuers)) { + $title .= ' FAQ'; + } + return $title . ' v' . $version; + } } diff --git a/src/Command/ListRestrictionsCommand.php b/src/Command/ListRestrictionsCommand.php index 16928759..9c5c89d2 100644 --- a/src/Command/ListRestrictionsCommand.php +++ b/src/Command/ListRestrictionsCommand.php @@ -48,11 +48,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int } else { $table = new Table($output); $table - ->setHeaders(['Code', 'Issuer', 'Version', 'Active', 'Date effective']); + ->setHeaders(['Code', 'Title', 'Issuer', 'Version', 'Active', 'Date effective']); foreach ($restrictions as $restriction) { $table->addRow([ $restriction->getCode(), + $restriction->getTitle(), $restriction->getIssuer(), $restriction->getVersion(), $restriction->isActive() ? 'yes' : 'no', diff --git a/src/Entity/Restriction.php b/src/Entity/Restriction.php index 8a483efc..b58fb950 100644 --- a/src/Entity/Restriction.php +++ b/src/Entity/Restriction.php @@ -33,6 +33,18 @@ class Restriction implements RestrictionInterface */ protected DateTime $effectiveOn; + /** + * @ORM\Column(name="title", type="string", length=50) + * + * @Assert\NotBlank() + * @Assert\Type(type="string") + * @Assert\Length( + * min = 1, + * max = 50 + * ) + */ + protected string $title; + /** * @ORM\Column(name="issuer", type="string", length=50) * @@ -100,6 +112,22 @@ public function getCode(): string return $this->code; } + /** + * @inheritdoc + */ + public function setTitle(string $title): void + { + $this->title = $title; + } + + /** + * @inheritdoc + */ + public function getTitle(): string + { + return $this->title; + } + /** * @inheritdoc */ diff --git a/src/Entity/RestrictionInterface.php b/src/Entity/RestrictionInterface.php index d949fa1c..7b2dcac8 100644 --- a/src/Entity/RestrictionInterface.php +++ b/src/Entity/RestrictionInterface.php @@ -15,6 +15,16 @@ interface RestrictionInterface */ public function setCode(string $code): void; + /** + * @return string + */ + public function getTitle(): string; + + /** + * @param string $title + */ + public function setTitle(string $title): void; + /** * @return string */