<?phpnamespace App\Entity;use App\Repository\PreferenceRepository;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\ORM\Mapping as ORM;use Symfony\Component\Validator\Constraints as Assert;/** * @ORM\Entity(repositoryClass=PreferenceRepository::class) */class Preference{ /** * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") */ private $id; /** * @ORM\Column(type="string", length=255) */ private $title; /** * @ORM\OneToMany(targetEntity=BlogPost::class, mappedBy="preference") */ private $blogPosts; /** * @ORM\ManyToOne(targetEntity=Instance::class) */ #[Assert\NotNull(message: 'L’organisation est obligatoire.')] private $instance; public function __construct() { $this->blogPosts = new ArrayCollection(); } public function getId(): ?int { return $this->id; } public function getTitle(): ?string { return $this->title; } public function setTitle(string $title): self { $this->title = $title; return $this; } /** * @return Collection<int, BlogPost> */ public function getBlogPosts(): Collection { return $this->blogPosts; } public function addBlogPost(BlogPost $blogPost): self { if (!$this->blogPosts->contains($blogPost)) { $this->blogPosts[] = $blogPost; $blogPost->setPreference($this); } return $this; } public function removeBlogPost(BlogPost $blogPost): self { if ($this->blogPosts->removeElement($blogPost)) { // set the owning side to null (unless already changed) if ($blogPost->getPreference() === $this) { $blogPost->setPreference(null); } } return $this; } public function __toString(): string { return $this->getTitle() ?? ''; } public function getInstance(): ?Instance { return $this->instance; } public function setInstance(?Instance $instance): self { $this->instance = $instance; return $this; }}