src/Entity/Agent.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\AgentRepository;
  4. use DateTimeImmutable;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\DBAL\Types\Types;
  8. use Doctrine\ORM\Mapping as ORM;
  9. #[ORM\Entity(repositoryClass: AgentRepository::class)]
  10. class Agent
  11. {
  12. #[ORM\Id]
  13. #[ORM\Column(type:"string", length:36)]
  14. private ?string $id = null;
  15. #[ORM\Column(type:"text")]
  16. private ?string $firstName = null;
  17. #[ORM\Column(type:"text", nullable: true)]
  18. private ?string $lastName = null;
  19. #[ORM\Column(type:"text")]
  20. private ?string $email = null;
  21. #[ORM\Column(type:"boolean", options: ['default' => true])]
  22. private ?bool $active = null;
  23. #[ORM\Column(type:"boolean", options: ['default' => false])]
  24. private ?bool $deleted = null;
  25. #[ORM\Column]
  26. private ?DateTimeImmutable $createdAt = null;
  27. #[ORM\Column(type: Types::DATETIME_MUTABLE)]
  28. private ?\DateTimeInterface $updatedAt = null;
  29. #[ORM\OneToMany(mappedBy: 'agent', targetEntity: Ticket::class)]
  30. private ?Collection $tickets = null;
  31. #[ORM\ManyToMany(targetEntity: Category::class, inversedBy: 'agents', fetch: 'EXTRA_LAZY')]
  32. #[ORM\JoinTable(name: 'AgentCategories')]
  33. private ?Collection $categories;
  34. public function __construct(
  35. $firstName, $email, $id = null, $lastName = null, $active = null, $deleted = null
  36. ) {
  37. $this->id = $id;
  38. $this->firstName = $firstName;
  39. $this->lastName = $lastName;
  40. $this->email = $email;
  41. $this->createdAt = new DateTimeImmutable('now');
  42. $this->updatedAt = new \DateTime('now');
  43. $this->tickets = new ArrayCollection();
  44. $this->categories = new ArrayCollection();
  45. $this->active = $active ?? true;
  46. $this->deleted = $deleted ?? false;
  47. }
  48. public function getId(): ?string
  49. {
  50. return $this->id;
  51. }
  52. public function setId(string $id): self
  53. {
  54. $this->id = $id;
  55. $this->markAsUpdated();
  56. return $this;
  57. }
  58. public function getFirstName(): ?string
  59. {
  60. return $this->firstName;
  61. }
  62. public function setFirstName(string $firstName): self
  63. {
  64. $this->firstName = $firstName;
  65. $this->markAsUpdated();
  66. return $this;
  67. }
  68. public function getLastName(): ?string
  69. {
  70. return $this->lastName;
  71. }
  72. public function setLastName(string $lastName): self
  73. {
  74. $this->lastName = $lastName;
  75. $this->markAsUpdated();
  76. return $this;
  77. }
  78. public function getEmail(): ?string
  79. {
  80. return $this->email;
  81. }
  82. public function setEmail(string $email): self
  83. {
  84. $this->email = $email;
  85. $this->markAsUpdated();
  86. return $this;
  87. }
  88. public function getCreatedAt(): ?DateTimeImmutable
  89. {
  90. return $this->createdAt;
  91. }
  92. public function setCreatedAt(DateTimeImmutable $createdAt): self
  93. {
  94. $this->createdAt = $createdAt;
  95. return $this;
  96. }
  97. public function getUpdatedAt(): ?\DateTimeInterface
  98. {
  99. return $this->updatedAt;
  100. }
  101. public function setUpdatedAt(\DateTimeInterface $updatedAt): self
  102. {
  103. $this->updatedAt = $updatedAt;
  104. return $this;
  105. }
  106. public function markAsUpdated(): void
  107. {
  108. $this->updatedAt = new DateTimeImmutable();
  109. }
  110. /**
  111. * @return Collection<int, Ticket>
  112. */
  113. public function getTickets(): Collection
  114. {
  115. return $this->tickets;
  116. }
  117. public function addTicket(Ticket $ticket): self
  118. {
  119. if ($this->tickets && !$this->tickets->contains($ticket)) {
  120. $this->tickets->add($ticket);
  121. $ticket->setAgent($this);
  122. }
  123. return $this;
  124. }
  125. public function removeTicket(Ticket $ticket): self
  126. {
  127. if ($this->tickets && $this->tickets->contains($ticket)) {
  128. $this->tickets->removeElement($ticket);
  129. if ($ticket->getAgent() === $this) {
  130. $ticket->setAgent(null);
  131. }
  132. }
  133. return $this;
  134. }
  135. /**
  136. * @return Collection<int, Category>
  137. */
  138. public function getCategories(): Collection
  139. {
  140. return $this->categories;
  141. }
  142. /**
  143. * @param Collection<int, Category> $categories
  144. */
  145. public function setCategories(Collection $categories): void
  146. {
  147. $this->categories = $categories;
  148. }
  149. public function isActive(): bool
  150. {
  151. return $this->active;
  152. }
  153. public function setActive(?bool $active): void
  154. {
  155. $this->active = $active;
  156. }
  157. public function isDeleted(): ?bool
  158. {
  159. return $this->deleted;
  160. }
  161. public function setDeleted(?bool $deleted): void
  162. {
  163. $this->deleted = $deleted;
  164. }
  165. }