Skip to content

Commit

Permalink
Merge pull request #687 from stopfstedt/restrictions_title
Browse files Browse the repository at this point in the history
adds title attribute to restrictions entity.
  • Loading branch information
stopfstedt authored Dec 14, 2020
2 parents 695d0f1 + 725ed65 commit 057b650
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 7 deletions.
33 changes: 33 additions & 0 deletions migrations/Version20201213002601.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Adds a title column to the restriction table.
*/
final class Version20201213002601 extends AbstractMigration
{
public function getDescription() : string
{
return 'Adds a title column to the restriction table.';
}

public function up(Schema $schema) : void
{
$this->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');
}
}
4 changes: 1 addition & 3 deletions src/Command/ActivateRestrictionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
4 changes: 1 addition & 3 deletions src/Command/DeactivateRestrictionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
24 changes: 24 additions & 0 deletions src/Command/ImportRestrictionsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
}
3 changes: 2 additions & 1 deletion src/Command/ListRestrictionsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() ? '<fg=green>yes</>' : '<fg=red>no</>',
Expand Down
28 changes: 28 additions & 0 deletions src/Entity/Restriction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*
Expand Down Expand Up @@ -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
*/
Expand Down
10 changes: 10 additions & 0 deletions src/Entity/RestrictionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 057b650

Please sign in to comment.