eZ Community » Forums » eZ Publish 5 Platform » Depth location in criterion
expandshrink

Depth location in criterion

Depth location in criterion

Saturday 28 June 2014 9:24:37 pm - 5 replies

Hello, 

I'm trying to retrieve all objects of a son without success.
The following code causes an error:

 <span style="font-size: 1.1em;">$criteria = array();        </span>
 
$resultats = array();        
$query = new Query();
$criteria[] = new Criterion\ParentLocationId((int)
$parentLocationId);
        if (array_key_exists('depth', $options)) {            
            $criteria[] = new Criterion\Location\Depth( Criterion\Operator::LTE, $options['depth']); 
<span style="font-size: 1.1em;"> }</span>
 
        $query->criterion = new Criterion\LogicalAnd($criteria);
 
        foreach ($this->repository->getSearchService()->findContent( $query)->searchHits as $r) {
                      $tmp = $this->locationService->loadLocation(
$r->valueObject->versionInfo->contentInfo->mainLocationId
);
            $resultats[] = $this->repository->getContentService()->loadContent($tmp->contentId);       
}

The error:

An exception has been thrown during the rendering of a template ("Argument '$query' is invalid: Location criterions cannot be used in Content search"blunk.gif Emoticon in ...

I do not understand what the problem is. You would have an idea?

Modified on Monday 30 June 2014 12:09:19 am by Jonathan Clavier

Saturday 28 June 2014 11:14:21 pm

To use Criterion\Location\Depth you have to be doing a Location search not a content search.
You would use a LocationQuery instead and use findLocations. 

Monday 30 June 2014 12:07:44 am

Thank you for your reply, but I need to recover the contents of each son objects with depth parameter.
I have no results 'empty array).
Any idéa ?

        if (array_key_exists('depth', $options)) {           
           $criteria[] = new Criterion\Location\Depth( Criterion\Operator::GTE, $options['depth']); 
       }
 
       $query->criterion = new Criterion\LogicalAnd($criteria);
 
  foreach ($this->repository->getSearchService()->findLocations( $query )->searchHits as $r) {
            $tmp = $this->locationService->loadLocation(                
                  $r->valueObject->contentInfo->mainLocationId            
          );
            $resultats[] = $this->repository->getContentService()->loadContent($tmp->contentId);        }

Monday 30 June 2014 2:34:25 am

If by "son" objects you mean children take a look at this gist.  Specifically the MenuHelper and SearchHelper that build

the subtree. 

https://gist.github.com/wizhippo/823d8b5b8455b26ad310

I hope this is along the lines of what you are looking for.  If not please clarify what you mean by "son" objects. 

Monday 30 June 2014 11:58:56 am

Thank you for the reply, but I did not explain myself properly. 

I'm on node 2 and I have objects of the same class but of different depths in my tree. I would like to retrieve all objects with a depth of 3.

In eZ4, it's:

$nodes =& eZContentObjectTreeNode::subTree( array( 'Depth' => 1,'ClassFilterType' => 'include','ClassFilterArray' => array( 'folder' ) ), 2 );

Modified on Monday 30 June 2014 12:00:00 pm by Jonathan Clavier

Monday 30 June 2014 3:17:57 pm

In your first post you have the following criteria:

new Criterion\ParentLocationId((int) $parentLocationId);

Is this still part of your Query?

If so this will restrict the search to content/locations that are only direct descendants of $parentLocationId and will not return the children/subtree.

You may want to replace that with:

new Criterion\Subtree($parentLocation->pathString);

So in the end something like:

$criteria = array(
      new Criterion\Subtree( $pathString ),
      new Criterion\Location\Depth( Operator::GTE,  $depth ),
      new Criterion\Visibility( Criterion\Visibility::VISIBLE ),
      new Criterion\ContentTypeIdentifier( $contentTypeIdentifier )
);

Modified on Monday 30 June 2014 3:19:50 pm by Douglas Hammond

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from