src/Entity/Update.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Enum\MessageType;
  4. use App\Enum\UpdateType;
  5. use App\Repository\UpdateRepository;
  6. use DateTimeImmutable;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Symfony\Component\Uid\Uuid;
  11. #[ORM\Entity(repositoryClass: UpdateRepository::class)]
  12. #[ORM\Table(name: 'TicketUpdate')]
  13. #[ORM\Index(columns: ['updateType'], name: 'ticket_update_idx_update_type')]
  14. #[ORM\Index(columns: ['messageType'], name: 'ticket_update_idx_message_type')]
  15. class Update
  16. {
  17. public function __construct(
  18. #[ORM\Column(type:"string")]
  19. private string $updateType,
  20. #[ORM\Column(type:"string")]
  21. private string $messageType,
  22. #[ORM\Id]
  23. #[ORM\Column(type:"string", length:36)]
  24. private ?string $id = null,
  25. #[ORM\ManyToOne(inversedBy: 'updates')]
  26. #[ORM\JoinColumn(name: "ticketId", referencedColumnName: "id", nullable: false)]
  27. private ?Ticket $ticket = null,
  28. #[ORM\Column(type:"text", nullable: true)]
  29. private ?string $description = null,
  30. #[ORM\Column(type: 'datetime_immutable', nullable: true)]
  31. private ?DateTimeImmutable $createdAt = null,
  32. #[ORM\OneToMany(
  33. mappedBy: 'update',
  34. targetEntity: UpdateAttachment::class,
  35. cascade: ['persist'],
  36. orphanRemoval: true
  37. )]
  38. private ?Collection $attachments = null,
  39. ) {
  40. $this->id = is_null($this->id) ? Uuid::v4()->toRfc4122() : $this->id;
  41. $this->attachments = is_null($this->attachments) ? new ArrayCollection() : $this->attachments;
  42. $this->createdAt = is_null($this->createdAt) ? new DateTimeImmutable('now') : $this->createdAt;
  43. }
  44. public function getId(): ?string
  45. {
  46. return $this->id;
  47. }
  48. public function getDescription(): ?string
  49. {
  50. return $this->description;
  51. }
  52. public function setDescription(?string $description): self
  53. {
  54. $this->description = $description;
  55. return $this;
  56. }
  57. public function getCreatedAt(): ?DateTimeImmutable
  58. {
  59. return $this->createdAt;
  60. }
  61. public function setCreatedAt(DateTimeImmutable $createdAt): self
  62. {
  63. $this->createdAt = $createdAt;
  64. return $this;
  65. }
  66. public function getTicket(): ?Ticket
  67. {
  68. return $this->ticket;
  69. }
  70. public function setTicket(?Ticket $ticket): self
  71. {
  72. $this->ticket = $ticket;
  73. return $this;
  74. }
  75. public function getUpdateType(): string
  76. {
  77. return $this->updateType;
  78. }
  79. public function setUpdateType(UpdateType $updateType): void
  80. {
  81. $this->updateType = $updateType->value;
  82. }
  83. public function getMessageType(): string
  84. {
  85. return $this->messageType;
  86. }
  87. public function setMessageType(MessageType $messageType): self
  88. {
  89. $this->messageType = $messageType->value;
  90. return $this;
  91. }
  92. /**
  93. * @return Collection|null
  94. */
  95. public function getAttachments(): ?Collection
  96. {
  97. return $this->attachments;
  98. }
  99. public function addAttachment(UpdateAttachment $attachment): void
  100. {
  101. if ($this->attachments && !$this->attachments->contains($attachment)) {
  102. $this->attachments->add($attachment);
  103. }
  104. }
  105. public function removeAttachment(UpdateAttachment $attachment): void
  106. {
  107. if ($this->attachments && $this->attachments->contains($attachment)) {
  108. $this->attachments->removeElement($attachment);
  109. }
  110. }
  111. }