src/Entity/Core/Users.php line 36

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Core;
  3. use App\Entity\Cvs\Candidates;
  4. use App\Entity\Houses\Syndicats;
  5. use App\Repository\Core\UsersRepository;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Security\Core\User\UserInterface;
  9. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  12. use Symfony\Component\HttpFoundation\File\File;
  13. use Symfony\Component\HttpFoundation\File\UploadedFile;
  14. use Vich\UploaderBundle\Entity\File as EmbeddedFile;
  15. use ApiPlatform\Core\Annotation\ApiResource;
  16. use Symfony\Component\Serializer\Annotation\Groups;
  17. use Symfony\Component\Serializer\Annotation\SerializedName;
  18. use Serializable;
  19. use DateTimeImmutable;
  20. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  21. use Vich\UploaderBundle\Templating\Helper\UploaderHelper;
  22. /**
  23.  * @ORM\Entity(repositoryClass=UsersRepository::class)
  24.  * @ORM\Table(name="users")
  25.  * @ORM\HasLifecycleCallbacks()
  26.  * @Vich\Uploadable
  27.  *
  28.  * @ApiResource(
  29.  *     normalizationContext={"groups"={"user:read"}},
  30.  *     denormalizationContext={"groups"={"user:write"}}
  31.  * )
  32.  */
  33. class Users implements UserInterfacePasswordAuthenticatedUserInterface\Serializable
  34. {
  35.     /**
  36.      * @ORM\Id
  37.      * @ORM\GeneratedValue
  38.      * @ORM\Column(type="integer")
  39.      *
  40.      * @Groups("user:read")
  41.      */
  42.     private $id;
  43.     /**
  44.      * @var datetime
  45.      *
  46.      * @ORM\Column(name="createdAt", type="datetime", nullable=true)
  47.      *
  48.      * @Groups("user:read")
  49.      */
  50.     private $createdAt;
  51.     /**
  52.      * @var datetime
  53.      *
  54.      * @ORM\Column(name="updatedAt", type="datetime", nullable=true)
  55.      */
  56.     private $updatedAt;
  57.     /**
  58.      * @var datetime
  59.      *
  60.      * @ORM\Column(name="last_login", type="datetime", nullable=true)
  61.      */
  62.     private $lastLogin;
  63.     /**
  64.      * @ORM\Column(type="string", length=180, unique=true)
  65.      * @Groups("user:read")
  66.      */
  67.     private $email;
  68.     /**
  69.      * @ORM\Column(type="string", length=180, nullable=true)
  70.      * @Groups("user:read")
  71.      */
  72.     private $name;
  73.     /**
  74.      * @ORM\Column(type="string", length=180, nullable=true)
  75.      * @Groups("user:read")
  76.      */
  77.     private $lastname;
  78.     /**
  79.      * @ORM\Column(type="json")
  80.      */
  81.     private $roles = [];
  82.     /**
  83.      * @var string The hashed password
  84.      * @ORM\Column(type="string")
  85.      */
  86.     private $password;
  87.     /**
  88.      * @ORM\Column(type="string", length=180, nullable=true)
  89.      */
  90.     private $username;
  91.     /**
  92.      * @ORM\Column(type="boolean", length=180, nullable=true)
  93.      */
  94.     private $first;
  95.     /**
  96.      * @ORM\Column(type="boolean", length=180, nullable=true)
  97.      */
  98.     private $enabled;
  99.     /**
  100.      * @ORM\Column(type="boolean", length=11, nullable=true)
  101.      */
  102.     private $verification;
  103.     /**
  104.      * @var string
  105.      *
  106.      * @ORM\Column(name="premium", type="boolean", nullable=false)
  107.      */
  108.     private $premium;
  109.     /**
  110.      * NOTE: This is not a mapped field of entity metadata, just a simple property.
  111.      *
  112.      * @Vich\UploadableField(mapping="avatars_files", fileNameProperty="image.name", size="image.size", mimeType="image.mimeType", originalName="image.originalName", dimensions="image.dimensions")
  113.      *
  114.      * @var File|null
  115.      */
  116.     private $imageFile;
  117.     /**
  118.      * @ORM\Embedded(class="Vich\UploaderBundle\Entity\File")
  119.      *
  120.      * @var EmbeddedFile
  121.      */
  122.     private $image;
  123.     /**
  124.      * @var \Agencies
  125.      *
  126.      * @ORM\ManyToOne(targetEntity="App\Entity\Core\Agencies")
  127.      * @ORM\JoinColumns({
  128.      *   @ORM\JoinColumn(name="current_agency_id", referencedColumnName="id", nullable=true)
  129.      * })
  130.      */
  131.     protected $currentAgency;
  132.     /**
  133.      * @var \Agencies
  134.      *
  135.      * @ORM\ManyToOne(targetEntity="App\Entity\Houses\Syndicats")
  136.      * @ORM\JoinColumns({
  137.      *   @ORM\JoinColumn(name="current_syndicat_id", referencedColumnName="id", nullable=true)
  138.      * })
  139.      */
  140.     protected $currentSyndicat;
  141.     /**
  142.      * @ORM\Column(name="password_forgotten", type="string", length=180, nullable=true)
  143.      */
  144.     private $passwordForgotten;
  145.     /**
  146.      * @var datetime
  147.      *
  148.      * @ORM\Column(name="password_forgotten_last_date", type="datetime", nullable=true)
  149.      */
  150.     private $passwordForgottenLastDate;
  151.     /**
  152.      * @var \Rib
  153.      *
  154.      * @ORM\ManyToOne(targetEntity="App\Entity\Core\Rib")
  155.      * @ORM\JoinColumns({
  156.      *   @ORM\JoinColumn(name="rib_id", referencedColumnName="id", nullable=true)
  157.      * })
  158.      */
  159.     protected $rib;
  160.     /**
  161.      * @var string
  162.      *
  163.      * @ORM\Column(name="partenariat", type="boolean", nullable=true)
  164.      */
  165.     private $partenariat;
  166.     /**
  167.      * @ORM\Column(name="description", type="text", nullable=true)
  168.      */
  169.     private $description;
  170.     /**
  171.      * @var string
  172.      *
  173.      * @ORM\Column(name="notifications_messages", type="boolean", nullable=true)
  174.      */
  175.     private $notificationsMessages;
  176.     /**
  177.      * @var string
  178.      *
  179.      * @ORM\Column(name="notifications_suivis", type="boolean", nullable=true)
  180.      */
  181.     private $notificationsSuivis;
  182.     /**
  183.      * @var string
  184.      *
  185.      * @ORM\Column(name="user_commission_unit", type="float", length=11, nullable=true)
  186.      */
  187.     private $userCommissionUnit;
  188.     /**
  189.      * @var string
  190.      *
  191.      * @ORM\Column(name="user_commission_pourcent", type="float", length=11, nullable=true)
  192.      */
  193.     private $userCommissionPourcent;
  194.     /**
  195.      * @var string
  196.      *
  197.      * @ORM\Column(name="type_account", type="string", length=255, nullable=true)
  198.      */
  199.     private $typeAccount;
  200.     /**
  201.      * @var \Candidates
  202.      *
  203.      * @ORM\ManyToOne(targetEntity="App\Entity\Cvs\Candidates")
  204.      * @ORM\JoinColumns({
  205.      *   @ORM\JoinColumn(name="candidate_id", referencedColumnName="id", nullable=true)
  206.      * })
  207.      */
  208.     protected $candidate;
  209.     /**
  210.      * @var string
  211.      *
  212.      * @ORM\Column(name="subscription_customer_stripe", type="string", length=255, nullable=true)
  213.      */
  214.     private $subscriptionCustomerStripe;
  215.     /**
  216.      * @ORM\Column(type="string", length=255, nullable=true)
  217.      */
  218.     private $verificationToken;
  219.     /**
  220.      * @ORM\Column(type="datetime", nullable=true)
  221.      */
  222.     private $tokenExpiration;
  223.     /**
  224.      * @ORM\Column(name="language", type="text", nullable=true)
  225.      */
  226.     private $language;
  227.     /**
  228.      * @ORM\Column(name="motif_verification", type="text", nullable=true)
  229.      */
  230.     private $motif;
  231.     public function __construct()
  232.     {
  233.         $this->image = new \Vich\UploaderBundle\Entity\File();
  234.     }
  235.     /**
  236.      * @ORM\PrePersist
  237.      */
  238.     public function setCreatedAtValue(): void
  239.     {
  240.         $this->setCreatedAt( new \DateTime("now"));
  241.         $this->setUpdatedAt( new \DateTime("now"));
  242.         $this->setPremium(false);
  243.     }
  244.     /**
  245.      * @ORM\PreUpdate
  246.      */
  247.     public function setUpdatedAtValue(): void
  248.     {
  249.         $this->setUpdatedAt( new \DateTime("now"));
  250.     }
  251.     public function __toString()
  252.     {
  253.         return "#".$this->id." ".$this->getName()." ".$this->getLastname();
  254.     }
  255.     public function getTitlePartner(): ?string
  256.     {
  257.         return "#".$this->id." ".$this->getName()." ".$this->getLastname();
  258.     }
  259.     public function serialize(): string
  260.     {
  261.         return serialize([
  262.             $this->id,
  263.             $this->email,
  264.             $this->password,
  265.             // autres propriétés que vous souhaitez sérialiser, sauf $imageFile
  266.         ]);
  267.     }
  268.     public function unserialize($serialized): void
  269.     {
  270.         list(
  271.             $this->id,
  272.             $this->email,
  273.             $this->password,
  274.             // autres propriétés que vous souhaitez désérialiser, sauf $imageFile
  275.             ) = unserialize($serialized);
  276.     }
  277.     public function getId(): ?int
  278.     {
  279.         return $this->id;
  280.     }
  281.     /**
  282.      * Retourne l'identifiant unique de l'utilisateur pour Symfony 5.3+
  283.      * On utilise l'email comme identifiant
  284.      */
  285.     public function getUserIdentifier(): string
  286.     {
  287.         return (string) $this->email;
  288.     }
  289.     public function getEmail(): ?string
  290.     {
  291.         return $this->email;
  292.     }
  293.     public function setEmail(string $email): self
  294.     {
  295.         $this->email $email;
  296.         return $this;
  297.     }
  298.     /**
  299.      * @see UserInterface
  300.      */
  301.     public function getRoles(): array
  302.     {
  303.         $roles $this->roles;
  304.         // guarantee every user at least has ROLE_USER
  305.         $roles[] = 'ROLE_USER';
  306.         return array_unique($roles);
  307.     }
  308.     public function setRoles(array $roles): self
  309.     {
  310.         $this->roles $roles;
  311.         return $this;
  312.     }
  313.     /**
  314.      * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
  315.      * of 'UploadedFile' is injected into this setter to trigger the  update. If this
  316.      * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
  317.      * must be able to accept an instance of 'File' as the bundle will inject one here
  318.      * during Doctrine hydration.
  319.      *
  320.      * @param File|UploadedFile|null $imageFile
  321.      */
  322.     public function setImageFile(?File $imageFile null)
  323.     {
  324.         $this->imageFile $imageFile;
  325.         if (null !== $imageFile) {
  326.             // It is required that at least one field changes if you are using doctrine
  327.             // otherwise the event listeners won't be called and the file is lost
  328.             $this->setUpdatedAt(new \DateTime("now"));
  329.         }
  330.     }
  331.     public function getImageFile(): ?File
  332.     {
  333.         return $this->imageFile;
  334.     }
  335.     public function getImageBase64(): ?string
  336.     {
  337.         if (!$this->image || !$this->image->getName()) {
  338.             return null;
  339.         }
  340.         // Utiliser $_SERVER['DOCUMENT_ROOT'] qui pointe vers /public
  341.         $filePath $_SERVER['DOCUMENT_ROOT'] . '/uploads/avatars/' $this->image->getName();
  342.         if (!file_exists($filePath)) {
  343.             // Debug : retourner le chemin pour voir ce qui cloche
  344.             return null// ou "Path: " . $filePath pour debugger
  345.         }
  346.         $imageData file_get_contents($filePath);
  347.         $mimeType $this->image->getMimeType() ?? mime_content_type($filePath);
  348.         return 'data:' $mimeType ';base64,' base64_encode($imageData);
  349.     }
  350.     public function setImage(EmbeddedFile $image): void
  351.     {
  352.         $this->image $image;
  353.     }
  354.     public function getImage(): ?EmbeddedFile
  355.     {
  356.         return $this->image;
  357.     }
  358.     /**
  359.      * @see UserInterface
  360.      */
  361.     public function getPassword(): string
  362.     {
  363.         return (string) $this->password;
  364.     }
  365.     /**
  366.      * @see UserInterface
  367.      */
  368.     public function getUsername(): string
  369.     {
  370.         return (string) $this->username;
  371.     }
  372.     public function setPassword(string $password): self
  373.     {
  374.         $this->password $password;
  375.         return $this;
  376.     }
  377.     /**
  378.      * @see UserInterface
  379.      */
  380.     public function getSalt()
  381.     {
  382.         // not needed when using the "bcrypt" algorithm in security.yaml
  383.     }
  384.     /**
  385.      * @see UserInterface
  386.      */
  387.     public function eraseCredentials()
  388.     {
  389.         // If you store any temporary, sensitive data on the user, clear it here
  390.         // $this->plainPassword = null;
  391.     }
  392.     public function getCreatedAt(): ?\DateTimeInterface
  393.     {
  394.         return $this->createdAt;
  395.     }
  396.     public function setCreatedAt(?\DateTimeInterface $createdAt): self
  397.     {
  398.         $this->createdAt $createdAt;
  399.         return $this;
  400.     }
  401.     public function getUpdatedAt(): ?\DateTimeInterface
  402.     {
  403.         return $this->updatedAt;
  404.     }
  405.     public function setUpdatedAt(?\DateTimeInterface $updatedAt): self
  406.     {
  407.         $this->updatedAt $updatedAt;
  408.         return $this;
  409.     }
  410.     public function getLastLogin(): ?\DateTimeInterface
  411.     {
  412.         return $this->lastLogin;
  413.     }
  414.     public function setLastLogin(?\DateTimeInterface $lastLogin): self
  415.     {
  416.         $this->lastLogin $lastLogin;
  417.         return $this;
  418.     }
  419.     public function getName(): ?string
  420.     {
  421.         return $this->name;
  422.     }
  423.     public function setName(?string $name): self
  424.     {
  425.         $this->name $name;
  426.         return $this;
  427.     }
  428.     public function getLastname(): ?string
  429.     {
  430.         return $this->lastname;
  431.     }
  432.     public function setLastname(?string $lastname): self
  433.     {
  434.         $this->lastname $lastname;
  435.         return $this;
  436.     }
  437.     public function setUsername(?string $username): self
  438.     {
  439.         $this->username $username;
  440.         return $this;
  441.     }
  442.     public function getFirst(): ?bool
  443.     {
  444.         return $this->first;
  445.     }
  446.     public function setFirst(?bool $first): self
  447.     {
  448.         $this->first $first;
  449.         return $this;
  450.     }
  451.     public function getEnabled(): ?bool
  452.     {
  453.         return $this->enabled;
  454.     }
  455.     public function setEnabled(?bool $enabled): self
  456.     {
  457.         $this->enabled $enabled;
  458.         return $this;
  459.     }
  460.     public function getPremium(): ?bool
  461.     {
  462.         return $this->premium;
  463.     }
  464.     public function setPremium(bool $premium): self
  465.     {
  466.         $this->premium $premium;
  467.         return $this;
  468.     }
  469.     public function getPasswordForgotten(): ?string
  470.     {
  471.         return $this->passwordForgotten;
  472.     }
  473.     public function setPasswordForgotten(?string $passwordForgotten): self
  474.     {
  475.         $this->passwordForgotten $passwordForgotten;
  476.         return $this;
  477.     }
  478.     public function getPasswordForgottenLastDate(): ?\DateTimeInterface
  479.     {
  480.         return $this->passwordForgottenLastDate;
  481.     }
  482.     public function setPasswordForgottenLastDate(?\DateTimeInterface $passwordForgottenLastDate): self
  483.     {
  484.         $this->passwordForgottenLastDate $passwordForgottenLastDate;
  485.         return $this;
  486.     }
  487.     public function getPartenariat(): ?bool
  488.     {
  489.         return $this->partenariat;
  490.     }
  491.     public function setPartenariat(?bool $partenariat): self
  492.     {
  493.         $this->partenariat $partenariat;
  494.         return $this;
  495.     }
  496.     public function getDescription(): ?string
  497.     {
  498.         return $this->description;
  499.     }
  500.     public function setDescription(?string $description): self
  501.     {
  502.         $this->description $description;
  503.         return $this;
  504.     }
  505.     public function getNotificationsMessages(): ?bool
  506.     {
  507.         return $this->notificationsMessages;
  508.     }
  509.     public function setNotificationsMessages(?bool $notificationsMessages): self
  510.     {
  511.         $this->notificationsMessages $notificationsMessages;
  512.         return $this;
  513.     }
  514.     public function getNotificationsSuivis(): ?bool
  515.     {
  516.         return $this->notificationsSuivis;
  517.     }
  518.     public function setNotificationsSuivis(?bool $notificationsSuivis): self
  519.     {
  520.         $this->notificationsSuivis $notificationsSuivis;
  521.         return $this;
  522.     }
  523.     public function getUserCommissionUnit(): ?float
  524.     {
  525.         return $this->userCommissionUnit;
  526.     }
  527.     public function setUserCommissionUnit(?float $userCommissionUnit): self
  528.     {
  529.         $this->userCommissionUnit $userCommissionUnit;
  530.         return $this;
  531.     }
  532.     public function getUserCommissionPourcent(): ?float
  533.     {
  534.         return $this->userCommissionPourcent;
  535.     }
  536.     public function setUserCommissionPourcent(?float $userCommissionPourcent): self
  537.     {
  538.         $this->userCommissionPourcent $userCommissionPourcent;
  539.         return $this;
  540.     }
  541.     public function getCurrentAgency(): ?Agencies
  542.     {
  543.         return $this->currentAgency;
  544.     }
  545.     public function setCurrentAgency(?Agencies $currentAgency): self
  546.     {
  547.         $this->currentAgency $currentAgency;
  548.         return $this;
  549.     }
  550.     public function getRib(): ?Rib
  551.     {
  552.         return $this->rib;
  553.     }
  554.     public function setRib(?Rib $rib): self
  555.     {
  556.         $this->rib $rib;
  557.         return $this;
  558.     }
  559.     public function getCurrentSyndicat(): ?Syndicats
  560.     {
  561.         return $this->currentSyndicat;
  562.     }
  563.     public function setCurrentSyndicat(?Syndicats $currentSyndicat): self
  564.     {
  565.         $this->currentSyndicat $currentSyndicat;
  566.         return $this;
  567.     }
  568.     public function isFirst(): ?bool
  569.     {
  570.         return $this->first;
  571.     }
  572.     public function isEnabled(): ?bool
  573.     {
  574.         return $this->enabled;
  575.     }
  576.     public function isPremium(): ?bool
  577.     {
  578.         return $this->premium;
  579.     }
  580.     public function isPartenariat(): ?bool
  581.     {
  582.         return $this->partenariat;
  583.     }
  584.     public function isNotificationsMessages(): ?bool
  585.     {
  586.         return $this->notificationsMessages;
  587.     }
  588.     public function isNotificationsSuivis(): ?bool
  589.     {
  590.         return $this->notificationsSuivis;
  591.     }
  592.     public function getTypeAccount(): ?string
  593.     {
  594.         return $this->typeAccount;
  595.     }
  596.     public function setTypeAccount(?string $description): self
  597.     {
  598.         $this->typeAccount $description;
  599.         return $this;
  600.     }
  601.     public function getCandidate(): ?Candidates
  602.     {
  603.         return $this->candidate;
  604.     }
  605.     public function setCandidate(?Candidates $candidate): static
  606.     {
  607.         $this->candidate $candidate;
  608.         return $this;
  609.     }
  610.     public function getSubscriptionCustomerStripe(): ?string
  611.     {
  612.         return $this->subscriptionCustomerStripe;
  613.     }
  614.     public function setSubscriptionCustomerStripe(?string $subscriptionCustomerStripe): static
  615.     {
  616.         $this->subscriptionCustomerStripe $subscriptionCustomerStripe;
  617.         return $this;
  618.     }
  619.     public function getVerificationToken(): ?string
  620.     {
  621.         return $this->verificationToken;
  622.     }
  623.     public function setVerificationToken(?string $verificationToken): self
  624.     {
  625.         $this->verificationToken $verificationToken;
  626.         return $this;
  627.     }
  628.     public function getTokenExpiration(): ?\DateTimeInterface
  629.     {
  630.         return $this->tokenExpiration;
  631.     }
  632.     public function setTokenExpiration(?\DateTimeInterface $tokenExpiration): self
  633.     {
  634.         $this->tokenExpiration $tokenExpiration;
  635.         return $this;
  636.     }
  637.     public function getLanguage(): ?string
  638.     {
  639.         return $this->language;
  640.     }
  641.     public function setLanguage(?string $description): self
  642.     {
  643.         $this->language $description;
  644.         return $this;
  645.     }
  646.     public function isVerification(): ?bool
  647.     {
  648.         return $this->verification;
  649.     }
  650.     public function setVerification(?bool $verification): self
  651.     {
  652.         $this->verification $verification;
  653.         return $this;
  654.     }
  655.     public function getMotif(): ?string
  656.     {
  657.         return $this->motif;
  658.     }
  659.     public function setMotif(?string $motif): self
  660.     {
  661.         $this->motif $motif;
  662.         return $this;
  663.     }
  664. }