<?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 Symfony\Component\Validator\Constraints as Assert;
#[Entity]
#[Table(
name: 'jpc_categories',
)]
class Category
{
public function __construct(
string $title
) {
$this->title = $title;
$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;
}
#[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;
}
#[Column(
name: 'title',
type: Types::STRING,
length: 512,
nullable: false
)]
#[Assert\Length(
min: 3,
max: 512,
)]
private string $title;
public function getTitle(): string
{
return $this->title;
}
public function setTitle(string $title): void
{
$this->title = $title;
}
#[ManyToOne(targetEntity: CustomerCategoryCatalog::class, cascade: ['persist'], inversedBy: 'categories')]
#[JoinColumn(name: 'customer_category_catalog_id', referencedColumnName: 'id', nullable: true)]
private ?CustomerCategoryCatalog $customerCategoryCatalog = null;
public function getCustomerCategoryCatalog(): ?CustomerCategoryCatalog
{
return $this->customerCategoryCatalog;
}
public function setCustomerCategoryCatalog(?CustomerCategoryCatalog $customerCategoryCatalog): void
{
$this->customerCategoryCatalog = $customerCategoryCatalog;
}
}