src/Entity/Theme.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ThemeRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\String\Slugger\AsciiSlugger;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  10. use Gedmo\Mapping\Annotation as Gedmo;
  11. /**
  12.  * @ORM\Entity(repositoryClass=ThemeRepository::class)
  13.  * @UniqueEntity("name")
  14.  */
  15. class Theme
  16. {
  17.     /**
  18.      * @ORM\Id()
  19.      * @ORM\GeneratedValue()
  20.      * @ORM\Column(type="integer")
  21.      */
  22.     private $id;
  23.     
  24.     /**
  25.      * @ORM\Column(type="string", length=255)
  26.      */
  27.     private $name;
  28.     
  29.     /**
  30.      * @Gedmo\Slug(fields={"name"})
  31.      * @ORM\Column(type="string", length=255, unique=true)
  32.      */
  33.     protected $slug;
  34.     /**
  35.      * @ORM\Column(type="integer", nullable=true)
  36.      */
  37.     private $priority;
  38.             
  39.     /**
  40.      * @var \DateTime $createdAt
  41.      *
  42.      * @Gedmo\Timestampable(on="create")
  43.      * @ORM\Column(type="datetime", nullable=true)
  44.      */
  45.     private $createdAt;
  46.     /**
  47.      * @var \DateTime $updatedAt
  48.      *
  49.      * @Gedmo\Timestampable(on="update")
  50.      * @ORM\Column(type="datetime")
  51.      */
  52.     private $updatedAt;
  53.     /* relations */
  54.         
  55.     /**
  56.      * @ORM\OneToOne(targetEntity="App\Entity\Media", mappedBy="theme", cascade={"persist", "remove"}))
  57.      * @ORM\JoinColumn(name="theme_picto", referencedColumnName="id", onDelete="CASCADE")
  58.      */
  59.     private $picto;    
  60.     
  61.     /**
  62.      * @ORM\ManyToMany(targetEntity="App\Entity\Tag", inversedBy="themes", cascade={"persist", "remove"})
  63.      * @ORM\OrderBy({"name" = "ASC"})
  64.      * @ORM\JoinTable(name="theme_tag",
  65.      *      joinColumns={@ORM\JoinColumn(name="theme_id", referencedColumnName="id")},
  66.      *      inverseJoinColumns={@ORM\JoinColumn(name="tag_id", referencedColumnName="id")}
  67.      * )
  68.      */
  69.     private $tags;
  70.     public function __construct()
  71.     {
  72.         // $slugger = new AsciiSlugger();
  73.         // $this->slug = $slugger->slug($this->name);
  74.         $this->createdAt = new \DateTime('now'); // default 
  75.         $this->updatedAt = new \DateTime('now'); // default
  76.         $this->tags = new ArrayCollection();
  77.     }
  78.     public function __toString()
  79.     {
  80.         return $this->name;    
  81.     }
  82.     public function getId(): ?int
  83.     {
  84.         return $this->id;
  85.     }
  86.     public function getName(): ?string
  87.     {
  88.         return $this->name;
  89.     }
  90.     public function setName(string $name): self
  91.     {
  92.         $this->name trim(strtolower($name));
  93.         return $this;
  94.     }
  95.     public function getSlug(): ?string
  96.     {
  97.         return $this->slug;
  98.     }
  99.     public function setSlug(string $slug): self
  100.     {
  101.         $this->slug $slug;
  102.         return $this;
  103.     }
  104.     public function getPriority(): ?int
  105.     {
  106.         return $this->priority;
  107.     }
  108.     public function setPriority(int $priority): self
  109.     {
  110.         $this->priority $priority;
  111.         return $this;
  112.     }
  113.     public function getCreatedAt(): ?\DateTimeInterface
  114.     {
  115.         return $this->createdAt;
  116.     }
  117.     public function setCreatedAt(?\DateTimeInterface $createdAt): self
  118.     {
  119.         $this->created $createdAt;
  120.         return $this;
  121.     }
  122.     public function getUpdatedAt(): ?\DateTimeInterface
  123.     {
  124.         return $this->updatedAt;
  125.     }
  126.     public function setUpdatedAt(\DateTimeInterface $updatedAt): self
  127.     {
  128.         $this->updatedAt $updatedAt;
  129.         return $this;
  130.     }
  131.     public function getPicto(): ?Media
  132.     {
  133.         return $this->picto;
  134.     }
  135.     public function setPicto(?Media $picto): self
  136.     {
  137.         $this->picto $picto;
  138.         // if($picto) $picto->setTheme($this);
  139.         return $this;
  140.     }
  141.     /**
  142.      * @return Collection|Tag[]
  143.      */
  144.     public function getTags(): ?Collection
  145.     {
  146.         return $this->tags;
  147.     }
  148.     public function addTag(Tag $tag): self
  149.     {
  150.         if (!$this->tags->contains($tag)) {
  151.             $this->tags[] = $tag;
  152.         }
  153.         return $this;
  154.     }
  155.     public function removeTag(Tag $tag): self
  156.     {
  157.         if ($this->tags->contains($tag)) {
  158.             $this->tags->removeElement($tag);
  159.         }
  160.         return $this;
  161.     }
  162. }