ソースを参照

nouvelle entité

Vincent 1 年間 前
コミット
46124f1040

+ 1 - 0
config/opentalent/products.yaml

@@ -3,6 +3,7 @@ parameters:
       Core:
         entities:
           - AccessProfile
+          - AccessPreference
           - Tips
           - Notification
           - NotificationUser

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

@@ -54,6 +54,7 @@ use App\Filter\ApiPlatform\Person\FullNameFilter;
 use App\Filter\ApiPlatform\Utils\InFilter;
 use App\Repository\Access\AccessRepository;
 // use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
+use App\Entity\Access\AccessPreference;
 use Doctrine\Common\Collections\ArrayCollection;
 use Doctrine\Common\Collections\Collection;
 use Doctrine\ORM\Mapping as ORM;
@@ -300,6 +301,9 @@ class Access implements UserInterface, PasswordAuthenticatedUserInterface
     #[ORM\InverseJoinColumn(name: 'tag_id', referencedColumnName: 'id')]
     private Collection $tags;
 
+    #[ORM\OneToOne(mappedBy: 'access', cascade: ['persist'], fetch: 'EAGER', orphanRemoval: true)]
+    private ?AccessPreference $preferences;
+
     #[Pure]
     public function __construct()
     {
@@ -2138,4 +2142,19 @@ class Access implements UserInterface, PasswordAuthenticatedUserInterface
 
         return $this;
     }
+
+    public function setPreferences(AccessPreference $preferences = null)
+    {
+        if(!is_null($preferences)){
+            $preferences->setAccess($this);
+        }
+        $this->preferences = $preferences;
+
+        return $this;
+    }
+
+    public function getPreferences()
+    {
+        return $this->preferences;
+    }
 }

+ 70 - 0
src/Entity/Access/AccessPreference.php

@@ -0,0 +1,70 @@
+<?php
+
+declare(strict_types=1);
+
+namespace App\Entity\Access;
+
+// use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
+use ApiPlatform\Metadata\ApiResource;
+use ApiPlatform\Metadata\Get;
+use ApiPlatform\Metadata\Put;
+use Doctrine\ORM\Mapping as ORM;
+
+/**
+ * Préférence pour un Access
+ */
+// #[Auditable]
+#[ORM\Entity]
+#[ApiResource(
+    operations: [
+        new Get(
+            security: 'object.getAccess().getId() == user.getId()'
+        ),
+        new Put(
+            security: 'object.getAccess().getId() == user.getId()'
+        )
+    ]
+)]
+class AccessPreference
+{
+    #[ORM\Id]
+    #[ORM\Column]
+    #[ORM\GeneratedValue]
+    private ?int $id = null;
+
+    #[ORM\OneToOne(inversedBy: 'preferences', fetch: 'EAGER')]
+    #[ORM\JoinColumn(nullable: true)]
+    private Access $access;
+
+    #[ORM\Column(options: ['default' => true])]
+    private bool $messageReport = true;
+
+    public function getId(): ?int
+    {
+        return $this->id;
+    }
+
+    public function getAccess(): ?Access
+    {
+        return $this->access;
+    }
+
+    public function setAccess(?Access $access): self
+    {
+        $this->access = $access;
+
+        return $this;
+    }
+
+    public function getMessageReport(): ?bool
+    {
+        return $this->messageReport;
+    }
+
+    public function setMessageReport(bool $messageReport): self
+    {
+        $this->messageReport = $messageReport;
+
+        return $this;
+    }
+}