<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass="App\Repository\BFProductEditionRepository")
*/
class BFProductEdition
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\BFEdition", inversedBy="bfproducteditions")
* @ORM\JoinColumn(onDelete="SET NULL")
*/
private $edition;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\BFTournoi", inversedBy="bfproducteditions")
* @ORM\OrderBy({"startdate" = "ASC", "enddate" = "ASC" })
*/
private $tournois;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\Column(type="integer")
* @Assert\Range(
* min = 0,
* max = 20001,
* notInRangeMessage = "Le prix doit être entre 0€ et 200€",)
*/
private $price;
/**
* @ORM\Column(type="text")
*/
private $description;
/**
* @ORM\Column(type="boolean")
*/
private $isactive;
/**
* @ORM\OneToMany(targetEntity="App\Entity\BFOrderEdition", mappedBy="productedition")
*/
private $bFOrderEditions;
const stripefeespercent = 0.014; // 1.4%
const stripefeesfix = 25; // 0.25€
public function __construct()
{
$this->tournois = new ArrayCollection();
$this->isactive=true;
$this->bFOrderEditions = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getEdition(): ?BFEdition
{
return $this->edition;
}
public function setEdition(?BFEdition $edition): self
{
$this->edition = $edition;
return $this;
}
/**
* @return Collection|BFTournoi[]
*/
public function getTournois(): Collection
{
return $this->tournois;
}
public function addTournois(BFTournoi $tournois): self
{
if (!$this->tournois->contains($tournois)) {
$this->tournois[] = $tournois;
}
return $this;
}
public function removeTournois(BFTournoi $tournois): self
{
if ($this->tournois->contains($tournois)) {
$this->tournois->removeElement($tournois);
}
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getPrice(): ?int
{
return $this->price;
}
public function setPrice(int $price): self
{
$this->price = $price;
return $this;
}
public function getDisplayprice(): ?float
{
return $this->getPrice()/100;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(string $description): self
{
$this->description = $description;
return $this;
}
public function getIsactive(): ?bool
{
return $this->isactive;
}
public function setIsactive(bool $isactive): self
{
$this->isactive = $isactive;
return $this;
}
public function getDeleteable(): ?bool
{
foreach($this->getBFOrderEditions() as $orderedition)
{
$paymentintentedition = $orderedition->getBFPaymentIntentEdition();
if($paymentintentedition!=null && $paymentintentedition->getSuccessdate()!=null)
return false;
}
return true;
}
/**
* @return Collection|BFOrderEdition[]
*/
public function getBFOrderEditions(): Collection
{
return $this->bFOrderEditions;
}
public function addBFOrderEdition(BFOrderEdition $bFOrderEdition): self
{
if (!$this->bFOrderEditions->contains($bFOrderEdition)) {
$this->bFOrderEditions[] = $bFOrderEdition;
$bFOrderEdition->setProductedition($this);
}
return $this;
}
public function removeBFOrderEdition(BFOrderEdition $bFOrderEdition): self
{
if ($this->bFOrderEditions->contains($bFOrderEdition)) {
$this->bFOrderEditions->removeElement($bFOrderEdition);
// set the owning side to null (unless already changed)
if ($bFOrderEdition->getProductedition() === $this) {
$bFOrderEdition->setProductedition(null);
}
}
return $this;
}
public function getFeebf(): ?int
{
$festivalfee = $this->getEdition()->getFestival()->getOrderfeebf();
return (int)ceil($this->getPrice()*self::stripefeespercent)+self::stripefeesfix+$festivalfee;
}
public function getDisplayfeebf(): ?float
{
return $this->getFeebf()/100;
}
}