src/Entity/Generic/User.php line 29

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