src/Repository/ProfileRepository.php line 149

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by simpson <simpsonwork@gmail.com>
  4.  * Date: 2019-03-19
  5.  * Time: 22:23
  6.  */
  7. namespace App\Repository;
  8. use App\Entity\Location\City;
  9. use App\Entity\Location\MapCoordinate;
  10. use App\Entity\Profile\Genders;
  11. use App\Entity\Profile\Photo;
  12. use App\Entity\Profile\Profile;
  13. use App\Entity\Sales\Profile\AdBoardPlacement;
  14. use App\Entity\Sales\Profile\AdBoardPlacementType;
  15. use App\Entity\Sales\Profile\PlacementHiding;
  16. use App\Entity\User;
  17. use App\Repository\ReadModel\CityReadModel;
  18. use App\Repository\ReadModel\ProfileApartmentPricingReadModel;
  19. use App\Repository\ReadModel\ProfileListingReadModel;
  20. use App\Repository\ReadModel\ProfileMapReadModel;
  21. use App\Repository\ReadModel\ProfilePersonParametersReadModel;
  22. use App\Repository\ReadModel\ProfilePlacementHidingDetailReadModel;
  23. use App\Repository\ReadModel\ProfilePlacementPriceDetailReadModel;
  24. use App\Repository\ReadModel\ProfileTakeOutPricingReadModel;
  25. use App\Repository\ReadModel\ProvidedServiceReadModel;
  26. use App\Repository\ReadModel\StationLineReadModel;
  27. use App\Repository\ReadModel\StationReadModel;
  28. use App\Service\Features;
  29. use App\Specification\Profile\ProfileIdINOrderedByINValues;
  30. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  31. use Doctrine\ORM\AbstractQuery;
  32. use Doctrine\Persistence\ManagerRegistry;
  33. use Doctrine\DBAL\Statement;
  34. use Doctrine\ORM\QueryBuilder;
  35. use Happyr\DoctrineSpecification\Filter\Filter;
  36. use Happyr\DoctrineSpecification\Query\QueryModifier;
  37. use Porpaginas\Doctrine\ORM\ORMQueryResult;
  38. class ProfileRepository extends ServiceEntityRepository
  39. {
  40.     use SpecificationTrait;
  41.     use EntityIteratorTrait;
  42.     private Features $features;
  43.     public function __construct(ManagerRegistry $registryFeatures $features)
  44.     {
  45.         parent::__construct($registryProfile::class);
  46.         $this->features $features;
  47.     }
  48.     /**
  49.      * Возвращает итератор по данным, необходимым для генерации файлов sitemap, в виде массивов с
  50.      * следующими ключами:
  51.      *  - id
  52.      *  - uri
  53.      *  - updatedAt
  54.      *  - city_uri
  55.      *
  56.      * @return iterable<array{id: int, uri: string, updatedAt: \DateTimeImmutable, city_uri: string}>
  57.      */
  58.     public function sitemapItemsIterator(): iterable
  59.     {
  60.         $qb $this->createQueryBuilder('profile')
  61.             ->select('profile.id, profile.uriIdentity AS uri, profile.updatedAt, city.uriIdentity AS city_uri')
  62.             ->join('profile.city''city')
  63.             ->andWhere('profile.deletedAt IS NULL');
  64.         $this->addModerationFilterToQb($qb'profile');
  65.         return $qb->getQuery()->toIterable([], AbstractQuery::HYDRATE_ARRAY);
  66.     }
  67.     protected function modifyListingQueryBuilder(QueryBuilder $qbstring $alias): void
  68.     {
  69.         $qb
  70.             ->addSelect('city')
  71.             ->addSelect('station')
  72.             ->addSelect('photo')
  73.             ->addSelect('video')
  74.             ->addSelect('comment')
  75.             ->addSelect('avatar')
  76.             ->join(sprintf('%s.city'$alias), 'city')
  77.         ;
  78.         if(!in_array('station'$qb->getAllAliases()))
  79.             $qb->leftJoin(sprintf('%s.stations'$alias), 'station');
  80.         if(!in_array('photo'$qb->getAllAliases()))
  81.             $qb->leftJoin(sprintf('%s.photos'$alias), 'photo');
  82.         if(!in_array('video'$qb->getAllAliases()))
  83.             $qb->leftJoin(sprintf('%s.videos'$alias), 'video');
  84.         if(!in_array('avatar'$qb->getAllAliases()))
  85.             $qb->leftJoin(sprintf('%s.avatar'$alias), 'avatar');
  86.         if(!in_array('comment'$qb->getAllAliases()))
  87.             $qb->leftJoin(sprintf('%s.comments'$alias), 'comment');
  88.         $this->addFemaleGenderFilterToQb($qb$alias);
  89.         //TODO убрать, если все ок
  90.         //$this->excludeHavingPlacementHiding($qb, $alias);
  91.         if (!in_array('profile_adboard_placement'$qb->getAllAliases())) {
  92.             $qb
  93.                 ->leftJoin(sprintf('%s.adBoardPlacement'$alias), 'profile_adboard_placement')
  94.             ;
  95.         }
  96.         $qb->addSelect('profile_adboard_placement');
  97.         if (!in_array('profile_top_placement'$qb->getAllAliases())) {
  98.             $qb
  99.                 ->leftJoin(sprintf('%s.topPlacements'$alias), 'profile_top_placement')
  100.             ;
  101.         }
  102.         $qb->addSelect('profile_top_placement');
  103.         //if($this->features->free_profiles()) {
  104.             if (!in_array('placement_hiding'$qb->getAllAliases())) {
  105.                 $qb
  106.                     ->leftJoin(sprintf('%s.placementHiding'$alias), 'placement_hiding');
  107.             }
  108.             $qb->addSelect('placement_hiding');
  109.         //}
  110.     }
  111.     public function ofUriIdentityWithinCity(string $uriIdentityCity $city): ?Profile
  112.     {
  113.         return $this->findOneBy([
  114.             'uriIdentity' => $uriIdentity,
  115.             'city' => $city,
  116.         ]);
  117.     }
  118.     /**
  119.      * Метод проверки уникальности анкет по URI не должен использовать никаких фильтров, кроме URI и города,
  120.      * поэтому QueryBuilder не используется
  121.      * @see https://redminez.net/issues/27310
  122.      */
  123.     public function isUniqueUriIdentityExistWithinCity(string $uriIdentityCity $city): bool
  124.     {
  125.         $connection $this->_em->getConnection();
  126.         $stmt $connection->executeQuery('SELECT COUNT(id) FROM profiles WHERE uri_identity = ? AND city_id = ?', [$uriIdentity$city->getId()]);
  127.         $count $stmt->fetchOne();
  128.         return $count 0;
  129.     }
  130.     public function countByCity(): array
  131.     {
  132.         $qb $this->createQueryBuilder('profile')
  133.             ->select('IDENTITY(profile.city), COUNT(profile.id)')
  134.             ->groupBy('profile.city')
  135.         ;
  136.         $this->addFemaleGenderFilterToQb($qb'profile');
  137.         $this->addModerationFilterToQb($qb'profile');
  138.         //$this->excludeHavingPlacementHiding($qb, 'profile');
  139.         $this->havingAdBoardPlacement($qb'profile');
  140.         $query $qb->getQuery()
  141.             ->useResultCache(true)
  142.             ->setResultCacheLifetime(120)
  143.         ;
  144.         $rawResult $query->getScalarResult();
  145.         $indexedResult = [];
  146.         foreach ($rawResult as $row) {
  147.             $indexedResult[$row[1]] = $row[2];
  148.         }
  149.         return $indexedResult;
  150.     }
  151.     public function countByStations(): array
  152.     {
  153.         $qb $this->createQueryBuilder('profiles')
  154.             ->select('stations.id, COUNT(profiles.id) as cnt')
  155.             ->join('profiles.stations''stations')
  156.             //это условие сильно затормжаживает запрос, но оно и не нужно при условии, что чужих(от других городов) станций у анкеты нет
  157.             //->where('profiles.city = stations.city')
  158.             ->groupBy('stations.id')
  159.         ;
  160.         $this->addFemaleGenderFilterToQb($qb'profiles');
  161.         $this->addModerationFilterToQb($qb'profiles');
  162.         //$this->excludeHavingPlacementHiding($qb, 'profiles');
  163.         $this->havingAdBoardPlacement($qb'profiles');
  164.         $query $qb->getQuery()
  165.             ->useResultCache(true)
  166.             ->setResultCacheLifetime(120)
  167.         ;
  168.         $rawResult $query->getScalarResult();
  169.         $indexedResult = [];
  170.         foreach ($rawResult as $row) {
  171.             $indexedResult[$row['id']] = $row['cnt'];
  172.         }
  173.         return $indexedResult;
  174.     }
  175.     public function countByDistricts(): array
  176.     {
  177.         $qb $this->createQueryBuilder('profiles')
  178.             ->select('districts.id, COUNT(profiles.id) as cnt')
  179.             ->join('profiles.stations''stations')
  180.             ->join('stations.district''districts')
  181.             ->groupBy('districts.id')
  182.         ;
  183.         $this->addFemaleGenderFilterToQb($qb'profiles');
  184.         $this->addModerationFilterToQb($qb'profiles');
  185.         //$this->excludeHavingPlacementHiding($qb, 'profiles');
  186.         $this->havingAdBoardPlacement($qb'profiles');
  187.         $query $qb->getQuery()
  188.             ->useResultCache(true)
  189.             ->setResultCacheLifetime(120)
  190.         ;
  191.         $rawResult $query->getScalarResult();
  192.         $indexedResult = [];
  193.         foreach ($rawResult as $row) {
  194.             $indexedResult[$row['id']] = $row['cnt'];
  195.         }
  196.         return $indexedResult;
  197.     }
  198.     public function countByCounties(): array
  199.     {
  200.         $qb $this->createQueryBuilder('profiles')
  201.             ->select('counties.id, COUNT(profiles.id) as cnt')
  202.             ->join('profiles.stations''stations')
  203.             ->join('stations.district''districts')
  204.             ->join('districts.county''counties')
  205.             ->groupBy('counties.id')
  206.         ;
  207.         $this->addFemaleGenderFilterToQb($qb'profiles');
  208.         $this->addModerationFilterToQb($qb'profiles');
  209.         //$this->excludeHavingPlacementHiding($qb, 'profiles');
  210.         $this->havingAdBoardPlacement($qb'profiles');
  211.         $query $qb->getQuery()
  212.             ->useResultCache(true)
  213.             ->setResultCacheLifetime(120)
  214.         ;
  215.         $rawResult $query->getScalarResult();
  216.         $indexedResult = [];
  217.         foreach ($rawResult as $row) {
  218.             $indexedResult[$row['id']] = $row['cnt'];
  219.         }
  220.         return $indexedResult;
  221.     }
  222.     /**
  223.      * @param array|int[] $ids
  224.      * @return Profile[]
  225.      */
  226.     public function findByIds(array $ids): array
  227.     {
  228.         return $this->createQueryBuilder('profile')
  229.             ->andWhere('profile.id IN (:ids)')
  230.             ->setParameter('ids'$ids)
  231.             ->orderBy('FIELD(profile.id,:ids2)')
  232.             ->setParameter('ids2'$ids)
  233.             ->getQuery()
  234.             ->getResult();
  235.     }
  236.     public function findByIdsIterate(array $ids): iterable
  237.     {
  238.         $qb $this->createQueryBuilder('profile')
  239.             ->andWhere('profile.id IN (:ids)')
  240.             ->setParameter('ids'$ids)
  241.             ->orderBy('FIELD(profile.id,:ids2)')
  242.             ->setParameter('ids2'$ids);
  243.         return $this->iterateQueryBuilder($qb);
  244.     }
  245.     /**
  246.      * Список анкет указанного типа (массажистки или нет), привязанных к аккаунту
  247.      */
  248.     public function ofOwnerAndTypePaged(User $ownerbool $masseurs): ORMQueryResult
  249.     {
  250.         $qb $this->createQueryBuilder('profile')
  251.             ->andWhere('profile.owner = :owner')
  252.             ->setParameter('owner'$owner)
  253.             ->andWhere('profile.masseur = :is_masseur')
  254.             ->setParameter('is_masseur'$masseurs)
  255.         ;
  256.         return new ORMQueryResult($qb);
  257.     }
  258.     /**
  259.      * Список активных анкет, привязанных к аккаунту
  260.      */
  261.     public function activeAndOwnedBy(User $owner): ORMQueryResult
  262.     {
  263.         $qb $this->createQueryBuilder('profile')
  264.             ->join('profile.adBoardPlacement''profile_adboard_placement')
  265.             ->andWhere('profile.owner = :owner')
  266.             ->setParameter('owner'$owner)
  267.         ;
  268.         return new ORMQueryResult($qb);
  269.     }
  270.     /**
  271.      * Список активных или скрытых анкет, привязанных к аккаунту
  272.      *
  273.      * @return Profile[]|ORMQueryResult
  274.      */
  275.     public function activeOrHiddenAndOwnedBy(User $owner): ORMQueryResult
  276.     {
  277.         $qb $this->createQueryBuilder('profile')
  278.             ->join('profile.adBoardPlacement''profile_adboard_placement')
  279. //            ->leftJoin('profile.placementHiding', 'placement_hiding')
  280. //            ->andWhere('profile_adboard_placement IS NOT NULL OR placement_hiding IS NOT NULL')
  281.             ->andWhere('profile.owner = :owner')
  282.             ->setParameter('owner'$owner)
  283.         ;
  284. //        return $this->iterateQueryBuilder($qb);
  285.         return new ORMQueryResult($qb);
  286.     }
  287.     public function countFreeUnapprovedLimited(): int
  288.     {
  289.         $qb $this->createQueryBuilder('profile')
  290.             ->select('count(profile)')
  291.             ->join('profile.adBoardPlacement''placement')
  292.             ->andWhere('placement.type = :placement_type')
  293.             ->setParameter('placement_type'AdBoardPlacementType::FREE)
  294.             ->leftJoin('profile.placementHiding''hiding')
  295.             ->andWhere('hiding IS NULL')
  296.             ->andWhere('profile.approved = false')
  297.         ;
  298.         return (int)$qb->getQuery()->getSingleScalarResult();
  299.     }
  300.     public function iterateFreeUnapprovedLimited(int $limit): iterable
  301.     {
  302.         $qb $this->createQueryBuilder('profile')
  303.             ->join('profile.adBoardPlacement''placement')
  304.             ->andWhere('placement.type = :placement_type')
  305.             ->setParameter('placement_type'AdBoardPlacementType::FREE)
  306.             ->leftJoin('profile.placementHiding''hiding')
  307.             ->andWhere('hiding IS NULL')
  308.             ->andWhere('profile.approved = false')
  309.             ->setMaxResults($limit)
  310.         ;
  311.         return $this->iterateQueryBuilder($qb);
  312.     }
  313.     /**
  314.      * Число активных анкет, привязанных к аккаунту
  315.      */
  316.     public function countActiveOfOwner(User $owner, ?bool $isMasseur false): int
  317.     {
  318.         $qb $this->createQueryBuilder('profile')
  319.             ->select('COUNT(profile.id)')
  320.             ->join('profile.adBoardPlacement''profile_adboard_placement')
  321.             ->andWhere('profile.owner = :owner')
  322.             ->setParameter('owner'$owner)
  323.         ;
  324.         if($this->features->hard_moderation()) {
  325.             $qb->leftJoin('profile.owner''owner');
  326.             $qb->andWhere(
  327.                 $qb->expr()->orX(
  328.                     'profile.moderationStatus = :status_passed',
  329.                     $qb->expr()->andX(
  330.                         'profile.moderationStatus = :status_waiting',
  331.                         'owner.trusted = true'
  332.                     )
  333.                 )
  334.             );
  335.             $qb->setParameter('status_passed'Profile::MODERATION_STATUS_APPROVED);
  336.             $qb->setParameter('status_waiting'Profile::MODERATION_STATUS_WAITING);
  337.         } else {
  338.             $qb->andWhere('profile.moderationStatus IN (:statuses)')
  339.                 ->setParameter('statuses', [Profile::MODERATION_STATUS_NOT_PASSEDProfile::MODERATION_STATUS_WAITINGProfile::MODERATION_STATUS_APPROVED]);
  340.         }
  341.         if(null !== $isMasseur) {
  342.             $qb->andWhere('profile.masseur = :is_masseur')
  343.                 ->setParameter('is_masseur'$isMasseur);
  344.         }
  345.         return (int)$qb->getQuery()->getSingleScalarResult();
  346.     }
  347.     /**
  348.      * Число всех анкет, привязанных к аккаунту
  349.      */
  350.     public function countAllOfOwnerNotDeleted(User $owner, ?bool $isMasseur false): int
  351.     {
  352.         $qb $this->createQueryBuilder('profile')
  353.             ->select('COUNT(profile.id)')
  354.             ->andWhere('profile.owner = :owner')
  355.             ->setParameter('owner'$owner)
  356.             //потому что используется в т.ч. на тех страницах, где отключен фильтр вывода "только неудаленных"
  357.             ->andWhere('profile.deletedAt IS NULL')
  358.             ;
  359.         if(null !== $isMasseur) {
  360.             $qb->andWhere('profile.masseur = :is_masseur')
  361.                 ->setParameter('is_masseur'$isMasseur);
  362.         }
  363.         return (int)$qb->getQuery()->getSingleScalarResult();
  364.     }
  365.     public function getTimezonesListByUser(User $owner): array
  366.     {
  367.         $q $this->_em->createQuery(sprintf("
  368.                 SELECT c
  369.                 FROM %s c
  370.                 WHERE c.id IN (
  371.                     SELECT DISTINCT(c2.id) 
  372.                     FROM %s p
  373.                     JOIN p.city c2
  374.                     WHERE p.owner = :user
  375.                 )
  376.             "$this->_em->getClassMetadata(City::class)->name$this->_em->getClassMetadata(Profile::class)->name))
  377.             ->setParameter('user'$owner);
  378.         return $q->getResult();
  379.     }
  380.     /**
  381.      * Список анкет, привязанных к аккаунту
  382.      *
  383.      * @return Profile[]
  384.      */
  385.     public function ofOwner(User $owner): array
  386.     {
  387.         $qb $this->createQueryBuilder('profile')
  388.             ->andWhere('profile.owner = :owner')
  389.             ->setParameter('owner'$owner)
  390.         ;
  391.         return $qb->getQuery()->getResult();
  392.     }
  393.     public function ofOwnerPaged(User $owner, array $genders = [Genders::FEMALE]): ORMQueryResult
  394.     {
  395.         $qb $this->createQueryBuilder('profile')
  396.             ->andWhere('profile.owner = :owner')
  397.             ->setParameter('owner'$owner)
  398.             ->andWhere('profile.personParameters.gender IN (:genders)')
  399.             ->setParameter('genders'$genders)
  400.         ;
  401.         return new ORMQueryResult($qb);
  402.     }
  403.     public function ofOwnerAndMasseurTypeWithPlacementFilterAndNameFilterIterateAll(User $ownerstring $placementTypeFilter, ?string $nameFilter, ?bool $isMasseur null): \Generator
  404.     {
  405.         $query $this->queryBuilderOfOwnerAndMasseurTypeWithPlacementFilterAndNameFilter($owner$placementTypeFilter$nameFilter$isMasseur)->getQuery();
  406.         foreach ($query->iterate() as $row) {
  407.             yield $row[0];
  408.         }
  409.     }
  410.     public function ofOwnerAndMasseurTypeWithPlacementFilterAndNameFilterPaged(User $ownerstring $placementTypeFilter, ?string $nameFilter, ?bool $isMasseur null): ORMQueryResult
  411.     {
  412.         $qb $this->queryBuilderOfOwnerAndMasseurTypeWithPlacementFilterAndNameFilter($owner$placementTypeFilter$nameFilter$isMasseur);
  413.         //сортируем анкеты по статусу UltraVip->Vip->Standard->Free->Hidden
  414.         $aliases $qb->getAllAliases();
  415.         if(false == in_array('placement'$aliases))
  416.             $qb->leftJoin('profile.adBoardPlacement''placement');
  417.         if(false == in_array('placement_hiding'$aliases))
  418.             $qb->leftJoin('profile.placementHiding''placement_hiding');
  419.         $qb->addSelect('IF(placement_hiding.id IS NULL, 0, 1) as HIDDEN is_hidden');
  420.         $qb->addOrderBy('placement.type''DESC');
  421.         $qb->addOrderBy('placement.placedAt''DESC');
  422.         $qb->addOrderBy('is_hidden''ASC');
  423.         return new ORMQueryResult($qb);
  424.     }
  425.     public function idsOfOwnerAndMasseurTypeWithPlacementFilterAndNameFilter(User $ownerstring $placementTypeFilter, ?string $nameFilter, ?bool $isMasseur null): array
  426.     {
  427.         $qb $this->queryBuilderOfOwnerAndMasseurTypeWithPlacementFilterAndNameFilter($owner$placementTypeFilter$nameFilter$isMasseur);
  428.         $qb->select('profile.id');
  429.         return $qb->getQuery()->getResult('column_hydrator');
  430.     }
  431.     public function countOfOwnerAndMasseurTypeWithPlacementFilterAndNameFilter(User $ownerstring $placementTypeFilter, ?string $nameFilter, ?bool $isMasseur null): int
  432.     {
  433.         $qb $this->queryBuilderOfOwnerAndMasseurTypeWithPlacementFilterAndNameFilter($owner$placementTypeFilter$nameFilter$isMasseur);
  434.         $qb->select('count(profile.id)')
  435.             ->setMaxResults(1);
  436.         return (int)$qb->getQuery()->getSingleScalarResult();
  437.     }
  438.     private function queryBuilderOfOwnerAndMasseurTypeWithPlacementFilterAndNameFilter(User $ownerstring $placementTypeFilter, ?string $nameFilter, ?bool $isMasseur null): QueryBuilder
  439.     {
  440.         $qb $this->createQueryBuilder('profile')
  441.             ->andWhere('profile.owner = :owner')
  442.             ->setParameter('owner'$owner)
  443.         ;
  444.         switch ($placementTypeFilter) {
  445.             case 'paid':
  446.                 $qb->join('profile.adBoardPlacement''placement')
  447.                     ->andWhere('placement.type != :placement_type')
  448.                     ->setParameter('placement_type'AdBoardPlacementType::FREE);
  449.                 break;
  450.             case 'free':
  451.                 $qb->join('profile.adBoardPlacement''placement')
  452.                     ->andWhere('placement.type = :placement_type')
  453.                     ->setParameter('placement_type'AdBoardPlacementType::FREE);
  454.                 break;
  455.             case 'ultra-vip':
  456.                 $qb->join('profile.adBoardPlacement''placement')
  457.                     ->andWhere('placement.type = :placement_type')
  458.                     ->setParameter('placement_type'AdBoardPlacementType::ULTRA_VIP);
  459.                 break;
  460.             case 'vip':
  461.                 $qb->join('profile.adBoardPlacement''placement')
  462.                     ->andWhere('placement.type = :placement_type')
  463.                     ->setParameter('placement_type'AdBoardPlacementType::VIP);
  464.                 break;
  465.             case 'standard':
  466.                 $qb->join('profile.adBoardPlacement''placement')
  467.                     ->andWhere('placement.type = :placement_type')
  468.                     ->setParameter('placement_type'AdBoardPlacementType::STANDARD);
  469.                 break;
  470.             case 'hidden':
  471.                 $qb->join('profile.placementHiding''placement_hiding');
  472.                 break;
  473.             case 'all':
  474.             default:
  475.                 break;
  476.         }
  477.         if($nameFilter) {
  478.             $nameExpr $qb->expr()->orX(
  479.                 'LOWER(JSON_UNQUOTE(JSON_EXTRACT(profile.name, :jsonPath))) LIKE :name_filter',
  480.                 \sprintf("REGEXP_REPLACE(profile.phoneNumber, '-| ', '') LIKE :name_filter"),
  481.                 'LOWER(profile.phoneNumber) LIKE :name_filter',
  482.                 \sprintf("REGEXP_REPLACE(profile.phoneNumber, '\+7', '8') LIKE :name_filter"),
  483.             );
  484.             $qb->setParameter('jsonPath''$.ru');
  485.             $qb->setParameter('name_filter''%'.addcslashes(mb_strtolower(str_replace(['('')'' ''-'], ''$nameFilter)), '%_').'%');
  486.             $qb->andWhere($nameExpr);
  487.         }
  488.         if(null !== $isMasseur) {
  489.             $qb->andWhere('profile.masseur = :is_masseur')
  490.                 ->setParameter('is_masseur'$isMasseur);
  491.         }
  492.         return $qb;
  493.     }
  494.     private function excludeHavingPlacementHiding(QueryBuilder $qb$alias): void
  495.     {
  496.         if($this->features->free_profiles()) {
  497. //            if (!in_array('placement_hiding', $qb->getAllAliases())) {
  498. //                $qb
  499. //                    ->leftJoin(sprintf('%s.placementHiding', $alias), 'placement_hiding')
  500. //                    ->andWhere(sprintf('placement_hiding IS NULL'))
  501. //                ;
  502. //        }
  503.         $sub = new QueryBuilder($qb->getEntityManager());
  504.         $sub->select("exclude_hidden_placement_hiding");
  505.         $sub->from($qb->getEntityManager()->getClassMetadata(PlacementHiding::class)->name,"exclude_hidden_placement_hiding");
  506.         $sub->andWhere(sprintf('exclude_hidden_placement_hiding.profile = %s'$alias));
  507.         $qb->andWhere($qb->expr()->not($qb->expr()->exists($sub->getDQL())));
  508.         }
  509.     }
  510.     private function havingAdBoardPlacement(QueryBuilder $qbstring $alias): void
  511.     {
  512.         $qb->join(sprintf('%s.adBoardPlacement'$alias), 'adboard_placement');
  513.     }
  514.     /**
  515.      * @deprecated
  516.      */
  517.     public function hydrateProfileRow(array $row): ProfileListingReadModel
  518.     {
  519.         $profile = new ProfileListingReadModel();
  520.         $profile->id $row['id'];
  521.         $profile->city $row['city'];
  522.         $profile->uriIdentity $row['uriIdentity'];
  523.         $profile->name $row['name'];
  524.         $profile->description $row['description'];
  525.         $profile->phoneNumber $row['phoneNumber'];
  526.         $profile->approved $row['approved'];
  527.         $now = new \DateTimeImmutable('now');
  528.         $hasRunningTopPlacement false;
  529.         foreach ($row['topPlacements'] as $topPlacement) {
  530.             if($topPlacement['placedAt'] <= $now && $now <= $topPlacement['expiresAt'])
  531.                 $hasRunningTopPlacement true;
  532.         }
  533.         $profile->active null !== $row['adBoardPlacement'] || $hasRunningTopPlacement;
  534.         $profile->hidden null != $row['placementHiding'];
  535.         $profile->personParameters = new ProfilePersonParametersReadModel();
  536.         $profile->personParameters->age $row['personParameters.age'];
  537.         $profile->personParameters->height $row['personParameters.height'];
  538.         $profile->personParameters->weight $row['personParameters.weight'];
  539.         $profile->personParameters->breastSize $row['personParameters.breastSize'];
  540.         $profile->personParameters->bodyType $row['personParameters.bodyType'];
  541.         $profile->personParameters->hairColor $row['personParameters.hairColor'];
  542.         $profile->personParameters->privateHaircut $row['personParameters.privateHaircut'];
  543.         $profile->personParameters->nationality $row['personParameters.nationality'];
  544.         $profile->personParameters->hasTattoo $row['personParameters.hasTattoo'];
  545.         $profile->personParameters->hasPiercing $row['personParameters.hasPiercing'];
  546.         $profile->stations $row['stations'];
  547.         $profile->avatar $row['avatar'];
  548.         foreach ($row['photos'] as $photo)
  549.             if($photo['main'])
  550.                 $profile->mainPhoto $photo;
  551.         $profile->mainPhoto null;
  552.         $profile->photos = [];
  553.         $profile->selfies = [];
  554.         foreach ($row['photos'] as $photo) {
  555.             if($photo['main'])
  556.                 $profile->mainPhoto $photo;
  557.             if($photo['type'] == Photo::TYPE_PHOTO)
  558.                 $profile->photos[] = $photo;
  559.             if($photo['type'] == Photo::TYPE_SELFIE)
  560.                 $profile->selfies[] = $photo;
  561.         }
  562.         $profile->videos $row['videos'];
  563.         $profile->comments $row['comments'];
  564.         $profile->apartmentsPricing = new ProfileApartmentPricingReadModel();
  565.         $profile->apartmentsPricing->oneHourPrice $row['apartmentsPricing.oneHourPrice'];
  566.         $profile->apartmentsPricing->twoHoursPrice $row['apartmentsPricing.twoHoursPrice'];
  567.         $profile->apartmentsPricing->nightPrice $row['apartmentsPricing.nightPrice'];
  568.         $profile->takeOutPricing = new ProfileTakeOutPricingReadModel();
  569.         $profile->takeOutPricing->oneHourPrice $row['takeOutPricing.oneHourPrice'];
  570.         $profile->takeOutPricing->twoHoursPrice $row['takeOutPricing.twoHoursPrice'];
  571.         $profile->takeOutPricing->nightPrice $row['takeOutPricing.nightPrice'];
  572.         return $profile;
  573.     }
  574.     public function deletedByPeriod(\DateTimeInterface $start\DateTimeInterface $end): array
  575.     {
  576.         $qb $this->createQueryBuilder('profile')
  577.             ->join('profile.city''city')
  578.             ->select('profile.uriIdentity _profile')
  579.             ->addSelect('city.uriIdentity _city')
  580.             ->andWhere('profile.deletedAt >= :start')
  581.             ->andWhere('profile.deletedAt <= :end')
  582.             ->setParameter('start'$start)
  583.             ->setParameter('end'$end)
  584.         ;
  585.         return $qb->getQuery()->getResult();
  586.     }
  587.     public function listForMapMatchingSpec(Filter|QueryModifier $specificationint $coordinatesRoundPrecision 3): array
  588.     {
  589.         /** @var QueryBuilder $qb */
  590.         $qb $this->createQueryBuilder($dqlAlias 'p');
  591.         $qb->select(sprintf('GROUP_CONCAT(p.id), count(p.id), CONCAT(ROUND(p.mapCoordinate.latitude,%1$s),\',\',ROUND(p.mapCoordinate.longitude,%1$s)) as coords'$coordinatesRoundPrecision));
  592.         $qb->groupBy('coords');
  593.         $specification->modify($qb$dqlAlias);
  594.         $qb->andWhere($specification->getFilter($qb$dqlAlias));
  595.         return $qb->getQuery()->getResult();
  596.     }
  597.     public function fetchListingByIds(ProfileIdINOrderedByINValues $specification): array
  598.     {
  599.         $ids implode(','$specification->getIds());
  600.         $mediaType $this->features->crop_avatar() ? Photo::TYPE_AVATAR Photo::TYPE_PHOTO;
  601.         $mediaIsMain $this->features->crop_avatar() ? 1;
  602.         $sql "
  603.             SELECT 
  604.                 p.*, JSON_UNQUOTE(JSON_EXTRACT(p.name, '$.ru')) 
  605.                     as `name`, 
  606.                 JSON_UNQUOTE(JSON_EXTRACT(p.description, '$.ru')) 
  607.                     as `description`,
  608.                 (SELECT path FROM profile_media_files pmf_avatar WHERE p.id = pmf_avatar.profile_id AND pmf_avatar.type = '{$mediaType}' AND pmf_avatar.is_main = {$mediaIsMain} LIMIT 1) 
  609.                     as `avatar_path`,
  610.                 (SELECT type FROM profile_adboard_placements pap WHERE p.id = pap.profile_id LIMIT 1) 
  611.                     as `adboard_placement_type`,
  612.                 (SELECT position FROM profile_adboard_placements pap WHERE p.id = pap.profile_id LIMIT 1) 
  613.                     as `adboard_placement_position`,
  614.                 c.id 
  615.                     as `city_id`, 
  616.                 JSON_UNQUOTE(JSON_EXTRACT(c.name, '$.ru')) 
  617.                     as `city_name`, 
  618.                 c.uri_identity 
  619.                     as `city_uri_identity`,
  620.                 c.country_code 
  621.                     as `city_country_code`,
  622.                 EXISTS(SELECT * FROM profile_top_placements ptp WHERE p.id = ptp.profile_id AND (NOW() BETWEEN ptp.placed_at AND ptp.expires_at))
  623.                     as `has_top_placement`,
  624.                 EXISTS(SELECT * FROM placement_hidings ph WHERE p.id = ph.profile_id AND ph.entity_type = 'profile') 
  625.                     as `has_placement_hiding`,
  626.                 EXISTS(SELECT * FROM profile_comments pc WHERE p.id = pc.profile_id AND pc.deleted_at is NULL) 
  627.                     as `has_comments`,
  628.                 EXISTS(SELECT * FROM profile_media_files pmf_video WHERE p.id = pmf_video.profile_id AND pmf_video.type = 'video') 
  629.                     as `has_videos`,
  630.                 EXISTS(SELECT * FROM profile_media_files pmf_selfie WHERE p.id = pmf_selfie.profile_id AND pmf_selfie.type = 'selfie') 
  631.                     as `has_selfies`
  632.             FROM profiles `p`
  633.             JOIN cities `c` ON c.id = p.city_id 
  634.             WHERE p.id IN ($ids)
  635.             ORDER BY FIELD(p.id,$ids)";
  636.         $conn $this->getEntityManager()->getConnection();
  637.         $stmt $conn->prepare($sql);
  638.         $result $stmt->executeQuery([]);
  639.         /** @var Statement $stmt */
  640.         $profiles $result->fetchAllAssociative();
  641.         $sql "SELECT 
  642.                     cs.id 
  643.                         as `id`,
  644.                     JSON_UNQUOTE(JSON_EXTRACT(cs.name, '$.ru')) 
  645.                         as `name`, 
  646.                     cs.uri_identity 
  647.                         as `uriIdentity`, 
  648.                     ps.profile_id
  649.                         as `profile_id`,
  650.                     csl.name
  651.                         as `line_name`,
  652.                     csl.color
  653.                         as `line_color`
  654.                 FROM profile_stations ps
  655.                 JOIN city_stations cs ON ps.station_id = cs.id 
  656.                 LEFT JOIN city_subway_station_lines cssl ON cssl.station_id = cs.id
  657.                 LEFT JOIN city_subway_lines csl ON csl.id = cssl.line_id
  658.                 WHERE ps.profile_id IN ($ids)";
  659.         $stmt $conn->prepare($sql);
  660.         $result $stmt->executeQuery([]);
  661.         /** @var Statement $stmt */
  662.         $stations $result->fetchAllAssociative();
  663.         $sql "SELECT 
  664.                     s.id 
  665.                         as `id`,
  666.                     JSON_UNQUOTE(JSON_EXTRACT(s.name, '$.ru')) 
  667.                         as `name`, 
  668.                     s.group 
  669.                         as `group`, 
  670.                     s.uri_identity 
  671.                         as `uriIdentity`,
  672.                     pps.profile_id
  673.                         as `profile_id`,
  674.                     pps.service_condition
  675.                         as `condition`,
  676.                     pps.extra_charge
  677.                         as `extra_charge`,
  678.                     pps.comment
  679.                         as `comment`
  680.                 FROM profile_provided_services pps
  681.                 JOIN services s ON pps.service_id = s.id 
  682.                 WHERE pps.profile_id IN ($ids)";
  683.         $stmt $conn->prepare($sql);
  684.         $result $stmt->executeQuery([]);
  685.         /** @var Statement $stmt */
  686.         $providedServices $result->fetchAllAssociative();
  687.         $result array_map(function($profile) use ($stations$providedServices): ProfileListingReadModel {
  688.             return $this->hydrateProfileRow2($profile$stations$providedServices);
  689.         }, $profiles);
  690.         return $result;
  691.     }
  692.     public function hydrateProfileRow2(array $row, array $stations, array $services): ProfileListingReadModel
  693.     {
  694.         $profile = new ProfileListingReadModel();
  695.         $profile->id $row['id'];
  696.         $profile->moderationStatus $row['moderation_status'];
  697.         $profile->city = new CityReadModel();
  698.         $profile->city->id $row['city_id'];
  699.         $profile->city->name $row['city_name'];
  700.         $profile->city->uriIdentity $row['city_uri_identity'];
  701.         $profile->city->countryCode $row['city_country_code'];
  702.         $profile->uriIdentity $row['uri_identity'];
  703.         $profile->name $row['name'];
  704.         $profile->description $row['description'];
  705.         $profile->phoneNumber $row['phone_number'];
  706.         $profile->approved = (bool)$row['is_approved'];
  707.         $profile->isUltraVip $row['adboard_placement_type'] == AdBoardPlacement::POSITION_GROUP_ULTRA_VIP;
  708.         $profile->isVip $row['adboard_placement_type'] == AdBoardPlacement::POSITION_GROUP_VIP;
  709.         $profile->isStandard false !== array_search(
  710.             $row['adboard_placement_type'],
  711.             [
  712.                 AdBoardPlacement::POSITION_GROUP_STANDARD_APPROVED,AdBoardPlacement::POSITION_GROUP_STANDARD,
  713.                 AdBoardPlacement::POSITION_GROUP_WITHOUT_OWNER_APPROVED,AdBoardPlacement::POSITION_GROUP_WITHOUT_OWNER
  714.             ]
  715.         );
  716.         $profile->position $row['adboard_placement_position'];
  717.         $profile->active null !== $row['adboard_placement_type'] || $row['has_top_placement'];
  718.         $profile->hidden $row['has_placement_hiding'] == true;
  719.         $profile->personParameters = new ProfilePersonParametersReadModel();
  720.         $profile->personParameters->age $row['person_age'];
  721.         $profile->personParameters->height $row['person_height'];
  722.         $profile->personParameters->weight $row['person_weight'];
  723.         $profile->personParameters->breastSize $row['person_breast_size'];
  724.         $profile->personParameters->bodyType $row['person_body_type'];
  725.         $profile->personParameters->hairColor $row['person_hair_color'];
  726.         $profile->personParameters->privateHaircut $row['person_private_haircut'];
  727.         $profile->personParameters->nationality $row['person_nationality'];
  728.         $profile->personParameters->hasTattoo $row['person_has_tattoo'];
  729.         $profile->personParameters->hasPiercing $row['person_has_piercing'];
  730.         $profile->stations = [];
  731.         foreach ($stations as $station) {
  732.             if($profile->id !== $station['profile_id'])
  733.                 continue;
  734.             $profileStation $profile->stations[$station['id']] ?? new StationReadModel($station['id'], $station['uriIdentity'], $station['name'], []);
  735.             if(null !== $station['line_name']) {
  736.                 $profileStation->lines[] = new StationLineReadModel($station['line_name'], $station['line_color']);
  737.             }
  738.             $profile->stations[$station['id']] = $profileStation;
  739.         }
  740.         $profile->providedServices = [];
  741.         foreach ($services as $service) {
  742.             if($profile->id !== $service['profile_id'])
  743.                 continue;
  744.             $providedService $profile->providedServices[$service['id']] ?? new ProvidedServiceReadModel(
  745.                 $service['id'], $service['name'], $service['group'], $service['uriIdentity'],
  746.                 $service['condition'], $service['extra_charge'], $service['comment']
  747.             );
  748.             $profile->providedServices[$service['id']] = $providedService;
  749.         }
  750.         $profile->selfies $row['has_selfies'] ? [1] : [];
  751.         $profile->videos $row['has_videos'] ? [1] : [];
  752.         $avatar = [
  753.             'path' => $row['avatar_path'] ?? '',
  754.             'type' => $this->features->crop_avatar() ? Photo::TYPE_AVATAR Photo::TYPE_PHOTO
  755.         ];
  756.         if($this->features->crop_avatar()) {
  757.             $profile->avatar $avatar;
  758.         } else {
  759.             $profile->mainPhoto $avatar;
  760.             $profile->photos = [];
  761.         }
  762.         $profile->comments $row['has_comments'] ? [1] : [];
  763.         $profile->apartmentsPricing = new ProfileApartmentPricingReadModel();
  764.         $profile->apartmentsPricing->oneHourPrice $row['apartments_one_hour_price'];
  765.         $profile->apartmentsPricing->twoHoursPrice $row['apartments_two_hours_price'];
  766.         $profile->apartmentsPricing->nightPrice $row['apartments_night_price'];
  767.         $profile->takeOutPricing = new ProfileTakeOutPricingReadModel();
  768.         $profile->takeOutPricing->oneHourPrice $row['take_out_one_hour_price'];
  769.         $profile->takeOutPricing->twoHoursPrice $row['take_out_two_hours_price'];
  770.         $profile->takeOutPricing->nightPrice $row['take_out_night_price'];
  771.         $profile->takeOutPricing->locations $row['take_out_locations'] ? array_map('intval'explode(','$row['take_out_locations'])) : [];
  772.         $profile->seo $row['seo'] ? json_decode($row['seo'], true) : null;
  773.         return $profile;
  774.     }
  775.     public function fetchMapProfilesByIds(ProfileIdINOrderedByINValues $specification): array
  776.     {
  777.         $ids implode(','$specification->getIds());
  778.         $mediaType $this->features->crop_avatar() ? Photo::TYPE_AVATAR Photo::TYPE_PHOTO;
  779.         $mediaIsMain $this->features->crop_avatar() ? 1;
  780.         $sql "
  781.             SELECT 
  782.                 p.id, p.uri_identity, p.map_latitude, p.map_longitude, p.phone_number, p.is_masseur, p.is_approved,
  783.                 p.person_age, p.person_breast_size, p.person_height, p.person_weight,
  784.                 JSON_UNQUOTE(JSON_EXTRACT(p.name, '$.ru')) 
  785.                     as `name`,
  786.                 (SELECT path FROM profile_media_files pmf_avatar WHERE p.id = pmf_avatar.profile_id AND pmf_avatar.type = '{$mediaType}' AND pmf_avatar.is_main = {$mediaIsMain} LIMIT 1) 
  787.                     as `avatar_path`,
  788.                 p.apartments_one_hour_price, p.apartments_two_hours_price, p.apartments_night_price, p.take_out_one_hour_price, p.take_out_two_hours_price, p.take_out_night_price,
  789.                 GROUP_CONCAT(ps.station_id) as `stations`,
  790.                 GROUP_CONCAT(pps.service_id) as `services`,
  791.                 EXISTS(SELECT * FROM profile_comments pc WHERE p.id = pc.profile_id AND pc.deleted_at is NULL) 
  792.                     as `has_comments`,
  793.                 EXISTS(SELECT * FROM profile_media_files pmf_video WHERE p.id = pmf_video.profile_id AND pmf_video.type = 'video') 
  794.                     as `has_videos`,
  795.                 EXISTS(SELECT * FROM profile_media_files pmf_selfie WHERE p.id = pmf_selfie.profile_id AND pmf_selfie.type = 'selfie') 
  796.                     as `has_selfies`
  797.             FROM profiles `p`
  798.             LEFT JOIN profile_stations ps ON ps.profile_id = p.id
  799.             LEFT JOIN profile_provided_services pps ON pps.profile_id = p.id
  800.             WHERE p.id IN ($ids)
  801.             GROUP BY p.id
  802.             "// AND p.map_latitude IS NOT NULL AND p.map_longitude IS NOT NULL; ORDER BY FIELD(p.id,$ids)
  803.         $conn $this->getEntityManager()->getConnection();
  804.         $stmt $conn->prepare($sql);
  805.         $result $stmt->executeQuery([]);
  806.         /** @var Statement $stmt */
  807.         $profiles $result->fetchAllAssociative();
  808.         $result array_map(function($profile): ProfileMapReadModel {
  809.             return $this->hydrateMapProfileRow($profile);
  810.         }, $profiles);
  811.         return $result;
  812.     }
  813.     public function hydrateMapProfileRow(array $row): ProfileMapReadModel
  814.     {
  815.         $profile = new ProfileMapReadModel();
  816.         $profile->id $row['id'];
  817.         $profile->uriIdentity $row['uri_identity'];
  818.         $profile->name $row['name'];
  819.         $profile->phoneNumber $row['phone_number'];
  820.         $profile->avatar = ['path' => $row['avatar_path'] ?? '''type' => $this->features->crop_avatar() ? Photo::TYPE_AVATAR Photo::TYPE_PHOTO];
  821.         $profile->mapLatitude $row['map_latitude'];
  822.         $profile->mapLongitude $row['map_longitude'];
  823.         $profile->age $row['person_age'];
  824.         $profile->breastSize $row['person_breast_size'];
  825.         $profile->height $row['person_height'];
  826.         $profile->weight $row['person_weight'];
  827.         $profile->isMasseur $row['is_masseur'];
  828.         $profile->isApproved $row['is_approved'];
  829.         $profile->hasComments $row['has_comments'];
  830.         $profile->hasSelfies $row['has_selfies'];
  831.         $profile->hasVideos $row['has_videos'];
  832.         $profile->apartmentOneHourPrice $row['apartments_one_hour_price'];
  833.         $profile->apartmentTwoHoursPrice $row['apartments_two_hours_price'];
  834.         $profile->apartmentNightPrice $row['apartments_night_price'];
  835.         $profile->takeOutOneHourPrice $row['take_out_one_hour_price'];
  836.         $profile->takeOutTwoHoursPrice $row['take_out_two_hours_price'];
  837.         $profile->takeOutNightPrice $row['take_out_night_price'];
  838.         $profile->station $row['stations'] ? explode(','$row['stations'])[0] : null;
  839.         $profile->services $row['services'] ? array_unique(explode(','$row['services'])) : [];
  840. //        $prices = [ $row['apartments_one_hour_price'], $row['apartments_two_hours_price'], $row['apartments_night_price'],
  841. //            $row['take_out_one_hour_price'], $row['take_out_two_hours_price'], $row['take_out_night_price'] ];
  842. //        $prices = array_filter($prices, function($item) {
  843. //            return $item != null;
  844. //        });
  845. //        $profile->price = count($prices) ? min($prices) : null;
  846.         return $profile;
  847.     }
  848.     public function fetchAccountProfileListByIds(ProfileIdINOrderedByINValues $specification): array
  849.     {
  850.         $ids implode(','$specification->getIds());
  851.         $mediaType $this->features->crop_avatar() ? Photo::TYPE_AVATAR Photo::TYPE_PHOTO;
  852.         $mediaIsMain $this->features->crop_avatar() ? 1;
  853.         $sql "
  854.             SELECT 
  855.                 p.*, JSON_UNQUOTE(JSON_EXTRACT(p.name, '$.ru')) 
  856.                     as `name`, 
  857.                 JSON_UNQUOTE(JSON_EXTRACT(p.description, '$.ru')) 
  858.                     as `description`,
  859.                 (SELECT path FROM profile_media_files pmf_avatar WHERE p.id = pmf_avatar.profile_id AND pmf_avatar.type = '{$mediaType}' AND pmf_avatar.is_main = {$mediaIsMain} LIMIT 1) 
  860.                     as `avatar_path`,
  861.                 (SELECT type FROM profile_adboard_placements pap WHERE p.id = pap.profile_id LIMIT 1) 
  862.                     as `adboard_placement_type`,
  863.                 c.id 
  864.                     as `city_id`, 
  865.                 JSON_UNQUOTE(JSON_EXTRACT(c.name, '$.ru')) 
  866.                     as `city_name`, 
  867.                 c.uri_identity 
  868.                     as `city_uri_identity`,
  869.                 c.country_code 
  870.                     as `city_country_code`,
  871.                 EXISTS(SELECT * FROM profile_top_placements ptp WHERE p.id = ptp.profile_id AND (NOW() BETWEEN ptp.placed_at AND ptp.expires_at))
  872.                     as `has_top_placement`,
  873.                 EXISTS(SELECT * FROM placement_hidings ph WHERE p.id = ph.profile_id AND ph.entity_type = 'profile') 
  874.                     as `has_placement_hiding`,
  875.                 EXISTS(SELECT * FROM profile_comments pc WHERE p.id = pc.profile_id AND pc.deleted_at is NULL) 
  876.                     as `has_comments`,
  877.                 EXISTS(SELECT * FROM profile_media_files pmf_video WHERE p.id = pmf_video.profile_id AND pmf_video.type = 'video') 
  878.                     as `has_videos`,
  879.                 EXISTS(SELECT * FROM profile_media_files pmf_selfie WHERE p.id = pmf_selfie.profile_id AND pmf_selfie.type = 'selfie') 
  880.                     as `has_selfies`
  881.             FROM profiles `p`
  882.             JOIN cities `c` ON c.id = p.city_id 
  883.             WHERE p.id IN ($ids)
  884.             ORDER BY FIELD(p.id,$ids)";
  885.         $conn $this->getEntityManager()->getConnection();
  886.         $stmt $conn->prepare($sql);
  887.         $result $stmt->executeQuery([]);
  888.         /** @var Statement $stmt */
  889.         $profiles $result->fetchAllAssociative();
  890.         $sql "SELECT 
  891.                     JSON_UNQUOTE(JSON_EXTRACT(cs.name, '$.ru')) 
  892.                         as `name`, 
  893.                     cs.uri_identity 
  894.                         as `uriIdentity`, 
  895.                     ps.profile_id
  896.                         as `profile_id` 
  897.                 FROM profile_stations ps
  898.                 JOIN city_stations cs ON ps.station_id = cs.id                 
  899.                 WHERE ps.profile_id IN ($ids)";
  900.         $stmt $conn->prepare($sql);
  901.         $result $stmt->executeQuery([]);
  902.         /** @var Statement $stmt */
  903.         $stations $result->fetchAllAssociative();
  904.         $sql "SELECT 
  905.                     s.id 
  906.                         as `id`,
  907.                     JSON_UNQUOTE(JSON_EXTRACT(s.name, '$.ru')) 
  908.                         as `name`, 
  909.                     s.group 
  910.                         as `group`, 
  911.                     s.uri_identity 
  912.                         as `uriIdentity`,
  913.                     pps.profile_id
  914.                         as `profile_id`,
  915.                     pps.service_condition
  916.                         as `condition`,
  917.                     pps.extra_charge
  918.                         as `extra_charge`,
  919.                     pps.comment
  920.                         as `comment`
  921.                 FROM profile_provided_services pps
  922.                 JOIN services s ON pps.service_id = s.id 
  923.                 WHERE pps.profile_id IN ($ids)";
  924.         $stmt $conn->prepare($sql);
  925.         $result $stmt->executeQuery([]);
  926.         /** @var Statement $stmt */
  927.         $providedServices $result->fetchAllAssociative();
  928.         $result array_map(function($profile) use ($stations$providedServices): ProfileListingReadModel {
  929.             return $this->hydrateProfileRow2($profile$stations$providedServices);
  930.         }, $profiles);
  931.         return $result;
  932.     }
  933.     protected function addGenderFilterToQb(QueryBuilder $qbstring $alias, array $genders = [Genders::FEMALE]): void
  934.     {
  935.         $qb->andWhere(sprintf('%s.personParameters.gender IN (:genders)'$alias));
  936.         $qb->setParameter('genders'$genders);
  937.     }
  938.     protected function addModerationFilterToQb(QueryBuilder $qbstring $dqlAlias): void
  939.     {
  940.         if($this->features->hard_moderation()) {
  941.             $qb->leftJoin(sprintf('%s.owner'$dqlAlias), 'owner');
  942.             $qb->andWhere(
  943.                 $qb->expr()->orX(
  944.                     sprintf('%s.moderationStatus = :status_passed'$dqlAlias),
  945.                     $qb->expr()->andX(
  946.                         sprintf('%s.moderationStatus = :status_waiting'$dqlAlias),
  947.                         'owner.trusted = true'
  948.                     )
  949.                 )
  950.             );
  951.             $qb->setParameter('status_passed'Profile::MODERATION_STATUS_APPROVED);
  952.             $qb->setParameter('status_waiting'Profile::MODERATION_STATUS_WAITING);
  953.         } else {
  954.             $qb->andWhere(sprintf('%s.moderationStatus IN (:statuses)'$dqlAlias));
  955.             $qb->setParameter('statuses', [Profile::MODERATION_STATUS_NOT_PASSEDProfile::MODERATION_STATUS_WAITINGProfile::MODERATION_STATUS_APPROVED]);
  956.         }
  957.     }
  958.     protected function addActiveFilterToQb(QueryBuilder $qbstring $dqlAlias)
  959.     {
  960.         if (!in_array('profile_adboard_placement'$qb->getAllAliases())) {
  961.             $qb
  962.                 ->join(sprintf('%s.adBoardPlacement'$dqlAlias), 'profile_adboard_placement')
  963.             ;
  964.         }
  965.     }
  966.     protected function addFemaleGenderFilterToQb(QueryBuilder $qbstring $alias): void
  967.     {
  968.         $this->addGenderFilterToQb($qb$alias, [Genders::FEMALE]);
  969.     }
  970.     public function getCommentedProfilesPaged(User $owner): ORMQueryResult
  971.     {
  972.         $qb $this->createQueryBuilder('profile')
  973.             ->join('profile.comments''comment')
  974.             ->andWhere('profile.owner = :owner')
  975.             ->setParameter('owner'$owner)
  976.             ->orderBy('comment.createdAt''DESC')
  977.         ;
  978.         return new ORMQueryResult($qb);
  979.     }
  980.     /**
  981.      * @return ProfilePlacementPriceDetailReadModel[]
  982.      */
  983.     public function fetchOfOwnerPlacedPriceDetails(User $owner): array
  984.     {
  985.         $sql "
  986.             SELECT 
  987.                 p.id, p.is_approved, psp.price_amount
  988.             FROM profiles `p`
  989.             JOIN profile_adboard_placements pap ON pap.profile_id = p.id AND pap.placement_price_id IS NOT NULL
  990.             JOIN paid_service_prices psp ON pap.placement_price_id = psp.id
  991.             WHERE p.user_id = {$owner->getId()}
  992.         ";
  993.         $conn $this->getEntityManager()->getConnection();
  994.         $stmt $conn->prepare($sql);
  995.         $result $stmt->executeQuery([]);
  996.         $profiles $result->fetchAllAssociative();
  997.         return array_map(function(array $row): ProfilePlacementPriceDetailReadModel {
  998.             return new ProfilePlacementPriceDetailReadModel(
  999.                 $row['id'], $row['is_approved'], $row['price_amount'] / 24
  1000.             );
  1001.         }, $profiles);
  1002.     }
  1003.     /**
  1004.      * @return ProfilePlacementHidingDetailReadModel[]
  1005.      */
  1006.     public function fetchOfOwnerHiddenDetails(User $owner): array
  1007.     {
  1008.         $sql "
  1009.             SELECT 
  1010.                 p.id, p.is_approved
  1011.             FROM profiles `p`
  1012.             JOIN placement_hidings ph ON ph.profile_id = p.id
  1013.             WHERE p.user_id = {$owner->getId()}
  1014.         ";
  1015.         $conn $this->getEntityManager()->getConnection();
  1016.         $stmt $conn->prepare($sql);
  1017.         $result $stmt->executeQuery([]);
  1018.         $profiles $result->fetchAllAssociative();
  1019.         return array_map(function(array $row): ProfilePlacementHidingDetailReadModel {
  1020.             return new ProfilePlacementHidingDetailReadModel(
  1021.                 $row['id'], $row['is_approved'], true
  1022.             );
  1023.         }, $profiles);
  1024.     }
  1025. }