/**
  * @test
  */
 public function findNodesByPropertyKeyAndValue()
 {
     $this->createNodesForNodeSearchTest();
     $result = $this->nodeDataRepository->findByProperties(array('test2' => 'simpleTestValue'), 'TYPO3.TYPO3CR.Testing:NodeType', $this->liveWorkspace, $this->context->getDimensions());
     $this->assertCount(1, $result);
     $this->assertEquals('test-node-2', array_shift($result)->getName());
 }
Exemplo n.º 2
0
 /**
  * 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 $term
  * @param array $searchNodeTypes
  * @param Context $context
  * @param NodeInterface $startingPoint
  * @return array <\TYPO3\TYPO3CR\Domain\Model\NodeInterface>
  */
 public function findByProperties($term, array $searchNodeTypes, Context $context, NodeInterface $startingPoint = null)
 {
     if (strlen($term) === 0) {
         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;
 }
Exemplo n.º 4
0
 /**
  * The dimension value of this node has to match the current target dimension value (must be higher in priority or equal)
  *
  * @return boolean
  */
 protected function dimensionsAreMatchingTargetDimensionValues()
 {
     $dimensions = $this->getDimensions();
     $contextDimensions = $this->context->getDimensions();
     foreach ($this->context->getTargetDimensions() as $dimensionName => $targetDimensionValue) {
         if (!isset($dimensions[$dimensionName])) {
             return FALSE;
         } 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;
 }
Exemplo n.º 5
0
 /**
  * Returns the specified property.
  *
  * If the node has a content object attached, the property will be fetched
  * there if it is gettable.
  *
  * @param string $propertyName Name of the property
  * @param boolean $returnNodesAsIdentifiers If enabled, references to nodes are returned as node identifiers instead of NodeData objects
  * @param \TYPO3\TYPO3CR\Domain\Service\Context $context An optional Context if $returnNodesAsIdentifiers === TRUE
  * @return mixed value of the property
  * @throws \TYPO3\TYPO3CR\Exception\NodeException if the content object exists but does not contain the specified property.
  */
 public function getProperty($propertyName, $returnNodesAsIdentifiers = FALSE, \TYPO3\TYPO3CR\Domain\Service\Context $context = NULL)
 {
     if (!is_object($this->contentObjectProxy)) {
         $value = isset($this->properties[$propertyName]) ? $this->properties[$propertyName] : NULL;
         if (!empty($value)) {
             // TODO: The next two lines are workarounds, actually a NodeData cannot correctly return references but should always return identifier. Node should then apply the context and return the real Node objects.
             $dimensions = $context !== NULL ? $context->getDimensions() : array();
             $workspace = $context !== NULL ? $context->getWorkspace() : $this->getWorkspace();
             switch ($this->getNodeType()->getPropertyType($propertyName)) {
                 case 'references':
                     $nodeDatas = array();
                     if (!is_array($value)) {
                         $value = array();
                     }
                     $valueNeedsToBeFixed = FALSE;
                     foreach ($value as $nodeIdentifier) {
                         // in cases where a reference is a NodeData instance, fix this
                         if ($nodeIdentifier instanceof NodeData) {
                             $nodeIdentifier = $nodeIdentifier->getIdentifier();
                             $valueNeedsToBeFixed = TRUE;
                         }
                         if ($returnNodesAsIdentifiers === FALSE) {
                             $nodeData = $this->nodeDataRepository->findOneByIdentifier($nodeIdentifier, $workspace, $dimensions);
                             if ($nodeData instanceof NodeData) {
                                 $nodeDatas[] = $nodeData;
                             }
                         } else {
                             $nodeDatas[] = $nodeIdentifier;
                         }
                     }
                     if ($valueNeedsToBeFixed === TRUE) {
                         $fixedValue = array();
                         foreach ($value as $nodeIdentifier) {
                             if ($nodeIdentifier instanceof NodeData) {
                                 $fixedValue[] = $nodeIdentifier->getIdentifier();
                             } else {
                                 $fixedValue[] = $nodeIdentifier;
                             }
                         }
                         $this->properties[$propertyName] = $fixedValue;
                         $this->update();
                     }
                     $value = $nodeDatas;
                     break;
                 case 'reference':
                     // in cases where a reference is a NodeData instance, fix this
                     if ($value instanceof NodeData) {
                         $value = $value->getIdentifier();
                         $this->properties[$propertyName] = $value;
                         $this->update();
                     }
                     if ($returnNodesAsIdentifiers === FALSE) {
                         $nodeData = $this->nodeDataRepository->findOneByIdentifier($value, $workspace, $dimensions);
                         if ($nodeData instanceof NodeData) {
                             $value = $nodeData;
                         } else {
                             $value = NULL;
                         }
                     }
                     break;
             }
         }
         return $value;
     } elseif (ObjectAccess::isPropertyGettable($this->contentObjectProxy->getObject(), $propertyName)) {
         return ObjectAccess::getProperty($this->contentObjectProxy->getObject(), $propertyName);
     }
     throw new \TYPO3\TYPO3CR\Exception\NodeException(sprintf('Property "%s" does not exist in content object of type %s.', $propertyName, get_class($this->contentObjectProxy->getObject())), 1291286995);
 }
 /**
  * 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. "TYPO3.Neos:Page", "!TYPO3.Neos:Page,TYPO3.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;
 }
Exemplo n.º 7
0
 /**
  * Adjust this instance to the given context.
  *
  * Internal use only!
  *
  * @param Context $context
  * @throws \TYPO3\TYPO3CR\Exception\InvalidNodeContextException
  */
 public function adjustToContext(Context $context)
 {
     $this->setWorkspace($context->getWorkspace());
     $nodeDimensions = new \Doctrine\Common\Collections\ArrayCollection();
     $targetDimensionValues = $context->getTargetDimensions();
     foreach ($context->getDimensions() as $dimensionName => $dimensionValues) {
         if (!isset($targetDimensionValues[$dimensionName])) {
             throw new \TYPO3\TYPO3CR\Exception\InvalidNodeContextException(sprintf('Missing target value for dimension "%"', $dimensionName), 1391686089);
         }
         $dimensionValueToSet = $targetDimensionValues[$dimensionName];
         $nodeDimensions->add(new NodeDimension($this, $dimensionName, $dimensionValueToSet));
     }
     $this->setDimensions($nodeDimensions);
 }