Skip to content

Instantly share code, notes, and snippets.

@andrerom
Forked from dpobel/new_way.php
Last active December 12, 2015 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrerom/4754390 to your computer and use it in GitHub Desktop.
Save andrerom/4754390 to your computer and use it in GitHub Desktop.
Updated query to reflect added ContentTypeIdentifier by @crevillo in 0cb178324a63767664dc0aed0f2ddd1ace7d1e1d in January 2013
<?php
use \eZ\Publish\API\Repository\Values\Content\Query;
$locationService = $this->getRepository()->getLocationService();
$searchService = $this->getRepository()->getSearchService();
$urlAliasService = $this->getRepository()->getUrlAliasService();
$root = $locationService->loadLocation( 2 );
$query = new Query();
$query->criterion = new Criterion\LogicalAND(
array(
new Criterion\Subtree( $root->pathString ),
new Criterion\ContentTypeIdentifier( array( 'folder', 'page', 'contact' ) ),
new Criterion\Visibility( Criterion\Visibility::VISIBLE )
)
);
$query->sortClauses = array(
new SortClause\LocationPriority( Query::SORT_DESC )
);
$results = $searchService->findContent( $query );
$items = array( );
foreach ( $results->searchHits as $hit )
{
$location = $locationService->loadLocation(
$hit->valueObject->contentInfo->mainLocationId
);
$locationUrl = $urlAliasService->reverseLookup( $location )->path;
$items[$locationUrl] = $location;
}
foreach ( $items as $url => $location )
{
echo "url: {$url} name: {$location->contentInfo->name}\n";
}
<?php
$items = eZContentObject::subTreeByNodeID(
array(
'ClassFilterType' => 'include',
'ClassFilterArray' => array( 'folder', 'page', 'contact' ),
'SortBy' => array( array( 'priority', false ) )
),
2
);
foreach ( $items as $node )
{
echo "url: {$node->attribute( 'url_alias' )} name: {$node->attribute( 'name' )}\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment