2015-03-28 13:27:45 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Wallabag\CoreBundle\Controller;
|
|
|
|
|
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
2015-10-02 12:51:41 +00:00
|
|
|
use Wallabag\UserBundle\Entity\User;
|
2015-03-28 13:27:45 +00:00
|
|
|
use Wallabag\CoreBundle\Entity\Entry;
|
2015-08-07 20:20:30 +00:00
|
|
|
use Pagerfanta\Adapter\DoctrineORMAdapter;
|
|
|
|
use Pagerfanta\Pagerfanta;
|
2015-03-28 13:27:45 +00:00
|
|
|
|
|
|
|
class RssController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
2015-05-30 11:52:26 +00:00
|
|
|
* Shows unread entries for current user.
|
2015-03-28 13:27:45 +00:00
|
|
|
*
|
|
|
|
* @Route("/{username}/{token}/unread.xml", name="unread_rss", defaults={"_format"="xml"})
|
2015-10-02 12:51:41 +00:00
|
|
|
* @ParamConverter("user", class="WallabagUserBundle:User", converter="username_rsstoken_converter")
|
2015-03-28 13:27:45 +00:00
|
|
|
*
|
|
|
|
* @return \Symfony\Component\HttpFoundation\Response
|
|
|
|
*/
|
|
|
|
public function showUnreadAction(User $user)
|
|
|
|
{
|
2015-08-20 18:10:06 +00:00
|
|
|
return $this->showEntries('unread', $user);
|
2015-03-28 13:27:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-05-30 11:52:26 +00:00
|
|
|
* Shows read entries for current user.
|
2015-03-28 13:27:45 +00:00
|
|
|
*
|
|
|
|
* @Route("/{username}/{token}/archive.xml", name="archive_rss")
|
2015-10-02 12:51:41 +00:00
|
|
|
* @ParamConverter("user", class="WallabagUserBundle:User", converter="username_rsstoken_converter")
|
2015-03-28 13:27:45 +00:00
|
|
|
*
|
|
|
|
* @return \Symfony\Component\HttpFoundation\Response
|
|
|
|
*/
|
|
|
|
public function showArchiveAction(User $user)
|
|
|
|
{
|
2015-08-20 18:10:06 +00:00
|
|
|
return $this->showEntries('archive', $user);
|
2015-03-28 13:27:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-05-30 11:52:26 +00:00
|
|
|
* Shows starred entries for current user.
|
2015-03-28 13:27:45 +00:00
|
|
|
*
|
|
|
|
* @Route("/{username}/{token}/starred.xml", name="starred_rss")
|
2015-10-02 12:51:41 +00:00
|
|
|
* @ParamConverter("user", class="WallabagUserBundle:User", converter="username_rsstoken_converter")
|
2015-03-28 13:27:45 +00:00
|
|
|
*
|
|
|
|
* @return \Symfony\Component\HttpFoundation\Response
|
|
|
|
*/
|
|
|
|
public function showStarredAction(User $user)
|
|
|
|
{
|
2015-08-20 18:10:06 +00:00
|
|
|
return $this->showEntries('starred', $user);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Global method to retrieve entries depending on the given type
|
|
|
|
* It returns the response to be send.
|
|
|
|
*
|
|
|
|
* @param string $type Entries type: unread, starred or archive
|
|
|
|
* @param User $user
|
|
|
|
*
|
|
|
|
* @return \Symfony\Component\HttpFoundation\Response
|
|
|
|
*/
|
|
|
|
private function showEntries($type, User $user)
|
|
|
|
{
|
|
|
|
$repository = $this->getDoctrine()->getRepository('WallabagCoreBundle:Entry');
|
|
|
|
|
|
|
|
switch ($type) {
|
|
|
|
case 'starred':
|
|
|
|
$qb = $repository->getBuilderForStarredByUser($user->getId());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'archive':
|
|
|
|
$qb = $repository->getBuilderForArchiveByUser($user->getId());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'unread':
|
|
|
|
$qb = $repository->getBuilderForUnreadByUser($user->getId());
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
throw new \InvalidArgumentException(sprintf('Type "%s" is not implemented.', $type));
|
|
|
|
}
|
2015-03-28 13:27:45 +00:00
|
|
|
|
2015-08-07 20:20:30 +00:00
|
|
|
$pagerAdapter = new DoctrineORMAdapter($qb->getQuery());
|
|
|
|
$entries = new Pagerfanta($pagerAdapter);
|
|
|
|
|
2015-07-27 21:20:32 +00:00
|
|
|
$perPage = $user->getConfig()->getRssLimit() ?: $this->container->getParameter('rss_limit');
|
|
|
|
$entries->setMaxPerPage($perPage);
|
|
|
|
|
2015-03-28 13:27:45 +00:00
|
|
|
return $this->render('WallabagCoreBundle:Entry:entries.xml.twig', array(
|
2015-08-20 18:10:06 +00:00
|
|
|
'type' => $type,
|
2015-03-28 13:27:45 +00:00
|
|
|
'entries' => $entries,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|