]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Controller/EntryController.php
Added button to show entries with the same domain
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Controller / EntryController.php
index ba5bfbe2916540ca7f2564d2f06891b6acd96ead..fad2b51cd5a760515447ec232a59423454ddfc26 100644 (file)
@@ -20,6 +20,48 @@ use Wallabag\CoreBundle\Form\Type\SearchEntryType;
 
 class EntryController extends Controller
 {
+    /**
+     * @Route("/mass", name="mass_action")
+     *
+     * @return \Symfony\Component\HttpFoundation\Response
+     */
+    public function massAction(Request $request)
+    {
+        $em = $this->getDoctrine()->getManager();
+        $values = $request->request->all();
+
+        $action = 'toggle-read';
+        if (isset($values['toggle-star'])) {
+            $action = 'toggle-star';
+        } elseif (isset($values['delete'])) {
+            $action = 'delete';
+        }
+
+        if (isset($values['entry-checkbox'])) {
+            foreach ($values['entry-checkbox'] as $id) {
+                /** @var Entry * */
+                $entry = $this->get('wallabag_core.entry_repository')->findById((int) $id)[0];
+
+                $this->checkUserAction($entry);
+
+                if ('toggle-read' === $action) {
+                    $entry->toggleArchive();
+                } elseif ('toggle-star' === $action) {
+                    $entry->toggleStar();
+                } elseif ('delete' === $action) {
+                    $this->get('event_dispatcher')->dispatch(EntryDeletedEvent::NAME, new EntryDeletedEvent($entry));
+                    $em->remove($entry);
+                }
+            }
+
+            $em->flush();
+        }
+
+        $redirectUrl = $this->get('wallabag_core.helper.redirect')->to($request->headers->get('referer'));
+
+        return $this->redirect($redirectUrl);
+    }
+
     /**
      * @param int $page
      *
@@ -475,6 +517,24 @@ class EntryController extends Controller
         );
     }
 
+    /**
+     * List the entries with the same domain as the current one.
+     *
+     * @param int $page
+     *
+     * @Route("/same-domain/{id}/{page}", requirements={"id" = ".+"}, defaults={"page" = 1}, name="same_domain")
+     *
+     * @return \Symfony\Component\HttpFoundation\Response
+     */
+    public function getSameDomainEntries(Request $request, $page = 1)
+    {
+        if (!$this->get('craue_config')->get('share_public')) {
+            throw $this->createAccessDeniedException('Sharing an entry is disabled for this user.');
+        }
+
+        return $this->showEntries('same-domain', $request, $page);
+    }
+
     /**
      * Global method to retrieve entries depending on the given type
      * It returns the response to be send.
@@ -506,6 +566,9 @@ class EntryController extends Controller
             case 'unread':
                 $qb = $repository->getBuilderForUnreadByUser($this->getUser()->getId());
                 break;
+            case 'same-domain':
+                $qb = $repository->getBuilderForSameDomainByUser($this->getUser()->getId(), $request->get('id'));
+                break;
             case 'all':
                 $qb = $repository->getBuilderForAllByUser($this->getUser()->getId());
                 break;