public function getChildren($path) { $root = $this->session->getNode($path); $children = array(); foreach ($root->getNodes() as $name => $node) { if (NodeHelper::isSystemItem($node)) { continue; } $child = $this->nodeToArray($name, $node); foreach ($node->getNodes() as $childname => $grandson) { $child['children'][] = $this->nodeToArray($childname, $grandson); } $children[] = $child; } return $children; }
public function testIsSystemItem() { $sys = $this->getMock('PHPCR\\Tests\\Stubs\\MockNode'); $sys->expects($this->once())->method('getDepth')->will($this->returnValue(0)); $sys->expects($this->once())->method('getName')->will($this->returnValue('jcr:root')); $this->assertTrue(NodeHelper::isSystemItem($sys)); $sys = $this->getMock('PHPCR\\Tests\\Stubs\\MockNode'); $sys->expects($this->once())->method('getDepth')->will($this->returnValue(1)); $sys->expects($this->once())->method('getName')->will($this->returnValue('jcr:system')); $this->assertTrue(NodeHelper::isSystemItem($sys)); $top = $this->getMock('PHPCR\\Tests\\Stubs\\MockNode'); $top->expects($this->once())->method('getDepth')->will($this->returnValue(1)); $top->expects($this->once())->method('getName')->will($this->returnValue('jcrname')); $this->assertFalse(NodeHelper::isSystemItem($top)); $deep = $this->getMock('PHPCR\\Tests\\Stubs\\MockNode'); $deep->expects($this->once())->method('getDepth')->will($this->returnValue(2)); $this->assertFalse(NodeHelper::isSystemItem($deep)); }
/** * Recursively output node and all its children into the file in the * document view format * * @param NodeInterface $node the node to output * @param NamespaceRegistryInterface $ns The namespace registry to export namespaces too * @param resource $stream the resource to write data out to * @param boolean $skipBinary A boolean governing whether binary properties * are to be serialized. * @param boolean $noRecurse A boolean governing whether the subgraph at * absPath is to be recursed. * @param boolean $root Whether this is the root node of the resulting * document, meaning the namespace declarations have to be included in * it. */ private static function exportDocumentViewRecursive(NodeInterface $node, NamespaceRegistryInterface $ns, $stream, $skipBinary, $noRecurse, $root = false) { $nodename = self::escapeXmlName($node->getName()); fwrite($stream, "<{$nodename}"); if ($root) { self::exportNamespaceDeclarations($ns, $stream); } foreach ($node->getProperties() as $name => $property) { /** @var $property \PHPCR\PropertyInterface */ if ($property->isMultiple()) { // skip multiple properties. jackrabbit does this too. cheap but whatever. use system view for a complete export continue; } if (PropertyType::BINARY == $property->getType()) { if ($skipBinary) { continue; } $value = base64_encode($property->getString()); } else { $value = htmlspecialchars($property->getString()); } fwrite($stream, ' ' . self::escapeXmlName($name) . '="' . $value . '"'); } if ($noRecurse || !$node->hasNodes()) { fwrite($stream, '/>'); } else { fwrite($stream, '>'); foreach ($node as $child) { if (!($child->getDepth() == 1 && NodeHelper::isSystemItem($child))) { self::exportDocumentViewRecursive($child, $ns, $stream, $skipBinary, $noRecurse); } } fwrite($stream, "</{$nodename}>"); } }
/** * This method fetches all version labels, if the cache array is not initialized yet. */ private function initVersionLabels() { if (!is_null($this->versionLabels)) { return; } $this->versionLabels = array(); $node = $this->getNode('jcr:versionLabels'); foreach ($node->getProperties() as $property) { /* @var Property $property */ if (NodeHelper::isSystemItem($node)) { $name = $property->getName(); $value = $this->objectManager->getNodeByIdentifier($property->getValue()->getIdentifier(), 'Version\\Version'); $this->versionLabels[$name] = $value; } } }
/** * Checks whether this item is a system item * * @param ItemInterface $item * * @return boolean */ public function mustVisit(ItemInterface $item) { return !NodeHelper::isSystemItem($item); }
/** * Get the children of the document at this path by looking at the Child and Children mappings. * * {@inheritDoc} */ public function getChildren($path) { $root = $this->dm->find(null, $path); $children = array(); if ($root) { $rootManager = $this->getModelManager($root); foreach ($this->getDocumentChildren($rootManager, $root) as $document) { if ($document instanceof Generic && (NodeHelper::isSystemItem($document->getNode()) || !strncmp('phpcr_locale:', $document->getNode()->getName(), 13))) { continue; } $manager = $this->getModelManager($document); $child = $this->documentToArray($manager, $document); if ($this->depth > 0) { foreach ($this->getDocumentChildren($manager, $document) as $grandchild) { $child['children'][] = $this->documentToArray($manager, $grandchild); } } $children[] = $child; } } return $children; }