<?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\BFTournoiRepository")
*/
class BFTournoi
{
/**
* @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\ManyToOne(targetEntity="App\Entity\BFEdition", inversedBy="bftournois")
* @ORM\JoinColumn(nullable=false)
*/
private $edition;
/**
* @ORM\OneToMany(targetEntity="App\Entity\BFSeance", mappedBy="tournoi", orphanRemoval=true)
* @ORM\OrderBy({"startdate" = "ASC"})
*/
private $seances;
/**
* @ORM\OneToOne(targetEntity="App\Entity\BFDescriptionTournoi", inversedBy="bftournoi", cascade={"persist", "remove"})
* @ORM\JoinColumn(nullable=false)
*/
private $description;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $type;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $creationdate;
/**
* @ORM\OneToMany(targetEntity="App\Entity\BFInscription", mappedBy="tournoi", orphanRemoval=true)
* @ORM\OrderBy({"updatedate" = "DESC", "creationdate" = "DESC"})
*/
private $inscriptions;
/**
* @ORM\OneToMany(targetEntity="App\Entity\BFMailTournoi", mappedBy="tournoi", orphanRemoval=true)
*/
private $mails;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\BFProductEdition", mappedBy="tournois")
*/
private $bfproducteditions;
public function __construct()
{
$this->seances = new ArrayCollection();
$this->description = new BFDescriptionTournoi();
$this->creationdate = new \DateTime('now');
$this->inscriptions = new ArrayCollection();
$this->mails = new ArrayCollection();
$this->bfproducteditions = 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 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 getEdition(): ?BFEdition
{
return $this->edition;
}
public function setEdition(?BFEdition $edition): self
{
$this->edition = $edition;
return $this;
}
public function getDescription(): ?BFDescriptionTournoi
{
return $this->description;
}
public function setDescription(?BFDescriptionTournoi $description): self
{
$this->description = $description;
return $this;
}
/**
* @return Collection|BFSeance[]
*/
public function getSeances(): Collection
{
return $this->seances;
}
public function addBfseance(BFSeance $seance): self
{
if (!$this->seances->contains($seance)) {
$this->seances[] = $seance;
$seance->setTournoiid($this);
}
return $this;
}
public function removeSeance(BFSeance $seance): self
{
if ($this->seances->contains($seance)) {
$this->seances->removeElement($seance);
// set the owning side to null (unless already changed)
if ($seance->getTournoiid() === $this) {
$seance->setTournoiid(null);
}
}
return $this;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(?string $type): self
{
$this->type = $type;
return $this;
}
/**
* @Assert\IsTrue(message="Les dates ne sont pas valides")
*/
public function isDatesValid()
{
return $this->startdate<=$this->enddate;
}
/**
* @Assert\IsTrue(message="Les dates ne sont pas comprises par celles de l'édition")
*/
public function isDatesInEdition()
{
$startdateedition = $this->getEdition()->getStartdate();
$enddateedition = $this->getEdition()->getEnddate();
return $this->startdate>=$startdateedition && $this->startdate<=$enddateedition
&& $this->enddate>=$startdateedition && $this->enddate<=$enddateedition;
}
public function getCreationdate(): ?\DateTimeInterface
{
return $this->creationdate;
}
public function setCreationdate(?\DateTimeInterface $creationdate): self
{
$this->creationdate = $creationdate;
return $this;
}
/**
* @return Collection|BFInscription[]
*/
public function getInscriptions(): Collection
{
return $this->inscriptions;
}
public function addInscription(BFInscription $inscription): self
{
if (!$this->inscriptions->contains($inscription)) {
$this->inscriptions[] = $inscription;
$inscription->setTournoi($this);
}
return $this;
}
public function removeInscription(BFInscription $inscription): self
{
if ($this->inscriptions->contains($inscription)) {
$this->inscriptions->removeElement($inscription);
// set the owning side to null (unless already changed)
if ($inscription->getTournoi() === $this) {
$inscription->setTournoi(null);
}
}
return $this;
}
public static function sorting($a,$b)
{
if($a->getStartdate()<$b->getStartdate())
return -1;
else if($a->getStartdate()==$b->getStartdate()
&& $a->getEnddate()<$b->getEnddate())
return -1;
else if($a->getStartdate()==$b->getStartdate()
&& $a->getEnddate()==$b->getEnddate())
return 0;
else
return 1;
}
/**
* @return Collection|BFMailTournoi[]
*/
public function getMails(): Collection
{
return $this->mails;
}
public function addMail(BFMailTournoi $mail): self
{
if (!$this->mails->contains($mail)) {
$this->mails[] = $mail;
$mail->setTournoi($this);
}
return $this;
}
public function removeMail(BFMailTournoi $mail): self
{
if ($this->mails->contains($mail)) {
$this->mails->removeElement($mail);
// set the owning side to null (unless already changed)
if ($mail->getTournoi() === $this) {
$mail->setTournoi(null);
}
}
return $this;
}
/**
* @return Collection|BFProductEdition[]
*/
public function getBfproducteditions(): Collection
{
return $this->bfproducteditions;
}
public function addBfproductedition(BFProductEdition $bfproductedition): self
{
if (!$this->bfproducteditions->contains($bfproductedition)) {
$this->bfproducteditions[] = $bfproductedition;
$bfproductedition->addTournois($this);
}
return $this;
}
public function removeBfproductedition(BFProductEdition $bfproductedition): self
{
if ($this->bfproducteditions->contains($bfproductedition)) {
$this->bfproducteditions->removeElement($bfproductedition);
$bfproductedition->removeTournois($this);
}
return $this;
}
}