diff options
author | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2015-08-07 22:20:30 +0200 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2015-08-12 09:01:29 +0200 |
commit | 2686457448372543fdf4f1fc54c4fd20f0f02c2c (patch) | |
tree | 485eeecc3bd3db3613d47de25662d5c9163e4afe /src/Wallabag/CoreBundle/Controller | |
parent | fedaf005377e6d62ff0986f7f54afef3287a6451 (diff) | |
download | wallabag-2686457448372543fdf4f1fc54c4fd20f0f02c2c.tar.gz wallabag-2686457448372543fdf4f1fc54c4fd20f0f02c2c.tar.zst wallabag-2686457448372543fdf4f1fc54c4fd20f0f02c2c.zip |
store estimated reading time / filters on reading time
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller')
-rw-r--r-- | src/Wallabag/CoreBundle/Controller/EntryController.php | 66 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Controller/RssController.php | 17 |
2 files changed, 74 insertions, 9 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php index 29e0ffb0..8894690c 100644 --- a/src/Wallabag/CoreBundle/Controller/EntryController.php +++ b/src/Wallabag/CoreBundle/Controller/EntryController.php | |||
@@ -9,6 +9,9 @@ use Wallabag\CoreBundle\Entity\Entry; | |||
9 | use Wallabag\CoreBundle\Service\Extractor; | 9 | use Wallabag\CoreBundle\Service\Extractor; |
10 | use Wallabag\CoreBundle\Form\Type\NewEntryType; | 10 | use Wallabag\CoreBundle\Form\Type\NewEntryType; |
11 | use Wallabag\CoreBundle\Form\Type\EditEntryType; | 11 | use Wallabag\CoreBundle\Form\Type\EditEntryType; |
12 | use Wallabag\CoreBundle\Filter\EntryFilterType; | ||
13 | use Pagerfanta\Adapter\DoctrineORMAdapter; | ||
14 | use Pagerfanta\Pagerfanta; | ||
12 | 15 | ||
13 | class EntryController extends Controller | 16 | class EntryController extends Controller |
14 | { | 17 | { |
@@ -89,22 +92,39 @@ class EntryController extends Controller | |||
89 | /** | 92 | /** |
90 | * Shows unread entries for current user. | 93 | * Shows unread entries for current user. |
91 | * | 94 | * |
95 | * @param Request $request | ||
96 | * @param int $page | ||
97 | * | ||
92 | * @Route("/unread/list/{page}", name="unread", defaults={"page" = "1"}) | 98 | * @Route("/unread/list/{page}", name="unread", defaults={"page" = "1"}) |
93 | * | 99 | * |
94 | * @return \Symfony\Component\HttpFoundation\Response | 100 | * @return \Symfony\Component\HttpFoundation\Response |
95 | */ | 101 | */ |
96 | public function showUnreadAction($page) | 102 | public function showUnreadAction(Request $request, $page) |
97 | { | 103 | { |
98 | $entries = $this->getDoctrine() | 104 | $form = $this->get('form.factory')->create(new EntryFilterType()); |
105 | |||
106 | $filterBuilder = $this->getDoctrine() | ||
99 | ->getRepository('WallabagCoreBundle:Entry') | 107 | ->getRepository('WallabagCoreBundle:Entry') |
100 | ->findUnreadByUser($this->getUser()->getId()); | 108 | ->findUnreadByUser($this->getUser()->getId()); |
101 | 109 | ||
110 | if ($request->query->has($form->getName())) { | ||
111 | // manually bind values from the request | ||
112 | $form->submit($request->query->get($form->getName())); | ||
113 | |||
114 | // build the query from the given form object | ||
115 | $this->get('lexik_form_filter.query_builder_updater')->addFilterConditions($form, $filterBuilder); | ||
116 | } | ||
117 | |||
118 | $pagerAdapter = new DoctrineORMAdapter($filterBuilder->getQuery()); | ||
119 | $entries = new Pagerfanta($pagerAdapter); | ||
120 | |||
102 | $entries->setMaxPerPage($this->getUser()->getConfig()->getItemsPerPage()); | 121 | $entries->setMaxPerPage($this->getUser()->getConfig()->getItemsPerPage()); |
103 | $entries->setCurrentPage($page); | 122 | $entries->setCurrentPage($page); |
104 | 123 | ||
105 | return $this->render( | 124 | return $this->render( |
106 | 'WallabagCoreBundle:Entry:entries.html.twig', | 125 | 'WallabagCoreBundle:Entry:entries.html.twig', |
107 | array( | 126 | array( |
127 | 'form' => $form->createView(), | ||
108 | 'entries' => $entries, | 128 | 'entries' => $entries, |
109 | 'currentPage' => $page | 129 | 'currentPage' => $page |
110 | ) | 130 | ) |
@@ -114,22 +134,39 @@ class EntryController extends Controller | |||
114 | /** | 134 | /** |
115 | * Shows read entries for current user. | 135 | * Shows read entries for current user. |
116 | * | 136 | * |
137 | * @param Request $request | ||
138 | * @param int $page | ||
139 | * | ||
117 | * @Route("/archive/list/{page}", name="archive", defaults={"page" = "1"}) | 140 | * @Route("/archive/list/{page}", name="archive", defaults={"page" = "1"}) |
118 | * | 141 | * |
119 | * @return \Symfony\Component\HttpFoundation\Response | 142 | * @return \Symfony\Component\HttpFoundation\Response |
120 | */ | 143 | */ |
121 | public function showArchiveAction($page) | 144 | public function showArchiveAction(Request $request, $page) |
122 | { | 145 | { |
123 | $entries = $this->getDoctrine() | 146 | $form = $this->get('form.factory')->create(new EntryFilterType()); |
147 | |||
148 | $filterBuilder = $this->getDoctrine() | ||
124 | ->getRepository('WallabagCoreBundle:Entry') | 149 | ->getRepository('WallabagCoreBundle:Entry') |
125 | ->findArchiveByUser($this->getUser()->getId()); | 150 | ->findArchiveByUser($this->getUser()->getId()); |
126 | 151 | ||
152 | if ($request->query->has($form->getName())) { | ||
153 | // manually bind values from the request | ||
154 | $form->submit($request->query->get($form->getName())); | ||
155 | |||
156 | // build the query from the given form object | ||
157 | $this->get('lexik_form_filter.query_builder_updater')->addFilterConditions($form, $filterBuilder); | ||
158 | } | ||
159 | |||
160 | $pagerAdapter = new DoctrineORMAdapter($filterBuilder->getQuery()); | ||
161 | $entries = new Pagerfanta($pagerAdapter); | ||
162 | |||
127 | $entries->setMaxPerPage($this->getUser()->getConfig()->getItemsPerPage()); | 163 | $entries->setMaxPerPage($this->getUser()->getConfig()->getItemsPerPage()); |
128 | $entries->setCurrentPage($page); | 164 | $entries->setCurrentPage($page); |
129 | 165 | ||
130 | return $this->render( | 166 | return $this->render( |
131 | 'WallabagCoreBundle:Entry:entries.html.twig', | 167 | 'WallabagCoreBundle:Entry:entries.html.twig', |
132 | array( | 168 | array( |
169 | 'form' => $form->createView(), | ||
133 | 'entries' => $entries, | 170 | 'entries' => $entries, |
134 | 'currentPage' => $page | 171 | 'currentPage' => $page |
135 | ) | 172 | ) |
@@ -139,22 +176,39 @@ class EntryController extends Controller | |||
139 | /** | 176 | /** |
140 | * Shows starred entries for current user. | 177 | * Shows starred entries for current user. |
141 | * | 178 | * |
179 | * @param Request $request | ||
180 | * @param int $page | ||
181 | * | ||
142 | * @Route("/starred/list/{page}", name="starred", defaults={"page" = "1"}) | 182 | * @Route("/starred/list/{page}", name="starred", defaults={"page" = "1"}) |
143 | * | 183 | * |
144 | * @return \Symfony\Component\HttpFoundation\Response | 184 | * @return \Symfony\Component\HttpFoundation\Response |
145 | */ | 185 | */ |
146 | public function showStarredAction($page) | 186 | public function showStarredAction(Request $request, $page) |
147 | { | 187 | { |
148 | $entries = $this->getDoctrine() | 188 | $form = $this->get('form.factory')->create(new EntryFilterType()); |
189 | |||
190 | $filterBuilder = $this->getDoctrine() | ||
149 | ->getRepository('WallabagCoreBundle:Entry') | 191 | ->getRepository('WallabagCoreBundle:Entry') |
150 | ->findStarredByUser($this->getUser()->getId()); | 192 | ->findStarredByUser($this->getUser()->getId()); |
151 | 193 | ||
194 | if ($request->query->has($form->getName())) { | ||
195 | // manually bind values from the request | ||
196 | $form->submit($request->query->get($form->getName())); | ||
197 | |||
198 | // build the query from the given form object | ||
199 | $this->get('lexik_form_filter.query_builder_updater')->addFilterConditions($form, $filterBuilder); | ||
200 | } | ||
201 | |||
202 | $pagerAdapter = new DoctrineORMAdapter($filterBuilder->getQuery()); | ||
203 | $entries = new Pagerfanta($pagerAdapter); | ||
204 | |||
152 | $entries->setMaxPerPage($this->getUser()->getConfig()->getItemsPerPage()); | 205 | $entries->setMaxPerPage($this->getUser()->getConfig()->getItemsPerPage()); |
153 | $entries->setCurrentPage($page); | 206 | $entries->setCurrentPage($page); |
154 | 207 | ||
155 | return $this->render( | 208 | return $this->render( |
156 | 'WallabagCoreBundle:Entry:entries.html.twig', | 209 | 'WallabagCoreBundle:Entry:entries.html.twig', |
157 | array( | 210 | array( |
211 | 'form' => $form->createView(), | ||
158 | 'entries' => $entries, | 212 | 'entries' => $entries, |
159 | 'currentPage' => $page | 213 | 'currentPage' => $page |
160 | ) | 214 | ) |
diff --git a/src/Wallabag/CoreBundle/Controller/RssController.php b/src/Wallabag/CoreBundle/Controller/RssController.php index 8428dce0..0558c53b 100644 --- a/src/Wallabag/CoreBundle/Controller/RssController.php +++ b/src/Wallabag/CoreBundle/Controller/RssController.php | |||
@@ -7,6 +7,8 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; | |||
7 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | 7 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
8 | use Wallabag\CoreBundle\Entity\User; | 8 | use Wallabag\CoreBundle\Entity\User; |
9 | use Wallabag\CoreBundle\Entity\Entry; | 9 | use Wallabag\CoreBundle\Entity\Entry; |
10 | use Pagerfanta\Adapter\DoctrineORMAdapter; | ||
11 | use Pagerfanta\Pagerfanta; | ||
10 | 12 | ||
11 | class RssController extends Controller | 13 | class RssController extends Controller |
12 | { | 14 | { |
@@ -20,12 +22,15 @@ class RssController extends Controller | |||
20 | */ | 22 | */ |
21 | public function showUnreadAction(User $user) | 23 | public function showUnreadAction(User $user) |
22 | { | 24 | { |
23 | $entries = $this->getDoctrine() | 25 | $qb = $this->getDoctrine() |
24 | ->getRepository('WallabagCoreBundle:Entry') | 26 | ->getRepository('WallabagCoreBundle:Entry') |
25 | ->findUnreadByUser( | 27 | ->findUnreadByUser( |
26 | $user->getId() | 28 | $user->getId() |
27 | ); | 29 | ); |
28 | 30 | ||
31 | $pagerAdapter = new DoctrineORMAdapter($qb->getQuery()); | ||
32 | $entries = new Pagerfanta($pagerAdapter); | ||
33 | |||
29 | $perPage = $user->getConfig()->getRssLimit() ?: $this->container->getParameter('rss_limit'); | 34 | $perPage = $user->getConfig()->getRssLimit() ?: $this->container->getParameter('rss_limit'); |
30 | $entries->setMaxPerPage($perPage); | 35 | $entries->setMaxPerPage($perPage); |
31 | 36 | ||
@@ -45,12 +50,15 @@ class RssController extends Controller | |||
45 | */ | 50 | */ |
46 | public function showArchiveAction(User $user) | 51 | public function showArchiveAction(User $user) |
47 | { | 52 | { |
48 | $entries = $this->getDoctrine() | 53 | $qb = $this->getDoctrine() |
49 | ->getRepository('WallabagCoreBundle:Entry') | 54 | ->getRepository('WallabagCoreBundle:Entry') |
50 | ->findArchiveByUser( | 55 | ->findArchiveByUser( |
51 | $user->getId() | 56 | $user->getId() |
52 | ); | 57 | ); |
53 | 58 | ||
59 | $pagerAdapter = new DoctrineORMAdapter($qb->getQuery()); | ||
60 | $entries = new Pagerfanta($pagerAdapter); | ||
61 | |||
54 | $perPage = $user->getConfig()->getRssLimit() ?: $this->container->getParameter('rss_limit'); | 62 | $perPage = $user->getConfig()->getRssLimit() ?: $this->container->getParameter('rss_limit'); |
55 | $entries->setMaxPerPage($perPage); | 63 | $entries->setMaxPerPage($perPage); |
56 | 64 | ||
@@ -70,12 +78,15 @@ class RssController extends Controller | |||
70 | */ | 78 | */ |
71 | public function showStarredAction(User $user) | 79 | public function showStarredAction(User $user) |
72 | { | 80 | { |
73 | $entries = $this->getDoctrine() | 81 | $qb = $this->getDoctrine() |
74 | ->getRepository('WallabagCoreBundle:Entry') | 82 | ->getRepository('WallabagCoreBundle:Entry') |
75 | ->findStarredByUser( | 83 | ->findStarredByUser( |
76 | $user->getId() | 84 | $user->getId() |
77 | ); | 85 | ); |
78 | 86 | ||
87 | $pagerAdapter = new DoctrineORMAdapter($qb->getQuery()); | ||
88 | $entries = new Pagerfanta($pagerAdapter); | ||
89 | |||
79 | $perPage = $user->getConfig()->getRssLimit() ?: $this->container->getParameter('rss_limit'); | 90 | $perPage = $user->getConfig()->getRssLimit() ?: $this->container->getParameter('rss_limit'); |
80 | $entries->setMaxPerPage($perPage); | 91 | $entries->setMaxPerPage($perPage); |
81 | 92 | ||