|
|
@@ -13,11 +13,17 @@ use Doctrine\ORM\Mapping as ORM;
|
|
|
use JetBrains\PhpStorm\Pure;
|
|
|
use Symfony\Component\Security\Core\User\UserInterface;
|
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
|
|
+use Symfony\Component\Serializer\Annotation\Groups;
|
|
|
|
|
|
/**
|
|
|
* Personne physique ou morale
|
|
|
*/
|
|
|
-#[ApiResource]
|
|
|
+#[ApiResource(
|
|
|
+ collectionOperations: [],
|
|
|
+ itemOperations: [
|
|
|
+ "get" => ["security" => "is_granted('ROLE_USERS_VIEW')"],
|
|
|
+ ]
|
|
|
+)]
|
|
|
#[ORM\Entity(repositoryClass: PersonRepository::class)]
|
|
|
class Person implements UserInterface
|
|
|
{
|
|
|
@@ -35,14 +41,20 @@ class Person implements UserInterface
|
|
|
private ?string $password = null;
|
|
|
|
|
|
#[ORM\Column(length: 255, nullable: true)]
|
|
|
+ #[Groups(["access_people_ref", "access_address"])]
|
|
|
private ?string $name = null;
|
|
|
|
|
|
#[ORM\Column(length: 255, nullable: true)]
|
|
|
+ #[Groups(["access_people_ref", "access_address"])]
|
|
|
private ?string $givenName = null;
|
|
|
|
|
|
#[ORM\ManyToMany(targetEntity: ContactPoint::class, mappedBy: 'person')]
|
|
|
private Collection $contactPoints;
|
|
|
|
|
|
+ #[ORM\OneToMany( mappedBy: 'person', targetEntity: PersonAddressPostal::class, orphanRemoval: true)]
|
|
|
+ #[Groups("access_address")]
|
|
|
+ private Collection $personAddressPostal;
|
|
|
+
|
|
|
#[ORM\Column(nullable: true)]
|
|
|
#[Assert\Choice(callback: ['\App\Enum\Person\GenderEnum', 'toArray'], message: 'invalid-gender')]
|
|
|
private ?string $gender = null;
|
|
|
@@ -51,9 +63,13 @@ class Person implements UserInterface
|
|
|
#[ORM\JoinColumn(referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
|
|
|
private ?File $image = null;
|
|
|
|
|
|
+ #[ORM\Column(options: ['default' => true])]
|
|
|
+ private bool $isPhysical = true;
|
|
|
+
|
|
|
#[Pure] public function __construct()
|
|
|
{
|
|
|
$this->contactPoints = new ArrayCollection();
|
|
|
+ $this->personAddressPostal = new ArrayCollection();
|
|
|
}
|
|
|
|
|
|
public function getId(): ?int
|
|
|
@@ -189,4 +205,44 @@ class Person implements UserInterface
|
|
|
{
|
|
|
return $this->image;
|
|
|
}
|
|
|
+
|
|
|
+ public function getPersonAddressPostal(): Collection
|
|
|
+ {
|
|
|
+ return $this->personAddressPostal;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function addPersonAddressPostal(PersonAddressPostal $personAddressPostal): self
|
|
|
+ {
|
|
|
+ if (!$this->personAddressPostal->contains($personAddressPostal)) {
|
|
|
+ $this->personAddressPostal[] = $personAddressPostal;
|
|
|
+ $personAddressPostal->setPerson($this);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function removePersonAddressPostal(PersonAddressPostal $personAddressPostal): self
|
|
|
+ {
|
|
|
+ if ($this->personAddressPostal->removeElement($personAddressPostal)) {
|
|
|
+ // set the owning side to null (unless already changed)
|
|
|
+ if ($personAddressPostal->getPerson() === $this) {
|
|
|
+ $personAddressPostal->setPerson(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getIsPhysical(): ?bool
|
|
|
+ {
|
|
|
+ return $this->isPhysical;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function setAdminAccess(bool $isPhysical): self
|
|
|
+ {
|
|
|
+ $this->isPhysical = $isPhysical;
|
|
|
+
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
}
|