src/Entity/User.php line 24

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 Serializable;
  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.  * @ORM\Table(name="`user`")
  14.  */
  15. /**
  16.  * @ORM\Entity(repositoryClass=UserRepository::class)
  17.  * @ORM\Table(name="`user`")
  18.  * @UniqueEntity(fields={"email"}, message="There is already an account with this email")
  19.  */
  20. #[UniqueEntity(fields: ['email'], message'message="Ce compte existe déjà')]
  21. class User implements UserInterfacePasswordAuthenticatedUserInterfaceSerializable
  22. {
  23.     /**
  24.      * @ORM\Id
  25.      * @ORM\GeneratedValue
  26.      * @ORM\Column(type="integer")
  27.      */
  28.     private $id;
  29.     /**
  30.      * @ORM\Column(type="string", length=180, unique=true)
  31.      */
  32.     private $email;
  33.     /**
  34.      * @ORM\Column(type="json")
  35.      */
  36.     private $roles = [];
  37.     /**
  38.      * @var string The hashed password
  39.      * @ORM\Column(type="string")
  40.      */
  41.     private $password;
  42.     /**
  43.      * @ORM\Column(type="string", length=255)
  44.      */
  45.     private $firstName;
  46.     /**
  47.      * @ORM\Column(type="string", length=255)
  48.      */
  49.     private $lastName;
  50.     /**
  51.      * @ORM\Column(type="string", length=255, nullable=true)
  52.      */
  53.     private $phoneNumber;
  54.     /**
  55.      * @ORM\ManyToMany(targetEntity=Role::class, inversedBy="users")
  56.      */
  57.     private $userRoles;
  58.     /**
  59.      * @ORM\ManyToOne(targetEntity=Company::class, inversedBy="employees", cascade={"persist"})
  60.      */
  61.     private $company;
  62.     /**
  63.      * @ORM\Column(type="boolean", nullable=true)
  64.      */
  65.     private $isManager;
  66.     /**
  67.      * @ORM\Column(type="boolean")
  68.      */
  69.     private $isVerified false;
  70.     /**
  71.      * @ORM\OneToOne(targetEntity=ImageManager::class, cascade={"persist", "remove"})
  72.      */
  73.     private $avatar;
  74.     /**
  75.      * @ORM\Column(type="string", length=255, nullable=true)
  76.      */
  77.     private $googleId;
  78.     /**
  79.      * @ORM\Column(type="string", length=255, nullable=true)
  80.      */
  81.     private $hostedDomain;
  82.     /**
  83.      * @ORM\Column(type="string", length=255, nullable=true)
  84.      */
  85.     private $avatarFromRemote;
  86.     /**
  87.      * @ORM\Column(type="string", length=255, nullable=true)
  88.      */
  89.     private $linkedinId;
  90.     /**
  91.      * @ORM\Column(type="string", length=255, nullable=true)
  92.      */
  93.     private $facebookId;
  94.     /**
  95.      * @ORM\Column(type="array", nullable=true)
  96.      */
  97.     private $deviceTokens = [];
  98.     /**
  99.      * @ORM\OneToMany(targetEntity=Payment::class, mappedBy="customer")
  100.      */
  101.     private $payments;
  102.     /**
  103.      * @ORM\OneToMany(targetEntity=CustomerBpModelAffected::class, mappedBy="customer")
  104.      */
  105.     private $customerBpModelAffecteds;
  106.     /**
  107.      * @ORM\ManyToMany(targetEntity=BPModel::class, mappedBy="customers")
  108.      */
  109.     private $bpModels;
  110.     /**
  111.      * @ORM\OneToOne(targetEntity=CustomerBilling::class, inversedBy="user", cascade={"persist", "remove"})
  112.      */
  113.     private $customerBilling;
  114.     public function __construct()
  115.     {
  116.         $this->userRoles = new ArrayCollection();
  117.         $this->payments = new ArrayCollection();
  118.         $this->customerBpModelAffecteds = new ArrayCollection();
  119.         $this->bpModels = new ArrayCollection();
  120.     }
  121.     public function getId(): ?int
  122.     {
  123.         return $this->id;
  124.     }
  125.     public function getEmail(): ?string
  126.     {
  127.         return $this->email;
  128.     }
  129.     public function setEmail(string $email): self
  130.     {
  131.         $this->email $email;
  132.         return $this;
  133.     }
  134.     /**
  135.      * A visual identifier that represents this user.
  136.      *
  137.      * @see UserInterface
  138.      */
  139.     public function getUserIdentifier(): string
  140.     {
  141.         return (string) $this->email;
  142.     }
  143.     /**
  144.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  145.      */
  146.     public function getUsername(): string
  147.     {
  148.         return (string) $this->email;
  149.     }
  150.     /**
  151.      * @see UserInterface
  152.      */
  153.     public function getRoles(): array
  154.     {
  155.         $roles $this->roles;
  156.         //$roles = [];
  157.         foreach ($this->getUserRoles() as $role) {
  158.             $roles [] = $role->getCode();
  159.         }
  160.         // guarantee every user at least has ROLE_USER
  161.         $roles[] = 'ROLE_USER';
  162.         return array_unique($roles);
  163.     }
  164.     public function setRoles(array $roles): self
  165.     {
  166.         $this->roles $roles;
  167.         return $this;
  168.     }
  169.     /**
  170.      * @see PasswordAuthenticatedUserInterface
  171.      */
  172.     public function getPassword(): string
  173.     {
  174.         return $this->password;
  175.     }
  176.     public function setPassword(string $password): self
  177.     {
  178.         $this->password $password;
  179.         return $this;
  180.     }
  181.     /**
  182.      * Returning a salt is only needed, if you are not using a modern
  183.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  184.      *
  185.      * @see UserInterface
  186.      */
  187.     public function getSalt(): ?string
  188.     {
  189.         return null;
  190.     }
  191.     /**
  192.      * @see UserInterface
  193.      */
  194.     public function eraseCredentials()
  195.     {
  196.         // If you store any temporary, sensitive data on the user, clear it here
  197.         // $this->plainPassword = null;
  198.     }
  199.     public function getFirstName(): ?string
  200.     {
  201.         return $this->firstName;
  202.     }
  203.     public function setFirstName(string $firstName): self
  204.     {
  205.         $this->firstName $firstName;
  206.         return $this;
  207.     }
  208.     public function getLastName(): ?string
  209.     {
  210.         return $this->lastName;
  211.     }
  212.     public function setLastName(string $lastName): self
  213.     {
  214.         $this->lastName $lastName;
  215.         return $this;
  216.     }
  217.     public function getPhoneNumber(): ?string
  218.     {
  219.         return $this->phoneNumber;
  220.     }
  221.     public function setPhoneNumber(?string $phoneNumber): self
  222.     {
  223.         $this->phoneNumber $phoneNumber;
  224.         return $this;
  225.     }
  226.     /**
  227.      * @return Collection<int, Role>
  228.      */
  229.     public function getUserRoles(): Collection
  230.     {
  231.         return $this->userRoles;
  232.     }
  233.     public function addUserRole(Role $userRole): self
  234.     {
  235.         if (!$this->userRoles->contains($userRole)) {
  236.             $this->userRoles[] = $userRole;
  237.         }
  238.         return $this;
  239.     }
  240.     public function removeUserRole(Role $userRole): self
  241.     {
  242.         $this->userRoles->removeElement($userRole);
  243.         return $this;
  244.     }
  245.     public function getFullName(): ?string
  246.     {
  247.         return $this->getLastName().' '.$this->getFirstName();
  248.     }
  249.     public function getCompany(): ?Company
  250.     {
  251.         return $this->company;
  252.     }
  253.     public function setCompany(?Company $company): self
  254.     {
  255.         $this->company $company;
  256.         return $this;
  257.     }
  258.     public function getIsManager(): ?bool
  259.     {
  260.         return $this->isManager;
  261.     }
  262.     public function setIsManager(?bool $isManager): self
  263.     {
  264.         $this->isManager $isManager;
  265.         return $this;
  266.     }
  267.     public function serialize()
  268.     {
  269.         return serialize(array(
  270.             $this->id,
  271.             $this->email,
  272.             $this->password,
  273.         ));
  274.     }
  275.     public function unserialize($serialized)
  276.     {
  277.         list(
  278.             $this->id,
  279.             $this->email,
  280.             $this->password,
  281.         ) = unserialize($serialized);
  282.     }
  283.     public function isVerified(): bool
  284.     {
  285.         return $this->isVerified;
  286.     }
  287.     public function setIsVerified(bool $isVerified): self
  288.     {
  289.         $this->isVerified $isVerified;
  290.         return $this;
  291.     }
  292.     public function getAvatar(): ?ImageManager
  293.     {
  294.         return $this->avatar;
  295.     }
  296.     public function setAvatar(?ImageManager $avatar): self
  297.     {
  298.         $this->avatar $avatar;
  299.         return $this;
  300.     }
  301.     public function getGoogleId(): ?string
  302.     {
  303.         return $this->googleId;
  304.     }
  305.     public function setGoogleId(?string $googleId): self
  306.     {
  307.         $this->googleId $googleId;
  308.         return $this;
  309.     }
  310.     public function getHostedDomain(): ?string
  311.     {
  312.         return $this->hostedDomain;
  313.     }
  314.     public function setHostedDomain(?string $hostedDomain): self
  315.     {
  316.         $this->hostedDomain $hostedDomain;
  317.         return $this;
  318.     }
  319.     public function getAvatarFromRemote(): ?string
  320.     {
  321.         return $this->avatarFromRemote;
  322.     }
  323.     public function setAvatarFromRemote(?string $avatarFromRemote): self
  324.     {
  325.         $this->avatarFromRemote $avatarFromRemote;
  326.         return $this;
  327.     }
  328.     public function getLinkedinId(): ?string
  329.     {
  330.         return $this->linkedinId;
  331.     }
  332.     public function setLinkedinId(?string $linkedinId): self
  333.     {
  334.         $this->linkedinId $linkedinId;
  335.         return $this;
  336.     }
  337.     public function getFacebookId(): ?string
  338.     {
  339.         return $this->facebookId;
  340.     }
  341.     public function setFacebookId(?string $facebookId): self
  342.     {
  343.         $this->facebookId $facebookId;
  344.         return $this;
  345.     }
  346.     public function isIsManager(): ?bool
  347.     {
  348.         return $this->isManager;
  349.     }
  350.     public function isIsVerified(): ?bool
  351.     {
  352.         return $this->isVerified;
  353.     }
  354.     /**
  355.      * @return array
  356.      */
  357.     public function getDeviceTokens(): ?array
  358.     {
  359.         return $this->deviceTokens;
  360.     }
  361.     /**
  362.      * @param array $deviceTokens
  363.      */
  364.     public function setDeviceTokens(array $deviceTokens): void
  365.     {
  366.         $this->deviceTokens $deviceTokens;
  367.     }
  368.     /**
  369.      * @return Collection<int, Payment>
  370.      */
  371.     public function getPayments(): Collection
  372.     {
  373.         return $this->payments;
  374.     }
  375.     public function addPayment(Payment $payment): self
  376.     {
  377.         if (!$this->payments->contains($payment)) {
  378.             $this->payments[] = $payment;
  379.             $payment->setCustomer($this);
  380.         }
  381.         return $this;
  382.     }
  383.     public function removePayment(Payment $payment): self
  384.     {
  385.         if ($this->payments->removeElement($payment)) {
  386.             // set the owning side to null (unless already changed)
  387.             if ($payment->getCustomer() === $this) {
  388.                 $payment->setCustomer(null);
  389.             }
  390.         }
  391.         return $this;
  392.     }
  393.     /**
  394.      * @return Collection<int, CustomerBpModelAffected>
  395.      */
  396.     public function getCustomerBpModelAffecteds(): Collection
  397.     {
  398.         return $this->customerBpModelAffecteds;
  399.     }
  400.     public function addCustomerBpModelAffected(CustomerBpModelAffected $customerBpModelAffected): self
  401.     {
  402.         if (!$this->customerBpModelAffecteds->contains($customerBpModelAffected)) {
  403.             $this->customerBpModelAffecteds[] = $customerBpModelAffected;
  404.             $customerBpModelAffected->setCustomer($this);
  405.         }
  406.         return $this;
  407.     }
  408.     public function removeCustomerBpModelAffected(CustomerBpModelAffected $customerBpModelAffected): self
  409.     {
  410.         if ($this->customerBpModelAffecteds->removeElement($customerBpModelAffected)) {
  411.             // set the owning side to null (unless already changed)
  412.             if ($customerBpModelAffected->getCustomer() === $this) {
  413.                 $customerBpModelAffected->setCustomer(null);
  414.             }
  415.         }
  416.         return $this;
  417.     }
  418.     /**
  419.      * @return Collection<int, BPModel>
  420.      */
  421.     public function getBpModels(): Collection
  422.     {
  423.         return $this->bpModels;
  424.     }
  425.     public function addBpModel(BPModel $bpModel): self
  426.     {
  427.         if (!$this->bpModels->contains($bpModel)) {
  428.             $this->bpModels[] = $bpModel;
  429.             $bpModel->addCustomer($this);
  430.         }
  431.         return $this;
  432.     }
  433.     public function removeBpModel(BPModel $bpModel): self
  434.     {
  435.         if ($this->bpModels->removeElement($bpModel)) {
  436.             $bpModel->removeCustomer($this);
  437.         }
  438.         return $this;
  439.     }
  440.     public function getCustomerBilling(): ?CustomerBilling
  441.     {
  442.         return $this->customerBilling;
  443.     }
  444.     public function setCustomerBilling(?CustomerBilling $customerBilling): self
  445.     {
  446.         $this->customerBilling $customerBilling;
  447.         return $this;
  448.     }
  449. }