vendor/kobizo/component/src/Entity/User.php line 40

Open in your IDE?
  1. <?php
  2. namespace Kobizo\Component\Entity;
  3. use DateTime as DateTime;
  4. use DateTimeInterface;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\Common\Collections\Criteria;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Gedmo\Mapping\Annotation as Gedmo;
  10. use Kobizo\Bundle\ECommerceBundle\Entity\Budget;
  11. use Kobizo\Bundle\ECommerceBundle\Entity\CustomerAddress;
  12. use Kobizo\Bundle\ECommerceBundle\Entity\CustomerGroup;
  13. use Kobizo\Bundle\ECommerceBundle\Entity\FavoStore;
  14. use Kobizo\Bundle\ECommerceBundle\Entity\Order;
  15. use Kobizo\Bundle\ECommerceBundle\Entity\OrderAddress;
  16. use Kobizo\Bundle\ECommerceBundle\Entity\Quote;
  17. use Kobizo\Bundle\ECommerceBundle\Entity\QuoteAddress;
  18. use Kobizo\Bundle\ECommerceBundle\Entity\Rating;
  19. use Kobizo\Bundle\ECommerceBundle\Entity\Review;
  20. use Kobizo\Bundle\ECommerceBundle\Entity\Store;
  21. use Kobizo\Bundle\ECommerceBundle\Entity\Table;
  22. use Kobizo\Bundle\ECommerceBundle\Entity\ViewedProduct;
  23. use Kobizo\Bundle\ECommerceBundle\Entity\Wishlist;
  24. use Kobizo\Component\Attributes\DefaultRolesAttribute;
  25. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  26. use Symfony\Component\Security\Core\User\EquatableInterface;
  27. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  28. use Symfony\Component\Security\Core\User\UserInterface;
  29. use Symfony\Component\Validator\Constraints as Assert;
  30. use Kobizo\Bundle\ECommerceBundle\Entity\Reservation;
  31. use Kobizo\Bundle\ECommerceBundle\Entity\ReservationTimeSetting;
  32. /**
  33.  * @ORM\Table(name="`user`")
  34.  * @ORM\Entity(repositoryClass="Kobizo\Bundle\CoreBundle\Repository\UserRepository")
  35.  * @UniqueEntity(fields={"email"}, message="There is already an account with this email")
  36.  */
  37. class User extends AbstractJson implements UserInterfaceEquatableInterfacePasswordAuthenticatedUserInterface
  38. {
  39.     const DEFAULT_GRVATAR_URL 'https://www.gravatar.com/avatar';
  40.     /**
  41.      * @ORM\Id()
  42.      * @ORM\GeneratedValue()
  43.      * @ORM\Column(type="integer")
  44.      */
  45.     private ?int $id null;
  46.     /**
  47.      * @ORM\Column(type="string", length=180, unique=true)
  48.      * @Assert\Email(message = "Please enter a valid email address.")
  49.      * @Assert\NotBlank
  50.      */
  51.     private string $email;
  52.     /**
  53.      * @var Collection|Role[]
  54.      * @ORM\ManyToMany(targetEntity="Role", inversedBy="users", cascade={"persist"})
  55.      * @ORM\JoinTable(
  56.      *     name="user_roles",
  57.      *     joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
  58.      *     inverseJoinColumns={@ORM\JoinColumn(name="role_id", referencedColumnName="id")}
  59.      * )
  60.      */
  61.     private Collection $roles;
  62.     /**
  63.      * @var string The hashed password
  64.      * @ORM\Column(type="string")
  65.      */
  66.     private string $password;
  67.     /**
  68.      * @ORM\Column(type="string", length=50)
  69.      */
  70.     private ?string $nicename null;
  71.     /**
  72.      * @ORM\Column(type="string", length=100, nullable=true)
  73.      */
  74.     private ?string $url null;
  75.     /**
  76.      * @ORM\Column(type="boolean", options={"default": false})
  77.      */
  78.     private bool $active false;
  79.     /**
  80.      * @Gedmo\Timestampable(on="create")
  81.      * @ORM\Column(type="datetime")
  82.      */
  83.     private DateTimeInterface $registered;
  84.     /**
  85.      * @Gedmo\Timestampable(on="update")
  86.      * @ORM\Column(type="datetime")
  87.      */
  88.     private DateTimeInterface $updatedAt;
  89.     /**
  90.      * @ORM\Column(type="string", length=255, nullable=true)
  91.      */
  92.     private ?string $confirmationToken null;
  93.     /**
  94.      * @ORM\Column(type="datetime", nullable=true)
  95.      */
  96.     private ?DateTime $passwordRequestedAt null;
  97.     /**
  98.      * @ORM\Column(type="integer", nullable=true)
  99.      */
  100.     private ?int $status null;
  101.     /**
  102.      * @ORM\Column(type="string", length=250)
  103.      */
  104.     private ?string $displayName null;
  105.     /**
  106.      * User's prefix.
  107.      *
  108.      * @ORM\Column(type="string", nullable=true)
  109.      */
  110.     private ?string $prefix null;
  111.     /**
  112.      * Customer's firstname.
  113.      *
  114.      * @ORM\Column(type="string")
  115.      */
  116.     private string $firstname;
  117.     /**
  118.      * Customer's middlename.
  119.      *
  120.      * @ORM\Column(type="string", nullable=true)
  121.      */
  122.     private ?string $middlename null;
  123.     /**
  124.      * Customer's lastname.
  125.      *
  126.      * @ORM\Column(type="string")
  127.      */
  128.     private string $lastname;
  129.     /**
  130.      * customer's suffix.
  131.      *
  132.      * @ORM\Column(type="string", nullable=true)
  133.      */
  134.     private ?string $suffix null;
  135.     /**
  136.      * Customer's DOB.
  137.      *
  138.      * @ORM\Column(type="datetime", nullable=true, nullable=true)
  139.      */
  140.     private ?DateTimeInterface $dob null;
  141.     /**
  142.      * Default Billing Address.
  143.      *
  144.      * @ORM\OneToOne(targetEntity="Kobizo\Bundle\ECommerceBundle\Entity\CustomerAddress", inversedBy="billingCustomer", cascade={"persist"})
  145.      * @ORM\JoinColumn(nullable=true)
  146.      */
  147.     private ?CustomerAddress $billingAddress null;
  148.     /**
  149.      * Default Billing Address.
  150.      *
  151.      * @ORM\OneToOne(targetEntity="Kobizo\Bundle\ECommerceBundle\Entity\CustomerAddress", inversedBy="shippingCustomer", cascade={"persist"})
  152.      * @ORM\JoinColumn(nullable=true)
  153.      */
  154.     private ?CustomerAddress $shippingAddress null;
  155.     /**
  156.      * User budget.
  157.      *
  158.      * @ORM\OneToOne(targetEntity="Kobizo\Bundle\ECommerceBundle\Entity\Budget", mappedBy="user")
  159.      * @ORM\JoinColumn(nullable=true)
  160.      */
  161.     private ?Budget $budget null;
  162.     /**
  163.      * Customer Group.
  164.      *
  165.      * @ORM\ManyToOne(targetEntity="Kobizo\Bundle\ECommerceBundle\Entity\CustomerGroup", inversedBy="customers")
  166.      * @ORM\JoinColumn(nullable=true)
  167.      */
  168.     private ?CustomerGroup $customerGroup null;
  169.     /**
  170.      * Gender, see GenderType.php.
  171.      *
  172.      * @ORM\Column(type="string", nullable=true)
  173.      */
  174.     private ?string $gender null;
  175.     /**
  176.      * Rating of current user to define which Option(s) customers can vote.
  177.      *
  178.      * @ORM\ManyToOne(targetEntity="Kobizo\Bundle\ECommerceBundle\Entity\Rating", inversedBy="users")
  179.      * @ORM\JoinColumn(nullable=true)
  180.      */
  181.     private ?Rating $rating;
  182.     /**
  183.      * User rating value. Calculated based on $value of ReviewVotes.
  184.      *
  185.      * @ORM\Column(type="decimal", precision=5, scale=2, nullable=true)
  186.      */
  187.     private ?float $ratingValue null;
  188.     /**
  189.      * Define which table user(ROLE_WORKER) is serving.
  190.      *
  191.      * @ORM\OneToOne(targetEntity="Kobizo\Bundle\ECommerceBundle\Entity\Table", mappedBy="user", cascade={"persist"})
  192.      * @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
  193.      */
  194.     private ?Table $table null;
  195.     /**
  196.      * customer's quotes.
  197.      *
  198.      * @ORM\OneToMany(targetEntity="Kobizo\Bundle\ECommerceBundle\Entity\Quote", mappedBy="customer")
  199.      */
  200.     private Collection $quotes;
  201.     /**
  202.      * customer's orders.
  203.      *
  204.      * @ORM\OneToMany(targetEntity="Kobizo\Bundle\ECommerceBundle\Entity\Order", mappedBy="customer")
  205.      */
  206.     private Collection $orders;
  207.     /**
  208.      * customer's quote addresses.
  209.      *
  210.      * @ORM\OneToMany(targetEntity="Kobizo\Bundle\ECommerceBundle\Entity\QuoteAddress", mappedBy="customer")
  211.      */
  212.     private Collection $quoteAddresses;
  213.     /**
  214.      * customer's quote addresses.
  215.      *
  216.      * @ORM\OneToMany(targetEntity="Kobizo\Bundle\ECommerceBundle\Entity\OrderAddress", mappedBy="customer")
  217.      */
  218.     private Collection $orderAddresses;
  219.     /**
  220.      * customer's addresses.
  221.      *
  222.      * @ORM\OneToMany(targetEntity="Kobizo\Bundle\ECommerceBundle\Entity\CustomerAddress", mappedBy="customer", orphanRemoval=true, cascade={"persist"})
  223.      */
  224.     private Collection $addresses;
  225.     /**
  226.      * @ORM\OneToMany(targetEntity="Usermeta", mappedBy="user", orphanRemoval=true, cascade={"persist"})
  227.      */
  228.     private Collection $usermetas;
  229.     /**
  230.      * @ORM\OneToMany(targetEntity="Post", mappedBy="author", orphanRemoval=true, cascade={"persist"})
  231.      */
  232.     private Collection $posts;
  233.     /**
  234.      * @ORM\OneToMany(targetEntity="Page", mappedBy="author", orphanRemoval=true, cascade={"persist"})
  235.      */
  236.     private Collection $pages;
  237.     /**
  238.      * @ORM\OneToMany(targetEntity="Menu", mappedBy="author", orphanRemoval=true, cascade={"persist"})
  239.      */
  240.     private Collection $menus;
  241.     /**
  242.      * @ORM\OneToMany(targetEntity="Attachment", mappedBy="author", orphanRemoval=true, cascade={"persist"})
  243.      */
  244.     private Collection $attachments;
  245.     /**
  246.      * @ORM\OneToMany(targetEntity="Kobizo\Bundle\ECommerceBundle\Entity\Wishlist", mappedBy="customer", orphanRemoval=true)
  247.      */
  248.     private Collection $wishlists;
  249.     /**
  250.      * Reviews created by User.
  251.      *
  252.      * @ORM\OneToMany(targetEntity="Kobizo\Bundle\ECommerceBundle\Entity\Review", mappedBy="customer", orphanRemoval=true)
  253.      */
  254.     private Collection $reviewsByUser;
  255.     /**
  256.      * Reviews for the user.
  257.      *
  258.      *  @var Review[]
  259.      */
  260.     private array $reviews = [];
  261.     /**
  262.      * @ORM\Column(type="string", nullable=true)
  263.      */
  264.     private ?string $avatar null;
  265.     /**
  266.      * @ORM\OneToMany(targetEntity="Kobizo\Bundle\ECommerceBundle\Entity\Store", mappedBy="presenter")
  267.      */
  268.     private Collection $stores;
  269.     /**
  270.      * @ORM\OneToMany(targetEntity="Kobizo\Bundle\ECommerceBundle\Entity\FavoStore", mappedBy="customer")
  271.      */
  272.     private Collection $favoStores;
  273.     /**
  274.      * @ORM\OneToMany(targetEntity="Kobizo\Bundle\ECommerceBundle\Entity\ViewedProduct", mappedBy="customer")
  275.      * @ORM\OrderBy({"addedAt" = "DESC"})
  276.      */
  277.     private Collection $viewedProducts;
  278.     /**
  279.      * Reservations by user.
  280.      *
  281.      * @ORM\OneToMany(targetEntity="Kobizo\Bundle\ECommerceBundle\Entity\Reservation", mappedBy="user", cascade={"persist"}, orphanRemoval=true)
  282.      */
  283.     private Collection $reservations;
  284.     public function __construct()
  285.     {
  286.         $this->quotes = new ArrayCollection();
  287.         $this->orders = new ArrayCollection();
  288.         $this->quoteAddresses = new ArrayCollection();
  289.         $this->orderAddresses = new ArrayCollection();
  290.         $this->addresses = new ArrayCollection();
  291.         $this->usermetas = new ArrayCollection();
  292.         $this->posts = new ArrayCollection();
  293.         $this->pages = new ArrayCollection();
  294.         $this->menus = new ArrayCollection();
  295.         $this->attachments = new ArrayCollection();
  296.         $this->stores = new ArrayCollection();
  297.         $this->roles = new ArrayCollection();
  298.         $this->wishlists = new ArrayCollection();
  299.         $this->viewedProducts = new ArrayCollection();
  300.         $this->favoStores = new ArrayCollection();
  301.         $this->reviewsByUser = new ArrayCollection();
  302.         $this->reservations = new ArrayCollection();
  303.     }
  304.     public function getId(): ?int
  305.     {
  306.         return $this->id;
  307.     }
  308.     public function getEmail(): ?string
  309.     {
  310.         return $this->email;
  311.     }
  312.     /**
  313.      * The public representation of the user (e.g. a username, an email address, etc.).
  314.      *
  315.      * @see UserInterface
  316.      */
  317.     public function getUserIdentifier(): string
  318.     {
  319.         return $this->email;
  320.     }
  321.     public function setEmail(string $email): self
  322.     {
  323.         $this->email $email;
  324.         return $this;
  325.     }
  326.     public function isActive(): bool
  327.     {
  328.         return $this->active;
  329.     }
  330.     public function setActive(bool $active): void
  331.     {
  332.         $this->active $active;
  333.     }
  334.     public function getRating(): ?Rating
  335.     {
  336.         return $this->rating;
  337.     }
  338.     public function setRating(?Rating $rating): self
  339.     {
  340.         $this->rating $rating;
  341.         return $this;
  342.     }
  343.     public function getRatingValue(): ?float
  344.     {
  345.         return $this->ratingValue;
  346.     }
  347.     public function setRatingValue(?float $ratingValue): self
  348.     {
  349.         $this->ratingValue $ratingValue;
  350.         return $this;
  351.     }
  352.     /**
  353.      * A visual identifier that represents this user.
  354.      *
  355.      * @see UserInterface
  356.      */
  357.     public function getUsername(): string
  358.     {
  359.         return $this->email;
  360.     }
  361.     /**
  362.      * This cannot be array of Role, otherwise we will get issue with logging in.
  363.      *
  364.      * @see UserInterface
  365.      *
  366.      * @return string[]
  367.      */
  368.     public function getRoles(): array
  369.     {
  370.         $roles = [];
  371.         /** @var Role $role */
  372.         foreach ($this->roles->toArray() as $role) {
  373.             $roles[] = $role->getCode();
  374.         }
  375.         return array_unique($roles);
  376.     }
  377.     public function setRoles(Collection $roles): self
  378.     {
  379.         $this->roles $roles;
  380.         return $this;
  381.     }
  382.     /**
  383.      * Unlike result of getRole() or input of removeRole(), the input variable $role of addRole() function is Role object.
  384.      *
  385.      * @return $this
  386.      */
  387.     public function addRole(Role $role): self
  388.     {
  389.         $this->roles->add($role);
  390.         return $this;
  391.     }
  392.     /**
  393.      * By default, Role in symfony should be a string but not object, but we still want to use this function for Role
  394.      * object, so we need to add is_string() here to get appropriate Role object to remove in case $role is string
  395.      * by default.
  396.      *
  397.      * @param string|Role $role
  398.      *
  399.      * @return $this
  400.      */
  401.     public function removeRole($role): self
  402.     {
  403.         if (is_string($role)) {
  404.             $role $this->roles->filter(function (Role $roleItem) use ($role) {
  405.                 return $roleItem->getCode() === $role;
  406.             })->first();
  407.         }
  408.         $this->roles->removeElement($role);
  409.         return $this;
  410.     }
  411.     public function getRole(): Role
  412.     {
  413.         return $this->roles->first();
  414.     }
  415.     /**
  416.      * Check if current user has a role.
  417.      */
  418.     public function hasRole(string $roleCode): bool
  419.     {
  420.         return in_array($roleCode$this->getRoles());
  421.     }
  422.     /**
  423.      * Check if current user is super admin.
  424.      */
  425.     public function isSuperAdmin(): bool
  426.     {
  427.         return $this->hasRole(DefaultRolesAttribute::SUPER_ADMINISTRATOR);
  428.     }
  429.     /**
  430.      * Check if current user is admin (it super admin is also admin).
  431.      */
  432.     public function isAdmin(): bool
  433.     {
  434.         $roleCodes $this->getRoles();
  435.         return in_array(DefaultRolesAttribute::SUPER_ADMINISTRATOR$roleCodes)
  436.             || in_array(DefaultRolesAttribute::ADMINISTRATOR$roleCodes);
  437.     }
  438.     /**
  439.      * @return string[]
  440.      */
  441.     public function getResources(): array
  442.     {
  443.         $resources = [];
  444.         foreach ($this->roles as $role) {
  445.             $resources += $role->getResources() + [$role->getCode()];
  446.         }
  447.         return array_unique($resources);
  448.     }
  449.     /**
  450.      * @see UserInterface
  451.      */
  452.     public function getPassword(): string
  453.     {
  454.         return (string) $this->password;
  455.     }
  456.     public function setPassword(string $password): self
  457.     {
  458.         if (!empty($password)) {
  459.             $this->password $password;
  460.         }
  461.         return $this;
  462.     }
  463.     public function getConfirmationToken(): ?string
  464.     {
  465.         return $this->confirmationToken;
  466.     }
  467.     /**
  468.      * @return $this
  469.      */
  470.     public function setConfirmationToken(?string $confirmationToken): self
  471.     {
  472.         $this->confirmationToken $confirmationToken;
  473.         return $this;
  474.     }
  475.     public function getPasswordRequestedAt(): ?DateTime
  476.     {
  477.         return $this->passwordRequestedAt;
  478.     }
  479.     /**
  480.      * @return $this
  481.      */
  482.     public function setPasswordRequestedAt(?DateTime $passwordRequestedAt): self
  483.     {
  484.         $this->passwordRequestedAt $passwordRequestedAt;
  485.         return $this;
  486.     }
  487.     /**
  488.      * @return bool
  489.      */
  490.     public function isPasswordRequestNoneExpired(int $ttl 0)
  491.     {
  492.         return $this->passwordRequestedAt instanceof DateTime && $this->passwordRequestedAt->getTimestamp() + $ttl time();
  493.     }
  494.     public function getNicename(): ?string
  495.     {
  496.         return $this->nicename;
  497.     }
  498.     public function setNicename(?string $nicename): self
  499.     {
  500.         $this->nicename $nicename;
  501.         return $this;
  502.     }
  503.     public function getUrl(): ?string
  504.     {
  505.         return $this->url;
  506.     }
  507.     public function setUrl(?string $url): self
  508.     {
  509.         $this->url $url;
  510.         return $this;
  511.     }
  512.     public function getRegistered(): ?DateTimeInterface
  513.     {
  514.         return $this->registered;
  515.     }
  516.     public function getStatus(): ?int
  517.     {
  518.         return $this->status;
  519.     }
  520.     public function setStatus(?int $status): self
  521.     {
  522.         $this->status $status;
  523.         return $this;
  524.     }
  525.     public function getDisplayName(): ?string
  526.     {
  527.         return $this->displayName;
  528.     }
  529.     public function setDisplayName(?string $displayName): self
  530.     {
  531.         $this->displayName $displayName;
  532.         return $this;
  533.     }
  534.     public function getPrefix(): ?string
  535.     {
  536.         return $this->prefix;
  537.     }
  538.     public function setPrefix(?string $prefix): self
  539.     {
  540.         $this->prefix $prefix;
  541.         return $this;
  542.     }
  543.     public function getFirstname(): ?string
  544.     {
  545.         return $this->firstname;
  546.     }
  547.     public function setFirstname(string $firstname): self
  548.     {
  549.         $this->firstname $firstname;
  550.         return $this;
  551.     }
  552.     public function getMiddlename(): ?string
  553.     {
  554.         return $this->middlename;
  555.     }
  556.     public function setMiddlename(?string $middlename): self
  557.     {
  558.         $this->middlename $middlename;
  559.         return $this;
  560.     }
  561.     public function getLastname(): ?string
  562.     {
  563.         return $this->lastname;
  564.     }
  565.     public function setLastname(string $lastname): self
  566.     {
  567.         $this->lastname $lastname;
  568.         return $this;
  569.     }
  570.     public function getSuffix(): ?string
  571.     {
  572.         return $this->suffix;
  573.     }
  574.     public function setSuffix(?string $suffix): self
  575.     {
  576.         $this->suffix $suffix;
  577.         return $this;
  578.     }
  579.     public function getDob(): ?DateTimeInterface
  580.     {
  581.         return $this->dob;
  582.     }
  583.     public function setDob(?DateTimeInterface $dob): self
  584.     {
  585.         $this->dob $dob;
  586.         return $this;
  587.     }
  588.     public function getBillingAddress(): ?CustomerAddress
  589.     {
  590.         return $this->billingAddress;
  591.     }
  592.     public function setBillingAddress(?CustomerAddress $customerAddress): self
  593.     {
  594.         $this->billingAddress $customerAddress;
  595.         return $this;
  596.     }
  597.     public function getShippingAddress(): ?CustomerAddress
  598.     {
  599.         return $this->shippingAddress;
  600.     }
  601.     public function setShippingAddress(?CustomerAddress $customerAddress): self
  602.     {
  603.         $this->shippingAddress $customerAddress;
  604.         return $this;
  605.     }
  606.     public function getCustomerGroup(): ?CustomerGroup
  607.     {
  608.         return $this->customerGroup;
  609.     }
  610.     public function setCustomerGroup(?CustomerGroup $customerGroup): self
  611.     {
  612.         $this->customerGroup $customerGroup;
  613.         return $this;
  614.     }
  615.     public function getGender(): ?string
  616.     {
  617.         return $this->gender;
  618.     }
  619.     public function setGender(?string $gender): self
  620.     {
  621.         $this->gender $gender;
  622.         return $this;
  623.     }
  624.     /**
  625.      * @return Collection|Quote[]
  626.      */
  627.     public function getQuotes(): Collection
  628.     {
  629.         return $this->quotes;
  630.     }
  631.     public function addQuote(Quote $quote): self
  632.     {
  633.         if (!$this->quotes->contains($quote)) {
  634.             $this->quotes[] = $quote;
  635.             $quote->setCustomer($this);
  636.         }
  637.         return $this;
  638.     }
  639.     public function removeQuote(Quote $quote): self
  640.     {
  641.         if ($this->quotes->contains($quote)) {
  642.             $this->quotes->removeElement($quote);
  643.             // set the owning side to null (unless already changed)
  644.             if ($quote->getCustomer() === $this) {
  645.                 $quote->setCustomer(null);
  646.             }
  647.         }
  648.         return $this;
  649.     }
  650.     /**
  651.      * Get the last quote of current customer regarding Store [and Table].
  652.      */
  653.     public function getLastQuote(Store $store, ?Table $table null): ?Quote
  654.     {
  655.         $quotes $this->quotes->filter(function (Quote $quote) use ($store$table) {
  656.             return $quote->getStore() === $store
  657.                 && is_null($quote->getConvertedAt())
  658.                 && (is_null($table)
  659.                     ? is_null($quote->getTable())
  660.                     : !is_null($quote->getTable()) && $quote->getTable() === $table
  661.                 );
  662.         });
  663.         $lastQuote null;
  664.         foreach ($quotes as $quote) {
  665.             if (!$lastQuote) {
  666.                 $lastQuote $quote;
  667.             } else {
  668.                 if ($lastQuote->getId() < $quote->getId()) {
  669.                     $lastQuote $quote;
  670.                 }
  671.             }
  672.         }
  673.         return $lastQuote;
  674.     }
  675.     /**
  676.      * @return Collection|Order[]
  677.      */
  678.     public function getOrders(): Collection
  679.     {
  680.         return $this->orders;
  681.     }
  682.     public function addOrder(Order $order): self
  683.     {
  684.         if (!$this->orders->contains($order)) {
  685.             $this->orders[] = $order;
  686.             $order->setCustomer($this);
  687.         }
  688.         return $this;
  689.     }
  690.     public function removeOrder(Order $order): self
  691.     {
  692.         if ($this->orders->contains($order)) {
  693.             $this->orders->removeElement($order);
  694.             // set the owning side to null (unless already changed)
  695.             if ($order->getCustomer() === $this) {
  696.                 $order->setCustomer(null);
  697.             }
  698.         }
  699.         return $this;
  700.     }
  701.     /**
  702.      * @return Collection|QuoteAddress[]
  703.      */
  704.     public function getQuoteAddresses(): Collection
  705.     {
  706.         return $this->quoteAddresses;
  707.     }
  708.     public function addQuoteAddress(QuoteAddress $quoteAddress): self
  709.     {
  710.         if (!$this->quoteAddresses->contains($quoteAddress)) {
  711.             $this->quoteAddresses[] = $quoteAddress;
  712.             $quoteAddress->setCustomer($this);
  713.         }
  714.         return $this;
  715.     }
  716.     public function removeQuoteAddress(QuoteAddress $quoteAddress): self
  717.     {
  718.         if ($this->quoteAddresses->contains($quoteAddress)) {
  719.             $this->quoteAddresses->removeElement($quoteAddress);
  720.             // set the owning side to null (unless already changed)
  721.             if ($quoteAddress->getCustomer() === $this) {
  722.                 $quoteAddress->setCustomer(null);
  723.             }
  724.         }
  725.         return $this;
  726.     }
  727.     /**
  728.      * @return Collection|OrderAddress[]
  729.      */
  730.     public function getOrderAddresses(): Collection
  731.     {
  732.         return $this->orderAddresses;
  733.     }
  734.     public function addOrderAddress(OrderAddress $orderAddress): self
  735.     {
  736.         if (!$this->orderAddresses->contains($orderAddress)) {
  737.             $this->orderAddresses[] = $orderAddress;
  738.             $orderAddress->setCustomer($this);
  739.         }
  740.         return $this;
  741.     }
  742.     public function removeOrderAddress(OrderAddress $orderAddress): self
  743.     {
  744.         if ($this->orderAddresses->contains($orderAddress)) {
  745.             $this->orderAddresses->removeElement($orderAddress);
  746.             // set the owning side to null (unless already changed)
  747.             if ($orderAddress->getCustomer() === $this) {
  748.                 $orderAddress->setCustomer(null);
  749.             }
  750.         }
  751.         return $this;
  752.     }
  753.     /**
  754.      * @return Collection|CustomerAddress[]
  755.      */
  756.     public function getAddresses(): Collection
  757.     {
  758.         return $this->addresses;
  759.     }
  760.     public function addAddress(CustomerAddress $customerAddress): self
  761.     {
  762.         if (!$this->addresses->contains($customerAddress)) {
  763.             $this->addresses[] = $customerAddress;
  764.             $customerAddress->setCustomer($this);
  765.         }
  766.         return $this;
  767.     }
  768.     public function removeAddress(CustomerAddress $customerAddress): self
  769.     {
  770.         if ($this->addresses->contains($customerAddress)) {
  771.             $this->addresses->removeElement($customerAddress);
  772.         }
  773.         return $this;
  774.     }
  775.     /**
  776.      * @return Collection|Usermeta[]
  777.      */
  778.     public function getUsermetas(): Collection
  779.     {
  780.         return $this->usermetas;
  781.     }
  782.     public function addUsermeta(Usermeta $usermeta): self
  783.     {
  784.         if (!$this->usermetas->contains($usermeta)) {
  785.             $this->usermetas[] = $usermeta;
  786.             $usermeta->setUser($this);
  787.         }
  788.         return $this;
  789.     }
  790.     public function removeUsermeta(Usermeta $usermeta): self
  791.     {
  792.         if ($this->usermetas->contains($usermeta)) {
  793.             $this->usermetas->removeElement($usermeta);
  794.         }
  795.         return $this;
  796.     }
  797.     public function getMetaValue(string $key): ?string
  798.     {
  799.         $metas $this->usermetas->filter(function (Usermeta $usermeta) use ($key) {
  800.             return $usermeta->getKey() === $key;
  801.         });
  802.         /** @var Usermeta $meta */
  803.         $meta $metas->first();
  804.         return $meta $meta->getValue() : null;
  805.     }
  806.     /**
  807.      * @return Collection|Post[]
  808.      */
  809.     public function getPosts(): Collection
  810.     {
  811.         return $this->posts;
  812.     }
  813.     public function getNumberOfPosts(): int
  814.     {
  815.         return $this->posts->count();
  816.     }
  817.     public function getLatestPosts(): ArrayCollection
  818.     {
  819.         $criteria Criteria::create();
  820.         $criteria->setMaxResults(10);
  821.         return $this->posts->matching($criteria);
  822.     }
  823.     public function addPost(Post $post): self
  824.     {
  825.         if (!$this->posts->contains($post)) {
  826.             $this->posts[] = $post;
  827.             $post->setAuthor($this);
  828.         }
  829.         return $this;
  830.     }
  831.     public function removePost(Post $post): self
  832.     {
  833.         if ($this->posts->contains($post)) {
  834.             $this->posts->removeElement($post);
  835.         }
  836.         return $this;
  837.     }
  838.     /**
  839.      * @return Collection|Page[]
  840.      */
  841.     public function getPages(): Collection
  842.     {
  843.         return $this->pages;
  844.     }
  845.     public function addPage(Page $page): self
  846.     {
  847.         if (!$this->pages->contains($page)) {
  848.             $this->pages[] = $page;
  849.             $page->setAuthor($this);
  850.         }
  851.         return $this;
  852.     }
  853.     public function removePage(Page $page): self
  854.     {
  855.         if ($this->pages->contains($page)) {
  856.             $this->pages->removeElement($page);
  857.         }
  858.         return $this;
  859.     }
  860.     /**
  861.      * @return Collection|Menu[]
  862.      */
  863.     public function getMenus(): Collection
  864.     {
  865.         return $this->menus;
  866.     }
  867.     public function addMenu(Menu $menu): self
  868.     {
  869.         if (!$this->menus->contains($menu)) {
  870.             $this->menus[] = $menu;
  871.             $menu->setAuthor($this);
  872.         }
  873.         return $this;
  874.     }
  875.     public function removeMenu(Menu $menu): self
  876.     {
  877.         if ($this->menus->contains($menu)) {
  878.             $this->menus->removeElement($menu);
  879.         }
  880.         return $this;
  881.     }
  882.     /**
  883.      * @return Collection|Attachment[]
  884.      */
  885.     public function getAttachments(): Collection
  886.     {
  887.         return $this->attachments;
  888.     }
  889.     public function addAttachment(Attachment $attachment): self
  890.     {
  891.         if (!$this->attachments->contains($attachment)) {
  892.             $this->attachments[] = $attachment;
  893.             $attachment->setAuthor($this);
  894.         }
  895.         return $this;
  896.     }
  897.     public function removeAttachment(Attachment $attachment): self
  898.     {
  899.         if ($this->attachments->contains($attachment)) {
  900.             $this->attachments->removeElement($attachment);
  901.         }
  902.         return $this;
  903.     }
  904.     /**
  905.      * @return Collection|Store[]
  906.      */
  907.     public function getStores(): Collection
  908.     {
  909.         return $this->stores;
  910.     }
  911.     public function addStore(Store $store): self
  912.     {
  913.         if (!$this->stores->contains($store)) {
  914.             $this->stores[] = $store;
  915.             $store->setPresenter($this);
  916.         }
  917.         return $this;
  918.     }
  919.     public function removeStore(Store $store): self
  920.     {
  921.         if ($this->stores->contains($store)) {
  922.             $this->stores->removeElement($store);
  923.             // set the owning side to null (unless already changed)
  924.             if ($store->getPresenter() === $this) {
  925.                 $store->setPresenter(null);
  926.             }
  927.         }
  928.         return $this;
  929.     }
  930.     /**
  931.      * @see UserInterface
  932.      *
  933.      * @return string|null
  934.      */
  935.     public function getSalt()
  936.     {
  937.         // not needed when using the "bcrypt" algorithm in security.yaml
  938.     }
  939.     /**
  940.      * @see UserInterface
  941.      */
  942.     public function eraseCredentials()
  943.     {
  944.         // If you store any temporary, sensitive data on the user, clear it here
  945.         // $this->plainPassword = null;
  946.     }
  947.     public function isEqualTo(UserInterface $user): bool
  948.     {
  949.         if ($this->password !== $user->getPassword()) {
  950.             return false;
  951.         }
  952.         if ($this->email !== $user->getUserIdentifier()) {
  953.             return false;
  954.         }
  955.         return true;
  956.     }
  957.     /**
  958.      * @return Collection|Wishlist[]
  959.      */
  960.     public function getWishlists(): Collection
  961.     {
  962.         return $this->wishlists;
  963.     }
  964.     public function addWishlist(Wishlist $wishlist): self
  965.     {
  966.         if (!$this->wishlists->contains($wishlist)) {
  967.             $this->wishlists[] = $wishlist;
  968.             $wishlist->setCustomer($this);
  969.         }
  970.         return $this;
  971.     }
  972.     public function removeWishlist(Wishlist $wishlist): self
  973.     {
  974.         if ($this->wishlists->contains($wishlist)) {
  975.             $this->wishlists->removeElement($wishlist);
  976.             // set the owning side to null (unless already changed)
  977.             if ($wishlist->getCustomer() === $this) {
  978.                 $wishlist->setCustomer(null);
  979.             }
  980.         }
  981.         return $this;
  982.     }
  983.     /**
  984.      * @return Collection|Review[]
  985.      */
  986.     public function getReviewsByUser(): Collection
  987.     {
  988.         return $this->reviewsByUser;
  989.     }
  990.     public function addReviewsByUser(Review $review): self
  991.     {
  992.         if (!$this->reviewsByUser->contains($review)) {
  993.             $this->reviewsByUser[] = $review;
  994.             $review->setCustomer($this);
  995.         }
  996.         return $this;
  997.     }
  998.     public function removeReviewsByUser(Review $review): self
  999.     {
  1000.         if ($this->wishlists->contains($review)) {
  1001.             $this->wishlists->removeElement($review);
  1002.             if ($review->getCustomer() === $this) {
  1003.                 $review->setCustomer(null);
  1004.             }
  1005.         }
  1006.         return $this;
  1007.     }
  1008.     /**
  1009.      * @return Collection|FavoStore[]
  1010.      */
  1011.     public function getFavoStores(): Collection
  1012.     {
  1013.         return $this->favoStores;
  1014.     }
  1015.     public function addFavoStore(FavoStore $favouriteStore): self
  1016.     {
  1017.         if (!$this->favoStores->contains($favouriteStore)) {
  1018.             $this->favoStores[] = $favouriteStore;
  1019.             $favouriteStore->setCustomer($this);
  1020.         }
  1021.         return $this;
  1022.     }
  1023.     public function removeFavoStore(FavoStore $favouriteStore): self
  1024.     {
  1025.         if ($this->favoStores->contains($favouriteStore)) {
  1026.             $this->favoStores->removeElement($favouriteStore);
  1027.         }
  1028.         return $this;
  1029.     }
  1030.     /**
  1031.      * @return Review[]
  1032.      */
  1033.     public function getReviews(): array
  1034.     {
  1035.         return $this->reviews;
  1036.     }
  1037.     public function addReview(Review $review): self
  1038.     {
  1039.         if (!in_array($review$this->reviewstrue)) {
  1040.             $this->reviews[] = $review;
  1041.             $review->setObjectId($this->getId());
  1042.         }
  1043.         return $this;
  1044.     }
  1045.     public function removeReview(Review $review): self
  1046.     {
  1047.         if (in_array($review$this->reviewstrue)) {
  1048.             $this->reviews array_filter($this->reviews, static function (Review $existedReview) use ($review) {
  1049.                 return $existedReview->getId() !== $review->getId();
  1050.             });
  1051.             if ($review->getObjectId() === $this->getId()) {
  1052.                 $review->setObjectId(null);
  1053.             }
  1054.         }
  1055.         return $this;
  1056.     }
  1057.     public function getAvatar(): ?string
  1058.     {
  1059.         return $this->avatar ?: self::DEFAULT_GRVATAR_URL;
  1060.     }
  1061.     public function setAvatar(?string $avatar): self
  1062.     {
  1063.         $this->avatar $avatar;
  1064.         return $this;
  1065.     }
  1066.     /**
  1067.      * @return Collection|ViewedProduct[]
  1068.      */
  1069.     public function getViewedProducts(): Collection
  1070.     {
  1071.         return $this->viewedProducts;
  1072.     }
  1073.     public function addViewedProduct(ViewedProduct $viewedProduct): self
  1074.     {
  1075.         if (!$this->viewedProducts->contains($viewedProduct)) {
  1076.             $this->viewedProducts->add($viewedProduct);
  1077.             $viewedProduct->setCustomer($this);
  1078.         }
  1079.         return $this;
  1080.     }
  1081.     public function removeViewedProduct(ViewedProduct $viewedProduct): self
  1082.     {
  1083.         if ($this->viewedProducts->contains($viewedProduct)) {
  1084.             $this->viewedProducts->removeElement($viewedProduct);
  1085.             // set the owning side to null (unless already changed)
  1086.             if ($viewedProduct->getCustomer() === $this) {
  1087.                 $viewedProduct->setCustomer(null);
  1088.             }
  1089.         }
  1090.         return $this;
  1091.     }
  1092.     public function __toString(): string
  1093.     {
  1094.         return sprintf('[%d] %s - %s'$this->getId(), $this->getEmail(), $this->getDisplayName() ?? 'EMPTY');
  1095.     }
  1096.     public function getUpdatedAt(): ?DateTimeInterface
  1097.     {
  1098.         return $this->updatedAt;
  1099.     }
  1100.     public function getBudget(): ?Budget
  1101.     {
  1102.         return $this->budget;
  1103.     }
  1104.     public function setBudget(?Budget $budget): self
  1105.     {
  1106.         $this->budget $budget;
  1107.         return $this;
  1108.     }
  1109.     /**
  1110.      * @return Collection|Reservation[]
  1111.      */
  1112.     public function getReservations(): Collection
  1113.     {
  1114.         return $this->reservations;
  1115.     }
  1116.     public function addReservation(Reservation $reservation): self
  1117.     {
  1118.         if (!$this->reservations->contains($reservation)) {
  1119.             $this->reservations[] = $reservation;
  1120.             $reservation->setUser($this);
  1121.         }
  1122.         return $this;
  1123.     }
  1124.     public function removeReservation(Reservation $reservation): self
  1125.     {
  1126.         if ($this->reservations->contains($reservation)) {
  1127.             $this->reservations->removeElement($reservation);
  1128.             if ($reservation->getUser() === $this) {
  1129.                 $reservation->setUser(null);
  1130.             }
  1131.         }
  1132.         return $this;
  1133.     }
  1134.     public function getTable(): ?Table
  1135.     {
  1136.         return $this->table;
  1137.     }
  1138.     public function setTable(?Table $table): self
  1139.     {
  1140.         $this->table $table;
  1141.         return $this;
  1142.     }
  1143.     public function removeTimeSetting(ReservationTimeSetting $timeSetting): self
  1144.     {
  1145.         if ($this->timeSettings->contains($timeSetting)) {
  1146.             $this->timeSettings->removeElement($timeSetting);
  1147.         }
  1148.         return $this;
  1149.     }
  1150. }