]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/FederationBundle/Controller/RecommandController.php
WIP
[github/wallabag/wallabag.git] / src / Wallabag / FederationBundle / Controller / RecommandController.php
diff --git a/src/Wallabag/FederationBundle/Controller/RecommandController.php b/src/Wallabag/FederationBundle/Controller/RecommandController.php
new file mode 100644 (file)
index 0000000..ea5a666
--- /dev/null
@@ -0,0 +1,34 @@
+<?php
+
+namespace Wallabag\FederationBundle\Controller;
+
+use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
+use Symfony\Bundle\FrameworkBundle\Controller\Controller;
+use Wallabag\CoreBundle\Entity\Entry;
+use Wallabag\CoreBundle\Event\Activity\Actions\Federation\RecommendedEntryEvent;
+use Wallabag\FederationBundle\Entity\Account;
+
+class RecommandController extends Controller
+{
+    /**
+     * @Route("/recommend/{entry}", name="recommend-entry")
+     *
+     * @param Entry $entry
+     */
+    public function postRecommendAction(Entry $entry)
+    {
+        if ($entry->getUser() !== $this->getUser()) {
+            $this->createAccessDeniedException("You can't recommend entries which are not your own");
+        }
+        $em = $this->getDoctrine()->getManager();
+
+        $entry->setRecommended(true);
+
+        $em->persist($entry);
+        $em->flush();
+
+        $this->get('event_dispatcher')->dispatch(RecommendedEntryEvent::NAME, new RecommendedEntryEvent($entry));
+
+        $this->redirectToRoute('view', ['id' => $entry->getId()]);
+    }
+}