$parentKeyFieldName = $columnMap->getParentKeyFieldName();
if ($columnMap->getTypeOfRelation() === Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_MANY) {
$query = $queryFactory->create($columnMap->getChildClassName());
+ if (!empty($childSortByFieldName)) {
+ $query->setOrderings(array($childSortByFieldName => Tx_Extbase_Persistence_QueryInterface::ORDER_ASCENDING));
+ }
$parentKeyFieldName = $columnMap->getParentKeyFieldName();
if (isset($parentKeyFieldName)) {
- $query->matching($query->equals($parentKeyFieldName, $parentObject->getUid()));
- if (!empty($childSortByFieldName)) {
- $query->setOrderings(array($childSortByFieldName => Tx_Extbase_Persistence_QueryInterface::ORDER_ASCENDING));
- }
- $objects = $query->execute();
+ $objects = $query->matching($query->equals($parentKeyFieldName, $parentObject->getUid()))->execute();
} else {
$uidArray = t3lib_div::intExplode(',', $fieldValue);
- $uids = implode(',', $uidArray);
- // FIXME Using statement() is only a preliminary solution
- $objects = $query->statement('SELECT * FROM ' . $columnMap->getChildTableName() . ' WHERE uid IN (' . $uids . ')')->execute();
+ $objects = $query->matching($query->equals('uid', $uidArray))->execute();
}
} elseif ($columnMap->getTypeOfRelation() === Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY) {
$relationTableName = $columnMap->getRelationTableName();
}
foreach ($this->operands as $name => $value) {
- $query->bindValue($name, $this->valueFactory->createValue($value));
+ if (is_array($value)) {
+ $newValue = array();
+ foreach ($value as $valueItem) {
+ $newValue[] = $this->valueFactory->createValue($valueItem);
+ }
+ $query->bindValue($name, $this->valueFactory->createValue($newValue));
+ } else {
+ $query->bindValue($name, $this->valueFactory->createValue($value));
+ }
}
$query->setQuerySettings($this->getQuerySettings());
return $query;
);
}
- if ($caseSensitive) {
+ // TODO Implement case sensitivity for arrays (callback)
+ if ($caseSensitive || !is_string($operand)) {
$this->operands[$uniqueVariableName] = $operand;
} else {
$this->operands[$uniqueVariableName] = strtolower($operand);
const OPERATOR_EQUAL_TO_NULL = 'operatorEqualToNull';
const OPERATOR_NOT_EQUAL_TO_NULL = 'operatorNotEqualToNull';
+ const OPERATOR_IN = 'operatorIn';
+ const OPERATOR_NOT_IN = 'operatorNotIn';
/**
* The TYPO3 database object
$statement = $this->getStatement($query, $parameters);
}
$this->replacePlaceholders($statement, $parameters);
+ // debug($statement,-2);
$result = $this->databaseHandle->sql_query($statement);
$this->checkSqlErrors();
return $this->getRowsFromResult($query->getSource(), $result);
$operator = self::OPERATOR_EQUAL_TO_NULL;
} elseif ($operator === Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_OPERATOR_NOT_EQUAL_TO) {
$operator = self::OPERATOR_NOT_EQUAL_TO_NULL;
- } else {
- // TODO Throw exception
}
+ } elseif (is_array($value)) {
+ if ($operator === Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_OPERATOR_EQUAL_TO) {
+ $operator = self::OPERATOR_IN;
+ } elseif ($operator === Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_OPERATOR_NOT_EQUAL_TO) {
+ $operator = self::OPERATOR_NOT_IN;
+ }
}
$parameters[] = $value;
case self::OPERATOR_NOT_EQUAL_TO_NULL:
$operator = 'IS NOT';
break;
+ case self::OPERATOR_IN:
+ $operator = 'IN';
+ break;
+ case self::OPERATOR_NOT_IN:
+ $operator = 'NOT IN';
+ break;
case Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_OPERATOR_EQUAL_TO:
$operator = '=';
break;
if ($markPosition !== FALSE) {
if ($parameter === NULL) {
$parameter = 'NULL';
+ } elseif (is_array($parameter)) {
+ $items = array();
+ foreach ($parameter as $item) {
+ $items[] = $this->databaseHandle->fullQuoteStr($item, 'foo');
+ }
+ $parameter = '(' . implode(',', $items) . ')';
} else {
$parameter = $this->databaseHandle->fullQuoteStr($parameter, 'foo'); // FIXME This may not work with DBAL; check this
}
*/
public function getString() {
if ($this->value === NULL) return NULL;
+ if (is_array($this->value)) return $this->value;
+
switch ($this->type) {
case Tx_Extbase_Persistence_PropertyType::DATE:
if (is_a($this->value, 'DateTime')) {
* @throws \IllegalArgumentException if the specified DateTime value cannot be expressed in the ISO 8601-based format defined in the JCR 2.0 specification and the implementation does not support dates incompatible with that format.
*/
public function createValue($value, $type = Tx_Extbase_Persistence_PropertyType::UNDEFINED, $weak = FALSE) {
- if (is_array($value)) {
+ if (is_array($value) && array_key_exists('uid', $value)) {
$value = $value['uid'];
}