filters: adapt queryBuilder for 'all' view

This commit is contained in:
Nicolas Lœuillet 2015-08-21 07:38:18 +02:00
parent e177976099
commit 2b7a488917
2 changed files with 19 additions and 28 deletions

View file

@ -113,34 +113,7 @@ class EntryController extends Controller
*/ */
public function showAllAction(Request $request, $page) public function showAllAction(Request $request, $page)
{ {
$form = $this->get('form.factory')->create(new EntryFilterType()); return $this->showEntries('all', $request, $page);
$filterBuilder = $this->getDoctrine()
->getRepository('WallabagCoreBundle:Entry')
->findAllByUser($this->getUser()->getId());
if ($request->query->has($form->getName())) {
// manually bind values from the request
$form->submit($request->query->get($form->getName()));
// build the query from the given form object
$this->get('lexik_form_filter.query_builder_updater')->addFilterConditions($form, $filterBuilder);
}
$pagerAdapter = new DoctrineORMAdapter($filterBuilder->getQuery());
$entries = new Pagerfanta($pagerAdapter);
$entries->setMaxPerPage($this->getUser()->getConfig()->getItemsPerPage());
$entries->setCurrentPage($page);
return $this->render(
'WallabagCoreBundle:Entry:entries.html.twig',
array(
'form' => $form->createView(),
'entries' => $entries,
'currentPage' => $page,
)
);
} }
/** /**
@ -215,6 +188,10 @@ class EntryController extends Controller
$qb = $repository->getBuilderForUnreadByUser($this->getUser()->getId()); $qb = $repository->getBuilderForUnreadByUser($this->getUser()->getId());
break; break;
case 'all':
$qb = $repository->getBuilderForAllByUser($this->getUser()->getId());
break;
default: default:
throw new \InvalidArgumentException(sprintf('Type "%s" is not implemented.', $type)); throw new \InvalidArgumentException(sprintf('Type "%s" is not implemented.', $type));
} }

View file

@ -24,6 +24,20 @@ class EntryRepository extends EntityRepository
; ;
} }
/**
* Retrieves all entries for a user.
*
* @param int $userId
*
* @return QueryBuilder
*/
public function getBuilderForAllByUser($userId)
{
return $this
->getBuilderByUser($userId)
;
}
/** /**
* Retrieves unread entries for a user. * Retrieves unread entries for a user.
* *