Skip to content

Commit

Permalink
IBX-8019: Replaced LocationService::loadLocationChildren use with `…
Browse files Browse the repository at this point in the history
…SearchService` (#2119)
  • Loading branch information
webhdx authored Jun 7, 2024
1 parent ef36131 commit f1a7540
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions src/lib/UI/Module/Subitems/ContentViewParameterSupplier.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
use eZ\Publish\API\Repository\ContentTypeService;
use eZ\Publish\API\Repository\LocationService;
use eZ\Publish\API\Repository\PermissionResolver;
use eZ\Publish\API\Repository\SearchService;
use eZ\Publish\API\Repository\Values\Content\Content;
use eZ\Publish\API\Repository\Values\Content\Location;
use eZ\Publish\API\Repository\Values\ContentType\ContentType;
use eZ\Publish\Core\MVC\Symfony\View\ContentView;
use eZ\Publish\Core\Query\QueryFactoryInterface;
use EzSystems\EzPlatformAdminUi\UI\Config\Provider\ContentTypeMappings;
use EzSystems\EzPlatformAdminUi\UI\Module\Subitems\ValueObjectVisitor\SubitemsList as SubitemsListValueObjectVisitor;
use EzSystems\EzPlatformAdminUi\UI\Module\Subitems\Values\SubitemsList;
Expand Down Expand Up @@ -63,18 +65,12 @@ class ContentViewParameterSupplier
/** @var \EzSystems\EzPlatformUser\UserSetting\UserSettingService */
private $userSettingService;

/**
* @param \EzSystems\EzPlatformRest\Output\Visitor $outputVisitor
* @param \EzSystems\EzPlatformRest\Output\Generator\Json $outputGenerator
* @param \EzSystems\EzPlatformRest\Server\Output\ValueObjectVisitor\ContentTypeInfoList $contentTypeInfoListValueObjectVisitor
* @param \EzSystems\EzPlatformAdminUi\UI\Module\Subitems\ValueObjectVisitor\SubitemsList $subitemsListValueObjectVisitor
* @param \eZ\Publish\API\Repository\LocationService $locationService
* @param \eZ\Publish\API\Repository\ContentService $contentService
* @param \eZ\Publish\API\Repository\ContentTypeService $contentTypeService
* @param \eZ\Publish\API\Repository\PermissionResolver $permissionResolver
* @param \EzSystems\EzPlatformAdminUi\UI\Config\Provider\ContentTypeMappings $contentTypeMappings
* @param \EzSystems\EzPlatformUser\UserSetting\UserSettingService $userSettingService
*/
/** @var \eZ\Publish\Core\Query\QueryFactoryInterface */
private $queryFactory;

/** @var \eZ\Publish\API\Repository\SearchService */
private $searchService;

public function __construct(
Visitor $outputVisitor,
JsonOutputGenerator $outputGenerator,
Expand All @@ -85,7 +81,9 @@ public function __construct(
ContentTypeService $contentTypeService,
PermissionResolver $permissionResolver,
ContentTypeMappings $contentTypeMappings,
UserSettingService $userSettingService
UserSettingService $userSettingService,
QueryFactoryInterface $queryFactory,
SearchService $searchService
) {
$this->outputVisitor = $outputVisitor;
$this->outputGenerator = $outputGenerator;
Expand All @@ -97,6 +95,8 @@ public function __construct(
$this->permissionResolver = $permissionResolver;
$this->contentTypeMappings = $contentTypeMappings;
$this->userSettingService = $userSettingService;
$this->queryFactory = $queryFactory;
$this->searchService = $searchService;
}

/**
Expand All @@ -121,12 +121,17 @@ public function supply(ContentView $view)
$contentTypes = [];
$subitemsRows = [];
$location = $view->getLocation();
$childrenCount = $this->locationService->getLocationChildCount($location);

$subitemsLimit = (int)$this->userSettingService->getUserSetting('subitems_limit')->value;

$locationChildren = $this->locationService->loadLocationChildren($location, 0, $subitemsLimit);
foreach ($locationChildren->locations as $locationChild) {
/** @var \eZ\Publish\API\Repository\Values\Content\LocationQuery $locationChildrenQuery */
$locationChildrenQuery = $this->queryFactory->create('Children', ['location' => $location]);
$locationChildrenQuery->offset = 0;
$locationChildrenQuery->limit = $subitemsLimit;

$searchResult = $this->searchService->findLocations($locationChildrenQuery);
foreach ($searchResult->searchHits as $searchHit) {
/** @var \eZ\Publish\API\Repository\Values\Content\Location $locationChild */
$locationChild = $searchHit->valueObject;
$contentType = $locationChild->getContent()->getContentType();

if (!isset($contentTypes[$contentType->identifier])) {
Expand All @@ -136,7 +141,7 @@ public function supply(ContentView $view)
$subitemsRows[] = $this->createSubitemsRow($locationChild, $contentType);
}

$subitemsList = new SubitemsList($subitemsRows, $childrenCount);
$subitemsList = new SubitemsList($subitemsRows, $searchResult->totalCount);
$contentTypeInfoList = new ContentTypeInfoList($contentTypes, '');

$subitemsListJson = $this->visitSubitemsList($subitemsList);
Expand Down

0 comments on commit f1a7540

Please sign in to comment.