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\Shop\Accounting\Transaction;
  5. use App\Entity\Shop\Blog\Article;
  6. use App\Entity\Shop\Blog\Comment;
  7. use App\Entity\Shop\Cart\Cart;
  8. use App\Entity\Shop\Order\Order;
  9. use App\Entity\Shop\Product\ProductReview;
  10. use App\Entity\Shop\Product\ProductReviewReply;
  11. use App\Entity\Shop\Product\ProductReviewVote;
  12. use App\Entity\Shop\Shop\Review;
  13. use App\Entity\Shop\Shop\Shop;
  14. use App\Entity\Shop\Ticket\Ticket;
  15. use App\Entity\Shop\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 ?Shop $shop 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.     public function __construct()
  97.     {
  98.         parent::__construct();
  99.         $this->wallet 0;
  100.         $this->orders = new ArrayCollection();
  101.         $this->carts = new ArrayCollection();
  102.         $this->reviews = new ArrayCollection();
  103.         $this->addresses = new ArrayCollection();
  104.         $this->productReviews = new ArrayCollection();
  105.         $this->productReviewVotes = new ArrayCollection();
  106.         $this->productReviewReplies = new ArrayCollection();
  107.         $this->articles = new ArrayCollection();
  108.         $this->comments = new ArrayCollection();
  109.         $this->tickets = new ArrayCollection();
  110.         $this->ticketMessages = new ArrayCollection();
  111.         $this->setVerifyCode(random_int(00000 99999));
  112.         $this->transactions = new ArrayCollection();
  113.     }
  114.     public function hasRole($role)
  115.     {
  116.         return in_array($role$this->roles);
  117.     }
  118.     public function getId(): ?string
  119.     {
  120.         return $this->id;
  121.     }
  122.     public function getEmail(): ?string
  123.     {
  124.         return $this->email;
  125.     }
  126.     public function setEmail(string $email): static
  127.     {
  128.         $this->email $email;
  129.         return $this;
  130.     }
  131.     /**
  132.      * @deprecated since Symfony 5.3, use getUserIdentifier instead
  133.      */
  134.     public function getUsername(): string
  135.     {
  136.         return (string) $this->email;
  137.     }
  138.     /**
  139.      * @see UserInterface
  140.      */
  141.     public function getRoles(): array
  142.     {
  143.         $roles $this->roles;
  144.         // guarantee every user at least has ROLE_USER
  145.         $roles[] = 'ROLE_USER';
  146.         return array_unique($roles);
  147.     }
  148.     public function setRoles(array $roles): static
  149.     {
  150.         $this->roles $roles;
  151.         return $this;
  152.     }
  153.     /**
  154.      * @see PasswordAuthenticatedUserInterface
  155.      */
  156.     public function getPassword(): string
  157.     {
  158.         return $this->password;
  159.     }
  160.     public function setPassword(string $password): static
  161.     {
  162.         $this->password $password;
  163.         return $this;
  164.     }
  165.     /**
  166.      * Returning a salt is only needed, if you are not using a modern
  167.      * hashing algorithm (e.g. bcrypt or sodium) in your security.yaml.
  168.      *
  169.      * @see UserInterface
  170.      */
  171.     public function getSalt(): ?string
  172.     {
  173.         return null;
  174.     }
  175.     /**
  176.      * @see UserInterface
  177.      */
  178.     public function eraseCredentials(): void
  179.     {
  180.         // If you store any temporary, sensitive data on the user, clear it here
  181.         // $this->plainPassword = null;
  182.     }
  183.     public function getWallet(): ?string
  184.     {
  185.         return $this->wallet;
  186.     }
  187.     public function setWallet(string $wallet): static
  188.     {
  189.         $this->wallet $wallet;
  190.         return $this;
  191.     }
  192.     public function getShop(): ?Shop
  193.     {
  194.         return $this->shop;
  195.     }
  196.     public function setShop(?Shop $shop): static
  197.     {
  198.         $this->shop $shop;
  199.         return $this;
  200.     }
  201.     /**
  202.      * @return Collection<int, Order>
  203.      */
  204.     public function getOrders(): Collection
  205.     {
  206.         return $this->orders;
  207.     }
  208.     public function addOrder(Order $order): static
  209.     {
  210.         if (!$this->orders->contains($order)) {
  211.             $this->orders->add($order);
  212.             $order->setCustomer($this);
  213.         }
  214.         return $this;
  215.     }
  216.     public function removeOrder(Order $order): static
  217.     {
  218.         if ($this->orders->removeElement($order)) {
  219.             // set the owning side to null (unless already changed)
  220.             if ($order->getCustomer() === $this) {
  221.                 $order->setCustomer(null);
  222.             }
  223.         }
  224.         return $this;
  225.     }
  226.     /**
  227.      * @return Collection<int, Cart>
  228.      */
  229.     public function getCarts(): Collection
  230.     {
  231.         return $this->carts;
  232.     }
  233.     public function addCart(Cart $cart): static
  234.     {
  235.         if (!$this->carts->contains($cart)) {
  236.             $this->carts->add($cart);
  237.             $cart->setCustomer($this);
  238.         }
  239.         return $this;
  240.     }
  241.     public function removeCart(Cart $cart): static
  242.     {
  243.         if ($this->carts->removeElement($cart)) {
  244.             // set the owning side to null (unless already changed)
  245.             if ($cart->getCustomer() === $this) {
  246.                 $cart->setCustomer(null);
  247.             }
  248.         }
  249.         return $this;
  250.     }
  251.     /**
  252.      * @return Collection<int, Review>
  253.      */
  254.     public function getReviews(): Collection
  255.     {
  256.         return $this->reviews;
  257.     }
  258.     public function addReview(Review $review): static
  259.     {
  260.         if (!$this->reviews->contains($review)) {
  261.             $this->reviews->add($review);
  262.             $review->setCustomer($this);
  263.         }
  264.         return $this;
  265.     }
  266.     public function removeReview(Review $review): static
  267.     {
  268.         if ($this->reviews->removeElement($review)) {
  269.             // set the owning side to null (unless already changed)
  270.             if ($review->getCustomer() === $this) {
  271.                 $review->setCustomer(null);
  272.             }
  273.         }
  274.         return $this;
  275.     }
  276.     /**
  277.      * @return Collection<int, Address>
  278.      */
  279.     public function getAddresses(): Collection
  280.     {
  281.         return $this->addresses;
  282.     }
  283.     public function addAddress(Address $address): static
  284.     {
  285.         if (!$this->addresses->contains($address)) {
  286.             $this->addresses->add($address);
  287.             $address->setCustomer($this);
  288.         }
  289.         return $this;
  290.     }
  291.     public function removeAddress(Address $address): static
  292.     {
  293.         if ($this->addresses->removeElement($address)) {
  294.             // set the owning side to null (unless already changed)
  295.             if ($address->getCustomer() === $this) {
  296.                 $address->setCustomer(null);
  297.             }
  298.         }
  299.         return $this;
  300.     }
  301.     /**
  302.      * @return Collection<int, ProductReview>
  303.      */
  304.     public function getProductReviews(): Collection
  305.     {
  306.         return $this->productReviews;
  307.     }
  308.     public function addProductReview(ProductReview $productReview): static
  309.     {
  310.         if (!$this->productReviews->contains($productReview)) {
  311.             $this->productReviews->add($productReview);
  312.             $productReview->setAuthor($this);
  313.         }
  314.         return $this;
  315.     }
  316.     public function removeProductReview(ProductReview $productReview): static
  317.     {
  318.         if ($this->productReviews->removeElement($productReview)) {
  319.             // set the owning side to null (unless already changed)
  320.             if ($productReview->getAuthor() === $this) {
  321.                 $productReview->setAuthor(null);
  322.             }
  323.         }
  324.         return $this;
  325.     }
  326.     /**
  327.      * @return Collection<int, ProductReviewVote>
  328.      */
  329.     public function getProductReviewVotes(): Collection
  330.     {
  331.         return $this->productReviewVotes;
  332.     }
  333.     public function addProductReviewVote(ProductReviewVote $productReviewVote): static
  334.     {
  335.         if (!$this->productReviewVotes->contains($productReviewVote)) {
  336.             $this->productReviewVotes->add($productReviewVote);
  337.             $productReviewVote->setUser($this);
  338.         }
  339.         return $this;
  340.     }
  341.     public function removeProductReviewVote(ProductReviewVote $productReviewVote): static
  342.     {
  343.         if ($this->productReviewVotes->removeElement($productReviewVote)) {
  344.             // set the owning side to null (unless already changed)
  345.             if ($productReviewVote->getUser() === $this) {
  346.                 $productReviewVote->setUser(null);
  347.             }
  348.         }
  349.         return $this;
  350.     }
  351.     /**
  352.      * @return Collection<int, ProductReviewReply>
  353.      */
  354.     public function getProductReviewReplies(): Collection
  355.     {
  356.         return $this->productReviewReplies;
  357.     }
  358.     public function addProductReviewReply(ProductReviewReply $productReviewReply): static
  359.     {
  360.         if (!$this->productReviewReplies->contains($productReviewReply)) {
  361.             $this->productReviewReplies->add($productReviewReply);
  362.             $productReviewReply->setAuthor($this);
  363.         }
  364.         return $this;
  365.     }
  366.     public function removeProductReviewReply(ProductReviewReply $productReviewReply): static
  367.     {
  368.         if ($this->productReviewReplies->removeElement($productReviewReply)) {
  369.             // set the owning side to null (unless already changed)
  370.             if ($productReviewReply->getAuthor() === $this) {
  371.                 $productReviewReply->setAuthor(null);
  372.             }
  373.         }
  374.         return $this;
  375.     }
  376.     /**
  377.      * @return Collection<int, Article>
  378.      */
  379.     public function getArticles(): Collection
  380.     {
  381.         return $this->articles;
  382.     }
  383.     public function addArticle(Article $article): static
  384.     {
  385.         if (!$this->articles->contains($article)) {
  386.             $this->articles->add($article);
  387.             $article->setAuthor($this);
  388.         }
  389.         return $this;
  390.     }
  391.     public function removeArticle(Article $article): static
  392.     {
  393.         if ($this->articles->removeElement($article)) {
  394.             // set the owning side to null (unless already changed)
  395.             if ($article->getAuthor() === $this) {
  396.                 $article->setAuthor(null);
  397.             }
  398.         }
  399.         return $this;
  400.     }
  401.     /**
  402.      * @return Collection<int, Comment>
  403.      */
  404.     public function getComments(): Collection
  405.     {
  406.         return $this->comments;
  407.     }
  408.     public function addComment(Comment $comment): static
  409.     {
  410.         if (!$this->comments->contains($comment)) {
  411.             $this->comments->add($comment);
  412.             $comment->setAuthor($this);
  413.         }
  414.         return $this;
  415.     }
  416.     public function removeComment(Comment $comment): static
  417.     {
  418.         if ($this->comments->removeElement($comment)) {
  419.             // set the owning side to null (unless already changed)
  420.             if ($comment->getAuthor() === $this) {
  421.                 $comment->setAuthor(null);
  422.             }
  423.         }
  424.         return $this;
  425.     }
  426.     /**
  427.      * @return Collection<int, Ticket>
  428.      */
  429.     public function getTickets(): Collection
  430.     {
  431.         return $this->tickets;
  432.     }
  433.     public function addTicket(Ticket $ticket): static
  434.     {
  435.         if (!$this->tickets->contains($ticket)) {
  436.             $this->tickets->add($ticket);
  437.             $ticket->setCreator($this);
  438.         }
  439.         return $this;
  440.     }
  441.     public function removeTicket(Ticket $ticket): static
  442.     {
  443.         if ($this->tickets->removeElement($ticket)) {
  444.             // set the owning side to null (unless already changed)
  445.             if ($ticket->getCreator() === $this) {
  446.                 $ticket->setCreator(null);
  447.             }
  448.         }
  449.         return $this;
  450.     }
  451.     /**
  452.      * @return Collection<int, TicketMessage>
  453.      */
  454.     public function getTicketMessages(): Collection
  455.     {
  456.         return $this->ticketMessages;
  457.     }
  458.     public function addTicketMessage(TicketMessage $ticketMessage): static
  459.     {
  460.         if (!$this->ticketMessages->contains($ticketMessage)) {
  461.             $this->ticketMessages->add($ticketMessage);
  462.             $ticketMessage->setAuthor($this);
  463.         }
  464.         return $this;
  465.     }
  466.     public function removeTicketMessage(TicketMessage $ticketMessage): static
  467.     {
  468.         if ($this->ticketMessages->removeElement($ticketMessage)) {
  469.             // set the owning side to null (unless already changed)
  470.             if ($ticketMessage->getAuthor() === $this) {
  471.                 $ticketMessage->setAuthor(null);
  472.             }
  473.         }
  474.         return $this;
  475.     }
  476.     public function getMobile(): ?string
  477.     {
  478.         return $this->mobile;
  479.     }
  480.     public function setMobile(?string $mobile): void
  481.     {
  482.         $this->mobile $mobile;
  483.     }
  484.     public function getIdentifier(): string
  485.     {
  486.         return $this->identifier;
  487.     }
  488.     public function setIdentifier(string $identifier): void
  489.     {
  490.         $this->identifier $identifier;
  491.     }
  492.     public function isVerified(): bool
  493.     {
  494.         return $this->isVerified;
  495.     }
  496.     public function setIsVerified(bool $isVerified): void
  497.     {
  498.         $this->isVerified $isVerified;
  499.     }
  500.     public function getVerifyCode(): ?int
  501.     {
  502.         return $this->verifyCode;
  503.     }
  504.     public function setVerifyCode(?int $verifyCode): void
  505.     {
  506.         $this->verifyCode $verifyCode;
  507.     }
  508.     public function getLastName(): ?string
  509.     {
  510.         return $this->lastName;
  511.     }
  512.     public function setLastName(?string $lastName): static
  513.     {
  514.         $this->lastName $lastName;
  515.         return $this;
  516.     }
  517.     /**
  518.      * @return Collection<int, Transaction>
  519.      */
  520.     public function getTransactions(): Collection
  521.     {
  522.         return $this->transactions;
  523.     }
  524.     public function addTransaction(Transaction $transaction): static
  525.     {
  526.         if (!$this->transactions->contains($transaction)) {
  527.             $this->transactions->add($transaction);
  528.             $transaction->setOwner($this);
  529.         }
  530.         return $this;
  531.     }
  532.     public function removeTransaction(Transaction $transaction): static
  533.     {
  534.         if ($this->transactions->removeElement($transaction)) {
  535.             // set the owning side to null (unless already changed)
  536.             if ($transaction->getOwner() === $this) {
  537.                 $transaction->setOwner(null);
  538.             }
  539.         }
  540.         return $this;
  541.     }
  542.     public function getFirstName(): mixed
  543.     {
  544.         return $this->firstName;
  545.     }
  546.     public function setFirstName(mixed $firstName): void
  547.     {
  548.         $this->firstName $firstName;
  549.     }
  550. }