[TYPO3-mvc] Persistence_rewrite merged!

Jochen Rau jochen.rau at typoplanet.de
Mon Jul 13 12:13:03 CEST 2009


Hi Frans.

I am crawling through the different topics now ;-).

> While playing around with the code I was wondering how to implement the
> following in a repository:
> - findByFirstLetter. This finds records by the first letter of the name
> of the record.
>
> For creating this functionality I had to create my own derived query
> class (Tx_MyExtension_Persistence_Query), and a derived query factory
> (Tx_MyExtension_Persistence_QueryFactory). The query class contains a
> new method:
> 	public function firstLetterEquals($propertyName, $operand,
> $caseSensitive = TRUE) {
> 		$propertyName = 'SUBSTRING('.$propertyName.',1,1)';
> 		$comparison = $this->QOMFactory->comparison(
> 			$this->QOMFactory->propertyValue($propertyName),
> Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_OPERATOR_EQUAL_TO,
> 			$this->QOMFactory->bindVariable($propertyName)
> 		);
> 	}
> Is this the best way to do this?

The following should work (although you loose the abstraction from the 
storage backend, as the parsing should be done only inside this backend):

public function firstLetterEquals($propertyName, $operand, 
$caseSensitive = TRUE) {
	$propertyName = 'SUBSTRING(' . $propertyName . ',1,1)';
	$comparison = $this->QOMFactory->comparison(
		$this->QOMFactory->propertyValue($propertyName),
	 
Tx_Extbase_Persistence_QOM_QueryObjectModelConstantsInterface::JCR_OPERATOR_EQUAL_TO,
		$this->QOMFactory->bindVariable($propertyName)
	);
	if ($caseSensitive) {
		$this->operands[$propertyName] = $operand;
	} else {
		$this->operands[$propertyName] = strtolower($operand);
	}
	return $comparison;
}

Regards
Jochen


-- 
Every nit picked is a bug fixed



More information about the TYPO3-project-typo3v4mvc mailing list