src/Entity/Users.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UsersRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  9. use Symfony\Component\Security\Core\User\UserInterface;
  10. use Symfony\Component\HttpFoundation\File\File;
  11. use Symfony\Component\Serializer\Annotation\Ignore;
  12. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  13. use Symfony\Component\Validator\Constraints as Assert;
  14. use Doctrine\DBAL\Types\Types;
  15. use Serializable;
  16. #[ORM\Entity(repositoryClassUsersRepository::class)]
  17. #[Vich\Uploadable]
  18. #[UniqueEntity(fields: ['email'], message'Il y a déjà un compte avec cet email !')]
  19. class Users implements UserInterfacePasswordAuthenticatedUserInterfaceSerializable
  20. {
  21.     #[ORM\Id]
  22.     #[ORM\GeneratedValue]
  23.     #[ORM\Column]
  24.     private ?int $id null;
  25.     #[ORM\Column(length180uniquetrue)]
  26.     private ?string $email null;
  27.     #[ORM\Column]
  28.     private array $roles = [];
  29.     /**
  30.      * @var string The hashed password
  31.      */
  32.     #[ORM\Column]
  33.     private ?string $password null;
  34.     #[ORM\Column(length100nullabletrue)]
  35.     private ?string $nom null;
  36.     #[ORM\Column(length125nullabletrue)]
  37.     private ?string $prenom null;
  38.     #[ORM\Column(length30nullabletrue)]
  39.     private ?string $telephone null;
  40.     #[ORM\Column(length255nullabletrue)]
  41.     private ?string $adresse null;
  42.     #[ORM\Column(length10nullabletrue)]
  43.     private ?string $code_postal null;
  44.     #[ORM\Column(length200nullabletrue)]
  45.     private ?string $ville null;
  46.     #[ORM\Column(length100nullabletrue)]
  47.     private ?string $pseudo null;
  48.     #[ORM\Column(length255nullabletrue)]
  49.     private ?string $description null;
  50.     #[ORM\Column(length255nullabletrue)]
  51.     private ?string $file null;
  52.     #[Vich\UploadableField(mapping'featured_profils'fileNameProperty'file')]  
  53.     #[Assert\File(maxSize:'2M'maxSizeMessage:  'La taille du fichier ne doit pas dépasser 2 Mo.')]
  54.     private $imageFile;
  55.     #[ORM\Column(type'boolean')]
  56.     private $is_verified false;
  57.     #[ORM\Column(type'string'length100nullabletrue)]
  58.     private ?string $resetToken;
  59.     #[ORM\Column(type'datetime_immutable'options: ['default' => 'CURRENT_TIMESTAMP'])]
  60.     private ?\DateTimeImmutable $created_at null;
  61.     #[ORM\Column(typeTypes::DATE_MUTABLEnullabletrue)]
  62.     private ?\DateTimeInterface $updated_at null;
  63.     #[ORM\OneToMany(mappedBy'user'targetEntitySubscription::class)]
  64.     private Collection $subscriptions;
  65.     #[ORM\Column(length255nullabletrue)]
  66.     private ?string $stripeId null;
  67.     #[ORM\OneToMany(mappedBy'userId'targetEntityDemandeDeTravail::class)]
  68.     private Collection $demandeDeTravails;
  69.     #[ORM\OneToMany(mappedBy'userId'targetEntityOffreDeTravail::class)]
  70.     private Collection $offreDeTravails;
  71.     #[ORM\OneToMany(mappedBy'userIdAuteur'targetEntityEvaluation::class)]
  72.     private Collection $evaluations;
  73.     #[ORM\OneToMany(mappedBy'expediteurId'targetEntityMessage::class)]
  74.     private Collection $messages;
  75.     #[ORM\OneToMany(mappedBy'userId'targetEntityNotification::class)]
  76.     private Collection $notifications;
  77.     public function __construct()
  78.     {
  79.         $this->created_at = new \DateTimeImmutable();
  80.         $this->subscriptions = new ArrayCollection();
  81.         $this->demandeDeTravails = new ArrayCollection();
  82.         $this->offreDeTravails = new ArrayCollection();
  83.         $this->evaluations = new ArrayCollection();
  84.         $this->messages = new ArrayCollection();
  85.         $this->notifications = new ArrayCollection();
  86.     }
  87.     public function getId(): ?int
  88.     {
  89.         return $this->id;
  90.     }
  91.     public function getEmail(): ?string
  92.     {
  93.         return $this->email;
  94.     }
  95.     public function setEmail(string $email): self
  96.     {
  97.         $this->email $email;
  98.         return $this;
  99.     }
  100.     /**
  101.      * A visual identifier that represents this user.
  102.      *
  103.      * @see UserInterface
  104.      */
  105.     public function getUserIdentifier(): string
  106.     {
  107.         return (string) $this->email;
  108.     }
  109.     /**
  110.      * @see UserInterface
  111.      */
  112.     public function getRoles(): array
  113.     {
  114.         $roles $this->roles;
  115.         // guarantee every user at least has ROLE_USER
  116.         $roles[] = 'ROLE_USER';
  117.         return array_unique($roles);
  118.     }
  119.     public function setRoles(array $roles): self
  120.     {
  121.         $this->roles $roles;
  122.         return $this;
  123.     }
  124.     /**
  125.      * @see PasswordAuthenticatedUserInterface
  126.      */
  127.     public function getPassword(): string
  128.     {
  129.         return $this->password;
  130.     }
  131.     public function setPassword(string $password): self
  132.     {
  133.         $this->password $password;
  134.         return $this;
  135.     }
  136.     /**
  137.      * @see UserInterface
  138.      */
  139.     public function eraseCredentials()
  140.     {
  141.         // If you store any temporary, sensitive data on the user, clear it here
  142.         // $this->plainPassword = null;
  143.     }
  144.     public function getNom(): ?string
  145.     {
  146.         return $this->nom;
  147.     }
  148.     public function setNom(?string $nom): self
  149.     {
  150.         $this->nom $nom;
  151.         return $this;
  152.     }
  153.     public function getPrenom(): ?string
  154.     {
  155.         return $this->prenom;
  156.     }
  157.     public function setPrenom(?string $prenom): self
  158.     {
  159.         $this->prenom $prenom;
  160.         return $this;
  161.     }
  162.     public function getTelephone(): ?string
  163.     {
  164.         return $this->telephone;
  165.     }
  166.     public function setTelephone(?string $telephone): self
  167.     {
  168.         $this->telephone $telephone;
  169.         return $this;
  170.     }
  171.     public function getAdresse(): ?string
  172.     {
  173.         return $this->adresse;
  174.     }
  175.     public function setAdresse(?string $adresse): self
  176.     {
  177.         $this->adresse $adresse;
  178.         return $this;
  179.     }
  180.     public function getCodePostal(): ?string
  181.     {
  182.         return $this->code_postal;
  183.     }
  184.     public function setCodePostal(?string $code_postal): self
  185.     {
  186.         $this->code_postal $code_postal;
  187.         return $this;
  188.     }
  189.     public function getVille(): ?string
  190.     {
  191.         return $this->ville;
  192.     }
  193.     public function setVille(?string $ville): self
  194.     {
  195.         $this->ville $ville;
  196.         return $this;
  197.     }
  198.     public function getPseudo(): ?string
  199.     {
  200.         return $this->pseudo;
  201.     }
  202.     public function setPseudo(?string $pseudo): self
  203.     {
  204.         $this->pseudo $pseudo;
  205.         return $this;
  206.     }
  207.     public function getDescription(): ?string
  208.     {
  209.         return $this->description;
  210.     }
  211.     public function setDescription(?string $description): self
  212.     {
  213.         $this->description $description;
  214.         return $this;
  215.     }
  216.     public function getFile(): ?string
  217.     {
  218.         return $this->file;
  219.     }
  220.     public function setFile(?string $file): self
  221.     {
  222.         $this->file $file;
  223.         return $this;
  224.     }
  225.     public function getImageFile(File $image null)
  226.     {
  227.         return $this->imageFile;
  228.     }
  229.     public function setImageFile(File $image null)
  230.     {        
  231.         $this->imageFile $image;
  232.          if($image) {
  233.             $this->file $image->getFilename();
  234.              $this->updated_at = new \DateTime('now');
  235.          }
  236.     }
  237.     public function getIsVerified(): ?bool
  238.     {
  239.         return $this->is_verified;
  240.     }
  241.     public function setIsVerified(?bool $is_verified): self
  242.     {
  243.         $this->is_verified $is_verified;
  244.         return $this;
  245.     }
  246.     public function getResetToken(): ?string
  247.     {
  248.         return $this->resetToken;
  249.     }
  250.     public function setResetToken(?string $resetToken): self
  251.     {
  252.         $this->resetToken $resetToken;
  253.         return $this;
  254.     }
  255.     public function getCreatedAt(): ?\DateTimeImmutable
  256.     {
  257.         return $this->created_at;
  258.     }
  259.     public function setCreatedAt(\DateTimeImmutable $created_at): self
  260.     {
  261.         $this->created_at $created_at;
  262.         return $this;
  263.     }
  264.     public function getUpdatedAt(): ?\DateTimeInterface
  265.     {
  266.         return $this->updated_at;
  267.     }
  268.     public function setUpdatedAt(?\DateTimeInterface $updated_at): self
  269.     {
  270.         $this->updated_at $updated_at;
  271.         return $this;
  272.     }
  273.     
  274.      /**
  275.      * @return Collection<int, Subscription>
  276.      */
  277.     public function getSubscriptions(): Collection
  278.     {
  279.         return $this->subscriptions;
  280.     }
  281.     public function addSubscription(Subscription $subscription): self
  282.     {
  283.         if (!$this->subscriptions->contains($subscription)) {
  284.             $this->subscriptions->add($subscription);
  285.             $subscription->setUser($this);
  286.         }
  287.         return $this;
  288.     }
  289.     public function removeSubscription(Subscription $subscription): self
  290.     {
  291.         if ($this->subscriptions->removeElement($subscription)) {
  292.             // set the owning side to null (unless already changed)
  293.             if ($subscription->getUser() === $this) {
  294.                 $subscription->setUser(null);
  295.             }
  296.         }
  297.         return $this;
  298.     }
  299.     public function hasActiveSubscription(): bool
  300.     {
  301.         foreach ($this->subscriptions as $subscription) {
  302.             if ($subscription->isActive()) {
  303.                 return true// L'utilisateur a au moins un abonnement actif
  304.             }
  305.         }
  306.         return false// Aucun abonnement actif trouvé
  307.     }
  308.     public function getStripeId(): ?string
  309.     {
  310.         return $this->stripeId;
  311.     }
  312.     public function setStripeId(?string $stripeId): self
  313.     {
  314.         $this->stripeId $stripeId;
  315.         return $this;
  316.     }
  317.     /**
  318.      * @see \Serializable::serialize()
  319.      */
  320.     public function serialize()
  321.     {
  322.         return serialize(array(
  323.             $this->id,
  324.             $this->email,
  325.             $this->password,
  326.             $this->file,
  327.             // see section on salt below
  328.             // $this->salt,
  329.         ));
  330.     }
  331.     /**
  332.      * @see \Serializable::unserialize()
  333.      */
  334.     public function unserialize($serialized)
  335.     {
  336.         [
  337.             $this->id,
  338.             $this->email,
  339.             $this->password,
  340.             $this->file,
  341.             // voir la section sur le sel ci-dessous
  342.             // $this->salt
  343.         ] = unserialize($serialized, ['allowed_classes' => false]);
  344.     }
  345.     /**
  346.      * @return Collection<int, DemandeDeTravail>
  347.      */
  348.     public function getDemandeDeTravails(): Collection
  349.     {
  350.         return $this->demandeDeTravails;
  351.     }
  352.     public function addDemandeDeTravail(DemandeDeTravail $demandeDeTravail): static
  353.     {
  354.         if (!$this->demandeDeTravails->contains($demandeDeTravail)) {
  355.             $this->demandeDeTravails->add($demandeDeTravail);
  356.             $demandeDeTravail->setUserId($this);
  357.         }
  358.         return $this;
  359.     }
  360.     public function removeDemandeDeTravail(DemandeDeTravail $demandeDeTravail): static
  361.     {
  362.         if ($this->demandeDeTravails->removeElement($demandeDeTravail)) {
  363.             // set the owning side to null (unless already changed)
  364.             if ($demandeDeTravail->getUserId() === $this) {
  365.                 $demandeDeTravail->setUserId(null);
  366.             }
  367.         }
  368.         return $this;
  369.     }
  370.     /**
  371.      * @return Collection<int, OffreDeTravail>
  372.      */
  373.     public function getOffreDeTravails(): Collection
  374.     {
  375.         return $this->offreDeTravails;
  376.     }
  377.     public function addOffreDeTravail(OffreDeTravail $offreDeTravail): static
  378.     {
  379.         if (!$this->offreDeTravails->contains($offreDeTravail)) {
  380.             $this->offreDeTravails->add($offreDeTravail);
  381.             $offreDeTravail->setUserId($this);
  382.         }
  383.         return $this;
  384.     }
  385.     public function removeOffreDeTravail(OffreDeTravail $offreDeTravail): static
  386.     {
  387.         if ($this->offreDeTravails->removeElement($offreDeTravail)) {
  388.             // set the owning side to null (unless already changed)
  389.             if ($offreDeTravail->getUserId() === $this) {
  390.                 $offreDeTravail->setUserId(null);
  391.             }
  392.         }
  393.         return $this;
  394.     }
  395.     /**
  396.      * @return Collection<int, Evaluation>
  397.      */
  398.     public function getEvaluations(): Collection
  399.     {
  400.         return $this->evaluations;
  401.     }
  402.     public function addEvaluation(Evaluation $evaluation): static
  403.     {
  404.         if (!$this->evaluations->contains($evaluation)) {
  405.             $this->evaluations->add($evaluation);
  406.             $evaluation->setUserIdAuteur($this);
  407.         }
  408.         return $this;
  409.     }
  410.     public function removeEvaluation(Evaluation $evaluation): static
  411.     {
  412.         if ($this->evaluations->removeElement($evaluation)) {
  413.             // set the owning side to null (unless already changed)
  414.             if ($evaluation->getUserIdAuteur() === $this) {
  415.                 $evaluation->setUserIdAuteur(null);
  416.             }
  417.         }
  418.         return $this;
  419.     }
  420.     /**
  421.      * @return Collection<int, Message>
  422.      */
  423.     public function getMessages(): Collection
  424.     {
  425.         return $this->messages;
  426.     }
  427.     public function addMessage(Message $message): static
  428.     {
  429.         if (!$this->messages->contains($message)) {
  430.             $this->messages->add($message);
  431.             $message->setExpediteurId($this);
  432.         }
  433.         return $this;
  434.     }
  435.     public function removeMessage(Message $message): static
  436.     {
  437.         if ($this->messages->removeElement($message)) {
  438.             // set the owning side to null (unless already changed)
  439.             if ($message->getExpediteurId() === $this) {
  440.                 $message->setExpediteurId(null);
  441.             }
  442.         }
  443.         return $this;
  444.     }
  445.     /**
  446.      * @return Collection<int, Notification>
  447.      */
  448.     public function getNotifications(): Collection
  449.     {
  450.         return $this->notifications;
  451.     }
  452.     public function addNotification(Notification $notification): static
  453.     {
  454.         if (!$this->notifications->contains($notification)) {
  455.             $this->notifications->add($notification);
  456.             $notification->setUserId($this);
  457.         }
  458.         return $this;
  459.     }
  460.     public function removeNotification(Notification $notification): static
  461.     {
  462.         if ($this->notifications->removeElement($notification)) {
  463.             // set the owning side to null (unless already changed)
  464.             if ($notification->getUserId() === $this) {
  465.                 $notification->setUserId(null);
  466.             }
  467.         }
  468.         return $this;
  469.     }
  470. }