diff --git a/src/Controller/TaskController.php b/src/Controller/TaskController.php
index 3850fb1..38f3f5e 100644
--- a/src/Controller/TaskController.php
+++ b/src/Controller/TaskController.php
@@ -16,6 +16,7 @@ use Symfony\Component\HttpFoundation\HeaderUtils;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
+use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Workflow\WorkflowInterface;
@@ -409,6 +410,55 @@ class TaskController extends AbstractController
return $response;
}
+ #[Route('/download/{slug}.csv', name: 'app_task_csv')]
+ public function csv(Request $request, EntityManagerInterface $entityManager, $slug): Response
+ {
+ $repository = $entityManager->getRepository(Project::class);
+ $project = $repository->findOneBySlug($slug);
+
+ if (!$project) {
+ $this->addFlash('warning', 'Projet non trouvé !');
+ return $this->redirect($request->headers->get('referer'));
+ }
+
+ $response = new StreamedResponse();
+
+ $response->setCallback(function () use ($project): void {
+ $output = fopen('php://output', 'a');
+ fputcsv(
+ $output, [
+ 'name',
+ 'description',
+ 'osm',
+ 'geojson',
+ 'status',
+ ]
+ );
+ foreach($project->getTasks() as $task) {
+ fputcsv(
+ $output,
+ [
+ $task->getName(),
+ $task->getDescription(),
+ $task->getOsm(),
+ $task->getGeojson(),
+ $task->getStatus(),
+ ]
+ );
+ }
+ fclose($output);
+ flush();
+ });
+
+ $response->headers->set('Content-Type', 'text/csv');
+ $response->headers->set('Content-Disposition', HeaderUtils::makeDisposition(
+ HeaderUtils::DISPOSITION_ATTACHMENT,
+ sprintf('%s.csv', $project->getSlug())
+ ));
+
+ return $response;
+ }
+
#[Route('/{slug}/changesets', name: 'app_task_changesets')]
public function changesets(OpenStreetMapClient $osmClient, EntityManagerInterface $entityManager, $slug): Response
{
diff --git a/templates/project/show.html.twig b/templates/project/show.html.twig
index 7b74428..504f85b 100644
--- a/templates/project/show.html.twig
+++ b/templates/project/show.html.twig
@@ -27,6 +27,7 @@
Requêter Overpass
{% endif %}
+ Exporter les tâches
Créer une tâche
{% endif %}
{% if randomTask %}