1
0
Fork 0
mirror of https://github.com/wallabag/wallabag.git synced 2025-07-22 17:18:37 +00:00

Added random feature

This commit is contained in:
Nicolas Lœuillet 2017-12-22 15:44:00 +01:00 committed by Jeremy Benoist
parent c73025ad8b
commit 09ef25c3c3
No known key found for this signature in database
GPG key ID: BCA73962457ACC3C
18 changed files with 169 additions and 10 deletions

View file

@ -2,6 +2,7 @@
namespace Wallabag\CoreBundle\Controller;
use Doctrine\ORM\NoResultException;
use Pagerfanta\Adapter\DoctrineORMAdapter;
use Pagerfanta\Exception\OutOfRangeCurrentPageException;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
@ -232,6 +233,110 @@ class EntryController extends Controller
return $this->showEntries('starred', $request, $page);
}
/**
* Shows random unread entry.
*
* @param Entry $entry
*
* @Route("/unread/random", name="unread_random")
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function showRandomUnreadEntryAction()
{
$repository = $this->get('wallabag_core.entry_repository');
try {
$entry = $repository->getRandomEntry($this->getUser()->getId(), 'unread');
} catch (NoResultException $e) {
$bag = $this->get('session')->getFlashBag();
$bag->clear();
$bag->add('notice', 'flashes.entry.notice.no_random_entry');
return $this->redirect($this->generateUrl('homepage'));
}
return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()]));
}
/**
* Shows random favorite entry.
*
* @param Entry $entry
*
* @Route("/starred/random", name="starred_random")
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function showRandomStarredEntryAction()
{
$repository = $this->get('wallabag_core.entry_repository');
try {
$entry = $repository->getRandomEntry($this->getUser()->getId(), 'starred');
} catch (NoResultException $e) {
$bag = $this->get('session')->getFlashBag();
$bag->clear();
$bag->add('notice', 'flashes.entry.notice.no_random_entry');
return $this->redirect($this->generateUrl('homepage'));
}
return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()]));
}
/**
* Shows random archived entry.
*
* @param Entry $entry
*
* @Route("/archive/random", name="archive_random")
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function showRandomArchiveEntryAction()
{
$repository = $this->get('wallabag_core.entry_repository');
try {
$entry = $repository->getRandomEntry($this->getUser()->getId(), 'starred');
} catch (NoResultException $e) {
$bag = $this->get('session')->getFlashBag();
$bag->clear();
$bag->add('notice', 'flashes.entry.notice.no_random_entry');
return $this->redirect($this->generateUrl('homepage'));
}
return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()]));
}
/**
* Shows random all entry.
*
* @param Entry $entry
*
* @Route("/all/random", name="all_random")
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function showRandomAllEntryAction()
{
$repository = $this->get('wallabag_core.entry_repository');
try {
$entry = $repository->getRandomEntry($this->getUser()->getId());
} catch (NoResultException $e) {
$bag = $this->get('session')->getFlashBag();
$bag->clear();
$bag->add('notice', 'flashes.entry.notice.no_random_entry');
return $this->redirect($this->generateUrl('homepage'));
}
return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()]));
}
/**
* Shows entry content.
*