public static function filter(Builder $query, FilterInterface $filter) { foreach ($filter->filters() as $condition => $filters) { $filters = self::removeEmptyFilters($filters); if (count($filters) > 0) { self::processConditions($query, $condition, $filters); } } return $query; }
/** * @param QueryBuilder $query * @param FilterInterface $filter * @param Mapping $mapping * * @return QueryBuilder */ public static function filter(QueryBuilder $query, FilterInterface $filter, Mapping $mapping) { $placeholders = []; $columns = $mapping->map(); foreach ($filter->filters() as $condition => $filters) { $filters = self::removeEmptyFilters($filters); if (count($filters) > 0) { self::processConditions($columns, $placeholders, $query, $condition, $filters); } } $query->setParameters($placeholders); return $query; }
/** * @param array $results * @param FilterInterface $filter * * @return array */ public static function filter(array $results, FilterInterface $filter) : array { $filteredResults = $results; foreach ($filter->filters() as $condition => $filters) { $filters = self::removeEmptyFilters($filters); if (count($filters) > 0) { switch ($condition) { case self::MUST: self::must($filteredResults, $filters); break; case self::MUST_NOT: self::mustNot($filteredResults, $filters); break; case self::SHOULD: self::should($results, $filteredResults, $filters); $filteredResults = array_unique($filteredResults); break; } } } return $filteredResults; }
/** * Returns all instances of the type. * * @param FilterInterface|null $filter * @param Sort|null $sort * @param Fields|null $fields * * @return array */ public function findBy(FilterInterface $filter = null, Sort $sort = null, Fields $fields = null) : array { $results = $this->data; if (null !== $filter && !$filter->isNull()) { $results = InMemoryFilter::filter($results, $filter); } if (null !== $sort && !$filter->isNull()) { $results = Sorter::sort($results, $sort); } return array_values($results); }
/** * {@inheritdoc} */ public function findByDistinct(Fields $distinctFields, Filter $filter = null, Sort $sort = null) : array { $hashFilter = $filter ? serialize($filter->filters()) : ''; $hashSort = $sort ? serialize($sort->orders()) : ''; $hashFields = $distinctFields ? serialize($distinctFields->get()) : ''; $key = $this->cacheNamespaceFindByDistinct . md5($hashFilter . $hashSort . $hashFields); $cachedItem = $this->cache->getItem($key); if ($cachedItem->isHit() && null !== ($result = $cachedItem->get())) { return (array) $result; } $result = $this->repository->findByDistinct($distinctFields, $filter, $sort); $this->saveToCache($cachedItem, $result); return (array) $result; }