src/Entity/Category.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CategoryRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8. * @ORM\Entity(repositoryClass=CategoryRepository::class)
  9. */
  10. class Category
  11. {
  12. /**
  13. * @ORM\Id
  14. * @ORM\GeneratedValue
  15. * @ORM\Column(type="integer")
  16. */
  17. private ?int $id;
  18. /**
  19. * @ORM\Column(type="string", length=255)
  20. */
  21. private ?string $name;
  22. /**
  23. * @ORM\Column(type="boolean")
  24. */
  25. private ?bool $display;
  26. /**
  27. * @ORM\Column(type="string", length=255)
  28. */
  29. private ?string $color;
  30. /**
  31. * @ORM\OneToMany(targetEntity=User::class, mappedBy="category")
  32. */
  33. private $users;
  34. public function __construct()
  35. {
  36. $this->users = new ArrayCollection();
  37. }
  38. public function getId(): ?int
  39. {
  40. return $this->id;
  41. }
  42. public function getName(): ?string
  43. {
  44. return $this->name;
  45. }
  46. public function setName(string $name): self
  47. {
  48. $this->name = $name;
  49. return $this;
  50. }
  51. public function getDisplay(): ?bool
  52. {
  53. return $this->display;
  54. }
  55. public function setDisplay(bool $display): self
  56. {
  57. $this->display = $display;
  58. return $this;
  59. }
  60. public function getColor(): ?string
  61. {
  62. return $this->color;
  63. }
  64. public function setColor(string $color): self
  65. {
  66. $this->color = $color;
  67. return $this;
  68. }
  69. /**
  70. * @return Collection|User[]
  71. */
  72. public function getUsers(): Collection
  73. {
  74. return $this->users;
  75. }
  76. public function addUser(User $user): self
  77. {
  78. if (!$this->users->contains($user)) {
  79. $this->users[] = $user;
  80. $user->setCategory($this);
  81. }
  82. return $this;
  83. }
  84. public function removeUser(User $user): self
  85. {
  86. if ($this->users->removeElement($user)) {
  87. // set the owning side to null (unless already changed)
  88. if ($user->getCategory() === $this) {
  89. $user->setCategory(null);
  90. }
  91. }
  92. return $this;
  93. }
  94. }