src/Entity/User.php line 27

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Gedmo\Mapping\Annotation as Gedmo;
  7. use Symfony\Component\Security\Core\User\UserInterface;
  8. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  9. use Gedmo\Timestampable\Traits\TimestampableEntity;
  10. use JMS\Serializer\Annotation\Groups;
  11. use JMS\Serializer\Annotation\Type;
  12. use Doctrine\ORM\Mapping\Index;
  13. use DMS\Filter\Rules as Filter;
  14. /**
  15.  * @ORM\Entity(repositoryClass="App\Repository\UserRepository")
  16.  * @ORM\Table(name="user", 
  17.  *   uniqueConstraints={
  18.  *     @ORM\UniqueConstraint(name="email", columns={"email"})  
  19.  *   }
  20.  * )
  21.  * @UniqueEntity("email", groups={"Registration", "CustomerRegistration", "UserPartnerRegistration"}, message="user.email.unique")
  22.  * @Gedmo\SoftDeleteable(fieldName="deletedAt")
  23.  */
  24. class User implements UserInterface
  25. {
  26.     use TimestampableEntity;
  27.     /**
  28.      * @ORM\Id()
  29.      * @ORM\GeneratedValue()
  30.      * @ORM\Column(type="integer")
  31.      */
  32.     private $id;
  33.     /**
  34.      * @ORM\Column(type="json")
  35.      */
  36.     private $roles = [];
  37.     /**
  38.      *  @Filter\StripTags()
  39.      *  @Filter\Trim()
  40.      *  @Filter\StripNewlines()          
  41.      * @ORM\Column(type="string", length=100, nullable=true)
  42.      * @Groups({"user"})
  43.      */
  44.     private $firstName;
  45.     /**
  46.      *  @Filter\StripTags()
  47.      *  @Filter\Trim()
  48.      *  @Filter\StripNewlines()          
  49.      * @ORM\Column(type="string", length=100, nullable=true)
  50.      * @Groups({"user"})
  51.      */
  52.     private $lastName;
  53.     /**
  54.      *  @Filter\StripTags()
  55.      *  @Filter\Trim()
  56.      *  @Filter\StripNewlines()          
  57.      * @ORM\Column(type="string", length=100, nullable=true)
  58.      * @Groups({"user"})
  59.      */
  60.     private $email;
  61.     /**
  62.      * @var string The hashed password
  63.      * @ORM\Column(type="string", nullable=true)
  64.      */
  65.     private $password;
  66.     /**
  67.      * @var string 
  68.      * @Type("string")
  69.      */
  70.     private $plainPassword;
  71.     /**
  72.      * @var string 
  73.      * @Type("string")
  74.      */
  75.     private $plainPassword2;
  76.     /**
  77.      * @ORM\Column(type="datetime", nullable=true)
  78.      */
  79.     private $deletedAt;
  80.     /**
  81.      * @ORM\Column(type="string", length=20, nullable=true)
  82.      * @Groups({"user"})
  83.      */
  84.     private $phoneNumber;
  85.     /**
  86.      * @ORM\ManyToOne(targetEntity=Country::class)
  87.      * @Groups({"user"})
  88.      */
  89.     private $phoneNumberAreaCode;
  90.     /**
  91.      * @ORM\ManyToOne(targetEntity=Customer::class, inversedBy="users")
  92.      * @Groups({"user"})
  93.      */
  94.     private $customer;
  95.     /**
  96.      * @ORM\OneToMany(targetEntity=BalanceTransaction::class, mappedBy="user")
  97.      */
  98.     private $balanceTransactions;
  99.     /**
  100.      * @ORM\Column(type="boolean")
  101.      */
  102.     private $isAuthenticationless false;
  103.     /**
  104.      * @ORM\ManyToOne(targetEntity=Partner::class)
  105.      */
  106.     private $partner;
  107.     public function __construct()
  108.     {
  109.         $this->balanceTransactions = new ArrayCollection();
  110.     }
  111.     public function getId(): ?int
  112.     {
  113.         return $this->id;
  114.     }
  115.     public function setId(int $id): self
  116.     {
  117.         $this->id $id;
  118.         return $this;
  119.     }
  120.     /**
  121.      * @see UserInterface
  122.      */
  123.     public function eraseCredentials()
  124.     {
  125.         // If you store any temporary, sensitive data on the user, clear it here
  126.         $this->plainPassword null;
  127.         $this->plainPassword2 null;
  128.     }
  129.     /**
  130.      * @see UserInterface
  131.      */
  132.     public function getRoles(): array
  133.     {
  134.         $roles $this->roles;
  135.         // guarantee every user at least has ROLE_USER
  136.         $roles[] = 'ROLE_USER';
  137.         return array_unique($roles);
  138.     }
  139.     public function setRoles(array $roles): self
  140.     {
  141.         $this->roles $roles;
  142.         return $this;
  143.     }
  144.     /**
  145.      * @see UserInterface
  146.      */
  147.     public function getPassword(): string
  148.     {
  149.         return (string) $this->password;
  150.     }
  151.     public function setPassword(string $password): self
  152.     {
  153.         $this->password $password;
  154.         return $this;
  155.     }
  156.     /**
  157.      * @see UserInterface
  158.      */
  159.     public function getPlainPassword(): ?string
  160.     {
  161.         return (string) $this->plainPassword;
  162.     }
  163.     public function setPlainPassword(?string $plainPassword): self
  164.     {
  165.         $this->plainPassword $plainPassword;
  166.         return $this;
  167.     }
  168.     /**
  169.      * @see UserInterface
  170.      */
  171.     public function getPlainPassword2(): ?string
  172.     {
  173.         return (string) $this->plainPassword2;
  174.     }
  175.     public function setPlainPassword2(?string $plainPassword2): self
  176.     {
  177.         $this->plainPassword2 $plainPassword2;
  178.         return $this;
  179.     }
  180.     /**
  181.      * @see UserInterface
  182.      */
  183.     public function getSalt()
  184.     {
  185.         // not needed when using the "bcrypt" algorithm in security.yaml
  186.     }
  187.     public function getFirstName(): ?string
  188.     {
  189.         return $this->firstName;
  190.     }
  191.     public function setFirstName(?string $firstName): self
  192.     {
  193.         $this->firstName $firstName;
  194.         return $this;
  195.     }
  196.     public function getLastName(): ?string
  197.     {
  198.         return $this->lastName;
  199.     }
  200.     public function setLastName(?string $lastName): self
  201.     {
  202.         $this->lastName $lastName;
  203.         return $this;
  204.     }
  205.     public function getEmail(): ?string
  206.     {
  207.         return $this->email;
  208.     }
  209.     public function setEmail(?string $email): self
  210.     {
  211.         $this->email $email;
  212.         return $this;
  213.     }
  214.     public function getDeletedAt(): ?\DateTimeInterface
  215.     {
  216.         return $this->deletedAt;
  217.     }
  218.     public function setDeletedAt(?\DateTimeInterface $deletedAt): self
  219.     {
  220.         $this->deletedAt $deletedAt;
  221.         return $this;
  222.     }
  223.     /**
  224.      * A visual identifier that represents this user.
  225.      *
  226.      * @see UserInterface
  227.      */
  228.     public function getUsername(): ?string
  229.     {
  230.         return (string) $this->email;
  231.     }
  232.     public function setUsername(?string $username): self
  233.     {
  234.         $this->email $username;
  235.         return $this;
  236.     }
  237.     public function getPhoneNumber(): ?string
  238.     {
  239.         return $this->phoneNumber;
  240.     }
  241.     public function setPhoneNumber(?string $phoneNumber): self
  242.     {
  243.         $this->phoneNumber $phoneNumber;
  244.         return $this;
  245.     }
  246.     public function getPhoneNumberAreaCode(): ?Country
  247.     {
  248.         return $this->phoneNumberAreaCode;
  249.     }
  250.     public function setPhoneNumberAreaCode(?Country $phoneNumberAreaCode): self
  251.     {
  252.         $this->phoneNumberAreaCode $phoneNumberAreaCode;
  253.         return $this;
  254.     }
  255.     public function getCustomer(): ?Customer
  256.     {
  257.         return $this->customer;
  258.     }
  259.     public function setCustomer(?Customer $customer): self
  260.     {
  261.         $this->customer $customer;
  262.         return $this;
  263.     }
  264.     /**
  265.      * @return Collection<int, BalanceTransaction>
  266.      */
  267.     public function getBalanceTransactions(): Collection
  268.     {
  269.         return $this->balanceTransactions;
  270.     }
  271.     public function addBalanceTransaction(BalanceTransaction $balanceTransaction): self
  272.     {
  273.         if (!$this->balanceTransactions->contains($balanceTransaction)) {
  274.             $this->balanceTransactions[] = $balanceTransaction;
  275.             $balanceTransaction->setUser($this);
  276.         }
  277.         return $this;
  278.     }
  279.     public function removeBalanceTransaction(BalanceTransaction $balanceTransaction): self
  280.     {
  281.         if ($this->balanceTransactions->removeElement($balanceTransaction)) {
  282.             // set the owning side to null (unless already changed)
  283.             if ($balanceTransaction->getUser() === $this) {
  284.                 $balanceTransaction->setUser(null);
  285.             }
  286.         }
  287.         return $this;
  288.     }
  289.     // custom methods
  290.     public function getFullName() {
  291.         return $this->firstName ' ' $this->lastName;
  292.     }
  293.     public function getIsAuthenticationless(): ?bool
  294.     {
  295.         return $this->isAuthenticationless;
  296.     }
  297.     public function setIsAuthenticationless(bool $isAuthenticationless): self
  298.     {
  299.         $this->isAuthenticationless $isAuthenticationless;
  300.         return $this;
  301.     }
  302.     public function getPartner(): ?Partner
  303.     {
  304.         return $this->partner;
  305.     }
  306.     public function setPartner(?Partner $partner): self
  307.     {
  308.         $this->partner $partner;
  309.         return $this;
  310.     }
  311. }