src/JanusHercules/JobProfessionCategory/Infrastructure/Entity/Category.php line 24

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace JanusHercules\JobProfessionCategory\Infrastructure\Entity;
  4. use App\Utility\DatabaseIdGenerator;
  5. use DateTime;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping\Column;
  8. use Doctrine\ORM\Mapping\CustomIdGenerator;
  9. use Doctrine\ORM\Mapping\Entity;
  10. use Doctrine\ORM\Mapping\GeneratedValue;
  11. use Doctrine\ORM\Mapping\Id;
  12. use Doctrine\ORM\Mapping\JoinColumn;
  13. use Doctrine\ORM\Mapping\ManyToOne;
  14. use Doctrine\ORM\Mapping\Table;
  15. use Symfony\Component\Validator\Constraints as Assert;
  16. #[Entity]
  17. #[Table(
  18. name: 'jpc_categories',
  19. )]
  20. class Category
  21. {
  22. public function __construct(
  23. string $title
  24. ) {
  25. $this->title = $title;
  26. $this->createdAt = new DateTime();
  27. }
  28. #[Id]
  29. #[GeneratedValue(strategy: 'CUSTOM')]
  30. #[CustomIdGenerator(class: DatabaseIdGenerator::class)]
  31. #[Column(
  32. type : Types::GUID,
  33. unique: true
  34. )]
  35. private ?string $id = null;
  36. public function getId(): ?string
  37. {
  38. return $this->id;
  39. }
  40. #[Column(
  41. type : Types::DATETIME_MUTABLE,
  42. nullable: false
  43. )]
  44. private DateTime $createdAt;
  45. public function getCreatedAt(): DateTime
  46. {
  47. return $this->createdAt;
  48. }
  49. public function setCreatedAt(DateTime $createdAt): void
  50. {
  51. $this->createdAt = $createdAt;
  52. }
  53. #[Column(
  54. name: 'title',
  55. type: Types::STRING,
  56. length: 512,
  57. nullable: false
  58. )]
  59. #[Assert\Length(
  60. min: 3,
  61. max: 512,
  62. )]
  63. private string $title;
  64. public function getTitle(): string
  65. {
  66. return $this->title;
  67. }
  68. public function setTitle(string $title): void
  69. {
  70. $this->title = $title;
  71. }
  72. #[ManyToOne(targetEntity: CustomerCategoryCatalog::class, cascade: ['persist'], inversedBy: 'categories')]
  73. #[JoinColumn(name: 'customer_category_catalog_id', referencedColumnName: 'id', nullable: true)]
  74. private ?CustomerCategoryCatalog $customerCategoryCatalog = null;
  75. public function getCustomerCategoryCatalog(): ?CustomerCategoryCatalog
  76. {
  77. return $this->customerCategoryCatalog;
  78. }
  79. public function setCustomerCategoryCatalog(?CustomerCategoryCatalog $customerCategoryCatalog): void
  80. {
  81. $this->customerCategoryCatalog = $customerCategoryCatalog;
  82. }
  83. }