src/Entity/Programme.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ProgrammeRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use JMS\Serializer\Annotation as Serializer;
  8. use JMS\Serializer\Annotation\Expose;
  9. use JMS\Serializer\Annotation\Groups;
  10. /**
  11. * @ORM\Entity(repositoryClass=ProgrammeRepository::class)
  12. *
  13. * @Serializer\ExclusionPolicy("ALL")
  14. */
  15. class Programme
  16. {
  17. /**
  18. * @ORM\Id
  19. * @ORM\GeneratedValue
  20. * @ORM\Column(type="integer")
  21. */
  22. private $id;
  23. /**
  24. * @ORM\Column(type="string", length=255)
  25. *
  26. * @Expose
  27. * @Groups({"user"})
  28. */
  29. private $name;
  30. /**
  31. * @ORM\OneToMany(targetEntity=User::class, mappedBy="programme")
  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. /**
  52. * @return Collection<int, User>
  53. */
  54. public function getUsers(): Collection
  55. {
  56. return $this->users;
  57. }
  58. public function addUser( User $user ): self
  59. {
  60. if ( !$this->users->contains( $user ) ) {
  61. $this->users[] = $user;
  62. $user->setProgramme( $this );
  63. }
  64. return $this;
  65. }
  66. public function removeUser( User $user ): self
  67. {
  68. if ( $this->users->removeElement( $user ) ) {
  69. // set the owning side to null (unless already changed)
  70. if ( $user->getProgramme() === $this ) {
  71. $user->setProgramme( NULL );
  72. }
  73. }
  74. return $this;
  75. }
  76. }