src/Entity/Registration.php line 67

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiFilter;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use ApiPlatform\Core\Annotation\ApiSubresource;
  6. use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
  7. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  8. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  9. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter;
  10. use App\Repository\RegistrationRepository;
  11. use Doctrine\ORM\Mapping as ORM;
  12. use Gedmo\Mapping\Annotation as Gedmo;
  13. use Symfony\Component\Serializer\Annotation\Groups;
  14. use Symfony\Component\Validator\Constraints as Assert;
  15. /**
  16.  * @ApiResource(
  17.  *     normalizationContext={
  18.  *          "groups"={"registration:read"}
  19.  *     },
  20.  *     denormalizationContext={
  21.  *          "groups"={"registration:write"}
  22.  *     },
  23.  *     itemOperations={
  24.  *         "get"={
  25.  *              "security"="is_granted('ROLE_CLIENT')",
  26.  *              "security_message"="You are not allowed to access this ressource"
  27.  *          }
  28.  *     },
  29.  *     collectionOperations={
  30.  *          "get"={
  31.  *              "security"="is_granted('ROLE_CLIENT')"
  32.  *          }
  33.  *     }
  34.  * )
  35.  * @ApiFilter(DateFilter::class, 
  36.  *      properties={
  37.  *          "createdAt", "event.start", "event.end"
  38.  *      }
  39.  * )
  40.  * @ApiFilter(SearchFilter::class, 
  41.  *      strategy="exact",
  42.  *      properties={
  43.  *          "id", "presence", "status", "paymentStatus", "price", "priceHt", "refundAmount", "refundDate",
  44.  *          "client", "client.company",
  45.  *          "event", "event.company", "event.status", "event.active",
  46.  *          "visioEvent"
  47.  *      }
  48.  * )
  49.  * @ApiFilter(OrderFilter::class, 
  50.  *      properties={
  51.  *          "id", "createdAt", "updatedAt", "status", "price", "paymentStatus", "presence", "refundDate",
  52.  *          "event.id", "event.name", "event.start", "event.end",
  53.  *          "visioEvent.start", "visioEvent.end"
  54.  *      }
  55.  * )
  56.  * @ApiFilter(PropertyFilter::class, 
  57.  *      arguments={
  58.  *          "parameterName"="fields", 
  59.  *          "overrideDefaultProperties"=true
  60.  *      }
  61.  * )
  62.  * @ORM\Entity(repositoryClass=RegistrationRepository::class)
  63.  */
  64. class Registration
  65. {
  66.     const STATUS_PENDING 'pending'// when the registration needs a confirmation (aka: payment most of the time)
  67.     const STATUS_PENDING_CANCELLATION 'pending_cancellation';
  68.     const STATUS_CANCELED 'canceled';
  69.     const STATUS_ON_WAITING_LIST 'on_waiting_list';
  70.     const STATUS_REGISTER 'register';
  71.     const STATUS_SURVEY_SENT 'survey_sent';
  72.     const PAYMENT_STATUS_FREE 'free';
  73.     const PAYMENT_STATUS_PENDING 'pending';
  74.     const PAYMENT_STATUS_CANCELED 'canceled';
  75.     const PAYMENT_STATUS_FAILED 'failed';
  76.     const PAYMENT_STATUS_SUCCESS 'success';
  77.     const PAYMENT_STATUS_REFUND_PENDING 'pending_refund';
  78.     const PAYMENT_STATUS_REFUND 'refund';
  79.     const STATUSES = [
  80.         self::STATUS_REGISTER,
  81.         self::STATUS_CANCELED,
  82.         self::STATUS_SURVEY_SENT,
  83.     ];
  84.     /**
  85.      * @ORM\Id
  86.      * @ORM\GeneratedValue
  87.      * @ORM\Column(type="integer")
  88.      * @Groups({"registration:read", "registration:read:id"})
  89.      */
  90.     private $id;
  91.     /**
  92.      * @ORM\Column(type="datetime")
  93.      * @Gedmo\Timestampable(on="create")
  94.      * @Groups({"registration:read", "registration:read:createdAt"})
  95.      */
  96.     private $createdAt;
  97.     /**
  98.      * @ORM\Column(type="string", length=255, nullable=true)
  99.      * @Groups({"registration:read", "registration:read:payment", "registration:write", "registration:write:create"})
  100.      */
  101.     private $payment;
  102.     /**
  103.      * @ORM\Column(type="float")
  104.      * @Groups({"registration:read", "registration:read:priceHt", "registration:write"})
  105.      */
  106.     private $priceHt 0;
  107.     /**
  108.      * @ORM\Column(type="float")
  109.      * @Groups({"registration:read", "registration:read:price", "registration:write"})
  110.      */
  111.     private $price 0;
  112.     /**
  113.      * @ORM\Column(type="string", length=255)
  114.      * @Assert\NotBlank
  115.      * @Groups({"registration:read", "registration:read:status", "registration:write"})
  116.      */
  117.     private $status self::STATUS_REGISTER;
  118.     /**
  119.      * @ORM\Column(type="string", length=255, nullable=true)
  120.      * @Groups({"registration:read", "registration:read:paymentStatus", "registration:write"})
  121.      */
  122.     private $paymentStatus self::PAYMENT_STATUS_FREE;
  123.     /**
  124.      * @ORM\Column(type="boolean", options={"default": "0"})
  125.      * @Groups({"registration:read", "registration:read:presence", "registration:write"})
  126.      */
  127.     private $presence false;
  128.     /**
  129.      * @ORM\Column(type="string", length=255)
  130.      * @Groups({"registration:read", "registration:read:statsCode", "registration:write"})
  131.      */
  132.     private $statsCode "code";
  133.     /**
  134.      * @ORM\ManyToOne(targetEntity=Event::class, inversedBy="registrations")
  135.      * @Assert\NotBlank
  136.      * @Groups({"client:read"})
  137.      * @Groups({"registration:read", "registration:read:event", "registration:write", "registration:write:create"})
  138.      */
  139.     private $event;
  140.     /**
  141.      * @ORM\ManyToOne(targetEntity=Client::class, inversedBy="registrations")
  142.      * @ORM\JoinColumn(nullable=false)
  143.      * @Assert\NotBlank
  144.      * @Groups({"registration:read", "registration:read:client", "registration:write", "registration:write:create"})
  145.      */
  146.     private $client;
  147.     /**
  148.      * @ORM\Column(type="datetime", nullable=true)
  149.      * @Gedmo\Timestampable(on="update")
  150.      * @Groups({"registration:read", "registration:read:updatedAt"})
  151.      */
  152.     private $updatedAt;
  153.     /**
  154.      * @ORM\Column(type="float", nullable=true)
  155.      * @Groups({"registration:read", "registration:read:expertNote", "registration:write"})
  156.      */
  157.     private $expertNote;
  158.     /**
  159.      * @ORM\Column(type="float", nullable=true)
  160.      * @Groups({"registration:read", "registration:read:workshopNote", "registration:write"})
  161.      */
  162.     private $workshopNote;
  163.     /**
  164.      * @ORM\Column(type="string", length=255, nullable=true)
  165.      * @Groups({"registration:read", "registration:read:updatedBy"})
  166.      */
  167.     private $updatedBy;
  168.     /**
  169.      * @ORM\ManyToOne(targetEntity=VisioEvent::class, inversedBy="registrations")
  170.      * @Groups({"registration:read", "registration:read:visioEvent"})
  171.      */
  172.     private $visioEvent;
  173.     /**
  174.      * @ORM\ManyToOne(targetEntity=VisioEventPromotion::class, inversedBy="registrations")
  175.      * @Groups({"registration:read", "registration:read:token", "registration:write"})
  176.      */
  177.     private $token;
  178.     /**
  179.      * @ORM\Column(type="float", nullable=true)
  180.      * @Groups({"registration:read", "registration:read:refundAmount", "registration:write"})
  181.      */
  182.     private $refundAmount;
  183.     /**
  184.      * @ORM\Column(type="datetime", nullable=true)
  185.      * @Groups({"registration:read", "registration:read:refundDate", "registration:write"})
  186.      */
  187.     private $refundDate;
  188.     public function __construct() {
  189.         $this->createdAt = new \DateTime();
  190.         $this->updatedAt = new \DateTime();
  191.     }
  192.     public function getId(): ?int
  193.     {
  194.         return $this->id;
  195.     }
  196.     public function getCreatedAt(): ?\DateTime
  197.     {
  198.         return $this->createdAt;
  199.     }
  200.     public function setCreatedAt(\DateTime $createdAt): self
  201.     {
  202.         $this->createdAt $createdAt;
  203.         return $this;
  204.     }
  205.     public function getPayment(): ?string
  206.     {
  207.         return $this->payment;
  208.     }
  209.     public function setPayment(?string $payment): self
  210.     {
  211.         $this->payment $payment;
  212.         return $this;
  213.     }
  214.     public function getPriceHt(): ?float
  215.     {
  216.         return $this->priceHt;
  217.     }
  218.     public function setPriceHt(float $priceHt): self
  219.     {
  220.         $this->priceHt $priceHt;
  221.         return $this;
  222.     }
  223.     public function getPrice(): ?float
  224.     {
  225.         return $this->price;
  226.     }
  227.     public function setPrice(float $price): self
  228.     {
  229.         $this->price $price;
  230.         return $this;
  231.     }
  232.     public function getStatus(): ?string
  233.     {
  234.         return $this->status;
  235.     }
  236.     public function setStatus(string $status): self
  237.     {
  238.         $this->status $status;
  239.         return $this;
  240.     }
  241.     public function getPaymentStatus(): ?string
  242.     {
  243.         return $this->paymentStatus;
  244.     }
  245.     public function setPaymentStatus(?string $paymentStatus): self
  246.     {
  247.         $this->paymentStatus $paymentStatus;
  248.         return $this;
  249.     }
  250.     public function getPresence(): ?bool
  251.     {
  252.         return $this->presence;
  253.     }
  254.     public function isPresence(): ?bool
  255.     {
  256.         return $this->presence;
  257.     }
  258.     public function setPresence(bool $presence): self
  259.     {
  260.         $this->presence $presence;
  261.         return $this;
  262.     }
  263.     public function getStatsCode(): ?string
  264.     {
  265.         return $this->statsCode;
  266.     }
  267.     public function setStatsCode(string $statsCode): self
  268.     {
  269.         $this->statsCode $statsCode;
  270.         return $this;
  271.     }
  272.     public function getEvent(): ?Event
  273.     {
  274.         return $this->event;
  275.     }
  276.     public function setEvent(?Event $event): self
  277.     {
  278.         $this->event $event;
  279.         return $this;
  280.     }
  281.     public function getClient(): ?Client
  282.     {
  283.         return $this->client;
  284.     }
  285.     public function setClient(?Client $client): self
  286.     {
  287.         $this->client $client;
  288.         return $this;
  289.     }
  290.     public function getUpdatedAt(): ?\DateTime
  291.     {
  292.         return $this->updatedAt;
  293.     }
  294.     public function setUpdatedAt(?\DateTime $updatedAt): self
  295.     {
  296.         $this->updatedAt $updatedAt;
  297.         return $this;
  298.     }
  299.     /**
  300.      * @return bool
  301.      */
  302.     public function isRegistered(): bool
  303.     {
  304.         return in_array($this->getStatus(), [self::STATUS_SURVEY_SENTself::STATUS_REGISTER]);
  305.     }
  306.     /**
  307.      * @return bool
  308.      */
  309.     public function isRegister(): bool
  310.     {
  311.         return ($this->status == self::STATUS_REGISTER);
  312.     }
  313.     public function isPresent(): bool
  314.     {
  315.         return $this->presence;
  316.     }
  317.     public function isSurveySent(): bool
  318.     {
  319.         return ($this->status == self::STATUS_SURVEY_SENT);
  320.     }
  321.     public function getCancelLimit()
  322.     {
  323.         if ($this->getEvent()->getCancellationParameters() instanceof CancellationParameters) {
  324.             return $this->getEvent()->getCancellationParameters()->getLimitB();
  325.         }
  326.         return null;
  327.     }
  328.     public function isAnnulable(): bool
  329.     {
  330.         $params $this->getEvent()->getCancellationParameters();
  331.         if ($params instanceof CancellationParameters && $params->getLimitB() > 0){
  332.             $date = new \DateTime();
  333.             $hours abs($this->getEvent()->getStart()->getTimestamp() - $date->getTimestamp()) / (60 60);
  334.             if ($hours <= $params->getLimitB()){
  335.                 return false;
  336.             }
  337.         }
  338.         return true;
  339.     }
  340.     public function getExpertNote(): ?float
  341.     {
  342.         return $this->expertNote;
  343.     }
  344.     public function setExpertNote(?float $expertNote): self
  345.     {
  346.         $this->expertNote $expertNote;
  347.         return $this;
  348.     }
  349.     public function getWorkshopNote(): ?float
  350.     {
  351.         return $this->workshopNote;
  352.     }
  353.     public function setWorkshopNote(?float $workshopNote): self
  354.     {
  355.         $this->workshopNote $workshopNote;
  356.         return $this;
  357.     }
  358.     public function getUpdatedBy(): ?string
  359.     {
  360.         return $this->updatedBy;
  361.     }
  362.     public function setUpdatedBy(?string $updatedBy): self
  363.     {
  364.         $this->updatedBy $updatedBy;
  365.         return $this;
  366.     }
  367.     public function getVisioEvent(): ?VisioEvent
  368.     {
  369.         return $this->visioEvent;
  370.     }
  371.     public function setVisioEvent(?VisioEvent $visioEvent): self
  372.     {
  373.         $this->visioEvent $visioEvent;
  374.         return $this;
  375.     }
  376.     public function isVisioValid(): bool
  377.     {
  378.         return (in_array($this->status, [
  379.             self::STATUS_PENDING,
  380.             self::STATUS_REGISTER,
  381.             self::STATUS_SURVEY_SENT,
  382.             self::STATUS_PENDING_CANCELLATION,
  383.         ]));
  384.     }
  385.     public function getToken(): ?VisioEventPromotion
  386.     {
  387.         return $this->token;
  388.     }
  389.     public function setToken(?VisioEventPromotion $token): self
  390.     {
  391.         $this->token $token;
  392.         return $this;
  393.     }
  394.     public function getRefundAmount(): ?float
  395.     {
  396.         return $this->refundAmount;
  397.     }
  398.     public function setRefundAmount(?float $refundAmount): self
  399.     {
  400.         $this->refundAmount $refundAmount;
  401.         return $this;
  402.     }
  403.     public function getRefundDate(): ?\DateTimeInterface
  404.     {
  405.         return $this->refundDate;
  406.     }
  407.     public function setRefundDate(?\DateTimeInterface $refundDate): self
  408.     {
  409.         $this->refundDate $refundDate;
  410.         return $this;
  411.     }
  412.     /**
  413.      * Permet de savoir si son incription est sur liste d'attente
  414.      * Status = STATUS_PENDING
  415.      * PaymentStatus = PAYMENT_STATUS_FREE
  416.      * Payment = NULL
  417.      * 
  418.      * @return bool
  419.      */
  420.     public function isOnWaitingList(): bool
  421.     {
  422.         return ($this->status === $this::STATUS_ON_WAITING_LIST);
  423.     }
  424.     /**
  425.      * Permet de savoir si la Registration est "en attente de paiement" 
  426.      * @return bool
  427.      */
  428.     public function isPendingPayment(): bool
  429.     {
  430.         return ($this->paymentStatus === $this::PAYMENT_STATUS_PENDING);
  431.     } 
  432.     /**
  433.      * Permet de savoir si la Registration est "annulĂ©" 
  434.      * @return bool
  435.      */
  436.     public function isCanceled(): bool
  437.     {
  438.         return ($this->status === $this::STATUS_CANCELED);
  439.     } 
  440.     /**
  441.      * Permet de savoir si la Registration est "en attente d'annulation" 
  442.      * @return bool
  443.      */
  444.     public function isPendingCancellation(): bool
  445.     {
  446.         return ($this->status === $this::STATUS_PENDING_CANCELLATION);
  447.     } 
  448.     /**
  449.      * Permet de savoir si une inscription est valide
  450.      */
  451.     public function isValid(): bool
  452.     {
  453.         return ($this->status === $this::STATUS_REGISTER 
  454.             && ($this->paymentStatus === $this::PAYMENT_STATUS_FREE || $this->paymentStatus === $this::PAYMENT_STATUS_SUCCESS)
  455.         );
  456.     }
  457.     /**
  458.      * Permet de savoir si une inscription est gratuite
  459.      */
  460.     public function isFree(): bool
  461.     {
  462.         return ($this->paymentStatus === $this::PAYMENT_STATUS_FREE);
  463.     }
  464. }