src/Entity/Registration.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Enum\RegistrationOrigin;
  4. use App\Entity\Enum\RegistrationStatus;
  5. use App\Entity\Enum\TransactionStatus;
  6. use App\Entity\Traits\Identifiable;
  7. use App\Entity\Traits\Timestampable;
  8. use App\Repository\RegistrationRepository;
  9. use DateInterval;
  10. use DateTimeImmutable;
  11. use Doctrine\Common\Collections\ArrayCollection;
  12. use Doctrine\Common\Collections\Collection;
  13. use Doctrine\DBAL\Types\Types;
  14. use Doctrine\ORM\Mapping as ORM;
  15. #[ORM\Entity(repositoryClassRegistrationRepository::class)]
  16. class Registration
  17. {
  18.     use Timestampable;
  19.     use Identifiable;
  20.     #[ORM\Column(type'string'length20enumTypeRegistrationStatus::class)]
  21.     private RegistrationStatus $status RegistrationStatus::Prospect;
  22.     #[ORM\Column(type'boolean'nullabletrue)]
  23.     private $hasTaxReceipt;
  24.     #[ORM\Column(type'boolean'nullabletrue)]
  25.     private $hasCompanyReceipt;
  26.     #[ORM\ManyToOne(targetEntityPerson::class, inversedBy'registrations'cascade: ['persist'])]
  27.     #[ORM\JoinColumn(nullablefalse)]
  28.     private $person;
  29.     #[ORM\ManyToOne(targetEntityPerson::class, inversedBy'signedRegistrations')]
  30.     private $signatory;
  31.     #[ORM\ManyToMany(targetEntitySlot::class, inversedBy'registrations')]
  32.     private $slots;
  33.     #[ORM\ManyToOne(targetEntityLesson::class, inversedBy'registrations')]
  34.     private $lesson;
  35.     #[ORM\ManyToOne(targetEntitySeason::class, inversedBy'registrations')]
  36.     #[ORM\JoinColumn(nullablefalse)]
  37.     private $season;
  38.     #[ORM\OneToOne(mappedBy'registration'targetEntityOrder::class, cascade: ['persist''remove'])]
  39.     private $order;
  40.     #[ORM\ManyToMany(targetEntityLesson::class)]
  41.     #[ORM\JoinTable(name'registration_proposed_lesson')]
  42.     private $proposedLessons;
  43.     #[ORM\ManyToMany(targetEntitySlot::class, inversedBy'registrationPropositions')]
  44.     #[ORM\JoinTable(name'registration_proposed_slot')]
  45.     private $proposedSlots;
  46.     #[ORM\Column(type'smallint'nullabletrue)]
  47.     private $validationStep 1;
  48.     #[ORM\Column(type'integer'nullabletrue)]
  49.     private $oldId;
  50.     #[ORM\OneToMany(mappedBy'registration'targetEntityDocument::class, cascade: ['remove'])]
  51.     private $documents;
  52.     #[ORM\Column(type'smallint')]
  53.     private $reminder 0;
  54.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  55.     private ?\DateTimeInterface $lastReminder null;
  56.     #[ORM\Column(type'string'length100enumTypeRegistrationOrigin::class)]
  57.     private $origin RegistrationOrigin::Frontoffice;
  58.     public function __construct()
  59.     {
  60.         $this->slots = new ArrayCollection();
  61.         $this->proposedLessons = new ArrayCollection();
  62.         $this->proposedSlots = new ArrayCollection();
  63.         $this->setOrder(new Order());
  64.         $this->documents = new ArrayCollection();
  65.     }
  66.     public function getStatus(): ?RegistrationStatus
  67.     {
  68.         return $this->status;
  69.     }
  70.     public function setStatus(RegistrationStatus $status): self
  71.     {
  72.         $this->status $status;
  73.         return $this;
  74.     }
  75.     public function getSignatory(): ?Person
  76.     {
  77.         return $this->signatory;
  78.     }
  79.     public function setSignatory(?Person $signatory): self
  80.     {
  81.         $this->signatory $signatory;
  82.         return $this;
  83.     }
  84.     public function getHasTaxReceipt(): ?bool
  85.     {
  86.         return $this->hasTaxReceipt;
  87.     }
  88.     public function setHasTaxReceipt(bool $hasTaxReceipt): self
  89.     {
  90.         $this->hasTaxReceipt $hasTaxReceipt;
  91.         return $this;
  92.     }
  93.     public function getHasCompanyReceipt(): ?bool
  94.     {
  95.         return $this->hasCompanyReceipt;
  96.     }
  97.     public function setHasCompanyReceipt(bool $hasCompanyReceipt): self
  98.     {
  99.         $this->hasCompanyReceipt $hasCompanyReceipt;
  100.         return $this;
  101.     }
  102.     /**
  103.      * @return Collection<int, Slot>
  104.      */
  105.     public function getSlots(): Collection
  106.     {
  107.         return $this->slots;
  108.     }
  109.     public function addSlot(Slot $slot): self
  110.     {
  111.         if (!$this->slots->contains($slot)) {
  112.             $this->slots[] = $slot;
  113.             $slot->addRegistration($this);
  114.         }
  115.         return $this;
  116.     }
  117.     public function removeSlot(Slot $slot): self
  118.     {
  119.         if ($this->slots->removeElement($slot)) {
  120.             $slot->removeRegistration($this);
  121.         }
  122.         return $this;
  123.     }
  124.     public function getPerson(): ?Person
  125.     {
  126.         return $this->person;
  127.     }
  128.     public function setPerson(?Person $person): self
  129.     {
  130.         $this->person $person;
  131.         return $this;
  132.     }
  133.     public function getSeason(): ?Season
  134.     {
  135.         return $this->season;
  136.     }
  137.     public function setSeason(?Season $season): self
  138.     {
  139.         $this->season $season;
  140.         return $this;
  141.     }
  142.     public function getOrder(): ?Order
  143.     {
  144.         return $this->order;
  145.     }
  146.     public function setOrder(?Order $order): self
  147.     {
  148.         // unset the owning side of the relation if necessary
  149.         if ($order === null && $this->order !== null) {
  150.             $this->order->setRegistration(null);
  151.         }
  152.         // set the owning side of the relation if necessary
  153.         if ($order !== null && $order->getRegistration() !== $this) {
  154.             $order->setRegistration($this);
  155.         }
  156.         $this->order $order;
  157.         return $this;
  158.     }
  159.     /**
  160.      * @return Collection<int, Lesson>
  161.      */
  162.     public function getProposedLessons(): Collection
  163.     {
  164.         return $this->proposedLessons;
  165.     }
  166.     public function addProposedLesson(Lesson $proposedLesson): self
  167.     {
  168.         if (!$this->proposedLessons->contains($proposedLesson)) {
  169.             $this->proposedLessons[] = $proposedLesson;
  170.         }
  171.         return $this;
  172.     }
  173.     public function removeProposedLesson(Lesson $proposedLesson): self
  174.     {
  175.         $this->proposedLessons->removeElement($proposedLesson);
  176.         return $this;
  177.     }
  178.     /**
  179.      * @return Collection<int, Slot>
  180.      */
  181.     public function getProposedSlots(): Collection
  182.     {
  183.         return $this->proposedSlots;
  184.     }
  185.     public function addProposedSlot(Slot $proposedSlot): self
  186.     {
  187.         if (!$this->proposedSlots->contains($proposedSlot)) {
  188.             $this->proposedSlots[] = $proposedSlot;
  189.         }
  190.         return $this;
  191.     }
  192.     public function removeProposedSlot(Slot $proposedSlot): self
  193.     {
  194.         $this->proposedSlots->removeElement($proposedSlot);
  195.         return $this;
  196.     }
  197.     public function getLesson(): ?Lesson
  198.     {
  199.         return $this->lesson;
  200.     }
  201.     public function setLesson(?Lesson $lesson): self
  202.     {
  203.         $this->lesson $lesson;
  204.         return $this;
  205.     }
  206.     public function getValidationStep(): ?int
  207.     {
  208.         return $this->validationStep;
  209.     }
  210.     public function setValidationStep(?int $validationStep): self
  211.     {
  212.         $this->validationStep $validationStep;
  213.         return $this;
  214.     }
  215.     public static function unaffectLessonsAndSlots(self $registration): self
  216.     {
  217.         $registration->setLesson(null);
  218.         $registration->getSlots()->clear();
  219.         return $registration;
  220.     }
  221.     public function getSection(): ?Section
  222.     {
  223.         return $this->getSeason()?->getSection();
  224.     }
  225.     public function getOldId(): ?int
  226.     {
  227.         return $this->oldId;
  228.     }
  229.     public function setOldId(?int $oldId): self
  230.     {
  231.         $this->oldId $oldId;
  232.         return $this;
  233.     }
  234.     /**
  235.      * @return Collection<int, Document>
  236.      */
  237.     public function getDocuments(bool $activeVersionOnly false): Collection
  238.     {
  239.         $documents $this->documents;
  240.         if ($activeVersionOnly) {
  241.             $finalArray = [];
  242.             $models = [];
  243.             $documentsArray array_reverse($documents->toArray());
  244.             /** @var Document $item */
  245.             foreach ($documentsArray as $item) {
  246.                 $modelId $item->getModel()?->getId();
  247.                 if ($modelId) {
  248.                     if (!in_array($modelId$modelstrue)) {
  249.                         $models[] = $modelId;
  250.                         $finalArray[] = $item;
  251.                     }
  252.                 } else {
  253.                     $finalArray[] = $item;
  254.                 }
  255.             }
  256.             return new ArrayCollection(array_reverse($finalArray));
  257.         }
  258.         return $documents;
  259.     }
  260.     public function addDocument(Document $document): self
  261.     {
  262.         if (!$this->documents->contains($document)) {
  263.             $this->documents[] = $document;
  264.             $document->setRegistration($this);
  265.         }
  266.         return $this;
  267.     }
  268.     public function removeDocument(Document $document): self
  269.     {
  270.         if ($this->documents->removeElement($document)) {
  271.             // set the owning side to null (unless already changed)
  272.             if ($document->getRegistration() === $this) {
  273.                 $document->setRegistration(null);
  274.             }
  275.         }
  276.         return $this;
  277.     }
  278.     /**
  279.      * @param bool $includeRentals
  280.      * @param bool $linkDocuments
  281.      * @return Collection<int, DocumentModel>
  282.      */
  283.     public function getRemainingDocumentModels(bool $includeRentals truebool $linkDocuments falsebool $removeAdminOnly false): Collection
  284.     {
  285.         /** @var Collection<int, DocumentModel> $models */
  286.         $models = new ArrayCollection();
  287.         $cart $this->getOrder()?->getCart();
  288.         foreach ($cart->getDiscounts() as $itemDiscount) {
  289.             foreach ($itemDiscount->getDiscount()?->getModel()?->getDocumentModels() ?? [] as $model) {
  290.                 if ($model->getSeason()->getGlobalSeason()->getId() ===
  291.                     $this->getSeason()->getGlobalSeason()->getId()) {
  292.                     $models->add($model);
  293.                 }
  294.             }
  295.         }
  296.         foreach ($this->getSeason()?->getDocumentModels(false) ?? [] as $model) {
  297.             if (($this->getPerson()->isMinor() && $model->getIsForMinor()) ||
  298.                 (!$this->getPerson()->isMinor() && $model->getIsForAdult())) {
  299.                 $models->add($model);
  300.             }
  301.         }
  302.         // Remove all models that are for admins only
  303.         if ($removeAdminOnly) {
  304.             foreach ($models as $model) {
  305.                 if ($model->isAdminOnly()) {
  306.                     $models->removeElement($model);
  307.                 }
  308.             }
  309.         }
  310.         if ($linkDocuments) {
  311.             foreach ($models as $model) {
  312.                 foreach ($this->getDocuments() as $document) {
  313.                     if ($document->getModel() === $model) {
  314.                         $model->addLinkedDocument($document);
  315.                     }
  316.                 }
  317.             }
  318.         }
  319.         return $models;
  320.     }
  321.     public function getReminder(): ?int
  322.     {
  323.         return $this->reminder;
  324.     }
  325.     public function setReminder(int $reminder): self
  326.     {
  327.         $this->reminder $reminder;
  328.         return $this;
  329.     }
  330.     public function getLastReminder(): ?\DateTimeInterface
  331.     {
  332.         return $this->lastReminder;
  333.     }
  334.     public function setLastReminder(?\DateTimeInterface $lastReminder): self
  335.     {
  336.         $this->lastReminder $lastReminder;
  337.         return $this;
  338.     }
  339.     public function getDiffSinceLastReminder(): ?DateInterval
  340.     {
  341.         $reminder $this->getLastReminder() ?? $this->getUpdatedAt() ?? new DateTimeImmutable();
  342.         $now = new DateTimeImmutable();
  343.         return $reminder->diff($now);
  344.     }
  345.     public function getOrigin(): ?RegistrationOrigin
  346.     {
  347.         return $this->origin;
  348.     }
  349.     public function setOrigin(RegistrationOrigin $origin): self
  350.     {
  351.         $this->origin $origin;
  352.         return $this;
  353.     }
  354.     public function guessPaymentType($printable false): ?string
  355.     {
  356.         $transaction $this->getOrder()->getTransactions(statuses: [
  357.             TransactionStatus::Created,
  358.             TransactionStatus::Waiting,
  359.             TransactionStatus::Successful,
  360.         ])->first();
  361.         if ($transaction) {
  362.             $class get_class($transaction);
  363.             if ($printable && Transaction::getNameByClass($class)) {
  364.                 return Transaction::getNameByClass($class);
  365.             }
  366.             return $class;
  367.         }
  368.         return null;
  369.     }
  370.     public function __clone()
  371.     {
  372.         $this->uuid null;
  373.         $this->id null;
  374.         $this->__construct();
  375.         $this->status RegistrationStatus::Prospect;
  376.         $this->hasTaxReceipt null;
  377.         $this->hasCompanyReceipt null;
  378.         $this->signatory null;
  379.         $this->lesson null;
  380.         $this->season null;
  381.         $this->validationStep 1;
  382.         $this->reminder 0;
  383.         $this->createdAt null;
  384.         $this->updatedAt null;
  385.     }
  386. }