/** * {@inheritdoc} */ public function fetchAll(ConfigInterface $config) { $entityRepository = $this->getEntityRepository(); $entityManager = $this->getEntityManager(); $queryBuilder = $entityManager->createQueryBuilder(); $queryBuilder->select($config->getIdOnly() ? 'e.id' : 'e')->from($entityRepository->getClassName(), 'e'); if ($config->getFilter()) { $queryBuilder->where($this->buildCondition($queryBuilder, array('operation' => 'AND', 'children' => $config->getFilter()))); } if ($config->getSorting()) { $hiddenIndex = 0; foreach ($config->getSorting() as $sort => $order) { $orderUppercase = strtoupper($order); if ($order && $orderUppercase != 'ASC' && $orderUppercase != 'DESC') { $queryBuilder->addSelect($order . ' AS HIDDEN _virtual_sorting_field_' . $hiddenIndex); $sort = '_virtual_sorting_field_' . $hiddenIndex; $order = null; $hiddenIndex++; } else { $sort = 'e.' . $sort; $order = $orderUppercase; } $queryBuilder->addOrderBy($sort, $order); } } if ($config->getStart()) { $queryBuilder->setFirstResult($config->getStart()); } if ($config->getAmount()) { $queryBuilder->setMaxResults($config->getAmount()); } $query = $queryBuilder->getQuery(); if ($config->getIdOnly()) { $entities = $query->getScalarResult(); } else { $entities = $query->getResult(); $entities = $this->mapEntities($entities); } return $entities; }