2020-03-21 18:39:12 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Controller;
|
|
|
|
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
|
|
use Symfony\Component\Routing\Annotation\Route;
|
|
|
|
use Symfony\Component\Filesystem\Filesystem;
|
|
|
|
use App\Motion\SnapshotRepository;
|
2020-03-22 20:34:33 +01:00
|
|
|
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
2020-03-24 23:47:46 +01:00
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
2020-03-21 18:39:12 +01:00
|
|
|
|
|
|
|
class EventController extends AbstractController
|
|
|
|
{
|
|
|
|
/**
|
2020-03-22 15:31:46 +01:00
|
|
|
* @Route("/events/{date}", name="events")
|
2020-03-21 18:39:12 +01:00
|
|
|
*/
|
2020-03-24 23:47:46 +01:00
|
|
|
public function events(SnapshotRepository $snapshotRepository, string $date = null): Response
|
2020-03-21 18:39:12 +01:00
|
|
|
{
|
2020-03-22 15:31:46 +01:00
|
|
|
$date = $date ?? date('Y-m-d');
|
|
|
|
|
|
|
|
$snapshots = $snapshotRepository->find([
|
|
|
|
'order' => 'DESC',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$days = [];
|
|
|
|
|
|
|
|
foreach ($snapshots as $snapshot) {
|
|
|
|
$day = $snapshot->getDate()->format('d/m');
|
|
|
|
|
|
|
|
if (!in_array($day, $days)) {
|
|
|
|
$days[$snapshot->getDate()->format('Y-m-d')] = $day;
|
|
|
|
}
|
|
|
|
}
|
2020-03-21 18:39:12 +01:00
|
|
|
|
|
|
|
return $this->render('events.html.twig', [
|
|
|
|
'snapshots' => $snapshots,
|
2020-03-22 15:31:46 +01:00
|
|
|
'days' => $days,
|
|
|
|
'date' => $date,
|
2020-03-21 18:39:12 +01:00
|
|
|
]);
|
|
|
|
}
|
2020-03-22 20:34:33 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @Route("/download_snapshot", name="download_snapshot")
|
|
|
|
*/
|
|
|
|
public function downloadSnapshot(SnapshotRepository $snapshotRepository, Request $request): BinaryFileResponse
|
|
|
|
{
|
|
|
|
$src = ltrim($request->query->get('src'), '/');
|
|
|
|
$snapshots = $snapshotRepository->find();
|
|
|
|
|
|
|
|
foreach ($snapshots as $snapshot) {
|
|
|
|
if ($snapshot->getMovie() === $src) {
|
|
|
|
return new BinaryFileResponse($src, 200, [
|
|
|
|
'Content-Type' => 'application/octect-stream',
|
|
|
|
'Content-Length' => filesize($src),
|
2020-04-29 19:51:01 +02:00
|
|
|
'Content-Disposition' => sprintf('attachment; filename="%s_%s"', $snapshot->getDate()->format('Y-m-d'), basename($src)),
|
2020-03-22 20:34:33 +01:00
|
|
|
'Content-Transfer-Encoding' => 'binary',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
throw $this->createNotFoundException();
|
|
|
|
}
|
2020-03-21 18:39:12 +01:00
|
|
|
}
|