107 lines
No EOL
2.5 KiB
PHP
107 lines
No EOL
2.5 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace GamesShop\Entities\Games;
|
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
use GamesShop\Entities\Account\User;
|
|
use GamesShop\Entities\GamesList;
|
|
use JsonSerializable;
|
|
|
|
#[ORM\Entity]
|
|
#[ORM\Table(name: 'keys')]
|
|
class Key implements JsonSerializable
|
|
{
|
|
#[ORM\Id]
|
|
#[ORM\Column(type: 'integer', options: ['unsigned' => true])]
|
|
#[ORM\GeneratedValue]
|
|
private int|null $id;
|
|
#[ORM\ManyToOne]
|
|
private Game $game;
|
|
#[ORM\ManyToOne]
|
|
private GamesList $list;
|
|
#[ORM\Column]
|
|
private string $key;
|
|
#[ORM\Column(type: 'string', enumType: Store::class)]
|
|
private Store $store;
|
|
#[ORM\Column(nullable: true)]
|
|
private string|null $storeLink;
|
|
#[ORM\Column]
|
|
private string|null $fromWhere;
|
|
#[ORM\Column(type: 'integer', enumType: KeyState::class)]
|
|
private KeyState $state;
|
|
|
|
#[ORM\ManyToOne]
|
|
private User $claimedUser;
|
|
|
|
public function __construct(Game $game, GamesList $list, string $key, Store $store, ?string $storeLink, ?string $fromWhere)
|
|
{
|
|
$this->game = $game;
|
|
$this->list = $list;
|
|
$this->key = $key;
|
|
$this->store = $store;
|
|
$this->storeLink = $storeLink;
|
|
$this->fromWhere = $fromWhere;
|
|
$this->state = KeyState::AVAILABLE;
|
|
}
|
|
|
|
public function getId(): ?int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function getGame(): Game
|
|
{
|
|
return $this->game;
|
|
}
|
|
|
|
public function getKey(): string
|
|
{
|
|
return $this->key;
|
|
}
|
|
|
|
public function getStore(): Store
|
|
{
|
|
return $this->store;
|
|
}
|
|
|
|
public function getStoreLink(): ?string
|
|
{
|
|
return $this->storeLink;
|
|
}
|
|
|
|
public function getFromWhere(): ?string
|
|
{
|
|
return $this->fromWhere;
|
|
}
|
|
|
|
public function getState(): KeyState
|
|
{
|
|
return $this->state;
|
|
}
|
|
|
|
public function getList(): GamesList
|
|
{
|
|
return $this->list;
|
|
}
|
|
|
|
public function setState(KeyState $state): void {
|
|
$this->state = $state;
|
|
}
|
|
|
|
public function setClaimedUser(User $claimedUser): void {
|
|
$this->claimedUser = $claimedUser;
|
|
}
|
|
|
|
public function jsonSerialize(): mixed
|
|
{
|
|
return [
|
|
'id' => $this->id,
|
|
'key' => $this->key,
|
|
'store' => $this->store->value,
|
|
'store_link' => $this->storeLink,
|
|
'from_where' => $this->fromWhere,
|
|
'state' => $this->state->value,
|
|
];
|
|
}
|
|
} |