Custom find all, sort by createAt desc.

@param array $filtersKeys List medias in this filters
772756
public function findAllByFiltersKeys(array $filtersKeys)
    {
        $qb = $this->entityManager->getRepository($this->class)->createQueryBuilder('m');

        $filters = array();
        $addNull = false;
        $inversedfilters = array();
        foreach ($filtersKeys as $filter) {
            if ($this->filter->has($filter)) {
                $value = $this->filter->get($filter);
                $inversedfilters[$value] = $filter;

                if ($value === null) {
                    $addNull = true;
                } else {
                    $filters[] = $value;
                }
            }
        }

        if ($addNull === false && empty($filters)) {
            return array();
        }

        if (!empty($filters)) {
            $qb
                ->select('m')
                ->where($qb->expr()->in('m.filter', $filters))
                ;
        }

        if ($addNull === true) {
            $qb->orWhere('m.filter IS NULL');
        }

        $medias = $qb->orderBy('m.createdAt', 'DESC')
            ->getQuery()
            ->getResult()
            ;

        foreach ($medias as $media) {
            $media->setCryptedFilter($inversedfilters[$media->getFilter()]);
        }

        return $medias;
    }
535189
private function sortEntities(array $entities, array $keys)
    {
        $map = [];
        foreach ($entities as $entity) {
            $map[(string) $entity->key()] = $entity;
        }

        $ret = [];
        foreach ($keys as $key) {
            if (isset($map[(string) $key])) {
                $ret[] = $map[(string) $key];
            }
        }

        return $ret;
    }
213734
public function whereSearch($filters)
    {
        $data = $this->request->get();

        foreach ($filters as $k => $v) {
            preg_match('#^(\w+)(.*)$#', is_string($k) ? $k : $v, $match);
            $field = $match[1];

            if (is_int($k)) {
                if (!isset($data[$field])) {
                    continue;
                }
                $value = $data[$field];
                if (is_string($value)) {
                    $value = trim($value);
                    if ($value === '') {
                        continue;
                    }
                }
                $this->where($v, $value);
            } else {
                $this->where($k, $v);
            }
        }

        return $this;
    }
500263
public function withFilters(array $filters = null)
    {
        if ($filters) {
            foreach ($filters as $filter) {
                switch ($filter['type']) {
                    case 'select':
                        $this->select($filter['fields']);
                        break;
                    case 'andWhere':
                        $this->andWhere($filter['field'], $filter['operation'], $filter['value']);
                        break;
                    case 'orWhere':
                        $this->orWhere($filter['field'], $filter['operation'], $filter['value']);
                        break;
                    case 'andHaving':
                        $this->andHaving($filter['field'], $filter['operation'], $filter['value']);
                        break;
                    case 'orHaving':
                        $this->orHaving($filter['field'], $filter['operation'], $filter['value']);
                        break;
                    case 'addGroupBy':
                        $this->addGroupBy($filter['field']);
                        break;
                    case 'addOrderBy':
                        $this->addOrderBy($filter['field'], $filter['order']);
                        break;
                    case 'fkAddOrderBy':
                        $this->fkAddOrderBy($filter['field'], $filter['fkField'], $filter['order']);
                        break;
                    case 'paginate':
                        if (isset($filter['page'])) {
                            $this->paginate($filter['limit'], $filter['page']);
                        } else {
                            $this->paginate($filter['limit']);
                        }
                        break;
                }
            }
        }

        return $this;
    }
85498
public function filterByKeys(array $keys)
    {
        /** @noinspection PhpMethodParametersCountMismatchInspection */
        $newInstance = new self();
        $newInstance->setArray(array_filter($this->array, function ($key) use ($keys) {
            return array_search($key, $keys) !== false;
        }, ARRAY_FILTER_USE_KEY));
        return $newInstance;
    }
1021721
private function getQueryFilter($filters)
    {
        $where = '';
        if (!empty($filters))
        {
            foreach ($filters as $filterKey => $filterValue)
            {
                $where .= ' AND m.' . $filterKey . ' LIKE :' . $filterKey;
            }
            $where = ' WHERE ' . substr($where, 4);
        }
        return $where;
    }
623779
public static function addFilter(array $filters, array $filterArray, string $key, string $name): array
    {
        if (isset($filterArray[$name][$key])) {
            unset($filterArray[$name][$key]);
        }
        if (sizeof($filterArray[$name]) > 0) {
            $filters['filter']['bool']['must'][] = $filterArray;
        }

        return $filters;
    }
1010060
private function all_filters( $values ) {

		foreach ( $values as $key => $value ) {
			foreach ( $this->filters as $filter ) {
				$values[ $key ] = $filter->filter( $value );
			}
		}

		return $values;
	}
695795
protected function searchFiles(array $directories, $filter = null)
    {
        $finder = new Finder();
        $finder->files()
            ->name('*.php')
            ->in($directories)
            ->depth($this->depth);

        if (isset($filter) && is_callable($filter)) {
            $finder->filter($filter);
        }

        return $finder;
    }
1273690
private function iteratorFromKeys(array $keys)
    {
        $values = [];
        $key    = ($this->request->qtype === 'eq')
            ? $this->request->key
            : null;

        foreach ($keys as $value) {
            $entry = new IndexEntry();

            $entry->indexKey  = $key;
            $entry->objectKey = $value;

            $values[] = $entry;
        }

        return new ArrayIterator($values);
    }
1062082
public static function maps(array $mappings, $key = 'default')
	{
		self::$mappings = array_merge_recursive(self::$mappings, [ $key => $mappings ]);
	}
1340129
public function setQueryKeys(array $keys)
    {
        $this->queryKeys = [];

        foreach ($keys as $key) {
            if (is_string($key)) {
                $this->addQueryKey($key);
            }
        }

        return $this;
    }
1274751
public function deselect($keyOrKeys)
    {
        if ($keyOrKeys instanceof Plugin) {
            $keys = [$keyOrKeys->getKey()];
        } elseif (is_array($keyOrKeys)) {
            $keys = [];
            foreach ($keyOrKeys as $kok) {
                $keys[] = $kok instanceof Plugin ? $kok->getKey() : $kok;
            }
        } else {
            $keys = [$keyOrKeys];
        }
        $this->selectedPlugins = array_diff($this->selectedPlugins, $keys);
    }
260909
private function prepareFilterParams($filtersOrConfigurationKey, array $extraFilters = [])
    {
        if (is_array($filtersOrConfigurationKey)) {
            return array_merge($filtersOrConfigurationKey, $extraFilters);
        }

        if (false !== strpos($filtersOrConfigurationKey, '.')) {
            list($configurationKey, $attribute) = explode('.', $filtersOrConfigurationKey);
        } else {
            $configurationKey = $filtersOrConfigurationKey;
            $attribute = null;
        }

        if (!isset($this->filtersConfigurations[$configurationKey])) {
            throw new ConfigurationException(sprintf('Unable to find filter configuration "%s"', $configurationKey));
        }

        if (null !== $attribute) {
            if (!isset($this->filtersConfigurations[$configurationKey][$attribute])) {
                throw new ConfigurationException(sprintf('Unable to find attribute "%s" in filter configuration "%s"', $attribute, $configurationKey));
            }

            return is_array($this->filtersConfigurations[$configurationKey][$attribute])
                ? array_merge($this->filtersConfigurations[$configurationKey][$attribute], $extraFilters)
                : $this->filtersConfigurations[$configurationKey][$attribute]
                ;
        }

        return is_array($this->filtersConfigurations[$configurationKey])
            ? array_merge($this->filtersConfigurations[$configurationKey], $extraFilters)
            : $this->filtersConfigurations[$configurationKey]
            ;
    }
236364
static function filterIn($arr,$keys)
    {
        $keys = explode(",", $keys);
        $result = array();
        foreach ($arr as $key=>$value) {
            if (in_array($key, $keys)) {
                $result[$key] = $value;
            }
        }
        return $result;
    }
519096
public function removeFilters(array $filterNames)
    {
        $filters = $this->getFilters();
        foreach ($filterNames as $filterName) {
            if (array_key_exists($filterName, $filters)) {
                unset($filters[$filterName]);
                $this->filters = $filters;
            }
        }

        return $this;
    }
576950
public function filterByPrimaryKeys($keys)
    {
        if (empty($keys)) {
            return $this->add(null, '1<>1', Criteria::CUSTOM);
        }
        foreach ($keys as $key) {
            $cton0 = $this->getNewCriterion(SkillGroupTableMap::COL_SKILL_ID, $key[0], Criteria::EQUAL);
            $cton1 = $this->getNewCriterion(SkillGroupTableMap::COL_GROUP_ID, $key[1], Criteria::EQUAL);
            $cton0->addAnd($cton1);
            $this->addOr($cton0);
        }

        return $this;
    }