1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Controller\Media; |
4
|
|
|
|
5
|
|
|
use App\Entity\Video; |
6
|
|
|
use App\Event\Video\VideoDeleteEvent; |
7
|
|
|
use App\Exception\RedirectException; |
8
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted; |
9
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
10
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
11
|
|
|
use Symfony\Component\HttpFoundation\Request; |
12
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class DeleteImageController |
16
|
|
|
* @package App\Controller\Image |
17
|
|
|
* @IsGranted("ROLE_USER") |
18
|
|
|
*/ |
19
|
|
|
class DeleteVideoController extends AbstractController |
20
|
|
|
{ |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var EventDispatcherInterface |
24
|
|
|
*/ |
25
|
|
|
private $dispatcher; |
26
|
|
|
|
27
|
|
|
public function __construct(EventDispatcherInterface $dispatcher) |
28
|
|
|
{ |
29
|
|
|
$this->dispatcher = $dispatcher; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @Route("/video/delete/{id}", name="video.deleteFromTrick", methods={"POST"}) |
34
|
|
|
* @param Video $video |
35
|
|
|
* @param Request $request |
36
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse |
37
|
|
|
*/ |
38
|
|
|
public function deleteTrickImage(video $video, Request $request) |
39
|
|
|
{ |
40
|
|
|
$submittedToken = $request->request->get('_token'); |
41
|
|
|
if (!$this->isCsrfTokenValid('delete-video' . $video->getId(), $submittedToken)) { |
42
|
|
|
throw new RedirectException($this->generateUrl('home'), 'Bad CSRF Token'); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
$trick = $video->getTrick(); |
46
|
|
|
$event = new VideoDeleteEvent($video, $video->getTrick()); |
|
|
|
|
47
|
|
|
$this->dispatcher->dispatch(VideoDeleteEvent::NAME, $event); |
48
|
|
|
|
49
|
|
|
return $this->redirectToRoute('trick.edit', [ |
50
|
|
|
'id' => $trick->getId(), |
51
|
|
|
]); |
52
|
|
|
} |
53
|
|
|
} |