src/JanusHercules/JobProfessionCategory/Infrastructure/Entity/CategoryRecurrentJob.php line 31

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 Doctrine\ORM\Mapping\UniqueConstraint;
  16. use Symfony\Component\Validator\Constraints as Assert;
  17. #[Entity]
  18. #[Table(
  19. name: 'jpc_category_recurrent_jobs',
  20. uniqueConstraints: [
  21. new UniqueConstraint(
  22. name: 'category_recurrent_job_unique',
  23. columns: ['category_id', 'recurrent_job_id']
  24. )
  25. ]
  26. )]
  27. class CategoryRecurrentJob
  28. {
  29. public function __construct(
  30. Category $category,
  31. string $recurrentJobId
  32. ) {
  33. $this->category = $category;
  34. $this->recurrentJobId = $recurrentJobId;
  35. $this->createdAt = new DateTime();
  36. }
  37. #[Id]
  38. #[GeneratedValue(strategy: 'CUSTOM')]
  39. #[CustomIdGenerator(class: DatabaseIdGenerator::class)]
  40. #[Column(
  41. type : Types::GUID,
  42. unique: true
  43. )]
  44. private ?string $id = null;
  45. public function getId(): ?string
  46. {
  47. return $this->id;
  48. }
  49. #[ManyToOne(targetEntity: Category::class)]
  50. #[JoinColumn(name: 'category_id', referencedColumnName: 'id')]
  51. private Category $category;
  52. public function getCategory(): Category
  53. {
  54. return $this->category;
  55. }
  56. public function setCategory(Category $category): void
  57. {
  58. $this->category = $category;
  59. }
  60. #[Column(
  61. name: 'recurrent_job_id',
  62. type: Types::GUID,
  63. length: 36,
  64. nullable: false
  65. )]
  66. #[Assert\NotBlank]
  67. #[Assert\Length(
  68. min: 36,
  69. max: 36
  70. )]
  71. private string $recurrentJobId;
  72. public function getRecurrentJobId(): string
  73. {
  74. return $this->recurrentJobId;
  75. }
  76. public function setRecurrentJobId(string $recurrentJobId): void
  77. {
  78. $this->recurrentJobId = $recurrentJobId;
  79. }
  80. #[Column(
  81. type : Types::DATETIME_MUTABLE,
  82. nullable: false
  83. )]
  84. private DateTime $createdAt;
  85. public function getCreatedAt(): DateTime
  86. {
  87. return $this->createdAt;
  88. }
  89. public function setCreatedAt(DateTime $createdAt): void
  90. {
  91. $this->createdAt = $createdAt;
  92. }
  93. }