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