/**
  * Returns latest published content that is located under $pathString and matching $contentTypeIdentifier.
  * The whole subtree will be passed through to find content.
  *
  * @param \eZ\Publish\API\Repository\Values\Content\Location $rootLocation Root location we want to start content search from.
  * @param string[] $includeContentTypeIdentifiers Array of ContentType identifiers we want content to match.
  * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion Additional criterion for filtering.
  * @param int|null $limit Max number of items to retrieve. If not provided, default limit will be used.
  *
  * @return \eZ\Publish\API\Repository\Values\Content\Content[]
  */
 public function getLatestContent(Location $rootLocation, array $includeContentTypeIdentifiers = array(), Criterion $criterion = null, $limit = null)
 {
     $criteria = array(new Criterion\Subtree($rootLocation->pathString), new Criterion\Visibility(Criterion\Visibility::VISIBLE));
     if ($includeContentTypeIdentifiers) {
         $criteria[] = new Criterion\ContentTypeIdentifier($includeContentTypeIdentifiers);
     }
     if (!empty($criterion)) {
         $criteria[] = $criterion;
     }
     $query = new Query(array('criterion' => new Criterion\LogicalAnd($criteria), 'sortClauses' => array(new SortClause\DatePublished(Query::SORT_DESC))));
     $query->limit = $limit ?: $this->defaultMenuLimit;
     return $this->searchHelper->buildListFromSearchResult($this->repository->getSearchService()->findContent($query));
 }
Exemple #2
0
    /**
     * 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 );
    }