<?php
namespace App\Entity\User;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter;
use App\Entity\Token;
use App\Repository\User\ReferentRepository;
use Doctrine\Common\Annotations\Annotation\IgnoreAnnotation;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Ramsey\Uuid\Doctrine\UuidGenerator;
use Ramsey\Uuid\Uuid;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\SerializedName;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass=ReferentRepository::class)
*
* @ApiResource(
* attributes={
* "normalization_context"={"groups"={
* "Referent:output",
* "Referent:io",
* }},
* "denormalization_context"={"groups"={
* "Referent:input",
* "Referent:io",
* }}
* },
* collectionOperations={
* "get"={
* "method"="GET",
* "path"="/public/referents",
* }
* },
* itemOperations={
* "get"={
* "method"="GET"
* },
* },
* paginationItemsPerPage=1710,
* order={"firstName"="ASC"},
* )
*
*/
class Referent implements UserInterface, PasswordAuthenticatedUserInterface
{
const COMPANY_NAME_OTHER = 'Autres';
/**
* Hook timestampable behavior
* updates createdAt, updatedAt fields
*/
use TimestampableEntity;
/**
* @ORM\Id
* @ORM\Column(type="uuid", unique=true)
* @ORM\CustomIdGenerator(class=UuidGenerator::class)
* @SerializedName("id")
* @Assert\Uuid()
* @Groups({
* "Referent:io",
* "User:output",
* })
*/
private string $id;
/**
* @ORM\Column(type="string", length=37, nullable=true)
* @SerializedName("first_name")
* @Assert\Length(max="37")
* @Assert\Regex("/^[\p{L}\d\s]+$/u", message = "Numbers or special characters are not allowed")
* @Groups({
* "Referent:io",
* "User:output",
* })
*/
private ?string $firstName;
/**
* @ORM\Column(type="string", length=37, nullable=true)
* @SerializedName("last_name")
* @Assert\Length(max="37")
* @Assert\Regex("/^[\p{L}\s]+$/u", message = "Numbers or special characters are not allowed")
* @Groups({
* "Referent:io",
* "User:output",
* })
*/
private ?string $lastName;
/**
* @ORM\Column(type="string", length=10, nullable=true)
* @SerializedName("phone_number")
* @Groups({
* "Referent:io",
* })
*/
private ?string $phoneNumber;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @SerializedName("street")
* @Assert\Length(min="1", max="255")
* @Groups({
* "Referent:io",
* })
*/
private ?string $street = null;
/**
* @ORM\Column(type="string", length=38, nullable=true)
* @SerializedName("complement")
* @Assert\Length(min="1", max="38")
* @Groups({
* "Referent:io",
* "User:output",
* })
*/
private ?string $complement = null;
/**
* @ORM\Column(type="string", length=10, nullable=true)
* @SerializedName("postal_code")
* @Assert\Length(min="5", max="10")
* @Assert\Type(type="numeric")
* @Groups({
* "Referent:io",
* "User:output",
* })
*/
private ?string $postalCode;
/**
* @ORM\Column(type="string", length=38, nullable=true)
* @SerializedName("city")
* @Assert\Length(min="1", max="38")
* @Groups({
* "Referent:io",
* "User:output",
* })
* @Assert\Regex("/^(?!\s*$)(?!.*\d).*$/", message = "Numbers or empty is not allowed")
*/
private ?string $city;
/**
* @ORM\Column(type="boolean", options={"default": 0})
* @SerializedName("is_active")
* @Groups({
* "Referent:io",
* })
* @ApiFilter(BooleanFilter::class)
*/
private bool $isActive = false;
/**
* @ORM\Column(type="string", nullable=true)
* @SerializedName("email")
* @Assert\Email(normalizer="trim")
* @Groups({
* "Referent:io",
* "User:output",
* })
*/
private ?string $email;
/**
* @ORM\Column(type="string")
* @SerializedName("company_name")
* @Groups({
* "Referent:io",
* "User:output",
* })
*/
private string $companyName;
/**
* @ORM\Column(type="string", nullable=true)
* @SerializedName("headquarters_address")
* @Groups({
* "Referent:io",
* "User:output",
* })
*/
private ?string $headquartersAddress;
/**
* @ORM\Column(type="string", nullable=true)
* @SerializedName("society_type")
* @Groups({
* "Referent:io",
* })
*/
private ?string $societyType;
/**
* @ORM\Column(type="float", nullable=true)
* @Groups({
* "Referent:io",
* })
*/
private ?float $capital;
/**
* @ORM\Column(type="string", length=13, nullable=true)
* @SerializedName("intra_community_vat_number")
* @Assert\Length(max="13")
* @Groups({
* "Referent:io",
* })
*/
private ?string $intraCommunityVATNumber;
/**
* @ORM\Column(type="string", nullable=true)
* @SerializedName("commercial_register_number")
* @Groups({
* "Referent:io",
* })
*/
private ?string $commercialRegisterNumber;
/**
* @ORM\OneToMany(targetEntity=Token::class, mappedBy="referent")
*/
private $tokens;
/**
* @ORM\Column(type="json")
*/
private $roles = [];
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $password;
public function __construct()
{
$this->id = Uuid::uuid4();
$this->tokens = new ArrayCollection();
}
public function getId(): ?string
{
return $this->id;
}
public function getFirstName(): ?string
{
return $this->firstName;
}
public function setFirstName(?string $firstName): self
{
$this->firstName = $firstName;
return $this;
}
public function getLastName(): ?string
{
return $this->lastName;
}
public function setLastName(?string $lastName): self
{
$this->lastName = $lastName;
return $this;
}
public function getFullName(): string
{
return $this->getFirstName().' '.$this->getLastName();
}
public function getPhoneNumber(): ?string
{
return $this->phoneNumber;
}
public function setPhoneNumber(?string $phoneNumber): Referent
{
$this->phoneNumber = $phoneNumber;
return $this;
}
public function getStreet(): ?string
{
return $this->street;
}
public function setStreet(?string $street): Referent
{
$this->street = $street;
return $this;
}
public function getComplement(): ?string
{
return $this->complement;
}
public function setComplement(?string $complement): Referent
{
$this->complement = $complement;
return $this;
}
public function getPostalCode(): ?string
{
return $this->postalCode;
}
public function setPostalCode(?string $postalCode): Referent
{
$this->postalCode = $postalCode;
return $this;
}
public function getCity(): ?string
{
return $this->city;
}
public function setCity(?string $city): Referent
{
$this->city = $city;
return $this;
}
public function isActive(): bool
{
return $this->isActive;
}
public function setIsActive(bool $isActive): Referent
{
$this->isActive = $isActive;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(?string $email): Referent
{
$this->email = $email;
return $this;
}
public function getCompanyName(): string
{
return $this->companyName;
}
public function setCompanyName(string $companyName): Referent
{
$this->companyName = $companyName;
return $this;
}
/**
* @return Collection<int, Token>
*/
public function getTokens(): Collection
{
return $this->tokens;
}
public function addToken(Token $token): self
{
if (!$this->tokens->contains($token)) {
$this->tokens[] = $token;
$token->setReferent($this);
}
return $this;
}
public function removeToken(Token $token): self
{
if ($this->tokens->removeElement($token)) {
// set the owning side to null (unless already changed)
if ($token->getReferent() === $this) {
$token->setReferent(null);
}
}
return $this;
}
public function getPassword(): ?string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
public function getRoles(): ?array
{
$roles = $this->roles;
$roles[] = 'ROLE_REFERENT';
return array_unique($roles);
}
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
public function getSalt(): ?string
{
return null;
}
public function getUsername(): string
{
return (string) $this->email;
}
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
}
/**
* @return string|null
*/
public function getHeadquartersAddress(): ?string
{
return $this->headquartersAddress;
}
/**
* @param string|null $headquartersAddress
* @return Referent
*/
public function setHeadquartersAddress(?string $headquartersAddress): Referent
{
$this->headquartersAddress = $headquartersAddress;
return $this;
}
/**
* @return string|null
*/
public function getSocietyType(): ?string
{
return $this->societyType;
}
/**
* @param string|null $societyType
* @return Referent
*/
public function setSocietyType(?string $societyType): Referent
{
$this->societyType = $societyType;
return $this;
}
/**
* @return float|null
*/
public function getCapital(): ?float
{
return $this->capital;
}
/**
* @param float|null $capital
* @return Referent
*/
public function setCapital(?float $capital): Referent
{
$this->capital = $capital;
return $this;
}
/**
* @return string|null
*/
public function getCommercialRegisterNumber(): ?string
{
return $this->commercialRegisterNumber;
}
/**
* @param string|null $commercialRegisterNumber
* @return Referent
*/
public function setCommercialRegisterNumber(?string $commercialRegisterNumber): Referent
{
$this->commercialRegisterNumber = $commercialRegisterNumber;
return $this;
}
/**
* @return string|null
*/
public function getIntraCommunityVATNumber(): ?string
{
return $this->intraCommunityVATNumber;
}
/**
* @param string|null $intraCommunityVATNumber
* @return Referent
*/
public function setIntraCommunityVATNumber(?string $intraCommunityVATNumber): Referent
{
$this->intraCommunityVATNumber = $intraCommunityVATNumber;
return $this;
}
public function getUserIdentifier(): string
{
return (string) $this->email;
}
public function getOpticiens(): ?string
{
return $this->companyName . ' ' . $this->street. ' ' . $this->postalCode. ' ' .$this->city;
}
}