src/Entity/BFEdition.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Symfony\Component\Validator\Constraints as Assert;
  7. /**
  8.  * @ORM\Entity(repositoryClass="App\Repository\BFEditionRepository")
  9.  */
  10. class BFEdition extends AbstractArrayAccess
  11. {
  12.     /**
  13.      * @ORM\Id()
  14.      * @ORM\GeneratedValue()
  15.      * @ORM\Column(type="integer")
  16.      */
  17.     private $id;
  18.     /**
  19.      * @ORM\Column(type="string", length=255)
  20.      */
  21.     private $name;
  22.     /**
  23.      * @ORM\Column(type="date")
  24.      */
  25.     private $startdate;
  26.     /**
  27.      * @ORM\Column(type="date")
  28.      */
  29.     private $enddate;
  30.     /**
  31.      * @ORM\Column(type="string", length=255)
  32.      */
  33.     private $location;
  34.     /**
  35.      * @ORM\ManyToOne(targetEntity="App\Entity\BFFestival", inversedBy="editions", cascade={"persist"})
  36.      * @ORM\JoinColumn(nullable=false)
  37.      */
  38.     private $festival;
  39.     /**
  40.      * @ORM\OneToMany(targetEntity="App\Entity\BFTournoi", mappedBy="edition", orphanRemoval=true)
  41.      * @ORM\OrderBy({"startdate" = "ASC", "enddate" = "ASC"})
  42.      */
  43.     private $tournois;
  44.     /**
  45.      * @ORM\OneToOne(targetEntity="App\Entity\BFDescriptionEdition", inversedBy="bfedition", cascade={"persist", "remove"})
  46.      * @ORM\JoinColumn(nullable=false)
  47.      */
  48.     private $description;
  49.     /**
  50.      * @ORM\Column(type="boolean")
  51.      */
  52.     private $isactive;
  53.     /**
  54.      * @ORM\Column(type="string", length=255, nullable=true)
  55.      */
  56.     private $placeid;
  57.     /**
  58.      * @ORM\Column(type="string", length=255, nullable=true)
  59.      */
  60.     private $locationhidden;
  61.     
  62.     //for festivalsearch
  63.     private $distance;
  64.     /**
  65.      * @ORM\OneToMany(targetEntity="App\Entity\BFAdminLicences", mappedBy="edition", cascade={"persist", "remove"})
  66.      */
  67.     private $BFAdminLicences;
  68.     /**
  69.      * @ORM\OneToOne(targetEntity="App\Entity\BFRouting", mappedBy="edition", cascade={"persist", "remove"})
  70.      */
  71.     private $route;
  72.     /**
  73.      * @ORM\Column(type="datetime", nullable=true)
  74.      */
  75.     private $creationdate;
  76.     /**
  77.      * @ORM\ManyToMany(targetEntity="App\Entity\BFChallengeEdition", mappedBy="editions")
  78.      */
  79.     private $challengeeditions;
  80.     /**
  81.      * @ORM\OneToMany(targetEntity="App\Entity\BFProductEdition", cascade={"persist"}, mappedBy="edition")
  82.      * @ORM\OrderBy({"price" = "ASC"})
  83.      */
  84.     private $bfproducteditions;
  85.     /**
  86.      * @ORM\OneToMany(targetEntity="App\Entity\BFPaymentIntentEdition", mappedBy="edition")
  87.      */
  88.     private $bFPaymentIntentEditions;
  89.     public function __construct()
  90.     {
  91.         $this->tournois = new ArrayCollection();
  92.         $this->description = new BFDescriptionEdition();
  93.         $this->BFAdminLicences = new ArrayCollection();
  94.         $this->creationdate=new \DateTime('now');
  95.         $this->challengeeditions = new ArrayCollection();
  96.         $this->bfproducteditions = new ArrayCollection();
  97.         $this->bFPaymentIntentEditions = new ArrayCollection();
  98.         $this->isactive=false;
  99.     }
  100.     public function getId(): ?int
  101.     {
  102.         return $this->id;
  103.     }
  104.     public function getName(): ?string
  105.     {
  106.         return $this->name;
  107.     }
  108.     public function setName(string $name): self
  109.     {
  110.         $this->name $name;
  111.         return $this;
  112.     }
  113.     public function getStartdate(): ?\DateTimeInterface
  114.     {
  115.         return $this->startdate;
  116.     }
  117.     public function setStartdate(\DateTimeInterface $startdate): self
  118.     {
  119.         $this->startdate $startdate;
  120.         return $this;
  121.     }
  122.     public function getEnddate(): ?\DateTimeInterface
  123.     {
  124.         return $this->enddate;
  125.     }
  126.     public function setEnddate(\DateTimeInterface $enddate): self
  127.     {
  128.         $this->enddate $enddate;
  129.         return $this;
  130.     }
  131.     public function getLocation(): ?string
  132.     {
  133.         return $this->location;
  134.     }
  135.     public function setLocation(string $location): self
  136.     {
  137.         $this->location $location;
  138.         return $this;
  139.     }
  140.     public function getFestival(): ?BFFestival
  141.     {
  142.         return $this->festival;
  143.     }
  144.     public function setFestival(?BFFestival $festival): self
  145.     {
  146.         $this->festival $festival;
  147.         return $this;
  148.     }
  149.     /**
  150.      * @return Collection|BFTournoi[]
  151.      */
  152.     public function getTournois(): Collection
  153.     {
  154.         return $this->tournois;
  155.     }
  156.     public function addTournois(BFTournoi $tournois): self
  157.     {
  158.         if (!$this->tournois->contains($tournois)) {
  159.             $this->$tournois[] = $tournois;
  160.             $tournois->setEditionid($this);
  161.         }
  162.         return $this;
  163.     }
  164.     public function removeTournois(BFTournoi $tournois): self
  165.     {
  166.         if ($this->bftournois->contains($tournois)) {
  167.             $this->bftournois->removeElement($tournois);
  168.             // set the owning side to null (unless already changed)
  169.             if ($tournois->getEditionid() === $this) {
  170.                 $tournois->setEditionid(null);
  171.             }
  172.         }
  173.         return $this;
  174.     }
  175.     public function getDescription(): ?BFDescriptionEdition
  176.     {
  177.         return $this->description;
  178.     }
  179.     public function setDescription(BFDescriptionEdition $description): self
  180.     {
  181.         $this->description $description;
  182.         return $this;
  183.     }
  184.     public function getIsactive(): ?bool
  185.     {
  186.         return $this->isactive;
  187.     }
  188.     public function setIsactive(bool $isactive): self
  189.     {
  190.         $this->isactive $isactive;
  191.         return $this;
  192.     }
  193.     
  194.     public function getCountdays()
  195.     {
  196.         $interval date_diff($this->enddate$this->startdate);
  197.     
  198.          return $interval->format('%a')+1
  199.     }
  200.     
  201.     public function getCounttournois()
  202.     {
  203.         return count($this->tournois);
  204.     }
  205.     public function getPlaceid(): ?string
  206.     {
  207.         return $this->placeid;
  208.     }
  209.     public function setPlaceid(?string $placeid): self
  210.     {
  211.         $this->placeid $placeid;
  212.         return $this;
  213.     }
  214.     public function getLocationhidden(): ?string
  215.     {
  216.         return $this->locationhidden;
  217.     }
  218.     public function setLocationhidden(?string $locationhidden): self
  219.     {
  220.         $this->locationhidden $locationhidden;
  221.         return $this;
  222.     }
  223.     
  224.     public function getDistance()
  225.     {
  226.         return $this->distance;
  227.     }
  228.     public function setDistance($distance): self
  229.     {
  230.         $this->distance $distance;
  231.         return $this;
  232.     }
  233.     
  234.     public function CleanLocation()
  235.     {
  236.         if($this->location != $this->locationhidden)
  237.         {
  238.             $this->locationhidden null;
  239.             $this->placeid=null;
  240.         }
  241.     }
  242.     /**
  243.      * @return Collection|BFAdminLicences[]
  244.      */
  245.     public function getBFAdminLicences(): Collection
  246.     {
  247.         return $this->BFAdminLicences;
  248.     }
  249.     public function addBFAdminLicence(BFAdminLicences $bFAdminLicence): self
  250.     {
  251.         if (!$this->BFAdminLicences->contains($bFAdminLicence)) {
  252.             $this->BFAdminLicences[] = $bFAdminLicence;
  253.             $bFAdminLicence->setEdition($this);
  254.         }
  255.         return $this;
  256.     }
  257.     public function removeBFAdminLicence(BFAdminLicences $bFAdminLicence): self
  258.     {
  259.         if ($this->BFAdminLicences->contains($bFAdminLicence)) {
  260.             $this->BFAdminLicences->removeElement($bFAdminLicence);
  261.             // set the owning side to null (unless already changed)
  262.             if ($bFAdminLicence->getEdition() === $this) {
  263.                 $bFAdminLicence->setEdition(null);
  264.             }
  265.         }
  266.         return $this;
  267.     }
  268.     public function getRoute(): ?BFRouting
  269.     {
  270.         return $this->route;
  271.     }
  272.     public function setRoute(?BFRouting $route): self
  273.     {
  274.         $this->route $route;
  275.         // set (or unset) the owning side of the relation if necessary
  276.         $newEdition null === $route null $this;
  277.         if ($route->getEdition() !== $newEdition) {
  278.             $route->setEdition($newEdition);
  279.         }
  280.         return $this;
  281.     }
  282.     
  283.     /**
  284.      * @Assert\IsTrue(message="Les dates ne sont pas valides")
  285.      */
  286.     public function isDatesValid()
  287.     {
  288.         return $this->startdate<=$this->enddate;
  289.     }
  290.     public function getCreationdate(): ?\DateTimeInterface
  291.     {
  292.         return $this->creationdate;
  293.     }
  294.     public function setCreationdate(?\DateTimeInterface $creationdate): self
  295.     {
  296.         $this->creationdate $creationdate;
  297.         return $this;
  298.     }
  299.     /**
  300.      * @return Collection|BFChallengeEdition[]
  301.      */
  302.     public function getChallengeeditions(): Collection
  303.     {
  304.         return $this->challengeeditions;
  305.     }
  306.     
  307.     public function getChallengeeditionsactive(): Collection
  308.     {
  309.         $collection$this->challengeeditions;
  310.         
  311.         $returncollection = new ArrayCollection();
  312.         
  313.         foreach($collection as $edition)
  314.         {
  315.             if($edition->getIsactive())
  316.                 $returncollection->add($edition);
  317.         }
  318.         
  319.         return $returncollection;
  320.     }
  321.     
  322.     public function addChallengeedition(BFChallengeEdition $challengeedition): self
  323.     {
  324.         if (!$this->challengeeditions->contains($challengeedition)) {
  325.             $this->challengeeditions[] = $challengeedition;
  326.             $challengeedition->addEdition($this);
  327.         }
  328.         return $this;
  329.     }
  330.     public function removeChallengeedition(BFChallengeEdition $challengeedition): self
  331.     {
  332.         if ($this->challengeeditions->contains($challengeedition)) {
  333.             $this->challengeeditions->removeElement($challengeedition);
  334.             $challengeedition->removeEdition($this);
  335.         }
  336.         return $this;
  337.     }
  338.     
  339.     public function getHaschallengeeditions()
  340.     {
  341.         return (count($this->getChallengeeditions())>0);
  342.     }
  343.     
  344.     public function getHaschallengeeditionsactive()
  345.     {
  346.         $return false;
  347.         if(count($this->getChallengeeditions())>0)
  348.         {
  349.             foreach($this->getChallengeeditions() as $challengeedition)
  350.             {
  351.                 if($challengeedition->getIsactive())
  352.                 {
  353.                     $return=true;
  354.                     break;
  355.                 }
  356.                 
  357.             }
  358.         }
  359.             
  360.         return $return;
  361.     }
  362.     /**
  363.      * @return Collection|BFProductEdition[]
  364.      */
  365.     public function getBfproducteditions(): Collection
  366.     {
  367.         $collection $this->bfproducteditions;
  368.         $iterator $collection->getIterator();
  369.         $iterator->uasort(function ($a$b) {
  370.             if($a->getTournois()->count()!=$b->getTournois()->count())
  371.             {
  372.                 return ($a->getTournois()->count()<$b->getTournois()->count()) ? : -1;
  373.             }
  374.             
  375.             if($a->getTournois()->count()>&& $b->getTournois()->count() >0)
  376.             {
  377.                 return ($a->getTournois()->first()->getStartdate()>$b->getTournois()->first()->getStartdate())? 1:-1;
  378.             }
  379.             
  380.             if($a->getPrice() != $b->getPrice())
  381.             {
  382.                 return ($a->getPrice()> $b->getPrice()) ? 1:-1;
  383.             }
  384.             
  385.             return ($a->getId() > $b->getId()) ? : -1;
  386.         });
  387.         
  388.         $sortedcollection = new ArrayCollection(iterator_to_array($iterator));
  389.         
  390.         return $sortedcollection;
  391.     }
  392.     public function addBfproductedition(BFProductEdition $bfproductedition): self
  393.     {
  394.         if (!$this->bfproducteditions->contains($bfproductedition)) {
  395.             $this->bfproducteditions[] = $bfproductedition;
  396.             $bfproductedition->setEdition($this);
  397.         }
  398.         return $this;
  399.     }
  400.     public function removeBfproductedition(BFProductEdition $bfproductedition): self
  401.     {
  402.         if ($this->bfproducteditions->contains($bfproductedition)) {
  403.             $this->bfproducteditions->removeElement($bfproductedition);
  404.             // set the owning side to null (unless already changed)
  405.             if ($bfproductedition->getEdition() === $this) {
  406.                 $bfproductedition->setEdition(null);
  407.             }
  408.         }
  409.         return $this;
  410.     }
  411.     /**
  412.      * @return Collection|BFPaymentIntentEdition[]
  413.      */
  414.     public function getBFPaymentIntentEditions(): Collection
  415.     {
  416.         return $this->bFPaymentIntentEditions;
  417.     }
  418.     public function addBFPaymentIntentEdition(BFPaymentIntentEdition $bFPaymentIntentEdition): self
  419.     {
  420.         if (!$this->bFPaymentIntentEditions->contains($bFPaymentIntentEdition)) {
  421.             $this->bFPaymentIntentEditions[] = $bFPaymentIntentEdition;
  422.             $bFPaymentIntentEdition->setEdition($this);
  423.         }
  424.         return $this;
  425.     }
  426.     public function removeBFPaymentIntentEdition(BFPaymentIntentEdition $bFPaymentIntentEdition): self
  427.     {
  428.         if ($this->bFPaymentIntentEditions->contains($bFPaymentIntentEdition)) {
  429.             $this->bFPaymentIntentEditions->removeElement($bFPaymentIntentEdition);
  430.             // set the owning side to null (unless already changed)
  431.             if ($bFPaymentIntentEdition->getEdition() === $this) {
  432.                 $bFPaymentIntentEdition->setEdition(null);
  433.             }
  434.         }
  435.         return $this;
  436.     }
  437.     
  438.     /**
  439.      * @return Collection|BFPaymentIntentEdition[]
  440.      */
  441.     public function getBFPaymentIntentEditionsvalid(): Collection
  442.     {
  443.         $returncollection = new ArrayCollection();
  444.         foreach($this->getBFPaymentIntentEditions() as $bfpaymentintent)
  445.         {
  446.             if($bfpaymentintent->getSuccessdate()!=null)
  447.                 $returncollection->add($bfpaymentintent);
  448.         }
  449.         return $returncollection;
  450.     }
  451. }