Browse Source

export des tâches

master
vincent 3 months ago
parent
commit
78c5e04a22
2 changed files with 51 additions and 0 deletions
  1. +50
    -0
      src/Controller/TaskController.php
  2. +1
    -0
      templates/project/show.html.twig

+ 50
- 0
src/Controller/TaskController.php View File

@ -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
{


+ 1
- 0
templates/project/show.html.twig View File

@ -27,6 +27,7 @@
<a href="{{ path('app_project_overpass', {'slug': project.slug}) }}" class="btn btn-secondary">Requêter Overpass</a>
{% endif %}
<button type="button" class="btn btn-secondary" data-bs-toggle="modal" data-bs-target="#modal">Importer des tâches</button>
<a href="{{ path('app_task_csv', {'slug': project.slug}) }}" class="btn btn-secondary">Exporter les tâches</a>
<a href="{{ path('app_task_create', {'slug': project.slug}) }}" class="btn btn-secondary">Créer une tâche</a>
{% endif %}
{% if randomTask %}


Loading…
Cancel
Save