- $repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entries');
- // TODO don't give the user ID like this
- // TODO change pagination
- $entries = $repository->findStarredByUser(1, 0);
+ $repository = $this->get('wallabag_core.entry_repository');
+
+ switch ($type) {
+ case 'starred':
+ $qb = $repository->getBuilderForStarredByUser($this->getUser()->getId());
+ break;
+
+ case 'archive':
+ $qb = $repository->getBuilderForArchiveByUser($this->getUser()->getId());
+ break;
+
+ case 'unread':
+ $qb = $repository->getBuilderForUnreadByUser($this->getUser()->getId());
+ break;
+
+ case 'all':
+ $qb = $repository->getBuilderForAllByUser($this->getUser()->getId());
+ break;
+
+ default:
+ throw new \InvalidArgumentException(sprintf('Type "%s" is not implemented.', $type));
+ }
+
+ $form = $this->createForm(EntryFilterType::class);
+
+ 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, $qb);
+ }
+
+ $pagerAdapter = new DoctrineORMAdapter($qb->getQuery());
+ $entries = new Pagerfanta($pagerAdapter);
+
+ $entries->setMaxPerPage($this->getUser()->getConfig()->getItemsPerPage());
+ $entries->setCurrentPage($page);