<?php
namespace App\Entity;
use App\Repository\CategoryRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ORM\Entity(repositoryClass=CategoryRepository::class)
*
* @ORM\HasLifecycleCallbacks()
*
* @Vich\Uploadable
*/
class Category {
use MetaTrait;
/**
* @ORM\Id
*
* @ORM\GeneratedValue
*
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $description;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $listImage;
/**
* @Vich\UploadableField(mapping="images", fileNameProperty="listImage")
*/
private $listImageFile;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $headerImage;
/**
* @Vich\UploadableField(mapping="images", fileNameProperty="headerImage")
*/
private $headerImageFile;
/**
* @ORM\ManyToMany(targetEntity=Product::class, inversedBy="categories")
*/
private $products;
/**
* @ORM\ManyToOne(targetEntity=Tenant::class, inversedBy="categories")
*
* @ORM\JoinColumn(nullable=false)
*/
private $tenant;
public function __construct() {
$this->products = new ArrayCollection();
}
public function __toString(): string {
return $this->getName();
}
public function getId(): ?int {
return $this->id;
}
public function getName(): ?string {
return $this->name;
}
public function setName(string $name): self {
$this->name = $name;
return $this;
}
public function getDescription(): ?string {
return $this->description;
}
public function setDescription(?string $description): self {
$this->description = $description;
return $this;
}
public function getListImage(): ?string {
return $this->listImage;
}
public function setListImage(?string $listImage): self {
$this->listImage = $listImage;
return $this;
}
public function getListImageFile(): ?File {
return $this->listImageFile;
}
public function setListImageFile(?File $listImageFile): self {
$this->listImageFile = $listImageFile;
if ($this->listImageFile instanceof File) {
$this->modifiedAt = new \DateTime();
}
return $this;
}
public function getHeaderImage(): ?string {
return $this->headerImage;
}
public function setHeaderImage(?string $headerImage): self {
$this->headerImage = $headerImage;
return $this;
}
public function getHeaderImageFile(): ?File {
return $this->headerImageFile;
}
public function setHeaderImageFile(?File $headerImageFile): self {
$this->headerImageFile = $headerImageFile;
if ($this->headerImageFile instanceof File) {
$this->modifiedAt = new \DateTime();
}
return $this;
}
/**
* @return Collection<int, Product>
*/
public function getProducts(): Collection {
return $this->products;
}
public function addProduct(Product $product): self {
if (!$this->products->contains($product)) {
$this->products[] = $product;
}
return $this;
}
public function removeProduct(Product $product): self {
$this->products->removeElement($product);
return $this;
}
public function getTenant(): ?Tenant {
return $this->tenant;
}
public function setTenant(?Tenant $tenant): self {
$this->tenant = $tenant;
return $this;
}
/**
* @ORM\PrePersist
*/
public function setDefaults(): self {
return $this
->setCreatedAt(new \DateTime())
;
}
/**
* @ORM\PreUpdate
*/
public function setModified(): self {
return $this
->setModifiedAt(new \DateTime())
;
}
}