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

Jochen Rau jochen.rau at typoplanet.de
Wed Feb 3 16:56:50 CET 2010


Hi Steffen

On 03.02.10 14:48, Steffen Ritter wrote:
> 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.

What's wrong with the way Extbase handles comma separated lists? If you 
have a *_TO_MANY relation and you don't specify a foreign_field in $TCA 
it assumes that you want to use a csl.

> 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'));


Did try

$query->matching($query->equals('categories', $categories));

with an array of Category objects in $categories?

Regards
Jochen


More information about the TYPO3-project-typo3v4mvc mailing list