src/Entity/Site.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\SiteRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Doctrine\ORM\PersistentCollection;
  8. use Gedmo\Mapping\Annotation as Gedmo;
  9. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  10. /**
  11.  * @ORM\Entity(repositoryClass=SiteRepository::class)
  12.  * @ORM\HasLifecycleCallbacks
  13.  * @Vich\Uploadable()
  14.  */
  15. class Site
  16. {
  17.     /**
  18.      * @ORM\Id
  19.      * @ORM\GeneratedValue
  20.      * @ORM\Column(type="integer")
  21.      */
  22.     private int $id;
  23.     /**
  24.      * @ORM\Column(type="string", length=255)
  25.      */
  26.     private string $title;
  27.     /**
  28.      * @ORM\Column(type="string", length=1024)
  29.      */
  30.     private string $shortDescription;
  31.     /**
  32.      * @ORM\Column(type="text")
  33.      */
  34.     private string $description;
  35.     /**
  36.      * @ORM\Column(type="string", length=255, nullable=true)
  37.      */
  38.     private ?string $location;
  39.     /**
  40.      * @ORM\Column(type="string", length=255, unique=true)
  41.      *
  42.      * @Gedmo\Slug(fields={"title"})
  43.      */
  44.     private string $slug;
  45.     /**
  46.      * @ORM\Column(type="date", nullable=true)
  47.      */
  48.     private ?\DateTimeInterface $date;
  49.     /**
  50.      * @ORM\Column(type="datetime")
  51.      */
  52.     private ?\DateTimeInterface $createdAt;
  53.     /**
  54.      * @ORM\Column(type="datetime")
  55.      */
  56.     private ?\DateTimeInterface $updatedAt;
  57.     /**
  58.      * @ORM\OneToMany(targetEntity="Image", mappedBy="site", cascade={"all"})
  59.      */
  60.     private $images;
  61.     /**
  62.      * @ORM\ManyToMany(targetEntity=Category::class)
  63.      */
  64.     private $categories;
  65.     public function __construct()
  66.     {
  67.         $this->createdAt = new \DateTimeImmutable();
  68.         $this->categories = new ArrayCollection();
  69.     }
  70.     /**
  71.      * @ORM\PrePersist
  72.      * @ORM\PreUpdate
  73.      */
  74.     public function updatedTimestamps(): void
  75.     {
  76.         $this->setUpdatedAt(new \DateTime('now'));
  77.         if ($this->getCreatedAt() === null) {
  78.             $this->setCreatedAt(new \DateTime('now'));
  79.         }
  80.     }
  81.     public function getId(): ?int
  82.     {
  83.         return $this->id;
  84.     }
  85.     public function getTitle(): ?string
  86.     {
  87.         return $this->title;
  88.     }
  89.     public function setTitle(string $title): self
  90.     {
  91.         $this->title $title;
  92.         return $this;
  93.     }
  94.     public function getShortDescription(): ?string
  95.     {
  96.         return $this->shortDescription;
  97.     }
  98.     public function setShortDescription(string $shortDescription): self
  99.     {
  100.         $this->shortDescription $shortDescription;
  101.         return $this;
  102.     }
  103.     public function getDescription(): ?string
  104.     {
  105.         return $this->description;
  106.     }
  107.     public function setDescription(string $description): self
  108.     {
  109.         $this->description $description;
  110.         return $this;
  111.     }
  112.     public function getLocation(): ?string
  113.     {
  114.         return $this->location;
  115.     }
  116.     public function setLocation(?string $location): self
  117.     {
  118.         $this->location $location;
  119.         return $this;
  120.     }
  121.     public function getSlug(): string
  122.     {
  123.         return $this->slug;
  124.     }
  125.     public function setSlug(string $slug): void
  126.     {
  127.         $this->slug $slug;
  128.     }
  129.     public function getDate(): ?\DateTimeInterface
  130.     {
  131.         return $this->date;
  132.     }
  133.     public function setDate(?\DateTimeInterface $date): self
  134.     {
  135.         $this->date $date;
  136.         return $this;
  137.     }
  138.     public function getImages()
  139.     {
  140.         return $this->images;
  141.     }
  142.     public function addImage(Image $image): self
  143.     {
  144.         $image->setSite($this);
  145.         $this->images[] = $image;
  146.         return $this;
  147.     }
  148.     public function removeImage(Image $image)
  149.     {
  150.         $image->setSite(null);
  151.         $this->images->removeElement($image);
  152.     }
  153.     public function __toString(): string
  154.     {
  155.         return $this->title ' '$this->location;
  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.     /**
  176.      * @return Collection|Category[]
  177.      */
  178.     public function getCategories(): Collection
  179.     {
  180.         return $this->categories;
  181.     }
  182.     public function addCategory(Category $category): self
  183.     {
  184.         if (!$this->categories->contains($category)) {
  185.             $this->categories[] = $category;
  186.         }
  187.         return $this;
  188.     }
  189.     public function removeCategory(Category $category): self
  190.     {
  191.         $this->categories->removeElement($category);
  192.         return $this;
  193.     }
  194. }