]> git.immae.eu Git - github/wallabag/wallabag.git/blob - src/Wallabag/FederationBundle/Controller/RecommandController.php
WIP
[github/wallabag/wallabag.git] / src / Wallabag / FederationBundle / Controller / RecommandController.php
1 <?php
2
3 namespace Wallabag\FederationBundle\Controller;
4
5 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6 use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7 use Wallabag\CoreBundle\Entity\Entry;
8 use Wallabag\CoreBundle\Event\Activity\Actions\Federation\RecommendedEntryEvent;
9 use Wallabag\FederationBundle\Entity\Account;
10
11 class RecommandController extends Controller
12 {
13 /**
14 * @Route("/recommend/{entry}", name="recommend-entry")
15 *
16 * @param Entry $entry
17 */
18 public function postRecommendAction(Entry $entry)
19 {
20 if ($entry->getUser() !== $this->getUser()) {
21 $this->createAccessDeniedException("You can't recommend entries which are not your own");
22 }
23 $em = $this->getDoctrine()->getManager();
24
25 $entry->setRecommended(true);
26
27 $em->persist($entry);
28 $em->flush();
29
30 $this->get('event_dispatcher')->dispatch(RecommendedEntryEvent::NAME, new RecommendedEntryEvent($entry));
31
32 $this->redirectToRoute('view', ['id' => $entry->getId()]);
33 }
34 }