<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\AnnonceRepository;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Constraints as Assert;
// use Symfony\Component\Validator\Constraint as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* @ORM\Entity(repositoryClass=AnnonceRepository::class)
* @UniqueEntity(
* fields={"titre"},
* message="Une autre annonce possède déjà ce titre, merci de la modifier"
* )
*/
class Annonce
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $titre;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $description;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="annonces",fetch="EAGER")
*/
private $users;
/**
* @ORM\ManyToOne(targetEntity=Category::class, inversedBy="annonces")
*/
private $categorys;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $createdAt;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $type;
/**
* @ORM\ManyToOne(targetEntity=CategoryAnnonceClient::class, inversedBy="annonces",fetch="EAGER")
*/
private $categoryAnnonceClient;
/**
* @ORM\OneToMany(targetEntity=Notification::class, mappedBy="annonce")
*/
private $notifications;
/**
* @ORM\OneToMany(targetEntity=ImageAnnonces::class, mappedBy="annonce" ,cascade={"persist", "remove"}, fetch="EAGER")
* @Assert\Valid()
*/
private $imageAnnonces;
/**
* @ORM\ManyToOne(targetEntity=SubCategory::class, inversedBy="annonces")
* @ORM\JoinColumn(nullable=false)
*/
private $subcategory;
public function __construct()
{
$this->notifications = new ArrayCollection();
$this->imageAnnonces = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getTitre(): ?string
{
return $this->titre;
}
public function setTitre(?string $titre): self
{
$this->titre = $titre;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getUsers(): ?User
{
return $this->users;
}
public function setUsers(?User $users): self
{
$this->users = $users;
return $this;
}
public function getCategorys(): ?Category
{
return $this->categorys;
}
public function setCategorys(?Category $categorys): self
{
$this->categorys = $categorys;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(?\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(?string $type): self
{
$this->type = $type;
return $this;
}
public function getCategoryAnnonceClient(): ?CategoryAnnonceClient
{
return $this->categoryAnnonceClient;
}
public function setCategoryAnnonceClient(?CategoryAnnonceClient $categoryAnnonceClient): self
{
$this->categoryAnnonceClient = $categoryAnnonceClient;
return $this;
}
/**
* @return Collection|Notification[]
*/
public function getNotifications(): Collection
{
return $this->notifications;
}
public function addNotification(Notification $notification): self
{
if (!$this->notifications->contains($notification)) {
$this->notifications[] = $notification;
$notification->setAnnonce($this);
}
return $this;
}
public function removeNotification(Notification $notification): self
{
if ($this->notifications->removeElement($notification)) {
// set the owning side to null (unless already changed)
if ($notification->getAnnonce() === $this) {
$notification->setAnnonce(null);
}
}
return $this;
}
/**
* @return Collection|ImageAnnonces[]
*/
public function getImageAnnonces(): Collection
{
return $this->imageAnnonces;
}
public function addImageAnnonce(ImageAnnonces $imageAnnonce): self
{
if (!$this->imageAnnonces->contains($imageAnnonce)) {
$this->imageAnnonces[] = $imageAnnonce;
$imageAnnonce->setAnnonce($this);
}
return $this;
}
public function removeImageAnnonce(ImageAnnonces $imageAnnonce): self
{
if ($this->imageAnnonces->removeElement($imageAnnonce)) {
// set the owning side to null (unless already changed)
if ($imageAnnonce->getAnnonce() === $this) {
$imageAnnonce->setAnnonce(null);
}
}
return $this;
}
public function getSubcategory(): ?SubCategory
{
return $this->subcategory;
}
public function setSubcategory(?SubCategory $subcategory): self
{
$this->subcategory = $subcategory;
return $this;
}
}