eZ\Publish\Core\Repository\SearchService::findLocations PHP Method

findLocations() public method

Finds Locations for the given query.
public findLocations ( eZ\Publish\API\Repository\Values\Content\LocationQuery $query, array $languageFilter = [], boolean $filterOnUserPermissions = true ) : eZ\Publish\API\Repository\Values\Content\Search\SearchResult
$query eZ\Publish\API\Repository\Values\Content\LocationQuery
$languageFilter array Configuration for specifying prioritized languages query will be performed on. Currently supports: array("languages" => array(,..), "useAlwaysAvailable" => bool) useAlwaysAvailable defaults to true to avoid exceptions on missing translations
$filterOnUserPermissions boolean 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 findLocations(LocationQuery $query, array $languageFilter = array(), $filterOnUserPermissions = true)
    {
        if (!is_int($query->offset)) {
            throw new InvalidArgumentType('$query->offset', 'integer', $query->offset);
        }
        if (!is_int($query->limit)) {
            throw new InvalidArgumentType('$query->limit', 'integer', $query->limit);
        }
        $query = clone $query;
        $query->filter = $query->filter ?: new Criterion\MatchAll();
        if ($filterOnUserPermissions && !$this->permissionsCriterionHandler->addPermissionsCriterion($query->filter)) {
            return new SearchResult(array('time' => 0, 'totalCount' => 0));
        }
        $result = $this->searchHandler->findLocations($query, $languageFilter);
        foreach ($result->searchHits as $hit) {
            $hit->valueObject = $this->domainMapper->buildLocationDomainObject($hit->valueObject);
        }
        return $result;
    }

Usage Example

 /**
  * Returns the number of results.
  *
  * @return integer The number of results.
  */
 public function getNbResults()
 {
     if (isset($this->nbResults)) {
         return $this->nbResults;
     }
     $countQuery = clone $this->query;
     $countQuery->limit = 0;
     return $this->nbResults = $this->searchService->findLocations($countQuery)->totalCount;
 }
All Usage Examples Of eZ\Publish\Core\Repository\SearchService::findLocations