src/Entity/Game.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use DateTime;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use JMS\Serializer\Annotation as Serializer;
  7. use Money\Money;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. /**
  10.  * @ORM\Entity(repositoryClass="App\Entity\Repository\GameRepository")
  11.  * @ORM\Table(name="`match`")
  12.  * @Serializer\ExclusionPolicy("all")
  13.  */
  14. class Game
  15. {
  16.     /**
  17.      * @var int
  18.      * @ORM\Id
  19.      * @ORM\GeneratedValue(strategy="AUTO")
  20.      * @ORM\Column(type="integer")
  21.      * @Serializer\Expose()
  22.      */
  23.     private $id;
  24.     /**
  25.      * @var DateTime
  26.      * @ORM\Column(type="datetime", nullable=true)
  27.      * @Serializer\Expose()
  28.      */
  29.     #[Assert\NotBlank]
  30.     private $date;
  31.     /**
  32.      * Many Matches have One homeClub.
  33.      *
  34.      * @var Club|null
  35.      *
  36.      * @ORM\ManyToOne(targetEntity="Club", inversedBy="homematches")
  37.      * @Serializer\Expose()
  38.      */
  39.     private $homeClub;
  40.     /**
  41.      * Many Matches have One awayClub.
  42.      *
  43.      * @var Club|null
  44.      *
  45.      * @ORM\ManyToOne(targetEntity="Club")
  46.      * @Serializer\Expose()
  47.      */
  48.     private $awayClub;
  49.     /**
  50.      * Many Matches have One matchCountry.
  51.      *
  52.      * @var Country|null
  53.      *
  54.      * @ORM\ManyToOne(targetEntity="Country")
  55.      */
  56.     private $matchCountry;
  57.     /**
  58.      * Many Matches have One Competition.
  59.      *
  60.      * @var Competition|null
  61.      *
  62.      * @ORM\ManyToOne(targetEntity="Competition", inversedBy="matches")
  63.      * @Serializer\Expose()
  64.      * @Serializer\Type("App\Entity\Competition")
  65.      */
  66.     private $competition;
  67.     /**
  68.      * Many Matches have One Stadium.
  69.      *
  70.      * @var Stadium|null
  71.      *
  72.      * @ORM\ManyToOne(targetEntity="Stadium")
  73.      * @Serializer\Expose()
  74.      */
  75.     private $stadium;
  76.     /**
  77.      * @var Money|null
  78.      * @ORM\Column(name="cheapest_accommodation", type="money", nullable=true)
  79.      * @Serializer\Type("Money\Money")
  80.      */
  81.     private $cheapestAccommodation;
  82.     /**
  83.      * @var Money|null
  84.      * @ORM\Column(name="match_ticket_price", type="money", nullable=true)
  85.      */
  86.     private $matchTicketPrice;
  87.     /**
  88.      * @var Money|null
  89.      * @ORM\Column(name="match_ticket_price_base", type="money", nullable=true)
  90.      */
  91.     private $matchTicketPriceBase;
  92.     /**
  93.      * One Match have Many GameCategories.
  94.      *
  95.      * @var GameCategory[]|ArrayCollection
  96.      *
  97.      * @ORM\OneToMany(targetEntity="GameCategory", mappedBy="match", orphanRemoval=true, cascade={"persist", "remove"})
  98.      */
  99.     private $categories;
  100.     /**
  101.      * @var bool
  102.      * @ORM\Column(type="boolean")
  103.      * @Serializer\Expose()
  104.      */
  105.     private $final false;
  106.     /**
  107.      * @var bool
  108.      * @ORM\Column(type="boolean")
  109.      */
  110.     private $offer false;
  111.     /**
  112.      * @var bool
  113.      * @ORM\Column(type="boolean")
  114.      */
  115.     private $popular false;
  116.     /**
  117.      * @var bool
  118.      * @ORM\Column(type="boolean")
  119.      * @Serializer\Expose()
  120.      */
  121.     private $hasFlight true;
  122.     /**
  123.      * @var bool
  124.      * @ORM\Column(type="boolean")
  125.      * @Serializer\Expose()
  126.      */
  127.     private $disableBooking false;
  128.     /**
  129.      * @var bool
  130.      * @ORM\Column(type="boolean")
  131.      * @Serializer\Expose()
  132.      */
  133.     private $firstOfMonth false;
  134.     /**
  135.      * @var DateTime
  136.      * @ORM\Column(type="datetime", nullable=true)
  137.      * @Serializer\Expose()
  138.      */
  139.     private $lastSyncDate;
  140.     /**
  141.      * @var int
  142.      * @ORM\Column(type="integer", nullable=true)
  143.      */
  144.     private $syncTime;
  145.     /**
  146.      * @var int
  147.      * @ORM\Column(type="integer", nullable=true)
  148.      */
  149.     private $syncStatus;
  150.     /**
  151.      * @var string
  152.      *
  153.      * @ORM\Column(type="string", length=255, nullable=true)
  154.      */
  155.     private $syncMessage;
  156.     /**
  157.      * Match constructor.
  158.      */
  159.     public function __construct()
  160.     {
  161.         $this->categories = new ArrayCollection();
  162.     }
  163.     /**
  164.      * @return int
  165.      */
  166.     public function getId(): ?int
  167.     {
  168.         return $this->id;
  169.     }
  170.     /**
  171.      * @return DateTime
  172.      */
  173.     public function getDate(): ?DateTime
  174.     {
  175.         return $this->date;
  176.     }
  177.     /**
  178.      * @param DateTime $date
  179.      */
  180.     public function setDate(?DateTime $date): self
  181.     {
  182.         $this->date $date;
  183.         return $this;
  184.     }
  185.     public function getHomeClub(): ?Club
  186.     {
  187.         return $this->homeClub;
  188.     }
  189.     public function setHomeClub(?Club $homeClub): self
  190.     {
  191.         $this->homeClub $homeClub;
  192.         return $this;
  193.     }
  194.     public function getAwayClub(): ?Club
  195.     {
  196.         return $this->awayClub;
  197.     }
  198.     public function setAwayClub(?Club $awayClub): self
  199.     {
  200.         $this->awayClub $awayClub;
  201.         return $this;
  202.     }
  203.     public function getMatchCountry(): ?Country
  204.     {
  205.         return $this->matchCountry;
  206.     }
  207.     public function setMatchCountry(?Country $matchCountry): self
  208.     {
  209.         $this->matchCountry $matchCountry;
  210.         return $this;
  211.     }
  212.     public function getCompetition(): ?Competition
  213.     {
  214.         return $this->competition;
  215.     }
  216.     public function setCompetition(?Competition $competition): self
  217.     {
  218.         $this->competition $competition;
  219.         return $this;
  220.     }
  221.     public function getStadium(): ?Stadium
  222.     {
  223.         return $this->stadium;
  224.     }
  225.     public function setStadium(?Stadium $stadium): self
  226.     {
  227.         $this->stadium $stadium;
  228.         return $this;
  229.     }
  230.     public function getCheapestAccommodation(): ?Money
  231.     {
  232.         return $this->cheapestAccommodation;
  233.     }
  234.     public function calculateCheapestAccommodation(): ?Money
  235.     {
  236.         $clone $this->cheapestAccommodation;
  237.         if (!$this->isFinal() && null !== $clone) {
  238.             return $clone->multiply(2);
  239.         }
  240.         return $clone;
  241.     }
  242.     public function setCheapestAccommodation(?Money $cheapestAccommodation): self
  243.     {
  244.         $this->cheapestAccommodation $cheapestAccommodation;
  245.         return $this;
  246.     }
  247.     public function getMatchTicketPrice(): ?Money
  248.     {
  249.         return $this->matchTicketPrice;
  250.     }
  251.     public function setMatchTicketPrice(?Money $matchTicketPrice): self
  252.     {
  253.         $this->matchTicketPrice $matchTicketPrice;
  254.         return $this;
  255.     }
  256.     public function getMatchTicketPriceBase(): ?Money
  257.     {
  258.         return $this->matchTicketPriceBase;
  259.     }
  260.     public function setMatchTicketPriceBase(?Money $matchTicketPriceBase): self
  261.     {
  262.         $this->matchTicketPriceBase $matchTicketPriceBase;
  263.         return $this;
  264.     }
  265.     /**
  266.      * @return GameCategory[]|ArrayCollection
  267.      */
  268.     public function getCategories()
  269.     {
  270.         return $this->categories;
  271.     }
  272.     /**
  273.      * @return $this
  274.      */
  275.     public function addCategory(GameCategory $category): self
  276.     {
  277.         if ($this->categories->contains($category)) {
  278.             return $this;
  279.         }
  280.         $this->categories->add($category);
  281.         $category->setMatch($this);
  282.         return $this;
  283.     }
  284.     /**
  285.      * @return $this
  286.      */
  287.     public function removeCategory(GameCategory $category): self
  288.     {
  289.         if (!$this->categories->contains($category)) {
  290.             return $this;
  291.         }
  292.         $this->categories->removeElement($category);
  293.         return $this;
  294.     }
  295.     public function removeCategories()
  296.     {
  297.         $this->categories->clear();
  298.     }
  299.     public function isFinal(): bool
  300.     {
  301.         return $this->final;
  302.     }
  303.     public function setFinal(bool $final): self
  304.     {
  305.         $this->final $final;
  306.         return $this;
  307.     }
  308.     public function isOffer(): bool
  309.     {
  310.         return $this->offer;
  311.     }
  312.     public function setOffer(bool $offer): self
  313.     {
  314.         $this->offer $offer;
  315.         return $this;
  316.     }
  317.     public function isPopular(): bool
  318.     {
  319.         return $this->popular;
  320.     }
  321.     public function setPopular(bool $popular): self
  322.     {
  323.         $this->popular $popular;
  324.         return $this;
  325.     }
  326.     /**
  327.      * @Serializer\VirtualProperty()
  328.      */
  329.     public function getPrice(): ?Money
  330.     {
  331.         $price $this->matchTicketPrice;
  332.         if ($price && $this->cheapestAccommodation) {
  333.             if(!$this->isFinal() && !in_array($this->getStadium()->getCountry()->getSlug(),['duitsland''frankrijk''denemarken'])) {
  334.                 $priceForExtraDay ceil($this->getCheapestAccommodation()->multiply(0.7,Money::ROUND_UP)->getAmount()/100)*100;
  335.                 $price $price->add(Money::EUR($priceForExtraDay));
  336.             }
  337.             $price $price->add($this->getCheapestAccommodation());
  338.         }
  339.         return $price;
  340.     }
  341.     public function isHasFlight(): bool
  342.     {
  343.         return $this->hasFlight;
  344.     }
  345.     public function setHasFlight(bool $hasFlight): self
  346.     {
  347.         $this->hasFlight $hasFlight;
  348.         return $this;
  349.     }
  350.     public function isDisableBooking(): bool
  351.     {
  352.         return $this->disableBooking;
  353.     }
  354.     public function setDisableBooking(bool $disableBooking): self
  355.     {
  356.         $this->disableBooking $disableBooking;
  357.         return $this;
  358.     }
  359.     public function setFirstOfMonth(bool $firstOfMonth): self
  360.     {
  361.         $this->firstOfMonth $firstOfMonth;
  362.         return $this;
  363.     }
  364.     public function isFirstOfMonth(): bool
  365.     {
  366.         return $this->firstOfMonth;
  367.     }
  368.     /**
  369.      * @return DateTime
  370.      */
  371.     public function getLastSyncDate(): ?DateTime
  372.     {
  373.         return $this->lastSyncDate;
  374.     }
  375.     /**
  376.      * @param DateTime $lastSyncDate
  377.      */
  378.     public function setLastSyncDate(?DateTime $lastSyncDate): self
  379.     {
  380.         $this->lastSyncDate $lastSyncDate;
  381.         return $this;
  382.     }
  383.     /**
  384.      * @return int
  385.      */
  386.     public function getSyncTime(): ?int
  387.     {
  388.         return $this->syncTime;
  389.     }
  390.     /**
  391.      * @param int $syncTime
  392.      */
  393.     public function setSyncTime(int $syncTime): self
  394.     {
  395.         $this->syncTime $syncTime;
  396.         return $this;
  397.     }
  398.     /**
  399.      * @return int
  400.      */
  401.     public function getSyncStatus(): ?int
  402.     {
  403.         return $this->syncStatus;
  404.     }
  405.     /**
  406.      * @param int $syncStatus
  407.      */
  408.     public function setSyncStatus(int $syncStatus): self
  409.     {
  410.         $this->syncStatus $syncStatus;
  411.         return $this;
  412.     }
  413.     /**
  414.      * @return string
  415.      */
  416.     public function getSyncMessage(): ?string
  417.     {
  418.         return $this->syncMessage;
  419.     }
  420.     /**
  421.      * @param string $syncMessage
  422.      */
  423.     public function setSyncMessage(string $syncMessage): self
  424.     {
  425.         $this->syncMessage $syncMessage;
  426.         return $this;
  427.     }
  428.     public function getMatchFormattedTitle(): string
  429.     {
  430.         return sprintf(
  431.             '%s - %s in %s, %s',
  432.             $this->homeClub->getName(),
  433.             $this->awayClub->getName(),
  434.             $this->stadium->getName(),
  435.             $this->date->format('d-m-Y')
  436.         );
  437.     }
  438.     public function __clone()
  439.     {
  440.         $this->categories = new ArrayCollection();
  441.     }
  442. }