]> git.immae.eu Git - github/wallabag/wallabag.git/blob - src/WallabagBundle/Controller/EntryController.php
fbbb76aa2054dbedc06ee391e3ca273c39de03f5
[github/wallabag/wallabag.git] / src / WallabagBundle / Controller / EntryController.php
1 <?php
2
3 namespace WallabagBundle\Controller;
4
5 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6 use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7 use Symfony\Component\HttpFoundation\Request;
8 use WallabagBundle\Repository;
9 use WallabagBundle\Entity\Entries;
10
11 class EntryController extends Controller
12 {
13 /**
14 * Shows unread entries for current user
15 *
16 * @Route("/unread", name="unread")
17 * @return \Symfony\Component\HttpFoundation\Response
18 */
19 public function showUnreadAction()
20 {
21 $repository = $this->getDoctrine()->getRepository('WallabagBundle:Entries');
22 $entries = $repository->findUnreadByUser(1, 0);
23
24 return $this->render(
25 'WallabagBundle:Entry:entries.html.twig',
26 array('entries' => $entries)
27 );
28 }
29
30 /**
31 * Shows read entries for current user
32 *
33 * @Route("/archive", name="archive")
34 * @return \Symfony\Component\HttpFoundation\Response
35 */
36 public function showArchiveAction()
37 {
38 $repository = $this->getDoctrine()->getRepository('WallabagBundle:Entries');
39 $entries = $repository->findArchiveByUser(1, 0);
40
41 return $this->render(
42 'WallabagBundle:Entry:entries.html.twig',
43 array('entries' => $entries)
44 );
45 }
46
47 /**
48 * Shows starred entries for current user
49 *
50 * @Route("/starred", name="starred")
51 * @return \Symfony\Component\HttpFoundation\Response
52 */
53 public function showStarredAction()
54 {
55 $repository = $this->getDoctrine()->getRepository('WallabagBundle:Entries');
56 $entries = $repository->findStarredByUser(1, 0);
57
58 return $this->render(
59 'WallabagBundle:Entry:entries.html.twig',
60 array('entries' => $entries)
61 );
62 }
63
64 /**
65 * Shows entry content
66 *
67 * @param Entries $entry
68 * @Route("/view/{id}", requirements={"id" = "\d+"}, name="view")
69 * @return \Symfony\Component\HttpFoundation\Response
70 */
71 public function viewAction(Entries $entry)
72 {
73 return $this->render(
74 'WallabagBundle:Entry:entry.html.twig',
75 array('entry' => $entry)
76 );
77 }
78
79 /**
80 * Changes read status for an entry
81 *
82 * @param Request $request
83 * @param Entries $entry
84 * @Route("/archive/{id}", requirements={"id" = "\d+"}, name="archive_entry")
85 * @return \Symfony\Component\HttpFoundation\RedirectResponse
86 */
87 public function toggleArchiveAction(Request $request, Entries $entry)
88 {
89 $entry->toggleArchive();
90 $this->getDoctrine()->getManager()->flush();
91
92 $this->get('session')->getFlashBag()->add(
93 'notice',
94 'Entry archived'
95 );
96
97 return $this->redirect($request->headers->get('referer'));
98 }
99
100 /**
101 * Changes favorite status for an entry
102 *
103 * @param Request $request
104 * @param Entries $entry
105 * @Route("/star/{id}", requirements={"id" = "\d+"}, name="star_entry")
106 * @return \Symfony\Component\HttpFoundation\RedirectResponse
107 */
108 public function toggleStarAction(Request $request, Entries $entry)
109 {
110 $entry->toggleStar();
111 $this->getDoctrine()->getManager()->flush();
112
113 $this->get('session')->getFlashBag()->add(
114 'notice',
115 'Entry starred'
116 );
117
118 return $this->redirect($request->headers->get('referer'));
119 }
120
121 /**
122 * Deletes entry
123 *
124 * @param Request $request
125 * @param Entries $entry
126 * @Route("/delete/{id}", requirements={"id" = "\d+"}, name="delete_entry")
127 * @return \Symfony\Component\HttpFoundation\RedirectResponse
128 */
129 public function deleteEntryAction(Request $request, Entries $entry)
130 {
131 $em = $this->getDoctrine()->getEntityManager();
132 $em->remove($entry);
133 $em->flush();
134
135 $this->get('session')->getFlashBag()->add(
136 'notice',
137 'Entry deleted'
138 );
139
140 return $this->redirect($request->headers->get('referer'));
141 }
142 }