/** * Returns all direct child nodes of this node. * If a node type is specified, only nodes of that type are returned. * * @param string $nodeTypeFilter If specified, only nodes with that node type are considered * @param integer $limit An optional limit for the number of nodes to find. Added or removed nodes can still change the number nodes! * @param integer $offset An optional offset for the query * @return array<\TYPO3\TYPO3CR\Domain\Model\NodeInterface> An array of nodes or an empty array if no child nodes matched * @api */ public function getChildNodes($nodeTypeFilter = NULL, $limit = NULL, $offset = NULL) { $nodes = $this->context->getFirstLevelNodeCache()->getChildNodesByPathAndNodeTypeFilter($this->getPath(), $nodeTypeFilter); if ($nodes === FALSE) { $nodes = $this->nodeDataRepository->findByParentAndNodeTypeInContext($this->getPath(), $nodeTypeFilter, $this->context, $limit, $offset); $this->context->getFirstLevelNodeCache()->setChildNodesByPathAndNodeTypeFilter($this->getPath(), $nodeTypeFilter, $nodes); } if ($offset !== NULL || $limit !== NULL) { $offset = $offset === NULL ? 0 : $offset; return array_slice($nodes, $offset, $limit); } return $nodes; }
/** * getRandomProducts * * @param Context $context * @param NodeInterface $startingPointProducts * * @return array */ private function getRandomProducts(Context $context, NodeInterface $startingPointProducts) { $searchResult = array(); $randomProducts = $this->nodeDataRepository->findByParentAndNodeTypeInContext($startingPointProducts->getPath(), 'Egobude.Products:Product', $context, TRUE); if (!empty($randomProducts)) { foreach ($randomProducts as $node) { /* @var $node \TYPO3\TYPO3CR\Domain\Model\NodeInterface */ $searchResult[] = $node->getIdentifier(); } shuffle($searchResult); $searchResult = array_slice($searchResult, mt_rand(1, count($searchResult))); } return $searchResult; }
/** * {@inheritdoc} * * @param FlowQuery $flowQuery the FlowQuery object * @param array $arguments the arguments for this operation * @return void */ public function evaluate(FlowQuery $flowQuery, array $arguments) { $context = $flowQuery->getContext(); if (!isset($context[0]) || empty($arguments[0])) { return; } $result = array(); $selectorAndFilter = $arguments[0]; $parsedFilter = NULL; $parsedFilter = \TYPO3\Eel\FlowQuery\FizzleParser::parseFilterGroup($selectorAndFilter); if (isset($parsedFilter['Filters']) && $this->hasOnlyInstanceOfFilters($parsedFilter['Filters'])) { $nodeTypes = array(); foreach ($parsedFilter['Filters'] as $filter) { $nodeTypes[] = $filter['AttributeFilters'][0]['Operand']; } /** @var \TYPO3\TYPO3CR\Domain\Model\NodeInterface $contextNode */ foreach ($context as $contextNode) { $result = array_merge($result, $this->nodeDataRepository->findByParentAndNodeTypeInContext($contextNode->getPath(), implode(',', $nodeTypes), $contextNode->getContext(), TRUE)); } } else { foreach ($parsedFilter['Filters'] as $filter) { $filterResults = array(); $generatedNodes = FALSE; if (isset($filter['IdentifierFilter'])) { if (!preg_match(\TYPO3\Flow\Validation\Validator\UuidValidator::PATTERN_MATCH_UUID, $filter['IdentifierFilter'])) { throw new \TYPO3\Eel\FlowQuery\FlowQueryException('find() requires a valid identifier', 1332492263); } /** @var \TYPO3\TYPO3CR\Domain\Model\NodeInterface $contextNode */ foreach ($context as $contextNode) { $filterResults = array($contextNode->getContext()->getNodeByIdentifier($filter['IdentifierFilter'])); } $generatedNodes = TRUE; } elseif (isset($filter['IdentifierFilter'])) { if (!preg_match(\TYPO3\Flow\Validation\Validator\UuidValidator::PATTERN_MATCH_UUID, $filter['IdentifierFilter'])) { throw new \TYPO3\Eel\FlowQuery\FlowQueryException('find() requires a valid identifier', 1332492263); } /** @var \TYPO3\TYPO3CR\Domain\Model\NodeInterface $contextNode */ foreach ($context as $contextNode) { $filterResults = array($contextNode->getContext()->getNodeByIdentifier($filter['IdentifierFilter'])); } $generatedNodes = TRUE; } elseif (isset($filter['PropertyNameFilter']) || isset($filter['PathFilter'])) { $nodePath = isset($filter['PropertyNameFilter']) ? $filter['PropertyNameFilter'] : $filter['PathFilter']; foreach ($context as $contextNode) { $node = $contextNode->getNode($nodePath); if ($node !== NULL) { array_push($filterResults, $node); } } $generatedNodes = TRUE; } if (isset($filter['AttributeFilters']) && $filter['AttributeFilters'][0]['Operator'] === 'instanceof') { foreach ($context as $contextNode) { $filterResults = array_merge($filterResults, $this->nodeDataRepository->findByParentAndNodeTypeInContext($contextNode->getPath(), $filter['AttributeFilters'][0]['Operand'], $contextNode->getContext(), TRUE)); } unset($filter['AttributeFilters'][0]); $generatedNodes = TRUE; } if (isset($filter['AttributeFilters']) && count($filter['AttributeFilters']) > 0) { if (!$generatedNodes) { throw new \TYPO3\Eel\FlowQuery\FlowQueryException('find() needs an identifier, path or instanceof filter for the first filter part', 1436884196); } $filterQuery = new FlowQuery($filterResults); foreach ($filter['AttributeFilters'] as $attributeFilter) { $filterQuery->pushOperation('filter', array($attributeFilter['text'])); } $filterResults = $filterQuery->get(); } $result = array_merge($result, $filterResults); } } $flowQuery->setContext(array_unique($result)); }