src/Entity/TargetPublic.php line 10

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