src/Entity/Account/Customer.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Account;
  3. use App\Entity\Profile\Comment\CommentByCustomer;
  4. use App\Entity\Profile\Profile;
  5. use App\Entity\User;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. #[ORM\Entity]
  10. class Customer extends User
  11. {
  12.     public const ROLE_CUSTOMER 'ROLE_CUSTOMER';
  13.     #[ORM\OneToOne(targetEntityCommentBan::class, mappedBy'user'cascade: ['all'], orphanRemovaltrue)]
  14.     private ?CommentBan $commentBan null;
  15.     #[ORM\OneToOne(targetEntityCustomerProfilePreference::class, mappedBy'user'cascade: ['all'], orphanRemovaltrue)]
  16.     private ?CustomerProfilePreference $profilePreference null;
  17.     #[ORM\OneToOne(targetEntityCustomerPreferredProfilesData::class, mappedBy'user'cascade: ['all'], orphanRemovaltrue)]
  18.     private ?CustomerPreferredProfilesData $preferredProfilesData null;
  19.     /** @var UserFavourite[] */
  20.     #[ORM\OneToMany(targetEntityUserFavourite::class, mappedBy'user'cascade: ['all'], orphanRemovaltrue)]
  21.     private Collection $favourites;
  22.     /** @var CommentByCustomer[]  */
  23.     #[ORM\OneToMany(targetEntityCommentByCustomer::class, mappedBy'user'cascade: ['all'], orphanRemovaltrue)]
  24.     private Collection $profileComments;
  25.     /** @var \App\Entity\Saloon\Comment\CommentByCustomer[]  */
  26.     #[ORM\OneToMany(targetEntity\App\Entity\Saloon\Comment\CommentByCustomer::class, mappedBy'user'cascade: ['all'], orphanRemovaltrue)]
  27.     private Collection $saloonComments;
  28.     public function __construct()
  29.     {
  30.         parent::__construct();
  31.         $this->favourites = new ArrayCollection();
  32.         $this->profileComments = new ArrayCollection();
  33.         $this->saloonComments = new ArrayCollection();
  34.         $this->setRoles(array_merge($this->getRoles(), [self::ROLE_CUSTOMER]));
  35.     }
  36.     public function getProfilePreference(): ?CustomerProfilePreference
  37.     {
  38.         return $this->profilePreference;
  39.     }
  40.     public function setProfilePreference(?CustomerProfilePreference $profilePreference): void
  41.     {
  42.         $this->profilePreference $profilePreference;
  43.     }
  44.     public function getPreferredProfilesData(): ?CustomerPreferredProfilesData
  45.     {
  46.         return $this->preferredProfilesData;
  47.     }
  48.     public function setPreferredProfilesData(?CustomerPreferredProfilesData $preferredProfilesData): void
  49.     {
  50.         $this->preferredProfilesData $preferredProfilesData;
  51.     }
  52.     /**
  53.      * @return UserFavourite[]
  54.      */
  55.     public function getFavourites(): Collection
  56.     {
  57.         return $this->favourites;
  58.     }
  59.     /**
  60.      * @return UserFavourite[]
  61.      */
  62.     public function getProfileFavourites(): Collection
  63.     {
  64.         return $this->favourites->filter(function(UserFavourite $userFavourite): bool {
  65.             return ($userFavourite instanceof FavouriteProfile);
  66.         });
  67.     }
  68.     public function findProfileInFavourites(Profile $profile): ?FavouriteProfile
  69.     {
  70.         $filtered $this->favourites->filter(function(UserFavourite $userFavourite) use ($profile): bool {
  71.             return ($userFavourite instanceof FavouriteProfile && $userFavourite->getProfile()->getId() == $profile->getId());
  72.         });
  73.         return $filtered->count() ? $filtered->getValues()[0] : null;
  74.     }
  75.     public function addToFavourites(Profile $profile): void
  76.     {
  77.         if(null != $this->findProfileInFavourites($profile))
  78.             return;
  79.         $res $this->favourites->add(new FavouriteProfile($this$profile));
  80.     }
  81.     public function removeFromFavourites(Profile $profile): void
  82.     {
  83.         if(null == $favouriteProfile $this->findProfileInFavourites($profile))
  84.             return;
  85.         $this->favourites->removeElement($favouriteProfile);
  86.     }
  87.     /**
  88.      * @return CommentByCustomer[]
  89.      */
  90.     public function getProfileComments(): Collection
  91.     {
  92.         return $this->profileComments;
  93.     }
  94.     /**
  95.      * @return \App\Entity\Saloon\Comment\CommentByCustomer[]
  96.      */
  97.     public function getSaloonComments(): Collection
  98.     {
  99.         return $this->saloonComments;
  100.     }
  101.     public function getCommentBan(): ?CommentBan
  102.     {
  103.         return $this->commentBan;
  104.     }
  105.     public function setCommentBan(?CommentBan $commentBan): void
  106.     {
  107.         $this->commentBan $commentBan;
  108.     }
  109. }