<?php
namespace Kobizo\Component\Entity;
use DateTime as DateTime;
use DateTimeInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Kobizo\Bundle\ECommerceBundle\Entity\Budget;
use Kobizo\Bundle\ECommerceBundle\Entity\CustomerAddress;
use Kobizo\Bundle\ECommerceBundle\Entity\CustomerGroup;
use Kobizo\Bundle\ECommerceBundle\Entity\FavoStore;
use Kobizo\Bundle\ECommerceBundle\Entity\Order;
use Kobizo\Bundle\ECommerceBundle\Entity\OrderAddress;
use Kobizo\Bundle\ECommerceBundle\Entity\Quote;
use Kobizo\Bundle\ECommerceBundle\Entity\QuoteAddress;
use Kobizo\Bundle\ECommerceBundle\Entity\Rating;
use Kobizo\Bundle\ECommerceBundle\Entity\Review;
use Kobizo\Bundle\ECommerceBundle\Entity\Store;
use Kobizo\Bundle\ECommerceBundle\Entity\Table;
use Kobizo\Bundle\ECommerceBundle\Entity\ViewedProduct;
use Kobizo\Bundle\ECommerceBundle\Entity\Wishlist;
use Kobizo\Component\Attributes\DefaultRolesAttribute;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\EquatableInterface;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Constraints as Assert;
use Kobizo\Bundle\ECommerceBundle\Entity\Reservation;
use Kobizo\Bundle\ECommerceBundle\Entity\ReservationTimeSetting;
/**
* @ORM\Table(name="`user`")
* @ORM\Entity(repositoryClass="Kobizo\Bundle\CoreBundle\Repository\UserRepository")
* @UniqueEntity(fields={"email"}, message="There is already an account with this email")
*/
class User extends AbstractJson implements UserInterface, EquatableInterface, PasswordAuthenticatedUserInterface
{
const DEFAULT_GRVATAR_URL = 'https://www.gravatar.com/avatar';
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private ?int $id = null;
/**
* @ORM\Column(type="string", length=180, unique=true)
* @Assert\Email(message = "Please enter a valid email address.")
* @Assert\NotBlank
*/
private string $email;
/**
* @var Collection|Role[]
* @ORM\ManyToMany(targetEntity="Role", inversedBy="users", cascade={"persist"})
* @ORM\JoinTable(
* name="user_roles",
* joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="role_id", referencedColumnName="id")}
* )
*/
private Collection $roles;
/**
* @var string The hashed password
* @ORM\Column(type="string")
*/
private string $password;
/**
* @ORM\Column(type="string", length=50)
*/
private ?string $nicename = null;
/**
* @ORM\Column(type="string", length=100, nullable=true)
*/
private ?string $url = null;
/**
* @ORM\Column(type="boolean", options={"default": false})
*/
private bool $active = false;
/**
* @Gedmo\Timestampable(on="create")
* @ORM\Column(type="datetime")
*/
private DateTimeInterface $registered;
/**
* @Gedmo\Timestampable(on="update")
* @ORM\Column(type="datetime")
*/
private DateTimeInterface $updatedAt;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $confirmationToken = null;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private ?DateTime $passwordRequestedAt = null;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private ?int $status = null;
/**
* @ORM\Column(type="string", length=250)
*/
private ?string $displayName = null;
/**
* User's prefix.
*
* @ORM\Column(type="string", nullable=true)
*/
private ?string $prefix = null;
/**
* Customer's firstname.
*
* @ORM\Column(type="string")
*/
private string $firstname;
/**
* Customer's middlename.
*
* @ORM\Column(type="string", nullable=true)
*/
private ?string $middlename = null;
/**
* Customer's lastname.
*
* @ORM\Column(type="string")
*/
private string $lastname;
/**
* customer's suffix.
*
* @ORM\Column(type="string", nullable=true)
*/
private ?string $suffix = null;
/**
* Customer's DOB.
*
* @ORM\Column(type="datetime", nullable=true, nullable=true)
*/
private ?DateTimeInterface $dob = null;
/**
* Default Billing Address.
*
* @ORM\OneToOne(targetEntity="Kobizo\Bundle\ECommerceBundle\Entity\CustomerAddress", inversedBy="billingCustomer", cascade={"persist"})
* @ORM\JoinColumn(nullable=true)
*/
private ?CustomerAddress $billingAddress = null;
/**
* Default Billing Address.
*
* @ORM\OneToOne(targetEntity="Kobizo\Bundle\ECommerceBundle\Entity\CustomerAddress", inversedBy="shippingCustomer", cascade={"persist"})
* @ORM\JoinColumn(nullable=true)
*/
private ?CustomerAddress $shippingAddress = null;
/**
* User budget.
*
* @ORM\OneToOne(targetEntity="Kobizo\Bundle\ECommerceBundle\Entity\Budget", mappedBy="user")
* @ORM\JoinColumn(nullable=true)
*/
private ?Budget $budget = null;
/**
* Customer Group.
*
* @ORM\ManyToOne(targetEntity="Kobizo\Bundle\ECommerceBundle\Entity\CustomerGroup", inversedBy="customers")
* @ORM\JoinColumn(nullable=true)
*/
private ?CustomerGroup $customerGroup = null;
/**
* Gender, see GenderType.php.
*
* @ORM\Column(type="string", nullable=true)
*/
private ?string $gender = null;
/**
* Rating of current user to define which Option(s) customers can vote.
*
* @ORM\ManyToOne(targetEntity="Kobizo\Bundle\ECommerceBundle\Entity\Rating", inversedBy="users")
* @ORM\JoinColumn(nullable=true)
*/
private ?Rating $rating;
/**
* User rating value. Calculated based on $value of ReviewVotes.
*
* @ORM\Column(type="decimal", precision=5, scale=2, nullable=true)
*/
private ?float $ratingValue = null;
/**
* Define which table user(ROLE_WORKER) is serving.
*
* @ORM\OneToOne(targetEntity="Kobizo\Bundle\ECommerceBundle\Entity\Table", mappedBy="user", cascade={"persist"})
* @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
*/
private ?Table $table = null;
/**
* customer's quotes.
*
* @ORM\OneToMany(targetEntity="Kobizo\Bundle\ECommerceBundle\Entity\Quote", mappedBy="customer")
*/
private Collection $quotes;
/**
* customer's orders.
*
* @ORM\OneToMany(targetEntity="Kobizo\Bundle\ECommerceBundle\Entity\Order", mappedBy="customer")
*/
private Collection $orders;
/**
* customer's quote addresses.
*
* @ORM\OneToMany(targetEntity="Kobizo\Bundle\ECommerceBundle\Entity\QuoteAddress", mappedBy="customer")
*/
private Collection $quoteAddresses;
/**
* customer's quote addresses.
*
* @ORM\OneToMany(targetEntity="Kobizo\Bundle\ECommerceBundle\Entity\OrderAddress", mappedBy="customer")
*/
private Collection $orderAddresses;
/**
* customer's addresses.
*
* @ORM\OneToMany(targetEntity="Kobizo\Bundle\ECommerceBundle\Entity\CustomerAddress", mappedBy="customer", orphanRemoval=true, cascade={"persist"})
*/
private Collection $addresses;
/**
* @ORM\OneToMany(targetEntity="Usermeta", mappedBy="user", orphanRemoval=true, cascade={"persist"})
*/
private Collection $usermetas;
/**
* @ORM\OneToMany(targetEntity="Post", mappedBy="author", orphanRemoval=true, cascade={"persist"})
*/
private Collection $posts;
/**
* @ORM\OneToMany(targetEntity="Page", mappedBy="author", orphanRemoval=true, cascade={"persist"})
*/
private Collection $pages;
/**
* @ORM\OneToMany(targetEntity="Menu", mappedBy="author", orphanRemoval=true, cascade={"persist"})
*/
private Collection $menus;
/**
* @ORM\OneToMany(targetEntity="Attachment", mappedBy="author", orphanRemoval=true, cascade={"persist"})
*/
private Collection $attachments;
/**
* @ORM\OneToMany(targetEntity="Kobizo\Bundle\ECommerceBundle\Entity\Wishlist", mappedBy="customer", orphanRemoval=true)
*/
private Collection $wishlists;
/**
* Reviews created by User.
*
* @ORM\OneToMany(targetEntity="Kobizo\Bundle\ECommerceBundle\Entity\Review", mappedBy="customer", orphanRemoval=true)
*/
private Collection $reviewsByUser;
/**
* Reviews for the user.
*
* @var Review[]
*/
private array $reviews = [];
/**
* @ORM\Column(type="string", nullable=true)
*/
private ?string $avatar = null;
/**
* @ORM\OneToMany(targetEntity="Kobizo\Bundle\ECommerceBundle\Entity\Store", mappedBy="presenter")
*/
private Collection $stores;
/**
* @ORM\OneToMany(targetEntity="Kobizo\Bundle\ECommerceBundle\Entity\FavoStore", mappedBy="customer")
*/
private Collection $favoStores;
/**
* @ORM\OneToMany(targetEntity="Kobizo\Bundle\ECommerceBundle\Entity\ViewedProduct", mappedBy="customer")
* @ORM\OrderBy({"addedAt" = "DESC"})
*/
private Collection $viewedProducts;
/**
* Reservations by user.
*
* @ORM\OneToMany(targetEntity="Kobizo\Bundle\ECommerceBundle\Entity\Reservation", mappedBy="user", cascade={"persist"}, orphanRemoval=true)
*/
private Collection $reservations;
public function __construct()
{
$this->quotes = new ArrayCollection();
$this->orders = new ArrayCollection();
$this->quoteAddresses = new ArrayCollection();
$this->orderAddresses = new ArrayCollection();
$this->addresses = new ArrayCollection();
$this->usermetas = new ArrayCollection();
$this->posts = new ArrayCollection();
$this->pages = new ArrayCollection();
$this->menus = new ArrayCollection();
$this->attachments = new ArrayCollection();
$this->stores = new ArrayCollection();
$this->roles = new ArrayCollection();
$this->wishlists = new ArrayCollection();
$this->viewedProducts = new ArrayCollection();
$this->favoStores = new ArrayCollection();
$this->reviewsByUser = new ArrayCollection();
$this->reservations = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getEmail(): ?string
{
return $this->email;
}
/**
* The public representation of the user (e.g. a username, an email address, etc.).
*
* @see UserInterface
*/
public function getUserIdentifier(): string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
public function isActive(): bool
{
return $this->active;
}
public function setActive(bool $active): void
{
$this->active = $active;
}
public function getRating(): ?Rating
{
return $this->rating;
}
public function setRating(?Rating $rating): self
{
$this->rating = $rating;
return $this;
}
public function getRatingValue(): ?float
{
return $this->ratingValue;
}
public function setRatingValue(?float $ratingValue): self
{
$this->ratingValue = $ratingValue;
return $this;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUsername(): string
{
return $this->email;
}
/**
* This cannot be array of Role, otherwise we will get issue with logging in.
*
* @see UserInterface
*
* @return string[]
*/
public function getRoles(): array
{
$roles = [];
/** @var Role $role */
foreach ($this->roles->toArray() as $role) {
$roles[] = $role->getCode();
}
return array_unique($roles);
}
public function setRoles(Collection $roles): self
{
$this->roles = $roles;
return $this;
}
/**
* Unlike result of getRole() or input of removeRole(), the input variable $role of addRole() function is Role object.
*
* @return $this
*/
public function addRole(Role $role): self
{
$this->roles->add($role);
return $this;
}
/**
* By default, Role in symfony should be a string but not object, but we still want to use this function for Role
* object, so we need to add is_string() here to get appropriate Role object to remove in case $role is string
* by default.
*
* @param string|Role $role
*
* @return $this
*/
public function removeRole($role): self
{
if (is_string($role)) {
$role = $this->roles->filter(function (Role $roleItem) use ($role) {
return $roleItem->getCode() === $role;
})->first();
}
$this->roles->removeElement($role);
return $this;
}
public function getRole(): Role
{
return $this->roles->first();
}
/**
* Check if current user has a role.
*/
public function hasRole(string $roleCode): bool
{
return in_array($roleCode, $this->getRoles());
}
/**
* Check if current user is super admin.
*/
public function isSuperAdmin(): bool
{
return $this->hasRole(DefaultRolesAttribute::SUPER_ADMINISTRATOR);
}
/**
* Check if current user is admin (it super admin is also admin).
*/
public function isAdmin(): bool
{
$roleCodes = $this->getRoles();
return in_array(DefaultRolesAttribute::SUPER_ADMINISTRATOR, $roleCodes)
|| in_array(DefaultRolesAttribute::ADMINISTRATOR, $roleCodes);
}
/**
* @return string[]
*/
public function getResources(): array
{
$resources = [];
foreach ($this->roles as $role) {
$resources += $role->getResources() + [$role->getCode()];
}
return array_unique($resources);
}
/**
* @see UserInterface
*/
public function getPassword(): string
{
return (string) $this->password;
}
public function setPassword(string $password): self
{
if (!empty($password)) {
$this->password = $password;
}
return $this;
}
public function getConfirmationToken(): ?string
{
return $this->confirmationToken;
}
/**
* @return $this
*/
public function setConfirmationToken(?string $confirmationToken): self
{
$this->confirmationToken = $confirmationToken;
return $this;
}
public function getPasswordRequestedAt(): ?DateTime
{
return $this->passwordRequestedAt;
}
/**
* @return $this
*/
public function setPasswordRequestedAt(?DateTime $passwordRequestedAt): self
{
$this->passwordRequestedAt = $passwordRequestedAt;
return $this;
}
/**
* @return bool
*/
public function isPasswordRequestNoneExpired(int $ttl = 0)
{
return $this->passwordRequestedAt instanceof DateTime && $this->passwordRequestedAt->getTimestamp() + $ttl > time();
}
public function getNicename(): ?string
{
return $this->nicename;
}
public function setNicename(?string $nicename): self
{
$this->nicename = $nicename;
return $this;
}
public function getUrl(): ?string
{
return $this->url;
}
public function setUrl(?string $url): self
{
$this->url = $url;
return $this;
}
public function getRegistered(): ?DateTimeInterface
{
return $this->registered;
}
public function getStatus(): ?int
{
return $this->status;
}
public function setStatus(?int $status): self
{
$this->status = $status;
return $this;
}
public function getDisplayName(): ?string
{
return $this->displayName;
}
public function setDisplayName(?string $displayName): self
{
$this->displayName = $displayName;
return $this;
}
public function getPrefix(): ?string
{
return $this->prefix;
}
public function setPrefix(?string $prefix): self
{
$this->prefix = $prefix;
return $this;
}
public function getFirstname(): ?string
{
return $this->firstname;
}
public function setFirstname(string $firstname): self
{
$this->firstname = $firstname;
return $this;
}
public function getMiddlename(): ?string
{
return $this->middlename;
}
public function setMiddlename(?string $middlename): self
{
$this->middlename = $middlename;
return $this;
}
public function getLastname(): ?string
{
return $this->lastname;
}
public function setLastname(string $lastname): self
{
$this->lastname = $lastname;
return $this;
}
public function getSuffix(): ?string
{
return $this->suffix;
}
public function setSuffix(?string $suffix): self
{
$this->suffix = $suffix;
return $this;
}
public function getDob(): ?DateTimeInterface
{
return $this->dob;
}
public function setDob(?DateTimeInterface $dob): self
{
$this->dob = $dob;
return $this;
}
public function getBillingAddress(): ?CustomerAddress
{
return $this->billingAddress;
}
public function setBillingAddress(?CustomerAddress $customerAddress): self
{
$this->billingAddress = $customerAddress;
return $this;
}
public function getShippingAddress(): ?CustomerAddress
{
return $this->shippingAddress;
}
public function setShippingAddress(?CustomerAddress $customerAddress): self
{
$this->shippingAddress = $customerAddress;
return $this;
}
public function getCustomerGroup(): ?CustomerGroup
{
return $this->customerGroup;
}
public function setCustomerGroup(?CustomerGroup $customerGroup): self
{
$this->customerGroup = $customerGroup;
return $this;
}
public function getGender(): ?string
{
return $this->gender;
}
public function setGender(?string $gender): self
{
$this->gender = $gender;
return $this;
}
/**
* @return Collection|Quote[]
*/
public function getQuotes(): Collection
{
return $this->quotes;
}
public function addQuote(Quote $quote): self
{
if (!$this->quotes->contains($quote)) {
$this->quotes[] = $quote;
$quote->setCustomer($this);
}
return $this;
}
public function removeQuote(Quote $quote): self
{
if ($this->quotes->contains($quote)) {
$this->quotes->removeElement($quote);
// set the owning side to null (unless already changed)
if ($quote->getCustomer() === $this) {
$quote->setCustomer(null);
}
}
return $this;
}
/**
* Get the last quote of current customer regarding Store [and Table].
*/
public function getLastQuote(Store $store, ?Table $table = null): ?Quote
{
$quotes = $this->quotes->filter(function (Quote $quote) use ($store, $table) {
return $quote->getStore() === $store
&& is_null($quote->getConvertedAt())
&& (is_null($table)
? is_null($quote->getTable())
: !is_null($quote->getTable()) && $quote->getTable() === $table
);
});
$lastQuote = null;
foreach ($quotes as $quote) {
if (!$lastQuote) {
$lastQuote = $quote;
} else {
if ($lastQuote->getId() < $quote->getId()) {
$lastQuote = $quote;
}
}
}
return $lastQuote;
}
/**
* @return Collection|Order[]
*/
public function getOrders(): Collection
{
return $this->orders;
}
public function addOrder(Order $order): self
{
if (!$this->orders->contains($order)) {
$this->orders[] = $order;
$order->setCustomer($this);
}
return $this;
}
public function removeOrder(Order $order): self
{
if ($this->orders->contains($order)) {
$this->orders->removeElement($order);
// set the owning side to null (unless already changed)
if ($order->getCustomer() === $this) {
$order->setCustomer(null);
}
}
return $this;
}
/**
* @return Collection|QuoteAddress[]
*/
public function getQuoteAddresses(): Collection
{
return $this->quoteAddresses;
}
public function addQuoteAddress(QuoteAddress $quoteAddress): self
{
if (!$this->quoteAddresses->contains($quoteAddress)) {
$this->quoteAddresses[] = $quoteAddress;
$quoteAddress->setCustomer($this);
}
return $this;
}
public function removeQuoteAddress(QuoteAddress $quoteAddress): self
{
if ($this->quoteAddresses->contains($quoteAddress)) {
$this->quoteAddresses->removeElement($quoteAddress);
// set the owning side to null (unless already changed)
if ($quoteAddress->getCustomer() === $this) {
$quoteAddress->setCustomer(null);
}
}
return $this;
}
/**
* @return Collection|OrderAddress[]
*/
public function getOrderAddresses(): Collection
{
return $this->orderAddresses;
}
public function addOrderAddress(OrderAddress $orderAddress): self
{
if (!$this->orderAddresses->contains($orderAddress)) {
$this->orderAddresses[] = $orderAddress;
$orderAddress->setCustomer($this);
}
return $this;
}
public function removeOrderAddress(OrderAddress $orderAddress): self
{
if ($this->orderAddresses->contains($orderAddress)) {
$this->orderAddresses->removeElement($orderAddress);
// set the owning side to null (unless already changed)
if ($orderAddress->getCustomer() === $this) {
$orderAddress->setCustomer(null);
}
}
return $this;
}
/**
* @return Collection|CustomerAddress[]
*/
public function getAddresses(): Collection
{
return $this->addresses;
}
public function addAddress(CustomerAddress $customerAddress): self
{
if (!$this->addresses->contains($customerAddress)) {
$this->addresses[] = $customerAddress;
$customerAddress->setCustomer($this);
}
return $this;
}
public function removeAddress(CustomerAddress $customerAddress): self
{
if ($this->addresses->contains($customerAddress)) {
$this->addresses->removeElement($customerAddress);
}
return $this;
}
/**
* @return Collection|Usermeta[]
*/
public function getUsermetas(): Collection
{
return $this->usermetas;
}
public function addUsermeta(Usermeta $usermeta): self
{
if (!$this->usermetas->contains($usermeta)) {
$this->usermetas[] = $usermeta;
$usermeta->setUser($this);
}
return $this;
}
public function removeUsermeta(Usermeta $usermeta): self
{
if ($this->usermetas->contains($usermeta)) {
$this->usermetas->removeElement($usermeta);
}
return $this;
}
public function getMetaValue(string $key): ?string
{
$metas = $this->usermetas->filter(function (Usermeta $usermeta) use ($key) {
return $usermeta->getKey() === $key;
});
/** @var Usermeta $meta */
$meta = $metas->first();
return $meta ? $meta->getValue() : null;
}
/**
* @return Collection|Post[]
*/
public function getPosts(): Collection
{
return $this->posts;
}
public function getNumberOfPosts(): int
{
return $this->posts->count();
}
public function getLatestPosts(): ArrayCollection
{
$criteria = Criteria::create();
$criteria->setMaxResults(10);
return $this->posts->matching($criteria);
}
public function addPost(Post $post): self
{
if (!$this->posts->contains($post)) {
$this->posts[] = $post;
$post->setAuthor($this);
}
return $this;
}
public function removePost(Post $post): self
{
if ($this->posts->contains($post)) {
$this->posts->removeElement($post);
}
return $this;
}
/**
* @return Collection|Page[]
*/
public function getPages(): Collection
{
return $this->pages;
}
public function addPage(Page $page): self
{
if (!$this->pages->contains($page)) {
$this->pages[] = $page;
$page->setAuthor($this);
}
return $this;
}
public function removePage(Page $page): self
{
if ($this->pages->contains($page)) {
$this->pages->removeElement($page);
}
return $this;
}
/**
* @return Collection|Menu[]
*/
public function getMenus(): Collection
{
return $this->menus;
}
public function addMenu(Menu $menu): self
{
if (!$this->menus->contains($menu)) {
$this->menus[] = $menu;
$menu->setAuthor($this);
}
return $this;
}
public function removeMenu(Menu $menu): self
{
if ($this->menus->contains($menu)) {
$this->menus->removeElement($menu);
}
return $this;
}
/**
* @return Collection|Attachment[]
*/
public function getAttachments(): Collection
{
return $this->attachments;
}
public function addAttachment(Attachment $attachment): self
{
if (!$this->attachments->contains($attachment)) {
$this->attachments[] = $attachment;
$attachment->setAuthor($this);
}
return $this;
}
public function removeAttachment(Attachment $attachment): self
{
if ($this->attachments->contains($attachment)) {
$this->attachments->removeElement($attachment);
}
return $this;
}
/**
* @return Collection|Store[]
*/
public function getStores(): Collection
{
return $this->stores;
}
public function addStore(Store $store): self
{
if (!$this->stores->contains($store)) {
$this->stores[] = $store;
$store->setPresenter($this);
}
return $this;
}
public function removeStore(Store $store): self
{
if ($this->stores->contains($store)) {
$this->stores->removeElement($store);
// set the owning side to null (unless already changed)
if ($store->getPresenter() === $this) {
$store->setPresenter(null);
}
}
return $this;
}
/**
* @see UserInterface
*
* @return string|null
*/
public function getSalt()
{
// not needed when using the "bcrypt" algorithm in security.yaml
}
/**
* @see UserInterface
*/
public function eraseCredentials()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function isEqualTo(UserInterface $user): bool
{
if ($this->password !== $user->getPassword()) {
return false;
}
if ($this->email !== $user->getUserIdentifier()) {
return false;
}
return true;
}
/**
* @return Collection|Wishlist[]
*/
public function getWishlists(): Collection
{
return $this->wishlists;
}
public function addWishlist(Wishlist $wishlist): self
{
if (!$this->wishlists->contains($wishlist)) {
$this->wishlists[] = $wishlist;
$wishlist->setCustomer($this);
}
return $this;
}
public function removeWishlist(Wishlist $wishlist): self
{
if ($this->wishlists->contains($wishlist)) {
$this->wishlists->removeElement($wishlist);
// set the owning side to null (unless already changed)
if ($wishlist->getCustomer() === $this) {
$wishlist->setCustomer(null);
}
}
return $this;
}
/**
* @return Collection|Review[]
*/
public function getReviewsByUser(): Collection
{
return $this->reviewsByUser;
}
public function addReviewsByUser(Review $review): self
{
if (!$this->reviewsByUser->contains($review)) {
$this->reviewsByUser[] = $review;
$review->setCustomer($this);
}
return $this;
}
public function removeReviewsByUser(Review $review): self
{
if ($this->wishlists->contains($review)) {
$this->wishlists->removeElement($review);
if ($review->getCustomer() === $this) {
$review->setCustomer(null);
}
}
return $this;
}
/**
* @return Collection|FavoStore[]
*/
public function getFavoStores(): Collection
{
return $this->favoStores;
}
public function addFavoStore(FavoStore $favouriteStore): self
{
if (!$this->favoStores->contains($favouriteStore)) {
$this->favoStores[] = $favouriteStore;
$favouriteStore->setCustomer($this);
}
return $this;
}
public function removeFavoStore(FavoStore $favouriteStore): self
{
if ($this->favoStores->contains($favouriteStore)) {
$this->favoStores->removeElement($favouriteStore);
}
return $this;
}
/**
* @return Review[]
*/
public function getReviews(): array
{
return $this->reviews;
}
public function addReview(Review $review): self
{
if (!in_array($review, $this->reviews, true)) {
$this->reviews[] = $review;
$review->setObjectId($this->getId());
}
return $this;
}
public function removeReview(Review $review): self
{
if (in_array($review, $this->reviews, true)) {
$this->reviews = array_filter($this->reviews, static function (Review $existedReview) use ($review) {
return $existedReview->getId() !== $review->getId();
});
if ($review->getObjectId() === $this->getId()) {
$review->setObjectId(null);
}
}
return $this;
}
public function getAvatar(): ?string
{
return $this->avatar ?: self::DEFAULT_GRVATAR_URL;
}
public function setAvatar(?string $avatar): self
{
$this->avatar = $avatar;
return $this;
}
/**
* @return Collection|ViewedProduct[]
*/
public function getViewedProducts(): Collection
{
return $this->viewedProducts;
}
public function addViewedProduct(ViewedProduct $viewedProduct): self
{
if (!$this->viewedProducts->contains($viewedProduct)) {
$this->viewedProducts->add($viewedProduct);
$viewedProduct->setCustomer($this);
}
return $this;
}
public function removeViewedProduct(ViewedProduct $viewedProduct): self
{
if ($this->viewedProducts->contains($viewedProduct)) {
$this->viewedProducts->removeElement($viewedProduct);
// set the owning side to null (unless already changed)
if ($viewedProduct->getCustomer() === $this) {
$viewedProduct->setCustomer(null);
}
}
return $this;
}
public function __toString(): string
{
return sprintf('[%d] %s - %s', $this->getId(), $this->getEmail(), $this->getDisplayName() ?? 'EMPTY');
}
public function getUpdatedAt(): ?DateTimeInterface
{
return $this->updatedAt;
}
public function getBudget(): ?Budget
{
return $this->budget;
}
public function setBudget(?Budget $budget): self
{
$this->budget = $budget;
return $this;
}
/**
* @return Collection|Reservation[]
*/
public function getReservations(): Collection
{
return $this->reservations;
}
public function addReservation(Reservation $reservation): self
{
if (!$this->reservations->contains($reservation)) {
$this->reservations[] = $reservation;
$reservation->setUser($this);
}
return $this;
}
public function removeReservation(Reservation $reservation): self
{
if ($this->reservations->contains($reservation)) {
$this->reservations->removeElement($reservation);
if ($reservation->getUser() === $this) {
$reservation->setUser(null);
}
}
return $this;
}
public function getTable(): ?Table
{
return $this->table;
}
public function setTable(?Table $table): self
{
$this->table = $table;
return $this;
}
public function removeTimeSetting(ReservationTimeSetting $timeSetting): self
{
if ($this->timeSettings->contains($timeSetting)) {
$this->timeSettings->removeElement($timeSetting);
}
return $this;
}
}