collectionFactory = $collectionFactory; $this->historyEntryRepository = $historyEntryRepository; $this->searchResultsFactory = $searchResultsFactory; } public function getList(SearchCriteriaInterface $searchCriteria): VisitHistoryEntrySearchResultsInterface { $searchResults = $this->searchResultsFactory->create(); $searchResults->setSearchCriteria($searchCriteria); $visitHistoryCollection = $this->collectionFactory->create(); $this->applyCriteria($searchCriteria, $visitHistoryCollection); $searchResults->setTotalCount($visitHistoryCollection->getSize()); $historyItems = array_map(function (VisitHistoryEntryInterface $visitHistory) { return $this->historyEntryRepository->getById($visitHistory->getId()); }, $visitHistoryCollection->getItems()); $searchResults->setItems($historyItems); return $searchResults; } }