src/Service/ProfileList.php line 175

Open in your IDE?
  1. <?php
  2. namespace App\Service;
  3. use App\Bridge\Porpaginas\Doctrine\ORM\FakeORMQueryPage;
  4. use App\Entity\Location\City;
  5. use App\Entity\Profile\Genders;
  6. use App\Entity\Profile\Profile;
  7. use App\Event\PaginatorPageTakenEvent;
  8. use App\Repository\ProfileRepository;
  9. use App\Repository\ReadModel\ProfileListingReadModel;
  10. use App\Specification\Profile\ICountIdSpec;
  11. use App\Specification\Profile\ISelectIdListSpec;
  12. use App\Specification\Profile\ProfileHasOneOfGenders;
  13. use App\Specification\Profile\ProfileIdINOrderedByINValues;
  14. use App\Specification\Profile\ProfileIdNotIn;
  15. use App\Specification\Profile\ProfileIsActive;
  16. use App\Specification\Profile\ProfileIsArchived;
  17. use App\Specification\Profile\ProfileIsLocatedInCountry;
  18. use App\Specification\Profile\ProfileIsLocated;
  19. use App\Specification\Profile\ProfileIsMasseur;
  20. use App\Specification\Profile\ProfileIsModerationPassed;
  21. use App\Specification\Profile\ProfileIsNotMasseur;
  22. use App\Specification\Profile\ProfileIsNotRejected;
  23. use App\Specification\QueryModifier\FreeProfilesFeatureArchivedProfileOrder;
  24. use App\Specification\QueryModifier\FreeProfilesFeatureProfileOrder;
  25. use App\Specification\Profile\ProfileIsHidden;
  26. use App\Specification\Profile\ProfileIsNotHidden;
  27. use App\Specification\QueryModifier\LimitResult;
  28. use App\Specification\QueryModifier\ProfileOrderedByCreated;
  29. use App\Specification\QueryModifier\ProfileOrderedByInactivated;
  30. use App\Specification\QueryModifier\ProfileOrderedByRandom;
  31. use App\Specification\QueryModifier\ProfileOrderedByUpdated;
  32. use App\Specification\QueryModifier\ProfileOrderedByStatus;
  33. use App\Specification\QueryModifier\ProfilePlacementHiding;
  34. use Doctrine\ORM\EntityManagerInterface;
  35. use Happyr\DoctrineSpecification\Filter\Filter;
  36. use Happyr\DoctrineSpecification\Logic\AndX;
  37. use Happyr\DoctrineSpecification\Spec;
  38. use Happyr\DoctrineSpecification\Specification\Specification;
  39. use Porpaginas\Page;
  40. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  41. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  42. use Symfony\Component\HttpFoundation\Request;
  43. use Symfony\Component\HttpFoundation\RequestStack;
  44. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  45. class ProfileList
  46. {
  47.     public const ORDER_BY_STATUS = 'status';
  48.     public const ORDER_BY_UPDATED = 'updated';
  49.     public const ORDER_NONE = 'none';
  50.     private ?Request $request;
  51.     private int $perPageDefault;
  52.     private int $perPage;
  53.     private array $executedCountQueryData;
  54.     private bool $withTopPlacementForPagination = false;
  55.     public function __construct(
  56.         private ProfileRepository $profileRepository,
  57.         RequestStack $requestStack,
  58.         private Features $features,
  59.         ParameterBagInterface $parameterBag,
  60.         private EventDispatcherInterface $eventDispatcher,
  61.         private EntityManagerInterface $entityManager,
  62.         private ProfileTopBoard $profileTopBoard,
  63.         private SplitFirstPagePagination $splitFirstPagePagination,
  64.     )
  65.     {
  66.         $this->request = $requestStack->getCurrentRequest();
  67.         $this->perPageDefault = intval($parameterBag->get('profile_list.per_page'));
  68.         $this->perPage = $this->perPageDefault;
  69.     }
  70.     public function listActiveWithinCityOrderedByStatusWithSpecAvoidingTopPlacement(
  71.         City $city, ?Filter $spec, array $additionalSpecs = null, array $genders = [Genders::FEMALE]
  72.     ): array|Page
  73.     {
  74.         return $this->listActiveWithinCityOrderedByStatusWithSpec($city, $spec, $additionalSpecs, $genders, true);
  75.     }
  76.     public function listActiveWithinCityOrderedByStatusWithSpec(
  77.         City $city, ?Filter $spec, array $additionalSpecs = null, array $genders = [Genders::FEMALE], bool $avoidTopPlacement = false
  78.     ): array|Page
  79.     {
  80.         return $this->list($city, null, $spec, $additionalSpecs, true, null, self::ORDER_BY_STATUS,
  81.             null, true, null, $genders, $avoidTopPlacement);
  82.     }
  83.     public function listActiveWithinCityOrderedByStatusWithSpecLimited(
  84.         City $city, ?Filter $spec, array $additionalSpecs = null, array $genders = [Genders::FEMALE], bool $avoidTopPlacement = false, int $limit = 0,
  85.     ): array|Page
  86.     {
  87.         return $this->list($city, null, $spec, $additionalSpecs, true, null, self::ORDER_BY_STATUS,
  88.             $limit, false, null, $genders, $avoidTopPlacement);
  89.     }
  90.     public function listActiveNotMasseurWithinCityOrderedByStatusWithSpec(
  91.         City $city, ?Filter $spec, array $additionalSpecs = null, array $genders = [Genders::FEMALE]
  92.     ): array|Page
  93.     {
  94.         return $this->list($city, null, $spec, $additionalSpecs, true, false, self::ORDER_BY_STATUS,
  95.             null, true, null, $genders);
  96.     }
  97.     public function listActiveOrderedByStatusWithSpec(
  98.         ?Filter $spec,
  99.         ?array $additionalSpecs = null,
  100.         array $genders = [Genders::FEMALE]
  101.     ): array|Page
  102.     {
  103.         $this->perPage = $this->perPageDefault;
  104.         $criteria = Spec::andX(
  105.             $this->getActiveSpecByFlag(true),
  106.             $this->getModerationSpecByFlag(),
  107.             new ProfileHasOneOfGenders($genders)
  108.         );
  109.         $criteriaForIdList = clone $criteria;
  110.         $countProfiles = $this->countOfCriteriaWithCustomSpec($criteria, $spec, $additionalSpecs);
  111.         if (0 === $countProfiles) {
  112.             $profiles = $this->takeFakePage($countProfiles, []);
  113.             $this->restorePerPageToDefault();
  114.             return $profiles;
  115.         }
  116.         $criteriaForIdList->andX($this->getOrderSpecByFlags(self::ORDER_BY_STATUS, true));
  117.         $idList = $this->listIdOfCriteriaWithCustomSpec($criteriaForIdList, $spec, $additionalSpecs, true);
  118.         $profiles = [];
  119.         if (!empty($idList)) {
  120.             $profiles = $this->profileRepository->fetchListingByIds(new ProfileIdINOrderedByINValues($idList));
  121.         }
  122.         $profiles = $this->takeFakePage($countProfiles, $profiles);
  123.         $this->restorePerPageToDefault();
  124.         return $profiles;
  125.     }
  126.     public function countActiveWithinCityWithSpec(
  127.         City $city, ?Filter $spec, array $additionalSpecs = null, array $genders = [Genders::FEMALE]
  128.     ): int
  129.     {
  130.         $criteria = Spec::andX(
  131.             ProfileIsLocated::withinCity($city),
  132.             $this->getActiveSpecByFlag(true)
  133.         );
  134.         $criteria->andX($this->getModerationSpecByFlag());
  135.         $criteria->andX(new ProfileHasOneOfGenders($genders));
  136.         return $this->countOfCriteriaWithCustomSpec($criteria, $spec, $additionalSpecs);
  137.     }
  138.     /**
  139.      * @param Profile|bool|null $avoidOrTopPlacement Принимает bool для обратной совместимости с старым кодом
  140.      */
  141.     public function list(
  142.         City $city, ?string $country, ?Filter $spec, ?array $additionalSpecs, bool $active, ?bool $masseur = false,
  143.         ?string $order = self::ORDER_BY_STATUS, ?int $limit = null, bool $paged = true, ?callable $fetchByIdMethod = null,
  144.         array $genders = [Genders::FEMALE], Profile|null|bool $avoidOrTopPlacement = false
  145.     ): array|Page
  146.     {
  147. //        $this->perPage = $limit ?? $this->perPageDefault;
  148.         $this->perPage = $this->perPageDefault;
  149.         $countProfiles = 0;
  150.         $returnProfiles = [];
  151.         $topPlacementToAvoidId = null;
  152.         if (/*null === $limit && */true === $avoidOrTopPlacement) {
  153.             $profileTopPlacement = $this->profileTopBoard->topPlacementSatisfiedBy($city, $spec);
  154.             if (null !== $profileTopPlacement) {
  155.                 $topPlacementToAvoidId = $profileTopPlacement->getId();
  156.                 $countProfiles = 1;
  157.                 $returnProfiles[] = $profileTopPlacement;
  158.             }
  159.         } elseif ($avoidOrTopPlacement instanceof Profile) {
  160.             $topPlacementToAvoidId = $avoidOrTopPlacement->getId();
  161.             $countProfiles = 1;
  162.             $returnProfiles[] = $avoidOrTopPlacement;
  163.         }
  164.         $this->withTopPlacementForPagination = null !== $topPlacementToAvoidId;
  165.         if ($this->withTopPlacementForPagination && !$this->splitFirstPagePagination->isActive()) {
  166.             //на тесте часто ставят 1 на страницу, что ломает логику, т.к. после декремента становится 0 на страницу,
  167.             //за тем и условие
  168.             if ($this->perPage > 1) {
  169.                 $this->perPage--;
  170.             }
  171.         }
  172.         $order = $this->getOrderSpecByFlags($order, $active);
  173.         $masseurSpec = $this->getMasseurSpecByFlag($masseur);
  174.         $activeSpec = $this->getActiveSpecByFlag($active);
  175.         $excludeTopProfileSpec = null !== $topPlacementToAvoidId ? new ProfileIdNotIn([$topPlacementToAvoidId]) : null;
  176.         $criteria = Spec::andX(
  177.             $country ? ProfileIsLocatedInCountry::withCountryCode($city->getCountryCode()) : ProfileIsLocated::withinCity($city),
  178.             $activeSpec
  179.         );
  180.         if ($masseurSpec) {
  181.             $criteria->andX($masseurSpec);
  182.         }
  183.         if (null !== $excludeTopProfileSpec) {
  184.             $criteria->andX($excludeTopProfileSpec);
  185.         }
  186.         $criteria->andX($this->getModerationSpecByFlag());
  187.         $criteria->andX(new ProfileHasOneOfGenders($genders));
  188.         $criteriaForIdList = clone $criteria;
  189.         if ($paged) {
  190.             $pagedCount = $this->countOfCriteriaWithCustomSpec($criteria, $spec, $additionalSpecs);
  191.             $countProfiles += $pagedCount;
  192.             if (0 === $pagedCount) {
  193.                 return $this->takeFakePage($countProfiles, $returnProfiles);
  194.             }
  195.         }
  196.         if ($order) {
  197.             $criteriaForIdList->andX($order);
  198.         }
  199.         $idList = $this->listIdOfCriteriaWithCustomSpec($criteriaForIdList, $spec, $additionalSpecs, $paged, $limit);
  200.         $profiles = [];
  201.         if(!empty($idList)) {
  202.             // $profiles = $this->profileRepository->matchingSpecRaw(new ProfileIdINOrderedByINValues($idList), null, true, array($this->profileRepository, 'hydrateProfileRow'));
  203.             $profiles = null === $fetchByIdMethod
  204.                 ? $this->profileRepository->fetchListingByIds(new ProfileIdINOrderedByINValues($idList))
  205.                 : $fetchByIdMethod(new ProfileIdINOrderedByINValues($idList));
  206.         }
  207.         $returnProfiles = array_merge($returnProfiles, $profiles);
  208.         if ($paged) {
  209.             $returnProfiles = $this->takeFakePage($countProfiles, $returnProfiles);
  210.         }
  211.         $this->restorePerPageToDefault();
  212.         return $returnProfiles;
  213.     }
  214.     public function listForMap(
  215.         City $city, ?string $country, ?Filter $spec, ?array $additionalSpecs, bool $active, ?bool $masseur = false,
  216.         ?string $order = self::ORDER_BY_STATUS, array $genders = [Genders::FEMALE], int $coordsRoundPrecision = 3,
  217.     ): array|Page
  218.     {
  219.         $order = $this->getOrderSpecByFlags($order, $active);
  220.         $masseurSpec = $this->getMasseurSpecByFlag($masseur);
  221.         $activeSpec = $this->getActiveSpecByFlag($active);
  222.         $criteria = Spec::andX(
  223.             $country ? ProfileIsLocatedInCountry::withCountryCode($city->getCountryCode()) : ProfileIsLocated::withinCity($city),
  224.             //$activeSpec
  225.         );
  226.         if($masseurSpec)
  227.             $criteria->andX($masseurSpec);
  228.         $criteria->andX($this->getModerationSpecByFlag());
  229.         $criteria->andX(new ProfileHasOneOfGenders($genders));
  230.         if(null == $additionalSpecs)
  231.             $additionalSpecs = [];
  232.         array_unshift($additionalSpecs, $spec);
  233.         array_walk($additionalSpecs, function($spec) use ($criteria): void {
  234.             $criteria->andX($spec);
  235.         });
  236.         $profiles = $this->profileRepository->listForMapMatchingSpec($criteria, $coordsRoundPrecision);
  237.         return $profiles;
  238.     }
  239.     protected function countOfCriteriaWithCustomSpec(AndX $criteria, ?Filter $spec, array $additionalSpecs = null): int
  240.     {
  241.         if(null == $additionalSpecs)
  242.             $additionalSpecs = [];
  243.         array_unshift($additionalSpecs, $spec);
  244.         array_walk($additionalSpecs, function($spec) use ($criteria): void {
  245.             $criteria->andX($spec);
  246.             if($spec instanceof ICountIdSpec)
  247.                 $criteria->andX($spec->getCountIdSpec());
  248.         });
  249.         $defaultStack = $this->entityManager->getConnection()->getConfiguration()->getSQLLogger();
  250.         $stack = new \Doctrine\DBAL\Logging\DebugStack();
  251.         $this->entityManager->getConnection()->getConfiguration()->setSQLLogger($stack);
  252.         $result = $this->profileRepository->countMatchingSpec($criteria);
  253.         //$this->executedCountQueryData = ['sql' => 'SELECT count( p0_.id ) AS sclr_0 FROM `profiles` p0_ INNER JOIN profile_adboard_placements p1_ ON p0_.id = p1_.profile_id  WHERE ( p0_.deleted_at IS NULL )', 'params' => [], 'types' => []];//
  254.         $this->executedCountQueryData = $stack->queries[count($stack->queries)];
  255.         $this->entityManager->getConnection()->getConfiguration()->setSQLLogger($defaultStack);
  256.         return $result;
  257.     }
  258.     protected function listIdOfCriteriaWithCustomSpec(AndX $criteria, ?Filter $spec, array $additionalSpecs = null, bool $paged = true, ?int $limit = null): array
  259.     {
  260.         if(null == $additionalSpecs)
  261.             $additionalSpecs = [];
  262.         array_unshift($additionalSpecs, $spec);
  263.         array_walk($additionalSpecs, function($spec) use ($criteria): void {
  264.             $criteria->andX($spec);
  265.             if($spec instanceof ISelectIdListSpec)
  266.                 $criteria->andX($spec->getIdListSpec());
  267.         });
  268.         return $this->profileRepository->listIdMatchingSpec(
  269.             $criteria,
  270.             $paged ? $this->getOffset() : 0,
  271.             $paged ? $this->getPerPageForQuery() : $limit
  272. //            $limit ?: $this->perPage
  273.         );
  274.     }
  275.     protected function getPage(): int
  276.     {
  277.         $page = (int)$this->request->get('page');
  278.         if ($page < 1)
  279.             $page = 1;
  280.         return $page;
  281.     }
  282.     protected function getOffset(): float|int
  283.     {
  284.         if ($this->splitFirstPagePagination->isActive()) {
  285.             return $this->splitFirstPagePagination->getOffsetForPage(
  286.                 $this->getPage(),
  287.                 $this->withTopPlacementForPagination
  288.             );
  289.         }
  290.         return ($this->getPage() - 1) * $this->perPage;
  291.     }
  292.     private function getPerPageForQuery(): int
  293.     {
  294.         if ($this->splitFirstPagePagination->isActive()) {
  295.             return $this->splitFirstPagePagination->getLimitForPage(
  296.                 $this->getPage(),
  297.                 $this->withTopPlacementForPagination
  298.             );
  299.         }
  300.         return $this->perPage;
  301.     }
  302.     protected function takeFakePage(int $totalResults, array $profiles): Page
  303.     {
  304.         if ($this->splitFirstPagePagination->isActive()) {
  305.             if ($this->splitFirstPagePagination->isPageOutOfRange($this->getPage(), $totalResults)) {
  306.                 throw new NotFoundHttpException('Page number doesn\'t exist');
  307.             }
  308.             $this->eventDispatcher->dispatch(new PaginatorPageTakenEvent($profiles), PaginatorPageTakenEvent::NAME);
  309.             return new FakeORMQueryPage(
  310.                 $this->splitFirstPagePagination->getDisplayOffset($this->getPage()),
  311.                 $this->getPage(),
  312.                 $this->splitFirstPagePagination->getDisplayLimit($this->getPage()),
  313.                 $totalResults,
  314.                 $profiles
  315.             );
  316.         }
  317.         //если передана страница, которой нет в основной выборке
  318.         //if($totalResults != 0 && $this->getPage() > ceil($totalResults / $this->perPage))
  319.         if ($totalResults > 0 && $this->getPage() !== 1 && $this->getOffset() > $totalResults - 1) {
  320.             throw new NotFoundHttpException('Page number doesn\'t exist');
  321.         }
  322.         //$profileIds = array_map(function(ProfileListingReadModel $profileListingReadModel): int {
  323.         //    return $profileListingReadModel->id;
  324.         //}, $profiles);
  325.         $this->eventDispatcher->dispatch(new PaginatorPageTakenEvent($profiles), PaginatorPageTakenEvent::NAME);
  326.         return new FakeORMQueryPage($this->getOffset(), $this->getPage(), $this->perPage, $totalResults, $profiles);
  327.     }
  328.     public function listRandom(
  329.         City $city, ?string $country, ?Filter $spec, ?array $additionalSpecs, bool $active, ?bool $masseur = false,
  330.         array $genders = [Genders::FEMALE], bool $paged = true, ?int $limit = null
  331.     ): array|Page
  332.     {
  333.         $masseurSpec = $this->getMasseurSpecByFlag($masseur);
  334.         $activeSpec = $this->getActiveSpecByFlag($active);
  335.         $criteria = Spec::andX(
  336.             $country ? ProfileIsLocatedInCountry::withCountryCode($city->getCountryCode()) : ProfileIsLocated::withinCity($city),
  337.             $activeSpec
  338.         );
  339.         if($masseurSpec)
  340.             $criteria->andX($masseurSpec);
  341.         $criteria->andX($this->getModerationSpecByFlag());
  342.         $criteria->andX(new ProfileHasOneOfGenders($genders));
  343.         $criteria->andX(new ProfileOrderedByRandom());
  344.         $idList = $this->listIdOfCriteriaWithCustomSpec($criteria, $spec, $additionalSpecs, $paged, $limit);
  345.         $profiles = [];
  346.         if(!empty($idList)) {
  347.             $profiles = $this->profileRepository->fetchListingByIds(new ProfileIdINOrderedByINValues($idList));
  348.         }
  349.         if($paged) {
  350.             $profiles = $this->takeFakePage(count($profiles)/*$this->perPage*/, $profiles);
  351.         }
  352.         return $profiles;
  353.     }
  354.     public function listRecent(City $city, int $count, array $genders = [Genders::FEMALE]): array
  355.     {
  356.         $criteria = Spec::andX(
  357.             //new ProfileAdBoardPlacement(),
  358.             new ProfileIsActive(),
  359.             new ProfilePlacementHiding(),
  360.             new \App\Specification\QueryModifier\ProfileAvatar(),
  361.             // убрано чтобы не было мало записей на маленьких городах
  362.             // new ProfileIsNew(),
  363.             ProfileIsLocated::withinCity($city),
  364.             new ProfileOrderedByCreated(),
  365.             new LimitResult($count)
  366.         );
  367.         $criteria->andX($this->getActiveSpecByFlag(true));
  368.         $criteria->andX($this->getModerationSpecByFlag());
  369.         $criteria->andX(new ProfileHasOneOfGenders($genders));
  370.         $result = $this->profileRepository->matchingSpecRaw($criteria, null, false);
  371.         return $result;
  372.     }
  373.     public function listLatestCreated(City $city, int $limit, array $genders = [Genders::FEMALE]): Page
  374.     {
  375.         $criteria = Spec::andX(
  376.             ProfileIsLocated::withinCity($city),
  377.             $this->getActiveSpecByFlag(true),
  378.             $this->getModerationSpecByFlag(),
  379.             new ProfileHasOneOfGenders($genders),
  380.             new ProfileOrderedByCreated()
  381.         );
  382.         $idList = $this->profileRepository->listIdMatchingSpec($criteria, 0, $limit);
  383.         $pageIds = array_slice($idList, (int)$this->getOffset(), $this->getPerPageForQuery());
  384.         $profiles = [];
  385.         if (!empty($pageIds)) {
  386.             $profiles = $this->profileRepository->fetchListingByIds(new ProfileIdINOrderedByINValues($pageIds));
  387.         }
  388.         $result = $this->takeFakePage(count($idList), $profiles);
  389.         $this->restorePerPageToDefault();
  390.         return $result;
  391.     }
  392.     public function listBySpec(?Filter $spec, ?array $additionalSpecs = null, ?int $limit = null, bool $paged = true, ?callable $fetchByIdMethod = null): array|Page
  393.     {
  394.         $this->perPage = $limit ?? $this->perPageDefault;
  395.         $criteria = Spec::andX(
  396.             $spec
  397.         );
  398.         $criteriaForIdList = clone $criteria;
  399.         if($paged) {
  400.             $count = $this->countOfCriteriaWithCustomSpec($criteria, $spec, $additionalSpecs);
  401.             if(0 == $count)
  402.                 return $this->takeFakePage($count, []);
  403.         }
  404.         $idList = $this->listIdOfCriteriaWithCustomSpec($criteriaForIdList, $spec, $additionalSpecs, $paged);
  405.         $profiles = [];
  406.         if(!empty($idList)) {
  407.             # $fetchByIdMethod передается если нужно, чтобы результат был не в виде ProfileListingReadModel, например.
  408.             # Как вариант - [$profileRepository, 'findByIds']
  409.             $profiles = null == $fetchByIdMethod
  410.                 ? $this->profileRepository->fetchListingByIds(new ProfileIdINOrderedByINValues($idList))
  411.                 : $fetchByIdMethod($idList);
  412.         }
  413.         if($paged) {
  414.             $profiles = $this->takeFakePage($count, $profiles);
  415.         }
  416.         $this->restorePerPageToDefault();
  417.         return $profiles;
  418.     }
  419.     protected function getMasseurSpecByFlag(?bool $masseur): ?Specification
  420.     {
  421.         if(true === $masseur) {
  422.             $masseurSpec = new ProfileIsMasseur();
  423.         } else if(false === $masseur) {
  424.             $masseurSpec = new ProfileIsNotMasseur();
  425.         } else {
  426.             $masseurSpec = null;
  427.         }
  428.         return $masseurSpec;
  429.     }
  430.     public function getActiveSpecByFlag(bool $active): ProfileIsHidden|ProfileIsArchived|ProfileIsNotHidden|ProfileIsActive
  431.     {
  432.         if($active) {
  433.             $activeSpec = $this->features->free_profiles() ? new ProfileIsNotHidden() : new ProfileIsActive();
  434.         } else {
  435.             $activeSpec = $this->features->free_profiles() ? new ProfileIsHidden() : new ProfileIsArchived();
  436.         }
  437.         return $activeSpec;
  438.     }
  439.     public function getModerationSpecByFlag(): ProfileIsModerationPassed|ProfileIsNotRejected
  440.     {
  441.         return $this->features->hard_moderation() ? new ProfileIsModerationPassed() : new ProfileIsNotRejected();
  442.     }
  443.     protected function getOrderSpecByFlags(string $order, bool $active): string|ProfileOrderedByStatus|ProfileOrderedByUpdated|ProfileOrderedByInactivated|FreeProfilesFeatureProfileOrder|FreeProfilesFeatureArchivedProfileOrder
  444.     {
  445.         switch($order) {
  446.             case self::ORDER_BY_UPDATED:
  447.                 $defaultOrder = new ProfileOrderedByUpdated();
  448.                 break;
  449.             case self::ORDER_NONE:
  450.                 $defaultOrder = null;
  451.                 break;
  452.             case self::ORDER_BY_STATUS:
  453.             default:
  454.                 $defaultOrder = new ProfileOrderedByStatus();
  455.                 break;
  456.         }
  457.         if(null != $defaultOrder) {
  458.             if ($this->features->free_profiles()) {
  459.                 $order = $active ? new FreeProfilesFeatureProfileOrder($this->features->consider_approved_priority()) : new FreeProfilesFeatureArchivedProfileOrder();
  460.             } else {
  461.                 $order = $active ? $defaultOrder : new ProfileOrderedByInactivated();
  462.             }
  463.         }
  464.         return $order;
  465.     }
  466.     public function executedCountQueryData(): array
  467.     {
  468.         return $this->executedCountQueryData;
  469.     }
  470.     protected function restorePerPageToDefault(): void
  471.     {
  472.         $this->perPage = $this->perPageDefault;
  473.         $this->withTopPlacementForPagination = false;
  474.     }
  475.   
  476.     public function getProfilesByIdsInOrder(array $ids): array
  477.     {
  478.         if (empty($ids)) {
  479.             return [];
  480.         }
  481.         return $this->profileRepository->fetchListingByIds(new \App\Specification\Profile\ProfileIdINOrderedByINValues($ids));
  482.     }
  483.     public function getActiveProfilesByIdsInOrderWithinCityAndSpec(
  484.         City $city,
  485.         array $ids,
  486.         ?Filter $spec,
  487.         ?array $additionalSpecs = null,
  488.         array $genders = [Genders::FEMALE],
  489.     ): array {
  490.         if (empty($ids)) {
  491.             return [];
  492.         }
  493.         $additionalSpecs ??= [];
  494.         $additionalSpecs[] = new ProfileIdINOrderedByINValues($ids);
  495.         return $this->list(
  496.             $city,
  497.             null,
  498.             $spec,
  499.             $additionalSpecs,
  500.             true,
  501.             null,
  502.             self::ORDER_NONE,
  503.             count($ids),
  504.             false,
  505.             null,
  506.             $genders,
  507.         );
  508.     }
  509.    
  510.     public function createFakePageFromProfiles(int $totalResults, array $profiles): Page
  511.     {
  512.         return $this->takeFakePage($totalResults, $profiles);
  513.     }
  514. }