| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- <?php
- declare(strict_types=1);
- namespace App\Entity\Person;
- use ApiPlatform\Core\Annotation\ApiResource;
- use App\Entity\Core\ContactPoint;
- use App\Entity\Core\File;
- use App\Repository\Person\PersonRepository;
- use Doctrine\Common\Collections\ArrayCollection;
- use Doctrine\Common\Collections\Collection;
- 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(
- collectionOperations: [],
- itemOperations: [
- "get" => ["security" => "is_granted('ROLE_USERS_VIEW')"],
- ]
- )]
- #[ORM\Entity(repositoryClass: PersonRepository::class)]
- class Person implements UserInterface
- {
- #[ORM\Id]
- #[ORM\Column]
- #[ORM\GeneratedValue]
- private ?int $id = null;
- #[ORM\Column(length: 180, unique: true, nullable: true)]
- private ?string $username = null;
- private array $roles = [];
- #[ORM\Column(nullable: true)]
- 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;
- #[ORM\ManyToOne(inversedBy: 'personImages')]
- #[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
- {
- return $this->id;
- }
- public function getUsername(): ?string
- {
- return (string) $this->username;
- }
- public function getUserIdentifier(): ?string
- {
- return (string) $this->username;
- }
- public function setUsername(?string $username): self
- {
- $this->username = $username;
- return $this;
- }
- public function getRoles(): array
- {
- $roles = $this->roles;
- // guarantee every user at least has ROLE_USER
- $roles[] = 'ROLE_USER';
- return array_unique($roles);
- }
- public function setRoles(array $roles): self
- {
- $this->roles = $roles;
- return $this;
- }
- public function getPassword(): ?string
- {
- return (string) $this->password;
- }
- public function setPassword(?string $password): self
- {
- $this->password = $password;
- return $this;
- }
- public function getSalt(): ?string
- {
- return null;
- // not needed when using the "bcrypt" algorithm in security.yaml
- }
- public function eraseCredentials()
- {
- // If you store any temporary, sensitive data on the user, clear it here
- // $this->plainPassword = null;
- }
- public function getName(): ?string
- {
- return $this->name;
- }
- public function setName(?string $name): self
- {
- $this->name = $name;
- return $this;
- }
- public function getGivenName(): ?string
- {
- return $this->givenName;
- }
- public function setGivenName(?string $givenName): self
- {
- $this->givenName = $givenName;
- return $this;
- }
- public function setGender(?string $gender): self
- {
- $this->gender = $gender;
- return $this;
- }
- public function getGender(): ?string
- {
- return $this->gender;
- }
- /**
- * @return Collection|ContactPoint[]
- */
- public function getContactPoints(): Collection
- {
- return $this->contactPoints;
- }
- public function addContactPoint(ContactPoint $contactPoint): self
- {
- if (!$this->contactPoints->contains($contactPoint)) {
- $this->contactPoints[] = $contactPoint;
- $contactPoint->addPerson($this);
- }
- return $this;
- }
- public function removeContactPoint(ContactPoint $contactPoint): self
- {
- if ($this->contactPoints->removeElement($contactPoint)) {
- $contactPoint->removePerson($this);
- }
- return $this;
- }
- public function setImage(?File $image):self
- {
- $this->image = $image;
- return $this;
- }
- public function getImage(): ?File
- {
- 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;
- }
- }
|