/** * Returns image items for a gallery, as Content objects. * * @param mixed $galleryLocationId * * @return \eZ\Publish\API\Repository\Values\Content\Content[] */ public function getGalleryItems($galleryLocationId) { $result = $this->searchService->findContent($this->generateGalleryItemsQuery($galleryLocationId)); $contentObjects = []; foreach ($result->searchHits as $hit) { $contentObjects[] = $hit->valueObject; } return $contentObjects; }
/** * Returns a slice of the results, as SearchHit objects. * * @param integer $offset The offset. * @param integer $length The length. * * @return \eZ\Publish\API\Repository\Values\Content\Search\SearchHit[] */ public function getSlice($offset, $length) { $query = clone $this->query; $query->offset = $offset; $query->limit = $length; $searchResult = $this->searchService->findContent($query); if (!isset($this->nbResults)) { $this->nbResults = $searchResult->totalCount; } return $searchResult->searchHits; }
/** * Returns a slice of the results, as SearchHit objects. * * @param int $offset The offset. * @param int $length The length. * * @return \eZ\Publish\API\Repository\Values\Content\Search\SearchHit[] */ public function getSlice($offset, $length) { $query = clone $this->query; $query->offset = $offset; $query->limit = $length; $query->performCount = false; $searchResult = $this->searchService->findContent($query); // Set count for further use if returned by search engine despite !performCount (Solr, ES) if (!isset($this->nbResults) && isset($searchResult->totalCount)) { $this->nbResults = $searchResult->totalCount; } return $searchResult->searchHits; }
/** * Returns all places contained in a place_list that are located between the range defined in * the default configuration. A sort clause array can be provided in order to sort the results. * * @param int|string $locationId * @param float $latitude * @param float $longitude * @param string|string[] $contentTypes to be retrieved * @param int $maxDist Maximum distance for the search in km * @param array $sortClauses * @param string|string[] $languages to be retrieved * * @return \eZ\Publish\API\Repository\Values\Content\Content[] */ public function getPlaceListSorted( $locationId, $latitude, $longitude, $contentTypes, $maxDist = null, $sortClauses = array(), $languages = array() ) { $location = $this->locationService->loadLocation( $locationId ); if ( $maxDist === null ) { $maxDist = $this->placeListMaxDist; } $query = new Query(); $query->filter = new Criterion\LogicalAnd( array( new Criterion\ContentTypeIdentifier( $contentTypes ), new Criterion\Subtree( $location->pathString ), new Criterion\LanguageCode( $languages ), new Criterion\MapLocationDistance( "location", Criterion\Operator::BETWEEN, array( $this->placeListMinDist, $maxDist ), $latitude, $longitude ) ) ); $query->sortClauses = $sortClauses; $searchResults = $this->searchService->findContent( $query ); return $this->searchHelper->buildListFromSearchResult( $searchResults ); }
public function viewContentTypeAction($contentTypeId, $languageCode = null) { $languageCode = $languageCode ?: $this->prioritizedLanguages[0]; $contentType = $this->contentTypeService->loadContentType($contentTypeId); $countQuery = new Query(['filter' => new Query\Criterion\ContentTypeId($contentTypeId), 'limit' => 0]); $contentCount = $this->searchService->findContent($countQuery, [], false)->totalCount; $deleteForm = $this->createForm(new ContentTypeDeleteType(), ['contentTypeId' => $contentTypeId]); return $this->render('eZPlatformUIBundle:ContentType:view_content_type.html.twig', ['language_code' => $languageCode, 'content_type' => $contentType, 'content_count' => $contentCount, 'modifier' => $this->userService->loadUser($contentType->modifierId), 'delete_form' => $deleteForm->createView(), 'can_edit' => $this->isGranted(new Attribute('class', 'update')), 'can_delete' => $this->isGranted(new Attribute('class', 'delete')) && !$this->contentTypeService->isContentTypeUsed($contentType)]); }
/** * Search User Groups with given name. * * @param string $name name of User Group to search for * @param string $parentLocationId (optional) parent location id to search in * * @return search results */ public function searchUserGroups($name, $parentLocationId = null) { $criterionArray = array(new Criterion\Subtree(self::USERGROUP_ROOT_SUBTREE), new Criterion\ContentTypeIdentifier(self::USERGROUP_CONTENT_IDENTIFIER), new Criterion\Field('name', Criterion\Operator::EQ, $name)); if ($parentLocationId) { $criterionArray[] = new Criterion\ParentLocationId($parentLocationId); } $query = new Query(); $query->filter = new Criterion\LogicalAnd($criterionArray); $result = $this->searchService->findContent($query, array(), false); return $result->searchHits; }
/** * Returns array of child content objects from given $locationId. * * @param int $locationId * @param int $limit * * @return array */ private function fetchItems($locationId, $limit) { $languages = $this->configResolver->getParameter('languages'); $query = new Query(); $location = $this->locationService->loadLocation($locationId); $query->query = $this->childrenCriteria->generateChildCriterion($location, $languages); $query->performCount = false; $query->limit = $limit; $query->sortClauses = [new SortClause\DatePublished(Query::SORT_DESC)]; $results = $this->searchService->findContent($query); $items = []; foreach ($results->searchHits as $item) { $items[] = $item->valueObject; } return $items; }
/** * Displays blog post content with random selected blog posts. * * @param \eZ\Publish\Core\MVC\Symfony\View\ContentView $view * * @return \eZ\Publish\Core\MVC\Symfony\View\ContentView */ public function showBlogPostAction(ContentView $view) { $languages = $this->configResolver->getParameter('languages'); $location = $this->locationService->loadLocation($view->getLocation()->parentLocationId); $query = new Query(); $query->query = $this->childrenCriteria->generateChildCriterion($location, $languages); $query->performCount = false; $query->sortClauses = [new SortClause\DatePublished(Query::SORT_DESC)]; $results = $this->searchService->findContent($query); $randomPosts = []; foreach ($results->searchHits as $item) { $randomPosts[] = $item->valueObject; } shuffle($randomPosts); $view->addParameters(['location' => $location, 'content' => $this->contentService->loadContentByContentInfo($view->getLocation()->getContentInfo()), 'randomPosts' => array_slice($randomPosts, 0, $this->randomPostsLimit, true)]); return $view; }
/** * Finds content objects for the given query. * * @todo define structs for the field filters * * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if query is not valid * * @param \eZ\Publish\API\Repository\Values\Content\Query $query * @param array $fieldFilters - a map of filters for the returned fields. * Currently supported: <code>array("languages" => array(<language1>,..))</code>. * @param bool $filterOnUserPermissions if true only the objects which is the user allowed to read are returned. * * @return \eZ\Publish\API\Repository\Values\Content\Search\SearchResult */ public function findContent(Query $query, array $fieldFilters = array(), $filterOnUserPermissions = true) { return $this->service->findContent($query, $fieldFilters, $filterOnUserPermissions); }