<?php
declare(strict_types=1);
namespace JanusHercules\JobProfessionCategory\Infrastructure\Entity;
use App\Utility\DatabaseIdGenerator;
use DateTime;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\CustomIdGenerator;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\JoinColumn;
use Doctrine\ORM\Mapping\ManyToOne;
use Doctrine\ORM\Mapping\Table;
use Doctrine\ORM\Mapping\UniqueConstraint;
use Symfony\Component\Validator\Constraints as Assert;
#[Entity]
#[Table(
name: 'jpc_category_recurrent_jobs',
uniqueConstraints: [
new UniqueConstraint(
name: 'category_recurrent_job_unique',
columns: ['category_id', 'recurrent_job_id']
)
]
)]
class CategoryRecurrentJob
{
public function __construct(
Category $category,
string $recurrentJobId
) {
$this->category = $category;
$this->recurrentJobId = $recurrentJobId;
$this->createdAt = new DateTime();
}
#[Id]
#[GeneratedValue(strategy: 'CUSTOM')]
#[CustomIdGenerator(class: DatabaseIdGenerator::class)]
#[Column(
type : Types::GUID,
unique: true
)]
private ?string $id = null;
public function getId(): ?string
{
return $this->id;
}
#[ManyToOne(targetEntity: Category::class)]
#[JoinColumn(name: 'category_id', referencedColumnName: 'id')]
private Category $category;
public function getCategory(): Category
{
return $this->category;
}
public function setCategory(Category $category): void
{
$this->category = $category;
}
#[Column(
name: 'recurrent_job_id',
type: Types::GUID,
length: 36,
nullable: false
)]
#[Assert\NotBlank]
#[Assert\Length(
min: 36,
max: 36
)]
private string $recurrentJobId;
public function getRecurrentJobId(): string
{
return $this->recurrentJobId;
}
public function setRecurrentJobId(string $recurrentJobId): void
{
$this->recurrentJobId = $recurrentJobId;
}
#[Column(
type : Types::DATETIME_MUTABLE,
nullable: false
)]
private DateTime $createdAt;
public function getCreatedAt(): DateTime
{
return $this->createdAt;
}
public function setCreatedAt(DateTime $createdAt): void
{
$this->createdAt = $createdAt;
}
}