src/Entity/Event.php line 62

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Validator as CustomAssert;
  4. use ApiPlatform\Core\Annotation\ApiFilter;
  5. use ApiPlatform\Core\Annotation\ApiProperty;
  6. use ApiPlatform\Core\Annotation\ApiResource;
  7. use ApiPlatform\Core\Annotation\ApiSubresource;
  8. use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
  9. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter;
  10. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  11. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  12. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\ExistsFilter;
  13. use App\Repository\EventRepository;
  14. use Doctrine\Common\Collections\ArrayCollection;
  15. use Doctrine\Common\Collections\Collection;
  16. use Doctrine\ORM\Mapping as ORM;
  17. use Gedmo\Mapping\Annotation as Gedmo;
  18. use Symfony\Component\Serializer\Annotation\Groups;
  19. use Symfony\Component\Validator\Constraints as Assert;
  20. /**
  21.  * @ApiResource(
  22.  *      normalizationContext={
  23.  *          "groups"={"event:read"}
  24.  *      },
  25.  *      denormalizationContext={
  26.  *          "groups"={"event:write"}
  27.  *      },
  28.  *      collectionOperations={
  29.  *          "get"={
  30.  *              "security"="is_granted('ROLE_USER')"
  31.  *          }
  32.  *     },
  33.  *     itemOperations={
  34.  *          "get"={
  35.  *              "security"="is_granted('ROLE_USER')"
  36.  *          }
  37.  *      }
  38.  * )
  39.  * @ApiFilter(DateFilter::class)
  40.  * @ApiFilter(SearchFilter::class, 
  41.  *      strategy="exact", 
  42.  *      properties={
  43.  *          "name":"partial", "status", "company", "isVirtual", "active",
  44.  *          "registrations.status", "registrations.client"
  45.  *      }
  46.  * )
  47.  * @ApiFilter(OrderFilter::class)
  48.  * @ApiFilter(ExistsFilter::class, properties={"parent"})
  49.  * @ApiFilter(PropertyFilter::class, 
  50.  *      arguments={
  51.  *          "parameterName"="fields", 
  52.  *          "overrideDefaultProperties"=true
  53.  *     }
  54.  * )
  55.  * @ORM\Entity(repositoryClass=EventRepository::class)
  56.  * 
  57.  * @CustomAssert\EventClass
  58.  */
  59. class Event
  60. {
  61.     const STATUS_OPEN 'open'// the event is open to acquire a specialist
  62.     const STATUS_PENDING_SPECIALIST 'pending_specialist_validation'// the event is open to acquire a specialist
  63.     const STATUS_VALID 'valid'// the event has a specialist
  64.     const STATUS_CANCELED 'canceled'// the event is canceled
  65.     const STATUS_FINISHED 'finished'// the event is finished
  66.     const STATUS_CANCELED_MAIL 'canceled_mail'// the event is canceled and send mails
  67.     const STATUS_FINISHED_MAIL 'finished_mail'// the event is finished and send mails
  68.     // CALENDAR TYPE
  69.     const  CALENDAR_TYPE_MONTHLY "monthly";
  70.     const  CALENDAR_TYPE_WEEKLY "weekly";
  71.     const  CALENDAR_TYPE_DAILY "daily";
  72.     const CALENDAR_TYPES = [
  73.         self::CALENDAR_TYPE_MONTHLY,
  74.         self::CALENDAR_TYPE_WEEKLY,
  75.         self::CALENDAR_TYPE_DAILY,
  76.     ];
  77.     /**
  78.      * Available statuses for the event
  79.      */
  80.     const STATUSES = [
  81.         self::STATUS_OPEN,
  82.         self::STATUS_VALID,
  83.         self::STATUS_CANCELED,
  84.         self::STATUS_FINISHED,
  85.         self::STATUS_CANCELED_MAIL,
  86.         self::STATUS_FINISHED_MAIL,
  87.     ];
  88.     const STATUSES_CLOSED = [
  89.         self::STATUS_CANCELED,
  90.         self::STATUS_FINISHED,
  91.     ];
  92.     const STATUSES_MAILER = [
  93.         self::STATUS_CANCELED => self::STATUS_CANCELED_MAIL,
  94.         self::STATUS_FINISHED => self::STATUS_FINISHED_MAIL,
  95.     ];
  96.     /**
  97.      * @ORM\Id
  98.      * @ORM\GeneratedValue
  99.      * @ORM\Column(type="integer")
  100.      * @ApiProperty(identifier=true)
  101.      * @Groups({"event:read", "event:read:id", "registration:read"})
  102.      */
  103.     private $id;
  104.     /**
  105.      * @ORM\Column(type="string", length=255)
  106.      * @Groups({"event:read", "event:read:name", "event:write", "registration:read"})
  107.      * @Assert\NotBlank
  108.      */
  109.     private $name;
  110.     /**
  111.      * @ORM\Column(type="text")
  112.      * @Groups({"event:read", "event:read:description", "event:write", "registration:read"})
  113.      * @Assert\NotBlank
  114.      */
  115.     private $description;
  116.     /**
  117.      * @ORM\Column(type="integer")
  118.      * @Groups({"event:read", "event:read:duration", "event:write", "registration:read"})
  119.      * @Assert\NotBlank
  120.      */
  121.     private $duration;
  122.     /**
  123.      * @ORM\Column(type="integer")
  124.      * @Groups({"event:read", "event:read:capacity", "event:write", "registration:read"})
  125.      * @Assert\NotBlank
  126.      */
  127.     private $capacity;
  128.     /**
  129.      * @ORM\Column(type="float")
  130.      * @Groups({"event:read", "event:read:price", "event:write", "registration:read"})
  131.      */
  132.     private $price 0;
  133.     /**
  134.      * @ORM\Column(type="datetime")
  135.      * @Groups({"event:read", "event:read:start", "event:write", "registration:read"})
  136.      * @Assert\NotBlank
  137.      */
  138.     private $start;
  139.     /**
  140.      * @ORM\Column(type="datetime")
  141.      * @Groups({"event:read", "event:read:end", "event:write", "registration:read"})
  142.      * @Assert\NotBlank
  143.      */
  144.     private $end;
  145.     /**
  146.      * @ORM\Column(type="float", nullable=true)
  147.      * @Groups({"event:read", "event:read:sellingPrice", "event:write", "registration:read"})
  148.      */
  149.     private $sellingPrice;
  150.     /**
  151.      * @ORM\Column(type="float", nullable=true)
  152.      * @Groups({"event:read", "event:read:purchasePrice", "event:write"})
  153.      */
  154.     private $purchasePrice;
  155.     /**
  156.      * @ORM\Column(type="float", nullable=true)
  157.      * @Groups({"event:read", "event:read:tva", "event:write"})
  158.      */
  159.     private $tva;
  160.     /**
  161.      * @ORM\Column(type="datetime")
  162.      * @Gedmo\Timestampable(on="create")
  163.      * @Groups({"event:read", "event:read:createdAt", "event:write"})
  164.      */
  165.     private $createdAt;
  166.     /**
  167.      * @ORM\Column(type="datetime", options={"default": "CURRENT_TIMESTAMP"})
  168.      * @Gedmo\Timestampable(on="update")
  169.      * @Groups({"event:read", "event:read:updatedAt", "event:write"})
  170.      */
  171.     private $updatedAt;
  172.     /**
  173.      * @ORM\ManyToOne(targetEntity=Event::class, inversedBy="children")
  174.      * @Groups({"event:read", "event:read:parent", "event:write"})
  175.      */
  176.     private $parent;
  177.     /**
  178.      * @ORM\OneToMany(targetEntity=Event::class, mappedBy="parent", cascade={"all"})
  179.      * @Groups({"event:read", "event:read:children", "event:write"})
  180.      */
  181.     private $children;
  182.     /**
  183.      * @ORM\ManyToOne(targetEntity=Workshop::class, inversedBy="events")
  184.      * @ORM\JoinColumn(nullable=false)
  185.      * @Groups({"event:read", "event:read:workshop", "event:write"})
  186.      * @Assert\NotBlank
  187.      */
  188.     private $workshop;
  189.     /**
  190.      * @ORM\ManyToOne(targetEntity=Room::class, inversedBy="events", cascade={"persist"})
  191.      * @Groups({"event:read", "event:read:room", "event:write", "registration:read"})
  192.      */
  193.     private $room;
  194.     /**
  195.      * @ORM\ManyToOne(targetEntity=Specialist::class, inversedBy="events")
  196.      * @Groups({"event:read", "event:read:specialist", "event:write"})
  197.      */
  198.     private $specialist;
  199.     /**
  200.      * @var Collection|Registration[]
  201.      * @ORM\OneToMany(targetEntity=Registration::class, mappedBy="event", orphanRemoval=true)
  202.      * @Groups({"event:read", "event:read:registrations", "event:write"})
  203.      */
  204.     private $registrations;
  205.     /**
  206.      * @ORM\ManyToOne(targetEntity=Company::class, inversedBy="events")
  207.      * @Groups({"event:read", "event:read:company", "event:write"})
  208.      */
  209.     private $company;
  210.     /**
  211.      * @ORM\Column(type="boolean", options={"default": "1"})
  212.      * @Groups({"event:read", "event:read:active", "event:write", "registration:read"})
  213.      */
  214.     private $active true;
  215.     /**
  216.      * @ORM\Column(type="string", length=255)
  217.      * @Groups({"event:read", "event:read:color", "event:write"})
  218.      */
  219.     private $color;
  220.     /**
  221.      * @ORM\OneToMany(targetEntity=SpecialistEventApplication::class, mappedBy="event", orphanRemoval=true)
  222.      * @Groups({"event:read", "event:read:applications", "event:write"})
  223.      */
  224.     private $applications;
  225.     /**
  226.      * @ORM\Column(type="string", length=50)
  227.      * @Groups({"event:read", "event:read:status", "event:write", "registration:read"})
  228.      * @Assert\Choice(choices=self::STATUSES)
  229.      */
  230.     private $status self::STATUS_OPEN;
  231.     /**
  232.      * If the event is locked it means that a company cannot modify the event
  233.      *
  234.      * @ORM\Column(type="boolean", options={"default": "0"})
  235.      * @Groups({"event:read", "event:read:locked", "event:write"})
  236.      */
  237.     private $locked false;
  238.     /**
  239.      * @ORM\OneToOne(targetEntity=CancellationParameters::class, mappedBy="event", cascade={"persist", "remove"})
  240.      * @Groups({"event:read", "event:read:cancellationParameters", "event:write"})
  241.      */
  242.     private $cancellationParameters;
  243.     /**
  244.      * @ORM\Column(type="string", length=255, nullable=true)
  245.      * @Groups({"event:read", "event:read:formLink", "event:write", "registration:read"})
  246.      */
  247.     private $formLink;
  248.     /**
  249.      * @ORM\Column(type="string", length=255, nullable=true)
  250.      * @Groups({"event:read", "event:read:statusMail", "event:write"})
  251.      */
  252.     private $statusMail;
  253.     /**
  254.      * @ORM\Column(type="array", nullable=true)
  255.      */
  256.     private $statusLogs = [];
  257.     /**
  258.      * @ORM\OneToMany(targetEntity=CancelEventApplication::class, mappedBy="event", orphanRemoval=true)
  259.      * @Groups({"event:read", "event:read:cancelEventApplications", "event:write"})
  260.      */
  261.     private $cancelEventApplications;
  262.     /**
  263.      * Will be filled with a unique id if repeated
  264.      * @var string
  265.      * @Groups({"event:read", "event:read:repeated"})
  266.      */
  267.     private $repeated null;
  268.     /**
  269.      * @ORM\Column(type="boolean", options={"default": 0})
  270.      * @Groups({"event:read", "event:read:isVirtual", "event:write", "registration:read"})
  271.      */
  272.     private $isVirtual false;
  273.     /**
  274.      * @ORM\Column(type="string", length=255, nullable=true)
  275.      * @Groups({"event:read", "event:read:virtualUrl", "event:write", "registration:read"})
  276.      */
  277.     private $virtualUrl;
  278.     /**
  279.      * @ORM\Column(type="boolean", nullable=true)
  280.      * @Groups({"event:read", "event:read:isSpecialistTva", "event:write"})
  281.      */
  282.     private $isSpecialistTva;
  283.     /**
  284.      * @ORM\Column(type="string", length=255, nullable=true)
  285.      * @Groups({"event:read", "event:read:updatedBy"})
  286.      */
  287.     private $updatedBy;
  288.     /**
  289.      * @ORM\Column(type="float", nullable=true)
  290.      * @Groups({"event:read", "event:read:coefMajoration", "event:write"})
  291.      */
  292.     private $coefMajoration;
  293.     /**
  294.      * @ORM\Column(type="float", nullable=true)
  295.      * @Groups({"event:read", "event:read:specialistPrice", "event:write"})
  296.      */
  297.     private $specialistPrice;
  298.     /**
  299.      * @ORM\Column(type="float", nullable=true)
  300.      * @Groups({"event:read", "event:read:coefMargin", "event:write"})
  301.      */
  302.     private $coefMargin;
  303.     /**
  304.      * @ORM\OneToMany(targetEntity=AffiliatedEventApplication::class, mappedBy="event", orphanRemoval=true)
  305.      * @Groups({"event:read", "event:read:affiliatedEventApplications", "event:write"})
  306.      */
  307.     private $affiliatedEventApplications;
  308.     /**
  309.      * @ORM\OneToOne(targetEntity=MarketplaceReservation::class, mappedBy="event", cascade={"persist", "remove"})
  310.      * @Groups({"event:read", "event:read:marketplaceReservation"})
  311.      */
  312.     private $marketplaceReservation;
  313.     /**
  314.      * @ORM\Column(type="boolean", options={"default": 0})
  315.      * @Groups({"event:read", "event:read:isMarketplace", "event:write", "registration:read"})
  316.      */
  317.     private $isMarketplace false;
  318.     /**
  319.      * @ORM\Column(type="boolean", options={"default": 0})
  320.      * @Groups({"event:read", "event:read:isFromStats", "event:write", "registration:read"})
  321.      */
  322.     private $isFromStats false;
  323.     /**
  324.      * @ORM\Column(type="text", nullable=true)
  325.      * @Groups({"event:read", "event:read:callsheetComment", "event:write"})
  326.      */
  327.     private $callsheetComment;
  328.     /**
  329.      * @ORM\Column(type="boolean", options={"default": 0})
  330.      * @Groups({"event:read", "event:read:overQuota", "event:write"})
  331.      */
  332.     private $overQuota false;
  333.     /**
  334.      * @ORM\Column(type="string", length=255, nullable=true)
  335.      * @Groups({"event:read", "event:read:overQuotaInfo", "event:write"})
  336.      */
  337.     private $overQuotaInfo;
  338.     /**
  339.      * @ORM\Column(type="boolean", options={"default": 0})
  340.      * @Groups({"event:read", "event:read:waitingListAssignationAuto", "event:write"})
  341.      */
  342.     private $waitingListAssignationAuto false;
  343.     /**
  344.      * @ORM\Column(type="boolean", nullable=true, options={"default": 0})
  345.      * @Groups({"event:read", "event:read:waitingListDefault", "event:write"})
  346.      */
  347.     private $waitingListDefault false;
  348.     /**
  349.      * @ORM\ManyToMany(targetEntity=Segmentation::class, inversedBy="events")
  350.      * @Groups({"event:read", "event:read:segmentations", "event:write"})
  351.      */
  352.     private $segmentations;
  353.     /**
  354.      * @ORM\Column(type="boolean", options={"default": 0})
  355.      * @Groups({"event:read", "event:read:negativeMailSent", "event:write"})
  356.      */
  357.     private $negativeMailSent false;
  358.     /**
  359.      * Inscriptions disponibles restantes
  360.      * @Groups({"event:read", "event:read:remainingAvailableRegistrations", "event:write"})
  361.      */
  362.     private $remainingAvailableRegistrations null;
  363.     /**
  364.      * @Groups({"event:read", "event:read:isRegistered"})
  365.      * @var ?bool
  366.      */
  367.     public $isRegistered null;
  368.     public $sendNotification false;
  369.     /**
  370.      * @Groups({"event:read", "event:read:imageUrl"})
  371.      * @var ?string
  372.      */
  373.     private $imageUrl null;
  374.     public function __construct()
  375.     {
  376.         $this->children = new ArrayCollection();
  377.         $this->registrations = new ArrayCollection();
  378.         $this->applications = new ArrayCollection();
  379.         $this->createdAt = new \DateTime();
  380.         $this->updatedAt = new \DateTime();
  381.         $this->statusLogs = [];
  382.         $this->cancelEventApplications = new ArrayCollection();
  383.         $this->affiliatedEventApplications = new ArrayCollection();
  384.         $this->segmentations = new ArrayCollection();
  385.     }
  386.     public function getId(): ?int
  387.     {
  388.         return $this->id;
  389.     }
  390.     public function getName(): ?string
  391.     {
  392.         return $this->name;
  393.     }
  394.     public function setName(string $name): self
  395.     {
  396.         $this->name $name;
  397.         return $this;
  398.     }
  399.     public function getDescription(): ?string
  400.     {
  401.         return $this->description;
  402.     }
  403.     public function setDescription(string $description): self
  404.     {
  405.         $this->description $description;
  406.         return $this;
  407.     }
  408.     public function getDuration(): ?int
  409.     {
  410.         return $this->duration;
  411.     }
  412.     public function setDuration(int $duration): self
  413.     {
  414.         $this->duration $duration;
  415.         return $this;
  416.     }
  417.     public function getCapacity(): ?int
  418.     {
  419.         return $this->capacity;
  420.     }
  421.     public function setCapacity(int $capacity): self
  422.     {
  423.         $this->capacity $capacity;
  424.         return $this;
  425.     }
  426.     public function getPrice(): ?float
  427.     {
  428.         return $this->price;
  429.     }
  430.     public function setPrice(?float $price): self
  431.     {
  432.         $this->price floatval($price);
  433.         return $this;
  434.     }
  435.     public function getStart(): ?\DateTime
  436.     {
  437.         return $this->start;
  438.     }
  439.     public function setStart(\DateTime $start): self
  440.     {
  441.         $this->start $start;
  442.         return $this;
  443.     }
  444.     public function getEnd(): ?\DateTime
  445.     {
  446.         return $this->end;
  447.     }
  448.     public function setEnd(\DateTime $end): self
  449.     {
  450.         $this->end $end;
  451.         return $this;
  452.     }
  453.     public function getCreatedAt(): ?\DateTime
  454.     {
  455.         return $this->createdAt;
  456.     }
  457.     public function setCreatedAt(\DateTime $createdAt): self
  458.     {
  459.         $this->createdAt $createdAt;
  460.         return $this;
  461.     }
  462.     public function getParent(): ?self
  463.     {
  464.         return $this->parent;
  465.     }
  466.     public function setParent(?self $parent): self
  467.     {
  468.         $this->parent $parent;
  469.         return $this;
  470.     }
  471.     /**
  472.      * @return Collection|self[]
  473.      */
  474.     public function getChildren(): Collection
  475.     {
  476.         return $this->children;
  477.     }
  478.     public function addChild(self $child): self
  479.     {
  480.         if (!$this->children->contains($child)) {
  481.             $this->children[] = $child;
  482.             $child->setParent($this);
  483.         }
  484.         return $this;
  485.     }
  486.     public function removeChild(self $child): self
  487.     {
  488.         if ($this->children->removeElement($child)) {
  489.             // set the owning side to null (unless already changed)
  490.             if ($child->getParent() === $this) {
  491.                 $child->setParent(null);
  492.             }
  493.         }
  494.         return $this;
  495.     }
  496.     public function getWorkshop(): ?Workshop
  497.     {
  498.         return $this->workshop;
  499.     }
  500.     public function setWorkshop(?Workshop $workshop): self
  501.     {
  502.         $this->workshop $workshop;
  503.         if (empty($this->color)) {
  504.             $this->color $workshop->getColor();
  505.         }
  506.         return $this;
  507.     }
  508.     public function getRoom(): ?Room
  509.     {
  510.         return $this->room;
  511.     }
  512.     public function setRoom(?Room $room): self
  513.     {
  514.         $this->room $room;
  515.         $this->setCompany($this->room->getCompany());
  516.         return $this;
  517.     }
  518.     public function getSpecialist(): ?Specialist
  519.     {
  520.         return $this->specialist;
  521.     }
  522.     public function setSpecialist(?Specialist $specialist): self
  523.     {
  524.         $this->specialist $specialist;
  525.         return $this;
  526.     }
  527.     /**
  528.      * @return Collection|Registration[]
  529.      */
  530.     public function getRegistrations(): Collection
  531.     {
  532.         return $this->registrations;
  533.     }
  534.     public function addRegistration(Registration $registration): self
  535.     {
  536.         if (!$this->registrations->contains($registration)) {
  537.             $this->registrations[] = $registration;
  538.             $registration->setEvent($this);
  539.         }
  540.         return $this;
  541.     }
  542.     public function removeRegistration(Registration $registration): self
  543.     {
  544.         if ($this->registrations->removeElement($registration)) {
  545.             // set the owning side to null (unless already changed)
  546.             if ($registration->getEvent() === $this) {
  547.                 $registration->setEvent(null);
  548.             }
  549.         }
  550.         return $this;
  551.     }
  552.     /**
  553.      * Permet de récupérer la derniere Registration d'un Client
  554.      * @var Client $client
  555.      * @return Registration|null
  556.      */
  557.     public function getLastClientRegistration(Client $client): ?Registration
  558.     {
  559.         $lastClientRegistration null;
  560.         if(!empty($this->registrations)) {
  561.             foreach($this->registrations as $registration) {
  562.                 if($registration->getClient() instanceof Client && $registration->getClient()->getId() === $client->getId() 
  563.                     && (empty($lastClientRegistration) || $registration->getCreatedAt() > $lastClientRegistration->getCreatedAt())) {
  564.                     $lastClientRegistration $registration;
  565.                 }
  566.             };
  567.         }
  568.         return $lastClientRegistration;
  569.     }
  570.     /**
  571.      * @param ArrayCollection $children
  572.      * @return Event
  573.      */
  574.     public function setChildren(ArrayCollection $children): Event
  575.     {
  576.         $this->children $children;
  577.         return $this;
  578.     }
  579.     public function getCompany(): ?Company
  580.     {
  581.         return $this->company;
  582.     }
  583.     public function setCompany(?Company $company): self
  584.     {
  585.         $this->company $company;
  586.         return $this;
  587.     }
  588.     public function getActive(): ?bool
  589.     {
  590.         return $this->active;
  591.     }
  592.     public function setActive(bool $active): self
  593.     {
  594.         $this->active $active;
  595.         return $this;
  596.     }
  597.     public function getColor(): ?string
  598.     {
  599.         return $this->color;
  600.     }
  601.     public function setColor(?string $color): self
  602.     {
  603.         if (!empty($color)) {
  604.             $this->color $color;
  605.         }
  606.         return $this;
  607.     }
  608.     /**
  609.      * @return Collection|SpecialistEventApplication[]
  610.      */
  611.     public function getApplications(): Collection
  612.     {
  613.         return $this->applications;
  614.     }
  615.     public function addApplication(SpecialistEventApplication $application): self
  616.     {
  617.         if (!$this->applications->contains($application)) {
  618.             $this->applications[] = $application;
  619.             $application->setEvent($this);
  620.         }
  621.         return $this;
  622.     }
  623.     public function removeApplication(SpecialistEventApplication $application): self
  624.     {
  625.         if ($this->applications->removeElement($application)) {
  626.             // set the owning side to null (unless already changed)
  627.             if ($application->getEvent() === $this) {
  628.                 $application->setEvent(null);
  629.             }
  630.         }
  631.         return $this;
  632.     }
  633.     public function getStatus(): ?string
  634.     {
  635.         return $this->status;
  636.     }
  637.     public function setStatus(string $status): self
  638.     {
  639.         $this->status $status;
  640.         return $this;
  641.     }
  642.     public function getCellColor(): string
  643.     {
  644.         $now = new \DateTime("now", new \DateTimeZone("Europe/Paris"));
  645.         if ($now <= $this->end && $now >= $this->start) {
  646.             $result 'success';
  647.         } elseif ($now >= $this->start) {
  648.             $result 'danger';
  649.         } else {
  650.             $result 'default';
  651.         }
  652.         return $result;
  653.     }
  654.     public function getLocked(): ?bool
  655.     {
  656.         return $this->locked;
  657.     }
  658.     public function setLocked(bool $locked): self
  659.     {
  660.         $this->locked $locked;
  661.         return $this;
  662.     }
  663.     public function getSellingPrice(): ?float
  664.     {
  665.         return $this->sellingPrice;
  666.     }
  667.     public function setSellingPrice(?float $sellingPrice): self
  668.     {
  669.         $this->sellingPrice $sellingPrice;
  670.         return $this;
  671.     }
  672.     public function getPurchasePrice(): ?float
  673.     {
  674.         return $this->purchasePrice;
  675.     }
  676.     public function setPurchasePrice(?float $purchasePrice): self
  677.     {
  678.         $this->purchasePrice $purchasePrice;
  679.         return $this;
  680.     }
  681.     public function getTva(): ?float
  682.     {
  683.         return $this->tva;
  684.     }
  685.     public function setTva(?float $tva): self
  686.     {
  687.         $this->tva $tva;
  688.         return $this;
  689.     }
  690.     public function getUpdatedAt(): ?\DateTimeInterface
  691.     {
  692.         return $this->updatedAt;
  693.     }
  694.     public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  695.     {
  696.         $this->updatedAt $updatedAt;
  697.         return $this;
  698.     }
  699.     public function getCancellationParameters(): ?CancellationParameters
  700.     {
  701.         return $this->cancellationParameters;
  702.     }
  703.     public function setCancellationParameters(?CancellationParameters $cancellationParameters): self
  704.     {
  705.         // unset the owning side of the relation if necessary
  706.         if ($cancellationParameters === null && $this->cancellationParameters !== null) {
  707.             $this->cancellationParameters->setEvent(null);
  708.         }
  709.         // set the owning side of the relation if necessary
  710.         if ($cancellationParameters !== null && $cancellationParameters->getEvent() !== $this) {
  711.             $cancellationParameters->setEvent($this);
  712.         }
  713.         $this->cancellationParameters $cancellationParameters;
  714.         return $this;
  715.     }
  716.     public function getFormLink(): ?string
  717.     {
  718.         return $this->formLink;
  719.     }
  720.     public function setFormLink(string $formLink): self
  721.     {
  722.         $this->formLink $formLink;
  723.         return $this;
  724.     }
  725.     /**
  726.      * Get valid registered participants count
  727.      * @return int
  728.      */
  729.     public function getRegisteredCount(): int
  730.     {
  731.         $cnt 0;
  732.         foreach ($this->registrations as $registration) {
  733.             if ($registration->isRegistered()) $cnt++;
  734.         }
  735.         return $cnt;
  736.     }
  737.     /**
  738.      * Get valid registered participants
  739.      * @return array
  740.      */
  741.     public function getRegistered(): array
  742.     {
  743.         $registered = [];
  744.         foreach ($this->registrations as $registration) {
  745.             if ($registration->isRegistered()) $registered[] = $registration;
  746.         }
  747.         return $registered;
  748.     }
  749.     public function getStatusMail(): ?string
  750.     {
  751.         return $this->statusMail;
  752.     }
  753.     public function setStatusMail(?string $statusMail): self
  754.     {
  755.         $this->statusMail $statusMail;
  756.         return $this;
  757.     }
  758.     public function getStatusLogs(): ?array
  759.     {
  760.         return $this->statusLogs;
  761.     }
  762.     public function setStatusLogs(?array $statusLogs): self
  763.     {
  764.         $this->statusLogs $statusLogs;
  765.         return $this;
  766.     }
  767.     /**
  768.      * @return Collection<int, CancelEventApplication>
  769.      */
  770.     public function getCancelEventApplications(): Collection
  771.     {
  772.         return $this->cancelEventApplications;
  773.     }
  774.     public function addCancelEventApplication(CancelEventApplication $cancelEventApplication): self
  775.     {
  776.         if (!$this->cancelEventApplications->contains($cancelEventApplication)) {
  777.             $this->cancelEventApplications[] = $cancelEventApplication;
  778.             $cancelEventApplication->setEvent($this);
  779.         }
  780.         return $this;
  781.     }
  782.     public function removeCancelEventApplication(CancelEventApplication $cancelEventApplication): self
  783.     {
  784.         if ($this->cancelEventApplications->removeElement($cancelEventApplication)) {
  785.             // set the owning side to null (unless already changed)
  786.             if ($cancelEventApplication->getEvent() === $this) {
  787.                 $cancelEventApplication->setEvent(null);
  788.             }
  789.         }
  790.         return $this;
  791.     }
  792.     
  793.     /**
  794.      * Estime le prix d'achat de l'event en fonction un Specialist
  795.      */
  796.     public function getEstimatedPurchasePrice($specialist): ?int
  797.     {
  798.         $estimatedPrice null;
  799.         // Récupérer la catégorie de l'event
  800.         $tag = ($this->workshop->getTag() instanceof Tag) ? $this->workshop->getTag() : null;
  801.         if($specialist instanceof Specialist) {
  802.             $specialistTags $specialist->getSpecialistTags()->toArray() ?? [];
  803.             foreach ($specialistTags as $specialistTag) {
  804.                 if($specialistTag instanceof SpecialistTag && $specialistTag->getTag() instanceof Tag
  805.                     && $specialistTag->getTag()->getId() == $tag->getId()) {
  806.                     $estimatedPrice $specialistTag->getPrice();
  807.                     break;
  808.                 }
  809.             }
  810.         }
  811.         return $estimatedPrice;
  812.     }
  813.     /**
  814.      * Estime le prix de vente de l'Event en fonction d'un Company
  815.      */
  816.     public function getEstimatedSellingPrice($company): ?int
  817.     {
  818.         $estimatedPrice null;
  819.         if($company instanceof Company) {
  820.         }
  821.         return $estimatedPrice;
  822.     }
  823.     /**
  824.      * @param string|null $repeated
  825.      * @return Event
  826.      */
  827.     public function setRepeated(?string $repeated): Event
  828.     {
  829.         $this->repeated $repeated;
  830.         return $this;
  831.     }
  832.     /**
  833.      * @return string
  834.      */
  835.     public function getRepeated(): ?string
  836.     {
  837.         return $this->repeated;
  838.     }
  839.     public function isEventRepeated(): bool
  840.     {
  841.         return !empty($this->repeated);
  842.     }
  843.     
  844.     public function getIsVirtual(): ?bool
  845.     {
  846.         return $this->isVirtual;
  847.     }
  848.     public function setIsVirtual(bool $isVirtual): self
  849.     {
  850.         $this->isVirtual $isVirtual;
  851.         return $this;
  852.     }
  853.         
  854.     public function getVirtualUrl(): ?string
  855.     {
  856.         return $this->virtualUrl;
  857.     }
  858.     public function setVirtualUrl(?string $virtualUrl): self
  859.     {
  860.         $this->virtualUrl $virtualUrl;
  861.         return $this;
  862.     }
  863.     public function getIsSpecialistTva(): ?bool
  864.     {
  865.         return $this->isSpecialistTva;
  866.     }
  867.     public function setIsSpecialistTva(?bool $isSpecialistTva): self
  868.     {
  869.         $this->isSpecialistTva $isSpecialistTva;
  870.         return $this;
  871.     }
  872.     
  873.     public function getUpdatedBy(): ?string
  874.     {
  875.         return $this->updatedBy;
  876.     }
  877.     public function setUpdatedBy(?string $updatedBy): self
  878.     {
  879.         $this->updatedBy $updatedBy;
  880.         
  881.         return $this;
  882.     }
  883.     /**
  884.      * Permet de savoir si l'Event est gratuit pour les participants
  885.      * @return bool
  886.      */
  887.     public function isFree(): bool
  888.     {
  889.         return ($this->price 0) ? false true;
  890.     }
  891.     /**
  892.      * Permet de savoir si l'Event est en cours
  893.      * @return bool
  894.      */
  895.     public function isInProgress(): bool
  896.     {
  897.         $now = new \DateTime("now");
  898.         return ($now <= $this->end && $now >= $this->start) ? true false;
  899.     }
  900.     /**
  901.      * Permet de savoir si l'Event est passé
  902.      * @return bool
  903.      */
  904.     public function isPast(): bool
  905.     {
  906.         $now = new \DateTime("now");
  907.         return ($now $this->end) ? true false;
  908.     }
  909.     /**
  910.      * Permet de savoir si l'Event est en attente d'un Specialist
  911.      * @return bool
  912.      */
  913.     public function isOpen(): bool
  914.     {
  915.         return ($this->status == $this::STATUS_OPEN) ? true false;
  916.     }
  917.     /**
  918.      * Permet de savoir si l'Event est a un Specialist
  919.      * @return bool
  920.      */
  921.     public function isValid(): bool
  922.     {
  923.         return ($this->status == $this::STATUS_VALID) ? true false;
  924.     }
  925.     /**
  926.      * Permet de savoir si l'Event est annulé
  927.      * @return bool
  928.      */
  929.     public function isCanceled(): bool
  930.     {
  931.         return ($this->status == $this::STATUS_CANCELED) ? true false;
  932.     }
  933.     /**
  934.      * Permet de savoir si une Demande d'annulation est en cours
  935.      * @return bool
  936.      */
  937.     public function isCancelEventApplication(): bool
  938.     {
  939.         foreach($this->cancelEventApplications as $cancelEventApplication) {
  940.             if($cancelEventApplication->getStatus() === CancelEventApplication::STATUS_OPEN) {
  941.                 return true;
  942.             }
  943.         }
  944.         return false;
  945.     }
  946.     /**
  947.      * Permet de récupérer la demande d'annulation en cours
  948.      * @return null|CancelEventApplication
  949.      */
  950.     public function cancelEventApplicationInProgress(): ?CancelEventApplication
  951.     {
  952.         foreach($this->cancelEventApplications as $cancelEventApplication) {
  953.             if($cancelEventApplication->getStatus() === CancelEventApplication::STATUS_OPEN) {
  954.                 return $cancelEventApplication;
  955.             }
  956.         }
  957.         return null;
  958.     }
  959.     /**
  960.      * Permet de récupérer la dernière demande d'annulation
  961.      * @return null|CancelEventApplication
  962.      */
  963.     public function getLastCancelEventApplication(): ?CancelEventApplication
  964.     {
  965.         $lastCancelEventApplication null;
  966.         if (!empty($this->cancelEventApplications)) {
  967.             $lastCancelEventApplication =  $this->cancelEventApplications[0];
  968.             foreach($this->cancelEventApplications as $cancelEventApplication) {
  969.                 if($cancelEventApplication->getId() > $lastCancelEventApplication->getId()) {
  970.                     $lastCancelEventApplication $cancelEventApplication;
  971.                 }
  972.             }
  973.         }
  974.         return $lastCancelEventApplication;
  975.     }
  976.     public function __toString()
  977.     {
  978.         return $this->getId() . " - " $this->getName();
  979.     }
  980.     
  981.     public function getNotation()
  982.     {
  983.         // Création variable ou l'on stock la note (default null) et création d'un compteur qui stockera le nombre de registrations valide
  984.         $note null;
  985.         $regCount 0;
  986.         // Récup tableau des registrations
  987.         $registrations $this->getRegistrations()->toArray();
  988.         // Parcourir le tableau pour valider ou non la présence
  989.         // Si present récup workshopNote et ajouter dans la variable qui stock les notes et incrementer le compteur
  990.         foreach ($registrations as $registration) {
  991.             if ($registration->getWorkshopNote() != null) {
  992.                 if ($note == null) {
  993.                     $note 0;
  994.                 }
  995.                 $note += $registration->getWorkshopNote();
  996.                 $regCount ++; 
  997.             }
  998.         }
  999.         // A la fin diviser la variable de note par le compteur si la note n'est pas null
  1000.         if ($note != null) {
  1001.             $note /= $regCount;
  1002.         }
  1003.        return $note;
  1004.     }
  1005.     public function getExpertNotation()
  1006.     {
  1007.          // Création variable ou l'on stock la note (default null) et création d'un compteur qui stockera le nombre de registrations valide
  1008.          $note null;
  1009.          $regCount 0;
  1010.          // Récup tableau des registrations
  1011.          $registrations $this->getRegistrations()->toArray();
  1012.          // Parcourir le tableau pour valider ou non la présence
  1013.          // Si present récup expertNote et ajouter dans la variable qui stock les notes et incrementer le compteur
  1014.          foreach ($registrations as $registration) {
  1015.              if ($registration->getExpertNote() != null) {
  1016.                  if ($note == null) {
  1017.                      $note 0;
  1018.                  }
  1019.                  $note += $registration->getExpertNote();
  1020.                  $regCount ++; 
  1021.              }
  1022.          }
  1023.          // A la fin diviser la variable de note par le compteur si la note n'est pas null
  1024.          if ($note != null) {
  1025.              $note /= $regCount;
  1026.          }
  1027.         return $note;
  1028.     }
  1029.     public function getNotationVoters()
  1030.     {
  1031.          // Création variable ou l'on stock la note (default null) et création d'un compteur qui stockera le nombre de registrations valide
  1032.          $regCount 0;
  1033.          // Récup tableau des registrations
  1034.          $registrations $this->getRegistrations()->toArray();
  1035.          // Parcourir le tableau pour valider ou non la présence
  1036.          // Si present récup expertNote et ajouter dans la variable qui stock les notes et incrementer le compteur
  1037.          foreach ($registrations as $registration) {
  1038.              if ($registration->getPresence() && $registration->getExpertNote() != null && $registration->getWorkshopNote() != null) {
  1039.                  $regCount ++; 
  1040.              }
  1041.          }
  1042.          // A la fin diviser la variable de note par le compteur si la note n'est pas null
  1043.         return $regCount;
  1044.     }
  1045.     public function getLimitDateCancellation(): ?\DateTime
  1046.     {
  1047.         if($this->getCancellationParameters() instanceof CancellationParameters) {
  1048.             return $this->getCancellationParameters()->getLimitDate();
  1049.         }
  1050.         return null;
  1051.     }
  1052.     /**
  1053.      * Permet de définir si l'event est en warning en fonction d'un certains nombre de jour donné 
  1054.      * et de ses parametres d'annulation
  1055.      * @var int $limitDays
  1056.      * @var int $limitHours
  1057.      */
  1058.     public function isWarning(int $limitDays 0int $limitHours 0): bool
  1059.     {
  1060.         $minDate = (new \DateTime("now"))->setTime(0,0,1);
  1061.         $maxDate = (new \DateTime("now"))->setTime(23,59,59);
  1062.         if($limitDays 0){
  1063.             $maxDate->modify("+ {$limitDays} days");
  1064.         }
  1065.         if($limitHours 0){
  1066.             $maxDate->modify("+ {$limitHours} hours");
  1067.         }
  1068.         return (!$this->isPast() 
  1069.             && $this->getCancellationParameters() instanceof CancellationParameters
  1070.             && $this->getLimitDateCancellation() >=  $minDate 
  1071.             && $this->getLimitDateCancellation() <= $maxDate
  1072.             && $this->getRegisteredCount() <= $this->getCancellationParameters()->getMinCapacity() 
  1073.         );
  1074.     }
  1075.     public function getCoefMajoration(): ?float
  1076.     {
  1077.         return $this->coefMajoration;
  1078.     }
  1079.     public function setCoefMajoration(?float $coefMajoration): self
  1080.     {
  1081.         $this->coefMajoration $coefMajoration;
  1082.         return $this;
  1083.     }
  1084.     public function getSpecialistPrice(): ?float
  1085.     {
  1086.         return $this->specialistPrice;
  1087.     }
  1088.     public function setSpecialistPrice(?float $specialistPrice): self
  1089.     {
  1090.         $this->specialistPrice $specialistPrice;
  1091.         return $this;
  1092.     }
  1093.     public function getCoefMargin(): ?float
  1094.     {
  1095.         return $this->coefMargin;
  1096.     }
  1097.     public function setCoefMargin(?float $coefMargin): self
  1098.     {
  1099.         $this->coefMargin $coefMargin;
  1100.         return $this;
  1101.     }
  1102.     
  1103.     /**
  1104.      * Permet de savoir si l'event est a venir
  1105.      */
  1106.     public function isInComing(): bool
  1107.     {
  1108.         return (!$this->isPast() && $this->status == self::STATUS_VALID);
  1109.     }
  1110.     /**
  1111.      * @return Collection<int, AffiliatedEventApplication>
  1112.      */
  1113.     public function getAffiliatedEventApplications(): Collection
  1114.     {
  1115.         return $this->affiliatedEventApplications;
  1116.     }
  1117.     public function addAffiliatedEventApplication(AffiliatedEventApplication $affiliatedEventApplication): self
  1118.     {
  1119.         if (!$this->affiliatedEventApplications->contains($affiliatedEventApplication)) {
  1120.             $this->affiliatedEventApplications[] = $affiliatedEventApplication;
  1121.             $affiliatedEventApplication->setEvent($this);
  1122.         }
  1123.         return $this;
  1124.     }
  1125.     public function removeAffiliatedEventApplication(AffiliatedEventApplication $affiliatedEventApplication): self
  1126.     {
  1127.         if ($this->affiliatedEventApplications->removeElement($affiliatedEventApplication)) {
  1128.             // set the owning side to null (unless already changed)
  1129.             if ($affiliatedEventApplication->getEvent() === $this) {
  1130.                 $affiliatedEventApplication->setEvent(null);
  1131.             }
  1132.         }
  1133.         return $this;
  1134.     }
  1135.     public function getMarketplaceReservation(): ?MarketplaceReservation
  1136.     {
  1137.         return $this->marketplaceReservation;
  1138.     }
  1139.     public function setMarketplaceReservation(?MarketplaceReservation $marketplaceReservation): self
  1140.     {
  1141.         // unset the owning side of the relation if necessary
  1142.         if ($marketplaceReservation === null && $this->marketplaceReservation !== null) {
  1143.             $this->marketplaceReservation->setEvent(null);
  1144.         }
  1145.         // set the owning side of the relation if necessary
  1146.         if ($marketplaceReservation !== null && $marketplaceReservation->getEvent() !== $this) {
  1147.             $marketplaceReservation->setEvent($this);
  1148.         }
  1149.         $this->marketplaceReservation $marketplaceReservation;
  1150.         return $this;
  1151.     }
  1152.     public function getIsMarketplace(): ?bool
  1153.     {
  1154.         return $this->isMarketplace;
  1155.     }
  1156.     public function setIsMarketplace(bool $isMarketplace): self
  1157.     {
  1158.         $this->isMarketplace $isMarketplace;
  1159.         return $this;
  1160.     }
  1161.     public function getIsFromStats(): ?bool
  1162.     {
  1163.         return $this->isFromStats;
  1164.     }
  1165.     public function setIsFromStats(bool $isFromStats): self
  1166.     {
  1167.         $this->isFromStats $isFromStats;
  1168.         return $this;
  1169.     }
  1170.     public function getCallsheetComment(): ?string
  1171.     {
  1172.         return $this->callsheetComment;
  1173.     }
  1174.     public function setCallsheetComment(?string $callsheetComment): self
  1175.     {
  1176.         $this->callsheetComment $callsheetComment;
  1177.         return $this;
  1178.     }
  1179.     public function getOverQuota(): ?bool
  1180.     {
  1181.         return $this->overQuota;
  1182.     }
  1183.     public function isOverQuota(): ?bool
  1184.     {
  1185.         return $this->overQuota;
  1186.     }
  1187.     public function setOverQuota(bool $overQuota): self
  1188.     {
  1189.         $this->overQuota $overQuota;
  1190.         return $this;
  1191.     }
  1192.     public function getOverQuotaInfo(): ?string
  1193.     {
  1194.         return $this->overQuotaInfo;
  1195.     }
  1196.     public function setOverQuotaInfo(?string $overQuotaInfo): self
  1197.     {
  1198.         $this->overQuotaInfo $overQuotaInfo;
  1199.         return $this;
  1200.     }
  1201.     /**
  1202.      * Permet de savoir si l'Event est complet (inscriptions)
  1203.      * @return bool
  1204.      */
  1205.     public function isFull(): bool
  1206.     {
  1207.         return ($this->getRegisteredCount() >= $this->getCapacity());
  1208.     }
  1209.     /**
  1210.      * Permet de savoir si l'Event est plus que complet (inscriptions)$
  1211.      * @return bool
  1212.      */
  1213.     public function isOverFull(): bool
  1214.     {
  1215.         return ($this->getRegisteredCount() > $this->getCapacity());
  1216.     }
  1217.     /**
  1218.      * Permet de récupérer les Registration sur liste d'attente
  1219.      * @return array
  1220.      */
  1221.     public function getWaitingList(): array
  1222.     {
  1223.         $waitingList = [];
  1224.         foreach($this->getRegistrations() as $registration) {
  1225.             if($registration->isOnWaitingList()) $waitingList[] = $registration;
  1226.         }
  1227.         return $waitingList;
  1228.     }
  1229.     /**
  1230.      * Compte le nombre de Registration de la liste d'attente
  1231.      * @return int
  1232.      */
  1233.     public function getWaitingListCount(): int
  1234.     {
  1235.         return count($this->getWaitingList());
  1236.     }
  1237.     public function getWaitingListAssignationAuto(): ?bool
  1238.     {
  1239.         return $this->waitingListAssignationAuto;
  1240.     }
  1241.     public function setWaitingListAssignationAuto(bool $waitingListAssignationAuto): self
  1242.     {
  1243.         $this->waitingListAssignationAuto $waitingListAssignationAuto;
  1244.         return $this;
  1245.     }
  1246.     public function getWaitingListDefault(): ?bool
  1247.     {
  1248.         return $this->waitingListDefault;
  1249.     }
  1250.     public function setWaitingListDefault(?bool $waitingListDefault): self
  1251.     {
  1252.         $this->waitingListDefault $waitingListDefault;
  1253.         return $this;
  1254.     }
  1255.     /**
  1256.      * Permet de savoir si c'est un parent
  1257.      */
  1258.     public function isParent(): bool
  1259.     {
  1260.         return (!$this->getChildren()->isEmpty());
  1261.     }
  1262.     /**
  1263.      * Permet de savoir si c'est un enfant
  1264.      */
  1265.     public function isChild(): bool
  1266.     {
  1267.         return ($this->getParent() instanceof Event);
  1268.     }
  1269.     /**
  1270.      * Permet de savoir si il contient des enfants
  1271.      */
  1272.     public function hasChildren(): bool
  1273.     {
  1274.         return (!$this->getChildren()->isEmpty());
  1275.     }
  1276.     /**
  1277.      * @return Collection<int, Segmentation>
  1278.      */
  1279.     public function getSegmentations(): Collection
  1280.     {
  1281.         return $this->segmentations;
  1282.     }
  1283.     public function addSegmentation(Segmentation $segmentation): self
  1284.     {
  1285.         if (!$this->segmentations->contains($segmentation)) {
  1286.             $this->segmentations[] = $segmentation;
  1287.         }
  1288.         return $this;
  1289.     }
  1290.     public function removeSegmentation(Segmentation $segmentation): self
  1291.     {
  1292.         $this->segmentations->removeElement($segmentation);
  1293.         return $this;
  1294.     }
  1295.     public function getNegativeMailSent(): ?bool
  1296.     {
  1297.         return $this->negativeMailSent;
  1298.     }
  1299.     public function setNegativeMailSent(bool $negativeMailSent): self
  1300.     {
  1301.         $this->negativeMailSent $negativeMailSent;
  1302.         return $this;
  1303.     }
  1304.     public function getRemainingAvailableRegistrations(): ?int
  1305.     {
  1306.         $this->remainingAvailableRegistrations $this->capacity $this->getRegisteredCount();
  1307.         return abs($this->remainingAvailableRegistrations);
  1308.     }
  1309.     public function getImageUrl(): ?string
  1310.     {
  1311.         if($this->getWorkshop() instanceof Workshop) {
  1312.             $this->imageUrl $this->getWorkshop()->getImageUrl();
  1313.         }
  1314.         return $this->imageUrl;
  1315.     }
  1316.     public function setImageUrl(string $imageUrl): self
  1317.     {
  1318.         $this->imageUrl $imageUrl;
  1319.         return $this;
  1320.     }
  1321. }