/** * Returns a struct containing the following values: * - limit the number of element by page * - offset the current offset * - items array, each element contains * - has_child boolean * - can_create boolean * - node eZContentObjectTreeNode * - has_prev boolean, true if there's a previous page * - has_next boolean, true if there's a next page * * @param eZContentObjectTreeNode $start the node where the browse will start * @param eZContentClass $class class of the object to be created * @param int $offset * @return array */ private static function getBrowseItems( eZContentObjectTreeNode $start, eZContentClass $class, $offset = 0 ) { $result = array( 'limit' => 10, 'offset' => $offset, 'items' => array(), 'has_prev' => ( $offset != 0 ), 'has_next' => false ); $containerClasses = eZPersistentObject::fetchObjectList( eZContentClass::definition(), null, array( 'version' => eZContentClass::VERSION_STATUS_DEFINED, 'is_container' => 1 ) ); $classFilterArray = array(); foreach ( $containerClasses as $c ) { $classFilterArray[] = $c->attribute( 'identifier' ); } $children = $start->subTree( array( 'ClassFilterArray' => $classFilterArray, 'ClassFilterType' => 'include', 'Depth' => 1, 'Limit' => $result['limit'], 'Offset' => $offset ) ); $count = $start->subTreeCount( array( 'ClassFilterArray' => $classFilterArray, 'ClassFilterType' => 'include', 'Depth' => 1 ) ); if ( $count > ( $offset + $result['limit'] ) ) { $result['has_next'] = true; } foreach( $children as $node ) { $elt = array(); $elt['node'] = $node; $canCreateClassist = $node->canCreateClassList(); foreach( $canCreateClassist as $c ) { if ( $c['id'] == $class->attribute( 'id' ) ) { $elt['can_create'] = true; break; } } if ( !isset( $elt['can_create'] ) ) { $elt['can_create'] = false; } $childrenContainerCount = $node->subTreeCount( array( 'ClassFilterArray' => $classFilterArray, 'ClassFilterType' => 'include', 'Depth' => 1 ) ); $elt['has_child'] = ( $childrenContainerCount > 0 ); $result['items'][] = $elt; } return $result; }
/** * Clears the view cache for a subtree * * @param eZContentObjectTreeNode $node * @param bool $clearForRootNode * @return bool */ static function clearViewCacheForSubtree(eZContentObjectTreeNode $node, $clearForRootNode = true) { // Max nodes to fetch at a time static $limit = 200; if ($clearForRootNode) { $objectID = $node->attribute('contentobject_id'); eZContentCacheManager::clearContentCacheIfNeeded($objectID); } $offset = 0; $params = array('AsObject' => false, 'Depth' => false, 'Limitation' => array()); // Empty array means no permission checking $subtreeCount = $node->subTreeCount($params); while ($offset < $subtreeCount) { $params['Offset'] = $offset; $params['Limit'] = $limit; $subtreeChunk = $node->subTree($params); $nNodesInChunk = count($subtreeChunk); $offset += $nNodesInChunk; if ($nNodesInChunk == 0) { break; } $objectIDList = array(); foreach ($subtreeChunk as $curNode) { $objectIDList[] = $curNode['id']; } unset($subtreeChunk); eZContentCacheManager::clearContentCacheIfNeeded(array_unique($objectIDList)); } return true; }
public function fetchCount() { return $this->mainNode->subTreeCount($this->fetchParameters); }