src/Entity/Preference.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\PreferenceRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. /**
  9.  * @ORM\Entity(repositoryClass=PreferenceRepository::class)
  10.  */
  11. class Preference
  12. {
  13.     /**
  14.      * @ORM\Id
  15.      * @ORM\GeneratedValue
  16.      * @ORM\Column(type="integer")
  17.      */
  18.     private $id;
  19.     /**
  20.      * @ORM\Column(type="string", length=255)
  21.      */
  22.     private $title;
  23.     /**
  24.      * @ORM\OneToMany(targetEntity=BlogPost::class, mappedBy="preference")
  25.      */
  26.     private $blogPosts;
  27.     /**
  28.      * @ORM\ManyToOne(targetEntity=Instance::class)
  29.      */
  30.     #[Assert\NotNull(message'L’organisation est obligatoire.')]
  31.     private $instance;
  32.     public function __construct()
  33.     {
  34.         $this->blogPosts = new ArrayCollection();
  35.     }
  36.     public function getId(): ?int
  37.     {
  38.         return $this->id;
  39.     }
  40.     public function getTitle(): ?string
  41.     {
  42.         return $this->title;
  43.     }
  44.     public function setTitle(string $title): self
  45.     {
  46.         $this->title $title;
  47.         return $this;
  48.     }
  49.     /**
  50.      * @return Collection<int, BlogPost>
  51.      */
  52.     public function getBlogPosts(): Collection
  53.     {
  54.         return $this->blogPosts;
  55.     }
  56.     public function addBlogPost(BlogPost $blogPost): self
  57.     {
  58.         if (!$this->blogPosts->contains($blogPost)) {
  59.             $this->blogPosts[] = $blogPost;
  60.             $blogPost->setPreference($this);
  61.         }
  62.         return $this;
  63.     }
  64.     public function removeBlogPost(BlogPost $blogPost): self
  65.     {
  66.         if ($this->blogPosts->removeElement($blogPost)) {
  67.             // set the owning side to null (unless already changed)
  68.             if ($blogPost->getPreference() === $this) {
  69.                 $blogPost->setPreference(null);
  70.             }
  71.         }
  72.         return $this;
  73.     }
  74.     public function __toString(): string
  75.     {
  76.         return $this->getTitle() ?? '';
  77.     }
  78.     public function getInstance(): ?Instance
  79.     {
  80.         return $this->instance;
  81.     }
  82.     public function setInstance(?Instance $instance): self
  83.     {
  84.         $this->instance $instance;
  85.         return $this;
  86.     }
  87. }