/** * @test */ public function findNodesByPropertyKeyAndValue() { $this->createNodesForNodeSearchTest(); $result = $this->nodeDataRepository->findByProperties(array('test2' => 'simpleTestValue'), 'Neos.ContentRepository.Testing:NodeType', $this->liveWorkspace, $this->context->getDimensions()); $this->assertCount(1, $result); $this->assertEquals('test-node-2', array_shift($result)->getName()); }
/** * Internal method * * The dimension value of this node has to match the current target dimension value (must be higher in priority or equal) * * @return boolean */ public function dimensionsAreMatchingTargetDimensionValues() { $dimensions = $this->getDimensions(); $contextDimensions = $this->context->getDimensions(); foreach ($this->context->getTargetDimensions() as $dimensionName => $targetDimensionValue) { if (!isset($dimensions[$dimensionName])) { if ($targetDimensionValue === null) { continue; } else { return false; } } elseif ($targetDimensionValue === null && $dimensions[$dimensionName] === array()) { continue; } elseif (!in_array($targetDimensionValue, $dimensions[$dimensionName], true)) { $contextDimensionValues = $contextDimensions[$dimensionName]; $targetPositionInContext = array_search($targetDimensionValue, $contextDimensionValues, true); $nodePositionInContext = min(array_map(function ($value) use($contextDimensionValues) { return array_search($value, $contextDimensionValues, true); }, $dimensions[$dimensionName])); $val = $targetPositionInContext !== false && $nodePositionInContext !== false && $targetPositionInContext >= $nodePositionInContext; if ($val === false) { return false; } } } return true; }
/** * Search all properties for given $term * * TODO: Implement a better search when Flow offer the possibility * * @param string|array $term search term * @param array $searchNodeTypes * @param Context $context * @param NodeInterface $startingPoint * @return array <\Neos\ContentRepository\Domain\Model\NodeInterface> */ public function findByProperties($term, array $searchNodeTypes, Context $context, NodeInterface $startingPoint = null) { if (empty($term)) { throw new \InvalidArgumentException('"term" cannot be empty: provide a term to search for.', 1421329285); } $searchResult = array(); $nodeTypeFilter = implode(',', $searchNodeTypes); $nodeDataRecords = $this->nodeDataRepository->findByProperties($term, $nodeTypeFilter, $context->getWorkspace(), $context->getDimensions(), $startingPoint ? $startingPoint->getPath() : null); foreach ($nodeDataRecords as $nodeData) { $node = $this->nodeFactory->createFromNodeData($nodeData, $context); if ($node !== null) { $searchResult[$node->getPath()] = $node; } } return $searchResult; }
/** * Finds a single node by its parent and (optionally) by its node type * * @param string $parentPath Absolute path of the parent node * @param string $nodeTypeFilter Filter the node type of the nodes, allows complex expressions (e.g. "Neos.Neos:Page", "!Neos.Neos:Page,Neos.Neos:Text" or NULL) * @param Context $context The containing context * @return NodeData The node found or NULL */ public function findFirstByParentAndNodeTypeInContext($parentPath, $nodeTypeFilter, Context $context) { $firstNode = $this->findFirstByParentAndNodeType($parentPath, $nodeTypeFilter, $context->getWorkspace(), $context->getDimensions(), $context->isRemovedContentShown() ? null : false); if ($firstNode !== null) { $firstNode = $this->nodeFactory->createFromNodeData($firstNode, $context); } return $firstNode; }