<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Annotation\ApiSubresource;
use App\Controller\Api\ProfileController;
use App\Controller\Api\ProfileImageController;
use App\Repository\ProfileRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\MaxDepth;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Symfony\Component\Validator\Constraints as Assert;
use App\Repository\AnswerRepository;
use Doctrine\Common\Collections\Criteria;
#[ORM\Entity(repositoryClass: ProfileRepository::class)]
#[ApiResource(
normalizationContext: ['groups' => ['profile']],
denormalizationContext: ['groups' => ['profile']],
)]
class Profile
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
#[Groups("profile")]
private $id;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Groups(["profile","read_2"])]
private $firstName;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Groups(["profile","read_2"])]
private $lastName;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Groups("profile")]
private $profileImage;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $phoneNumber;
#[ORM\Column(type: 'string', nullable: true)]
#[Groups("profile")]
private $gender;
#[ORM\OneToOne(inversedBy: 'profile', targetEntity: User::class, cascade: ['persist', 'remove'])]
#[Groups(["profile","read_2"])]
#[Assert\Valid]
private $user;
#[ORM\ManyToMany(targetEntity: Langue::class, inversedBy: 'profiles')]
#[Groups("read")]
private Collection $langues;
#[ORM\Column(length: 255, nullable: true)]
#[Groups("profile")]
private ?string $profession = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups("profile")]
private ?string $bio = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups("profile")]
private ?string $pseudoName = null;
#[ORM\OneToMany(mappedBy: 'profile', targetEntity: Gallery::class)]
private Collection $galleries;
#[ORM\ManyToMany(targetEntity: Interest::class, inversedBy: 'profiles')]
#[Groups("read")]
private Collection $interests;
#[ORM\Column(length: 255, nullable: true)]
#[Groups("profile")]
private ?string $address = null;
#[ORM\OneToOne(inversedBy: 'profile', cascade: ['persist', 'remove'])]
#[Groups("profile")]
private ?ProfileTargetSetting $profileTargetSetting = null;
#[ORM\Column(nullable: true)]
#[Groups("profile")]
private ?bool $isVisible = true;
#[ORM\Column(nullable: true)]
#[Groups("profile")]
private ?bool $isDeleted = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups("profile")]
private ?string $lng = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups("profile")]
private ?string $lat = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups("profile")]
private ?string $educationLevel = null;
#[ORM\ManyToMany(targetEntity: Answer::class, inversedBy: 'profiles')]
#[Groups("profile")]
private Collection $answers;
#[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
#[Groups("profile")]
private ?\DateTimeInterface $bornAt = null;
#[ORM\Column(nullable: true)]
#[Groups("profile")]
private ?bool $isSmoker = null;
#[ORM\Column(nullable: true)]
#[Groups("profile")]
private ?bool $isDrinker = null;
#[ORM\Column(nullable: true)]
#[Groups("profile")]
private ?bool $hasKids = null;
#[ORM\Column(nullable: true)]
#[Groups("profile")]
private ?bool $isDevorced = null;
#[ORM\OneToMany(mappedBy: 'profileAskForMatch', targetEntity: MatchProfile::class)]
#[Groups("read")]
private Collection $askedMatches;
#[Groups("read")]
#[ORM\OneToMany(mappedBy: 'profileMatched', targetEntity: MatchProfile::class)]
private Collection $matchesByOthers;
#[ORM\Column(nullable: true)]
#[Groups("profile")]
private ?bool $isNewMatchesByEmail = null;
#[ORM\Column(nullable: true)]
#[Groups("profile")]
private ?bool $isNewMessagesByEmail = null;
#[ORM\Column(nullable: true)]
#[Groups("profile")]
private ?bool $isNewFeedsByEmail = null;
#[ORM\Column(nullable: true)]
#[Groups("profile")]
private ?bool $isNewMatchesByNotif = null;
#[ORM\Column(nullable: true)]
#[Groups("profile")]
private ?bool $isNewMessagesByNotif = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups("profile")]
private ?string $imageGallery1 = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups("profile")]
private ?string $imageGallery2 = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups("profile")]
private ?string $imageGallery3 = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups("profile")]
private ?string $imageGallery4 = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups("profile")]
private ?string $imageGallery5 = null;
#[ORM\ManyToMany(targetEntity: self::class, inversedBy: 'likedBy')]
#[ORM\JoinTable(
name: "profiles_likes"
)]
private Collection $likedProfiles;
#[ORM\ManyToMany(targetEntity: self::class, mappedBy: 'likedProfiles')]
private Collection $likedBy;
#[ORM\ManyToMany(targetEntity: self::class, inversedBy: 'dislikedBy')]
#[ORM\JoinTable(
name: "profiles_dislikes"
)]
private Collection $dislikedProfiles;
#[ORM\ManyToMany(targetEntity: self::class, mappedBy: 'dislikedProfiles')]
private Collection $dislikedBy;
#[ORM\ManyToMany(targetEntity: self::class, inversedBy: 'matchedByProfiles')]
private Collection $matchedProfiles;
#[ORM\ManyToMany(targetEntity: self::class, mappedBy: 'matchedProfiles')]
private Collection $matchedByProfiles;
public function __construct()
{
$this->langues = new ArrayCollection();
// $this->matchs = new ArrayCollection();
// $this->boosts = new ArrayCollection();
$this->galleries = new ArrayCollection();
$this->interests = new ArrayCollection();
$this->user = new User();
$this->answers = new ArrayCollection();
$this->askedMatches = new ArrayCollection();
$this->matchesByOthers = new ArrayCollection();
$this->setProfileTargetSetting(new ProfileTargetSetting());
$this->likedProfiles = new ArrayCollection();
$this->likedBy = new ArrayCollection();
$this->dislikedProfiles = new ArrayCollection();
$this->dislikedBy = new ArrayCollection();
$this->matchedProfiles = new ArrayCollection();
$this->matchedByProfiles = new ArrayCollection();
}
public function __toString()
{
if(!$this->firstName && !$this->lastName){
return (string)$this->getUser()->getEmail();
}
return (string)$this->firstName ." : ".(string)$this->getUser()->getEmail();
}
public function getId(): ?int
{
return $this->id;
}
public function getFirstName(): ?string
{
return $this->firstName;
}
public function setFirstName(?string $firstName): self
{
$this->firstName = $firstName;
return $this;
}
public function getLastName(): ?string
{
return $this->lastName;
}
public function setLastName(?string $lastName): self
{
$this->lastName = $lastName;
return $this;
}
public function getProfileImage(): ?string
{
return $this->profileImage;
}
public function setProfileImage(?string $profileImage): self
{
$this->profileImage = $profileImage;
return $this;
}
public function getPhoneNumber(): ?string
{
return $this->phoneNumber;
}
public function setPhoneNumber(?string $phoneNumber): self
{
$this->phoneNumber = $phoneNumber;
return $this;
}
public function getGender(): ?string
{
return $this->gender;
}
public function setGender(?string $gender): self
{
$this->gender = $gender;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
// unset the owning side of the relation if necessary
if ($user === null && $this->user !== null) {
$this->user->setProfile(null);
}
// set the owning side of the relation if necessary
if ($user !== null && $user->getProfile() !== $this) {
$user->setProfile($this);
}
$this->user = $user;
return $this;
}
/**
* @return Collection<int, Langue>
*/
public function getLangues(): Collection
{
return $this->langues;
}
public function addLangue(Langue $langue): self
{
if (!$this->langues->contains($langue)) {
$this->langues->add($langue);
}
return $this;
}
public function removeLangue(Langue $langue): self
{
$this->langues->removeElement($langue);
return $this;
}
public function getProfession(): ?string
{
return $this->profession;
}
public function setProfession(?string $profession): self
{
$this->profession = $profession;
return $this;
}
public function getBio(): ?string
{
return $this->bio;
}
public function setBio(?string $bio): self
{
$this->bio = $bio;
return $this;
}
public function getPseudoName(): ?string
{
return $this->pseudoName;
}
public function setPseudoName(?string $pseudoName): self
{
$this->pseudoName = $pseudoName;
return $this;
}
/**
* @return Collection<int, Gallery>
*/
public function getGalleries(): Collection
{
return $this->galleries;
}
public function addGallery(Gallery $gallery): self
{
if (!$this->galleries->contains($gallery)) {
$this->galleries->add($gallery);
$gallery->setProfile($this);
}
return $this;
}
public function removeGallery(Gallery $gallery): self
{
if ($this->galleries->removeElement($gallery)) {
// set the owning side to null (unless already changed)
if ($gallery->getProfile() === $this) {
$gallery->setProfile(null);
}
}
return $this;
}
/**
* @return Collection<int, Interest>
*/
public function getInterests(): Collection
{
return $this->interests;
}
public function addInterest(Interest $interest): self
{
if (!$this->interests->contains($interest)) {
$this->interests->add($interest);
}
return $this;
}
public function removeInterest(Interest $interest): self
{
$this->interests->removeElement($interest);
return $this;
}
public function getAddress(): ?string
{
return $this->address;
}
public function setAddress(string $address): self
{
$this->address = $address;
return $this;
}
public function getProfileTargetSetting(): ?ProfileTargetSetting
{
return $this->profileTargetSetting;
}
public function setProfileTargetSetting(?ProfileTargetSetting $profileTargetSetting): self
{
// unset the owning side of the relation if necessary
if ($profileTargetSetting === null && $this->profileTargetSetting !== null) {
$this->profileTargetSetting->setProfile(null);
}
// set the owning side of the relation if necessary
if ($profileTargetSetting !== null && $profileTargetSetting->getProfile() !== $this) {
$profileTargetSetting->setProfile($this);
}
$this->profileTargetSetting = $profileTargetSetting;
return $this;
}
public function isIsVisible(): ?bool
{
return $this->isVisible;
}
public function setIsVisible(?bool $isVisible): self
{
$this->isVisible = $isVisible;
return $this;
}
public function isIsDeleted(): ?bool
{
return $this->isDeleted;
}
public function setIsDeleted(?bool $isDeleted): self
{
$this->isDeleted = $isDeleted;
return $this;
}
public function getLng(): ?string
{
return $this->lng;
}
public function setLng(?string $lng): self
{
$this->lng = $lng;
return $this;
}
public function getLat(): ?string
{
return $this->lat;
}
public function setLat(?string $lat): self
{
$this->lat = $lat;
return $this;
}
public function getEducationLevel(): ?string
{
return $this->educationLevel;
}
public function setEducationLevel(?string $educationLevel): self
{
$this->educationLevel = $educationLevel;
return $this;
}
/**
* @return Collection<int, Answer>
*/
public function getAnswers($type=null): Collection
{
return $this->answers;
}
public function getAnswersByType($conditionValue)
{
$filtredAnswers = [];
foreach($this->answers as $singleAnswer){
if($singleAnswer->getQuestion()->getType() == $conditionValue){
$filtredAnswers[] = $singleAnswer;
}
}
return $filtredAnswers;
}
public function addAnswer(Answer $answer): self
{
if (!$this->answers->contains($answer)) {
$this->answers->add($answer);
}
return $this;
}
public function removeAnswer(Answer $answer): self
{
$this->answers->removeElement($answer);
return $this;
}
public function getBornAt(): ?\DateTimeInterface
{
return $this->bornAt;
}
public function setBornAt(?\DateTimeInterface $bornAt): self
{
$this->bornAt = $bornAt;
return $this;
}
#[Groups("profile")]
public function getAge()
{
$bornAt = $this->getBornAt();
if($this->getBornAt()){
$dateOfBirth = $bornAt->format("Y-m-d");
$today = date("Y-m-d");
$diff = date_diff(date_create($today),date_create($dateOfBirth));
return (int)$diff->format('%y');
}
return 0;
}
public function isIsSmoker(): ?bool
{
return $this->isSmoker;
}
public function setIsSmoker(?bool $isSmoker): self
{
$this->isSmoker = $isSmoker;
return $this;
}
public function isIsDrinker(): ?bool
{
return $this->isDrinker;
}
public function setIsDrinker(?bool $isDrinker): self
{
$this->isDrinker = $isDrinker;
return $this;
}
public function isHasKids(): ?bool
{
return $this->hasKids;
}
public function setHasKids(?bool $hasKids): self
{
$this->hasKids = $hasKids;
return $this;
}
public function isIsDevorced(): ?bool
{
return $this->isDevorced;
}
public function setIsDevorced(?bool $isDevorced): self
{
$this->isDevorced = $isDevorced;
return $this;
}
/**
* @return Collection<int, MatchProfile>
*/
public function getAskedMatches(): Collection
{
return $this->askedMatches;
}
public function addAskedMatch(MatchProfile $askedMatch): self
{
if (!$this->askedMatches->contains($askedMatch)) {
$this->askedMatches->add($askedMatch);
$askedMatch->setProfileAskForMatch($this);
}
return $this;
}
public function removeAskedMatch(MatchProfile $askedMatch): self
{
if ($this->askedMatches->removeElement($askedMatch)) {
// set the owning side to null (unless already changed)
if ($askedMatch->getProfileAskForMatch() === $this) {
$askedMatch->setProfileAskForMatch(null);
}
}
return $this;
}
/**
* @return Collection<int, MatchProfile>
*/
public function getMatchesByOthers(): Collection
{
return $this->matchesByOthers;
}
public function addMatchesByOther(MatchProfile $matchesByOther): self
{
if (!$this->matchesByOthers->contains($matchesByOther)) {
$this->matchesByOthers->add($matchesByOther);
$matchesByOther->setProfileMatched($this);
}
return $this;
}
public function removeMatchesByOther(MatchProfile $matchesByOther): self
{
if ($this->matchesByOthers->removeElement($matchesByOther)) {
// set the owning side to null (unless already changed)
if ($matchesByOther->getProfileMatched() === $this) {
$matchesByOther->setProfileMatched(null);
}
}
return $this;
}
public function isIsNewMatchesByEmail(): ?bool
{
return $this->isNewMatchesByEmail;
}
public function setIsNewMatchesByEmail(?bool $isNewMatchesByEmail): self
{
$this->isNewMatchesByEmail = $isNewMatchesByEmail;
return $this;
}
public function isIsNewMessagesByEmail(): ?bool
{
return $this->isNewMessagesByEmail;
}
public function setIsNewMessagesByEmail(?bool $isNewMessagesByEmail): self
{
$this->isNewMessagesByEmail = $isNewMessagesByEmail;
return $this;
}
public function isIsNewFeedsByEmail(): ?bool
{
return $this->isNewFeedsByEmail;
}
public function setIsNewFeedsByEmail(?bool $isNewFeedsByEmail): self
{
$this->isNewFeedsByEmail = $isNewFeedsByEmail;
return $this;
}
public function isIsNewMatchesByNotif(): ?bool
{
return $this->isNewMatchesByNotif;
}
public function setIsNewMatchesByNotif(?bool $isNewMatchesByNotif): self
{
$this->isNewMatchesByNotif = $isNewMatchesByNotif;
return $this;
}
public function isIsNewMessagesByNotif(): ?bool
{
return $this->isNewMessagesByNotif;
}
public function setIsNewMessagesByNotif(?bool $isNewMessagesByNotif): self
{
$this->isNewMessagesByNotif = $isNewMessagesByNotif;
return $this;
}
public function getImageGallery1(): ?string
{
return $this->imageGallery1;
}
public function setImageGallery1(?string $imageGallery1): self
{
$this->imageGallery1 = $imageGallery1;
return $this;
}
public function getImageGallery2(): ?string
{
return $this->imageGallery2;
}
public function setImageGallery2(?string $imageGallery2): self
{
$this->imageGallery2 = $imageGallery2;
return $this;
}
public function getImageGallery3(): ?string
{
return $this->imageGallery3;
}
public function setImageGallery3(?string $imageGallery3): self
{
$this->imageGallery3 = $imageGallery3;
return $this;
}
public function getImageGallery4(): ?string
{
return $this->imageGallery4;
}
public function setImageGallery4(?string $imageGallery4): self
{
$this->imageGallery4 = $imageGallery4;
return $this;
}
public function getImageGallery5(): ?string
{
return $this->imageGallery5;
}
public function setImageGallery5(?string $imageGallery5): self
{
$this->imageGallery5 = $imageGallery5;
return $this;
}
#[Groups("profile")]
public function getCompletionProfilePercentage(){
$percentage = 0;
$value = 9.09;
if($this->pseudoName){
$percentage = $percentage + $value;
}
if($this->gender){
$percentage = $percentage + $value;
}
if($this->profileImage){
$percentage = $percentage + $value;
}
if($this->profession){
$percentage = $percentage + $value;
}
if($this->educationLevel){
$percentage = $percentage + $value;
}
if($this->bio){
$percentage = $percentage + $value;
}
if($this->address){
$percentage = $percentage + $value;
}
if($this->lng and $this->lat){
$percentage = $percentage + $value;
}
if($this->bornAt){
$percentage = $percentage + $value;
}
if(count($this->langues) > 0){
$percentage = $percentage + $value;
}
if(count($this->interests) > 0){
$percentage = $percentage + $value;
}
return round($percentage, 0, PHP_ROUND_HALF_UP);
}
public function getLikedProfiles()
{
$filtredData = [];
//return $filtredData;
foreach($this->likedProfiles as $singleProfile){
if(
!in_array($singleProfile,$this->getMatchedProfiles()) and
!in_array($singleProfile,$this->getMatchedByProfiles()) and
$singleProfile->isIsVisible()
){
$filtredData[]=$singleProfile;
}
}
return $filtredData;
}
public function addLikedProfile(self $likedProfile): self
{
if (!$this->likedProfiles->contains($likedProfile)) {
$this->likedProfiles->add($likedProfile);
}
return $this;
}
public function removeLikedProfile(self $likedProfile): self
{
$this->likedProfiles->removeElement($likedProfile);
return $this;
}
public function getLikedBy()
{
$filtredData = [];
//return $filtredData;
foreach($this->likedBy as $singleProfile){
if(
!in_array($singleProfile,$this->getMatchedProfiles()) and
!in_array($singleProfile,$this->getMatchedByProfiles()) and
$singleProfile->isIsVisible()
){
$filtredData[]=$singleProfile;
}
}
return $filtredData;
//return $this->likedBy;
}
public function addLikedBy(self $likedBy): self
{
if (!$this->likedBy->contains($likedBy)) {
$this->likedBy->add($likedBy);
$likedBy->addLikedProfile($this);
}
return $this;
}
public function removeLikedBy(self $likedBy): self
{
if ($this->likedBy->removeElement($likedBy)) {
$likedBy->removeLikedProfile($this);
}
return $this;
}
public function getDislikedProfiles()
{
$filtredData = [];
//return $filtredData;
foreach($this->dislikedProfiles as $singleProfile){
if(
!in_array($singleProfile,$this->getMatchedProfiles()) and
!in_array($singleProfile,$this->getMatchedByProfiles()) and
$singleProfile->isIsVisible()
){
$filtredData[]=$singleProfile;
}
}
return $filtredData;
//return $this->dislikedProfiles;
}
public function addDislikedProfile(self $dislikedProfile): self
{
if (!$this->dislikedProfiles->contains($dislikedProfile)) {
$this->dislikedProfiles->add($dislikedProfile);
}
return $this;
}
public function removeDislikedProfile(self $dislikedProfile): self
{
$this->dislikedProfiles->removeElement($dislikedProfile);
return $this;
}
public function getDislikedBy()
{
$filtredData = [];
//return $filtredData;
foreach($this->dislikedBy as $singleProfile){
if(
!in_array($singleProfile,$this->getMatchedProfiles()) and
!in_array($singleProfile,$this->getMatchedByProfiles()) and
$singleProfile->isIsVisible()
){
$filtredData[]=$singleProfile;
}
}
return $filtredData;
//return $this->dislikedBy;
}
public function addDislikedBy(self $dislikedBy): self
{
if (!$this->dislikedBy->contains($dislikedBy)) {
$this->dislikedBy->add($dislikedBy);
$dislikedBy->addDislikedProfile($this);
}
return $this;
}
public function removeDislikedBy(self $dislikedBy): self
{
if ($this->dislikedBy->removeElement($dislikedBy)) {
$dislikedBy->removeDislikedProfile($this);
}
return $this;
}
public function getMatchedProfiles()
{
return $this->matchedProfiles->toArray();
}
public function addMatchedProfile(self $matchedProfile): self
{
if (!$this->matchedProfiles->contains($matchedProfile)) {
$this->matchedProfiles->add($matchedProfile);
}
return $this;
}
public function removeMatchedProfile(self $matchedProfile): self
{
$this->matchedProfiles->removeElement($matchedProfile);
return $this;
}
public function getMatchedByProfiles()
{
return $this->matchedByProfiles->toArray();
}
public function addMatchedByProfile(self $matchedByProfile): self
{
if (!$this->matchedByProfiles->contains($matchedByProfile)) {
$this->matchedByProfiles->add($matchedByProfile);
$matchedByProfile->addMatchedProfile($this);
}
return $this;
}
public function removeMatchedByProfile(self $matchedByProfile): self
{
if ($this->matchedByProfiles->removeElement($matchedByProfile)) {
$matchedByProfile->removeMatchedProfile($this);
}
return $this;
}
}