Vincent 10 miesięcy temu
rodzic
commit
686c316951

+ 30 - 0
src/ApiResources/Profile/OrganizationProfile.php

@@ -70,6 +70,12 @@ class OrganizationProfile implements ApiResourcesInterface
     #[Assert\Type(type: PrincipalTypeEnum::class)]
     private ?PrincipalTypeEnum $principalType = null;
 
+    #[Groups('access_profile_read')]
+    private ?bool $trialActive = false;
+
+    #[Groups('access_profile_read')]
+    private ?int $trialCountDown = null;
+
     public function getId(): ?int
     {
         return $this->id;
@@ -241,4 +247,28 @@ class OrganizationProfile implements ApiResourcesInterface
 
         return $this;
     }
+
+    public function isTrialActive(): bool
+    {
+        return $this->trialActive;
+    }
+
+    public function setTrialActive(?bool $trialActive): self
+    {
+        $this->trialActive = $trialActive ?? false;
+
+        return $this;
+    }
+
+    public function getTrialCountDown(): ?int
+    {
+        return $this->trialCountDown;
+    }
+
+    public function setTrialCountDown(?int $trialCountDown): self
+    {
+        $this->trialCountDown = $trialCountDown;
+
+        return $this;
+    }
 }

+ 45 - 0
src/Entity/Organization/Settings.php

@@ -41,6 +41,15 @@ class Settings
     #[ORM\Column(length: 255, options: ['default' => 'FRANCE'])]
     private string $country;
 
+    #[ORM\Column(nullable: true)]
+    private ?bool $trialActive = false;
+
+    #[ORM\Column(type: 'date', nullable: true)]
+    private ?\DateTimeInterface $lastTrialStartDate = null;
+
+    #[ORM\Column(length: 50, nullable: true, enumType: SettingsProductEnum::class)]
+    private ?SettingsProductEnum $productBeforeTrial;
+
     public function getId(): ?int
     {
         return $this->id;
@@ -121,4 +130,40 @@ class Settings
 
         return $this;
     }
+
+    public function isTrialActive(): ?bool
+    {
+        return $this->trialActive;
+    }
+
+    public function setTrialActive(?bool $trialActive): self
+    {
+        $this->trialActive = $trialActive;
+
+        return $this;
+    }
+
+    public function getlLastTrialStartDate(): ?\DateTimeInterface
+    {
+        return $this->lastTrialStartDate;
+    }
+
+    public function setLastTrialStartDate(?\DateTimeInterface $lastTrialStartDate): self
+    {
+        $this->lastTrialStartDate = $lastTrialStartDate;
+
+        return $this;
+    }
+
+    public function getProductBeforeTrial(): ?SettingsProductEnum
+    {
+        return $this->productBeforeTrial;
+    }
+
+    public function setProductBeforeTrial(?SettingsProductEnum $productBeforeTrial): self
+    {
+        $this->productBeforeTrial = $productBeforeTrial;
+
+        return $this;
+    }
 }

+ 3 - 0
src/Service/Organization/OrganizationProfileCreator.php

@@ -22,6 +22,7 @@ class OrganizationProfileCreator
         private Module $module,
         private Tree $tree,
         private OrganizationUtils $organizationUtils,
+        private Trial $trialService
     ) {
     }
 
@@ -38,6 +39,8 @@ class OrganizationProfileCreator
         $organizationProfile->setParametersId($organization->getParameters()->getId());
         $organizationProfile->setLegalStatus($organization->getLegalStatus());
         $organizationProfile->setPrincipalType($organization->getPrincipalType());
+        $organizationProfile->setTrialActive($organization->getSettings()->isTrialActive());
+        $organizationProfile->setTrialCountDown($this->trialService->getTrialCountdown($organization->getSettings()->getlLastTrialStartDate()));
         $organizationProfile->setHasChildren($organization->getNetworkOrganizationChildren()->count() > 1);
         $organizationProfile->setShowAdherentList(
             $organization->getParameters()->getShowAdherentList()

+ 37 - 0
src/Service/Organization/Trial.php

@@ -0,0 +1,37 @@
+<?php
+
+declare(strict_types=1);
+
+namespace App\Service\Organization;
+
+use App\Service\Utils\DatesUtils;
+
+/**
+ * Class OrganizationProfileCreator : Service contenant les manipulations associés à la ressource OrganizationProfile.
+ */
+class Trial
+{
+    public function __construct(
+        private DatesUtils $datesUtils
+    )
+    {
+    }
+
+    /**
+     * Retourne le décompte sur 30 jours du dernier lancement d'essai
+     * @param $trialStartDate
+     * @return int
+     */
+    public function getTrialCountdown(?\DateTimeInterface $trialStartDate){
+        if(empty($trialStartDate)){
+            return 0;
+        }
+
+        $daysSince = $this->datesUtils::daysSince($trialStartDate);
+        if($daysSince > 30){
+            return 0;
+        }
+
+        return 30 - $daysSince;
+    }
+}