src/Entity/Annonce.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use App\Repository\AnnonceRepository;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. // use Symfony\Component\Validator\Constraint as Assert;
  9. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  10. /**
  11.  * @ORM\Entity(repositoryClass=AnnonceRepository::class)
  12.  * @UniqueEntity(
  13.  * fields={"titre"},
  14.  * message="Une autre annonce possède déjà ce titre, merci de la modifier"
  15.  * )
  16.  */
  17. class Annonce
  18. {
  19.     /**
  20.      * @ORM\Id
  21.      * @ORM\GeneratedValue
  22.      * @ORM\Column(type="integer")
  23.      */
  24.     private $id;
  25.     /**
  26.      * @ORM\Column(type="string", length=255, nullable=true)
  27.      */
  28.     private $titre;
  29.     /**
  30.      * @ORM\Column(type="text", nullable=true)
  31.      */
  32.     private $description;
  33.     /**
  34.      * @ORM\ManyToOne(targetEntity=User::class, inversedBy="annonces",fetch="EAGER")
  35.      */
  36.     private $users;
  37.     /**
  38.      * @ORM\ManyToOne(targetEntity=Category::class, inversedBy="annonces")
  39.      */
  40.     private $categorys;
  41.     /**
  42.      * @ORM\Column(type="datetime", nullable=true)
  43.      */
  44.     private $createdAt;
  45.     /**
  46.      * @ORM\Column(type="string", length=255, nullable=true)
  47.      */
  48.     private $type;
  49.     /**
  50.      * @ORM\ManyToOne(targetEntity=CategoryAnnonceClient::class, inversedBy="annonces",fetch="EAGER")
  51.      */
  52.     private $categoryAnnonceClient;
  53.     /**
  54.      * @ORM\OneToMany(targetEntity=Notification::class, mappedBy="annonce")
  55.      */
  56.     private $notifications;
  57.     /**
  58.      * @ORM\OneToMany(targetEntity=ImageAnnonces::class, mappedBy="annonce" ,cascade={"persist", "remove"}, fetch="EAGER")
  59.      * @Assert\Valid()
  60.      */
  61.     private $imageAnnonces;
  62.     /**
  63.      * @ORM\ManyToOne(targetEntity=SubCategory::class, inversedBy="annonces")
  64.      * @ORM\JoinColumn(nullable=false)
  65.      */
  66.     private $subcategory;
  67.     public function __construct()
  68.     {
  69.         $this->notifications = new ArrayCollection();
  70.         $this->imageAnnonces = new ArrayCollection();
  71.     }
  72.     public function getId(): ?int
  73.     {
  74.         return $this->id;
  75.     }
  76.     public function getTitre(): ?string
  77.     {
  78.         return $this->titre;
  79.     }
  80.     public function setTitre(?string $titre): self
  81.     {
  82.         $this->titre $titre;
  83.         return $this;
  84.     }
  85.     public function getDescription(): ?string
  86.     {
  87.         return $this->description;
  88.     }
  89.     public function setDescription(?string $description): self
  90.     {
  91.         $this->description $description;
  92.         return $this;
  93.     }
  94.     public function getUsers(): ?User
  95.     {
  96.         return $this->users;
  97.     }
  98.     public function setUsers(?User $users): self
  99.     {
  100.         $this->users $users;
  101.         return $this;
  102.     }
  103.     public function getCategorys(): ?Category
  104.     {
  105.         return $this->categorys;
  106.     }
  107.     public function setCategorys(?Category $categorys): self
  108.     {
  109.         $this->categorys $categorys;
  110.         return $this;
  111.     }
  112.     public function getCreatedAt(): ?\DateTimeInterface
  113.     {
  114.         return $this->createdAt;
  115.     }
  116.     public function setCreatedAt(?\DateTimeInterface $createdAt): self
  117.     {
  118.         $this->createdAt $createdAt;
  119.         return $this;
  120.     }
  121.     public function getType(): ?string
  122.     {
  123.         return $this->type;
  124.     }
  125.     public function setType(?string $type): self
  126.     {
  127.         $this->type $type;
  128.         return $this;
  129.     }
  130.     public function getCategoryAnnonceClient(): ?CategoryAnnonceClient
  131.     {
  132.         return $this->categoryAnnonceClient;
  133.     }
  134.     public function setCategoryAnnonceClient(?CategoryAnnonceClient $categoryAnnonceClient): self
  135.     {
  136.         $this->categoryAnnonceClient $categoryAnnonceClient;
  137.         return $this;
  138.     }
  139.     /**
  140.      * @return Collection|Notification[]
  141.      */
  142.     public function getNotifications(): Collection
  143.     {
  144.         return $this->notifications;
  145.     }
  146.     public function addNotification(Notification $notification): self
  147.     {
  148.         if (!$this->notifications->contains($notification)) {
  149.             $this->notifications[] = $notification;
  150.             $notification->setAnnonce($this);
  151.         }
  152.         return $this;
  153.     }
  154.     public function removeNotification(Notification $notification): self
  155.     {
  156.         if ($this->notifications->removeElement($notification)) {
  157.             // set the owning side to null (unless already changed)
  158.             if ($notification->getAnnonce() === $this) {
  159.                 $notification->setAnnonce(null);
  160.             }
  161.         }
  162.         return $this;
  163.     }
  164.     /**
  165.      * @return Collection|ImageAnnonces[]
  166.      */
  167.     public function getImageAnnonces(): Collection
  168.     {
  169.         return $this->imageAnnonces;
  170.     }
  171.     public function addImageAnnonce(ImageAnnonces $imageAnnonce): self
  172.     {
  173.         if (!$this->imageAnnonces->contains($imageAnnonce)) {
  174.             $this->imageAnnonces[] = $imageAnnonce;
  175.             $imageAnnonce->setAnnonce($this);
  176.         }
  177.         return $this;
  178.     }
  179.     public function removeImageAnnonce(ImageAnnonces $imageAnnonce): self
  180.     {
  181.         if ($this->imageAnnonces->removeElement($imageAnnonce)) {
  182.             // set the owning side to null (unless already changed)
  183.             if ($imageAnnonce->getAnnonce() === $this) {
  184.                 $imageAnnonce->setAnnonce(null);
  185.             }
  186.         }
  187.         return $this;
  188.     }
  189.     public function getSubcategory(): ?SubCategory
  190.     {
  191.         return $this->subcategory;
  192.     }
  193.     public function setSubcategory(?SubCategory $subcategory): self
  194.     {
  195.         $this->subcategory $subcategory;
  196.         return $this;
  197.     }
  198. }