Преглед изворни кода

add Subdomain entity, update parameters

Olivier Massot пре 3 година
родитељ
комит
89ce3b730e

+ 8 - 0
src/Entity/Organization/Parameters.php

@@ -160,6 +160,14 @@ class Parameters
     #[ORM\Column(options: ['default' => false])]
     private bool $sendAttendanceSms = false;
 
+    #[ORM\OneToOne( mappedBy: 'parameters', targetEntity: Subdomain::class)]
+    #[ApiSubresource]
+    private Subdomain $activeSubdomain;
+
+    #[ORM\OneToMany( mappedBy: 'parameters', targetEntity: Subdomain::class)]
+    #[ApiSubresource]
+    private Collection $subdomains;
+
     #[Pure] public function __construct()
     {
         $this->publicationDirectors = new ArrayCollection();

+ 83 - 0
src/Entity/Organization/Subdomain.php

@@ -0,0 +1,83 @@
+<?php
+
+namespace App\Entity\Organization;
+
+use App\Repository\Organization\SubdomainRepository;
+use Doctrine\ORM\Mapping as ORM;
+use ApiPlatform\Core\Annotation\ApiResource;
+
+/**
+ * Sous-domaine enregistré par une organisation
+ */
+#[ApiResource(
+    itemOperations: [
+        'get' => [
+            'security' => '(is_granted("ROLE_ORGANIZATION_VIEW") or is_granted("ROLE_ORGANIZATION")) and object.getOrganization().getId() == user.getOrganization().getId()'
+        ],
+        'put' => [
+            'security' => 'is_granted("ROLE_ORGANIZATION") and object.getOrganization().getId() == user.getOrganization().getId()'
+        ]
+    ]
+)]
+#[ORM\Entity(repositoryClass: SubdomainRepository::class)]
+class Subdomain
+{
+    #[ORM\Id]
+    #[ORM\Column]
+    #[ORM\GeneratedValue]
+    private ?int $id = null;
+
+    #[ORM\ManyToOne(inversedBy: 'subdomains')]
+    private Parameters $parameters;
+
+    #[ORM\Column(length: 60, nullable: false)]
+    private string $subdomain;
+
+    /**
+     * @return int|null
+     */
+    public function getId(): ?int
+    {
+        return $this->id;
+    }
+
+    /**
+     * @param int|null $id
+     */
+    public function setId(?int $id): void
+    {
+        $this->id = $id;
+    }
+
+    /**
+     * @return Parameters
+     */
+    public function getParameters(): Parameters
+    {
+        return $this->parameters;
+    }
+
+    /**
+     * @param Parameters $parameters
+     */
+    public function setParameters(Parameters $parameters): void
+    {
+        $this->parameters = $parameters;
+    }
+
+    /**
+     * @return string
+     */
+    public function getSubdomain(): string
+    {
+        return $this->subdomain;
+    }
+
+    /**
+     * @param string $subdomain
+     */
+    public function setSubdomain(string $subdomain): void
+    {
+        $this->subdomain = $subdomain;
+    }
+}

+ 22 - 0
src/Repository/Organization/SubdomainRepository.php

@@ -0,0 +1,22 @@
+<?php
+declare(strict_types=1);
+
+namespace App\Repository\Organization;
+
+use App\Entity\Organization\Subdomain;
+use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
+use Doctrine\Persistence\ManagerRegistry;
+
+/**
+ * @method Subdomain|null find($id, $lockMode = null, $lockVersion = null)
+ * @method Subdomain|null findOneBy(array $criteria, array $orderBy = null)
+ * @method Subdomain[]    findAll()
+ * @method Subdomain[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
+ */
+class SubdomainRepository extends ServiceEntityRepository
+{
+    public function __construct(ManagerRegistry $registry)
+    {
+        parent::__construct($registry, Subdomain::class);
+    }
+}