You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

48 lines
1.5 KiB

<?php
namespace App\Service;
use App\Entity\Project;
use App\Entity\Task;
use GeoJson\GeoJson;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Workflow\WorkflowInterface;
class GeoJsonManager
{
public function __construct(
private UrlGeneratorInterface $router,
private WorkflowInterface $taskLifecycleStateMachine,
) {
}
private function getFullGeoJson(Task $task)
{
$data = json_decode($task->getGeojson(), true);
$data['features'][0]['properties'] = array_merge($data['features'][0]['properties'], [
'name' => $task->getName(),
'url' => $this->router->generate('app_task_show', ['projectSlug' => $task->getProject()->getSlug(), 'taskSlug' => $task->getSlug()], UrlGeneratorInterface::ABSOLUTE_URL),
'color' => $this->taskLifecycleStateMachine->getMetadataStore()->getPlaceMetadata($task->getStatus())['color'],
]);
return $data;
}
public function generateGeoJson($entity)
{
$geoJsons = [];
if ($entity instanceof Task) {
$task = $entity;
$geoJsons[] = GeoJson::jsonUnserialize($this->getFullGeojson($task));
} elseif ($entity instanceof Project) {
$project = $entity;
foreach ($project->getTasks() as $task) {
$geoJsons[] = GeoJson::jsonUnserialize($this->getFullGeojson($task));
}
}
return $geoJsons;
}
}