resource: @WallabagCoreBundle/Controller/
type: annotation
-homepage:
- pattern: /
- defaults: { _controller: WallabagCoreBundle:Entry:showUnread }
-
doc-api:
resource: "@NelmioApiDocBundle/Resources/config/routing.yml"
prefix: /api/doc
login:
pattern: /login
defaults: { _controller: WallabagCoreBundle:Security:login }
+
login_check:
pattern: /login_check
+
logout:
path: /logout
type : rest
resource : "routing_rest.yml"
prefix : /api
+
+homepage:
+ pattern: "/{page}"
+ defaults: { _controller: WallabagCoreBundle:Entry:showUnread, page : 1 }
+ requirements:
+ page: \d+
$this->validateUserAccess($entry->getUser()->getId(), $this->getUser()->getId());
$title = $request->request->get('title');
- $isArchived = $request->request->get('archive');
- $isStarred = $request->request->get('star');
+ $isArchived = $request->request->get('is_archived');
+ $isStarred = $request->request->get('is_starred');
if (!is_null($title)) {
$entry->setTitle($title);
/**
* Shows unread entries for current user.
*
- * @Route("/unread", name="unread")
+ * @Route("/unread/list/{page}", name="unread", defaults={"page" = "1"})
*
* @return \Symfony\Component\HttpFoundation\Response
*/
- public function showUnreadAction()
+ public function showUnreadAction($page)
{
- // TODO change pagination
$entries = $this->getDoctrine()
->getRepository('WallabagCoreBundle:Entry')
- ->findUnreadByUser($this->getUser()->getId(), 0);
+ ->findUnreadByUser($this->getUser()->getId());
+
+ $entries->setCurrentPage($page);
return $this->render(
'WallabagCoreBundle:Entry:entries.html.twig',
- array('entries' => $entries)
+ array(
+ 'entries' => $entries,
+ 'currentPage' => $page
+ )
);
}
/**
* Shows read entries for current user.
*
- * @Route("/archive", name="archive")
+ * @Route("/archive/list/{page}", name="archive", defaults={"page" = "1"})
*
* @return \Symfony\Component\HttpFoundation\Response
*/
- public function showArchiveAction()
+ public function showArchiveAction($page)
{
- // TODO change pagination
$entries = $this->getDoctrine()
->getRepository('WallabagCoreBundle:Entry')
- ->findArchiveByUser($this->getUser()->getId(), 0);
+ ->findArchiveByUser($this->getUser()->getId());
+
+ $entries->setCurrentPage($page);
return $this->render(
'WallabagCoreBundle:Entry:entries.html.twig',
- array('entries' => $entries)
+ array(
+ 'entries' => $entries,
+ 'currentPage' => $page
+ )
);
}
/**
* Shows starred entries for current user.
*
- * @Route("/starred", name="starred")
+ * @Route("/starred/list/{page}", name="starred", defaults={"page" = "1"})
*
* @return \Symfony\Component\HttpFoundation\Response
*/
- public function showStarredAction()
+ public function showStarredAction($page)
{
- // TODO change pagination
$entries = $this->getDoctrine()
->getRepository('WallabagCoreBundle:Entry')
- ->findStarredByUser($this->getUser()->getId(), 0);
+ ->findStarredByUser($this->getUser()->getId());
+
+ $entries->setCurrentPage($page);
return $this->render(
'WallabagCoreBundle:Entry:entries.html.twig',
- array('entries' => $entries)
+ array(
+ 'entries' => $entries,
+ 'currentPage' => $page
+ )
);
}
$entries = $this->getDoctrine()
->getRepository('WallabagCoreBundle:Entry')
->findUnreadByUser(
- $user->getId(),
- 0,
- $user->getConfig()->getRssLimit() ?: $this->container->getParameter('rss_limit')
+ $user->getId()
);
+ $perPage = $user->getConfig()->getRssLimit() ?: $this->container->getParameter('rss_limit');
+ $entries->setMaxPerPage($perPage);
+
return $this->render('WallabagCoreBundle:Entry:entries.xml.twig', array(
'type' => 'unread',
'entries' => $entries,
$entries = $this->getDoctrine()
->getRepository('WallabagCoreBundle:Entry')
->findArchiveByUser(
- $user->getId(),
- 0,
- $user->getConfig()->getRssLimit() ?: $this->container->getParameter('rss_limit')
+ $user->getId()
);
+ $perPage = $user->getConfig()->getRssLimit() ?: $this->container->getParameter('rss_limit');
+ $entries->setMaxPerPage($perPage);
+
return $this->render('WallabagCoreBundle:Entry:entries.xml.twig', array(
'type' => 'archive',
'entries' => $entries,
$entries = $this->getDoctrine()
->getRepository('WallabagCoreBundle:Entry')
->findStarredByUser(
- $user->getId(),
- 0,
- $user->getConfig()->getRssLimit() ?: $this->container->getParameter('rss_limit')
+ $user->getId()
);
+ $perPage = $user->getConfig()->getRssLimit() ?: $this->container->getParameter('rss_limit');
+ $entries->setMaxPerPage($perPage);
+
return $this->render('WallabagCoreBundle:Entry:entries.xml.twig', array(
'type' => 'starred',
'entries' => $entries,
namespace Wallabag\CoreBundle\Repository;
use Doctrine\ORM\EntityRepository;
-use Doctrine\ORM\Tools\Pagination\Paginator;
use Pagerfanta\Adapter\DoctrineORMAdapter;
use Pagerfanta\Pagerfanta;
* Retrieves unread entries for a user.
*
* @param int $userId
- * @param int $firstResult
- * @param int $maxResults
*
- * @return Paginator
+ * @return Pagerfanta
*/
- public function findUnreadByUser($userId, $firstResult, $maxResults = 12)
+ public function findUnreadByUser($userId)
{
$qb = $this->createQueryBuilder('e')
- ->setFirstResult($firstResult)
- ->setMaxResults($maxResults)
->leftJoin('e.user', 'u')
->where('e.isArchived = false')
->andWhere('u.id =:userId')->setParameter('userId', $userId)
->orderBy('e.id', 'desc')
->getQuery();
- $paginator = new Paginator($qb);
+ $pagerAdapter = new DoctrineORMAdapter($qb);
- return $paginator;
+ return new Pagerfanta($pagerAdapter);
}
/**
* Retrieves read entries for a user.
*
* @param int $userId
- * @param int $firstResult
- * @param int $maxResults
*
- * @return Paginator
+ * @return Pagerfanta
*/
- public function findArchiveByUser($userId, $firstResult, $maxResults = 12)
+ public function findArchiveByUser($userId)
{
$qb = $this->createQueryBuilder('e')
->select('e')
- ->setFirstResult($firstResult)
- ->setMaxResults($maxResults)
->leftJoin('e.user', 'u')
->where('e.isArchived = true')
->andWhere('u.id =:userId')->setParameter('userId', $userId)
->orderBy('e.id', 'desc')
->getQuery();
- $paginator = new Paginator($qb);
+ $pagerAdapter = new DoctrineORMAdapter($qb);
- return $paginator;
+ return new Pagerfanta($pagerAdapter);
}
/**
* Retrieves starred entries for a user.
*
* @param int $userId
- * @param int $firstResult
- * @param int $maxResults
*
- * @return Paginator
+ * @return Pagerfanta
*/
- public function findStarredByUser($userId, $firstResult, $maxResults = 12)
+ public function findStarredByUser($userId)
{
+
$qb = $this->createQueryBuilder('e')
->select('e')
- ->setFirstResult($firstResult)
- ->setMaxResults($maxResults)
->leftJoin('e.user', 'u')
->where('e.isStarred = true')
->andWhere('u.id =:userId')->setParameter('userId', $userId)
->orderBy('e.id', 'desc')
->getQuery();
- $paginator = new Paginator($qb);
+ $pagerAdapter = new DoctrineORMAdapter($qb);
- return $paginator;
+ return new Pagerfanta($pagerAdapter);
}
/**
<div class="results">
<div class="nb-results">{{ entries.count }} {% trans %}entries{% endtrans %}</div>
<div class="pagination">
- {% for p in range(1, entries.count) %}
+ {% for p in range(1, entries.nbPages) %}
<li>
- <a href="{{ path(app.request.attributes.get('_route'), {'page': p}) }}">{{ p }}</a>
+ <a href="{{ path(app.request.attributes.get('_route'), {'page': p}) }}" class="{{ currentPage == p ? 'current':''}}" >{{ p }}</a>
</li>
{% endfor %}
</div>
display: none;
}
+.pagination .current {
+ height: 25px;
+ padding: 4px 8px;
+ border: 1px solid #d5d5d5;
+ text-decoration: none;
+ font-weight: bold;
+ color: #000;
+ background-color: #ccc;
+}
+
/* ==========================================================================
2.1 = "save a link" related styles
========================================================================== */
$this->logInAs('admin');
$client = $this->getClient();
- $client->request('GET', '/archive');
+ $client->request('GET', '/archive/list');
$this->assertEquals(200, $client->getResponse()->getStatusCode());
}
$this->logInAs('admin');
$client = $this->getClient();
- $client->request('GET', '/starred');
+ $client->request('GET', '/starred/list');
$this->assertEquals(200, $client->getResponse()->getStatusCode());
}