Create Doctrine entity for storing date periods (Breaths etc)
This commit is contained in:
parent
71a52739c6
commit
78105244d9
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use App\Contract\Entity\Nexus\GamePeriodIdEnum;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
final class Version0006 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return 'Create dictonary table for game periods';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
$this->addSql(
|
||||
<<<'SQL'
|
||||
CREATE TABLE nexus_game_period (
|
||||
id INT NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
started_at TIMESTAMP(0) WITH TIME ZONE NOT NULL,
|
||||
completed_at TIMESTAMP(0) WITH TIME ZONE DEFAULT NULL,
|
||||
current BOOLEAN NOT NULL DEFAULT false,
|
||||
PRIMARY KEY(id))
|
||||
SQL
|
||||
);
|
||||
$this->addSql("COMMENT ON COLUMN nexus_game_period.started_at IS '(DC2Type:datetimetz_immutable)'");
|
||||
$this->addSql("COMMENT ON COLUMN nexus_game_period.completed_at IS '(DC2Type:datetimetz_immutable)'");
|
||||
|
||||
$sql = <<<'SQL'
|
||||
INSERT INTO nexus_game_period (id, name, started_at, completed_at, current)
|
||||
VALUES (:id, :name, :startedAt, :completedAt, false)
|
||||
SQL;
|
||||
$params = [
|
||||
'id' => GamePeriodIdEnum::BREATH_4,
|
||||
'name' => 'Breath 3.5 (also known as Breath 4)',
|
||||
'startedAt' => '2015-07-25 00:00:00 UTC',
|
||||
'completedAt' => '2021-11-24 00:00:00 UTC',
|
||||
];
|
||||
$this->addSql(sql: $sql, params: $params);
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
$this->addSql('DROP TABLE nexus_game_period');
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Contract\Entity\Nexus;
|
||||
|
||||
// TODO convert into native enum when PHP 8.1 is available on production
|
||||
class GamePeriodIdEnum
|
||||
{
|
||||
public const BREATH_4 = 1;
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Contract\Entity\Nexus;
|
||||
|
||||
use DateTimeInterface;
|
||||
|
||||
/**
|
||||
* Significant date period, for example a Breath or a part of Breath.
|
||||
*/
|
||||
interface GamePeriodInterface
|
||||
{
|
||||
public function getId(): ?int;
|
||||
|
||||
public function setId(?int $value): void;
|
||||
|
||||
public function getName(): ?string;
|
||||
|
||||
public function setName(string $name): void;
|
||||
|
||||
public function getStartedAt(): DateTimeInterface;
|
||||
|
||||
public function setStartedAt(DateTimeInterface $value): void;
|
||||
|
||||
public function getCompletedAt(): DateTimeInterface;
|
||||
|
||||
public function setCompletedAt(?DateTimeInterface $value): void;
|
||||
|
||||
public function isCurrent(): bool;
|
||||
|
||||
public function setCurrent(bool $value): void;
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Doctrine\Entity\Nexus;
|
||||
|
||||
use App\Contract\Entity\Nexus\GamePeriodInterface;
|
||||
use App\Doctrine\Repository\Nexus\GamePeriodRepository;
|
||||
use DateTimeImmutable;
|
||||
use DateTimeInterface;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[
|
||||
ORM\Entity(repositoryClass: GamePeriodRepository::class),
|
||||
ORM\Table(name: 'nexus_game_period'),
|
||||
]
|
||||
class GamePeriod implements GamePeriodInterface
|
||||
{
|
||||
#[
|
||||
ORM\Id,
|
||||
ORM\Column(name: 'id', type: Types::INTEGER, nullable: false),
|
||||
]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(name: 'name', type: Types::TEXT, nullable: false)]
|
||||
private ?string $name = null;
|
||||
|
||||
#[ORM\Column(name: 'started_at', type: Types::DATETIMETZ_IMMUTABLE, nullable: false)]
|
||||
private ?DateTimeImmutable $startedAt = null;
|
||||
|
||||
#[ORM\Column(name: 'completed_at', type: Types::DATETIMETZ_IMMUTABLE, nullable: true)]
|
||||
private ?DateTimeImmutable $completedAt = null;
|
||||
|
||||
#[ORM\Column(name: 'current', type: Types::BOOLEAN, nullable: false, options: ['default' => false])]
|
||||
private bool $current = false;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function setId(?int $value): void
|
||||
{
|
||||
$this->id = $value;
|
||||
}
|
||||
|
||||
public function getName(): ?string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setName(string $name): void
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function getStartedAt(): DateTimeInterface
|
||||
{
|
||||
return $this->startedAt;
|
||||
}
|
||||
|
||||
public function setStartedAt(DateTimeInterface $value): void
|
||||
{
|
||||
$this->startedAt = DateTimeImmutable::createFromInterface(object: $value);
|
||||
}
|
||||
|
||||
public function getCompletedAt(): DateTimeInterface
|
||||
{
|
||||
return $this->completedAt;
|
||||
}
|
||||
|
||||
public function setCompletedAt(?DateTimeInterface $value): void
|
||||
{
|
||||
if (null !== $value) {
|
||||
$this->completedAt = DateTimeImmutable::createFromInterface(object: $value);
|
||||
} else {
|
||||
$this->completedAt = null;
|
||||
}
|
||||
}
|
||||
|
||||
public function isCurrent(): bool
|
||||
{
|
||||
return $this->current;
|
||||
}
|
||||
|
||||
public function setCurrent(bool $value): void
|
||||
{
|
||||
$this->current = $value;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Doctrine\Repository\Nexus;
|
||||
|
||||
use App\Doctrine\Entity\Nexus\GamePeriod;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @method GamePeriod|null find($id, $lockMode = null, $lockVersion = null)
|
||||
* @method GamePeriod|null findOneBy(array $criteria, array $orderBy = null)
|
||||
* @method GamePeriod[] findAll()
|
||||
* @method GamePeriod[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
||||
*/
|
||||
class GamePeriodRepository extends ServiceEntityRepository
|
||||
{
|
||||
public function __construct(ManagerRegistry $registry)
|
||||
{
|
||||
parent::__construct($registry, GamePeriod::class);
|
||||
}
|
||||
}
|
Reference in New Issue