Last active
August 29, 2015 13:58
-
-
Save pspanja/9972066 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Example of Criterions not relating to each other: | |
There is a Content with two Locations: Location A and Location B | |
- Location A is visible | |
- Location B is hidden | |
Searching with LocationId criterion with Location B id and Visibility | |
criterion with Visibility::VISIBLE will return the Content because | |
conditions are satisfied: | |
- Content has Location B | |
- Content is visible (it has Location A that is visible) | |
Code: | |
<?php | |
use eZ\Publish\API\Repository\Values\Content\Query; | |
use eZ\Publish\API\Repository\Values\Content\Query\Criterion\LogicalAnd; | |
use eZ\Publish\API\Repository\Values\Content\Query\Criterion\LocationId; | |
use eZ\Publish\API\Repository\Values\Content\Query\Criterion\Visibility; | |
/** @var string|int $locationBId */ | |
/** @var \eZ\Publish\API\Repository\Repository $repository */ | |
$searchService = $repository->getSearchService(); | |
$query = new Query( | |
array( | |
'filter' => new LogicalAnd( | |
array( | |
new LocationId( $locationBId ), | |
new Visibility( Visibility::VISIBLE ), | |
) | |
) | |
) | |
); | |
$searchResult = $searchService->findContent( $query ); | |
// Content is found | |
$content = $searchResult->searchHits[0]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment