コード例 #1
0
 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;
 }
コード例 #2
0
 /**
  * @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;
 }
コード例 #3
0
ファイル: Filter.php プロジェクト: nilportugues/repository
 /**
  * @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;
 }
コード例 #4
0
 /**
  * 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);
 }
コード例 #5
0
 /**
  * {@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;
 }