src/Entity/User.php line 75

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiFilter;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter;
  6. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  7. use App\Controller\ControllerChangePassword;
  8. use App\Controller\ControllerResetPassword;
  9. use App\Dto\ConfirmationOtpInput;
  10. use App\Dto\ConfirmationOtpOuput;
  11. use App\Dto\OtpInput;
  12. use App\Dto\OtpOuput;
  13. use App\Controller\CreateAcademicienAction;
  14. use App\Repository\UserRepository;
  15. use App\Service\Utils;
  16. use DateTimeImmutable;
  17. use Doctrine\Common\Collections\ArrayCollection;
  18. use Doctrine\Common\Collections\Collection;
  19. use Doctrine\ORM\Mapping as ORM;
  20. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  21. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  22. use Symfony\Component\Security\Core\User\UserInterface;
  23. use Symfony\Component\Serializer\Annotation\Groups;
  24. use Symfony\Component\Validator\Constraints as Assert;
  25. #[ORM\Entity(repositoryClassUserRepository::class)]
  26. #[UniqueEntity(fields:'phone'message:'Le numéro existe déjà')]
  27. // #[UniqueEntity(fields:'email', message:'L\'email existe déjà')]
  28. #[ApiResource(
  29.     normalizationContext:[
  30.         'groups'=>['user:read']
  31.     ],
  32.     collectionOperations: [
  33.         "get" ,
  34.         "post",
  35.         'changePassword' => [
  36.             'method' => 'GET',
  37.             'path' => "users/change-password/{userId}/{lastpassword}/{newpassword}",
  38.             'controller' => ControllerChangePassword::class,
  39.             'read' => false,
  40.         ],
  41.          'resetPassword' => [
  42.              'method' => 'GET',
  43.              'path' => 'users/reset-password/{phone}',
  44.             'controller' => ControllerResetPassword::class,
  45.             'read' => false,
  46.          ],
  47.         'createAcademicien' => [
  48.             'method' => 'POST',
  49.             'path' => "users/academicien",
  50.             'controller' => CreateAcademicienAction::class,
  51.             'read' => false,
  52.             'denormalization_context' => ['groups' => 'academicien'],
  53.         ],
  54.     ],
  55.     itemOperations: [
  56.         "get" ,
  57.         "put" ,
  58.         "delete"
  59.     ]
  60. )]
  61. #[ApiFilter(SearchFilter::class, properties: [
  62.     'firstName'=>'ipartial',
  63.     'lastName' =>'ipartial',
  64.     'reference'=>'exact',
  65.     'academy'  =>'exact',
  66.     'parent'   =>'exact',
  67.     'typeUser' =>'exact',
  68.     'academy'  =>'exact'
  69. ])]
  70. #[ApiFilter(DateFilter::class, properties: ['dateBirth'])]
  71. class User implements UserInterfacePasswordAuthenticatedUserInterface
  72. {
  73.     #[ORM\Id]
  74.     #[ORM\GeneratedValue]
  75.     #[ORM\Column(type'integer')]
  76.     #[Groups(['reservation:read','user:read','payement:read','abonnement:read'])]
  77.     private $id;
  78.     #[ORM\Column(type'string'length60)]
  79.     #[Assert\NotBlank]
  80.     #[Assert\NotNull]
  81.     #[Groups(['reservation:read','academicien','user:read','payement:read','abonnement:read'])]
  82.     private $firstName;
  83.     #[ORM\Column(type'string'length255)]
  84.     #[Assert\NotBlank]
  85.     #[Assert\NotNull]
  86.     #[Groups(['reservation:read','academicien','user:read','abonnement:read'])]
  87.     private $lastName;
  88.     #[ORM\Column(type'string'length16nullable:true)]
  89.     #[Groups(['reservation:read','academicien','user:read','abonnement:read'])]
  90.     private $phone null;
  91.     #[ORM\Column(type'string'length255nullable:true)]
  92.     private $password null;
  93.     #[ORM\OneToMany(mappedBy'customer'targetEntityReservation::class)]
  94.     #[ORM\JoinColumn(nullabletrueonDelete'SET NULL')]
  95.     #[Groups(['user:read'])]
  96.     private $reservations;
  97.     #[ORM\Column(type'string'length10)]
  98.     #[Groups(['reservation:read','academicien','user:read','abonnement:read'])]
  99.     private $reference;
  100.     #[ORM\Column(type'string'length180nullabletrue)]
  101.     #[Groups(['user:read','abonnement:read'])]
  102.     private $email;
  103.     #[ORM\Column(type'datetime')]
  104.     #[Groups(['user:read'])]
  105.     private $createdAt;
  106.     #[ORM\ManyToOne(targetEntityTypeUser::class)]
  107.     #[ORM\JoinColumn(nullablefalse)]
  108.     #[Groups(['academicien','user:read'])]
  109.     private $typeUser;
  110.     #[ORM\ManyToOne(targetEntityself::class, inversedBy'users')]
  111.     #[ORM\JoinColumn(nullabletrueonDelete'SET NULL')]
  112.     /**
  113.      * @ORM\JoinColumn(onDelete="SET NULL")
  114.      */
  115.     #[Groups(['academicien','user:read'])]
  116.     private $parent;
  117.     #[ORM\OneToMany(mappedBy'parent'targetEntityself::class)]
  118.     private $users;
  119.     #[ORM\Column(type'string'length20nullabletrue)]
  120.     #[Groups(['user:read'])]
  121.     private $code;
  122.     #[ORM\ManyToOne(targetEntityAcademy::class, inversedBy'users')]
  123.     #[Groups(['academicien','user:read'])]
  124.     private $academy;
  125.     #[ORM\OneToMany(mappedBy'academicien'targetEntityAbonnement::class)]
  126.     #[ORM\JoinColumn(nullabletrueonDelete'SET NULL')]
  127.     /**
  128.      * @ORM\JoinColumn(onDelete="SET NULL")
  129.      */
  130.     #[Groups(['academicien','user:read'])]
  131.     private $abonnements;
  132.     #[ORM\Column(type'date'nullabletrue)]
  133.     #[Groups(['academicien','user:read'])]
  134.     private $dateBirth;
  135.     #[ORM\Column(type'datetime'nullabletrue)]
  136.     #[Groups(['academicien','user:read'])]
  137.     private $dateLimited;
  138.     #[ORM\Column(type'boolean'nullabletrue)]
  139.     #[Groups(['academicien','user:read'])]
  140.     private $isOld;
  141.     public function __construct()
  142.     {
  143.         $this->reservations = new ArrayCollection();
  144.         $this->createdAt = new DateTimeImmutable();
  145.         $this->users = new ArrayCollection();
  146.         $this->abonnements = new ArrayCollection();
  147.         $this->isOld false;
  148.     }
  149.     public function getId(): ?int
  150.     {
  151.         return $this->id;
  152.     }
  153.     public function getFirstName(): ?string
  154.     {
  155.         return $this->firstName;
  156.     }
  157.     public function setFirstName(string $firstName): self
  158.     {
  159.         $this->firstName strtolower($firstName);
  160.         return $this;
  161.     }
  162.     public function getLastName(): ?string
  163.     {
  164.         return $this->lastName;
  165.     }
  166.     public function setLastName(string $lastName): self
  167.     {
  168.         $this->lastName strtolower($lastName);
  169.         return $this;
  170.     }
  171.     public function getPhone(): ?string
  172.     {
  173.         return $this->phone;
  174.     }
  175.     public function setPhone(string $phone): self
  176.     {
  177.         $this->phone $phone;
  178.         return $this;
  179.     }
  180.     public function getPassword(): ?string
  181.     {
  182.         return $this->password;
  183.     }
  184.     public function setPassword(string $password): self
  185.     {
  186.         $this->password $password;
  187.         return $this;
  188.     }
  189.     /**
  190.     * Returns the roles granted to the user.
  191.     *
  192.     *     public function getRoles()
  193.     *     {
  194.     *         return ['ROLE_USER'];
  195.     *     }
  196.     *
  197.     * Alternatively, the roles might be stored in a ``roles`` property,
  198.     * and populated in any number of different ways when the user object
  199.     * is created.
  200.     *
  201.     * @return string[]
  202.     */
  203.     public function getRoles(): array
  204.     {
  205.         return array('ROLE_USER');
  206.     }
  207.     /**
  208.      * Removes sensitive data from the user.
  209.      *
  210.      * This is important if, at any given point, sensitive information like
  211.      * the plain-text password is stored on this object.
  212.      */
  213.     public function eraseCredentials()
  214.     {
  215.     }
  216.     /**
  217.      * Returns the identifier for this user (e.g. its username or email address).
  218.      */
  219.     public function getUserIdentifier(): string
  220.     {
  221.         return $this->phone;
  222.     }
  223.     /**
  224.      * @return Collection<int, Reservation>
  225.      */
  226.     public function getReservations(): Collection
  227.     {
  228.         return $this->reservations;
  229.     }
  230.     public function addReservation(Reservation $reservation): self
  231.     {
  232.         if (!$this->reservations->contains($reservation)) {
  233.             $this->reservations[] = $reservation;
  234.             $reservation->setCustomer($this);
  235.         }
  236.         return $this;
  237.     }
  238.     public function removeReservation(Reservation $reservation): self
  239.     {
  240.         if ($this->reservations->removeElement($reservation)) {
  241.             // set the owning side to null (unless already changed)
  242.             if ($reservation->getCustomer() === $this) {
  243.                 $reservation->setCustomer(null);
  244.             }
  245.         }
  246.         return $this;
  247.     }
  248.     public function getReference(): ?string
  249.     {
  250.         return $this->reference;
  251.     }
  252.     public function setReference(string $reference): self
  253.     {
  254.         $this->reference $reference;
  255.         return $this;
  256.     }
  257.     public function getEmail(): ?string
  258.     {
  259.         return $this->email;
  260.     }
  261.     public function setEmail(?string $email): self
  262.     {
  263.         $this->email $email;
  264.         return $this;
  265.     }
  266.     public function getCreatedAt(): ?\DateTimeInterface
  267.     {
  268.         return $this->createdAt;
  269.     }
  270.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  271.     {
  272.         $this->createdAt $createdAt;
  273.         return $this;
  274.     }
  275.     public function getTypeUser(): ?TypeUser
  276.     {
  277.         return $this->typeUser;
  278.     }
  279.     public function setTypeUser(?TypeUser $typeUser): self
  280.     {
  281.         $this->typeUser $typeUser;
  282.         return $this;
  283.     }
  284.     public function getParent(): ?self
  285.     {
  286.         return $this->parent;
  287.     }
  288.     public function setParent(?self $parent): self
  289.     {
  290.         $this->parent $parent;
  291.         return $this;
  292.     }
  293.     /**
  294.      * @return Collection<int, self>
  295.      */
  296.     public function getUsers(): Collection
  297.     {
  298.         return $this->users;
  299.     }
  300.     public function addUser(self $user): self
  301.     {
  302.         if (!$this->users->contains($user)) {
  303.             $this->users[] = $user;
  304.             $user->setParent($this);
  305.         }
  306.         return $this;
  307.     }
  308.     public function removeUser(self $user): self
  309.     {
  310.         if ($this->users->removeElement($user)) {
  311.             // set the owning side to null (unless already changed)
  312.             if ($user->getParent() === $this) {
  313.                 $user->setParent(null);
  314.             }
  315.         }
  316.         return $this;
  317.     }
  318.     public function getCode(): ?string
  319.     {
  320.         return $this->code;
  321.     }
  322.     public function setCode(?string $code): self
  323.     {
  324.         $this->code $code;
  325.         return $this;
  326.     }
  327.     public function getAcademy(): ?Academy
  328.     {
  329.         return $this->academy;
  330.     }
  331.     public function setAcademy(?Academy $academy): self
  332.     {
  333.         $this->academy $academy;
  334.         return $this;
  335.     }
  336.     /**
  337.      * @return Collection<int, Abonnement>
  338.      */
  339.     public function getAbonnements(): Collection
  340.     {
  341.         return $this->abonnements;
  342.     }
  343.     public function addAbonnement(Abonnement $abonnement): self
  344.     {
  345.         if (!$this->abonnements->contains($abonnement)) {
  346.             $this->abonnements[] = $abonnement;
  347.             $abonnement->setAcademicien($this);
  348.         }
  349.         return $this;
  350.     }
  351.     public function removeAbonnement(Abonnement $abonnement): self
  352.     {
  353.         if ($this->abonnements->removeElement($abonnement)) {
  354.             // set the owning side to null (unless already changed)
  355.             if ($abonnement->getAcademicien() === $this) {
  356.                 $abonnement->setAcademicien(null);
  357.             }
  358.         }
  359.         return $this;
  360.     }
  361.     public function getDateBirth(): ?\DateTimeInterface
  362.     {
  363.         return $this->dateBirth;
  364.     }
  365.     public function setDateBirth(?\DateTimeInterface $dateBirth): self
  366.     {
  367.         $this->dateBirth $dateBirth;
  368.         return $this;
  369.     }
  370.     public function getDateLimited(): ?\DateTimeInterface
  371.     {
  372.         return $this->dateLimited;
  373.     }
  374.     public function setDateLimited(?\DateTimeInterface $dateLimited): self
  375.     {
  376.         $this->dateLimited $dateLimited;
  377.         return $this;
  378.     }
  379.     public function isIsOld(): ?bool
  380.     {
  381.         return $this->isOld;
  382.     }
  383.     public function setIsOld(?bool $isOld): self
  384.     {
  385.         $this->isOld $isOld;
  386.         return $this;
  387.     }
  388. }