<?php
namespace App\Entity;
use App\Repository\WorkshopRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Serializer\Annotation\Groups;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ORM\Entity(repositoryClass=WorkshopRepository::class)
* @Vich\Uploadable
*/
class Workshop
{
const DELAY_TYPES = [
'days',
'hours'
];
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups("user_favorite:read")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
* @Assert\NotBlank
* @Groups("user_favorite:read")
*/
private $name;
/**
* @ORM\Column(type="text")
* @Assert\NotBlank
* @Groups("user_favorite:read")
*/
private $description;
/**
* @ORM\Column(type="integer")
* @Assert\NotBlank
* @Groups("user_favorite:read")
*/
private $duration;
/**
* @ORM\Column(type="integer", nullable=true)
* @Groups("user_favorite:read")
*/
private $capacity;
/**
* @ORM\Column(type="float", nullable=true)
* @Groups("user_favorite:read")
*/
private $price;
/**
* @ORM\Column(type="float", nullable=true)
* @Groups("user_favorite:read")
*/
private $tva;
/**
* @ORM\Column(type="string", length=50)
* @Assert\NotBlank
*/
private $color;
/**
* @ORM\Column(type="string", length=255)
* @Groups("user_favorite:read")
*/
private $image;
/**
* @ORM\Column(type="datetime")
*/
private $createdAt;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $updatedAt;
/**
* @ORM\ManyToOne(targetEntity=Tag::class)
* @ORM\JoinColumn(nullable=false)
* @Groups("user_favorite:read")
*/
private $tag;
/**
* @ORM\ManyToOne(targetEntity=Company::class, inversedBy="workshops")
*/
private $company;
/**
* @ORM\OneToMany(targetEntity=Event::class, mappedBy="workshop", orphanRemoval=true)
*/
private $events;
/**
* @Vich\UploadableField(mapping="workshop_images", fileNameProperty="image")
* @Assert\File(
* mimeTypes={"image/jpeg", "image/gif", "image/png"},
* maxSize="700Ki",
* )
* @var File|null
*/
private $imageFile;
/**
* @ORM\Column(type="string", length=50, nullable=true)
*/
private $delay;
/**
* @ORM\Column(type="string", length=50, nullable=true)
*/
private $delayType;
/**
* @ORM\ManyToOne(targetEntity=Specialist::class, inversedBy="workshops")
* @Groups("user_favorite:read")
*/
private $specialist;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $coefMajoration;
/**
* @ORM\Column(type="boolean", options={"default": 0})
* @Groups("user_favorite:read")
*/
private $isFixedPrice = false;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $fixedPurchasePrice;
/**
* @ORM\Column(type="float", nullable=true)
* @Groups("user_favorite:read")
*/
private $fixedSellingPrice;
/**
* @ORM\Column(type="integer", nullable=true)
* @Groups("user_favorite:read")
*/
private $marketplaceFamily;
/**
* @ORM\ManyToOne(targetEntity=MarketplaceCategory::class, inversedBy="workshops")
* @Groups("user_favorite:read")
*/
private $marketplaceCategory;
/**
* @ORM\Column(type="boolean", options={"default": 0})
* @Groups("user_favorite:read")
*/
private $marketplaceIsDisplay = false;
/**
* @ORM\Column(type="boolean", options={"default": 0})
* @Groups("user_favorite:read")
*/
private $isVirtual = false;
/**
* @ORM\OneToMany(targetEntity=MarketplaceReservation::class, mappedBy="workshop")
*/
private $marketplaceReservations;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups("user_favorite:read")
*/
private $bannerImage;
/**
* @Vich\UploadableField(mapping="workshop_images", fileNameProperty="bannerImage")
* @Assert\File(
* mimeTypes={"image/jpeg", "image/gif", "image/png"},
* maxSize="700Ki",
* )
* @var File|null
*/
private $bannerImageFile;
public $isFavorite = false;
/**
* @return File|null
*/
public function getImageFile(): ?File
{
return $this->imageFile;
}
/**
* @param File|null $imageFile
* @return Workshop
*/
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 File|null
*/
public function getBannerImageFile(): ?File
{
return $this->bannerImageFile;
}
/**
* @param File|null $bannerImageFile
* @return Workshop
*/
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 __construct()
{
$this->events = new ArrayCollection();
$this->createdAt = new \DateTime();
$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 getDescription(): ?string
{
return $this->description;
}
public function setDescription(string $description): self
{
$this->description = $description;
return $this;
}
public function getDuration(): ?int
{
return $this->duration;
}
public function setDuration(int $duration): self
{
$this->duration = $duration;
return $this;
}
public function getCapacity(): ?int
{
return $this->capacity;
}
public function setCapacity(int $capacity): self
{
$this->capacity = $capacity;
return $this;
}
public function getPrice(): ?float
{
return $this->price;
}
public function setPrice(?float $price): self
{
$this->price = $price;
return $this;
}
public function getTva(): ?float
{
return $this->tva;
}
public function setTva(?float $tva): self
{
$this->tva = $tva;
return $this;
}
public function getColor(): ?string
{
return $this->color;
}
public function setColor(string $color): self
{
$this->color = $color;
return $this;
}
public function getImage(): ?string
{
return $this->image;
}
public function setImage(?string $image): self
{
$this->image = $image;
return $this;
}
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;
}
public function getTag(): ?Tag
{
return $this->tag;
}
public function setTag(?Tag $tag): self
{
$this->tag = $tag;
return $this;
}
public function getCompany(): ?Company
{
return $this->company;
}
public function setCompany(?Company $company): self
{
$this->company = $company;
return $this;
}
/**
* @return Collection|Event[]
*/
public function getEvents(): Collection
{
return $this->events;
}
public function addEvent(Event $event): self
{
if (!$this->events->contains($event)) {
$this->events[] = $event;
$event->setWorkshop($this);
}
return $this;
}
public function removeEvent(Event $event): self
{
if ($this->events->removeElement($event)) {
// set the owning side to null (unless already changed)
if ($event->getWorkshop() === $this) {
$event->setWorkshop(null);
}
}
return $this;
}
public function __toString()
{
$result = $this->name . " (max: $this->capacity)";
if ($this->company instanceof Company){
$result .= ' - ' . strtoupper((string)$this->company);
}
if ($this->specialist instanceof Specialist){
$result .= ' - assuré par ' . $this->specialist;
}
return $result;
}
public function getDelay(): ?string
{
return $this->delay;
}
public function setDelay(?string $delay): self
{
$this->delay = $delay;
return $this;
}
public function getDelayType(): ?string
{
return $this->delayType;
}
public function setDelayType(?string $delayType): self
{
$this->delayType = $delayType;
return $this;
}
public function getSpecialist(): ?Specialist
{
return $this->specialist;
}
public function setSpecialist(?Specialist $specialist): self
{
$this->specialist = $specialist;
return $this;
}
public function getCoefMajoration(): ?float
{
return $this->coefMajoration;
}
public function setCoefMajoration(?float $coefMajoration): self
{
$this->coefMajoration = $coefMajoration;
return $this;
}
public function getIsFixedPrice(): ?bool
{
return $this->isFixedPrice;
}
public function setIsFixedPrice(bool $isFixedPrice): self
{
$this->isFixedPrice = $isFixedPrice;
return $this;
}
public function getFixedPurchasePrice(): ?float
{
return $this->fixedPurchasePrice;
}
public function setFixedPurchasePrice(?float $fixedPurchasePrice): self
{
$this->fixedPurchasePrice = $fixedPurchasePrice;
return $this;
}
public function getFixedSellingPrice(): ?float
{
return $this->fixedSellingPrice;
}
public function setFixedSellingPrice(?float $fixedSellingPrice): self
{
$this->fixedSellingPrice = $fixedSellingPrice;
return $this;
}
public function getMarketplaceFamily(): ?int
{
return $this->marketplaceFamily;
}
public function setMarketplaceFamily(?int $marketplaceFamily): self
{
$this->marketplaceFamily = $marketplaceFamily;
return $this;
}
public function getMarketplaceCategory(): ?MarketplaceCategory
{
return $this->marketplaceCategory;
}
public function setMarketplaceCategory(?MarketplaceCategory $marketplaceCategory): self
{
$this->marketplaceCategory = $marketplaceCategory;
return $this;
}
public function getMarketplaceIsDisplay(): ?bool
{
return $this->marketplaceIsDisplay;
}
public function setMarketplaceIsDisplay(bool $marketplaceIsDisplay): self
{
$this->marketplaceIsDisplay = $marketplaceIsDisplay;
return $this;
}
public function getIsVirtual(): ?bool
{
return $this->isVirtual;
}
public function setIsVirtual(?bool $isVirtual): self
{
$this->isVirtual = $isVirtual;
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->setWorkshop($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->getWorkshop() === $this) {
$marketplaceReservation->setWorkshop(null);
}
}
return $this;
}
public function isFreeSellingPrice(): Bool
{
return (empty($this->fixedSellingPrice));
}
public function getBannerImage(): ?string
{
return $this->bannerImage;
}
public function setBannerImage(?string $bannerImage): self
{
$this->bannerImage = $bannerImage;
return $this;
}
}