src/Entity/VisioEvent.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\VisioEventRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\Common\Collections\Criteria;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Gedmo\Mapping\Annotation as Gedmo;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. /**
  11.  * @ORM\Entity(repositoryClass=VisioEventRepository::class)
  12.  * @ORM\HasLifecycleCallbacks()
  13.  */
  14. class VisioEvent
  15. {
  16.     const STATUS_VALID 'valid'//event is valid but no one is registered
  17.     const STATUS_REGISTERED 'registered'//event is valid and registered
  18.     const STATUS_CANCELLED 'cancelled'//event has been cancelled no more applications
  19.     const STATUSES = [
  20.         self::STATUS_VALID,
  21.         self::STATUS_REGISTERED,
  22.         self::STATUS_CANCELLED,
  23.     ];
  24.     /**
  25.      * @ORM\Id
  26.      * @ORM\GeneratedValue
  27.      * @ORM\Column(type="integer")
  28.      */
  29.     private $id;
  30.     /**
  31.      * @ORM\Column(type="string", length=255)
  32.      * @Assert\NotBlank
  33.      */
  34.     private $name;
  35.     /**
  36.      * @ORM\Column(type="string", length=255, nullable=true)
  37.      * @var string|null
  38.      */
  39.     private $link;
  40.     /**
  41.      * @var string|null
  42.      * @ORM\Column(type="string", length=255)
  43.      */
  44.     private $status self::STATUS_VALID;
  45.     /**
  46.      * @ORM\Column(type="text", nullable=true)
  47.      */
  48.     private $description;
  49.     /**
  50.      * @ORM\Column(type="integer")
  51.      * @Assert\NotBlank
  52.      * @Assert\GreaterThan(value="0")
  53.      */
  54.     private $duration;
  55.     /**
  56.      * @ORM\Column(type="float")
  57.      */
  58.     private $clientPrice 0;
  59.     /**
  60.      * @ORM\Column(type="datetime")
  61.      * @Assert\NotBlank
  62.      * @Assert\LessThan(propertyPath="end")
  63.      */
  64.     private $start;
  65.     /**
  66.      * @ORM\Column(type="datetime")
  67.      * @Assert\NotBlank
  68.      * @Assert\GreaterThan(propertyPath="start")
  69.      */
  70.     private $end;
  71.     /**
  72.      * Cancellation limit for the client in hours
  73.      * @ORM\Column(type="integer", nullable=true)
  74.      * @var integer|null
  75.      */
  76.     private $cancellationLimit 0;
  77.     /**
  78.      * Price with commission accounted for
  79.      * @ORM\Column(type="float")
  80.      */
  81.     private $sellingPrice 0;
  82.     /**
  83.      * @var float|null
  84.      * @ORM\Column(type="float")
  85.      */
  86.     private $visioCommissionPercent 0;
  87.     /**
  88.      * @var float|null
  89.      * @ORM\Column(type="float")
  90.      */
  91.     private $visioCommissionPrice 0;
  92.     /**
  93.      * Price being paid to the specialist
  94.      * @ORM\Column(type="float")
  95.      */
  96.     private $purchasePrice 0;
  97.     /**
  98.      * @ORM\Column(type="float", nullable=true)
  99.      */
  100.     private $tva 0;
  101.     /**
  102.      * @ORM\Column(type="datetime")
  103.      * @Gedmo\Timestampable(on="create")
  104.      */
  105.     private $createdAt;
  106.     /**
  107.      * @ORM\Column(type="datetime", nullable=true)
  108.      * @Gedmo\Timestampable(on="update")
  109.      */
  110.     private $updatedAt;
  111.     /**
  112.      * @ORM\ManyToOne(targetEntity=Specialist::class, inversedBy="visioEvents")
  113.      * @ORM\JoinColumn(nullable=false)
  114.      */
  115.     private $specialist;
  116.     /**
  117.      * @ORM\ManyToOne(targetEntity=Tag::class, inversedBy="visioEvents")
  118.      * @ORM\JoinColumn(nullable=false)
  119.      */
  120.     private $tag;
  121.     /**
  122.      * @ORM\Column(type="boolean", options={"default": 0})
  123.      */
  124.     private $tvaApplicable false;
  125.     /**
  126.      * @ORM\OneToMany(targetEntity=Registration::class, mappedBy="visioEvent")
  127.      */
  128.     private $registrations;
  129.     /**
  130.      * @ORM\OneToMany(targetEntity=Document::class, mappedBy="visioEvent", cascade={"persist"})
  131.      */
  132.     private $documents;
  133.     public function __construct()
  134.     {
  135.         $this->createdAt = new \DateTime();
  136.         $this->registrations = new ArrayCollection();
  137.         $this->documents = new ArrayCollection();
  138.     }
  139.     public function getId(): ?int
  140.     {
  141.         return $this->id;
  142.     }
  143.     public function getName(): ?string
  144.     {
  145.         return $this->name;
  146.     }
  147.     public function setName(string $name): self
  148.     {
  149.         $this->name $name;
  150.         return $this;
  151.     }
  152.     public function getDescription(): ?string
  153.     {
  154.         return $this->description;
  155.     }
  156.     public function setDescription(?string $description): self
  157.     {
  158.         $this->description $description;
  159.         return $this;
  160.     }
  161.     public function getDuration(): ?int
  162.     {
  163.         return $this->duration;
  164.     }
  165.     public function setDuration(int $duration): self
  166.     {
  167.         $this->duration $duration;
  168.         return $this;
  169.     }
  170.     public function getClientPrice(): ?float
  171.     {
  172.         return $this->clientPrice;
  173.     }
  174.     public function setClientPrice(float $clientPrice): self
  175.     {
  176.         $this->clientPrice $clientPrice;
  177.         return $this;
  178.     }
  179.     public function getStart(): ?\DateTimeInterface
  180.     {
  181.         return $this->start;
  182.     }
  183.     public function setStart(\DateTimeInterface $start): self
  184.     {
  185.         $this->start $start;
  186.         return $this;
  187.     }
  188.     public function getEnd(): ?\DateTimeInterface
  189.     {
  190.         return $this->end;
  191.     }
  192.     public function setEnd(\DateTimeInterface $end): self
  193.     {
  194.         $this->end $end;
  195.         return $this;
  196.     }
  197.     public function getSellingPrice(): ?float
  198.     {
  199.         return $this->sellingPrice;
  200.     }
  201.     public function setSellingPrice(float $sellingPrice): self
  202.     {
  203.         $this->sellingPrice $sellingPrice;
  204.         return $this;
  205.     }
  206.     public function getPurchasePrice(): ?float
  207.     {
  208.         return $this->purchasePrice;
  209.     }
  210.     public function setPurchasePrice(float $purchasePrice): self
  211.     {
  212.         $this->purchasePrice $purchasePrice;
  213.         return $this;
  214.     }
  215.     public function getTva(): ?float
  216.     {
  217.         return $this->tva;
  218.     }
  219.     public function setTva(?float $tva): self
  220.     {
  221.         $this->tva $tva;
  222.         return $this;
  223.     }
  224.     public function getCreatedAt(): ?\DateTimeInterface
  225.     {
  226.         return $this->createdAt;
  227.     }
  228.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  229.     {
  230.         $this->createdAt $createdAt;
  231.         return $this;
  232.     }
  233.     public function getUpdatedAt(): ?\DateTimeInterface
  234.     {
  235.         return $this->updatedAt;
  236.     }
  237.     public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  238.     {
  239.         $this->updatedAt $updatedAt;
  240.         return $this;
  241.     }
  242.     public function getSpecialist(): ?Specialist
  243.     {
  244.         return $this->specialist;
  245.     }
  246.     public function setSpecialist(?Specialist $specialist): self
  247.     {
  248.         $this->specialist $specialist;
  249.         return $this;
  250.     }
  251.     public function getTag(): ?Tag
  252.     {
  253.         return $this->tag;
  254.     }
  255.     public function setTag(?Tag $tag): self
  256.     {
  257.         $this->tag $tag;
  258.         return $this;
  259.     }
  260.     public function isOpen(): bool
  261.     {
  262.         return empty($this->getRegistration());
  263.     }
  264.     public function getTvaApplicable(): ?bool
  265.     {
  266.         return $this->tvaApplicable;
  267.     }
  268.     public function setTvaApplicable(bool $tvaApplicable): self
  269.     {
  270.         $this->tvaApplicable $tvaApplicable;
  271.         return $this;
  272.     }
  273.     /**
  274.      * Retrieves the current active and valid registration
  275.      * @return Registration|null
  276.      */
  277.     public function getRegistration(): ?Registration
  278.     {
  279.         foreach ($this->registrations as $registration) {
  280.             if ($registration->isVisioValid()){
  281.                 return $registration;
  282.             }
  283.         }
  284.         return null;
  285.     }
  286.     /**
  287.      * @return Collection<int, Registration>
  288.      */
  289.     public function getRegistrations(): Collection
  290.     {
  291.         return $this->registrations;
  292.     }
  293.     public function addRegistration(Registration $registration): self
  294.     {
  295.         if (!$this->registrations->contains($registration)) {
  296.             $this->registrations[] = $registration;
  297.             $registration->setVisioEvent($this);
  298.         }
  299.         return $this;
  300.     }
  301.     public function removeRegistration(Registration $registration): self
  302.     {
  303.         if ($this->registrations->removeElement($registration)) {
  304.             // set the owning side to null (unless already changed)
  305.             if ($registration->getVisioEvent() === $this) {
  306.                 $registration->setVisioEvent(null);
  307.             }
  308.         }
  309.         return $this;
  310.     }
  311.     /**
  312.      * @return Collection<int, Document>
  313.      */
  314.     public function getDocuments(): Collection
  315.     {
  316.         return $this->documents;
  317.     }
  318.     /**
  319.      * @return Collection<int, Document>
  320.      */
  321.     public function getDocumentsOrdered(): Collection
  322.     {
  323.         $criteria Criteria::create()
  324.             ->orderBy(array("created_at" => Criteria::DESC));
  325.         return $this->documents->matching($criteria);
  326.     }
  327.     public function addDocument(Document $document): self
  328.     {
  329.         if (!$this->documents->contains($document)) {
  330.             $this->documents[] = $document;
  331.             $document->setVisioEvent($this);
  332.         }
  333.         return $this;
  334.     }
  335.     public function removeDocument(Document $document): self
  336.     {
  337.         if ($this->documents->removeElement($document)) {
  338.             // set the owning side to null (unless already changed)
  339.             if ($document->getVisioEvent() === $this) {
  340.                 $document->setVisioEvent(null);
  341.             }
  342.         }
  343.         return $this;
  344.     }
  345.     /**
  346.      * @param string|null $status
  347.      * @return VisioEvent
  348.      */
  349.     public function setStatus(?string $status): VisioEvent
  350.     {
  351.         $this->status $status;
  352.         return $this;
  353.     }
  354.     /**
  355.      * @return string|null
  356.      */
  357.     public function getStatus(): ?string
  358.     {
  359.         return $this->status;
  360.     }
  361.     /**
  362.      * @return bool
  363.      */
  364.     public function isCancelled(): bool
  365.     {
  366.         return ($this->status == self::STATUS_CANCELLED);
  367.     }
  368.     /**
  369.      * @param int|null $cancellationLimit
  370.      * @return VisioEvent
  371.      */
  372.     public function setCancellationLimit(?int $cancellationLimit): VisioEvent
  373.     {
  374.         $this->cancellationLimit $cancellationLimit;
  375.         return $this;
  376.     }
  377.     /**
  378.      * @return int|null
  379.      */
  380.     public function getCancellationLimit(): ?int
  381.     {
  382.         return $this->cancellationLimit;
  383.     }
  384.     /**
  385.      * @param string|null $link
  386.      * @return VisioEvent
  387.      */
  388.     public function setLink(?string $link): VisioEvent
  389.     {
  390.         $this->link $link;
  391.         return $this;
  392.     }
  393.     /**
  394.      * @return string|null
  395.      */
  396.     public function getLink(): ?string
  397.     {
  398.         return $this->link;
  399.     }
  400.     /**
  401.      * @param float|null $visioCommissionPercent
  402.      * @return VisioEvent
  403.      */
  404.     public function setVisioCommissionPercent(?float $visioCommissionPercent): VisioEvent
  405.     {
  406.         $this->visioCommissionPercent $visioCommissionPercent;
  407.         return $this;
  408.     }
  409.     /**
  410.      * @param float|null $visioCommissionPrice
  411.      * @return VisioEvent
  412.      */
  413.     public function setVisioCommissionPrice(?float $visioCommissionPrice): VisioEvent
  414.     {
  415.         $this->visioCommissionPrice $visioCommissionPrice;
  416.         return $this;
  417.     }
  418.     /**
  419.      * @return float|null
  420.      */
  421.     public function getVisioCommissionPercent()
  422.     {
  423.         return $this->visioCommissionPercent;
  424.     }
  425.     /**
  426.      * @return float|null
  427.      */
  428.     public function getVisioCommissionPrice()
  429.     {
  430.         return $this->visioCommissionPrice;
  431.     }
  432.     /**
  433.      * Récupère la dernière Registration
  434.      * @return Registration|null
  435.      */
  436.     public function getCurrentRegistration(): ?Registration
  437.     {
  438.         $currentRegistration null;
  439.         if(!empty($this->getRegistrations()->toArray())) {
  440.             foreach ($this->getRegistrations()->toArray() as $key => $registration) {
  441.                 if($currentRegistration instanceof Registration && $registration->getId() > $currentRegistration->getId()) {
  442.                     $currentRegistration $registration;
  443.                 } else $currentRegistration $registration
  444.             }
  445.         }
  446.         return $currentRegistration;
  447.     }
  448.     /**
  449.      * Récupère une inscription valid
  450.      * @return Registration|null
  451.      */
  452.     public function getRegistered(): ?Registration
  453.     {
  454.         foreach ($this->getRegistrations()->toArray() as $key => $registration) {
  455.             if($registration->getStatus() === Registration::STATUS_REGISTER) {
  456.                 return $registration;
  457.             }
  458.         }
  459.         return null;
  460.     }
  461. }