aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Controller
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2017-12-22 15:44:00 +0100
committerJeremy Benoist <jeremy.benoist@gmail.com>2019-01-19 21:09:32 +0100
commit09ef25c3c3882db94b3941f3ba33ebc78b5dbe4d (patch)
tree380f1b23be485b58c58052b22877054b7481c0b1 /src/Wallabag/CoreBundle/Controller
parentc73025ad8b684de1ac21ba7583f1af6f1d185159 (diff)
downloadwallabag-09ef25c3c3882db94b3941f3ba33ebc78b5dbe4d.tar.gz
wallabag-09ef25c3c3882db94b3941f3ba33ebc78b5dbe4d.tar.zst
wallabag-09ef25c3c3882db94b3941f3ba33ebc78b5dbe4d.zip
Added random feature
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller')
-rw-r--r--src/Wallabag/CoreBundle/Controller/EntryController.php105
1 files changed, 105 insertions, 0 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php
index ac372a33..6c843ba7 100644
--- a/src/Wallabag/CoreBundle/Controller/EntryController.php
+++ b/src/Wallabag/CoreBundle/Controller/EntryController.php
@@ -2,6 +2,7 @@
2 2
3namespace Wallabag\CoreBundle\Controller; 3namespace Wallabag\CoreBundle\Controller;
4 4
5use Doctrine\ORM\NoResultException;
5use Pagerfanta\Adapter\DoctrineORMAdapter; 6use Pagerfanta\Adapter\DoctrineORMAdapter;
6use Pagerfanta\Exception\OutOfRangeCurrentPageException; 7use Pagerfanta\Exception\OutOfRangeCurrentPageException;
7use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache; 8use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
@@ -233,6 +234,110 @@ class EntryController extends Controller
233 } 234 }
234 235
235 /** 236 /**
237 * Shows random unread entry.
238 *
239 * @param Entry $entry
240 *
241 * @Route("/unread/random", name="unread_random")
242 *
243 * @return \Symfony\Component\HttpFoundation\Response
244 */
245 public function showRandomUnreadEntryAction()
246 {
247 $repository = $this->get('wallabag_core.entry_repository');
248
249 try {
250 $entry = $repository->getRandomEntry($this->getUser()->getId(), 'unread');
251 } catch (NoResultException $e) {
252 $bag = $this->get('session')->getFlashBag();
253 $bag->clear();
254 $bag->add('notice', 'flashes.entry.notice.no_random_entry');
255
256 return $this->redirect($this->generateUrl('homepage'));
257 }
258
259 return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()]));
260 }
261
262 /**
263 * Shows random favorite entry.
264 *
265 * @param Entry $entry
266 *
267 * @Route("/starred/random", name="starred_random")
268 *
269 * @return \Symfony\Component\HttpFoundation\Response
270 */
271 public function showRandomStarredEntryAction()
272 {
273 $repository = $this->get('wallabag_core.entry_repository');
274
275 try {
276 $entry = $repository->getRandomEntry($this->getUser()->getId(), 'starred');
277 } catch (NoResultException $e) {
278 $bag = $this->get('session')->getFlashBag();
279 $bag->clear();
280 $bag->add('notice', 'flashes.entry.notice.no_random_entry');
281
282 return $this->redirect($this->generateUrl('homepage'));
283 }
284
285 return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()]));
286 }
287
288 /**
289 * Shows random archived entry.
290 *
291 * @param Entry $entry
292 *
293 * @Route("/archive/random", name="archive_random")
294 *
295 * @return \Symfony\Component\HttpFoundation\Response
296 */
297 public function showRandomArchiveEntryAction()
298 {
299 $repository = $this->get('wallabag_core.entry_repository');
300
301 try {
302 $entry = $repository->getRandomEntry($this->getUser()->getId(), 'starred');
303 } catch (NoResultException $e) {
304 $bag = $this->get('session')->getFlashBag();
305 $bag->clear();
306 $bag->add('notice', 'flashes.entry.notice.no_random_entry');
307
308 return $this->redirect($this->generateUrl('homepage'));
309 }
310
311 return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()]));
312 }
313
314 /**
315 * Shows random all entry.
316 *
317 * @param Entry $entry
318 *
319 * @Route("/all/random", name="all_random")
320 *
321 * @return \Symfony\Component\HttpFoundation\Response
322 */
323 public function showRandomAllEntryAction()
324 {
325 $repository = $this->get('wallabag_core.entry_repository');
326
327 try {
328 $entry = $repository->getRandomEntry($this->getUser()->getId());
329 } catch (NoResultException $e) {
330 $bag = $this->get('session')->getFlashBag();
331 $bag->clear();
332 $bag->add('notice', 'flashes.entry.notice.no_random_entry');
333
334 return $this->redirect($this->generateUrl('homepage'));
335 }
336
337 return $this->redirect($this->generateUrl('view', ['id' => $entry->getId()]));
338 }
339
340 /**
236 * Shows entry content. 341 * Shows entry content.
237 * 342 *
238 * @param Entry $entry 343 * @param Entry $entry