Skip to content

Instantly share code, notes, and snippets.

@andrerom
Forked from dpobel/new_way.php
Last active December 12, 2015 09:49

Revisions

  1. andrerom revised this gist Feb 11, 2013. 1 changed file with 1 addition and 9 deletions.
    10 changes: 1 addition & 9 deletions new_way.php
    Original file line number Diff line number Diff line change
    @@ -4,21 +4,13 @@
    $locationService = $this->getRepository()->getLocationService();
    $searchService = $this->getRepository()->getSearchService();
    $urlAliasService = $this->getRepository()->getUrlAliasService();
    $typeService = $this->getRepository()->getContentTypeService();

    $identifiers = array( 'folder', 'page', 'contact' );
    $ids = array();
    foreach ( $identifiers as $identifier )
    {
    $ids[] = $typeService->loadByIdentifier( $identifier )->id;
    }

    $root = $locationService->loadLocation( 2 );
    $query = new Query();
    $query->criterion = new Criterion\LogicalAND(
    array(
    new Criterion\Subtree( $root->pathString ),
    new Criterion\ContentTypeId( $ids ),
    new Criterion\ContentTypeIdentifier( array( 'folder', 'page', 'contact' ) ),
    new Criterion\Visibility( Criterion\Visibility::VISIBLE )
    )
    );
  2. @dpobel dpobel revised this gist Nov 19, 2012. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion new_way.php
    Original file line number Diff line number Diff line change
    @@ -13,10 +13,11 @@
    $ids[] = $typeService->loadByIdentifier( $identifier )->id;
    }

    $root = $locationService->loadLocation( 2 );
    $query = new Query();
    $query->criterion = new Criterion\LogicalAND(
    array(
    new Criterion\ParentLocationId( 2 ),
    new Criterion\Subtree( $root->pathString ),
    new Criterion\ContentTypeId( $ids ),
    new Criterion\Visibility( Criterion\Visibility::VISIBLE )
    )
  3. @dpobel dpobel revised this gist Nov 19, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion new_way.php
    Original file line number Diff line number Diff line change
    @@ -22,7 +22,7 @@
    )
    );
    $query->sortClauses = array(
    new SortClause\LocationPriority( Query::SORT_ASC )
    new SortClause\LocationPriority( Query::SORT_DESC )
    );
    $results = $searchService->findContent( $query );
    $items = array( );
  4. @dpobel dpobel revised this gist Nov 19, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion new_way.php
    Original file line number Diff line number Diff line change
    @@ -22,7 +22,7 @@
    )
    );
    $query->sortClauses = array(
    new SortClause\LocationPriority()
    new SortClause\LocationPriority( Query::SORT_ASC )
    );
    $results = $searchService->findContent( $query );
    $items = array( );
  5. @dpobel dpobel revised this gist Nov 19, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion new_way.php
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    <?php
    use \eZ\Publish\API\Repository\Values\Content\Query,
    use \eZ\Publish\API\Repository\Values\Content\Query;

    $locationService = $this->getRepository()->getLocationService();
    $searchService = $this->getRepository()->getSearchService();
  6. @dpobel dpobel revised this gist Nov 19, 2012. 1 changed file with 8 additions and 12 deletions.
    20 changes: 8 additions & 12 deletions new_way.php
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,6 @@
    <?php
    use \eZ\Publish\API\Repository\Values\Content\Query,

    $locationService = $this->getRepository()->getLocationService();
    $searchService = $this->getRepository()->getSearchService();
    $urlAliasService = $this->getRepository()->getUrlAliasService();
    @@ -11,22 +13,16 @@
    $ids[] = $typeService->loadByIdentifier( $identifier )->id;
    }

    $query = new \eZ\Publish\API\Repository\Values\Content\Query();
    $query->criterion = new \eZ\Publish\API\Repository\Values\Content\Query\Criterion\LogicalAND(
    $query = new Query();
    $query->criterion = new Criterion\LogicalAND(
    array(
    new \eZ\Publish\API\Repository\Values\Content\Query\Criterion\ParentLocationId(
    2
    ),
    new \eZ\Publish\API\Repository\Values\Content\Query\Criterion\ContentTypeId(
    $ids
    ),
    new \eZ\Publish\API\Repository\Values\Content\Query\Criterion\Visibility(
    \eZ\Publish\API\Repository\Values\Content\Query\Criterion\Visibility::VISIBLE
    )
    new Criterion\ParentLocationId( 2 ),
    new Criterion\ContentTypeId( $ids ),
    new Criterion\Visibility( Criterion\Visibility::VISIBLE )
    )
    );
    $query->sortClauses = array(
    new \eZ\Publish\API\Repository\Values\Content\Query\SortClause\LocationPriority()
    new SortClause\LocationPriority()
    );
    $results = $searchService->findContent( $query );
    $items = array( );
  7. @dpobel dpobel revised this gist Nov 19, 2012. 1 changed file with 10 additions and 2 deletions.
    12 changes: 10 additions & 2 deletions new_way.php
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,14 @@
    $locationService = $this->getRepository()->getLocationService();
    $searchService = $this->getRepository()->getSearchService();
    $urlAliasService = $this->getRepository()->getUrlAliasService();
    $typeService = $this->getRepository()->getContentTypeService();

    $identifiers = array( 'folder', 'page', 'contact' );
    $ids = array();
    foreach ( $identifiers as $identifier )
    {
    $ids[] = $typeService->loadByIdentifier( $identifier )->id;
    }

    $query = new \eZ\Publish\API\Repository\Values\Content\Query();
    $query->criterion = new \eZ\Publish\API\Repository\Values\Content\Query\Criterion\LogicalAND(
    @@ -10,7 +18,7 @@
    2
    ),
    new \eZ\Publish\API\Repository\Values\Content\Query\Criterion\ContentTypeId(
    array( 1, 20, 21 )
    $ids
    ),
    new \eZ\Publish\API\Repository\Values\Content\Query\Criterion\Visibility(
    \eZ\Publish\API\Repository\Values\Content\Query\Criterion\Visibility::VISIBLE
    @@ -34,4 +42,4 @@
    foreach ( $items as $url => $location )
    {
    echo "url: {$url} name: {$location->contentInfo->name}\n";
    }
    }
  8. @dpobel dpobel revised this gist Nov 19, 2012. 2 changed files with 0 additions and 2 deletions.
    1 change: 0 additions & 1 deletion new_way.php
    Original file line number Diff line number Diff line change
    @@ -31,7 +31,6 @@
    $items[$locationUrl] = $location;
    }

    // somewhere in a template
    foreach ( $items as $url => $location )
    {
    echo "url: {$url} name: {$location->contentInfo->name}\n";
    1 change: 0 additions & 1 deletion old_way.php
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,6 @@
    2
    );

    // somewhere in a template
    foreach ( $items as $node )
    {
    echo "url: {$node->attribute( 'url_alias' )} name: {$node->attribute( 'name' )}\n";
  9. @dpobel dpobel revised this gist Nov 19, 2012. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions new_way.php
    Original file line number Diff line number Diff line change
    @@ -11,6 +11,9 @@
    ),
    new \eZ\Publish\API\Repository\Values\Content\Query\Criterion\ContentTypeId(
    array( 1, 20, 21 )
    ),
    new \eZ\Publish\API\Repository\Values\Content\Query\Criterion\Visibility(
    \eZ\Publish\API\Repository\Values\Content\Query\Criterion\Visibility::VISIBLE
    )
    )
    );
  10. @dpobel dpobel revised this gist Oct 31, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion new_way.php
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    <?php
    $locationService = $this->getRepository()->getLocationService();
    $searchService = $this->getRepository()->getSearchService();
    $urlAliasService = $this>getRepository()->getUrlAliasService();
    $urlAliasService = $this->getRepository()->getUrlAliasService();

    $query = new \eZ\Publish\API\Repository\Values\Content\Query();
    $query->criterion = new \eZ\Publish\API\Repository\Values\Content\Query\Criterion\LogicalAND(
  11. @dpobel dpobel revised this gist Oct 31, 2012. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion new_way.php
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    <?php
    $locationService = $this->getRepository()->getLocationService();
    $searchService = $this->getRepository()->getSearchService();
    $urlAliasService = $this−>getRepository()->getUrlAliasService();

    $query = new \eZ\Publish\API\Repository\Values\Content\Query();
    $query->criterion = new \eZ\Publish\API\Repository\Values\Content\Query\Criterion\LogicalAND(
    @@ -30,5 +31,5 @@
    // somewhere in a template
    foreach ( $items as $url => $location )
    {
    echo "url: $url name: {$location->contentInfo->name}\n";
    echo "url: {$url} name: {$location->contentInfo->name}\n";
    }
  12. @dpobel dpobel revised this gist Oct 31, 2012. 2 changed files with 16 additions and 3 deletions.
    9 changes: 8 additions & 1 deletion new_way.php
    Original file line number Diff line number Diff line change
    @@ -23,5 +23,12 @@
    $location = $locationService->loadLocation(
    $hit->valueObject->contentInfo->mainLocationId
    );
    $items[] = $location;
    $locationUrl = $urlAliasService->reverseLookup( $location )->path;
    $items[$locationUrl] = $location;
    }

    // somewhere in a template
    foreach ( $items as $url => $location )
    {
    echo "url: $url name: {$location->contentInfo->name}\n";
    }
    10 changes: 8 additions & 2 deletions old_way.php
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,15 @@
    <?php
    eZContentObject::subTreeByNodeID(
    $items = eZContentObject::subTreeByNodeID(
    array(
    'ClassFilterType' => 'include',
    'ClassFilterArray' => array( 'folder', 'page', 'contact' ),
    'SortBy' => array( array( 'priority', false ) )
    ),
    2
    );
    );

    // somewhere in a template
    foreach ( $items as $node )
    {
    echo "url: {$node->attribute( 'url_alias' )} name: {$node->attribute( 'name' )}\n";
    }
  13. @dpobel dpobel created this gist Oct 30, 2012.
    27 changes: 27 additions & 0 deletions new_way.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    <?php
    $locationService = $this->getRepository()->getLocationService();
    $searchService = $this->getRepository()->getSearchService();

    $query = new \eZ\Publish\API\Repository\Values\Content\Query();
    $query->criterion = new \eZ\Publish\API\Repository\Values\Content\Query\Criterion\LogicalAND(
    array(
    new \eZ\Publish\API\Repository\Values\Content\Query\Criterion\ParentLocationId(
    2
    ),
    new \eZ\Publish\API\Repository\Values\Content\Query\Criterion\ContentTypeId(
    array( 1, 20, 21 )
    )
    )
    );
    $query->sortClauses = array(
    new \eZ\Publish\API\Repository\Values\Content\Query\SortClause\LocationPriority()
    );
    $results = $searchService->findContent( $query );
    $items = array( );
    foreach ( $results->searchHits as $hit )
    {
    $location = $locationService->loadLocation(
    $hit->valueObject->contentInfo->mainLocationId
    );
    $items[] = $location;
    }
    9 changes: 9 additions & 0 deletions old_way.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    <?php
    eZContentObject::subTreeByNodeID(
    array(
    'ClassFilterType' => 'include',
    'ClassFilterArray' => array( 'folder', 'page', 'contact' ),
    'SortBy' => array( array( 'priority', false ) )
    ),
    2
    );