Browse Source

corrige les commentaires par projet

master
vincent 3 months ago
parent
commit
30b4bdafcd
7 changed files with 53 additions and 16 deletions
  1. +1
    -1
      src/Controller/HomeController.php
  2. +20
    -6
      src/Controller/TaskController.php
  3. +5
    -0
      src/Entity/Task.php
  4. +1
    -1
      src/Form/TaskType.php
  5. +1
    -1
      src/Repository/CommentRepository.php
  6. +23
    -7
      src/Service/GeoJsonManager.php
  7. +2
    -0
      templates/project/show.html.twig

+ 1
- 1
src/Controller/HomeController.php View File

@ -21,7 +21,7 @@ class HomeController extends AbstractController
public function error(Request $request, $exception, $logger = null): Response
{
$this->addFlash('danger', $exception->getMessage());
$this->addFlash('danger', $exception->getMessage()); // . ' ' . $exception->getFile() . ':' . $exception->getLine());
if ($request->headers->has('Referer')) {
return $this->redirect($request->headers->get('Referer'));


+ 20
- 6
src/Controller/TaskController.php View File

@ -53,6 +53,9 @@ class TaskController extends AbstractController
$task = $createForm->getData();
try {
if (!$task->hasGeojson()) {
$task->setGeojson('{}');
}
$task->setCreatedBy($this->getUser());
$entityManager->persist($task);
$entityManager->flush();
@ -104,9 +107,6 @@ class TaskController extends AbstractController
'label' => 'Commenter',
]);
$geom = \geoPHP::load($task->getGeojson(), 'json');
$bbox = $geom->getBBox();
$josmCommands = [
'imagery' => [
'id' => $project->hasImagery() ? $project->getImagery() : 'osmfr',
@ -120,7 +120,13 @@ class TaskController extends AbstractController
UrlGeneratorInterface::ABSOLUTE_URL
),
],
'zoom' => [
];
if ($task->hasGeojson()) {
$geom = \geoPHP::load($task->getGeojson(), 'json');
$bbox = $geom->getBBox();
$josmCommands['zoom'] = [
'bottom' => $bbox['miny'],
'top' => $bbox['maxy'],
'left' => $bbox['minx'],
@ -128,8 +134,8 @@ class TaskController extends AbstractController
'changeset_comment' => sprintf('%s %s', $project->getName(), $task->getName()),
'changeset_source' => $project->getSource(),
'changeset_hashtags' => $project->getHashtags(),
],
];
];
}
return $this->render('task/show.html.twig', [
'task' => $task,
@ -329,6 +335,10 @@ class TaskController extends AbstractController
return $this->redirect($request->headers->get('Referer'));
}
if (!$task->hasGeojson()) {
return new Response('Not found', 404);
}
$response = JsonResponse::fromJsonString($task->getGeojson());
$response->headers->set('Content-Disposition', HeaderUtils::makeDisposition(
@ -353,6 +363,10 @@ class TaskController extends AbstractController
return $this->redirect($request->headers->get('Referer'));
}
if (!$task->hasGeojson()) {
return new Response('Not found', 404);
}
$geom = \geoPHP::load($task->getGeojson(), 'json');
$gpx = $geom->out('gpx');


+ 5
- 0
src/Entity/Task.php View File

@ -162,6 +162,11 @@ class Task
return $this;
}
public function hasGeojson(): bool
{
return isset($this->geojson);
}
public function getGeojson(): ?string
{
return $this->geojson;


+ 1
- 1
src/Form/TaskType.php View File

@ -16,7 +16,7 @@ class TaskType extends AbstractType
$builder
->add('name', null, ['label' => 'Nom'])
->add('description', null, ['label' => 'Description'])
->add('geojson', TextareaType::class, ['label' => 'GeoJSON'])
->add('geojson', TextareaType::class, ['label' => 'GeoJSON', 'required' => false])
->add('osm', TextareaType::class, ['label' => 'OSM', 'required' => false])
->add('status', TaskLifecycleType::class, ['label' => 'État'])
->add('urgent', null, ['label' => 'Urgence', 'required' => false])


+ 1
- 1
src/Repository/CommentRepository.php View File

@ -24,7 +24,7 @@ class CommentRepository extends ServiceEntityRepository
public function findLatestByProject(Project $project): array
{
return $this->createQueryBuilder('c')
->join(Task::class, 't')
->join('c.task', 't')
->andWhere('t.project = :project')
->setParameter('project', $project)
->orderBy('c.createdAt', 'ASC')


+ 23
- 7
src/Service/GeoJsonManager.php View File

@ -19,16 +19,26 @@ class GeoJsonManager
private function getFullGeoJson(Task $task)
{
$data = json_decode($task->getGeojson(), true);
if (isset($data['features'][0]['properties'])) {
if (!$task->hasGeojson()) {
return null;
}
try {
$data = json_decode($task->getGeojson(), true);
} catch (\Exception $exception) {
return null;
}
if (!isset($data['features'][0]['properties'])) {
return null;
}
$data['features'][0]['properties'] = array_merge($data['features'][0]['properties'], [
'name' => $task->getName(),
'url' => $this->router->generate('app_task_show', ['slug' => $task->getSlug()], UrlGeneratorInterface::ABSOLUTE_URL),
'color' => $this->taskLifecycleStateMachine->getMetadataStore()->getPlaceMetadata($task->getStatus())['color'],
]);
} else {
dump($data);
}
return $data;
}
@ -38,11 +48,17 @@ class GeoJsonManager
if ($entity instanceof Task) {
$task = $entity;
$geoJsons[] = GeoJson::jsonUnserialize($this->getFullGeojson($task));
$geoJson = $this->getFullGeojson($task);
if (!is_null($geoJson)) {
$geoJsons[] = GeoJson::jsonUnserialize($geoJson);
}
} elseif ($entity instanceof Project) {
$project = $entity;
foreach ($project->getTasks() as $task) {
$geoJsons[] = GeoJson::jsonUnserialize($this->getFullGeojson($task));
$geoJson = $this->getFullGeojson($task);
if (!is_null($geoJson)) {
$geoJsons[] = GeoJson::jsonUnserialize($geoJson);
}
}
}


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

@ -105,6 +105,8 @@
<div class="col mb-3">
{% for comment in comments %}
<blockquote class="blockquote">
{{ project.name }}
{{ comment.task.project.name }}
{{ comment.content|markdown_to_html }}
</blockquote>
<figcaption class="blockquote-footer">


Loading…
Cancel
Save