[TYPO3-mvc] Sharing matching function for comma-separated uid-list constraints

Steffen Ritter info at rs-websystems.de
Wed Feb 3 14:48:52 CET 2010


Hey folks,
in T3v4 you often will have to deal with uid-lists in commaseparated way.

I wrote a little function you may use to automatically get a constraint 
for this to use in query->matching.

I would like to here your opininions about providing this one as patch 
for the query object...

As long as it is not included: have fun with that function which you 
need to include in your (abstract)repository:

protected function constraintUidList($uidList,$query,$field) {
	$uids = explode (',',$uidList);
	$first = array_pop($uids);
	$constraint = $query->equals($field,$first);
	foreach($uids AS $uid) {
		$constraint = $query->logicalOr(
			$constraint,
			$query->equals($field,$uid)
		);		
	}		
	return $constraint;
}


usage is very simple:

$query->matching($this->constraintUidList($categories,$query,'kategorien'));
		

regards

Steffen


More information about the TYPO3-project-typo3v4mvc mailing list