src/Entity/Admin/Article.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Admin;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Doctrine\Common\Collections\Collection;
  6. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. use Cocur\Slugify\Slugify;
  9. /**
  10.  * @ORM\Entity(repositoryClass="App\Repository\Admin\ArticleRepository")
  11.  * @Vich\Uploadable
  12.  */
  13. class Article
  14. {
  15.     /**
  16.      * @ORM\Id()
  17.      * @ORM\GeneratedValue()
  18.      * @ORM\Column(type="integer")
  19.      */
  20.     private $id;
  21.     /**
  22.      * @ORM\Column(type="string", length=255)
  23.      */
  24.     private $titre;
  25.     /**
  26.      * @ORM\Column(type="text")
  27.      */
  28.     private $contenu;
  29.     /**
  30.      * @ORM\Column(type="datetime")
  31.      */
  32.     private $dateAjoutAt;
  33.     /**
  34.      * Option pour qu'on ait le choix de pouvoir selectionner des article pr l'accueil
  35.      * @ORM\Column(type="boolean")
  36.      */
  37.     private $pourAccueil;
  38.     /**
  39.      * @ORM\OneToMany(targetEntity="App\Entity\Admin\ArticleImage", mappedBy="article", orphanRemoval=true, cascade={"persist"})
  40.      */
  41.     private $articleImages;
  42.     /**
  43.      * @Assert\All({
  44.      *  @Assert\Image(mimeTypes={"image/png", "image/jpeg", "image/jpg"})
  45.      * })
  46.      */
  47.     private $fichiersImage;
  48.     /**
  49.      * @ORM\ManyToOne(targetEntity="App\Entity\Admin\Theme", inversedBy="articles")
  50.      * @ORM\JoinColumn(nullable=false)
  51.      */
  52.     private $theme;
  53.     /**
  54.      * @ORM\Column(type="string", length=255, nullable=true)
  55.      */
  56.     private $en_titre;
  57.     /**
  58.      * @ORM\Column(type="text", nullable=true)
  59.      */
  60.     private $en_contenu;
  61.     public function __construct()
  62.     {
  63.         $this->articleImages = new ArrayCollection();
  64.     }
  65.     public function __toString()
  66.     {
  67.         return $this->titre;
  68.     }
  69.     public function getId(): ?int
  70.     {
  71.         return $this->id;
  72.     }
  73.     public function getTitre(): ?string
  74.     {
  75.         return $this->titre;
  76.     }
  77.     public function setTitre(string $titre): self
  78.     {
  79.         $this->titre $titre;
  80.         return $this;
  81.     }
  82.     public function getContenu(): ?string
  83.     {
  84.         return $this->contenu;
  85.     }
  86.     public function setContenu(string $contenu): self
  87.     {
  88.         $this->contenu $contenu;
  89.         return $this;
  90.     }
  91.     public function getDateAjoutAt(): ?\DateTimeInterface
  92.     {
  93.         return $this->dateAjoutAt;
  94.     }
  95.     public function setDateAjoutAt(\DateTimeInterface $dateAjoutAt): self
  96.     {
  97.         $this->dateAjoutAt $dateAjoutAt;
  98.         return $this;
  99.     }
  100.     public function getPourAccueil(): ?bool
  101.     {
  102.         return $this->pourAccueil;
  103.     }
  104.     public function setPourAccueil(bool $pourAccueil): self
  105.     {
  106.         $this->pourAccueil $pourAccueil;
  107.         return $this;
  108.     }
  109.     public function getTheme(): ?Theme
  110.     {
  111.         return $this->theme;
  112.     }
  113.     public function setTheme(?Theme $theme): self
  114.     {
  115.         $this->theme $theme;
  116.         return $this;
  117.     }
  118.     /**
  119.      * @return Collection|Image[]
  120.      */
  121.     public function getArticleImages(): Collection
  122.     {
  123.         return $this->articleImages;
  124.     }
  125.     public function addArticleImage(ArticleImage $articleImage): self
  126.     {
  127.         if (!$this->articleImages->contains($articleImage)) {
  128.             $this->articleImages[] = $articleImage;
  129.             $articleImage->setArticle($this);
  130.         }
  131.         return $this;
  132.     }
  133.     public function removeArticleImage(ArticleImage $articleImage): self
  134.     {
  135.         if ($this->articleImages->contains($articleImage)) {
  136.             $this->articleImages->removeElement($articleImage);
  137.             // set the owning side to null (unless already changed)
  138.             if ($articleImage->getArticle() === $this) {
  139.                 $articleImage->setArticle(null);
  140.             }
  141.         }
  142.         return $this;
  143.     }
  144.     /**
  145.      * @return mixed
  146.      */
  147.     public function getFichiersImage()
  148.     {
  149.         return $this->fichiersImage;
  150.     }
  151.     /**
  152.      * @param mixed $fichiersImage
  153.      * @return Article
  154.      */
  155.     public function setFichiersImage($fichiersImage): self
  156.     {
  157.         foreach ($fichiersImage as $fichierImage){
  158.             $articleImage = new ArticleImage();
  159.             $articleImage->setImageFile($fichierImage);
  160.             $this->addArticleImage($articleImage);
  161.         }
  162.         $this->fichiersImage $fichiersImage;
  163.         return $this;
  164.     }
  165.     public function getSlug(): string
  166.     {
  167.         return (new Slugify())->slugify($this->getTitre());
  168.     }
  169.     public function getEnTitre(): ?string
  170.     {
  171.         return $this->en_titre;
  172.     }
  173.     public function setEnTitre(?string $en_titre): self
  174.     {
  175.         $this->en_titre $en_titre;
  176.         return $this;
  177.     }
  178.     public function getEnContenu(): ?string
  179.     {
  180.         return $this->en_contenu;
  181.     }
  182.     public function setEnContenu(?string $en_contenu): self
  183.     {
  184.         $this->en_contenu $en_contenu;
  185.         return $this;
  186.     }
  187. }