<?php
namespace App\Entity\Account;
use App\Entity\Profile\Comment\CommentByCustomer;
use App\Entity\Profile\Profile;
use App\Entity\User;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity]
class Customer extends User
{
public const ROLE_CUSTOMER = 'ROLE_CUSTOMER';
#[ORM\OneToOne(targetEntity: CommentBan::class, mappedBy: 'user', cascade: ['all'], orphanRemoval: true)]
private ?CommentBan $commentBan = null;
#[ORM\OneToOne(targetEntity: CustomerProfilePreference::class, mappedBy: 'user', cascade: ['all'], orphanRemoval: true)]
private ?CustomerProfilePreference $profilePreference = null;
#[ORM\OneToOne(targetEntity: CustomerPreferredProfilesData::class, mappedBy: 'user', cascade: ['all'], orphanRemoval: true)]
private ?CustomerPreferredProfilesData $preferredProfilesData = null;
/** @var UserFavourite[] */
#[ORM\OneToMany(targetEntity: UserFavourite::class, mappedBy: 'user', cascade: ['all'], orphanRemoval: true)]
private Collection $favourites;
/** @var CommentByCustomer[] */
#[ORM\OneToMany(targetEntity: CommentByCustomer::class, mappedBy: 'user', cascade: ['all'], orphanRemoval: true)]
private Collection $profileComments;
/** @var \App\Entity\Saloon\Comment\CommentByCustomer[] */
#[ORM\OneToMany(targetEntity: \App\Entity\Saloon\Comment\CommentByCustomer::class, mappedBy: 'user', cascade: ['all'], orphanRemoval: true)]
private Collection $saloonComments;
public function __construct()
{
parent::__construct();
$this->favourites = new ArrayCollection();
$this->profileComments = new ArrayCollection();
$this->saloonComments = new ArrayCollection();
$this->setRoles(array_merge($this->getRoles(), [self::ROLE_CUSTOMER]));
}
public function getProfilePreference(): ?CustomerProfilePreference
{
return $this->profilePreference;
}
public function setProfilePreference(?CustomerProfilePreference $profilePreference): void
{
$this->profilePreference = $profilePreference;
}
public function getPreferredProfilesData(): ?CustomerPreferredProfilesData
{
return $this->preferredProfilesData;
}
public function setPreferredProfilesData(?CustomerPreferredProfilesData $preferredProfilesData): void
{
$this->preferredProfilesData = $preferredProfilesData;
}
/**
* @return UserFavourite[]
*/
public function getFavourites(): Collection
{
return $this->favourites;
}
/**
* @return UserFavourite[]
*/
public function getProfileFavourites(): Collection
{
return $this->favourites->filter(function(UserFavourite $userFavourite): bool {
return ($userFavourite instanceof FavouriteProfile);
});
}
public function findProfileInFavourites(Profile $profile): ?FavouriteProfile
{
$filtered = $this->favourites->filter(function(UserFavourite $userFavourite) use ($profile): bool {
return ($userFavourite instanceof FavouriteProfile && $userFavourite->getProfile()->getId() == $profile->getId());
});
return $filtered->count() ? $filtered->getValues()[0] : null;
}
public function addToFavourites(Profile $profile): void
{
if(null != $this->findProfileInFavourites($profile))
return;
$res = $this->favourites->add(new FavouriteProfile($this, $profile));
}
public function removeFromFavourites(Profile $profile): void
{
if(null == $favouriteProfile = $this->findProfileInFavourites($profile))
return;
$this->favourites->removeElement($favouriteProfile);
}
/**
* @return CommentByCustomer[]
*/
public function getProfileComments(): Collection
{
return $this->profileComments;
}
/**
* @return \App\Entity\Saloon\Comment\CommentByCustomer[]
*/
public function getSaloonComments(): Collection
{
return $this->saloonComments;
}
public function getCommentBan(): ?CommentBan
{
return $this->commentBan;
}
public function setCommentBan(?CommentBan $commentBan): void
{
$this->commentBan = $commentBan;
}
}