Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds title attribute to restrictions entity. #687

Merged
merged 1 commit into from
Dec 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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