src/Entity/User/Referent.php line 53

Open in your IDE?
  1. <?php
  2. namespace App\Entity\User;
  3. use ApiPlatform\Core\Annotation\ApiFilter;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter;
  6. use App\Entity\Token;
  7. use App\Repository\User\ReferentRepository;
  8. use Doctrine\Common\Annotations\Annotation\IgnoreAnnotation;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\Common\Collections\Collection;
  11. use Doctrine\ORM\Mapping as ORM;
  12. use Gedmo\Timestampable\Traits\TimestampableEntity;
  13. use Ramsey\Uuid\Doctrine\UuidGenerator;
  14. use Ramsey\Uuid\Uuid;
  15. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  16. use Symfony\Component\Security\Core\User\UserInterface;
  17. use Symfony\Component\Serializer\Annotation\Groups;
  18. use Symfony\Component\Serializer\Annotation\SerializedName;
  19. use Symfony\Component\Validator\Constraints as Assert;
  20. /**
  21.  * @ORM\Entity(repositoryClass=ReferentRepository::class)
  22.  *
  23.  * @ApiResource(
  24.  *     attributes={
  25.  *          "normalization_context"={"groups"={
  26.  *              "Referent:output",
  27.  *              "Referent:io",
  28.  *          }},
  29.  *          "denormalization_context"={"groups"={
  30.  *              "Referent:input",
  31.  *              "Referent:io",
  32.  *          }}
  33.  *      },
  34.  *     collectionOperations={
  35.  *          "get"={
  36.  *              "method"="GET",
  37.  *              "path"="/public/referents",
  38.  *          }
  39.  *     },
  40.  *     itemOperations={
  41.  *          "get"={
  42.  *              "method"="GET"
  43.  *          },
  44.  *      },
  45.  *     paginationItemsPerPage=1710,
  46.  *     order={"firstName"="ASC"},
  47.  * )
  48.  *
  49.  */
  50. class Referent implements UserInterfacePasswordAuthenticatedUserInterface
  51. {
  52.     const COMPANY_NAME_OTHER 'Autres';
  53.     /**
  54.      * Hook timestampable behavior
  55.      * updates createdAt, updatedAt fields
  56.      */
  57.     use TimestampableEntity;
  58.     /**
  59.      * @ORM\Id
  60.      * @ORM\Column(type="uuid", unique=true)
  61.      * @ORM\CustomIdGenerator(class=UuidGenerator::class)
  62.      * @SerializedName("id")
  63.      * @Assert\Uuid()
  64.      * @Groups({
  65.      *     "Referent:io",
  66.      *     "User:output",
  67.      * })
  68.      */
  69.     private string $id;
  70.     /**
  71.      * @ORM\Column(type="string", length=37, nullable=true)
  72.      * @SerializedName("first_name")
  73.      * @Assert\Length(max="37")
  74.      * @Assert\Regex("/^[\p{L}\d\s]+$/u", message = "Numbers or special characters are not allowed")
  75.      * @Groups({
  76.      *     "Referent:io",
  77.      *     "User:output",
  78.      * })
  79.      */
  80.     private ?string $firstName;
  81.     /**
  82.      * @ORM\Column(type="string", length=37, nullable=true)
  83.      * @SerializedName("last_name")
  84.      * @Assert\Length(max="37")
  85.      * @Assert\Regex("/^[\p{L}\s]+$/u", message = "Numbers or special characters are not allowed")
  86.      * @Groups({
  87.      *     "Referent:io",
  88.      *     "User:output",
  89.      * })
  90.      */
  91.     private ?string $lastName;
  92.     /**
  93.      * @ORM\Column(type="string", length=10, nullable=true)
  94.      * @SerializedName("phone_number")
  95.      * @Groups({
  96.      *     "Referent:io",
  97.      * })
  98.      */
  99.     private ?string $phoneNumber;
  100.     /**
  101.      * @ORM\Column(type="string", length=255, nullable=true)
  102.      * @SerializedName("street")
  103.      * @Assert\Length(min="1", max="255")
  104.      * @Groups({
  105.      *     "Referent:io",
  106.      * })
  107.      */
  108.     private ?string $street null;
  109.     /**
  110.      * @ORM\Column(type="string", length=38, nullable=true)
  111.      * @SerializedName("complement")
  112.      * @Assert\Length(min="1", max="38")
  113.      * @Groups({
  114.      *     "Referent:io",
  115.      *     "User:output",
  116.      * })
  117.      */
  118.     private ?string $complement null;
  119.     /**
  120.      * @ORM\Column(type="string", length=10, nullable=true)
  121.      * @SerializedName("postal_code")
  122.      * @Assert\Length(min="5", max="10")
  123.      * @Assert\Type(type="numeric")
  124.      * @Groups({
  125.      *     "Referent:io",
  126.      *     "User:output",
  127.      * })
  128.      */
  129.     private ?string $postalCode;
  130.     /**
  131.      * @ORM\Column(type="string", length=38, nullable=true)
  132.      * @SerializedName("city")
  133.      * @Assert\Length(min="1", max="38")
  134.      * @Groups({
  135.      *     "Referent:io",
  136.      *     "User:output",
  137.      * })
  138.      * @Assert\Regex("/^(?!\s*$)(?!.*\d).*$/", message = "Numbers or empty is not allowed")
  139.      */
  140.     private ?string $city;
  141.     /**
  142.      * @ORM\Column(type="boolean", options={"default": 0})
  143.      * @SerializedName("is_active")
  144.      * @Groups({
  145.      *     "Referent:io",
  146.      * })
  147.      * @ApiFilter(BooleanFilter::class)
  148.      */
  149.     private bool $isActive false;
  150.     /**
  151.      * @ORM\Column(type="string", nullable=true)
  152.      * @SerializedName("email")
  153.      * @Assert\Email(normalizer="trim")
  154.      * @Groups({
  155.      *     "Referent:io",
  156.      *     "User:output",
  157.      * })
  158.      */
  159.     private ?string $email;
  160.     /**
  161.      * @ORM\Column(type="string")
  162.      * @SerializedName("company_name")
  163.      * @Groups({
  164.      *     "Referent:io",
  165.      *     "User:output",
  166.      * })
  167.      */
  168.     private string $companyName;
  169.     /**
  170.      * @ORM\Column(type="string", nullable=true)
  171.      * @SerializedName("headquarters_address")
  172.      * @Groups({
  173.      *     "Referent:io",
  174.      *     "User:output",
  175.      * })
  176.      */
  177.     private ?string $headquartersAddress;
  178.     /**
  179.      * @ORM\Column(type="string", nullable=true)
  180.      * @SerializedName("society_type")
  181.      * @Groups({
  182.      *     "Referent:io",
  183.      * })
  184.      */
  185.     private ?string $societyType;
  186.     /**
  187.      * @ORM\Column(type="float", nullable=true)
  188.      * @Groups({
  189.      *     "Referent:io",
  190.      * })
  191.      */
  192.     private ?float $capital;
  193.     /**
  194.      * @ORM\Column(type="string", length=13, nullable=true)
  195.      * @SerializedName("intra_community_vat_number")
  196.      * @Assert\Length(max="13")
  197.      * @Groups({
  198.      *     "Referent:io",
  199.      * })
  200.      */
  201.     private ?string $intraCommunityVATNumber;
  202.     /**
  203.      * @ORM\Column(type="string", nullable=true)
  204.      * @SerializedName("commercial_register_number")
  205.      * @Groups({
  206.      *     "Referent:io",
  207.      * })
  208.      */
  209.     private ?string $commercialRegisterNumber;
  210.     /**
  211.      * @ORM\OneToMany(targetEntity=Token::class, mappedBy="referent")
  212.      */
  213.     private $tokens;
  214.     /**
  215.      * @ORM\Column(type="json")
  216.      */
  217.     private $roles = [];
  218.     /**
  219.      * @ORM\Column(type="string", length=255, nullable=true)
  220.      */
  221.     private $password;
  222.     public function __construct()
  223.     {
  224.         $this->id Uuid::uuid4();
  225.         $this->tokens = new ArrayCollection();
  226.     }
  227.     public function getId(): ?string
  228.     {
  229.         return $this->id;
  230.     }
  231.     public function getFirstName(): ?string
  232.     {
  233.         return $this->firstName;
  234.     }
  235.     public function setFirstName(?string $firstName): self
  236.     {
  237.         $this->firstName $firstName;
  238.         return $this;
  239.     }
  240.     public function getLastName(): ?string
  241.     {
  242.         return $this->lastName;
  243.     }
  244.     public function setLastName(?string $lastName): self
  245.     {
  246.         $this->lastName $lastName;
  247.         return $this;
  248.     }
  249.     public function getFullName(): string
  250.     {
  251.         return $this->getFirstName().' '.$this->getLastName();
  252.     }
  253.     public function getPhoneNumber(): ?string
  254.     {
  255.         return $this->phoneNumber;
  256.     }
  257.     public function setPhoneNumber(?string $phoneNumber): Referent
  258.     {
  259.         $this->phoneNumber $phoneNumber;
  260.         return $this;
  261.     }
  262.     public function getStreet(): ?string
  263.     {
  264.         return $this->street;
  265.     }
  266.     public function setStreet(?string $street): Referent
  267.     {
  268.         $this->street $street;
  269.         return $this;
  270.     }
  271.     public function getComplement(): ?string
  272.     {
  273.         return $this->complement;
  274.     }
  275.     public function setComplement(?string $complement): Referent
  276.     {
  277.         $this->complement $complement;
  278.         return $this;
  279.     }
  280.     public function getPostalCode(): ?string
  281.     {
  282.         return $this->postalCode;
  283.     }
  284.     public function setPostalCode(?string $postalCode): Referent
  285.     {
  286.         $this->postalCode $postalCode;
  287.         return $this;
  288.     }
  289.     public function getCity(): ?string
  290.     {
  291.         return $this->city;
  292.     }
  293.     public function setCity(?string $city): Referent
  294.     {
  295.         $this->city $city;
  296.         return $this;
  297.     }
  298.     public function isActive(): bool
  299.     {
  300.         return $this->isActive;
  301.     }
  302.     public function setIsActive(bool $isActive): Referent
  303.     {
  304.         $this->isActive $isActive;
  305.         return $this;
  306.     }
  307.     public function getEmail(): ?string
  308.     {
  309.         return $this->email;
  310.     }
  311.     public function setEmail(?string $email): Referent
  312.     {
  313.         $this->email $email;
  314.         return $this;
  315.     }
  316.     public function getCompanyName(): string
  317.     {
  318.         return $this->companyName;
  319.     }
  320.     public function setCompanyName(string $companyName): Referent
  321.     {
  322.         $this->companyName $companyName;
  323.         return $this;
  324.     }
  325.     /**
  326.      * @return Collection<int, Token>
  327.      */
  328.     public function getTokens(): Collection
  329.     {
  330.         return $this->tokens;
  331.     }
  332.     public function addToken(Token $token): self
  333.     {
  334.         if (!$this->tokens->contains($token)) {
  335.             $this->tokens[] = $token;
  336.             $token->setReferent($this);
  337.         }
  338.         return $this;
  339.     }
  340.     public function removeToken(Token $token): self
  341.     {
  342.         if ($this->tokens->removeElement($token)) {
  343.             // set the owning side to null (unless already changed)
  344.             if ($token->getReferent() === $this) {
  345.                 $token->setReferent(null);
  346.             }
  347.         }
  348.         return $this;
  349.     }
  350.     public function getPassword(): ?string
  351.     {
  352.         return $this->password;
  353.     }
  354.     public function setPassword(string $password): self
  355.     {
  356.         $this->password $password;
  357.         return $this;
  358.     }
  359.     public function getRoles(): ?array
  360.     {
  361.         $roles $this->roles;
  362.         $roles[] = 'ROLE_REFERENT';
  363.         return array_unique($roles);
  364.     }
  365.     public function setRoles(array $roles): self
  366.     {
  367.         $this->roles $roles;
  368.         return $this;
  369.     }
  370.     public function getSalt(): ?string
  371.     {
  372.         return null;
  373.     }
  374.     public function getUsername(): string
  375.     {
  376.         return (string) $this->email;
  377.     }
  378.     public function eraseCredentials()
  379.     {
  380.         // If you store any temporary, sensitive data on the user, clear it here
  381.     }
  382.     /**
  383.      * @return string|null
  384.      */
  385.     public function getHeadquartersAddress(): ?string
  386.     {
  387.         return $this->headquartersAddress;
  388.     }
  389.     /**
  390.      * @param string|null $headquartersAddress
  391.      * @return Referent
  392.      */
  393.     public function setHeadquartersAddress(?string $headquartersAddress): Referent
  394.     {
  395.         $this->headquartersAddress $headquartersAddress;
  396.         return $this;
  397.     }
  398.     /**
  399.      * @return string|null
  400.      */
  401.     public function getSocietyType(): ?string
  402.     {
  403.         return $this->societyType;
  404.     }
  405.     /**
  406.      * @param string|null $societyType
  407.      * @return Referent
  408.      */
  409.     public function setSocietyType(?string $societyType): Referent
  410.     {
  411.         $this->societyType $societyType;
  412.         return $this;
  413.     }
  414.     /**
  415.      * @return float|null
  416.      */
  417.     public function getCapital(): ?float
  418.     {
  419.         return $this->capital;
  420.     }
  421.     /**
  422.      * @param float|null $capital
  423.      * @return Referent
  424.      */
  425.     public function setCapital(?float $capital): Referent
  426.     {
  427.         $this->capital $capital;
  428.         return $this;
  429.     }
  430.     /**
  431.      * @return string|null
  432.      */
  433.     public function getCommercialRegisterNumber(): ?string
  434.     {
  435.         return $this->commercialRegisterNumber;
  436.     }
  437.     /**
  438.      * @param string|null $commercialRegisterNumber
  439.      * @return Referent
  440.      */
  441.     public function setCommercialRegisterNumber(?string $commercialRegisterNumber): Referent
  442.     {
  443.         $this->commercialRegisterNumber $commercialRegisterNumber;
  444.         return $this;
  445.     }
  446.     /**
  447.      * @return string|null
  448.      */
  449.     public function getIntraCommunityVATNumber(): ?string
  450.     {
  451.         return $this->intraCommunityVATNumber;
  452.     }
  453.     /**
  454.      * @param string|null $intraCommunityVATNumber
  455.      * @return Referent
  456.      */
  457.     public function setIntraCommunityVATNumber(?string $intraCommunityVATNumber): Referent
  458.     {
  459.         $this->intraCommunityVATNumber $intraCommunityVATNumber;
  460.         return $this;
  461.     }
  462.     public function getUserIdentifier(): string
  463.     {
  464.         return (string) $this->email;
  465.     }
  466.     public function getOpticiens(): ?string
  467.     {
  468.         return $this->companyName ' ' $this->street' ' $this->postalCode' ' .$this->city;
  469.     }
  470. }