src/Entity/User.php line 61

  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use ApiPlatform\Metadata\Get;
  5. use ApiPlatform\Metadata\Post;
  6. use ApiPlatform\Metadata\Put;
  7. use App\Controller\Api\Controller\User\MeController;
  8. use App\Repository\UserRepository;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\Common\Collections\Collection;
  11. use Doctrine\ORM\Mapping as ORM;
  12. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  13. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  14. use Symfony\Component\Security\Core\User\UserInterface;
  15. use Symfony\Component\Serializer\Annotation\Groups;
  16. use Symfony\Component\Validator\Constraints as Assert;
  17. use Symfony\Component\Validator\Constraints\Valid;
  18. #[ORM\Entity(repositoryClassUserRepository::class)]
  19. #[ORM\Table(name'kulmapeck_user')]
  20. #[UniqueEntity(fields: ['username'], message'Ce nom d\'utilisateur est déjà utilisé.')]
  21. #[UniqueEntity(fields: ['phoneNumber'], message'Ce numéro de téléphone est déjà utilisé.')]
  22. #[ORM\EntityListeners(['App\EntityListener\UserListener'])]
  23. #[ORM\HasLifecycleCallbacks]
  24. #[ApiResource(
  25.     operations: [
  26.         new Post(
  27.             denormalizationContext: [
  28.                 'groups' => ['post:user:item']
  29.             ],
  30.         ),
  31.         new Get(
  32.             normalizationContext: [
  33.                 'groups' => ['post:user:item''read:user:item']
  34.             ],
  35.         ),
  36.         new Get(
  37.             paginationEnabledfalse,
  38.             uriTemplate'/me',
  39.             controllerMeController::class,
  40.             readfalse,
  41.             normalizationContext: [
  42.                 'groups' => ['read:user:item''post:user:item''read:personne:item']
  43.             ],
  44.             openapiContext: [
  45.                 'security' => [[ 'bearerAuth' => [] ]]
  46.             ]
  47.         ),
  48.         new Put(
  49.             denormalizationContext: [
  50.                 'groups' => ['post:user:item']
  51.             ],
  52.         ),
  53.     ],
  54.     normalizationContext: [
  55.         'groups' => ['read:user:item']
  56.     ],
  57. )]
  58. class User implements UserInterfacePasswordAuthenticatedUserInterface
  59. {
  60.     #[ORM\Id]
  61.     #[ORM\GeneratedValue]
  62.     #[ORM\Column]
  63.     #[Groups(['read:course:collection''read:forum:item''read:forum:messsage:collection''read:sujet:item''read:sujet:collection''read:exam:collection''read:user:item''read:payment:collection''read:review:collection'])]
  64.     private ?int $id null;
  65.     #[ORM\Column(length180nullabletrue)]
  66.     #[Assert\Email(message"L'email {{ value }} n'est pas une adresse e-mail valide !")]
  67.     #[Groups(['read:course:collection''read:sujet:collection''post:user:item''post:user:item''read:payment:collection''read:review:collection'])]
  68.     private ?string $email null;
  69.     #[ORM\Column(length180uniquetrue)]
  70.     #[Groups(['read:course:collection''read:sujet:collection''post:user:item''read:payment:collection''read:review:collection'])]
  71.     private ?string $username null;
  72.     #[ORM\Column(length180uniquetruenullabletrue)]
  73.     #[Groups(['read:course:collection''read:sujet:collection''post:user:item''read:payment:collection''read:review:collection'])]
  74.     private ?string $phoneNumber null;
  75.     #[ORM\Column]
  76.     #[Groups(['read:user:item'])]
  77.     private array $roles = [];
  78.     /**
  79.      * @var string The hashed password
  80.      */
  81.     #[ORM\Column]
  82.     #[Groups(['post:user:item'])]
  83.     private ?string $password null;
  84.     #[ORM\OneToMany(mappedBy'destinataire'targetEntityNotification::class, orphanRemovaltrue)]
  85.     private Collection $notifications;
  86.     #[ORM\OneToOne(mappedBy'utilisateur'cascade: ['persist''remove'])]
  87.     #[Groups(['read:course:collection''post:user:item'])]
  88.     #[Valid()]
  89.     private ?Eleve $eleve null;
  90.     #[ORM\OneToOne(mappedBy'utilisateur'cascade: ['persist''remove'])]
  91.     private ?Enseignant $enseignant null;
  92.     #[ORM\OneToMany(mappedBy'author'targetEntityLike::class, orphanRemovaltrue)]
  93.     private Collection $likes;
  94.     #[ORM\Column(type'boolean')]
  95.     private ?bool $isVerified false;
  96.     #[Groups(['post:user:item'])]
  97.     public ?string $parentCode null;
  98.     #[ORM\OneToOne(mappedBy'utilisateur'cascade: ['persist''remove'])]
  99.     #[Groups(['read:course:collection''read:personne:item''read:sujet:item''read:sujet:collection''read:review:collection''read:exam:collection''post:user:item''read:payment:collection''read:quizresult:collection'])]
  100.     #[Valid()]
  101.     private ?Personne $personne null;
  102.     #[ORM\Column(nullabletrue)]
  103.     #[Groups(['read:user:item''read:review:collection'])]
  104.     private ?bool $isBlocked null;
  105.     #[ORM\Column(nullabletrue)]
  106.     #[Groups(['read:user:item''read:review:collection'])]
  107.     private ?bool $isAdmin null;
  108.     #[ORM\OneToMany(mappedBy'user'targetEntityExam::class)]
  109.     private Collection $exams;
  110.     #[ORM\OneToMany(mappedBy'user'targetEntityNotificationSetting::class, orphanRemovaltrue)]
  111.     private Collection $notificationSettings;
  112.     #[ORM\ManyToMany(targetEntityFiliere::class, inversedBy'users')]
  113.     private Collection $filieres;
  114.     #[ORM\Column(nullabletrue)]
  115.     #[Groups(['read:user:item'])]
  116.     private ?float $points null;
  117.     #[ORM\OneToMany(mappedBy'user'targetEntityRetrait::class, orphanRemovaltrue)]
  118.     #[Groups(['read:user:item''read:retraits:collection'])]
  119.     private Collection $retraits;
  120.     #[ORM\Column]
  121.     #[Groups(['read:user:item'])]
  122.     private ?float $especes null;
  123.     #[ORM\OneToMany(mappedBy'deviceToken'targetEntityDevice::class)]
  124.     private Collection $devices;
  125.     #[ORM\OneToMany(mappedBy'user'targetEntityContact::class)]
  126.     private Collection $contacts;
  127.     #[ORM\OneToMany(mappedBy'sender'targetEntityMessageChat::class, orphanRemovaltrue)]
  128.     private Collection $messageChats;
  129.     #[ORM\OneToMany(mappedBy'user'targetEntityWebSocketConnection::class, orphanRemovaltrue)]
  130.     private Collection $webSocketConnections;
  131.     public function __construct()
  132.     {
  133.         $this->roles = [];
  134.         $this->notifications = new ArrayCollection();
  135.         $this->likes = new ArrayCollection();
  136.         $this->exams = new ArrayCollection();
  137.         $this->notificationSettings = new ArrayCollection();
  138.         $this->filieres = new ArrayCollection();
  139.         $this->retraits = new ArrayCollection();
  140.         $this->especes 0;
  141.         $this->points 0;
  142.         $this->isBlocked false;
  143.         $this->isVerified false;
  144.         $this->isAdmin false;
  145.         $this->devices = new ArrayCollection();
  146.         $this->contacts = new ArrayCollection();
  147.         $this->messageChats = new ArrayCollection();
  148.         $this->webSocketConnections = new ArrayCollection();
  149.        
  150.     }
  151.     public function getId(): ?int
  152.     {
  153.         return $this->id;
  154.     }
  155.     public function getEmail(): ?string
  156.     {
  157.         return $this->email;
  158.     }
  159.     public function setEmail(string $email): self
  160.     {
  161.         $this->email $email;
  162.         return $this;
  163.     }
  164.     public function getUsername(): ?string
  165.     {
  166.         return $this->username;
  167.     }
  168.     public function setUsername(string $username): self
  169.     {
  170.         $this->username $username;
  171.         return $this;
  172.     }
  173.     public function getPhoneNumber(): ?string
  174.     {
  175.         return $this->phoneNumber;
  176.     }
  177.     public function setPhoneNumber(?string $phoneNumber): self
  178.     {
  179.         $this->phoneNumber $phoneNumber;
  180.         return $this;
  181.     }
  182.     /**
  183.      * A visual identifier that represents this user.
  184.      *
  185.      * @see UserInterface
  186.      */
  187.     public function getUserIdentifier(): string
  188.     {
  189.         return (string) $this->username;
  190.     }
  191.     /**
  192.      * @see UserInterface
  193.      */
  194.     public function getRoles(): array
  195.     {
  196.         $roles $this->roles;
  197.         // guarantee every user at least has ROLE_USER
  198.         $roles[] = 'ROLE_USER';
  199.         return array_unique($roles);
  200.     }
  201.     public function setRoles(array $roles): self
  202.     {
  203.         $this->roles $roles;
  204.         return $this;
  205.     }
  206.     public function addRole(string $role): self
  207.     {
  208.         $this->roles[] = $role;
  209.         return $this;
  210.     }
  211.     /**
  212.      * @see PasswordAuthenticatedUserInterface
  213.      */
  214.     public function getPassword(): string
  215.     {
  216.         return $this->password;
  217.     }
  218.     public function setPassword(string $password): self
  219.     {
  220.         $this->password $password;
  221.         return $this;
  222.     }
  223.     /**
  224.      * @see UserInterface
  225.      */
  226.     public function eraseCredentials()
  227.     {
  228.         // If you store any temporary, sensitive data on the user, clear it here
  229.         // $this->plainPassword = null;
  230.     }
  231.     /**
  232.      * @return Collection<int, Notification>
  233.      */
  234.     public function getNotifications(): Collection
  235.     {
  236.         return $this->notifications;
  237.     }
  238.     public function addNotification(Notification $notification): self
  239.     {
  240.         if (!$this->notifications->contains($notification)) {
  241.             $this->notifications->add($notification);
  242.             $notification->setDestinataire($this);
  243.         }
  244.         return $this;
  245.     }
  246.     public function removeNotification(Notification $notification): self
  247.     {
  248.         if ($this->notifications->removeElement($notification)) {
  249.             // set the owning side to null ( unless already changed )
  250.             if ($notification->getDestinataire() === $this) {
  251.                 $notification->setDestinataire(null);
  252.             }
  253.         }
  254.         return $this;
  255.     }
  256.     public function getEleve(): ?Eleve
  257.     {
  258.         return $this->eleve;
  259.     }
  260.     public function setEleve(Eleve $eleve): self
  261.     {
  262.         // set the owning side of the relation if necessary
  263.         if ($eleve->getUtilisateur() !== $this) {
  264.             $eleve->setUtilisateur($this);
  265.         }
  266.         $this->eleve $eleve;
  267.         return $this;
  268.     }
  269.     public function getEnseignant(): ?Enseignant
  270.     {
  271.         return $this->enseignant;
  272.     }
  273.     public function setEnseignant(Enseignant $enseignant): self
  274.     {
  275.         // set the owning side of the relation if necessary
  276.         if ($enseignant->getUtilisateur() !== $this) {
  277.             $enseignant->setUtilisateur($this);
  278.         }
  279.         $this->enseignant $enseignant;
  280.         return $this;
  281.     }
  282.     /**
  283.      * @return Collection<int, Like>
  284.      */
  285.     public function getLikes(): Collection
  286.     {
  287.         return $this->likes;
  288.     }
  289.     public function addLike(Like $like): self
  290.     {
  291.         if (!$this->likes->contains($like)) {
  292.             $this->likes->add($like);
  293.             $like->setAuthor($this);
  294.         }
  295.         return $this;
  296.     }
  297.     public function removeLike(Like $like): self
  298.     {
  299.         if ($this->likes->removeElement($like)) {
  300.             // set the owning side to null ( unless already changed )
  301.             if ($like->getAuthor() === $this) {
  302.                 $like->setAuthor(null);
  303.             }
  304.         }
  305.         return $this;
  306.     }
  307.     public function isVerified(): bool
  308.     {
  309.         return $this->isVerified;
  310.     }
  311.     public function setIsVerified(bool $isVerified): self
  312.     {
  313.         $this->isVerified $isVerified;
  314.         return $this;
  315.     }
  316.     public function getPersonne(): ?Personne
  317.     {
  318.         return $this->personne;
  319.     }
  320.     public function setPersonne(?Personne $personne): self
  321.     {
  322.         $this->personne $personne;
  323.         return $this;
  324.     }
  325.     public function isIsBlocked(): ?bool
  326.     {
  327.         return $this->isBlocked;
  328.     }
  329.     public function setIsBlocked(?bool $isBlocked): self
  330.     {
  331.         $this->isBlocked $isBlocked;
  332.         return $this;
  333.     }
  334.     public function isIsAdmin(): ?bool
  335.     {
  336.         return $this->isAdmin;
  337.     }
  338.     public function setIsAdmin(?bool $isAdmin): self
  339.     {
  340.         $this->isAdmin $isAdmin;
  341.         return $this;
  342.     }
  343.     /**
  344.      * @return Collection<int, Exam>
  345.      */
  346.     public function getExams(): Collection
  347.     {
  348.         return $this->exams;
  349.     }
  350.     public function addExam(Exam $exam): self
  351.     {
  352.         if (!$this->exams->contains($exam)) {
  353.             $this->exams->add($exam);
  354.             $exam->setUser($this);
  355.         }
  356.         return $this;
  357.     }
  358.     public function removeExam(Exam $exam): self
  359.     {
  360.         if ($this->exams->removeElement($exam)) {
  361.             // set the owning side to null ( unless already changed )
  362.             if ($exam->getUser() === $this) {
  363.                 $exam->setUser(null);
  364.             }
  365.         }
  366.         return $this;
  367.     }
  368.     /**
  369.      * @return Collection<int, NotificationSetting>
  370.      */
  371.     public function getNotificationSettings(): Collection
  372.     {
  373.         return $this->notificationSettings;
  374.     }
  375.     public function addNotificationSetting(NotificationSetting $notificationSetting): self
  376.     {
  377.         if (!$this->notificationSettings->contains($notificationSetting)) {
  378.             $this->notificationSettings->add($notificationSetting);
  379.             $notificationSetting->setUser($this);
  380.         }
  381.         return $this;
  382.     }
  383.     public function removeNotificationSetting(NotificationSetting $notificationSetting): self
  384.     {
  385.         if ($this->notificationSettings->removeElement($notificationSetting)) {
  386.             // set the owning side to null ( unless already changed )
  387.             if ($notificationSetting->getUser() === $this) {
  388.                 $notificationSetting->setUser(null);
  389.             }
  390.         }
  391.         return $this;
  392.     }
  393.     /**
  394.      * @return Collection<int, Filiere>
  395.      */
  396.     public function getFilieres(): Collection
  397.     {
  398.         return $this->filieres;
  399.     }
  400.     public function addFiliere(Filiere $filiere): self
  401.     {
  402.         if (!$this->filieres->contains($filiere)) {
  403.             $this->filieres->add($filiere);
  404.         }
  405.         return $this;
  406.     }
  407.     public function removeFiliere(Filiere $filiere): self
  408.     {
  409.         $this->filieres->removeElement($filiere);
  410.         return $this;
  411.     }
  412.     public function getPoints(): ?float
  413.     {
  414.         return $this->points;
  415.     }
  416.     public function setPoints(?float $points): static
  417.     {
  418.         $this->points $points;
  419.         return $this;
  420.     }
  421.     /**
  422.      * @return Collection<int, Retrait>
  423.      */
  424.     public function getRetraits(): Collection
  425.     {
  426.         return $this->retraits;
  427.     }
  428.     public function addRetrait(Retrait $retrait): static
  429.     {
  430.         if (!$this->retraits->contains($retrait)) {
  431.             $this->retraits->add($retrait);
  432.             $retrait->setUser($this);
  433.         }
  434.         return $this;
  435.     }
  436.     public function removeRetrait(Retrait $retrait): static
  437.     {
  438.         if ($this->retraits->removeElement($retrait)) {
  439.             // set the owning side to null ( unless already changed )
  440.             if ($retrait->getUser() === $this) {
  441.                 $retrait->setUser(null);
  442.             }
  443.         }
  444.         return $this;
  445.     }
  446.     public function getEspeces(): ?float
  447.     {
  448.         return $this->especes;
  449.     }
  450.     public function setEspeces(float $especes): static
  451.     {
  452.         $this->especes $especes;
  453.         return $this;
  454.     }
  455.     /**
  456.      * @return Collection<int, Device>
  457.      */
  458.     public function getDevices(): Collection
  459.     {
  460.         return $this->devices;
  461.     }
  462.     public function addDevice(Device $device): static
  463.     {
  464.         if (!$this->devices->contains($device)) {
  465.             $this->devices->add($device);
  466.             $device->setDeviceToken($this);
  467.         }
  468.         return $this;
  469.     }
  470.     public function removeDevice(Device $device): static
  471.     {
  472.         if ($this->devices->removeElement($device)) {
  473.             // set the owning side to null ( unless already changed )
  474.             if ($device->getDeviceToken() === $this) {
  475.                 $device->setDeviceToken(null);
  476.             }
  477.         }
  478.         return $this;
  479.     }
  480.     /**
  481.      * @return Collection<int, Contact>
  482.      */
  483.     public function getContacts(): Collection
  484.     {
  485.         return $this->contacts;
  486.     }
  487.     public function addContact(Contact $contact): static
  488.     {
  489.         if (!$this->contacts->contains($contact)) {
  490.             $this->contacts->add($contact);
  491.             $contact->setUser($this);
  492.         }
  493.         return $this;
  494.     }
  495.     public function removeContact(Contact $contact): static
  496.     {
  497.         if ($this->contacts->removeElement($contact)) {
  498.             // set the owning side to null ( unless already changed )
  499.             if ($contact->getUser() === $this) {
  500.                 $contact->setUser(null);
  501.             }
  502.         }
  503.         return $this;
  504.     }
  505.     public function __toString()
  506.     {
  507.         return $this->getPersonne()->getNomComplet();
  508.         // Or any other property that represents the user as a string
  509.     }
  510.     /**
  511.      * @return Collection<int, MessageChat>
  512.      */
  513.     public function getMessageChats(): Collection
  514.     {
  515.         return $this->messageChats;
  516.     }
  517.     public function addMessageChat(MessageChat $messageChat): static
  518.     {
  519.         if (!$this->messageChats->contains($messageChat)) {
  520.             $this->messageChats->add($messageChat);
  521.             $messageChat->setSender($this);
  522.         }
  523.         return $this;
  524.     }
  525.     public function removeMessageChat(MessageChat $messageChat): static
  526.     {
  527.         if ($this->messageChats->removeElement($messageChat)) {
  528.             // set the owning side to null (unless already changed)
  529.             if ($messageChat->getSender() === $this) {
  530.                 $messageChat->setSender(null);
  531.             }
  532.         }
  533.         return $this;
  534.     }
  535.     /**
  536.      * @return Collection<int, WebSocketConnection>
  537.      */
  538.     public function getWebSocketConnections(): Collection
  539.     {
  540.         return $this->webSocketConnections;
  541.     }
  542.     public function addWebSocketConnection(WebSocketConnection $webSocketConnection): static
  543.     {
  544.         if (!$this->webSocketConnections->contains($webSocketConnection)) {
  545.             $this->webSocketConnections->add($webSocketConnection);
  546.             $webSocketConnection->setUser($this);
  547.         }
  548.         return $this;
  549.     }
  550.     public function removeWebSocketConnection(WebSocketConnection $webSocketConnection): static
  551.     {
  552.         if ($this->webSocketConnections->removeElement($webSocketConnection)) {
  553.             // set the owning side to null (unless already changed)
  554.             if ($webSocketConnection->getUser() === $this) {
  555.                 $webSocketConnection->setUser(null);
  556.             }
  557.         }
  558.         return $this;
  559.     }
  560. }