Browse Source

factor createDate and createdBy in a new trait

Olivier Massot 1 year ago
parent
commit
869e745f47

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

@@ -50,6 +50,7 @@ use App\Entity\Product\Equipment;
 use App\Entity\Product\EquipmentLoan;
 use App\Entity\Product\EquipmentRepair;
 use App\Entity\Reward\AccessReward;
+use App\Entity\Traits\CreatedOnAndByTrait;
 use App\Filter\ApiPlatform\Person\FullNameFilter;
 use App\Filter\ApiPlatform\Utils\InFilter;
 use App\Repository\Access\AccessRepository;
@@ -79,6 +80,8 @@ use Symfony\Component\Serializer\Annotation\Groups;
 #[ApiFilter(GroupFilter::class, arguments: ['whitelist' => ['access_people_ref']])]
 class Access implements UserInterface, PasswordAuthenticatedUserInterface
 {
+    use CreatedOnAndByTrait;
+
     #[ORM\Id]
     #[ORM\Column]
     #[ORM\GeneratedValue]
@@ -300,12 +303,6 @@ class Access implements UserInterface, PasswordAuthenticatedUserInterface
     #[ORM\InverseJoinColumn(name: 'tag_id', referencedColumnName: 'id')]
     private Collection $tags;
 
-    #[ORM\Column(type: 'date', nullable: true)]
-    private ?\DateTimeInterface $createDate = null;
-
-    #[ORM\Column(nullable: true)]
-    private ?int $createdBy = null;
-
     #[Pure]
     public function __construct()
     {
@@ -2144,26 +2141,4 @@ class Access implements UserInterface, PasswordAuthenticatedUserInterface
 
         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;
-    }
 }

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

@@ -9,6 +9,7 @@ use App\Entity\Organization\OrganizationAddressPostal;
 use App\Entity\Person\PersonAddressPostal;
 use App\Entity\Place\Place;
 // use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
+use App\Entity\Traits\CreatedOnAndByTrait;
 use App\Repository\Core\AddressPostalRepository;
 use Doctrine\Common\Collections\ArrayCollection;
 use Doctrine\Common\Collections\Collection;
@@ -27,6 +28,8 @@ use Symfony\Component\Serializer\Annotation\Groups;
 #[ORM\Entity(repositoryClass: AddressPostalRepository::class)]
 class AddressPostal
 {
+    use CreatedOnAndByTrait;
+
     #[ORM\Id]
     #[ORM\Column]
     #[ORM\GeneratedValue]
@@ -78,12 +81,6 @@ 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();
@@ -255,26 +252,4 @@ 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;
-    }
 }

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

@@ -9,6 +9,7 @@ use App\Entity\Organization\Organization;
 use App\Entity\Person\Person;
 use App\Entity\Place\Place;
 // use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
+use App\Entity\Traits\CreatedOnAndByTrait;
 use App\Enum\Core\ContactPointTypeEnum;
 use App\Repository\Core\ContactPointRepository;
 use App\Validator\Core as OpentalentAssert;
@@ -32,6 +33,8 @@ use Symfony\Component\Validator\Constraints as Assert;
 #[OpentalentAssert\ContactPoint]
 class ContactPoint
 {
+    use CreatedOnAndByTrait;
+
     #[ORM\Id]
     #[ORM\Column]
     #[ORM\GeneratedValue]
@@ -83,12 +86,6 @@ 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()
     {
@@ -296,26 +293,4 @@ 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;
-    }
 }

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

@@ -7,6 +7,7 @@ namespace App\Entity\Network;
 use ApiPlatform\Metadata\ApiResource;
 use App\Attribute\DateTimeConstraintAware;
 use App\Entity\Organization\Organization;
+use App\Entity\Traits\CreatedOnAndByTrait;
 use App\Repository\Network\NetworkOrganizationRepository;
 // use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
 use Doctrine\ORM\Mapping as ORM;
@@ -25,6 +26,8 @@ use Symfony\Component\Serializer\Annotation\Groups;
 #[DateTimeConstraintAware(startDateFieldName: 'startDate', endDateFieldName: 'endDate')]
 class NetworkOrganization
 {
+    use CreatedOnAndByTrait;
+
     #[ORM\Id]
     #[ORM\Column]
     #[ORM\GeneratedValue]
@@ -53,12 +56,6 @@ 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;
@@ -138,26 +135,4 @@ 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;
-    }
 }

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

@@ -35,6 +35,7 @@ use App\Entity\Place\Place;
 use App\Entity\Product\Equipment;
 use App\Entity\Product\Intangible;
 use App\Entity\Reward\Reward;
+use App\Entity\Traits\CreatedOnAndByTrait;
 use App\Enum\Organization\CategoryEnum;
 use App\Enum\Organization\LegalEnum;
 use App\Enum\Organization\OpcaEnum;
@@ -63,6 +64,8 @@ use JetBrains\PhpStorm\Pure;
 #[ORM\Entity(repositoryClass: OrganizationRepository::class)]
 class Organization
 {
+    use CreatedOnAndByTrait;
+
     #[ORM\Id]
     #[ORM\Column]
     #[ORM\GeneratedValue]
@@ -105,12 +108,10 @@ class Organization
     #[ORM\Column(type: 'text', nullable: true)]
     private ?string $description = null;
 
+    // TODO: utile ce champs? ou c'est juste un doublon du champs 'createDate'?
     #[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;
 
@@ -554,17 +555,6 @@ 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;

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

@@ -7,6 +7,7 @@ namespace App\Entity\Organization;
 use ApiPlatform\Metadata\ApiResource;
 use App\Attribute\OrganizationDefaultValue;
 use App\Entity\Core\AddressPostal;
+use App\Entity\Traits\CreatedOnAndByTrait;
 use App\Enum\Organization\AddressPostalOrganizationTypeEnum;
 use App\Repository\Organization\OrganizationAddressPostalRepository;
 // use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
@@ -33,6 +34,8 @@ use Symfony\Component\Validator\Constraints as Assert;
 #[OpentalentAssert\OrganizationAddressPostal]
 class OrganizationAddressPostal
 {
+    use CreatedOnAndByTrait;
+
     #[ORM\Id]
     #[ORM\Column]
     #[ORM\GeneratedValue]
@@ -53,12 +56,6 @@ 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;
@@ -99,26 +96,4 @@ 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;
-    }
 }

+ 3 - 17
src/Entity/Organization/Settings.php

@@ -5,6 +5,7 @@ declare(strict_types=1);
 namespace App\Entity\Organization;
 
 use ApiPlatform\Metadata\ApiResource;
+use App\Entity\Traits\CreatedOnAndByTrait;
 use App\Enum\Organization\SettingsProductEnum;
 use App\Repository\Organization\SettingsRepository;
 // use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
@@ -18,6 +19,8 @@ use Doctrine\ORM\Mapping as ORM;
 #[ORM\Entity(repositoryClass: SettingsRepository::class)]
 class Settings
 {
+    use CreatedOnAndByTrait;
+
     #[ORM\Id]
     #[ORM\Column]
     #[ORM\GeneratedValue]
@@ -41,12 +44,6 @@ 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;
@@ -138,15 +135,4 @@ class Settings
         $this->createDate = $createDate;
         return $this;
     }
-
-    public function getCreatedBy(): ?int
-    {
-        return $this->createdBy;
-    }
-
-    public function setCreatedBy(?int $createdBy): self
-    {
-        $this->createdBy = $createdBy;
-        return $this;
-    }
 }

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

@@ -11,6 +11,7 @@ use App\Entity\Core\BankAccount;
 use App\Entity\Core\ContactPoint;
 use App\Entity\Core\Country;
 use App\Entity\Core\File;
+use App\Entity\Traits\CreatedOnAndByTrait;
 use App\Enum\Person\GenderEnum;
 use App\Repository\Person\PersonRepository;
 // use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
@@ -30,6 +31,8 @@ use Symfony\Component\Serializer\Annotation\Groups;
 #[ORM\Entity(repositoryClass: PersonRepository::class)]
 class Person implements UserInterface, PasswordAuthenticatedUserInterface
 {
+    use CreatedOnAndByTrait;
+
     #[ORM\Id]
     #[ORM\Column]
     #[ORM\GeneratedValue]
@@ -110,12 +113,6 @@ class Person implements UserInterface, PasswordAuthenticatedUserInterface
     #[ORM\Column(type: "json", nullable: true)]
     private array $confidentiality = [];
 
-    #[ORM\Column(type: 'date', nullable: true)]
-    private ?\DateTimeInterface $createDate = null;
-
-    #[ORM\Column(nullable: true)]
-    private ?int $createdBy = null;
-
     #[Pure]
     public function __construct()
     {
@@ -619,27 +616,4 @@ class Person implements UserInterface, PasswordAuthenticatedUserInterface
         $this->confidentiality = $confidentiality;
         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;
-    }
-
 }

+ 40 - 0
src/Entity/Traits/CreatedOnAndByTrait.php

@@ -0,0 +1,40 @@
+<?php
+declare(strict_types=1);
+
+namespace App\Entity\Traits;
+
+use Doctrine\ORM\Mapping as ORM;
+
+/**
+ * Add the 'createDate' and 'createdBy' properties to an entity.
+ */
+trait CreatedOnAndByTrait
+{
+    #[ORM\Column(type: 'datetime', nullable: true)]
+    private ?\DateTimeInterface $createDate = null;
+
+    #[ORM\Column(nullable: true)]
+    private ?int $createdBy = null;
+
+    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;
+    }
+}