src/Entity/User.php line 19

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\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\PasswordHasher\Hasher\UserPasswordHasherInterface;
  11. /**
  12.  * @ORM\Entity(repositoryClass=UserRepository::class)
  13.  * @UniqueEntity(fields={"email"}, message="There is already an account with this email")
  14.  * @ORM\HasLifecycleCallbacks
  15.  */
  16. class User implements UserInterfacePasswordAuthenticatedUserInterface
  17. {
  18.     /**
  19.      * @ORM\Id
  20.      * @ORM\GeneratedValue
  21.      * @ORM\Column(type="integer")
  22.      */
  23.     private $id;
  24.     /**
  25.      * @ORM\Column(type="string", length=180, unique=true)
  26.      */
  27.     private $email;
  28.     /**
  29.      * @ORM\Column(type="json")
  30.      */
  31.     private $roles = [];
  32.     /**
  33.      * @var string The hashed password
  34.      * @ORM\Column(type="string")
  35.      */
  36.     private $password;
  37.     /**
  38.      * @ORM\Column(type="string", length=255, nullable=true)
  39.      */
  40.     private $phone;
  41.     /**
  42.      * @ORM\Column(type="string", length=255, nullable=true)
  43.      */
  44.     private $address;
  45.     /**
  46.      * @ORM\Column(type="string", length=255, nullable=true)
  47.      */
  48.     private $city;
  49.     /**
  50.      * @ORM\Column(type="date", nullable=true)
  51.      */
  52.     private $date_birth;
  53.     /**
  54.      * @ORM\Column(type="boolean")
  55.      */
  56.     private $isVerified false;
  57.     /**
  58.      * @ORM\OneToMany(targetEntity=Subscription::class, mappedBy="user")
  59.      */
  60.     private $subscriptions;
  61.     /**
  62.      * @ORM\ManyToOne(targetEntity=User::class, inversedBy="users")
  63.      */
  64.     private $partner;
  65.     /**
  66.      * @ORM\OneToMany(targetEntity=User::class, mappedBy="partner")
  67.      */
  68.     private $users;
  69.     private $canCode false;
  70.     /**
  71.      * @ORM\Column(type="datetime_immutable")
  72.      */
  73.     private $createdAt;
  74.     /**
  75.      * @ORM\Column(type="datetime_immutable")
  76.      */
  77.     private $updatedAt;
  78.     /**
  79.      * @ORM\Column(type="string", length=255, nullable=true)
  80.      */
  81.     private $fname;
  82.     /**
  83.      * @ORM\Column(type="string", length=255, nullable=true)
  84.      */
  85.     private $lname;
  86.     /**
  87.      * @ORM\OneToMany(targetEntity=DossierCPF::class, mappedBy="user")
  88.      */
  89.     private $dossierCPFs;
  90.     /**
  91.      * @ORM\Column(type="text", nullable=true)
  92.      */
  93.     private $data;
  94.     
  95.     public function __construct()
  96.     {
  97.         $this->subscriptions = new ArrayCollection();
  98.         $this->users = new ArrayCollection();
  99.         $this->dossierCPFs = new ArrayCollection();
  100.     }
  101.     public function __toString(): string
  102.     {
  103.         return $this->email;
  104.     }
  105.     public function getId(): ?int
  106.     {
  107.         return $this->id;
  108.     }
  109.     public function getEmail(): ?string
  110.     {
  111.         return $this->email;
  112.     }
  113.     public function setEmail(string $email): self
  114.     {
  115.         $this->email $email;
  116.         return $this;
  117.     }
  118.     /**
  119.      * A visual identifier that represents this user.
  120.      *
  121.      * @see UserInterface
  122.      */
  123.     public function getUserIdentifier(): string
  124.     {
  125.         return (string) $this->email;
  126.     }
  127.     /**
  128.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  129.      */
  130.     public function getUsername(): string
  131.     {
  132.         return (string) $this->email;
  133.     }
  134.     /**
  135.      * @see UserInterface
  136.      */
  137.     public function getRoles(): array
  138.     {
  139.         $roles $this->roles;
  140.         // guarantee every user at least has ROLE_USER
  141.         $roles[] = 'ROLE_USER';
  142.         return array_unique($roles);
  143.     }
  144.     public function setRoles(array $roles): self
  145.     {
  146.         $this->roles $roles;
  147.         return $this;
  148.     }
  149.     /**
  150.      * @see PasswordAuthenticatedUserInterface
  151.      */
  152.     public function getPassword(): string
  153.     {
  154.         return $this->password;
  155.     }
  156.     public function setPassword(string $password): self
  157.     {
  158.         $this->password $password;
  159.         return $this;
  160.     }
  161.     /**
  162.      * Returning a salt is only needed, if you are not using a modern
  163.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  164.      *
  165.      * @see UserInterface
  166.      */
  167.     public function getSalt(): ?string
  168.     {
  169.         return null;
  170.     }
  171.     /**
  172.      * @see UserInterface
  173.      */
  174.     public function eraseCredentials()
  175.     {
  176.         // If you store any temporary, sensitive data on the user, clear it here
  177.         // $this->plainPassword = null;
  178.     }
  179.     public function getPhone(): ?string
  180.     {
  181.         return $this->phone;
  182.     }
  183.     public function setPhone(?string $phone): self
  184.     {
  185.         $this->phone $phone;
  186.         return $this;
  187.     }
  188.     public function getAddress(): ?string
  189.     {
  190.         return $this->address;
  191.     }
  192.     public function setAddress(?string $address): self
  193.     {
  194.         $this->address $address;
  195.         return $this;
  196.     }
  197.     public function getCity(): ?string
  198.     {
  199.         return $this->city;
  200.     }
  201.     public function setCity(?string $city): self
  202.     {
  203.         $this->city $city;
  204.         return $this;
  205.     }
  206.     public function getDateBirth(): ?\DateTimeInterface
  207.     {
  208.         return $this->date_birth;
  209.     }
  210.     public function setDateBirth(?\DateTimeInterface $date_birth): self
  211.     {
  212.         $this->date_birth $date_birth;
  213.         return $this;
  214.     }
  215.     public function isVerified(): bool
  216.     {
  217.         return $this->isVerified;
  218.     }
  219.     public function setIsVerified(bool $isVerified): self
  220.     {
  221.         $this->isVerified $isVerified;
  222.         return $this;
  223.     }
  224.     /**
  225.      * @return Collection|Subscription[]
  226.      */
  227.     public function getSubscriptions(): Collection
  228.     {
  229.         return $this->subscriptions;
  230.     }
  231.     public function addSubscription(Subscription $subscription): self
  232.     {
  233.         if (!$this->subscriptions->contains($subscription)) {
  234.             $this->subscriptions[] = $subscription;
  235.             $subscription->setUser($this);
  236.         }
  237.         return $this;
  238.     }
  239.     public function removeSubscription(Subscription $subscription): self
  240.     {
  241.         if ($this->subscriptions->removeElement($subscription)) {
  242.             // set the owning side to null (unless already changed)
  243.             if ($subscription->getUser() === $this) {
  244.                 $subscription->setUser(null);
  245.             }
  246.         }
  247.         return $this;
  248.     }
  249.     public function getPartner(): ?self
  250.     {
  251.         return $this->partner;
  252.     }
  253.     public function setPartner(?self $partner): self
  254.     {
  255.         $this->partner $partner;
  256.         return $this;
  257.     }
  258.     /**
  259.      * @return Collection|self[]
  260.      */
  261.     public function getUsers(): Collection
  262.     {
  263.         return $this->users;
  264.     }
  265.     public function addUser(self $user): self
  266.     {
  267.         if (!$this->users->contains($user)) {
  268.             $this->users[] = $user;
  269.             $user->setPartner($this);
  270.         }
  271.         return $this;
  272.     }
  273.     public function removeUser(self $user): self
  274.     {
  275.         if ($this->users->removeElement($user)) {
  276.             // set the owning side to null (unless already changed)
  277.             if ($user->getPartner() === $this) {
  278.                 $user->setPartner(null);
  279.             }
  280.         }
  281.         return $this;
  282.     }
  283.     public function canCode()//: bool
  284.     {
  285.         $canCode false;
  286.         $excludedPacks = array(83738);
  287.         if($this->subscriptions){
  288.             foreach($this->subscriptions as $subscription){
  289.                 // if($subscription->getPack()->getCategory() == 'code' && $subscription->getStatus() == 1) $canCode = $subscription;
  290.                 if($subscription->getPack()->getCategory() == 'code' && $subscription->getStatus() == && !in_array($subscription->getPack()->getId(), $excludedPacks)) $canCode $subscription;
  291.             }
  292.         }
  293.         return $canCode;
  294.     }
  295.     public function getCreatedAt(): ?\DateTimeImmutable
  296.     {
  297.         return $this->createdAt;
  298.     }
  299.     public function setCreatedAt(\DateTimeImmutable $createdAt): self
  300.     {
  301.         $this->createdAt $createdAt;
  302.         return $this;
  303.     }
  304.     public function getUpdatedAt(): ?\DateTimeImmutable
  305.     {
  306.         return $this->updatedAt;
  307.     }
  308.     public function setUpdatedAt(\DateTimeImmutable $updatedAt): self
  309.     {
  310.         $this->updatedAt $updatedAt;
  311.         return $this;
  312.     }
  313.     public function getFname(): ?string
  314.     {
  315.         return $this->fname;
  316.     }
  317.     public function setFname(?string $fname): self
  318.     {
  319.         $this->fname $fname;
  320.         return $this;
  321.     }
  322.     public function getLname(): ?string
  323.     {
  324.         return $this->lname;
  325.     }
  326.     public function setLname(?string $lname): self
  327.     {
  328.         $this->lname $lname;
  329.         return $this;
  330.     }
  331.     /**
  332.      * @ORM\PrePersist
  333.      * @ORM\PreUpdate
  334.     */
  335.     public function updatedTimestamps(): void
  336.     {
  337.         $this->setUpdatedAt(new \DateTimeImmutable('now'));    
  338.         if ($this->getCreatedAt() === null) {
  339.             $this->setCreatedAt(new \DateTimeImmutable('now'));
  340.         }
  341.     }
  342.     /**
  343.      * @ORM\PreUpdate
  344.     */
  345.     public function preUpdate$eventArgs) {   
  346.         $oldPasswordValue $eventArgs->getOldValue('password');
  347.         $newPasswordValue $eventArgs->getNewValue('password');
  348.         if($newPasswordValue == '' || $newPasswordValue == -1){
  349.             $this->setPassword($oldPasswordValue);
  350.         }
  351.     }
  352.     /**
  353.      * @return Collection|DossierCPF[]
  354.      */
  355.     public function getDossierCPFs(): Collection
  356.     {
  357.         return $this->dossierCPFs;
  358.     }
  359.     public function addDossierCPF(DossierCPF $dossierCPF): self
  360.     {
  361.         if (!$this->dossierCPFs->contains($dossierCPF)) {
  362.             $this->dossierCPFs[] = $dossierCPF;
  363.             $dossierCPF->setUser($this);
  364.         }
  365.         return $this;
  366.     }
  367.     public function removeDossierCPF(DossierCPF $dossierCPF): self
  368.     {
  369.         if ($this->dossierCPFs->removeElement($dossierCPF)) {
  370.             // set the owning side to null (unless already changed)
  371.             if ($dossierCPF->getUser() === $this) {
  372.                 $dossierCPF->setUser(null);
  373.             }
  374.         }
  375.         return $this;
  376.     }
  377.     public function isPartner(): bool
  378.     {
  379.         return in_array('ROLE_PARTNER'$this->roles);
  380.     }
  381.     public function getData(): array
  382.     {
  383.         return $this->data json_decode($this->datatrue) : array();
  384.     }
  385.     public function setData(?string $data): self
  386.     {
  387.         $this->data $data;
  388.         return $this;
  389.     }
  390. }