protected function doMoveDownAction(AbstractAdminListConfigurator $configurator, $entityId, Request $request)
 {
     $em = $this->getEntityManager();
     $sortableField = $configurator->getSortableField();
     $repo = $em->getRepository($configurator->getRepositoryName());
     $item = $repo->find($entityId);
     $setter = "set" . ucfirst($sortableField);
     $getter = "get" . ucfirst($sortableField);
     $nextItem = $repo->createQueryBuilder('i')->where('i.' . $sortableField . ' > :weight')->setParameter('weight', $item->{$getter}())->orderBy('i.' . $sortableField, 'ASC')->setMaxResults(1)->getQuery()->getOneOrNullResult();
     if ($nextItem) {
         $nextItem->{$setter}($item->{$getter}());
         $em->persist($nextItem);
     }
     $item->{$setter}($item->{$getter}() + 1);
     $em->persist($item);
     $em->flush();
     $indexUrl = $configurator->getIndexUrl();
     return new RedirectResponse($this->generateUrl($indexUrl['path'], isset($indexUrl['params']) ? $indexUrl['params'] : array()));
 }
 /**
  * Delete the Entity using its ID
  *
  * @param AbstractAdminListConfigurator $configurator The adminlist configurator
  * @param integer                       $entityId     The id to delete
  * @param null|Request                  $request
  *
  * @throws NotFoundHttpException
  * @throws AccessDeniedHttpException
  *
  * @return Response
  */
 protected function doDeleteAction(AbstractAdminListConfigurator $configurator, $entityId, Request $request = null)
 {
     /* @var $em EntityManager */
     $em = $this->getEntityManager();
     if (is_null($request)) {
         $request = $this->getRequest();
     }
     $helper = $em->getRepository($configurator->getRepositoryName())->findOneById($entityId);
     if ($helper === null) {
         throw new NotFoundHttpException("Entity not found.");
     }
     if (!$configurator->canDelete($helper)) {
         throw new AccessDeniedHttpException('You do not have sufficient rights to access this page.');
     }
     $indexUrl = $configurator->getIndexUrl();
     if ($request->isMethod('POST')) {
         $em->remove($helper);
         $em->flush();
     }
     return new RedirectResponse($this->generateUrl($indexUrl['path'], isset($indexUrl['params']) ? $indexUrl['params'] : array()));
 }