src/Entity/Generic/Customer/Customer.php line 34

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Generic\Customer;
  3. use App\Entity\BaseEntity;
  4. use App\Entity\Website\Accounting\Transaction;
  5. use App\Entity\Website\Blog\Article;
  6. use App\Entity\Website\Blog\Comment;
  7. use App\Entity\Website\Cart\Cart;
  8. use App\Entity\Website\Order\Order;
  9. use App\Entity\Website\Product\ProductReview;
  10. use App\Entity\Website\Product\ProductReviewReply;
  11. use App\Entity\Website\Product\ProductReviewVote;
  12. use App\Entity\Website\Website\Review;
  13. use App\Entity\Website\Website\Website;
  14. use App\Entity\Website\Ticket\Ticket;
  15. use App\Entity\Website\Ticket\TicketMessage;
  16. use App\Repository\Generic\CustomerRepository;
  17. use Doctrine\Common\Collections\ArrayCollection;
  18. use Doctrine\Common\Collections\Collection;
  19. use Doctrine\DBAL\Types\Types;
  20. use Doctrine\ORM\Mapping as ORM;
  21. use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
  22. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  23. use Symfony\Component\Security\Core\User\UserInterface;
  24. #[ORM\Table(
  25.     name'customer',
  26.     uniqueConstraints: [
  27.         new ORM\UniqueConstraint(name'shop_identifier_unique'columns: ['shop_id''identifier' 'mobile'])
  28.     ]
  29. )]
  30. #[ORM\Entity(repositoryClassCustomerRepository::class)]
  31. class Customer extends BaseEntity implements UserInterfacePasswordAuthenticatedUserInterface
  32. {
  33.     #[ORM\Id]
  34.     #[ORM\Column(type'guid'uniquetrue)]
  35.     #[ORM\GeneratedValue(strategy'CUSTOM')]
  36.     #[ORM\CustomIdGenerator(class: UuidGenerator::class)]
  37.     private ?string $id;
  38.     #[ORM\Column(type'string'length255nullabletrue)]
  39.     private mixed $firstName;
  40.     #[ORM\Column(length180 nullabletrue)]
  41.     private ?string $email null;
  42.     #[ORM\Column]
  43.     private array $roles = [];
  44.     #[ORM\Column(length20nullabletrue)]
  45.     private ?string $mobile null;
  46.     #[ORM\Column(length180)]
  47.     private string $identifier// ایمیل یا شماره موبایل (برای ورود)
  48.     /**
  49.      * @var string The hashed password
  50.      */
  51.     #[ORM\Column]
  52.     private ?string $password null;
  53.     #[ORM\Column(type'boolean')]
  54.     private bool $isVerified false;
  55.     #[ORM\Column(typeTypes::BIGINT)]
  56.     private ?string $wallet null;
  57.     #[ORM\ManyToOne(inversedBy'customers')]
  58.     #[ORM\JoinColumn(nullablefalse)]
  59.     private ?Website $website null;
  60.     public function getUserIdentifier(): string
  61.     {
  62.         return $this->identifier;
  63.     }
  64.     public function __toString()
  65.     {
  66.         return $this->getIdentifier();
  67.     }
  68.     #[ORM\OneToMany(mappedBy'customer'targetEntityOrder::class)]
  69.     private Collection $orders;
  70.     #[ORM\OneToMany(mappedBy'customer'targetEntityCart::class)]
  71.     private Collection $carts;
  72.     #[ORM\OneToMany(mappedBy'customer'targetEntityReview::class)]
  73.     private Collection $reviews;
  74.     #[ORM\OneToMany(mappedBy'customer'targetEntityAddress::class)]
  75.     private Collection $addresses;
  76.     #[ORM\OneToMany(mappedBy'author'targetEntityProductReview::class)]
  77.     private Collection $productReviews;
  78.     #[ORM\OneToMany(mappedBy'user'targetEntityProductReviewVote::class)]
  79.     private Collection $productReviewVotes;
  80.     #[ORM\OneToMany(mappedBy'author'targetEntityProductReviewReply::class)]
  81.     private Collection $productReviewReplies;
  82.     #[ORM\OneToMany(mappedBy'author'targetEntityArticle::class)]
  83.     private Collection $articles;
  84.     #[ORM\OneToMany(mappedBy'author'targetEntityComment::class)]
  85.     private Collection $comments;
  86.     #[ORM\OneToMany(mappedBy'creator'targetEntityTicket::class)]
  87.     private Collection $tickets;
  88.     #[ORM\OneToMany(mappedBy'author'targetEntityTicketMessage::class)]
  89.     private Collection $ticketMessages;
  90.     #[ORM\Column(nullabletrue)]
  91.     private ?int $verifyCode null;
  92.     #[ORM\Column(length255nullabletrue)]
  93.     private ?string $lastName null;
  94.     #[ORM\OneToMany(mappedBy'owner'targetEntityTransaction::class)]
  95.     private Collection $transactions;
  96.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  97.     private ?\DateTimeInterface $passwordResetAt null;
  98.     public function __construct()
  99.     {
  100.         parent::__construct();
  101.         $this->wallet 0;
  102.         $this->orders = new ArrayCollection();
  103.         $this->carts = new ArrayCollection();
  104.         $this->reviews = new ArrayCollection();
  105.         $this->addresses = new ArrayCollection();
  106.         $this->productReviews = new ArrayCollection();
  107.         $this->productReviewVotes = new ArrayCollection();
  108.         $this->productReviewReplies = new ArrayCollection();
  109.         $this->articles = new ArrayCollection();
  110.         $this->comments = new ArrayCollection();
  111.         $this->tickets = new ArrayCollection();
  112.         $this->ticketMessages = new ArrayCollection();
  113.         $this->setVerifyCode(random_int(00000 99999));
  114.         $this->transactions = new ArrayCollection();
  115.     }
  116.     public function hasRole($role)
  117.     {
  118.         return in_array($role$this->roles);
  119.     }
  120.     public function getId(): ?string
  121.     {
  122.         return $this->id;
  123.     }
  124.     public function getEmail(): ?string
  125.     {
  126.         return $this->email;
  127.     }
  128.     public function setEmail(string $email): static
  129.     {
  130.         $this->email $email;
  131.         return $this;
  132.     }
  133.     /**
  134.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  135.      */
  136.     public function getUsername(): string
  137.     {
  138.         return (string) $this->email;
  139.     }
  140.     /**
  141.      * @see UserInterface
  142.      */
  143.     public function getRoles(): array
  144.     {
  145.         $roles $this->roles;
  146.         // guarantee every user at least has ROLE_USER
  147.         $roles[] = 'ROLE_USER';
  148.         return array_unique($roles);
  149.     }
  150.     public function setRoles(array $roles): static
  151.     {
  152.         $this->roles $roles;
  153.         return $this;
  154.     }
  155.     /**
  156.      * @see PasswordAuthenticatedUserInterface
  157.      */
  158.     public function getPassword(): string
  159.     {
  160.         return $this->password;
  161.     }
  162.     public function setPassword(string $password): static
  163.     {
  164.         $this->password $password;
  165.         return $this;
  166.     }
  167.     /**
  168.      * Returning a salt is only needed, if you are not using a modern
  169.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  170.      *
  171.      * @see UserInterface
  172.      */
  173.     public function getSalt(): ?string
  174.     {
  175.         return null;
  176.     }
  177.     /**
  178.      * @see UserInterface
  179.      */
  180.     public function eraseCredentials(): void
  181.     {
  182.         // If you store any temporary, sensitive data on the user, clear it here
  183.         // $this->plainPassword = null;
  184.     }
  185.     public function getWallet(): ?string
  186.     {
  187.         return $this->wallet;
  188.     }
  189.     public function setWallet(string $wallet): static
  190.     {
  191.         $this->wallet $wallet;
  192.         return $this;
  193.     }
  194.     public function getWebsite(): ?Website
  195.     {
  196.         return $this->website;
  197.     }
  198.     public function setWebsite(?Website $shop): static
  199.     {
  200.         $this->website $shop;
  201.         return $this;
  202.     }
  203.     /**
  204.      * @return Collection<int, Order>
  205.      */
  206.     public function getOrders(): Collection
  207.     {
  208.         return $this->orders;
  209.     }
  210.     public function addOrder(Order $order): static
  211.     {
  212.         if (!$this->orders->contains($order)) {
  213.             $this->orders->add($order);
  214.             $order->setCustomer($this);
  215.         }
  216.         return $this;
  217.     }
  218.     public function removeOrder(Order $order): static
  219.     {
  220.         if ($this->orders->removeElement($order)) {
  221.             // set the owning side to null (unless already changed)
  222.             if ($order->getCustomer() === $this) {
  223.                 $order->setCustomer(null);
  224.             }
  225.         }
  226.         return $this;
  227.     }
  228.     /**
  229.      * @return Collection<int, Cart>
  230.      */
  231.     public function getCarts(): Collection
  232.     {
  233.         return $this->carts;
  234.     }
  235.     public function addCart(Cart $cart): static
  236.     {
  237.         if (!$this->carts->contains($cart)) {
  238.             $this->carts->add($cart);
  239.             $cart->setCustomer($this);
  240.         }
  241.         return $this;
  242.     }
  243.     public function removeCart(Cart $cart): static
  244.     {
  245.         if ($this->carts->removeElement($cart)) {
  246.             // set the owning side to null (unless already changed)
  247.             if ($cart->getCustomer() === $this) {
  248.                 $cart->setCustomer(null);
  249.             }
  250.         }
  251.         return $this;
  252.     }
  253.     /**
  254.      * @return Collection<int, Review>
  255.      */
  256.     public function getReviews(): Collection
  257.     {
  258.         return $this->reviews;
  259.     }
  260.     public function addReview(Review $review): static
  261.     {
  262.         if (!$this->reviews->contains($review)) {
  263.             $this->reviews->add($review);
  264.             $review->setCustomer($this);
  265.         }
  266.         return $this;
  267.     }
  268.     public function removeReview(Review $review): static
  269.     {
  270.         if ($this->reviews->removeElement($review)) {
  271.             // set the owning side to null (unless already changed)
  272.             if ($review->getCustomer() === $this) {
  273.                 $review->setCustomer(null);
  274.             }
  275.         }
  276.         return $this;
  277.     }
  278.     /**
  279.      * @return Collection<int, Address>
  280.      */
  281.     public function getAddresses(): Collection
  282.     {
  283.         return $this->addresses;
  284.     }
  285.     public function addAddress(Address $address): static
  286.     {
  287.         if (!$this->addresses->contains($address)) {
  288.             $this->addresses->add($address);
  289.             $address->setCustomer($this);
  290.         }
  291.         return $this;
  292.     }
  293.     public function removeAddress(Address $address): static
  294.     {
  295.         if ($this->addresses->removeElement($address)) {
  296.             // set the owning side to null (unless already changed)
  297.             if ($address->getCustomer() === $this) {
  298.                 $address->setCustomer(null);
  299.             }
  300.         }
  301.         return $this;
  302.     }
  303.     /**
  304.      * @return Collection<int, ProductReview>
  305.      */
  306.     public function getProductReviews(): Collection
  307.     {
  308.         return $this->productReviews;
  309.     }
  310.     public function addProductReview(ProductReview $productReview): static
  311.     {
  312.         if (!$this->productReviews->contains($productReview)) {
  313.             $this->productReviews->add($productReview);
  314.             $productReview->setAuthor($this);
  315.         }
  316.         return $this;
  317.     }
  318.     public function removeProductReview(ProductReview $productReview): static
  319.     {
  320.         if ($this->productReviews->removeElement($productReview)) {
  321.             // set the owning side to null (unless already changed)
  322.             if ($productReview->getAuthor() === $this) {
  323.                 $productReview->setAuthor(null);
  324.             }
  325.         }
  326.         return $this;
  327.     }
  328.     /**
  329.      * @return Collection<int, ProductReviewVote>
  330.      */
  331.     public function getProductReviewVotes(): Collection
  332.     {
  333.         return $this->productReviewVotes;
  334.     }
  335.     public function addProductReviewVote(ProductReviewVote $productReviewVote): static
  336.     {
  337.         if (!$this->productReviewVotes->contains($productReviewVote)) {
  338.             $this->productReviewVotes->add($productReviewVote);
  339.             $productReviewVote->setUser($this);
  340.         }
  341.         return $this;
  342.     }
  343.     public function removeProductReviewVote(ProductReviewVote $productReviewVote): static
  344.     {
  345.         if ($this->productReviewVotes->removeElement($productReviewVote)) {
  346.             // set the owning side to null (unless already changed)
  347.             if ($productReviewVote->getUser() === $this) {
  348.                 $productReviewVote->setUser(null);
  349.             }
  350.         }
  351.         return $this;
  352.     }
  353.     /**
  354.      * @return Collection<int, ProductReviewReply>
  355.      */
  356.     public function getProductReviewReplies(): Collection
  357.     {
  358.         return $this->productReviewReplies;
  359.     }
  360.     public function addProductReviewReply(ProductReviewReply $productReviewReply): static
  361.     {
  362.         if (!$this->productReviewReplies->contains($productReviewReply)) {
  363.             $this->productReviewReplies->add($productReviewReply);
  364.             $productReviewReply->setAuthor($this);
  365.         }
  366.         return $this;
  367.     }
  368.     public function removeProductReviewReply(ProductReviewReply $productReviewReply): static
  369.     {
  370.         if ($this->productReviewReplies->removeElement($productReviewReply)) {
  371.             // set the owning side to null (unless already changed)
  372.             if ($productReviewReply->getAuthor() === $this) {
  373.                 $productReviewReply->setAuthor(null);
  374.             }
  375.         }
  376.         return $this;
  377.     }
  378.     /**
  379.      * @return Collection<int, Article>
  380.      */
  381.     public function getArticles(): Collection
  382.     {
  383.         return $this->articles;
  384.     }
  385.     public function addArticle(Article $article): static
  386.     {
  387.         if (!$this->articles->contains($article)) {
  388.             $this->articles->add($article);
  389.             $article->setAuthor($this);
  390.         }
  391.         return $this;
  392.     }
  393.     public function removeArticle(Article $article): static
  394.     {
  395.         if ($this->articles->removeElement($article)) {
  396.             // set the owning side to null (unless already changed)
  397.             if ($article->getAuthor() === $this) {
  398.                 $article->setAuthor(null);
  399.             }
  400.         }
  401.         return $this;
  402.     }
  403.     /**
  404.      * @return Collection<int, Comment>
  405.      */
  406.     public function getComments(): Collection
  407.     {
  408.         return $this->comments;
  409.     }
  410.     public function addComment(Comment $comment): static
  411.     {
  412.         if (!$this->comments->contains($comment)) {
  413.             $this->comments->add($comment);
  414.             $comment->setAuthor($this);
  415.         }
  416.         return $this;
  417.     }
  418.     public function removeComment(Comment $comment): static
  419.     {
  420.         if ($this->comments->removeElement($comment)) {
  421.             // set the owning side to null (unless already changed)
  422.             if ($comment->getAuthor() === $this) {
  423.                 $comment->setAuthor(null);
  424.             }
  425.         }
  426.         return $this;
  427.     }
  428.     /**
  429.      * @return Collection<int, Ticket>
  430.      */
  431.     public function getTickets(): Collection
  432.     {
  433.         return $this->tickets;
  434.     }
  435.     public function addTicket(Ticket $ticket): static
  436.     {
  437.         if (!$this->tickets->contains($ticket)) {
  438.             $this->tickets->add($ticket);
  439.             $ticket->setCreator($this);
  440.         }
  441.         return $this;
  442.     }
  443.     public function removeTicket(Ticket $ticket): static
  444.     {
  445.         if ($this->tickets->removeElement($ticket)) {
  446.             // set the owning side to null (unless already changed)
  447.             if ($ticket->getCreator() === $this) {
  448.                 $ticket->setCreator(null);
  449.             }
  450.         }
  451.         return $this;
  452.     }
  453.     /**
  454.      * @return Collection<int, TicketMessage>
  455.      */
  456.     public function getTicketMessages(): Collection
  457.     {
  458.         return $this->ticketMessages;
  459.     }
  460.     public function addTicketMessage(TicketMessage $ticketMessage): static
  461.     {
  462.         if (!$this->ticketMessages->contains($ticketMessage)) {
  463.             $this->ticketMessages->add($ticketMessage);
  464.             $ticketMessage->setAuthor($this);
  465.         }
  466.         return $this;
  467.     }
  468.     public function removeTicketMessage(TicketMessage $ticketMessage): static
  469.     {
  470.         if ($this->ticketMessages->removeElement($ticketMessage)) {
  471.             // set the owning side to null (unless already changed)
  472.             if ($ticketMessage->getAuthor() === $this) {
  473.                 $ticketMessage->setAuthor(null);
  474.             }
  475.         }
  476.         return $this;
  477.     }
  478.     public function getMobile(): ?string
  479.     {
  480.         return $this->mobile;
  481.     }
  482.     public function setMobile(?string $mobile): void
  483.     {
  484.         $this->mobile $mobile;
  485.     }
  486.     public function getIdentifier(): string
  487.     {
  488.         return $this->identifier;
  489.     }
  490.     public function setIdentifier(string $identifier): void
  491.     {
  492.         $this->identifier $identifier;
  493.     }
  494.     public function isVerified(): bool
  495.     {
  496.         return $this->isVerified;
  497.     }
  498.     public function setIsVerified(bool $isVerified): void
  499.     {
  500.         $this->isVerified $isVerified;
  501.     }
  502.     public function getVerifyCode(): ?int
  503.     {
  504.         return $this->verifyCode;
  505.     }
  506.     public function setVerifyCode(?int $verifyCode): void
  507.     {
  508.         $this->verifyCode $verifyCode;
  509.     }
  510.     public function getLastName(): ?string
  511.     {
  512.         return $this->lastName;
  513.     }
  514.     public function setLastName(?string $lastName): static
  515.     {
  516.         $this->lastName $lastName;
  517.         return $this;
  518.     }
  519.     /**
  520.      * @return Collection<int, Transaction>
  521.      */
  522.     public function getTransactions(): Collection
  523.     {
  524.         return $this->transactions;
  525.     }
  526.     public function addTransaction(Transaction $transaction): static
  527.     {
  528.         if (!$this->transactions->contains($transaction)) {
  529.             $this->transactions->add($transaction);
  530.             $transaction->setOwner($this);
  531.         }
  532.         return $this;
  533.     }
  534.     public function removeTransaction(Transaction $transaction): static
  535.     {
  536.         if ($this->transactions->removeElement($transaction)) {
  537.             // set the owning side to null (unless already changed)
  538.             if ($transaction->getOwner() === $this) {
  539.                 $transaction->setOwner(null);
  540.             }
  541.         }
  542.         return $this;
  543.     }
  544.     public function getFirstName(): mixed
  545.     {
  546.         return $this->firstName;
  547.     }
  548.     public function setFirstName(mixed $firstName): void
  549.     {
  550.         $this->firstName $firstName;
  551.     }
  552.     public function getPasswordResetAt(): ?\DateTimeInterface
  553.     {
  554.         return $this->passwordResetAt;
  555.     }
  556.     public function setPasswordResetAt(?\DateTimeInterface $passwordResetAt): static
  557.     {
  558.         $this->passwordResetAt $passwordResetAt;
  559.         return $this;
  560.     }
  561. }