<?php
namespace App\Entity;
use App\Repository\MarketplaceCategoryRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Validator\Constraints as Assert;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ORM\Entity(repositoryClass=MarketplaceCategoryRepository::class)
* @Vich\Uploadable
*/
class MarketplaceCategory
{
const SPORT = "Sport";
const SANTE = "Santé";
const ORGANISATION = "Organisation";
const BIEN_ETRE = "Bien-ĂȘtre";
const FAMILIES = [
self::SPORT => 1,
self::SANTE => 2,
self::ORGANISATION => 3,
self::BIEN_ETRE => 4,
];
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\Column(type="integer", nullable=true)
* @Assert\Choice(choices=self::FAMILIES)
*/
private $family;
/**
* @ORM\Column(type="datetime")
* @Gedmo\Timestampable(on="create")
*/
private $createdAt;
/**
* @ORM\Column(type="datetime", nullable=true)
* @Gedmo\Timestampable(on="update")
*/
private $updatedAt;
/**
* @ORM\OneToMany(targetEntity=Workshop::class, mappedBy="marketplaceCategory")
*/
private $workshops;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $image;
/**
* @Vich\UploadableField(mapping="marketplace_category_images", fileNameProperty="image")
* @Assert\File(
* mimeTypes={"image/jpeg", "image/gif", "image/png"},
* maxSize="700Ki",
* )
* @var File|null
*/
private $imageFile;
/**
* @ORM\OneToMany(targetEntity=MarketplaceReservation::class, mappedBy="category")
*/
private $marketplaceReservations;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $bannerImage;
/**
* @Vich\UploadableField(mapping="marketplace_category_images", fileNameProperty="bannerImage")
* @Assert\File(
* mimeTypes={"image/jpeg", "image/gif", "image/png"},
* maxSize="700Ki",
* )
* @var File|null
*/
private $bannerImageFile;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $description;
public function __construct()
{
$this->workshops = new ArrayCollection();
$this->marketplaceReservations = new ArrayCollection();
}
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 getFamily(): ?int
{
return $this->family;
}
public function setFamily(?int $family): self
{
$this->family = $family;
return $this;
}
public function getFamilyName(): ?string
{
return array_flip(self::FAMILIES)[$this->family];
}
public function getCreatedAt(): ?\DateTime
{
return $this->createdAt;
}
public function setCreatedAt(\DateTime $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTime
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTime $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* @return Collection<int, Workshop>
*/
public function getWorkshops(): Collection
{
return $this->workshops;
}
public function addWorkshop(Workshop $workshop): self
{
if (!$this->workshops->contains($workshop)) {
$this->workshops[] = $workshop;
$workshop->setMarketplaceCategory($this);
}
return $this;
}
public function removeWorkshop(Workshop $workshop): self
{
if ($this->workshops->removeElement($workshop)) {
// set the owning side to null (unless already changed)
if ($workshop->getMarketplaceCategory() === $this) {
$workshop->setMarketplaceCategory(null);
}
}
return $this;
}
public function getImage(): ?string
{
return $this->image;
}
public function setImage(?string $image): self
{
$this->image = $image;
return $this;
}
/**
* @return File|null
*/
public function getImageFile(): ?File
{
return $this->imageFile;
}
/**
* @param File|null $imageFile
* @return MarketplaceCategory
*/
public function setImageFile(?File $imageFile = null): self
{
$this->imageFile = $imageFile;
if ($imageFile) {
// if 'updatedAt' is not defined in your entity, use another property
$this->updatedAt = new \DateTime('now');
}
return $this;
}
/**
* @return Collection<int, MarketplaceReservation>
*/
public function getMarketplaceReservations(): Collection
{
return $this->marketplaceReservations;
}
public function addMarketplaceReservation(MarketplaceReservation $marketplaceReservation): self
{
if (!$this->marketplaceReservations->contains($marketplaceReservation)) {
$this->marketplaceReservations[] = $marketplaceReservation;
$marketplaceReservation->setCategory($this);
}
return $this;
}
public function removeMarketplaceReservation(MarketplaceReservation $marketplaceReservation): self
{
if ($this->marketplaceReservations->removeElement($marketplaceReservation)) {
// set the owning side to null (unless already changed)
if ($marketplaceReservation->getCategory() === $this) {
$marketplaceReservation->setCategory(null);
}
}
return $this;
}
public function getBannerImage(): ?string
{
return $this->bannerImage;
}
public function setBannerImage(?string $bannerImage): self
{
$this->bannerImage = $bannerImage;
return $this;
}
/**
* @return File|null
*/
public function getBannerImageFile(): ?File
{
return $this->bannerImageFile;
}
/**
* @param File|null $bannerImageFile
* @return MarketplaceCategory
*/
public function setBannerImageFile(?File $bannerImageFile = null): self
{
$this->bannerImageFile = $bannerImageFile;
if ($bannerImageFile) {
// if 'updatedAt' is not defined in your entity, use another property
$this->updatedAt = new \DateTime('now');
}
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
}