<?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\BFEditionRepository")
*/
class BFEdition extends AbstractArrayAccess
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\Column(type="date")
*/
private $startdate;
/**
* @ORM\Column(type="date")
*/
private $enddate;
/**
* @ORM\Column(type="string", length=255)
*/
private $location;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\BFFestival", inversedBy="editions", cascade={"persist"})
* @ORM\JoinColumn(nullable=false)
*/
private $festival;
/**
* @ORM\OneToMany(targetEntity="App\Entity\BFTournoi", mappedBy="edition", orphanRemoval=true)
* @ORM\OrderBy({"startdate" = "ASC", "enddate" = "ASC"})
*/
private $tournois;
/**
* @ORM\OneToOne(targetEntity="App\Entity\BFDescriptionEdition", inversedBy="bfedition", cascade={"persist", "remove"})
* @ORM\JoinColumn(nullable=false)
*/
private $description;
/**
* @ORM\Column(type="boolean")
*/
private $isactive;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $placeid;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $locationhidden;
//for festivalsearch
private $distance;
/**
* @ORM\OneToMany(targetEntity="App\Entity\BFAdminLicences", mappedBy="edition", cascade={"persist", "remove"})
*/
private $BFAdminLicences;
/**
* @ORM\OneToOne(targetEntity="App\Entity\BFRouting", mappedBy="edition", cascade={"persist", "remove"})
*/
private $route;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $creationdate;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\BFChallengeEdition", mappedBy="editions")
*/
private $challengeeditions;
/**
* @ORM\OneToMany(targetEntity="App\Entity\BFProductEdition", cascade={"persist"}, mappedBy="edition")
* @ORM\OrderBy({"price" = "ASC"})
*/
private $bfproducteditions;
/**
* @ORM\OneToMany(targetEntity="App\Entity\BFPaymentIntentEdition", mappedBy="edition")
*/
private $bFPaymentIntentEditions;
public function __construct()
{
$this->tournois = new ArrayCollection();
$this->description = new BFDescriptionEdition();
$this->BFAdminLicences = new ArrayCollection();
$this->creationdate=new \DateTime('now');
$this->challengeeditions = new ArrayCollection();
$this->bfproducteditions = new ArrayCollection();
$this->bFPaymentIntentEditions = new ArrayCollection();
$this->isactive=false;
}
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 getStartdate(): ?\DateTimeInterface
{
return $this->startdate;
}
public function setStartdate(\DateTimeInterface $startdate): self
{
$this->startdate = $startdate;
return $this;
}
public function getEnddate(): ?\DateTimeInterface
{
return $this->enddate;
}
public function setEnddate(\DateTimeInterface $enddate): self
{
$this->enddate = $enddate;
return $this;
}
public function getLocation(): ?string
{
return $this->location;
}
public function setLocation(string $location): self
{
$this->location = $location;
return $this;
}
public function getFestival(): ?BFFestival
{
return $this->festival;
}
public function setFestival(?BFFestival $festival): self
{
$this->festival = $festival;
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;
$tournois->setEditionid($this);
}
return $this;
}
public function removeTournois(BFTournoi $tournois): self
{
if ($this->bftournois->contains($tournois)) {
$this->bftournois->removeElement($tournois);
// set the owning side to null (unless already changed)
if ($tournois->getEditionid() === $this) {
$tournois->setEditionid(null);
}
}
return $this;
}
public function getDescription(): ?BFDescriptionEdition
{
return $this->description;
}
public function setDescription(BFDescriptionEdition $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 getCountdays()
{
$interval = date_diff($this->enddate, $this->startdate);
return $interval->format('%a')+1;
}
public function getCounttournois()
{
return count($this->tournois);
}
public function getPlaceid(): ?string
{
return $this->placeid;
}
public function setPlaceid(?string $placeid): self
{
$this->placeid = $placeid;
return $this;
}
public function getLocationhidden(): ?string
{
return $this->locationhidden;
}
public function setLocationhidden(?string $locationhidden): self
{
$this->locationhidden = $locationhidden;
return $this;
}
public function getDistance()
{
return $this->distance;
}
public function setDistance($distance): self
{
$this->distance = $distance;
return $this;
}
public function CleanLocation()
{
if($this->location != $this->locationhidden)
{
$this->locationhidden = null;
$this->placeid=null;
}
}
/**
* @return Collection|BFAdminLicences[]
*/
public function getBFAdminLicences(): Collection
{
return $this->BFAdminLicences;
}
public function addBFAdminLicence(BFAdminLicences $bFAdminLicence): self
{
if (!$this->BFAdminLicences->contains($bFAdminLicence)) {
$this->BFAdminLicences[] = $bFAdminLicence;
$bFAdminLicence->setEdition($this);
}
return $this;
}
public function removeBFAdminLicence(BFAdminLicences $bFAdminLicence): self
{
if ($this->BFAdminLicences->contains($bFAdminLicence)) {
$this->BFAdminLicences->removeElement($bFAdminLicence);
// set the owning side to null (unless already changed)
if ($bFAdminLicence->getEdition() === $this) {
$bFAdminLicence->setEdition(null);
}
}
return $this;
}
public function getRoute(): ?BFRouting
{
return $this->route;
}
public function setRoute(?BFRouting $route): self
{
$this->route = $route;
// set (or unset) the owning side of the relation if necessary
$newEdition = null === $route ? null : $this;
if ($route->getEdition() !== $newEdition) {
$route->setEdition($newEdition);
}
return $this;
}
/**
* @Assert\IsTrue(message="Les dates ne sont pas valides")
*/
public function isDatesValid()
{
return $this->startdate<=$this->enddate;
}
public function getCreationdate(): ?\DateTimeInterface
{
return $this->creationdate;
}
public function setCreationdate(?\DateTimeInterface $creationdate): self
{
$this->creationdate = $creationdate;
return $this;
}
/**
* @return Collection|BFChallengeEdition[]
*/
public function getChallengeeditions(): Collection
{
return $this->challengeeditions;
}
public function getChallengeeditionsactive(): Collection
{
$collection= $this->challengeeditions;
$returncollection = new ArrayCollection();
foreach($collection as $edition)
{
if($edition->getIsactive())
$returncollection->add($edition);
}
return $returncollection;
}
public function addChallengeedition(BFChallengeEdition $challengeedition): self
{
if (!$this->challengeeditions->contains($challengeedition)) {
$this->challengeeditions[] = $challengeedition;
$challengeedition->addEdition($this);
}
return $this;
}
public function removeChallengeedition(BFChallengeEdition $challengeedition): self
{
if ($this->challengeeditions->contains($challengeedition)) {
$this->challengeeditions->removeElement($challengeedition);
$challengeedition->removeEdition($this);
}
return $this;
}
public function getHaschallengeeditions()
{
return (count($this->getChallengeeditions())>0);
}
public function getHaschallengeeditionsactive()
{
$return = false;
if(count($this->getChallengeeditions())>0)
{
foreach($this->getChallengeeditions() as $challengeedition)
{
if($challengeedition->getIsactive())
{
$return=true;
break;
}
}
}
return $return;
}
/**
* @return Collection|BFProductEdition[]
*/
public function getBfproducteditions(): Collection
{
$collection = $this->bfproducteditions;
$iterator = $collection->getIterator();
$iterator->uasort(function ($a, $b) {
if($a->getTournois()->count()!=$b->getTournois()->count())
{
return ($a->getTournois()->count()<$b->getTournois()->count()) ? 1 : -1;
}
if($a->getTournois()->count()>0 && $b->getTournois()->count() >0)
{
return ($a->getTournois()->first()->getStartdate()>$b->getTournois()->first()->getStartdate())? 1:-1;
}
if($a->getPrice() != $b->getPrice())
{
return ($a->getPrice()> $b->getPrice()) ? 1:-1;
}
return ($a->getId() > $b->getId()) ? 1 : -1;
});
$sortedcollection = new ArrayCollection(iterator_to_array($iterator));
return $sortedcollection;
}
public function addBfproductedition(BFProductEdition $bfproductedition): self
{
if (!$this->bfproducteditions->contains($bfproductedition)) {
$this->bfproducteditions[] = $bfproductedition;
$bfproductedition->setEdition($this);
}
return $this;
}
public function removeBfproductedition(BFProductEdition $bfproductedition): self
{
if ($this->bfproducteditions->contains($bfproductedition)) {
$this->bfproducteditions->removeElement($bfproductedition);
// set the owning side to null (unless already changed)
if ($bfproductedition->getEdition() === $this) {
$bfproductedition->setEdition(null);
}
}
return $this;
}
/**
* @return Collection|BFPaymentIntentEdition[]
*/
public function getBFPaymentIntentEditions(): Collection
{
return $this->bFPaymentIntentEditions;
}
public function addBFPaymentIntentEdition(BFPaymentIntentEdition $bFPaymentIntentEdition): self
{
if (!$this->bFPaymentIntentEditions->contains($bFPaymentIntentEdition)) {
$this->bFPaymentIntentEditions[] = $bFPaymentIntentEdition;
$bFPaymentIntentEdition->setEdition($this);
}
return $this;
}
public function removeBFPaymentIntentEdition(BFPaymentIntentEdition $bFPaymentIntentEdition): self
{
if ($this->bFPaymentIntentEditions->contains($bFPaymentIntentEdition)) {
$this->bFPaymentIntentEditions->removeElement($bFPaymentIntentEdition);
// set the owning side to null (unless already changed)
if ($bFPaymentIntentEdition->getEdition() === $this) {
$bFPaymentIntentEdition->setEdition(null);
}
}
return $this;
}
/**
* @return Collection|BFPaymentIntentEdition[]
*/
public function getBFPaymentIntentEditionsvalid(): Collection
{
$returncollection = new ArrayCollection();
foreach($this->getBFPaymentIntentEditions() as $bfpaymentintent)
{
if($bfpaymentintent->getSuccessdate()!=null)
$returncollection->add($bfpaymentintent);
}
return $returncollection;
}
}