src/Entity/Category.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CategoryRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Gedmo\Mapping\Annotation as Gedmo;
  8. /**
  9.  * @ORM\Entity(repositoryClass=CategoryRepository::class)
  10.  */
  11. class Category
  12. {
  13.     /**
  14.      * @ORM\Id
  15.      * @ORM\GeneratedValue
  16.      * @ORM\Column(type="integer")
  17.      */
  18.     private $id;
  19.     /**
  20.      * @ORM\Column(type="string", length=255)
  21.      */
  22.     private $name;
  23.     /**
  24.      * @ORM\Column(type="string", length=191, unique=true)
  25.      * @Gedmo\Slug(fields={"name"})
  26.      */
  27.     private $slug;
  28.     /**
  29.      * @ORM\Column(type="text", nullable=true)
  30.      */
  31.     private $description;
  32.     /**
  33.      * @ORM\Column(type="string", length=50, nullable=true)
  34.      */
  35.     private $color;
  36.     /**
  37.      * @ORM\Column(type="string", length=50, nullable=true)
  38.      */
  39.     private $icon;
  40.     /**
  41.      * @ORM\Column(type="integer")
  42.      */
  43.     private $position 0;
  44.     /**
  45.      * @ORM\Column(type="boolean")
  46.      */
  47.     private $isActive true;
  48.     /**
  49.      * @ORM\OneToMany(targetEntity=Article::class, mappedBy="category")
  50.      */
  51.     private $articles;
  52.     /**
  53.      * @ORM\Column(type="datetime")
  54.      * @Gedmo\Timestampable(on="create")
  55.      */
  56.     private $createdAt;
  57.     /**
  58.      * @ORM\Column(type="datetime")
  59.      * @Gedmo\Timestampable(on="update")
  60.      */
  61.     private $updatedAt;
  62.     public function __construct()
  63.     {
  64.         $this->articles = new ArrayCollection();
  65.     }
  66.     public function getId(): ?int
  67.     {
  68.         return $this->id;
  69.     }
  70.     public function getName(): ?string
  71.     {
  72.         return $this->name;
  73.     }
  74.     public function setName(string $name): self
  75.     {
  76.         $this->name $name;
  77.         return $this;
  78.     }
  79.     public function getSlug(): ?string
  80.     {
  81.         return $this->slug;
  82.     }
  83.     public function setSlug(string $slug): self
  84.     {
  85.         $this->slug $slug;
  86.         return $this;
  87.     }
  88.     public function getDescription(): ?string
  89.     {
  90.         return $this->description;
  91.     }
  92.     public function setDescription(?string $description): self
  93.     {
  94.         $this->description $description;
  95.         return $this;
  96.     }
  97.     public function getColor(): ?string
  98.     {
  99.         return $this->color;
  100.     }
  101.     public function setColor(?string $color): self
  102.     {
  103.         $this->color $color;
  104.         return $this;
  105.     }
  106.     public function getIcon(): ?string
  107.     {
  108.         return $this->icon;
  109.     }
  110.     public function setIcon(?string $icon): self
  111.     {
  112.         $this->icon $icon;
  113.         return $this;
  114.     }
  115.     public function getPosition(): ?int
  116.     {
  117.         return $this->position;
  118.     }
  119.     public function setPosition(int $position): self
  120.     {
  121.         $this->position $position;
  122.         return $this;
  123.     }
  124.     public function getIsActive(): ?bool
  125.     {
  126.         return $this->isActive;
  127.     }
  128.     public function setIsActive(bool $isActive): self
  129.     {
  130.         $this->isActive $isActive;
  131.         return $this;
  132.     }
  133.     /**
  134.      * @return Collection|Article[]
  135.      */
  136.     public function getArticles(): Collection
  137.     {
  138.         return $this->articles;
  139.     }
  140.     public function addArticle(Article $article): self
  141.     {
  142.         if (!$this->articles->contains($article)) {
  143.             $this->articles[] = $article;
  144.             $article->setCategory($this);
  145.         }
  146.         return $this;
  147.     }
  148.     public function removeArticle(Article $article): self
  149.     {
  150.         if ($this->articles->removeElement($article)) {
  151.             if ($article->getCategory() === $this) {
  152.                 $article->setCategory(null);
  153.             }
  154.         }
  155.         return $this;
  156.     }
  157.     public function getCreatedAt(): ?\DateTimeInterface
  158.     {
  159.         return $this->createdAt;
  160.     }
  161.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  162.     {
  163.         $this->createdAt $createdAt;
  164.         return $this;
  165.     }
  166.     public function getUpdatedAt(): ?\DateTimeInterface
  167.     {
  168.         return $this->updatedAt;
  169.     }
  170.     public function setUpdatedAt(\DateTimeInterface $updatedAt): self
  171.     {
  172.         $this->updatedAt $updatedAt;
  173.         return $this;
  174.     }
  175.     public function __toString(): string
  176.     {
  177.         return $this->name ?? '';
  178.     }
  179. }