Forráskód Böngészése

organization creation : complete author and creationDate fields

Olivier Massot 1 éve
szülő
commit
9b8b06d273

+ 25 - 0
src/ApiResources/Organization/OrganizationCreationRequest.php

@@ -135,6 +135,9 @@ class OrganizationCreationRequest
      */
     private string $status = self::STATUS_PENDING;
 
+    private ?\DateTimeInterface $creationDate = null;
+    private ?int $authorId = null;
+
     /**
      * For testing purposes only
      * @var bool
@@ -383,6 +386,28 @@ class OrganizationCreationRequest
         return $this;
     }
 
+    public function getCreationDate(): ?\DateTime
+    {
+        return $this->creationDate;
+    }
+
+    public function setCreationDate(?\DateTime $creationDate): self
+    {
+        $this->creationDate = $creationDate;
+        return $this;
+    }
+
+    public function getAuthorId(): ?int
+    {
+        return $this->authorId;
+    }
+
+    public function setAuthorId(?int $authorId): self
+    {
+        $this->authorId = $authorId;
+        return $this;
+    }
+
     public function isAsync(): bool
     {
         return $this->async;

+ 28 - 0
src/Entity/Access/Access.php

@@ -300,6 +300,12 @@ class Access implements UserInterface, PasswordAuthenticatedUserInterface
     #[ORM\InverseJoinColumn(name: 'tag_id', referencedColumnName: 'id')]
     private Collection $tags;
 
+    #[ORM\Column(type: 'date', nullable: true)]
+    private ?\DateTimeInterface $creationDate = null;
+
+    #[ORM\Column(nullable: true)]
+    private ?int $createdBy = null;
+
     #[Pure]
     public function __construct()
     {
@@ -2138,4 +2144,26 @@ class Access implements UserInterface, PasswordAuthenticatedUserInterface
 
         return $this;
     }
+
+    public function getCreationDate(): ?\DateTimeInterface
+    {
+        return $this->creationDate;
+    }
+
+    public function setCreationDate(?\DateTimeInterface $creationDate): self
+    {
+        $this->creationDate = $creationDate;
+        return $this;
+    }
+
+    public function getCreatedBy(): ?int
+    {
+        return $this->createdBy;
+    }
+
+    public function setCreatedBy(?int $createdBy): self
+    {
+        $this->createdBy = $createdBy;
+        return $this;
+    }
 }

+ 28 - 0
src/Entity/Core/AddressPostal.php

@@ -78,6 +78,12 @@ class AddressPostal
     #[ORM\OneToMany(mappedBy: 'addressPostal', targetEntity: Place::class)]
     private Collection $places;
 
+    #[ORM\Column(type: 'date', nullable: true)]
+    private ?\DateTimeInterface $createDate = null;
+
+    #[ORM\Column(nullable: true)]
+    private ?int $createdBy = null;
+
     public function __construct()
     {
         $this->places = new ArrayCollection();
@@ -249,4 +255,26 @@ class AddressPostal
 
         return $this;
     }
+
+    public function getCreateDate(): ?\DateTimeInterface
+    {
+        return $this->createDate;
+    }
+
+    public function setCreateDate(?\DateTimeInterface $createDate): self
+    {
+        $this->createDate = $createDate;
+        return $this;
+    }
+
+    public function getCreatedBy(): ?int
+    {
+        return $this->createdBy;
+    }
+
+    public function setCreatedBy(?int $createdBy): self
+    {
+        $this->createdBy = $createdBy;
+        return $this;
+    }
 }

+ 28 - 0
src/Entity/Core/ContactPoint.php

@@ -83,6 +83,12 @@ class ContactPoint
     #[ORM\InverseJoinColumn(name: 'place_id', referencedColumnName: 'id')]
     private Collection $place;
 
+    #[ORM\Column(type: 'date', nullable: true)]
+    private ?\DateTimeInterface $createDate = null;
+
+    #[ORM\Column(nullable: true)]
+    private ?int $createdBy = null;
+
     #[Pure]
     public function __construct()
     {
@@ -290,4 +296,26 @@ class ContactPoint
 
         return $this;
     }
+
+    public function getCreateDate(): ?\DateTimeInterface
+    {
+        return $this->createDate;
+    }
+
+    public function setCreateDate(?\DateTimeInterface $createDate): self
+    {
+        $this->createDate = $createDate;
+        return $this;
+    }
+
+    public function getCreatedBy(): ?int
+    {
+        return $this->createdBy;
+    }
+
+    public function setCreatedBy(?int $createdBy): self
+    {
+        $this->createdBy = $createdBy;
+        return $this;
+    }
 }

+ 28 - 0
src/Entity/Network/NetworkOrganization.php

@@ -53,6 +53,12 @@ class NetworkOrganization
     #[ORM\Column(type: 'date', nullable: true)]
     private ?\DateTimeInterface $endDate = null;
 
+    #[ORM\Column(type: 'date', nullable: true)]
+    private ?\DateTimeInterface $createDate = null;
+
+    #[ORM\Column(nullable: true)]
+    private ?int $createdBy = null;
+
     public function getId(): ?int
     {
         return $this->id;
@@ -132,4 +138,26 @@ class NetworkOrganization
 
         return $this;
     }
+
+    public function getCreateDate(): ?\DateTimeInterface
+    {
+        return $this->createDate;
+    }
+
+    public function setCreateDate(?\DateTimeInterface $createDate): self
+    {
+        $this->createDate = $createDate;
+        return $this;
+    }
+
+    public function getCreatedBy(): ?int
+    {
+        return $this->createdBy;
+    }
+
+    public function setCreatedBy(?int $createdBy): self
+    {
+        $this->createdBy = $createdBy;
+        return $this;
+    }
 }

+ 14 - 0
src/Entity/Organization/Organization.php

@@ -108,6 +108,9 @@ class Organization
     #[ORM\Column(type: 'date', nullable: true)]
     private ?\DateTimeInterface $creationDate = null;
 
+    #[ORM\Column(nullable: true)]
+    private ?int $createdBy = null;
+
     #[ORM\Column(type: 'date', nullable: true)]
     private ?\DateTimeInterface $declarationDate = null;
 
@@ -551,6 +554,17 @@ class Organization
         return $this;
     }
 
+    public function getCreatedBy(): ?int
+    {
+        return $this->createdBy;
+    }
+
+    public function setCreatedBy(?int $createdBy): self
+    {
+        $this->createdBy = $createdBy;
+        return $this;
+    }
+
     public function getDeclarationDate(): ?\DateTimeInterface
     {
         return $this->declarationDate;

+ 28 - 0
src/Entity/Organization/OrganizationAddressPostal.php

@@ -53,6 +53,12 @@ class OrganizationAddressPostal
     #[Groups('address')]
     private AddressPostalOrganizationTypeEnum $type;
 
+    #[ORM\Column(type: 'date', nullable: true)]
+    private ?\DateTimeInterface $createDate = null;
+
+    #[ORM\Column(nullable: true)]
+    private ?int $createdBy = null;
+
     public function getId(): ?int
     {
         return $this->id;
@@ -93,4 +99,26 @@ class OrganizationAddressPostal
 
         return $this;
     }
+
+    public function getCreateDate(): ?\DateTimeInterface
+    {
+        return $this->createDate;
+    }
+
+    public function setCreateDate(?\DateTimeInterface $createDate): self
+    {
+        $this->createDate = $createDate;
+        return $this;
+    }
+
+    public function getCreatedBy(): ?int
+    {
+        return $this->createdBy;
+    }
+
+    public function setCreatedBy(?int $createdBy): self
+    {
+        $this->createdBy = $createdBy;
+        return $this;
+    }
 }

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

@@ -41,6 +41,12 @@ class Settings
     #[ORM\Column(length: 255, options: ['default' => 'FRANCE'])]
     private string $country;
 
+    #[ORM\Column(type: 'date', nullable: true)]
+    private ?\DateTimeInterface $createDate = null;
+
+    #[ORM\Column(nullable: true)]
+    private ?int $createdBy = null;
+
     public function getId(): ?int
     {
         return $this->id;
@@ -121,4 +127,26 @@ class Settings
 
         return $this;
     }
+
+    public function getCreateDate(): ?\DateTimeInterface
+    {
+        return $this->createDate;
+    }
+
+    public function setCreateDate(?\DateTimeInterface $createDate): self
+    {
+        $this->createDate = $createDate;
+        return $this;
+    }
+
+    public function getCreatedBy(): ?int
+    {
+        return $this->createdBy;
+    }
+
+    public function setCreatedBy(?int $createdBy): self
+    {
+        $this->createdBy = $createdBy;
+        return $this;
+    }
 }

+ 29 - 0
src/Entity/Person/Person.php

@@ -110,6 +110,12 @@ class Person implements UserInterface, PasswordAuthenticatedUserInterface
     #[ORM\Column(type: "json", nullable: true)]
     private array $confidentiality = [];
 
+    #[ORM\Column(type: 'date', nullable: true)]
+    private ?\DateTimeInterface $creationDate = null;
+
+    #[ORM\Column(nullable: true)]
+    private ?int $createdBy = null;
+
     #[Pure]
     public function __construct()
     {
@@ -613,4 +619,27 @@ class Person implements UserInterface, PasswordAuthenticatedUserInterface
         $this->confidentiality = $confidentiality;
         return $this;
     }
+
+    public function getCreationDate(): ?\DateTimeInterface
+    {
+        return $this->creationDate;
+    }
+
+    public function setCreationDate(?\DateTimeInterface $creationDate): self
+    {
+        $this->creationDate = $creationDate;
+        return $this;
+    }
+
+    public function getCreatedBy(): ?int
+    {
+        return $this->createdBy;
+    }
+
+    public function setCreatedBy(?int $createdBy): self
+    {
+        $this->createdBy = $createdBy;
+        return $this;
+    }
+
 }

+ 15 - 0
src/Service/Organization/OrganizationFactory.php

@@ -100,6 +100,9 @@ class OrganizationFactory
 
             // On persiste et on commit, les objets liés seront persistés en cascade
             $this->entityManager->persist($organization);
+
+            dd($organization);
+
             $this->entityManager->flush();
 
             $this->entityManager->commit();
@@ -295,6 +298,8 @@ class OrganizationFactory
         $organization->setLegalStatus($organizationCreationRequest->getLegalStatus());
         $organization->setPrincipalType($organizationCreationRequest->getPrincipalType());
         $organization->setIdentifier($organizationCreationRequest->getIdentifier());
+        $organization->setCreationDate($organizationCreationRequest->getCreationDate());
+        $organization->setCreatedBy($organizationCreationRequest->getAuthorId());
         return $organization;
     }
 
@@ -322,6 +327,8 @@ class OrganizationFactory
     {
         $settings = new Settings();
         $settings->setProduct($organizationCreationRequest->getProduct());
+        $settings->setCreateDate($organizationCreationRequest->getCreationDate());
+        $settings->setCreatedBy($organizationCreationRequest->getAuthorId());
         return $settings;
     }
 
@@ -346,10 +353,14 @@ class OrganizationFactory
         $addressPostal->setPostalCode($organizationCreationRequest->getPostalCode());
         $addressPostal->setAddressCity($organizationCreationRequest->getCity());
         $addressPostal->setAddressCountry($country);
+        $addressPostal->setCreateDate($organizationCreationRequest->getCreationDate());
+        $addressPostal->setCreatedBy($organizationCreationRequest->getAuthorId());
 
         $organizationAddressPostal = new OrganizationAddressPostal();
         $organizationAddressPostal->setAddressPostal($addressPostal);
         $organizationAddressPostal->setType(AddressPostalOrganizationTypeEnum::ADDRESS_HEAD_OFFICE);
+        $organizationAddressPostal->setCreateDate($organizationCreationRequest->getCreationDate());
+        $organizationAddressPostal->setCreatedBy($organizationCreationRequest->getAuthorId());
 
         return $organizationAddressPostal;
     }
@@ -374,6 +385,8 @@ class OrganizationFactory
         $contactPoint->setContactType(ContactPointTypeEnum::PRINCIPAL);
         $contactPoint->setEmail($organizationCreationRequest->getEmail());
         $contactPoint->setTelphone($phoneNumber);
+        $contactPoint->setCreateDate($organizationCreationRequest->getCreationDate());
+        $contactPoint->setCreatedBy($organizationCreationRequest->getAuthorId());
 
         return $contactPoint;
     }
@@ -426,6 +439,8 @@ class OrganizationFactory
         $networkOrganization->setParent($parent);
         $networkOrganization->setNetwork($network);
         $networkOrganization->setStartDate(DatesUtils::new());
+        $networkOrganization->setCreateDate($organizationCreationRequest->getCreationDate());
+        $networkOrganization->setCreatedBy($organizationCreationRequest->getAuthorId());
 
         return $networkOrganization;
     }

+ 10 - 0
src/State/Processor/Organization/OrganizationCreationRequestProcessor.php

@@ -8,8 +8,11 @@ use ApiPlatform\Metadata\Operation;
 use ApiPlatform\Metadata\Post;
 use ApiPlatform\State\ProcessorInterface;
 use App\ApiResources\Organization\OrganizationCreationRequest;
+use App\Entity\Access\Access;
 use App\Message\Command\OrganizationCreationCommand;
 use App\Service\Organization\OrganizationFactory;
+use App\Service\Utils\DatesUtils;
+use Symfony\Bundle\SecurityBundle\Security;
 use Symfony\Component\HttpFoundation\Response;
 use Symfony\Component\Messenger\MessageBusInterface;
 
@@ -18,6 +21,7 @@ class OrganizationCreationRequestProcessor implements ProcessorInterface
     public function __construct(
         private readonly MessageBusInterface $messageBus,
         private readonly OrganizationFactory $organizationFactory,
+        private Security $security,
     ) {}
 
     /**
@@ -33,6 +37,12 @@ class OrganizationCreationRequestProcessor implements ProcessorInterface
             throw new \RuntimeException('not supported', Response::HTTP_METHOD_NOT_ALLOWED);
         }
 
+        /** @var Access $access */
+        $access = $this->security->getUser();
+
+        $organizationCreationRequest->setCreationDate(DatesUtils::new());
+        $organizationCreationRequest->setAuthorId($access?->getId());
+
         if ($organizationCreationRequest->isAsync()) {
             // Send the export request to Messenger (@see App\Message\Handler\OrganizationCreationHandler)
             $this->messageBus->dispatch(