src/Entity/Article.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Gedmo\Mapping\Annotation as Gedmo;
  7. use Symfony\Component\HttpFoundation\File\File;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  10. /**
  11.  * @ORM\Table(name="article")
  12.  * @ORM\Entity(repositoryClass="App\Repository\ArticleRepository")
  13.  * @Vich\Uploadable
  14.  * @ORM\HasLifecycleCallbacks()
  15.  */
  16. class Article
  17. {
  18.     /**
  19.      * @var int
  20.      *
  21.      * @ORM\Column(name="id", type="integer")
  22.      * @ORM\Id
  23.      * @ORM\GeneratedValue(strategy="AUTO")
  24.      */
  25.     private $id;
  26.     /**
  27.      * @var string
  28.      *
  29.      * @ORM\Column(name="title", type="string", length=255)
  30.      * @Assert\NotBlank(
  31.      *     message="Champ obligatoire"
  32.      * )
  33.      */
  34.     private $title;
  35.     /**
  36.      * @var string
  37.      *
  38.      * @Gedmo\Slug(fields={"title"})
  39.      * @ORM\Column(type="string", unique=true)
  40.      */
  41.     private $slug;
  42.     /**
  43.      * @var \DateTime
  44.      *
  45.      * @ORM\Column(name="create_at", type="datetime", nullable=false)
  46.      */
  47.     private $createAt;
  48.     /**
  49.      * @var string
  50.      *
  51.      * @ORM\Column(name="content", type="text")
  52.      * @Assert\NotBlank(
  53.      *     message="Champ obligatoire"
  54.      * )
  55.      */
  56.     private $content;
  57.     /**
  58.      * @var Admin
  59.      *
  60.      * @ORM\ManyToOne(targetEntity="App\Entity\Admin")
  61.      * @ORM\JoinColumn(nullable=false, name="user_id")
  62.      */
  63.     private $author;
  64.     /**
  65.      * @ORM\Column(type="string", length=50, nullable=true)
  66.      */
  67.     private $logo;
  68.     /**
  69.      * @Vich\UploadableField(mapping="marque_upload", fileNameProperty="logo")
  70.      * @var File
  71.      */
  72.     public $logoFile;
  73.     /**
  74.      * @var ArrayCollection
  75.      * @ORM\ManyToMany(targetEntity="App\Entity\Tag", cascade={"persist"})
  76.      */
  77.     private $tags;
  78.     public function __construct()
  79.     {
  80.         $this->tags = new ArrayCollection();
  81.     }
  82.     public function __toString()
  83.     {
  84.        return $this->getTitle();
  85.     }
  86.     public function getId(): ?int
  87.     {
  88.         return $this->id;
  89.     }
  90.     public function setTitle(?string $title): Article
  91.     {
  92.         $this->title $title;
  93.         return $this;
  94.     }
  95.     public function getTitle(): ?string
  96.     {
  97.         return $this->title;
  98.     }
  99.     /**
  100.      * @ORM\PrePersist
  101.      */
  102.     public function setCreateAt(): self
  103.     {
  104.         $this->createAt = new \DateTime();
  105.         return $this;
  106.     }
  107.     public function getCreateAt(): ?\DateTime
  108.     {
  109.         return $this->createAt;
  110.     }
  111.     public function setContent(?string $content): self
  112.     {
  113.         $this->content $content;
  114.         return $this;
  115.     }
  116.     public function getContent(): ?string
  117.     {
  118.         return $this->content;
  119.     }
  120.     public function getAuthor(): ?Admin
  121.     {
  122.         return $this->author;
  123.     }
  124.     public function setAuthor(Admin $author): self
  125.     {
  126.         $this->author $author;
  127.         return $this;
  128.     }
  129.     public function addTag(Tag ...$tags): void
  130.     {
  131.         foreach ($tags as $tag) {
  132.             if (!$this->tags->contains($tag)) {
  133.                 $this->tags->add($tag);
  134.             }
  135.         }
  136.     }
  137.     public function removeTag(Tag $tag): void
  138.     {
  139.         $this->tags->removeElement($tag);
  140.     }
  141.     public function getTags(): ?Collection
  142.     {
  143.         return $this->tags;
  144.     }
  145.     public function getSlug(): string
  146.     {
  147.         return $this->slug;
  148.     }
  149.     public function setSlug($slug): string
  150.     {
  151.          $this->slug $slug;
  152.         return $this;
  153.     }
  154.     public function getLogo(): ?string
  155.     {
  156.         return $this->logo;
  157.     }
  158.     public function setLogo(?string $logo): self
  159.     {
  160.         $this->logo $logo;
  161.         return $this;
  162.     }
  163. }