src/Repository/ProfileRepository.php line 742

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