src/Entity/Article.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Tag;
  4. use App\Entity\Media;
  5. use App\Entity\Category;
  6. use App\Model\Taggable;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Doctrine\ORM\PersistentCollection;
  9. use Doctrine\Common\Collections\Collection;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use Symfony\Component\String\Slugger\AsciiSlugger;
  12. /**
  13.  * @ORM\Entity(repositoryClass=App\Repository\ArticleRepository::class)
  14.  */
  15. class Article
  16. {
  17.     use Taggable;
  18.     /**
  19.      * @var int
  20.      * @ORM\Id
  21.      * @ORM\GeneratedValue
  22.      * @ORM\Column(type="integer")
  23.      */
  24.     private $id;
  25.     /**
  26.      * @ORM\Column(type="string", length=255)
  27.      * @var string
  28.      */
  29.     private $slug;
  30.     /**
  31.      * @ORM\Column(type="integer")
  32.      * @var integer
  33.      */
  34.     private $position;
  35.     /**
  36.      * @var string
  37.      * @ORM\Column(type="string")
  38.      */
  39.     private $metaDescription;
  40.     /**
  41.      * @var Media
  42.      * @ORM\ManyToOne(targetEntity="Media", cascade={"persist"})
  43.      * @ORM\JoinColumn(name="video_poster_id", referencedColumnName="id")
  44.      */
  45.     private $videoPoster;
  46.     /**
  47.      * @var Category
  48.      * @ORM\ManyToOne(targetEntity=Category::class, inversedBy="articles")
  49.      * @ORM\JoinColumn(nullable=false)
  50.      */
  51.     private $category;
  52.     /**
  53.      * @var Comment
  54.      * @ORM\OneToMany(targetEntity=Comment::class, mappedBy="article", orphanRemoval=true)
  55.      */
  56.     private $comments;
  57.     /**
  58.      * @var string
  59.      * @ORM\Column(type="string", length=255)
  60.      */
  61.     private $status;
  62.     /**
  63.      * @var Media
  64.      * @ORM\ManyToOne(targetEntity="Media", cascade={"persist"}, fetch="EAGER")
  65.      * @ORM\JoinColumn(name="video_id", referencedColumnName="id")
  66.      */
  67.     private $video;
  68.     /**
  69.      * @ORM\OneToMany(targetEntity=VideoMarker::class, mappedBy="article", cascade={"persist"})
  70.      */
  71.     private $videoMarkers;
  72.     /**
  73.      * @var Collection
  74.      * @ORM\ManyToMany(targetEntity="Tag",cascade={"persist"})
  75.      * @ORM\JoinTable(name="tag_article",
  76.      *      joinColumns={@ORM\JoinColumn(name="article_id", referencedColumnName="id")},
  77.      *      inverseJoinColumns={@ORM\JoinColumn(name="tag_id", referencedColumnName="id")}
  78.      *      )
  79.      */
  80.     private $tags;
  81.     /**
  82.      * @ORM\Column(type="datetime")
  83.      */
  84.     private $createdAt;
  85.     /**
  86.      * @ORM\Column(type="datetime")
  87.      */
  88.     private $updatedAt;
  89.     public function __construct()
  90.     {
  91.         $this->comments = new ArrayCollection();
  92.         $this->videoMarkers = new ArrayCollection();
  93.     }
  94.     public function getId(): ?int
  95.     {
  96.         return $this->id;
  97.     }
  98.     public function getMetaDescription(): ?string
  99.     {
  100.         return $this->metaDescription;
  101.     }
  102.     public function setMetaDescription(string $metaDescription): self
  103.     {
  104.         $this->metaDescription $metaDescription;
  105.         return $this;
  106.     }
  107.     public function getVideoPoster(): ?Media
  108.     {
  109.         return $this->videoPoster;
  110.     }
  111.     public function setVideoPoster(Media $videoPoster): self
  112.     {
  113.         $this->videoPoster $videoPoster;
  114.         return $this;
  115.     }
  116.     public function getPosition(): ?int
  117.     {
  118.         return $this->position;
  119.     }
  120.     public function setPosition(int $position): self
  121.     {
  122.         $this->position $position;
  123.         return $this;
  124.     }
  125.     public function getCreatedAt(): ?\DateTimeInterface
  126.     {
  127.         return $this->createdAt;
  128.     }
  129.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  130.     {
  131.         $this->createdAt $createdAt;
  132.         return $this;
  133.     }
  134.     public function getCategory(): ?Category
  135.     {
  136.         return $this->category;
  137.     }
  138.     public function setCategory(?Category $category): self
  139.     {
  140.         $this->category $category;
  141.         return $this;
  142.     }
  143.     /**
  144.      * @return Collection|videoMarkers[]
  145.      */
  146.     public function getVideoMarkers(): Collection
  147.     {
  148.         return $this->videoMarkers;
  149.     }
  150.     public function addVideoMarker(videoMarker $attachment): self
  151.     {
  152.         if (!$this->videoMarkers->contains($attachment)) {
  153.             $this->videoMarkers[] = $attachment;
  154.             $attachment->setArticle($this);
  155.         }
  156.         return $this;
  157.     }
  158.     public function removeVideoMarker(videoMarker $attachment): self
  159.     {
  160.         if ($this->videoMarkers->contains($attachment)) {
  161.             $this->videoMarkers->removeElement($attachment);
  162.             // set the owning side to null (unless already changed)
  163.             if ($attachment->getArticle() === $this) {
  164.                 $attachment->setArticle(null);
  165.             }
  166.         }
  167.         return $this;
  168.     }
  169.     public function getStatus(): ?string
  170.     {
  171.         return $this->status;
  172.     }
  173.     /**
  174.      * setStatus
  175.      *
  176.      * @param  mixed $status
  177.      * @return self
  178.      */
  179.     public function setStatus(string $status): self
  180.     {
  181.         $this->status $status;
  182.         return $this;
  183.     }
  184.     /**
  185.      * getVideo
  186.      *
  187.      * @return Media
  188.      */
  189.     public function getVideo(): ?Media
  190.     {
  191.         return $this->video;
  192.     }
  193.     /**
  194.      * setVideo
  195.      *
  196.      * @param  mixed $video
  197.      * @return self
  198.      */
  199.     public function setVideo(?Media $video): self
  200.     {
  201.         $this->video $video;
  202.         return $this;
  203.     }
  204.     /**
  205.      * @return string
  206.      */
  207.     public function getTags(): ?ArrayCollection
  208.     {
  209.         if (empty($this->tags))
  210.             return null;
  211.         return new \Doctrine\Common\Collections\ArrayCollection($this->tags->toArray());
  212.     }
  213.     /**
  214.      * SetTags
  215.      *
  216.      * @param  Collection $tags
  217.      * @return self
  218.      */
  219.     public function setTags(Collection $tags): self
  220.     {
  221.         $this->tags $tags;
  222.         return $this;
  223.     }
  224.     /**
  225.      * addTag
  226.      *
  227.      * @param  Tag $tag
  228.      * @return self
  229.      */
  230.     public function addTag(Tag $tag): self
  231.     {
  232.         if ($this->tags == null || !$this->tags->contains($tag)) {
  233.             if (gettype($this->tags) == 'ArrayCollection')
  234.                 $this->tags->add($tag);
  235.             else
  236.                 $this->tags[] = $tag;
  237.         }
  238.         return $this;
  239.     }
  240.     /**
  241.      * Get the value of updatedAt
  242.      */
  243.     public function getUpdatedAt()
  244.     {
  245.         return $this->updatedAt;
  246.     }
  247.     /**
  248.      * Set the value of updatedAt
  249.      *
  250.      * @return  self
  251.      */
  252.     public function setUpdatedAt($updatedAt)
  253.     {
  254.         $this->updatedAt $updatedAt;
  255.         return $this;
  256.     }
  257.     /**
  258.      * @return  string
  259.      */
  260.     public function getSlug(): ?string
  261.     {
  262.         return $this->slug;
  263.     }
  264.     /**
  265.      *
  266.      * @param  string  $slug
  267.      *
  268.      * @return  self
  269.      */
  270.     public function setSlug(string $slug): self
  271.     {
  272.         $slugger = new AsciiSlugger('fr');
  273.         $this->slug $slugger->slug($slug);
  274.         return $this;
  275.     }
  276. }