src/Entity/User.php line 43

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Action\NotFoundAction;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use App\Controller\MeController;
  6. use App\Repository\UserRepository;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\Common\Collections\Collection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  11. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  12. use Symfony\Component\Security\Core\User\UserInterface;
  13. use Symfony\Component\Serializer\Annotation\Groups;
  14. use Symfony\Component\Validator\Constraints as Assert;
  15. /**
  16.  * @ORM\Entity(repositoryClass=UserRepository::class)
  17.  * @UniqueEntity(fields={"email"}, message="There is already an account with this email")
  18.  */
  19. #[ApiResource(
  20.     collectionOperations:[
  21.         'me'=>[
  22.             'pagination_enabled'=>false,
  23.             'path'=>'/me',
  24.             'method'=>'get',
  25.             'controller'=>MeController::class,
  26.             'read'=>false
  27.         ]
  28.     ],
  29.     itemOperations:[
  30.         'get'=>[
  31.             'controller'=>NotFoundAction::class,
  32.             'openapi_context'=>['summary'=>'hidden'],
  33.             'read'=>false,
  34.             'output'=>false
  35.         ]
  36.         ],
  37.         normalizationContext:['groups'=>['read:User']]
  38. )]
  39. class User implements UserInterfacePasswordAuthenticatedUserInterface
  40. {
  41.     const roles=[
  42.         // 'Administrateur'=>'ROLE_ADMIN',
  43.         'Gérant'=>'ROLE_EDITOR',
  44.         // 'Client'=>'ROLE_CLIENT',
  45.         // 'Utilisateur'=>'ROLE_USER'
  46.     ];
  47.     const status=[
  48.         'Activer'=>'Activer',
  49.         'Désactiver'=>'Désactiver',
  50.         'Delete'=>'Delete'
  51.     ];
  52.     /**
  53.      * @ORM\Id
  54.      * @ORM\GeneratedValue
  55.      * @ORM\Column(type="integer")
  56.      */
  57.     #[Groups(['read:User'])]
  58.     private $id;
  59.     /**
  60.      * @Assert\NotBlank()
  61.      * @ORM\Column(type="string", length=180, unique=true)
  62.      */
  63.     #[Groups(['read:User'])]
  64.     private $email;
  65.     /**
  66.      * @Assert\NotBlank()
  67.      * @ORM\Column(type="json")
  68.      */
  69.     #[Groups(['read:User'])]
  70.     private $roles = [];
  71.     /**
  72.      * @var string The hashed password
  73.      * @Assert\NotNull()
  74.      * @Assert\NotBlank()
  75.      * @ORM\Column(type="string")
  76.      */
  77.     private $password;
  78.     /**
  79.      * password_verify
  80.      * @Assert\EqualTo(propertyPath="password", message="Le Mot de passe ne correspond pas")
  81.      * @var mixed
  82.      */
  83.     private $password_verify;
  84.     /**
  85.      * @ORM\OneToMany(targetEntity=Comment::class, mappedBy="user", orphanRemoval=true)
  86.      */
  87.     private $comments;
  88.     /**
  89.      * @ORM\OneToMany(targetEntity=Order::class, mappedBy="user", orphanRemoval=true)
  90.      */
  91.     private $orders;
  92.     /**
  93.      * @Assert\Valid
  94.      * @ORM\OneToOne(targetEntity=Client::class, mappedBy="user", cascade={"persist", "remove"})
  95.      */
  96.     private $client;
  97.     /**
  98.      * @ORM\Column(type="datetime")
  99.      */
  100.     private $created_at;
  101.     /**
  102.      * @ORM\ManyToMany(targetEntity=Article::class, mappedBy="favori")
  103.      */
  104.     private $favoris;
  105.     /**
  106.      * @ORM\OneToOne(targetEntity=DeliverySpace::class, inversedBy="user", cascade={"persist", "remove"})
  107.      */
  108.     private $delivery_space;
  109.     /**
  110.      * @ORM\Column(type="string", length=255, nullable=true)
  111.      */
  112.     private $username;
  113.     /**
  114.      * @ORM\Column(type="string", length=255)
  115.      * @Assert\NotBlank()
  116.      * @Assert\NotNull()
  117.      */
  118.     private $phone_number;
  119.         /**
  120.      * 
  121.      * @ORM\OneToMany(targetEntity=Phone::class, mappedBy="user")
  122.      */
  123.     private $phones;
  124.     /**
  125.      * @ORM\Column(type="datetime", nullable=true)
  126.      */
  127.     private $last_login_at;
  128.     /**
  129.      * @ORM\Column(type="boolean")
  130.      */
  131.     private $is_active true;
  132.     /**
  133.      * @Assert\Valid
  134.      * @ORM\OneToOne(targetEntity=Adresse::class, inversedBy="user", cascade={"persist", "remove"})
  135.      */
  136.     private $adresse;
  137.     /**
  138.      * @ORM\Column(type="string", length=255)
  139.      */
  140.     private $cle;
  141.     /**
  142.      * @ORM\Column(type="string", length=255)
  143.      */
  144.     private $status;
  145.     /**
  146.      * @ORM\Column(type="boolean")
  147.      */
  148.     private $is_verified;
  149.     /**
  150.      * @ORM\Column(type="string", length=255)
  151.      */
  152.     private $first_name;
  153.     /**
  154.      * @ORM\Column(type="string", length=255)
  155.      */
  156.     private $last_name;
  157.     /**
  158.      * @ORM\Column(type="string", length=255, nullable=true)
  159.      */
  160.     private $api_key;
  161.     public function __construct()
  162.     {
  163.         $this->comments = new ArrayCollection();
  164.         $this->orders = new ArrayCollection();
  165.         $this->created_at = new \DateTime();
  166.         $this->favoris = new ArrayCollection();
  167.         $this->phones = new ArrayCollection();
  168.         $this->status 'Activer';
  169.         $this->is_verified false;
  170.     }
  171.     public function getId(): ?int
  172.     {
  173.         return $this->id;
  174.     }
  175.     public function getEmail(): ?string
  176.     {
  177.         return $this->email;
  178.     }
  179.     public function setEmail(string $email): self
  180.     {
  181.         $this->email $email;
  182.         return $this;
  183.     }
  184.     /**
  185.      * A visual identifier that represents this user.
  186.      *
  187.      * @see UserInterface
  188.      */
  189.     public function getUserIdentifier(): string
  190.     {
  191.         return (string) $this->email;
  192.     }
  193.     /**
  194.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  195.      */
  196.     public function getUsername(): string
  197.     {
  198.         return (string) $this->email;
  199.     }
  200.     /**
  201.      * @see UserInterface
  202.      */
  203.     public function getRoles(): array
  204.     {
  205.         $roles $this->roles;
  206.         // guarantee every user at least has ROLE_USER
  207.         // $roles[] = 'ROLE_USER';
  208.         return array_unique($roles);
  209.     }
  210.     public function setRoles(array $roles): self
  211.     {
  212.         $this->roles $roles;
  213.         return $this;
  214.     }
  215.     /**
  216.      * @see PasswordAuthenticatedUserInterface
  217.      */
  218.     public function getPassword(): string
  219.     {
  220.         return $this->password;
  221.     }
  222.     public function setPassword(string $password): self
  223.     {
  224.         $this->password $password;
  225.         return $this;
  226.     }
  227.     /**
  228.      * Returning a salt is only needed, if you are not using a modern
  229.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  230.      *
  231.      * @see UserInterface
  232.      */
  233.     public function getSalt(): ?string
  234.     {
  235.         return null;
  236.     }
  237.     /**
  238.      * @see UserInterface
  239.      */
  240.     public function eraseCredentials()
  241.     {
  242.         // If you store any temporary, sensitive data on the user, clear it here
  243.         // $this->plainPassword = null;
  244.     }
  245.     /**
  246.      * @return Collection|Comment[]
  247.      */
  248.     public function getComments(): Collection
  249.     {
  250.         return $this->comments;
  251.     }
  252.     public function addComment(Comment $comment): self
  253.     {
  254.         if (!$this->comments->contains($comment)) {
  255.             $this->comments[] = $comment;
  256.             $comment->setUser($this);
  257.         }
  258.         return $this;
  259.     }
  260.     public function removeComment(Comment $comment): self
  261.     {
  262.         if ($this->comments->removeElement($comment)) {
  263.             // set the owning side to null (unless already changed)
  264.             if ($comment->getUser() === $this) {
  265.                 $comment->setUser(null);
  266.             }
  267.         }
  268.         return $this;
  269.     }
  270.     /**
  271.      * @return Collection|Order[]
  272.      */
  273.     public function getOrders(): Collection
  274.     {
  275.         return $this->orders;
  276.     }
  277.     public function addOrder(Order $order): self
  278.     {
  279.         if (!$this->orders->contains($order)) {
  280.             $this->orders[] = $order;
  281.             $order->setUser($this);
  282.         }
  283.         return $this;
  284.     }
  285.     public function removeOrder(Order $order): self
  286.     {
  287.         if ($this->orders->removeElement($order)) {
  288.             // set the owning side to null (unless already changed)
  289.             if ($order->getUser() === $this) {
  290.                 $order->setUser(null);
  291.             }
  292.         }
  293.         return $this;
  294.     }
  295.     public function getClient(): ?Client
  296.     {
  297.         return $this->client;
  298.     }
  299.     public function setClient(Client $client): self
  300.     {
  301.         // set the owning side of the relation if necessary
  302.         if ($client->getUser() !== $this) {
  303.             $client->setUser($this);
  304.         }
  305.         $this->client $client;
  306.         return $this;
  307.     }
  308.     public function getCreatedAt(): ?\DateTimeInterface
  309.     {
  310.         return $this->created_at;
  311.     }
  312.     public function setCreatedAt(\DateTimeInterface $created_at): self
  313.     {
  314.         $this->created_at $created_at;
  315.         return $this;
  316.     }
  317.     /**
  318.      * @return Collection|Article[]
  319.      */
  320.     public function getFavoris(): Collection
  321.     {
  322.         return $this->favoris;
  323.     }
  324.     public function addFavori(Article $favori): self
  325.     {
  326.         if (!$this->favoris->contains($favori)) {
  327.             $this->favoris[] = $favori;
  328.             $favori->addFavori($this);
  329.         }
  330.         return $this;
  331.     }
  332.     public function removeFavori(Article $favori): self
  333.     {
  334.         if ($this->favoris->removeElement($favori)) {
  335.             $favori->removeFavori($this);
  336.         }
  337.         return $this;
  338.     }
  339.     public function getDeliverySpace(): ?DeliverySpace
  340.     {
  341.         return $this->delivery_space;
  342.     }
  343.     public function setDeliverySpace(?DeliverySpace $delivery_space): self
  344.     {
  345.         $this->delivery_space $delivery_space;
  346.         return $this;
  347.     }
  348.     public function setUsername(?string $username): self
  349.     {
  350.         $this->username $username;
  351.         return $this;
  352.     }
  353.     public function getPhoneNumber(): ?string
  354.     {
  355.         return $this->phone_number;
  356.     }
  357.     public function setPhoneNumber(string $phone_number): self
  358.     {
  359.         $this->phone_number $phone_number;
  360.         return $this;
  361.     }
  362.     /**
  363.      * Get the value of password_verify
  364.      */ 
  365.     public function getPasswordVerify()
  366.     {
  367.         return $this->password_verify;
  368.     }
  369.     /**
  370.      * Set the value of password_verify
  371.      *
  372.      * @return  self
  373.      */ 
  374.     public function setPasswordVerify($password_verify)
  375.     {
  376.         $this->password_verify $password_verify;
  377.         return $this;
  378.     }
  379.     public function getLastLoginAt(): ?\DateTime
  380.     {
  381.         return $this->last_login_at;
  382.     }
  383.     public function setLastLoginAt(?\DateTime $last_login_at): self
  384.     {
  385.         $this->last_login_at $last_login_at;
  386.         return $this;
  387.     }
  388.     public function getIsActive(): ?bool
  389.     {
  390.         return $this->is_active;
  391.     }
  392.     public function setIsActive(bool $is_active): self
  393.     {
  394.         $this->is_active $is_active;
  395.         return $this;
  396.     }
  397.     public function getAdresse(): ?Adresse
  398.     {
  399.         return $this->adresse;
  400.     }
  401.     public function setAdresse(?Adresse $adresse): self
  402.     {
  403.         $this->adresse $adresse;
  404.         return $this;
  405.     }
  406.     /**
  407.      * @return Collection|Phone[]
  408.      */
  409.     public function getPhones(): Collection
  410.     {
  411.         return $this->phones;
  412.     }
  413.     public function addPhone(Phone $phone): self
  414.     {
  415.         if (!$this->phones->contains($phone)) {
  416.             $this->phones[] = $phone;
  417.             $phone->setUser($this);
  418.         }
  419.         return $this;
  420.     }
  421.     public function removePhone(Phone $phone): self
  422.     {
  423.         if ($this->phones->removeElement($phone)) {
  424.             // set the owning side to null (unless already changed)
  425.             if ($phone->getUser() === $this) {
  426.                 $phone->setUser(null);
  427.             }
  428.         }
  429.         return $this;
  430.     }
  431.     public function getCle(): ?string
  432.     {
  433.         return $this->cle;
  434.     }
  435.     public function setCle(string $cle): self
  436.     {
  437.         $this->cle $cle;
  438.         return $this;
  439.     }
  440.     public function getStatus(): ?string
  441.     {
  442.         return $this->status;
  443.     }
  444.     public function setStatus(string $status): self
  445.     {
  446.         $this->status $status;
  447.         return $this;
  448.     }
  449.     public function getIsVerified(): ?bool
  450.     {
  451.         return $this->is_verified;
  452.     }
  453.     public function setIsVerified(bool $is_verified): self
  454.     {
  455.         $this->is_verified $is_verified;
  456.         return $this;
  457.     }
  458.     public function getFullName(): ?string
  459.     {
  460.         return $this->first_name' ' $this->last_name;
  461.     }
  462.     public function getFirstName(): ?string
  463.     {
  464.         return $this->first_name;
  465.     }
  466.     public function setFirstName(string $first_name): self
  467.     {
  468.         $this->first_name $first_name;
  469.         return $this;
  470.     }
  471.     public function getLastName(): ?string
  472.     {
  473.         return $this->last_name;
  474.     }
  475.     public function setLastName(string $last_name): self
  476.     {
  477.         $this->last_name $last_name;
  478.         return $this;
  479.     }
  480.     public function getApiKey(): ?string
  481.     {
  482.         return $this->api_key;
  483.     }
  484.     public function setApiKey(string $api_key): self
  485.     {
  486.         $this->api_key $api_key;
  487.         return $this;
  488.     }
  489. }