src/Entity/Profile.php line 27

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use ApiPlatform\Core\Annotation\ApiSubresource;
  5. use App\Controller\Api\ProfileController;
  6. use App\Controller\Api\ProfileImageController;
  7. use App\Repository\ProfileRepository;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Doctrine\Common\Collections\Collection;
  10. use Doctrine\DBAL\Types\Types;
  11. use Doctrine\ORM\Mapping as ORM;
  12. use Symfony\Component\Serializer\Annotation\Groups;
  13. use Symfony\Component\Serializer\Annotation\MaxDepth;
  14. use Symfony\Component\HttpFoundation\File\File;
  15. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  16. use Symfony\Component\Validator\Constraints as Assert;
  17. use App\Repository\AnswerRepository;
  18. #[ORM\Entity(repositoryClassProfileRepository::class)]
  19. /*#[ApiResource(
  20.     normalizationContext: ['groups' => ['profile','read']],
  21.     denormalizationContext: ['groups' => ['profile']],
  22.     
  23.     )]*/
  24. class Profile
  25. {
  26.     #[ORM\Id]
  27.     #[ORM\GeneratedValue]
  28.     #[ORM\Column(type'integer')]
  29.     #[Groups("profile")]
  30.     private $id;
  31.     #[ORM\Column(type'string'length255nullabletrue)]
  32.     #[Groups("profile")]
  33.    
  34.     private $firstName;
  35.     #[ORM\Column(type'string'length255nullabletrue)]
  36.     #[Groups("profile")]
  37.     private $lastName;
  38.     #[ORM\Column(type'string'length255nullabletrue)]
  39.     #[Groups("profile")]
  40.     private $profileImage;
  41.     #[ORM\Column(type'string'length255nullabletrue)]
  42.     private $phoneNumber;
  43.     #[ORM\Column(type'string'nullabletrue)]
  44.     #[Groups("profile")]
  45.     private $gender;
  46.     #[ORM\OneToOne(inversedBy'profile'targetEntityUser::class, cascade: ['persist''remove'])]
  47.     #[Groups("profile")]
  48.     #[Assert\Valid]
  49.     private $user;
  50.     
  51.     #[ORM\ManyToMany(targetEntityLangue::class, inversedBy'profiles')]
  52.     #[Groups("profile")]
  53.     private Collection $langues;
  54.     #[ORM\Column(length255nullabletrue)]
  55.     #[Groups("profile")]
  56.     private ?string $profession null;
  57.     #[ORM\Column(length255nullabletrue)]
  58.     #[Groups("profile")]
  59.     private ?string $bio null;
  60.     #[ORM\Column(length255nullabletrue)]
  61.     #[Groups("profile")]
  62.     private ?string $pseudoName null;
  63.     #[ORM\OneToMany(mappedBy'profile'targetEntityGallery::class)]
  64.     private Collection $galleries;
  65.     #[ORM\ManyToMany(targetEntityInterest::class, inversedBy'profiles')]
  66.     #[Groups("profile")]
  67.     private Collection $interests;
  68.     #[ORM\Column(length255nullabletrue)]
  69.     #[Groups("profile")]
  70.     private ?string $address null;
  71.     #[ORM\OneToOne(inversedBy'profile'cascade: ['persist''remove'])]
  72.     #[Groups("profile")]
  73.     private ?ProfileTargetSetting $profileTargetSetting null;
  74.     #[ORM\Column(nullabletrue)]
  75.     #[Groups("profile")]
  76.     private ?bool $isVisible true;
  77.     #[ORM\Column(nullabletrue)]
  78.     #[Groups("profile")]
  79.     private ?bool $isDeleted null;
  80.     #[ORM\Column(length255nullabletrue)]
  81.     #[Groups("profile")]
  82.     private ?string $lng null;
  83.     #[ORM\Column(length255nullabletrue)]
  84.     #[Groups("profile")]
  85.     private ?string $lat null;
  86.     #[ORM\Column(length255nullabletrue)]
  87.     #[Groups("profile")]
  88.     private ?string $educationLevel null;
  89.     #[ORM\ManyToMany(targetEntityAnswer::class, inversedBy'profiles')]
  90.     #[Groups("profile")]
  91.     private Collection $answers;
  92.     #[ORM\Column(typeTypes::DATE_MUTABLEnullabletrue)]
  93.     #[Groups("profile")]
  94.     private ?\DateTimeInterface $bornAt null;
  95.     #[ORM\Column(nullabletrue)]
  96.     #[Groups("profile")]
  97.     private ?bool $isSmoker null;
  98.     #[ORM\Column(nullabletrue)]
  99.     #[Groups("profile")]
  100.     private ?bool $isDrinker null;
  101.     #[ORM\Column(nullabletrue)]
  102.     #[Groups("profile")]
  103.     private ?bool $hasKids null;
  104.     #[ORM\Column(nullabletrue)]
  105.     #[Groups("profile")]
  106.     private ?bool $isDevorced null;
  107.     #[ORM\OneToMany(mappedBy'profileAskForMatch'targetEntityMatchProfile::class)]
  108.     #[Groups("read")]
  109.     private Collection $askedMatches;
  110.     
  111.  #[Groups("read")]
  112.     #[ORM\OneToMany(mappedBy'profileMatched'targetEntityMatchProfile::class)]
  113.     
  114.     private Collection $matchesByOthers;
  115.     #[ORM\Column(nullabletrue)]
  116.     #[Groups("profile")]
  117.     private ?bool $isNewMatchesByEmail null;
  118.     #[ORM\Column(nullabletrue)]
  119.     #[Groups("profile")]
  120.     private ?bool $isNewMessagesByEmail null;
  121.     #[ORM\Column(nullabletrue)]
  122.     #[Groups("profile")]
  123.     private ?bool $isNewFeedsByEmail null;
  124.     #[ORM\Column(nullabletrue)]
  125.     #[Groups("profile")]
  126.     private ?bool $isNewMatchesByNotif null;
  127.     #[ORM\Column(nullabletrue)]
  128.     #[Groups("profile")]
  129.     private ?bool $isNewMessagesByNotif null;
  130.     #[ORM\Column(length255nullabletrue)]
  131.     #[Groups("profile")]
  132.     private ?string $imageGallery1 null;
  133.     #[ORM\Column(length255nullabletrue)]
  134.     #[Groups("profile")]
  135.     private ?string $imageGallery2 null;
  136.     #[ORM\Column(length255nullabletrue)]
  137.     #[Groups("profile")]
  138.     private ?string $imageGallery3 null;
  139.     #[ORM\Column(length255nullabletrue)]
  140.     #[Groups("profile")]
  141.     private ?string $imageGallery4 null;
  142.     #[ORM\Column(length255nullabletrue)]
  143.     #[Groups("profile")]
  144.     private ?string $imageGallery5 null;
  145.     
  146.     public function __construct()
  147.     {
  148.     
  149.       
  150.         $this->langues = new ArrayCollection();
  151.         $this->matchs = new ArrayCollection();
  152.         $this->boosts = new ArrayCollection();
  153.         $this->galleries = new ArrayCollection();
  154.         $this->interests = new ArrayCollection();
  155.         $this->user = new User();
  156.         $this->answers = new ArrayCollection();
  157.         $this->askedMatches = new ArrayCollection();
  158.         $this->matchesByOthers = new ArrayCollection();
  159.         $this->setProfileTargetSetting(new ProfileTargetSetting());
  160.     }
  161.     
  162.     public function __toString()
  163.     {
  164.         if(!$this->firstName && !$this->lastName){
  165.             return (string)$this->getUser()->getEmail();
  166.         }
  167.         return (string)$this->firstName ." : ".(string)$this->getUser()->getEmail();
  168.     }
  169.     public function getId(): ?int
  170.     {
  171.         return $this->id;
  172.     }
  173.     public function getFirstName(): ?string
  174.     {
  175.         return $this->firstName;
  176.     }
  177.     public function setFirstName(?string $firstName): self
  178.     {
  179.         $this->firstName $firstName;
  180.         return $this;
  181.     }
  182.     public function getLastName(): ?string
  183.     {
  184.         return $this->lastName;
  185.     }
  186.     public function setLastName(?string $lastName): self
  187.     {
  188.         $this->lastName $lastName;
  189.         return $this;
  190.     }
  191.     public function getProfileImage(): ?string
  192.     {
  193.         return $this->profileImage;
  194.     }
  195.     public function setProfileImage(?string $profileImage): self
  196.     {
  197.         $this->profileImage $profileImage;
  198.         return $this;
  199.     }
  200.     public function getPhoneNumber(): ?string
  201.     {
  202.         return $this->phoneNumber;
  203.     }
  204.     public function setPhoneNumber(?string $phoneNumber): self
  205.     {
  206.         $this->phoneNumber $phoneNumber;
  207.         return $this;
  208.     }
  209.     public function getGender(): ?string
  210.     {
  211.         return $this->gender;
  212.     }
  213.     public function setGender(?string $gender): self
  214.     {
  215.         $this->gender $gender;
  216.         return $this;
  217.     }
  218.     public function getUser(): ?User
  219.     {
  220.         return $this->user;
  221.     }
  222.     public function setUser(?User $user): self
  223.     {
  224.         // unset the owning side of the relation if necessary
  225.         if ($user === null && $this->user !== null) {
  226.             $this->user->setProfile(null);
  227.         }
  228.         // set the owning side of the relation if necessary
  229.         if ($user !== null && $user->getProfile() !== $this) {
  230.             $user->setProfile($this);
  231.         }
  232.         $this->user $user;
  233.         return $this;
  234.     }
  235.     /**
  236.      * @return Collection<int, Langue>
  237.      */
  238.     public function getLangues(): Collection
  239.     {
  240.         return $this->langues;
  241.     }
  242.     public function addLangue(Langue $langue): self
  243.     {
  244.         if (!$this->langues->contains($langue)) {
  245.             $this->langues->add($langue);
  246.         }
  247.         return $this;
  248.        
  249.     }
  250.     public function removeLangue(Langue $langue): self
  251.     {
  252.         $this->langues->removeElement($langue);
  253.         return $this;
  254.     }
  255.     public function getProfession(): ?string
  256.     {
  257.         return $this->profession;
  258.     }
  259.     public function setProfession(?string $profession): self
  260.     {
  261.         $this->profession $profession;
  262.         return $this;
  263.     }
  264.     public function getBio(): ?string
  265.     {
  266.         return $this->bio;
  267.     }
  268.     public function setBio(?string $bio): self
  269.     {
  270.         $this->bio $bio;
  271.         return $this;
  272.     }
  273.     public function getPseudoName(): ?string
  274.     {
  275.         return $this->pseudoName;
  276.     }
  277.     public function setPseudoName(?string $pseudoName): self
  278.     {
  279.         $this->pseudoName $pseudoName;
  280.         return $this;
  281.     }
  282.     /**
  283.      * @return Collection<int, Gallery>
  284.      */
  285.     public function getGalleries(): Collection
  286.     {
  287.         return $this->galleries;
  288.     }
  289.     public function addGallery(Gallery $gallery): self
  290.     {
  291.         if (!$this->galleries->contains($gallery)) {
  292.             $this->galleries->add($gallery);
  293.             $gallery->setProfile($this);
  294.         }
  295.         return $this;
  296.     }
  297.     public function removeGallery(Gallery $gallery): self
  298.     {
  299.         if ($this->galleries->removeElement($gallery)) {
  300.             // set the owning side to null (unless already changed)
  301.             if ($gallery->getProfile() === $this) {
  302.                 $gallery->setProfile(null);
  303.             }
  304.         }
  305.         return $this;
  306.     }
  307.     /**
  308.      * @return Collection<int, Interest>
  309.      */
  310.     public function getInterests(): Collection
  311.     {
  312.         return $this->interests;
  313.     }
  314.     public function addInterest(Interest $interest): self
  315.     {
  316.         if (!$this->interests->contains($interest)) {
  317.             $this->interests->add($interest);
  318.         }
  319.         return $this;
  320.     }
  321.     public function removeInterest(Interest $interest): self
  322.     {
  323.         $this->interests->removeElement($interest);
  324.         return $this;
  325.     }
  326.     public function getAddress(): ?string
  327.     {
  328.         return $this->address;
  329.     }
  330.     public function setAddress(string $address): self
  331.     {
  332.         $this->address $address;
  333.         return $this;
  334.     }
  335.     public function getProfileTargetSetting(): ?ProfileTargetSetting
  336.     {
  337.         return $this->profileTargetSetting;
  338.     }
  339.     public function setProfileTargetSetting(?ProfileTargetSetting $profileTargetSetting): self
  340.     {
  341.         // unset the owning side of the relation if necessary
  342.         if ($profileTargetSetting === null && $this->profileTargetSetting !== null) {
  343.             $this->profileTargetSetting->setProfile(null);
  344.         }
  345.         // set the owning side of the relation if necessary
  346.         if ($profileTargetSetting !== null && $profileTargetSetting->getProfile() !== $this) {
  347.             $profileTargetSetting->setProfile($this);
  348.         }
  349.         $this->profileTargetSetting $profileTargetSetting;
  350.         return $this;
  351.     }
  352.     public function isIsVisible(): ?bool
  353.     {
  354.         return $this->isVisible;
  355.     }
  356.     public function setIsVisible(?bool $isVisible): self
  357.     {
  358.         $this->isVisible $isVisible;
  359.         return $this;
  360.     }
  361.     public function isIsDeleted(): ?bool
  362.     {
  363.         return $this->isDeleted;
  364.     }
  365.     public function setIsDeleted(?bool $isDeleted): self
  366.     {
  367.         $this->isDeleted $isDeleted;
  368.         return $this;
  369.     }
  370.     public function getLng(): ?string
  371.     {
  372.         return $this->lng;
  373.     }
  374.     public function setLng(?string $lng): self
  375.     {
  376.         $this->lng $lng;
  377.         return $this;
  378.     }
  379.     public function getLat(): ?string
  380.     {
  381.         return $this->lat;
  382.     }
  383.     public function setLat(?string $lat): self
  384.     {
  385.         $this->lat $lat;
  386.         return $this;
  387.     }
  388.     public function getEducationLevel(): ?string
  389.     {
  390.         return $this->educationLevel;
  391.     }
  392.     public function setEducationLevel(?string $educationLevel): self
  393.     {
  394.         $this->educationLevel $educationLevel;
  395.         return $this;
  396.     }
  397.     /**
  398.      * @return Collection<int, Answer>
  399.      */
  400.     public function getAnswers(): Collection
  401.     {
  402.         return $this->answers;
  403.     }
  404.     public function addAnswer(Answer $answer): self
  405.     {
  406.         if (!$this->answers->contains($answer)) {
  407.             $this->answers->add($answer);
  408.         }
  409.         return $this;
  410.     }
  411.     public function removeAnswer(Answer $answer): self
  412.     {
  413.         $this->answers->removeElement($answer);
  414.         return $this;
  415.     }
  416.     public function getBornAt(): ?\DateTimeInterface
  417.     {
  418.         return $this->bornAt;
  419.     }
  420.     public function setBornAt(?\DateTimeInterface $bornAt): self
  421.     {
  422.         $this->bornAt $bornAt;
  423.         return $this;
  424.     }
  425.     #[Groups("profile")]
  426.     public function getAge()
  427.     {
  428.         $bornAt $this->getBornAt();
  429.         $dateOfBirth $bornAt->format("Y-m-d");
  430.         $today date("Y-m-d");
  431.         $diff date_diff(date_create($today),date_create($dateOfBirth));
  432.         return (int)$diff->format('%y');
  433.     }
  434.     public function isIsSmoker(): ?bool
  435.     {
  436.         return $this->isSmoker;
  437.     }
  438.     public function setIsSmoker(?bool $isSmoker): self
  439.     {
  440.         $this->isSmoker $isSmoker;
  441.         return $this;
  442.     }
  443.     public function isIsDrinker(): ?bool
  444.     {
  445.         return $this->isDrinker;
  446.     }
  447.     public function setIsDrinker(?bool $isDrinker): self
  448.     {
  449.         $this->isDrinker $isDrinker;
  450.         return $this;
  451.     }
  452.     public function isHasKids(): ?bool
  453.     {
  454.         return $this->hasKids;
  455.     }
  456.     public function setHasKids(?bool $hasKids): self
  457.     {
  458.         $this->hasKids $hasKids;
  459.         return $this;
  460.     }
  461.     public function isIsDevorced(): ?bool
  462.     {
  463.         return $this->isDevorced;
  464.     }
  465.     public function setIsDevorced(?bool $isDevorced): self
  466.     {
  467.         $this->isDevorced $isDevorced;
  468.         return $this;
  469.     }
  470.     /**
  471.      * @return Collection<int, MatchProfile>
  472.      */
  473.     public function getAskedMatches(): Collection
  474.     {
  475.         return $this->askedMatches;
  476.     }
  477.     public function addAskedMatch(MatchProfile $askedMatch): self
  478.     {
  479.         if (!$this->askedMatches->contains($askedMatch)) {
  480.             $this->askedMatches->add($askedMatch);
  481.             $askedMatch->setProfileAskForMatch($this);
  482.         }
  483.         return $this;
  484.     }
  485.     public function removeAskedMatch(MatchProfile $askedMatch): self
  486.     {
  487.         if ($this->askedMatches->removeElement($askedMatch)) {
  488.             // set the owning side to null (unless already changed)
  489.             if ($askedMatch->getProfileAskForMatch() === $this) {
  490.                 $askedMatch->setProfileAskForMatch(null);
  491.             }
  492.         }
  493.         return $this;
  494.     }
  495.     /**
  496.      * @return Collection<int, MatchProfile>
  497.      */
  498.     public function getMatchesByOthers(): Collection
  499.     {
  500.         return $this->matchesByOthers;
  501.     }
  502.     public function addMatchesByOther(MatchProfile $matchesByOther): self
  503.     {
  504.         if (!$this->matchesByOthers->contains($matchesByOther)) {
  505.             $this->matchesByOthers->add($matchesByOther);
  506.             $matchesByOther->setProfileMatched($this);
  507.         }
  508.         return $this;
  509.     }
  510.     public function removeMatchesByOther(MatchProfile $matchesByOther): self
  511.     {
  512.         if ($this->matchesByOthers->removeElement($matchesByOther)) {
  513.             // set the owning side to null (unless already changed)
  514.             if ($matchesByOther->getProfileMatched() === $this) {
  515.                 $matchesByOther->setProfileMatched(null);
  516.             }
  517.         }
  518.         return $this;
  519.     }
  520.     public function isIsNewMatchesByEmail(): ?bool
  521.     {
  522.         return $this->isNewMatchesByEmail;
  523.     }
  524.     public function setIsNewMatchesByEmail(?bool $isNewMatchesByEmail): self
  525.     {
  526.         $this->isNewMatchesByEmail $isNewMatchesByEmail;
  527.         return $this;
  528.     }
  529.     public function isIsNewMessagesByEmail(): ?bool
  530.     {
  531.         return $this->isNewMessagesByEmail;
  532.     }
  533.     public function setIsNewMessagesByEmail(?bool $isNewMessagesByEmail): self
  534.     {
  535.         $this->isNewMessagesByEmail $isNewMessagesByEmail;
  536.         return $this;
  537.     }
  538.     public function isIsNewFeedsByEmail(): ?bool
  539.     {
  540.         return $this->isNewFeedsByEmail;
  541.     }
  542.     public function setIsNewFeedsByEmail(?bool $isNewFeedsByEmail): self
  543.     {
  544.         $this->isNewFeedsByEmail $isNewFeedsByEmail;
  545.         return $this;
  546.     }
  547.     public function isIsNewMatchesByNotif(): ?bool
  548.     {
  549.         return $this->isNewMatchesByNotif;
  550.     }
  551.     public function setIsNewMatchesByNotif(?bool $isNewMatchesByNotif): self
  552.     {
  553.         $this->isNewMatchesByNotif $isNewMatchesByNotif;
  554.         return $this;
  555.     }
  556.     public function isIsNewMessagesByNotif(): ?bool
  557.     {
  558.         return $this->isNewMessagesByNotif;
  559.     }
  560.     public function setIsNewMessagesByNotif(?bool $isNewMessagesByNotif): self
  561.     {
  562.         $this->isNewMessagesByNotif $isNewMessagesByNotif;
  563.         return $this;
  564.     }
  565.     public function getImageGallery1(): ?string
  566.     {
  567.         return $this->imageGallery1;
  568.     }
  569.     public function setImageGallery1(?string $imageGallery1): self
  570.     {
  571.         $this->imageGallery1 $imageGallery1;
  572.         return $this;
  573.     }
  574.     public function getImageGallery2(): ?string
  575.     {
  576.         return $this->imageGallery2;
  577.     }
  578.     public function setImageGallery2(?string $imageGallery2): self
  579.     {
  580.         $this->imageGallery2 $imageGallery2;
  581.         return $this;
  582.     }
  583.     public function getImageGallery3(): ?string
  584.     {
  585.         return $this->imageGallery3;
  586.     }
  587.     public function setImageGallery3(?string $imageGallery3): self
  588.     {
  589.         $this->imageGallery3 $imageGallery3;
  590.         return $this;
  591.     }
  592.     public function getImageGallery4(): ?string
  593.     {
  594.         return $this->imageGallery4;
  595.     }
  596.     public function setImageGallery4(?string $imageGallery4): self
  597.     {
  598.         $this->imageGallery4 $imageGallery4;
  599.         return $this;
  600.     }
  601.     public function getImageGallery5(): ?string
  602.     {
  603.         return $this->imageGallery5;
  604.     }
  605.     public function setImageGallery5(?string $imageGallery5): self
  606.     {
  607.         $this->imageGallery5 $imageGallery5;
  608.         return $this;
  609.     }
  610. #[Groups("profile")]
  611.     public function getCompletionProfilePercentage(){
  612.         
  613.         $percentage 0;
  614.         
  615.         $value 9.09
  616.         if($this->pseudoName){
  617.             $percentage $percentage +   $value;
  618.         }
  619.         if($this->gender){
  620.             $percentage $percentage +   $value;
  621.         }
  622.         if($this->profileImage){
  623.             $percentage $percentage +   $value;
  624.         }
  625.         if($this->profession){
  626.             $percentage $percentage +   $value;
  627.         }
  628.         if($this->educationLevel){
  629.             $percentage $percentage +   $value;
  630.         }
  631.         if($this->bio){
  632.             $percentage $percentage +   $value;
  633.         }
  634.         if($this->address){
  635.             $percentage $percentage +   $value;
  636.         }
  637.         
  638.         if($this->lng and $this->lat){
  639.             $percentage $percentage +   $value;
  640.         }
  641.         
  642.         if($this->bornAt){
  643.             $percentage $percentage +   $value;
  644.         }
  645.         
  646.         if(count($this->langues) > 0){
  647.             $percentage $percentage +   $value;
  648.         }
  649.         if(count($this->interests) > 0){
  650.             $percentage $percentage +   $value;
  651.         }
  652.         
  653.         return round($percentage0PHP_ROUND_HALF_UP);
  654.     }
  655.     
  656.     
  657.     #[Groups("profile")]
  658.     public function getMatchingAnswers(): Collection{
  659.         
  660.         
  661.        return $this->answers->matching(AnswerRepository::findMatchedAnswers($this));
  662.     }
  663.     
  664.    
  665. }