src/Entity/User.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Media;
  4. use App\Repository\UserRepository;
  5. use DateTime;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\Common\Collections\Criteria;
  9. use Doctrine\DBAL\Types\Types;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use Gedmo\Blameable\Traits\BlameableEntity;
  12. use Gedmo\Timestampable\Traits\TimestampableEntity;
  13. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  14. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  15. use Symfony\Component\Security\Core\User\UserInterface;
  16. use Symfony\Component\Validator\Constraints as Assert;
  17. #[ORM\Entity(repositoryClassUserRepository::class)]
  18. #[ORM\Table(name'`user`')]
  19. #[UniqueEntity('email''general.email_already_exists')]
  20. #[UniqueEntity('username''general.email_already_exists')]
  21. #[UniqueEntity('nickname''general.nickname_already_exists')]
  22. class User implements UserInterfacePasswordAuthenticatedUserInterface
  23. {
  24.     use BlameableEntity//Hook blameable behavior. Updates createdBy, updatedBy fields
  25.     use TimestampableEntity//Hook timestampable behavior. Updates createdAt, updatedAt fields 
  26.     const ROLE_USER "ROLE_USER";
  27.     const ROLE_INFLUENCER 'ROLE_INFLUENCER';
  28.     const ROLE_ADMIN 'ROLE_ADMIN';
  29.     const ROLE_SUPER_ADMIN 'ROLE_SUPER_ADMIN';
  30.     const SEX_MAN 0;
  31.     const SEX_WOMAN 1;
  32.     const SEX_OTHER 2;
  33.     const SEX_PREFER_NOT_SAY 3;
  34.     #[ORM\Id]
  35.     #[ORM\GeneratedValue(strategy"IDENTITY")]
  36.     #[ORM\Column]
  37.     private ?int $id null;
  38.     #[ORM\Column(length180uniquetrue)]
  39.     #[Assert\NotNull()]
  40.     #[Assert\Length(max180)]
  41.     private ?string $username null;
  42.     #[ORM\Column(length180uniquetrue)]
  43.     #[Assert\NotNull()]
  44.     #[Assert\Length(max180)]
  45.     private ?string $nickname null;
  46.     #[ORM\Column]
  47.     private array $roles = ['ROLE_USER'];
  48.     /**
  49.      * @var string The hashed password
  50.      */
  51.     #[ORM\Column]
  52.     private ?string $password null;
  53.     #[ORM\Column(length255uniquetrue)]
  54.     #[Assert\NotNull()]
  55.     #[Assert\Email]
  56.     #[Assert\Length(max255)]
  57.     private ?string $email null;
  58.     #[ORM\Column]
  59.     private ?bool $isOnBoarding true;
  60.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  61.     private ?\DateTimeInterface $acceptedCommunications null;
  62.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  63.     private ?\DateTimeInterface $acceptedPolicies null;
  64.     #[ORM\Column]
  65.     private ?bool $isActive true;
  66.     #[ORM\Column]
  67.     private ?bool $legalAge true;
  68.     #[ORM\Column]
  69.     private ?bool $isNotificationsActive true;
  70.     #[ORM\OneToMany(mappedBy'user'targetEntityAddress::class, orphanRemovaltrue)]
  71.     private Collection $addresses;
  72.     #[ORM\OneToOne(inversedBy'user'cascade: ['persist''remove'])]
  73.     private ?Media $avatar null;
  74.     #[ORM\ManyToMany(targetEntityCategory::class, inversedBy'users')]
  75.     private Collection $categoryInterests;
  76.     #[ORM\ManyToMany(targetEntitySubcategory::class, inversedBy'users')]
  77.     private Collection $subcategoryInterests;  
  78.     #[ORM\Column(type'boolean'options: ['default' => false])]
  79.     private $isVerified false;
  80.     #[ORM\Column(length100)]
  81.     //#[Assert\NotNull()]
  82.     #[Assert\Length(max100)]
  83.     private ?string $name null;
  84.     #[ORM\Column(length255)]
  85.     //#[Assert\NotNull()]
  86.     #[Assert\Length(max255)]
  87.     private ?string $surname null;
  88.     #[ORM\Column(length100nullabletrue)]
  89.     #[Assert\Length(max100)]
  90.     private ?string $cif null;
  91.     #[ORM\Column(length100nullabletrue)]
  92.     #[Assert\Length(max100)]
  93.     private ?string $phone null;
  94.     #[ORM\Column(length100nullabletrue)]
  95.     #[Assert\Length(max100)]
  96.     private ?string $cpostal null;
  97.     #[ORM\Column]
  98.     //#[Assert\NotNull()]
  99.     private ?int $sex 3;
  100.     #[ORM\OneToOne(mappedBy'buyer'cascade: ['persist''remove'])]
  101.     private ?ShoppingCart $shoppingCart null;
  102.     #[ORM\OneToMany(mappedBy'buyer'targetEntityOrder::class)]
  103.     private Collection $orders;
  104.     #[ORM\OneToMany(mappedBy'owner'targetEntityCard::class)]
  105.     private Collection $cards;
  106.     #[ORM\ManyToMany(targetEntityProduct::class, inversedBy"userFavourites")]
  107.     private Collection $favouriteProducts;
  108.     #[ORM\ManyToMany(targetEntityProduct::class, mappedBy"fakeTriweersInOffer")]
  109.     private Collection $asFakeTriweerInOffer;
  110.     #[ORM\OneToMany(mappedBy'owner'targetEntityWallet::class)]
  111.     private Collection $wallets;
  112.     #[ORM\Column(length500nullabletrue)]
  113.     private ?string $holdedId null;
  114.     #[ORM\Column(nullabletrue)]
  115.     private ?bool $notificationWhatsapp null;
  116.     #[ORM\Column(nullabletrue)]
  117.     private ?string $emailToken null;
  118.     #[ORM\Column(typeTypes::DATETIME_MUTABLEnullabletrue)]
  119.     private ?\DateTimeInterface $emailTokenExpiresAt null;
  120.     #[ORM\Column(typeTypes::DATE_MUTABLEnullabletrue)]
  121.     //#[Assert\NotNull()]
  122.     #[Assert\LessThan('today')]
  123.     private ?\DateTimeInterface $birthday null;
  124.     #[ORM\OneToMany(mappedBy'Buyer'targetEntityProductReturn::class)]
  125.     private Collection $productReturns;
  126.     /**
  127.      * @var ArrayCollection
  128.      */
  129.     #[ORM\OneToMany(mappedBy'mainUser'targetEntityFriendTriweer::class)]
  130.     private Collection $friends;
  131.     /**
  132.      * @var ArrayCollection
  133.      */
  134.     #[ORM\OneToMany(mappedBy'friendUser'targetEntityFriendTriweer::class)]
  135.     private Collection $friendships;
  136.     #[ORM\OneToMany(mappedBy'userToShare'targetEntitySharedAddress::class)]
  137.     private Collection $sharedAddressesToMe;
  138.     #[ORM\ManyToOne(inversedBy'shareFavouriteProductUsers')]
  139.     #[ORM\JoinColumn(nullablefalse)]
  140.     private ?ShareType $shareFavouriteProductsType null;
  141.     #[ORM\ManyToOne(inversedBy'shareShoppingUsers')]
  142.     #[ORM\JoinColumn(nullablefalse)]
  143.     private ?ShareType $shareShoppingType null;
  144.     #[ORM\ManyToOne]
  145.     #[ORM\JoinColumn(nullabletrueoptions: ['default' => 1])]
  146.     private ?Language $language null;
  147.     #[ORM\OneToMany(mappedBy'mainUser'targetEntityBuyingGroup::class)]
  148.     private Collection $buyingGroups;
  149.     #[ORM\ManyToMany(targetEntityBuyingGroup::class, inversedBy'members')]
  150.     private Collection $memberBuyingGroups;
  151.     #[ORM\Column(type'boolean'options: ['default' => false])]
  152.     private ?bool $bankTransferActive false;
  153.     #[ORM\ManyToOne(targetEntityPaymentMethod::class, inversedBy'users')]
  154.     #[ORM\JoinColumn(nullablefalse)]
  155.     private ?PaymentMethod $paymentMethod null;
  156.     public function __construct()
  157.     {
  158.         $this->addresses            = new ArrayCollection();
  159.         $this->categoryInterests    = new ArrayCollection();
  160.         $this->subcategoryInterests = new ArrayCollection();
  161.         $this->acceptedPolicies     = new DateTime();
  162.         $this->orders               = new ArrayCollection();
  163.         $this->cards                = new ArrayCollection();
  164.         $this->favouriteProducts    = new ArrayCollection();
  165.         $this->asFakeTriweerInOffer = new ArrayCollection();
  166.         $this->wallets              = new ArrayCollection();
  167.         $this->productReturns       = new ArrayCollection();
  168.         $this->friends              = new ArrayCollection();
  169.         $this->friendships          = new ArrayCollection();
  170.         $this->sharedAddressesToMe  = new ArrayCollection();
  171.         $this->buyingGroups         = new ArrayCollection();
  172.         $this->memberBuyingGroups   = new ArrayCollection();
  173.     }
  174.     public function getId(): ?int
  175.     {
  176.         return $this->id;
  177.     }
  178.     public function getUsername(): ?string
  179.     {
  180.         return $this->username;
  181.     }
  182.     public function setUsername(string $username): self
  183.     {
  184.         $this->username $username;
  185.         return $this;
  186.     }
  187.     public function getNickname(): ?string
  188.     {
  189.         return $this->nickname;
  190.     }
  191.     public function setNickname(string $nickname): self
  192.     {
  193.         $this->nickname $nickname;
  194.         return $this;
  195.     }
  196.     public function getPaymentMethod(): ?PaymentMethod
  197.     {
  198.         return $this->paymentMethod;
  199.     }
  200.     public function setPaymentMethod(?PaymentMethod $paymentMethod): self
  201.     {
  202.         $this->paymentMethod $paymentMethod;
  203.         return $this;
  204.     }
  205.     public function createNewDefaultNickname(): self
  206.     {
  207.         if ($this->getName() || $this->getSurname()) {
  208.             $this->nickname mb_strtolower(
  209.                 str_replace(
  210.                     ' ',
  211.                     '.',
  212.                     $this->getName() . '.' $this->getSurname()
  213.                 )
  214.             );
  215.         }
  216.         return $this;
  217.     }
  218.     /**
  219.      * A visual identifier that represents this user.
  220.      *
  221.      * @see UserInterface
  222.      */
  223.     public function getUserIdentifier(): string
  224.     {
  225.         return (string) $this->username;
  226.     }
  227.     public function setIsInfluencer(bool $isInfluencer): self
  228.     {
  229.         if ($isInfluencer) {
  230.             $this->addRoles([self::ROLE_INFLUENCER]);
  231.         } else {
  232.             $this->removeRoles([self::ROLE_INFLUENCER]);
  233.         }
  234.         return $this;
  235.     }
  236.     public function getIsInfluencer(): bool
  237.     {
  238.         return in_array(self::ROLE_INFLUENCER$this->roles);
  239.     }
  240.     /**
  241.      * @see UserInterface
  242.      */
  243.     public function getRoles(): array
  244.     {
  245.         $roles $this->roles;
  246.         // guarantee every user at least has ROLE_USER
  247.         $roles[] = 'ROLE_USER';
  248.         return array_unique($roles);
  249.     }
  250.     public function setRoles(array $roles): self
  251.     {
  252.         $this->roles $roles;
  253.         return $this;
  254.     }
  255.     public function addRoles(array $rolesToAdd): self
  256.     {
  257.         $this->roles array_unique(array_merge($this->roles$rolesToAdd));
  258.         return $this;
  259.     }
  260.     public function removeRoles(array $rolesToRemove): self
  261.     {
  262.         $this->roles array_diff($this->roles$rolesToRemove);
  263.         return $this;
  264.     }
  265.     /**
  266.      * @see PasswordAuthenticatedUserInterface
  267.      */
  268.     public function getPassword(): string
  269.     {
  270.         return $this->password;
  271.     }
  272.     public function setPassword(string $password): self
  273.     {
  274.         $this->password $password;
  275.         return $this;
  276.     }
  277.     /**
  278.      * @see UserInterface
  279.      */
  280.     public function eraseCredentials()
  281.     {
  282.         // If you store any temporary, sensitive data on the user, clear it here
  283.         // $this->plainPassword = null;
  284.     }
  285.     public function getEmail(): ?string
  286.     {
  287.         return $this->email;
  288.     }
  289.     public function setEmail(string $email): self
  290.     {
  291.         $this->email $email;
  292.         return $this;
  293.     }
  294.     public function isOnBoarding(): ?bool
  295.     {
  296.         return $this->isOnBoarding;
  297.     }
  298.     public function setIsOnBoarding(bool $isOnBoarding): self
  299.     {
  300.         $this->isOnBoarding $isOnBoarding;
  301.         return $this;
  302.     }
  303.     public function getAcceptedCommunications(): ?\DateTimeInterface
  304.     {
  305.         return $this->acceptedCommunications;
  306.     }
  307.     public function setAcceptedCommunications(?\DateTimeInterface $acceptedCommunications): self
  308.     {
  309.         $this->acceptedCommunications $acceptedCommunications;
  310.         return $this;
  311.     }
  312.     public function getAcceptedPolicies(): ?\DateTimeInterface
  313.     {
  314.         return $this->acceptedPolicies;
  315.     }
  316.     public function setAcceptedPolicies(?\DateTimeInterface $acceptedPolicies): self
  317.     {
  318.         $this->acceptedPolicies $acceptedPolicies;
  319.         return $this;
  320.     }
  321.     public function isActive(): ?bool
  322.     {
  323.         return $this->isActive;
  324.     }
  325.     public function setIsActive(bool $isActive): self
  326.     {
  327.         $this->isActive $isActive;
  328.         return $this;
  329.     }
  330.     public function legalAge(): ?bool
  331.     {
  332.         return $this->legalAge;
  333.     }
  334.     public function setLegalAge(bool $legalAge): self
  335.     {
  336.         $this->legalAge $legalAge;
  337.         return $this;
  338.     }
  339.     public function isNotificationsActive(): ?bool
  340.     {
  341.         return $this->isNotificationsActive;
  342.     }
  343.     public function setIsNotificationsActive(bool $isNotificationsActive): self
  344.     {
  345.         $this->isNotificationsActive $isNotificationsActive;
  346.         return $this;
  347.     }
  348.     /**
  349.      * @return Collection<int, Address>
  350.      */
  351.     public function getShippingAddresses(): Collection
  352.     {
  353.         return $this->addresses->filter(function (Address $address) {
  354.             return !$address->isIsBillingAddress();
  355.         });
  356.     }
  357.     /**
  358.      * @return Collection<int, Address>
  359.      */
  360.     public function getBillingAddresses(): Collection
  361.     {
  362.         return $this->addresses->filter(function (Address $address) {
  363.             return $address->isIsBillingAddress();
  364.         });
  365.     }
  366.     /**
  367.      * @return Collection<int, Address>
  368.      */
  369.     public function getAddresses(): Collection
  370.     {
  371.         return $this->addresses;
  372.     }
  373.     public function addAddress(Address $address): self
  374.     {
  375.         if (!$this->addresses->contains($address)) {
  376.             $this->addresses->add($address);
  377.             $address->setUser($this);
  378.         }
  379.         return $this;
  380.     }
  381.     public function removeAddress(Address $address): self
  382.     {
  383.         if ($this->addresses->removeElement($address)) {
  384.             // set the owning side to null (unless already changed)
  385.             if ($address->getUser() === $this) {
  386.                 $address->setUser(null);
  387.             }
  388.         }
  389.         return $this;
  390.     }
  391.     /**
  392.      * Find user's main address and return it. If the user has more than 1 main address return the first one found
  393.      * 
  394.      * @return Address|null
  395.      */
  396.     public function getMainAddress(): ?Address
  397.     {
  398.         foreach ($this->addresses as $address) {
  399.             if ($address->isIsDefaultAddress()) {
  400.                 return $address;
  401.             }
  402.         }
  403.         return null;
  404.     }
  405.     public function getAvatar(): ?Media
  406.     {
  407.         return $this->avatar;
  408.     }
  409.     public function setAvatar(?Media $avatar): self
  410.     {
  411.         $avatar->setDirectory('user');
  412.         $this->avatar $avatar;
  413.         return $this;
  414.     }
  415.     /**
  416.      * @return Collection<int, Category>
  417.      */
  418.     public function getCategoryInterests(): Collection
  419.     {
  420.         return $this->categoryInterests;
  421.     }
  422.     public function addCategoryInterest(Category $categoryInterest): self
  423.     {
  424.         if (!$this->categoryInterests->contains($categoryInterest)) {
  425.             $this->categoryInterests->add($categoryInterest);
  426.         }
  427.         return $this;
  428.     }
  429.     public function removeCategoryInterest(Category $categoryInterest): self
  430.     {
  431.         $this->categoryInterests->removeElement($categoryInterest);
  432.         return $this;
  433.     }
  434.     /**
  435.      * @return Collection<int, Subcategory>
  436.      */
  437.     public function getSubcategoryInterests(): Collection
  438.     {
  439.         return $this->subcategoryInterests;
  440.     }
  441.     public function addSubcategoryInterest(Subcategory $subcategoryInterest): self
  442.     {
  443.         if (!$this->subcategoryInterests->contains($subcategoryInterest)) {
  444.             $this->subcategoryInterests->add($subcategoryInterest);
  445.         }
  446.         return $this;
  447.     }
  448.     public function removeSubcategoryInterest(Subcategory $subcategoryInterest): self
  449.     {
  450.         $this->subcategoryInterests->removeElement($subcategoryInterest);
  451.         return $this;
  452.     }
  453.     public function isVerified(): bool
  454.     {
  455.         return $this->isVerified;
  456.     }
  457.     public function setIsVerified(bool $isVerified): self
  458.     {
  459.         $this->isVerified $isVerified;
  460.         return $this;
  461.     }
  462.     public function getName(): ?string
  463.     {
  464.         return $this->name;
  465.     }
  466.     public function setName(?string $name): self
  467.     {
  468.         $this->name $name;
  469.         return $this;
  470.     }
  471.     public function getSurname(): ?string
  472.     {
  473.         return $this->surname;
  474.     }
  475.     public function setSurname(?string $surname): self
  476.     {
  477.         $this->surname $surname;
  478.         return $this;
  479.     }
  480.     public function getFullName(): ?string
  481.     {
  482.         return $this->getName() . ' ' $this->getSurname();
  483.     }
  484.     public function getFullNameWithId(): ?string
  485.     {
  486.         return $this->getName() . ' ' $this->getSurname() . " (ID: " $this->getId() . ")";
  487.     }
  488.     public function getCif(): ?string
  489.     {
  490.         return $this->cif;
  491.     }
  492.     public function setCif(?string $cif): self
  493.     {
  494.         $this->cif $cif;
  495.         return $this;
  496.     }
  497.     public function getPhone(): ?string
  498.     {
  499.         return $this->phone;
  500.     }
  501.     public function setPhone(?string $phone): self
  502.     {
  503.         $this->phone str_replace(' '''$phone);
  504.         return $this;
  505.     }
  506.     public function getCpostal(): ?string
  507.     {
  508.         return $this->cpostal;
  509.     }
  510.     public function setCpostal(?string $cpostal): self
  511.     {
  512.         $this->cpostal $cpostal;
  513.         return $this;
  514.     }
  515.     public function getSex(): ?string
  516.     {
  517.         return $this->sex;
  518.     }
  519.     public function setSex(?int $sex): self
  520.     {
  521.         $this->sex $sex;
  522.         return $this;
  523.     }
  524.     public function getShoppingCartItemNumber(): ?int
  525.     {
  526.         if ($this->shoppingCart && $this->shoppingCart->getShoppingCartDetails()) {
  527.             return $this->shoppingCart->getShoppingCartDetails()->count();
  528.         }
  529.         return null;
  530.     }
  531.     public function getShoppingCart(): ?ShoppingCart
  532.     {
  533.         return $this->shoppingCart;
  534.     }
  535.     public function setShoppingCart(ShoppingCart $shoppingCart): self
  536.     {
  537.         // set the owning side of the relation if necessary
  538.         if ($shoppingCart->getBuyer() !== $this) {
  539.             $shoppingCart->setBuyer($this);
  540.         }
  541.         $this->shoppingCart $shoppingCart;
  542.         return $this;
  543.     }
  544.     public function emptyShoppingCart(): self
  545.     {
  546.         $this->shoppingCart null;
  547.         return $this;
  548.     }
  549.     /**
  550.      * @return Collection<int, Order>
  551.      */
  552.     public function getOrders(): Collection
  553.     {
  554.         return $this->orders;
  555.     }
  556.     public function addOrder(Order $order): self
  557.     {
  558.         if (!$this->orders->contains($order)) {
  559.             $this->orders->add($order);
  560.             $order->setBuyer($this);
  561.         }
  562.         return $this;
  563.     }
  564.     public function removeOrder(Order $order): self
  565.     {
  566.         if ($this->orders->removeElement($order)) {
  567.             // set the owning side to null (unless already changed)
  568.             if ($order->getBuyer() === $this) {
  569.                 $order->setBuyer(null);
  570.             }
  571.         }
  572.         return $this;
  573.     }
  574.     /**
  575.      * Find user's last order by updatedAt datetime field
  576.      * 
  577.      * @return Order|null
  578.      */
  579.     public function getLastOrder(): ?Order
  580.     {
  581.         $lastOrder null;
  582.         foreach ($this->orders as $order) {
  583.             if ($lastOrder == null) {
  584.                 $lastOrder $order;
  585.             }
  586.             if ($lastOrder->getUpdatedAt() < $order->getUpdatedAt()) {
  587.                 $lastOrder $order;
  588.             }
  589.         }
  590.         return $lastOrder;
  591.     }
  592.     /**
  593.      * @return Collection<int, Card>
  594.      */
  595.     public function getCards(): Collection
  596.     {
  597.         return $this->cards;
  598.     }
  599.     public function addCard(Card $card): self
  600.     {
  601.         if (!$this->cards->contains($card)) {
  602.             $this->cards->add($card);
  603.             $card->setOwner($this);
  604.         }
  605.         return $this;
  606.     }
  607.     public function removeCard(Card $card): self
  608.     {
  609.         if ($this->cards->removeElement($card)) {
  610.             // set the owning side to null (unless already changed)
  611.             if ($card->getOwner() === $this) {
  612.                 $card->setOwner(null);
  613.             }
  614.         }
  615.         return $this;
  616.     }
  617.     /**
  618.      * @return Collection<int, Product>
  619.      */
  620.     public function getFavouriteProducts(): Collection
  621.     {
  622.         return $this->favouriteProducts;
  623.     }
  624.     public function addFavouriteProduct(Product $favouriteProduct): self
  625.     {
  626.         if (!$this->favouriteProducts->contains($favouriteProduct)) {
  627.             $this->favouriteProducts->add($favouriteProduct);
  628.         }
  629.         return $this;
  630.     }
  631.     public function removeFavouriteProduct(Product $favouriteProduct): self
  632.     {
  633.         $this->favouriteProducts->removeElement($favouriteProduct);
  634.         return $this;
  635.     }
  636.     /**
  637.      * @return Collection<int, Product>
  638.      */
  639.     public function getAsFakeTriweerInOffer(): Collection
  640.     {
  641.         return $this->asFakeTriweerInOffer;
  642.     }
  643.     /**
  644.      * @return float
  645.      */
  646.     public function getPositiveAvailableWalletCoins(): float
  647.     {
  648.         $availableCoins $this->getAvailableWalletCoins();
  649.         if ($availableCoins 0) {
  650.             $availableCoins 0;
  651.         }
  652.         return $availableCoins;
  653.     }
  654.     /**
  655.      * @return float
  656.      */
  657.     public function getAvailableWalletCoins(): float
  658.     {
  659.         $sum 0;
  660.         foreach ($this->getWallets() as $wallet) {
  661.             if (
  662.                 ($wallet->getSpentOrder() &&
  663.                     $wallet->getSpentOrder()->getStatus()->getKey() == OrderStatus::PENDING_PAYMENT
  664.                 ) ||
  665.                 ($wallet->getOrderDetail() &&
  666.                     $wallet->getOrderDetail()->getHeader()->getStatus()->getKey() == OrderStatus::PENDING_PAYMENT
  667.                 )
  668.             ) {
  669.                 continue;
  670.             }
  671.             if (
  672.                 !$wallet->isCancelled() && !$wallet->isPending()
  673.             ) {
  674.                 $sum += $wallet->getAmount();
  675.             }
  676.         }
  677.         return $sum;
  678.     }
  679.     /**
  680.      * @return Collection<int, Wallet>
  681.      */
  682.     public function getPendingWalletCoins(): float
  683.     {
  684.         $sum 0;
  685.         foreach ($this->getWallets() as $wallet) {
  686.             if (
  687.                 ($wallet->getSpentOrder() &&
  688.                     $wallet->getSpentOrder()->getStatus()->getKey() == OrderStatus::PENDING_PAYMENT
  689.                 ) ||
  690.                 ($wallet->getOrderDetail() &&
  691.                     $wallet->getOrderDetail()->getHeader()->getStatus()->getKey() == OrderStatus::PENDING_PAYMENT
  692.                 )
  693.             ) {
  694.                 continue;
  695.             }
  696.             if (
  697.                 !$wallet->isCancelled() && $wallet->isPending()
  698.             ) {
  699.                 $sum += $wallet->getAmount();
  700.             }
  701.         }
  702.         return $sum;
  703.     }
  704.     /**
  705.      * @return Collection<int, Wallet>
  706.      */
  707.     public function getWallets(): Collection
  708.     {
  709.         return $this->wallets;
  710.     }
  711.     public function addWallet(Wallet $wallet): self
  712.     {
  713.         if (!$this->wallets->contains($wallet)) {
  714.             $this->wallets->add($wallet);
  715.             $wallet->setOwner($this);
  716.         }
  717.         return $this;
  718.     }
  719.     public function removeWallet(Wallet $wallet): self
  720.     {
  721.         if ($this->wallets->removeElement($wallet)) {
  722.             // set the owning side to null (unless already changed)
  723.             if ($wallet->getOwner() === $this) {
  724.                 $wallet->setOwner(null);
  725.             }
  726.         }
  727.         return $this;
  728.     }
  729.     public function getHoldedId(): ?string
  730.     {
  731.         return $this->holdedId;
  732.     }
  733.     public function setHoldedId(?string $holdedId): self
  734.     {
  735.         $this->holdedId $holdedId;
  736.         return $this;
  737.     }
  738.     public function isNotificationWhatsapp(): ?bool
  739.     {
  740.         return $this->notificationWhatsapp;
  741.     }
  742.     public function setNotificationWhatsapp(?bool $notificationWhatsapp): self
  743.     {
  744.         $this->notificationWhatsapp $notificationWhatsapp;
  745.         return $this;
  746.     }
  747.     public function getEmailToken(): ?string
  748.     {
  749.         return $this->emailToken;
  750.     }
  751.     public function setEmailToken(string $emailToken): self
  752.     {
  753.         $this->emailToken $emailToken;
  754.         return $this;
  755.     }
  756.     public function getEmailTokenExpiresAt(): ?\DateTimeInterface
  757.     {
  758.         return $this->emailTokenExpiresAt;
  759.     }
  760.     public function setEmailTokenExpiresAt(?\DateTimeInterface $emailTokenExpiresAt): self
  761.     {
  762.         $this->emailTokenExpiresAt $emailTokenExpiresAt;
  763.         return $this;
  764.     }
  765.     public function getIsAdult(): ?bool
  766.     {
  767.         if (!$this->birthday) {
  768.             return false;
  769.         }
  770.         $today = new \DateTime(date("Y-m-d"));
  771.         $interval $today->diff($this->birthday);
  772.         if (intval($interval->y) > 18) {
  773.             return true;
  774.         } else {
  775.             return false;
  776.         }
  777.     }
  778.     public function getBirthday(): ?\DateTimeInterface
  779.     {
  780.         return $this->birthday;
  781.     }
  782.     public function setBirthday(?\DateTimeInterface $birthday): self
  783.     {
  784.         $this->birthday $birthday;
  785.         return $this;
  786.     }
  787.     /**
  788.      * @return Collection<int, ProductReturn>
  789.      */
  790.     public function getProductReturns(): Collection
  791.     {
  792.         return $this->productReturns;
  793.     }
  794.     public function addProductReturn(ProductReturn $productReturn): self
  795.     {
  796.         if (!$this->productReturns->contains($productReturn)) {
  797.             $this->productReturns->add($productReturn);
  798.             $productReturn->setBuyer($this);
  799.         }
  800.         return $this;
  801.     }
  802.     public function removeProductReturn(ProductReturn $productReturn): self
  803.     {
  804.         if ($this->productReturns->removeElement($productReturn)) {
  805.             // set the owning side to null (unless already changed)
  806.             if ($productReturn->getBuyer() === $this) {
  807.                 $productReturn->setBuyer(null);
  808.             }
  809.         }
  810.         return $this;
  811.     }
  812.     /**
  813.      * @return Collection<int, FriendTriweer>
  814.      */
  815.     public function getFriends(): Collection
  816.     {
  817.         return $this->friends;
  818.     }
  819.     /**
  820.      * @return Collection<int, FriendTriweer>
  821.      */
  822.     public function getFriendships(): Collection
  823.     {
  824.         return $this->friendships;
  825.     }
  826.     /**
  827.      * @param User $friendUser
  828.      * @return FriendTriweer|false
  829.      */
  830.     public function getFriendTriweer(User $friendUser)
  831.     {
  832.         $criteria Criteria::create()
  833.             ->andWhere(Criteria::expr()->eq('mainUser'$this))
  834.             ->andWhere(Criteria::expr()->eq('friendUser'$friendUser));
  835.         return $this->friends->matching($criteria)->first();
  836.     }
  837.     public function addFriend(FriendTriweer $friend): self
  838.     {
  839.         if (!$this->friends->contains($friend)) {
  840.             $this->friends->add($friend);
  841.             $friend->setMainUser($this);
  842.         }
  843.         return $this;
  844.     }
  845.     public function removeFriend(FriendTriweer $friend): self
  846.     {
  847.         if ($this->friends->removeElement($friend)) {
  848.             // set the owning side to null (unless already changed)
  849.             if ($friend->getMainUser() === $this) {
  850.                 $friend->setMainUser(null);
  851.             }
  852.         }
  853.         return $this;
  854.     }
  855.     /**
  856.      * @return Collection<int, SharedAddress>
  857.      */
  858.     public function getSharedAddressesToMe(): Collection
  859.     {
  860.         return $this->sharedAddressesToMe;
  861.     }
  862.     public function addSharedAddressesToMe(SharedAddress $sharedAddressesToMe): self
  863.     {
  864.         if (!$this->sharedAddressesToMe->contains($sharedAddressesToMe)) {
  865.             $this->sharedAddressesToMe->add($sharedAddressesToMe);
  866.             $sharedAddressesToMe->setUserToShare($this);
  867.         }
  868.         return $this;
  869.     }
  870.     public function removeSharedAddressesToMe(SharedAddress $sharedAddressesToMe): self
  871.     {
  872.         if ($this->sharedAddressesToMe->removeElement($sharedAddressesToMe)) {
  873.             // set the owning side to null (unless already changed)
  874.             if ($sharedAddressesToMe->getUserToShare() === $this) {
  875.                 $sharedAddressesToMe->setUserToShare(null);
  876.             }
  877.         }
  878.         return $this;
  879.     }
  880.     public function getLanguage(): ?Language
  881.     {
  882.         return $this->language;
  883.     }
  884.     public function setLanguage(?Language $language): self
  885.     {
  886.         $this->language $language;
  887.         return $this;
  888.     }
  889.     public function getShareFavouriteProductsType(): ?ShareType
  890.     {
  891.         return $this->shareFavouriteProductsType;
  892.     }
  893.     public function setShareFavouriteProductsType(?ShareType $shareFavouriteProductsType): self
  894.     {
  895.         $this->shareFavouriteProductsType $shareFavouriteProductsType;
  896.         return $this;
  897.     }
  898.     public function getShareShoppingType(): ?ShareType
  899.     {
  900.         return $this->shareShoppingType;
  901.     }
  902.     public function setShareShoppingType(?ShareType $shareShoppingType): self
  903.     {
  904.         $this->shareShoppingType $shareShoppingType;
  905.         return $this;
  906.     }
  907.     /**
  908.      * @return Collection<int, BuyingGroup>
  909.      */
  910.     public function getBuyingGroups(): Collection
  911.     {
  912.         return $this->buyingGroups;
  913.     }
  914.     public function addBuyingGroup(BuyingGroup $buyingGroup): self
  915.     {
  916.         if (!$this->buyingGroups->contains($buyingGroup)) {
  917.             $this->buyingGroups->add($buyingGroup);
  918.             $buyingGroup->setMainUser($this);
  919.         }
  920.         return $this;
  921.     }
  922.     public function removeBuyingGroup(BuyingGroup $buyingGroup): self
  923.     {
  924.         if ($this->buyingGroups->removeElement($buyingGroup)) {
  925.             // set the owning side to null (unless already changed)
  926.             if ($buyingGroup->getMainUser() === $this) {
  927.                 $buyingGroup->setMainUser(null);
  928.             }
  929.         }
  930.         return $this;
  931.     }
  932.     /**
  933.      * @return Collection<int, BuyingGroup>
  934.      */
  935.     public function getMemberBuyingGroups(): Collection
  936.     {
  937.         return $this->memberBuyingGroups;
  938.     }
  939.     public function addMemberBuyingGroup(BuyingGroup $buyingGroup): self
  940.     {
  941.         if (!$this->memberBuyingGroups->contains($buyingGroup)) {
  942.             $this->memberBuyingGroups->add($buyingGroup);
  943.             $buyingGroup->setMainUser($this);
  944.         }
  945.         return $this;
  946.     }
  947.     public function removeMemberBuyingGroup(BuyingGroup $buyingGroup): self
  948.     {
  949.         if ($this->memberBuyingGroups->removeElement($buyingGroup)) {
  950.             // set the owning side to null (unless already changed)
  951.             if ($buyingGroup->getMainUser() === $this) {
  952.                 $buyingGroup->setMainUser(null);
  953.             }
  954.         }
  955.         return $this;
  956.     }
  957.     public function isBankTransferActive(): ?bool
  958.     {
  959.         return $this->bankTransferActive;
  960.     }
  961.     public function setBankTransferActive(bool $bankTransferActive): self
  962.     {
  963.         $this->bankTransferActive $bankTransferActive;
  964.         return $this;
  965.     }
  966. }