src/Entity/User.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  9. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  10. use Symfony\Component\Security\Core\User\UserInterface;
  11. /**
  12.  * @ORM\Entity(repositoryClass=UserRepository::class)
  13.  * @UniqueEntity(fields={"email"}, message="There is already an account associated with this email address.")
  14.  */
  15. class User implements UserInterfacePasswordAuthenticatedUserInterface
  16. {
  17.     /**
  18.      * @ORM\Id
  19.      * @ORM\GeneratedValue
  20.      * @ORM\Column(type="integer")
  21.      */
  22.     private $id;
  23.     /**
  24.      * @ORM\Column(type="string", length=180, unique=true)
  25.      */
  26.     private $email;
  27.     /**
  28.      * @ORM\Column(type="json")
  29.      */
  30.     private $roles = [];
  31.     /**
  32.      * @var string The hashed password
  33.      * @ORM\Column(type="string")
  34.      */
  35.     private $password;
  36.     /**
  37.      * @ORM\Column(type="boolean")
  38.      */
  39.     private $isVerified false;
  40.     /**
  41.      * @ORM\Column(type="string", length=255, nullable=true)
  42.      */
  43.     private $firstname;
  44.     /**
  45.      * @ORM\Column(type="string", length=255, nullable=true)
  46.      */
  47.     private $lastname;
  48.     /**
  49.      * @ORM\Column(type="string", length=255, nullable=true)
  50.      */
  51.     private $phone;
  52.     /**
  53.      * @ORM\Column(type="string", length=255)
  54.      */
  55.     public $type 'freelance';
  56.     /**
  57.      * @ORM\Column(type="string", length=255, nullable=true)
  58.      */
  59.     private $photo;
  60.     /**
  61.      * @ORM\OneToOne(targetEntity=Society::class, mappedBy="user", cascade={"persist", "remove"})
  62.      */
  63.     private $society;
  64.     /**
  65.      * @ORM\OneToMany(targetEntity=Profile::class, mappedBy="user", orphanRemoval=true)
  66.      */
  67.     private $profiles;
  68.     /**
  69.      * @ORM\Column(type="datetime", nullable=true)
  70.      */
  71.     private $deleteAt;
  72.     /**
  73.      * @ORM\Column(type="datetime", nullable=true)
  74.      */
  75.     private $lastConnection;
  76.     /**
  77.      * @ORM\OneToMany(targetEntity=Message::class, mappedBy="writer")
  78.      */
  79.     private $messages;
  80.     /**
  81.      * @ORM\OneToMany(targetEntity=Room::class, mappedBy="caller")
  82.      */
  83.     private $rooms;
  84.     /**
  85.      * @ORM\OneToMany(targetEntity=OfferFavorite::class, mappedBy="user", orphanRemoval=true)
  86.      */
  87.     private $offerFavorites;
  88.     /**
  89.      * @ORM\Column(type="datetime")
  90.      */
  91.     private $createdAt;
  92.     /**
  93.      * @ORM\OneToMany(targetEntity=AuthLog::class, mappedBy="user", orphanRemoval=true)
  94.      */
  95.     private $authLogs;
  96.     /**
  97.      * @ORM\OneToMany(targetEntity=OfferVisit::class, mappedBy="user", orphanRemoval=true)
  98.      */
  99.     private $offerVisits;
  100.     /**
  101.      * @ORM\OneToMany(targetEntity=Report::class, mappedBy="user", orphanRemoval=true)
  102.      */
  103.     private $reports;
  104.     /**
  105.      * @ORM\OneToMany(targetEntity=OfferAlert::class, mappedBy="user", orphanRemoval=true)
  106.      */
  107.     private $offerAlerts;
  108.     /**
  109.      * @ORM\OneToMany(targetEntity=ProfileFavorite::class, mappedBy="user")
  110.      */
  111.     private $profileFavorites;
  112.     /**
  113.      * @ORM\Column(type="integer", nullable=true)
  114.      */
  115.     private $civility;
  116.     /**
  117.      * @ORM\Column(type="string", length=50, nullable=true)
  118.      */
  119.     private $jobSociety;
  120.     /**
  121.      * @ORM\ManyToOne(targetEntity=Society::class)
  122.      */
  123.     private $CompteSociety;
  124.     /**
  125.      * @ORM\Column(type="boolean", nullable=true)
  126.      */
  127.     private $compteTestIsNotActive;
  128.     /**
  129.      * @ORM\OneToOne(targetEntity=ForumUser::class, mappedBy="user", cascade={"persist", "remove"})
  130.      */
  131.     private $forumUser;
  132.     public function __construct()
  133.     {
  134.         $this->profiles = new ArrayCollection();
  135.         $this->messages = new ArrayCollection();
  136.         $this->rooms = new ArrayCollection();
  137.         $this->offerFavorites = new ArrayCollection();
  138.         $this->authLogs = new ArrayCollection();
  139.         $this->offerVisits = new ArrayCollection();
  140.         $this->reports = new ArrayCollection();
  141.         $this->offerAlerts = new ArrayCollection();
  142.         $this->profileFavorites = new ArrayCollection();
  143.     }
  144.     // ---------------------------------
  145.     public function getCivilityString(): string
  146.     {
  147.         if ($this->civility == 1){
  148.             return "Mr.";
  149.         }
  150.         if ($this->civility == 2){
  151.             return "Ms.";
  152.         }
  153.         return "";
  154.     }
  155.     public function isRole(string $role){
  156.         if (in_array($role$this->roles)){
  157.             return true;
  158.         }
  159.         return false;
  160.     }
  161.     // ---------------------------------
  162.     public function getId(): ?int
  163.     {
  164.         return $this->id;
  165.     }
  166.     public function getEmail(): ?string
  167.     {
  168.         return $this->email;
  169.     }
  170.     public function setEmail(string $email): self
  171.     {
  172.         $this->email $email;
  173.         return $this;
  174.     }
  175.     /**
  176.      * A visual identifier that represents this user.
  177.      *
  178.      * @see UserInterface
  179.      */
  180.     public function getUserIdentifier(): string
  181.     {
  182.         return (string)$this->email;
  183.     }
  184.     /**
  185.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  186.      */
  187.     public function getUsername(): string
  188.     {
  189.         return (string)$this->email;
  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.     /**
  207.      * @see PasswordAuthenticatedUserInterface
  208.      */
  209.     public function getPassword(): string
  210.     {
  211.         return $this->password;
  212.     }
  213.     public function setPassword(string $password): self
  214.     {
  215.         $this->password $password;
  216.         return $this;
  217.     }
  218.     /**
  219.      * Returning a salt is only needed, if you are not using a modern
  220.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  221.      *
  222.      * @see UserInterface
  223.      */
  224.     public function getSalt(): ?string
  225.     {
  226.         return null;
  227.     }
  228.     /**
  229.      * @see UserInterface
  230.      */
  231.     public function eraseCredentials()
  232.     {
  233.         // If you store any temporary, sensitive data on the user, clear it here
  234.         // $this->plainPassword = null;
  235.     }
  236.     public function isVerified(): bool
  237.     {
  238.         return $this->isVerified;
  239.     }
  240.     public function hasProfile(): bool
  241.     {
  242.         return $this->getUniqueProfile()->getId() !== null;
  243.     }
  244.     public function setIsVerified(bool $isVerified): self
  245.     {
  246.         $this->isVerified $isVerified;
  247.         return $this;
  248.     }
  249.     public function getType(): ?string
  250.     {
  251.         return $this->type;
  252.     }
  253.     public function setType(string $type): self
  254.     {
  255.         $this->type $type;
  256.         return $this;
  257.     }
  258.     public function getPhoto(): ?string
  259.     {
  260.         if($this->getCompteSociety()){
  261.             $societe $this->getCompteSociety();
  262.             return $societe->getUser()->getPhoto();
  263.         }
  264.         return $this->photo;
  265.     }
  266.     public function setPhoto(?string $photo): self
  267.     {
  268.         $this->photo $photo;
  269.         return $this;
  270.     }
  271.     public function getFullName(): string
  272.     {
  273.         if ($this->type == 'freelance'){
  274.             $profile $this->getUniqueProfile();
  275.             return $profile->getFullName();
  276.         }
  277.         return $this->firstname ' ' $this->lastname;
  278.     }
  279.     public function getSociety(): ?Society
  280.     {
  281.         if($this->getCompteSociety() && in_array("ROLE_RECRUTEUR"$this->roles)){
  282.             return $this->getCompteSociety();
  283.         }
  284.         return $this->society;
  285.     }
  286.     public function setSociety(Society $society): self
  287.     {
  288.         // set the owning side of the relation if necessary
  289.         if ($society->getUser() !== $this) {
  290.             $society->setUser($this);
  291.         }
  292.         $this->society $society;
  293.         return $this;
  294.     }
  295.     public function isFreelance(): bool
  296.     {
  297.         return $this->type === 'freelance';
  298.     }
  299.     public function isSociety(): bool
  300.     {
  301.         if($this->getCompteSociety()){
  302.             return true;
  303.         }
  304.         return $this->type === 'society';
  305.     }
  306.     public function isAdmin(): bool
  307.     {
  308.         return $this->type == 'admin';
  309.     }
  310.     /**
  311.      * @return Collection|Profile[]
  312.      */
  313.     public function getProfiles(): Collection
  314.     {
  315.         return $this->profiles;
  316.     }
  317.     public function addProfile(Profile $profile): self
  318.     {
  319.         if (!$this->profiles->contains($profile)) {
  320.             $this->profiles[] = $profile;
  321.             $profile->setUser($this);
  322.         }
  323.         return $this;
  324.     }
  325.     public function removeProfile(Profile $profile): self
  326.     {
  327.         if ($this->profiles->removeElement($profile)) {
  328.             // set the owning side to null (unless already changed)
  329.             if ($profile->getUser() === $this) {
  330.                 $profile->setUser(null);
  331.             }
  332.         }
  333.         return $this;
  334.     }
  335.     public function getUniqueProfile(): Profile
  336.     {
  337.         return $this->getProfiles()->isEmpty()
  338.             ? (new Profile())
  339.                 ->setUser($this)
  340.                 ->setIsIntercontrat($this->isSociety())
  341.                 ->setName($this->isFreelance() ? $this->getLastname() : 'Intercontrat')
  342.                 ->setPhone($this->getPhone() ?? '')
  343.                 ->setFirstname($this->isFreelance() ? $this->getFirstname() : 'Intercontrat')
  344.             : $this->getProfiles()->first();
  345.     }
  346.     public function getDeleteAt(): ?\DateTimeInterface
  347.     {
  348.         return $this->deleteAt;
  349.     }
  350.     public function setDeleteAt(?\DateTimeInterface $deleteAt): self
  351.     {
  352.         $this->deleteAt $deleteAt;
  353.         return $this;
  354.     }
  355.     public function getLastConnection(): ?\DateTimeInterface
  356.     {
  357.         return $this->lastConnection;
  358.     }
  359.     public function setLastConnection(?\DateTimeInterface $lastConnection): self
  360.     {
  361.         $this->lastConnection $lastConnection;
  362.         return $this;
  363.     }
  364.     /**
  365.      * @return Collection|Message[]
  366.      */
  367.     public function getMessages(): Collection
  368.     {
  369.         return $this->messages;
  370.     }
  371.     public function addMessage(Message $message): self
  372.     {
  373.         if (!$this->messages->contains($message)) {
  374.             $this->messages[] = $message;
  375.             $message->setWriter($this);
  376.         }
  377.         return $this;
  378.     }
  379.     public function removeMessage(Message $message): self
  380.     {
  381.         if ($this->messages->removeElement($message)) {
  382.             // set the owning side to null (unless already changed)
  383.             if ($message->getWriter() === $this) {
  384.                 $message->setWriter(null);
  385.             }
  386.         }
  387.         return $this;
  388.     }
  389.     /**
  390.      * @return Collection|Room[]
  391.      */
  392.     public function getRooms(): Collection
  393.     {
  394.         return $this->rooms;
  395.     }
  396.     public function addRoom(Room $room): self
  397.     {
  398.         if (!$this->rooms->contains($room)) {
  399.             $this->rooms[] = $room;
  400.             $room->setCaller($this);
  401.         }
  402.         return $this;
  403.     }
  404.     public function removeRoom(Room $room): self
  405.     {
  406.         if ($this->rooms->removeElement($room)) {
  407.             // set the owning side to null (unless already changed)
  408.             if ($room->getCaller() === $this) {
  409.                 $room->setCaller(null);
  410.             }
  411.         }
  412.         return $this;
  413.     }
  414.     /**
  415.      * @return Collection|OfferFavorite[]
  416.      */
  417.     public function getOfferFavorites(): Collection
  418.     {
  419.         return $this->offerFavorites;
  420.     }
  421.     public function addOfferFavorite(OfferFavorite $offerFavorite): self
  422.     {
  423.         if (!$this->offerFavorites->contains($offerFavorite)) {
  424.             $this->offerFavorites[] = $offerFavorite;
  425.             $offerFavorite->setUser($this);
  426.         }
  427.         return $this;
  428.     }
  429.     public function removeOfferFavorite(OfferFavorite $offerFavorite): self
  430.     {
  431.         if ($this->offerFavorites->removeElement($offerFavorite)) {
  432.             // set the owning side to null (unless already changed)
  433.             if ($offerFavorite->getUser() === $this) {
  434.                 $offerFavorite->setUser(null);
  435.             }
  436.         }
  437.         return $this;
  438.     }
  439.     public function getCreatedAt(): ?\DateTimeInterface
  440.     {
  441.         return $this->createdAt;
  442.     }
  443.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  444.     {
  445.         $this->createdAt $createdAt;
  446.         return $this;
  447.     }
  448.     /**
  449.      * @return Collection|AuthLog[]
  450.      */
  451.     public function getAuthLogs(): Collection
  452.     {
  453.         return $this->authLogs;
  454.     }
  455.     public function addAuthLog(AuthLog $authLog): self
  456.     {
  457.         if (!$this->authLogs->contains($authLog)) {
  458.             $this->authLogs[] = $authLog;
  459.             $authLog->setUser($this);
  460.         }
  461.         return $this;
  462.     }
  463.     public function removeAuthLog(AuthLog $authLog): self
  464.     {
  465.         if ($this->authLogs->removeElement($authLog)) {
  466.             // set the owning side to null (unless already changed)
  467.             if ($authLog->getUser() === $this) {
  468.                 $authLog->setUser(null);
  469.             }
  470.         }
  471.         return $this;
  472.     }
  473.     /**
  474.      * @return Collection|OfferVisit[]
  475.      */
  476.     public function getOfferVisits(): Collection
  477.     {
  478.         return $this->offerVisits;
  479.     }
  480.     public function addOfferVisit(OfferVisit $offerVisit): self
  481.     {
  482.         if (!$this->offerVisits->contains($offerVisit)) {
  483.             $this->offerVisits[] = $offerVisit;
  484.             $offerVisit->setUser($this);
  485.         }
  486.         return $this;
  487.     }
  488.     public function removeOfferVisit(OfferVisit $offerVisit): self
  489.     {
  490.         if ($this->offerVisits->removeElement($offerVisit)) {
  491.             // set the owning side to null (unless already changed)
  492.             if ($offerVisit->getUser() === $this) {
  493.                 $offerVisit->setUser(null);
  494.             }
  495.         }
  496.         return $this;
  497.     }
  498.     public function getPublicName(): ?string
  499.     {
  500.         return $this->isSociety()
  501.             ? $this->getSociety()->getName()
  502.             : $this->getUniqueProfile()->getPublicName();
  503.     }
  504.     /**
  505.      * @return Collection|Report[]
  506.      */
  507.     public function getReports(): Collection
  508.     {
  509.         return $this->reports;
  510.     }
  511.     public function addReport(Report $report): self
  512.     {
  513.         if (!$this->reports->contains($report)) {
  514.             $this->reports[] = $report;
  515.             $report->setUser($this);
  516.         }
  517.         return $this;
  518.     }
  519.     public function removeReport(Report $report): self
  520.     {
  521.         if ($this->reports->removeElement($report)) {
  522.             // set the owning side to null (unless already changed)
  523.             if ($report->getUser() === $this) {
  524.                 $report->setUser(null);
  525.             }
  526.         }
  527.         return $this;
  528.     }
  529.     /**
  530.      * @return Collection|OfferAlert[]
  531.      */
  532.     public function getOfferAlerts(): Collection
  533.     {
  534.         return $this->offerAlerts;
  535.     }
  536.     public function addOfferAlert(OfferAlert $offerAlert): self
  537.     {
  538.         if (!$this->offerAlerts->contains($offerAlert)) {
  539.             $this->offerAlerts[] = $offerAlert;
  540.             $offerAlert->setUser($this);
  541.         }
  542.         return $this;
  543.     }
  544.     public function removeOfferAlert(OfferAlert $offerAlert): self
  545.     {
  546.         if ($this->offerAlerts->removeElement($offerAlert)) {
  547.             // set the owning side to null (unless already changed)
  548.             if ($offerAlert->getUser() === $this) {
  549.                 $offerAlert->setUser(null);
  550.             }
  551.         }
  552.         return $this;
  553.     }
  554.     public function isOauth(): bool
  555.     {
  556.         return $this->password == 'nopass';
  557.     }
  558.     /**
  559.      * @return Collection<int, ProfileFavorite>
  560.      */
  561.     public function getProfileFavorites(): Collection
  562.     {
  563.         return $this->profileFavorites;
  564.     }
  565.     public function addProfileFavorite(ProfileFavorite $profileFavorite): self
  566.     {
  567.         if (!$this->profileFavorites->contains($profileFavorite)) {
  568.             $this->profileFavorites[] = $profileFavorite;
  569.             $profileFavorite->setUser($this);
  570.         }
  571.         return $this;
  572.     }
  573.     public function removeProfileFavorite(ProfileFavorite $profileFavorite): self
  574.     {
  575.         if ($this->profileFavorites->removeElement($profileFavorite)) {
  576.             // set the owning side to null (unless already changed)
  577.             if ($profileFavorite->getUser() === $this) {
  578.                 $profileFavorite->setUser(null);
  579.             }
  580.         }
  581.         return $this;
  582.     }
  583.     public function isIsVerified(): ?bool
  584.     {
  585.         return $this->isVerified;
  586.     }
  587.     public function getPhone(): ?string
  588.     {
  589.         return $this->phone;
  590.     }
  591.     public function setPhone(?string $phone): self
  592.     {
  593.         $this->phone $phone;
  594.         return $this;
  595.     }
  596.     public function getCivility(): ?int
  597.     {
  598.         return $this->civility;
  599.     }
  600.     public function setCivility(?int $civility): self
  601.     {
  602.         $this->civility $civility;
  603.         return $this;
  604.     }
  605.     public function getJobSociety(): ?string
  606.     {
  607.         return $this->jobSociety;
  608.     }
  609.     public function setJobSociety(?string $jobSociety): self
  610.     {
  611.         $this->jobSociety $jobSociety;
  612.         return $this;
  613.     }
  614.     public function getCompteSociety(): ?Society
  615.     {
  616.         return $this->CompteSociety;
  617.     }
  618.     public function setCompteSociety(?Society $CompteSociety): self
  619.     {
  620.         $this->CompteSociety $CompteSociety;
  621.         return $this;
  622.     }
  623.     public function isCompteTestIsNotActive(): ?bool
  624.     {
  625.         return $this->compteTestIsNotActive;
  626.     }
  627.     public function setCompteTestIsNotActive(?bool $compteTestIsNotActive): self
  628.     {
  629.         $this->compteTestIsNotActive $compteTestIsNotActive;
  630.         return $this;
  631.     }
  632.     public function getFirstname(): ?string
  633.     {
  634.         return $this->firstname;
  635.     }
  636.     public function setFirstname(?string $firstname): self
  637.     {
  638.         $this->firstname $firstname;
  639.         return $this;
  640.     }
  641.     public function getLastname(): ?string
  642.     {
  643.         return $this->lastname;
  644.     }
  645.     public function setLastname(?string $lastname): self
  646.     {
  647.         $this->lastname $lastname;
  648.         return $this;
  649.     }
  650.     public function getForumUser(): ?ForumUser
  651.     {
  652.         return $this->forumUser;
  653.     }
  654.     public function setForumUser(?ForumUser $forumUser): self
  655.     {
  656.         // unset the owning side of the relation if necessary
  657.         if ($forumUser === null && $this->forumUser !== null) {
  658.             $this->forumUser->setUser(null);
  659.         }
  660.         // set the owning side of the relation if necessary
  661.         if ($forumUser !== null && $forumUser->getUser() !== $this) {
  662.             $forumUser->setUser($this);
  663.         }
  664.         $this->forumUser $forumUser;
  665.         return $this;
  666.     }
  667. }