From 163eae0bb15d0daa5390f434a42a8176eca186e7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Nicolas=20L=C5=93uillet?= Date: Fri, 23 Jan 2015 12:45:24 +0100 Subject: [PATCH] toggle archive / fav actions --- bin/install | 6 +- .../Controller/EntryController.php | 92 +++++++++++++++++-- .../Controller/StaticController.php | 20 ++++ src/WallabagBundle/Entity/Entries.php | 13 +++ .../Repository/EntriesRepository.php | 26 +++--- .../Resources/views/Entry/entries.html.twig | 20 +++- .../Resources/views/Entry/entry.html.twig | 18 ++-- .../Resources/views/Static/about.html.twig | 84 +++++++++++++++++ .../Resources/views/_menu.html.twig | 6 +- .../Resources/views/_save_form.html.twig | 10 ++ .../Resources/views/_search_form.html.twig | 9 ++ .../Resources/views/layout.html.twig | 8 +- 12 files changed, 268 insertions(+), 44 deletions(-) create mode 100644 src/WallabagBundle/Controller/StaticController.php create mode 100755 src/WallabagBundle/Resources/views/Static/about.html.twig create mode 100755 src/WallabagBundle/Resources/views/_save_form.html.twig create mode 100644 src/WallabagBundle/Resources/views/_search_form.html.twig diff --git a/bin/install b/bin/install index 5b93e46e..61ffcb65 100755 --- a/bin/install +++ b/bin/install @@ -67,8 +67,6 @@ $query = executeQuery($handle, $sql, $params); echo 'wallabag is now installed'; echo "\r\n"; -echo 'Just execute the following commands for using wallabag:'; +echo 'Just execute `php app/console server:run` for using wallabag:'; echo "\r\n"; -echo 'cd web'; -echo "\r\n"; -echo 'php -S localhost:8000'; \ No newline at end of file +echo 'http://localhost:8000'; \ No newline at end of file diff --git a/src/WallabagBundle/Controller/EntryController.php b/src/WallabagBundle/Controller/EntryController.php index 233a6c32..fbbb76aa 100644 --- a/src/WallabagBundle/Controller/EntryController.php +++ b/src/WallabagBundle/Controller/EntryController.php @@ -4,67 +4,139 @@ namespace WallabagBundle\Controller; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Symfony\Bundle\FrameworkBundle\Controller\Controller; +use Symfony\Component\HttpFoundation\Request; use WallabagBundle\Repository; +use WallabagBundle\Entity\Entries; class EntryController extends Controller { /** + * Shows unread entries for current user + * * @Route("/unread", name="unread") + * @return \Symfony\Component\HttpFoundation\Response */ public function showUnreadAction() { $repository = $this->getDoctrine()->getRepository('WallabagBundle:Entries'); - $entries = $repository->findUnreadByUser(1); + $entries = $repository->findUnreadByUser(1, 0); return $this->render( 'WallabagBundle:Entry:entries.html.twig', array('entries' => $entries) ); - } /** + * Shows read entries for current user + * * @Route("/archive", name="archive") + * @return \Symfony\Component\HttpFoundation\Response */ public function showArchiveAction() { $repository = $this->getDoctrine()->getRepository('WallabagBundle:Entries'); - $entries = $repository->findArchiveByUser(1); + $entries = $repository->findArchiveByUser(1, 0); return $this->render( 'WallabagBundle:Entry:entries.html.twig', array('entries' => $entries) ); - } /** + * Shows starred entries for current user + * * @Route("/starred", name="starred") + * @return \Symfony\Component\HttpFoundation\Response */ public function showStarredAction() { $repository = $this->getDoctrine()->getRepository('WallabagBundle:Entries'); - $entries = $repository->findStarredByUser(1); + $entries = $repository->findStarredByUser(1, 0); return $this->render( 'WallabagBundle:Entry:entries.html.twig', array('entries' => $entries) ); - } /** + * Shows entry content + * + * @param Entries $entry * @Route("/view/{id}", requirements={"id" = "\d+"}, name="view") + * @return \Symfony\Component\HttpFoundation\Response */ - public function viewAction($id) + public function viewAction(Entries $entry) { - $repository = $this->getDoctrine()->getRepository('WallabagBundle:Entries'); - $entry = $repository->find($id); - return $this->render( 'WallabagBundle:Entry:entry.html.twig', array('entry' => $entry) ); + } + + /** + * Changes read status for an entry + * + * @param Request $request + * @param Entries $entry + * @Route("/archive/{id}", requirements={"id" = "\d+"}, name="archive_entry") + * @return \Symfony\Component\HttpFoundation\RedirectResponse + */ + public function toggleArchiveAction(Request $request, Entries $entry) + { + $entry->toggleArchive(); + $this->getDoctrine()->getManager()->flush(); + + $this->get('session')->getFlashBag()->add( + 'notice', + 'Entry archived' + ); + + return $this->redirect($request->headers->get('referer')); + } + + /** + * Changes favorite status for an entry + * + * @param Request $request + * @param Entries $entry + * @Route("/star/{id}", requirements={"id" = "\d+"}, name="star_entry") + * @return \Symfony\Component\HttpFoundation\RedirectResponse + */ + public function toggleStarAction(Request $request, Entries $entry) + { + $entry->toggleStar(); + $this->getDoctrine()->getManager()->flush(); + + $this->get('session')->getFlashBag()->add( + 'notice', + 'Entry starred' + ); + + return $this->redirect($request->headers->get('referer')); + } + + /** + * Deletes entry + * + * @param Request $request + * @param Entries $entry + * @Route("/delete/{id}", requirements={"id" = "\d+"}, name="delete_entry") + * @return \Symfony\Component\HttpFoundation\RedirectResponse + */ + public function deleteEntryAction(Request $request, Entries $entry) + { + $em = $this->getDoctrine()->getEntityManager(); + $em->remove($entry); + $em->flush(); + + $this->get('session')->getFlashBag()->add( + 'notice', + 'Entry deleted' + ); + return $this->redirect($request->headers->get('referer')); } } diff --git a/src/WallabagBundle/Controller/StaticController.php b/src/WallabagBundle/Controller/StaticController.php new file mode 100644 index 00000000..aee2bb7e --- /dev/null +++ b/src/WallabagBundle/Controller/StaticController.php @@ -0,0 +1,20 @@ +render( + 'WallabagBundle:Static:about.html.twig', + array() + ); + } +} diff --git a/src/WallabagBundle/Entity/Entries.php b/src/WallabagBundle/Entity/Entries.php index 69c6be0d..b364e0c3 100644 --- a/src/WallabagBundle/Entity/Entries.php +++ b/src/WallabagBundle/Entity/Entries.php @@ -144,6 +144,12 @@ class Entries return $this->isRead; } + public function toggleArchive() + { + $this->isRead = $this->getIsRead() ^ 1; + return $this; + } + /** * Set isFav * @@ -167,6 +173,13 @@ class Entries return $this->isFav; } + public function toggleStar() + { + $this->isFav = $this->getIsFav() ^ 1; + + return $this; + } + /** * Set content * diff --git a/src/WallabagBundle/Repository/EntriesRepository.php b/src/WallabagBundle/Repository/EntriesRepository.php index c355a012..c4428a1d 100644 --- a/src/WallabagBundle/Repository/EntriesRepository.php +++ b/src/WallabagBundle/Repository/EntriesRepository.php @@ -4,31 +4,31 @@ namespace WallabagBundle\Repository; use Doctrine\ORM\Query; use Doctrine\ORM\EntityRepository; +use Doctrine\ORM\Tools\Pagination\Paginator; -/** - * EntriesRepository - * - * This class was generated by the Doctrine ORM. Add your own custom - * repository methods below. - */ class EntriesRepository extends EntityRepository { - public function findUnreadByUser($userId) + public function findUnreadByUser($userId, $firstResult, $maxResults = 12) { $qb = $this->createQueryBuilder('e') ->select('e') + ->setFirstResult($firstResult) + ->setMaxResults($maxResults) ->where('e.isRead = 0') ->andWhere('e.userId =:userId')->setParameter('userId', $userId) - ->getQuery() - ->getResult(Query::HYDRATE_ARRAY); + ->getQuery(); - return $qb; + $pag = new Paginator($qb); + + return $pag; } - public function findArchiveByUser($userId) + public function findArchiveByUser($userId, $firstResult, $maxResults = 12) { $qb = $this->createQueryBuilder('e') ->select('e') + ->setFirstResult($firstResult) + ->setMaxResults($maxResults) ->where('e.isRead = 1') ->andWhere('e.userId =:userId')->setParameter('userId', $userId) ->getQuery() @@ -37,10 +37,12 @@ class EntriesRepository extends EntityRepository return $qb; } - public function findStarredByUser($userId) + public function findStarredByUser($userId, $firstResult, $maxResults = 12) { $qb = $this->createQueryBuilder('e') ->select('e') + ->setFirstResult($firstResult) + ->setMaxResults($maxResults) ->where('e.isFav = 1') ->andWhere('e.userId =:userId')->setParameter('userId', $userId) ->getQuery() diff --git a/src/WallabagBundle/Resources/views/Entry/entries.html.twig b/src/WallabagBundle/Resources/views/Entry/entries.html.twig index 81177298..de343aa2 100644 --- a/src/WallabagBundle/Resources/views/Entry/entries.html.twig +++ b/src/WallabagBundle/Resources/views/Entry/entries.html.twig @@ -7,6 +7,20 @@ {% endblock %} {% block content %} + {% block pager %} + {% if entries is not empty %} +
+
{{ entries.count }} {% trans %}entries{% endtrans %}
+ +
+ {% endif %} + {% endblock %} {% if entries is empty %}

{% trans %}No articles found.{% endtrans %}

@@ -21,9 +35,9 @@ {% endif %}

{{ entry.content|striptags|slice(0, 300) }}...

diff --git a/src/WallabagBundle/Resources/views/Entry/entry.html.twig b/src/WallabagBundle/Resources/views/Entry/entry.html.twig index 19d4650e..8c08b2ef 100644 --- a/src/WallabagBundle/Resources/views/Entry/entry.html.twig +++ b/src/WallabagBundle/Resources/views/Entry/entry.html.twig @@ -11,9 +11,9 @@ diff --git a/src/WallabagBundle/Resources/views/_save_form.html.twig b/src/WallabagBundle/Resources/views/_save_form.html.twig new file mode 100755 index 00000000..acaa5dbc --- /dev/null +++ b/src/WallabagBundle/Resources/views/_save_form.html.twig @@ -0,0 +1,10 @@ + diff --git a/src/WallabagBundle/Resources/views/_search_form.html.twig b/src/WallabagBundle/Resources/views/_search_form.html.twig new file mode 100644 index 00000000..7eb1b67d --- /dev/null +++ b/src/WallabagBundle/Resources/views/_search_form.html.twig @@ -0,0 +1,9 @@ + diff --git a/src/WallabagBundle/Resources/views/layout.html.twig b/src/WallabagBundle/Resources/views/layout.html.twig index 4a3f0f5c..34d9b1b0 100644 --- a/src/WallabagBundle/Resources/views/layout.html.twig +++ b/src/WallabagBundle/Resources/views/layout.html.twig @@ -19,9 +19,11 @@
{% block menu %}{% endblock %} {% block precontent %}{% endblock %} - {% block messages %} - {% include "WallabagBundle::_messages.html.twig" %} - {% endblock %} + {% for flashMessage in app.session.flashbag.get('notice') %} +
+ {{ flashMessage }} +
+ {% endfor %}
{% block content %}{% endblock %}
-- 2.41.0