aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/FederationBundle/Controller/RecommandController.php
blob: ea5a66601aa8f540bfabe7ce1d29bfac79498b3e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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()]);
    }
}