src/Entity/Generic/User.php line 30

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Generic;
  3. use App\Entity\BaseEntity;
  4. use App\Entity\BaseSite\Messages\WebBuilder;
  5. use App\Entity\BaseSite\Ticket\Ticket;
  6. use App\Entity\BaseSite\Ticket\TicketMessage;
  7. use App\Entity\BaseSite\Transaction;
  8. use App\Entity\Website\Website\Website;
  9. use App\Repository\Generic\UserRepository;
  10. use DateTimeInterface;
  11. use Doctrine\Common\Collections\ArrayCollection;
  12. use Doctrine\Common\Collections\Collection;
  13. use Doctrine\DBAL\Types\Types;
  14. use Doctrine\ORM\Mapping as ORM;
  15. use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
  16. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  17. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  18. use Symfony\Component\Security\Core\User\UserInterface;
  19. #[ORM\Entity(repositoryClassUserRepository::class)]
  20. #[ORM\Table(name'`user`' ,    uniqueConstraints: [
  21.     new ORM\UniqueConstraint(name'shop_identifier_unique'columns: [ 'identifier' 'phone' 'email'])
  22. ])]
  23. #[UniqueEntity(fields: ['email'], message'این پست الکترونیک از قبل موجود می باشد')]
  24. #[UniqueEntity(fields: ['mobile'], message'این شماره موبایل از قبل موجود می باشد')]
  25. #[UniqueEntity(fields: ['identifier'], message'این پست الکترونیک یا شماره موبایل از قبل موجود می باشد')]
  26. class User extends BaseEntity implements UserInterfacePasswordAuthenticatedUserInterface
  27. {
  28.     #[ORM\Id]
  29.     #[ORM\Column(type'guid'uniquetrue)]
  30.     #[ORM\GeneratedValue(strategy'CUSTOM')]
  31.     #[ORM\CustomIdGenerator(class: UuidGenerator::class)]
  32.     private ?string $id;
  33.     #[ORM\Column(length180uniquetrue)]
  34.     private string $identifier;
  35.     #[ORM\Column(length180uniquetruenullabletrue)]
  36.     private ?string $email null;
  37.     #[ORM\Column(length20uniquetruenullabletrue)]
  38.     private ?string $mobile null;
  39.     #[ORM\Column(type'json')]
  40.     private array $roles = [];
  41.     #[ORM\Column(type'string')]
  42.     private string $password;
  43.     #[ORM\Column(type'boolean')]
  44.     private bool $isVerified false;
  45.     #[ORM\Column(type'string'length255nullabletrue)]
  46.     private  $firstName;
  47.     #[ORM\Column(type'string'length255nullabletrue)]
  48.     private  $lastName;
  49.     #[ORM\Column(type'bigint')]
  50.     private string $wallet "0";
  51.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  52.     private ?DateTimeInterface $lastLogin null;
  53.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  54.     private ?DateTimeInterface $lastBuy null;
  55.     #[ORM\Column(nullabletrue)]
  56.     private ?int $verifyCode null;
  57.     #[ORM\OneToMany(mappedBy'owner'targetEntityTransaction::class)]
  58.     private Collection $transactions;
  59.     #[ORM\OneToMany(mappedBy'owner'targetEntityWebsite::class)]
  60.     private Collection $shops;
  61.     #[ORM\OneToMany(mappedBy'creator'targetEntityTicket::class)]
  62.     private Collection $tickets;
  63.     #[ORM\OneToMany(mappedBy'author'targetEntityTicketMessage::class)]
  64.     private Collection $ticketMessages;
  65.     #[ORM\OneToMany(mappedBy'user'targetEntityWebBuilder::class)]
  66.     private Collection $webBuilders;
  67.     public function __construct()
  68.     {
  69.         parent::__construct();
  70.         $this->transactions = new ArrayCollection();
  71.         $this->shops = new ArrayCollection();
  72.         $this->setVerifyCode(random_int(00000 99999));
  73.         $this->tickets = new ArrayCollection();
  74.         $this->ticketMessages = new ArrayCollection();
  75.         $this->webBuilders = new ArrayCollection();
  76.     }
  77.     public function getId(): ?string
  78.     {
  79.         return $this->id;
  80.     }
  81.     public function getEmail(): ?string
  82.     {
  83.         return $this->email;
  84.     }
  85.     public function __toString(): string
  86.     {
  87.         return $this->getIdentifier();
  88.     }
  89.     public function setEmail(string $email): self
  90.     {
  91.         $this->email $email;
  92.         return $this;
  93.     }
  94.     /**
  95.      * @see UserInterface
  96.      */
  97.     public function getRoles(): array
  98.     {
  99.         $roles $this->roles;
  100.         // guarantee every user at least has ROLE_USER
  101.         $roles[] = 'ROLE_USER';
  102.         return array_unique($roles);
  103.     }
  104.     public function setRoles(array $roles): self
  105.     {
  106.         $this->roles $roles;
  107.         return $this;
  108.     }
  109.     /**
  110.      * A visual identifier that represents this user.
  111.      *
  112.      * @see UserInterface
  113.      */
  114.     public function getUserIdentifier(): string
  115.     {
  116.         return (string)$this->email;
  117.     }
  118.     /**
  119.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  120.      */
  121.     public function getUsername(): string
  122.     {
  123.         return (string)$this->email;
  124.     }
  125.     /**
  126.      * @see PasswordAuthenticatedUserInterface
  127.      */
  128.     public function getPassword(): string
  129.     {
  130.         return $this->password;
  131.     }
  132.     public function setPassword(string $password): self
  133.     {
  134.         $this->password $password;
  135.         return $this;
  136.     }
  137.     /**
  138.      * Returning a salt is only needed, if you are not using a modern
  139.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  140.      *
  141.      * @see UserInterface
  142.      */
  143.     public function getSalt(): ?string
  144.     {
  145.         return null;
  146.     }
  147.     /**
  148.      * @see UserInterface
  149.      */
  150.     public function eraseCredentials()
  151.     {
  152.         // If you store any temporary, sensitive data on the user, clear it here
  153.         // $this->plainPassword = null;
  154.     }
  155.     public function isVerified(): bool
  156.     {
  157.         return $this->isVerified;
  158.     }
  159.     public function setIsVerified(bool $isVerified): void
  160.     {
  161.         $this->isVerified $isVerified;
  162.     }
  163.     /**
  164.      * @return mixed
  165.      */
  166.     public function getFirstName()
  167.     {
  168.         return $this->firstName;
  169.     }
  170.     /**
  171.      * @param mixed $firstName
  172.      */
  173.     public function setFirstName(mixed $firstName): void
  174.     {
  175.         $this->firstName $firstName;
  176.     }
  177.     /**
  178.      * @return mixed
  179.      */
  180.     public function getLastName(): mixed
  181.     {
  182.         return $this->lastName;
  183.     }
  184.     /**
  185.      * @param mixed $lastName
  186.      */
  187.     public function setLastName(mixed $lastName): void
  188.     {
  189.         $this->lastName $lastName;
  190.     }
  191.     public function getWallet(): int
  192.     {
  193.         return $this->wallet;
  194.     }
  195.     public function setWallet(int $wallet): void
  196.     {
  197.         $this->wallet $wallet;
  198.     }
  199.     public function getMobile(): ?string
  200.     {
  201.         return $this->mobile;
  202.     }
  203.     public function setMobile(?string $mobile): void
  204.     {
  205.         $this->mobile $mobile;
  206.     }
  207.     public function getLastLogin(): ?DateTimeInterface
  208.     {
  209.         return $this->lastLogin;
  210.     }
  211.     public function setLastLogin(?DateTimeInterface $lastLogin): void
  212.     {
  213.         $this->lastLogin $lastLogin;
  214.     }
  215.     public function getLastBuy(): ?DateTimeInterface
  216.     {
  217.         return $this->lastBuy;
  218.     }
  219.     public function setLastBuy(?DateTimeInterface $lastBuy): void
  220.     {
  221.         $this->lastBuy $lastBuy;
  222.     }
  223.     public function getVerifyCode(): ?int
  224.     {
  225.         return $this->verifyCode;
  226.     }
  227.     public function setVerifyCode(?int $verifyCode): void
  228.     {
  229.         $this->verifyCode $verifyCode;
  230.     }
  231.     public function hasRole($role): bool
  232.     {
  233.         return in_array($role$this->getRoles(), true);
  234.     }
  235.     /**
  236.      * @return Collection<int, Transaction>
  237.      */
  238.     public function getTransactions(): Collection
  239.     {
  240.         return $this->transactions;
  241.     }
  242.     public function addTransaction(Transaction $transaction): static
  243.     {
  244.         if (!$this->transactions->contains($transaction)) {
  245.             $this->transactions->add($transaction);
  246.             $transaction->setOwner($this);
  247.         }
  248.         return $this;
  249.     }
  250.     public function removeTransaction(Transaction $transaction): static
  251.     {
  252.         if ($this->transactions->removeElement($transaction)) {
  253.             // set the owning side to null (unless already changed)
  254.             if ($transaction->getOwner() === $this) {
  255.                 $transaction->setOwner(null);
  256.             }
  257.         }
  258.         return $this;
  259.     }
  260.     /**
  261.      * @return Collection<int, Website>
  262.      */
  263.     public function getShops(): Collection
  264.     {
  265.         return $this->shops;
  266.     }
  267.     public function addShop(Website $shop): static
  268.     {
  269.         if (!$this->shops->contains($shop)) {
  270.             $this->shops->add($shop);
  271.             $shop->setOwner($this);
  272.         }
  273.         return $this;
  274.     }
  275.     public function removeShop(Website $shop): static
  276.     {
  277.         if ($this->shops->removeElement($shop)) {
  278.             // set the owning side to null (unless already changed)
  279.             if ($shop->getOwner() === $this) {
  280.                 $shop->setOwner(null);
  281.             }
  282.         }
  283.         return $this;
  284.     }
  285.     public function getIdentifier(): string
  286.     {
  287.         return $this->identifier;
  288.     }
  289.     public function setIdentifier(string $identifier): void
  290.     {
  291.         $this->identifier $identifier;
  292.     }
  293.     /**
  294.      * @return Collection<int, Ticket>
  295.      */
  296.     public function getTickets(): Collection
  297.     {
  298.         return $this->tickets;
  299.     }
  300.     public function addTicket(Ticket $ticket): static
  301.     {
  302.         if (!$this->tickets->contains($ticket)) {
  303.             $this->tickets->add($ticket);
  304.             $ticket->setCreator($this);
  305.         }
  306.         return $this;
  307.     }
  308.     public function removeTicket(Ticket $ticket): static
  309.     {
  310.         if ($this->tickets->removeElement($ticket)) {
  311.             // set the owning side to null (unless already changed)
  312.             if ($ticket->getCreator() === $this) {
  313.                 $ticket->setCreator(null);
  314.             }
  315.         }
  316.         return $this;
  317.     }
  318.     /**
  319.      * @return Collection<int, TicketMessage>
  320.      */
  321.     public function getTicketMessages(): Collection
  322.     {
  323.         return $this->ticketMessages;
  324.     }
  325.     public function addTicketMessage(TicketMessage $ticketMessage): static
  326.     {
  327.         if (!$this->ticketMessages->contains($ticketMessage)) {
  328.             $this->ticketMessages->add($ticketMessage);
  329.             $ticketMessage->setAuthor($this);
  330.         }
  331.         return $this;
  332.     }
  333.     public function removeTicketMessage(TicketMessage $ticketMessage): static
  334.     {
  335.         if ($this->ticketMessages->removeElement($ticketMessage)) {
  336.             // set the owning side to null (unless already changed)
  337.             if ($ticketMessage->getAuthor() === $this) {
  338.                 $ticketMessage->setAuthor(null);
  339.             }
  340.         }
  341.         return $this;
  342.     }
  343.     /**
  344.      * @return Collection<int, WebBuilder>
  345.      */
  346.     public function getWebBuilders(): Collection
  347.     {
  348.         return $this->webBuilders;
  349.     }
  350.     public function addWebBuilder(WebBuilder $webBuilder): static
  351.     {
  352.         if (!$this->webBuilders->contains($webBuilder)) {
  353.             $this->webBuilders->add($webBuilder);
  354.             $webBuilder->setUser($this);
  355.         }
  356.         return $this;
  357.     }
  358.     public function removeWebBuilder(WebBuilder $webBuilder): static
  359.     {
  360.         if ($this->webBuilders->removeElement($webBuilder)) {
  361.             // set the owning side to null (unless already changed)
  362.             if ($webBuilder->getUser() === $this) {
  363.                 $webBuilder->setUser(null);
  364.             }
  365.         }
  366.         return $this;
  367.     }
  368. }