src/Entity/Rate.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Ticket;
  4. use App\Repository\RateRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Uid\Uuid;
  9. #[ORM\Entity(repositoryClass: RateRepository::class)]
  10. class Rate
  11. {
  12. #[ORM\Id]
  13. #[ORM\Column(type:"string", length:36)]
  14. private ?string $id = null;
  15. #[ORM\Column(type:"text")]
  16. private ?string $name = null;
  17. #[ORM\Column]
  18. private ?int $value = null;
  19. #[ORM\OneToMany(mappedBy: 'rate', targetEntity: Ticket::class)]
  20. private Collection $tickets;
  21. public function __construct($name, $value)
  22. {
  23. $this->id = Uuid::v4()->toRfc4122();
  24. $this->name = $name;
  25. $this->value = $value;
  26. $this->tickets = new ArrayCollection();
  27. }
  28. public function getId(): ?string
  29. {
  30. return $this->id;
  31. }
  32. public function getName(): ?string
  33. {
  34. return $this->name;
  35. }
  36. public function setName(string $name): self
  37. {
  38. $this->name = $name;
  39. return $this;
  40. }
  41. public function getValue(): ?int
  42. {
  43. return $this->value;
  44. }
  45. public function setValue(int $value): self
  46. {
  47. $this->value = $value;
  48. return $this;
  49. }
  50. /**
  51. * @return Collection<int, Ticket>
  52. */
  53. public function getTickets(): Collection
  54. {
  55. return $this->tickets;
  56. }
  57. public function addTicket(Ticket $ticket): self
  58. {
  59. if (!$this->tickets->contains($ticket)) {
  60. $this->tickets->add($ticket);
  61. $ticket->setRate($this);
  62. }
  63. return $this;
  64. }
  65. public function removeTicket(Ticket $ticket): self
  66. {
  67. if ($this->tickets->removeElement($ticket)) {
  68. // set the owning side to null (unless already changed)
  69. if ($ticket->getRate() === $this) {
  70. $ticket->setRate(null);
  71. }
  72. }
  73. return $this;
  74. }
  75. }