src/Zicht/Bundle/FrameworkExtraBundle/Twig/Extension.php
public function where($items, array $keyValuePairs, $comparator = 'eq', $booleanOperator = 'and')
    {
        if (is_array($items)) {
            $items = new ArrayCollection($items);
        }
        if ($items instanceof PersistentCollection && !$items->isInitialized()) {
            $items->initialize();
        }

        $whereMethod = $booleanOperator . 'Where';

        $eb = new ExpressionBuilder();
        $criteria = new Criteria();
        foreach ($keyValuePairs as $key => $value) {
            if (is_array($value)) {
                if ($comparator === 'eq') {
                    $criteria->$whereMethod($eb->in($key, $value));
                    continue;
                } elseif ($comparator === 'neq') {
                    $criteria->$whereMethod($eb->notIn($key, $value));
                    continue;
                }
            }
            $criteria->$whereMethod($eb->$comparator($key, $value));
        }

        return $items->matching($criteria);
    }
public function where($items, array $keyValuePairs, $comparator = 'eq', $booleanOperator = 'and')
    {
        if (is_array($items)) {
            $items = new ArrayCollection($items);
        }
        if ($items instanceof PersistentCollection && !$items->isInitialized()) {
            $items->initialize();
        }

        $whereMethod = $booleanOperator . 'Where';

        $eb = new ExpressionBuilder();
        $criteria = new Criteria();
        foreach ($keyValuePairs as $key => $value) {
            if (is_array($value)) {
                if ($comparator === 'eq') {
                    $criteria->$whereMethod($eb->in($key, $value));
                    continue;
                } elseif ($comparator === 'neq') {
                    $criteria->$whereMethod($eb->notIn($key, $value));
                    continue;
                }
            }
            $criteria->$whereMethod($eb->$comparator($key, $value));
        }

        return $items->matching($criteria);
    }
public function where ( $ items , array $ keyValuePairs , $ comparator = 'eq' , $ booleanOperator = 'and' ) { if ( is_array ( $ items ) ) { $ items = new ArrayCollection ( $ items ) ; } if ( $ items instanceof PersistentCollection && ! $ items -> isInitialized ( ) ) { $ items -> initialize ( ) ; } $ whereMethod = $ booleanOperator . 'Where' ; $ eb = new ExpressionBuilder ( ) ; $ criteria = new Criteria ( ) ; foreach ( $ keyValuePairs as $ key => $ value ) { if ( is_array ( $ value ) ) { if ( $ comparator === 'eq' ) { $ criteria -> $ whereMethod ( $ eb -> in ( $ key , $ value ) ) ; continue ; } elseif ( $ comparator === 'neq' ) { $ criteria -> $ whereMethod ( $ eb -> notIn ( $ key , $ value ) ) ; continue ; } } $ criteria -> $ whereMethod ( $ eb -> $ comparator ( $ key , $ value ) ) ; } return $ items -> matching ( $ criteria ) ; }
Filter a collection based on properties of the collection's items

@param array|Collection $items
@param array $keyValuePairs
@param string $comparator
@param string $booleanOperator
@return \Doctrine\Common\Collections\Collection
Filter a collection based on properties of the collection s items