/** * @param QueryInterface $query * @param $nodeTypeFilter * @return array */ protected function getNodeTypeFilterConstraints(QueryInterface $query, $nodeTypeFilter) { $includeNodeTypeConstraints = array(); $excludeNodeTypeConstraints = array(); $nodeTypeFilterParts = Arrays::trimExplode(',', $nodeTypeFilter); foreach ($nodeTypeFilterParts as $nodeTypeFilterPart) { $nodeTypeFilterPart = trim($nodeTypeFilterPart); if (strpos($nodeTypeFilterPart, '!') === 0) { $negate = true; $nodeTypeFilterPart = substr($nodeTypeFilterPart, 1); } else { $negate = false; } $nodeTypeFilterPartSubTypes = array_merge(array($nodeTypeFilterPart), $this->nodeTypeManager->getSubNodeTypes($nodeTypeFilterPart, false)); foreach ($nodeTypeFilterPartSubTypes as $nodeTypeFilterPartSubType) { if ($negate === true) { $excludeNodeTypeConstraints[] = $query->logicalNot($query->equals('nodeType', $nodeTypeFilterPartSubType)); } else { $includeNodeTypeConstraints[] = $query->equals('nodeType', $nodeTypeFilterPartSubType); } } } $constraints = $excludeNodeTypeConstraints; if (count($includeNodeTypeConstraints) > 0) { $constraints[] = $query->logicalOr($includeNodeTypeConstraints); } return $constraints; }
/** * Builds a QOM constraint object for one single constraint expression * * @param array $constraintDefinition The constraint expression * @param \TYPO3\Flow\Persistence\QueryInterface $query The query object to build the constraint with * @return \TYPO3\Flow\Persistence\Generic\Qom\Constraint The build constraint object * @throws \TYPO3\Flow\Security\Exception\InvalidQueryRewritingConstraintException */ protected function getQomConstraintForSingleConstraintDefinition(array $constraintDefinition, QueryInterface $query) { if (!is_array($constraintDefinition['leftValue']) && strpos($constraintDefinition['leftValue'], 'this.') === 0) { $propertyName = substr($constraintDefinition['leftValue'], 5); $operand = $this->getValueForOperand($constraintDefinition['rightValue']); } elseif (!is_array($constraintDefinition['rightValue']) && strpos($constraintDefinition['rightValue'], 'this.') === 0) { $propertyName = substr($constraintDefinition['rightValue'], 5); $operand = $this->getValueForOperand($constraintDefinition['leftValue']); } else { throw new InvalidQueryRewritingConstraintException('An entity constraint has to have one operand that references to "this.". Got: "' . $constraintDefinition['leftValue'] . '" and "' . $constraintDefinition['rightValue'] . '"', 1267881842); } switch ($constraintDefinition['operator']) { case '==': return $query->equals($propertyName, $operand); break; case '!=': return $query->logicalNot($query->equals($propertyName, $operand)); break; case '<': return $query->lessThan($propertyName, $operand); break; case '>': return $query->greaterThan($propertyName, $operand); break; case '<=': return $query->lessThanOrEqual($propertyName, $operand); break; case '>=': return $query->greaterThanOrEqual($propertyName, $operand); break; case 'in': return $query->in($propertyName, $operand); break; case 'contains': return $query->contains($propertyName, $operand); break; case 'matches': $compositeConstraint = NULL; foreach ($operand as $operandEntry) { $currentConstraint = $query->contains($propertyName, $operandEntry); if ($compositeConstraint === NULL) { $compositeConstraint = $currentConstraint; continue; } $compositeConstraint = $query->logicalAnd($currentConstraint, $compositeConstraint); } return $compositeConstraint; break; } throw new InvalidQueryRewritingConstraintException('The configured operator of the entity constraint is not valid. Got: ' . $constraintDefinition['operator'], 1270483540); }