diff --git a/src/Controller/TaskController.php b/src/Controller/TaskController.php index 1871d08..c91ea68 100644 --- a/src/Controller/TaskController.php +++ b/src/Controller/TaskController.php @@ -3,6 +3,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Routing\Generator\UrlGenerator; use App\Entity\ActorEntity; use App\Entity\TaskEntity; use App\Repository\ActorRepository; @@ -109,8 +110,44 @@ // Get task $task = $taskRepository->find($id); + // Task delete form + /** @var TaskDeleteForm $taskDeleteForm */ + $taskDeleteForm = $this->createNamedCustomForm('taskDelete', TaskDeleteForm::class); + $taskDeleteForm->handleRequest($request); + if ($taskDeleteForm->isSubmitted() && $taskDeleteForm->isValid()) { + $errors = $taskDeleteForm->validate(); + if (empty($errors)) { + if (!is_null($task)) { + $entityManager->remove($task); + $entityManager->flush(); + if (is_null($task->getActivity())) { + return $this->ajaxFormAnswer([ + 'redirect' => $this->generateUrl('task_tasks', [], UrlGenerator::ABSOLUTE_PATH), + ]); + } else { + return $this->ajaxFormAnswer([ + 'redirect' => $this->generateUrl('activity_activity', [ + 'id' => $task->getActivity() + ->getId() + ], UrlGenerator::ABSOLUTE_PATH), + ]); + } + } + return $this->ajaxFormAnswer([ + 'error' => 'Tâche non trouvé', + 'code' => Response::HTTP_BAD_REQUEST, + ]); + } else { + return $this->ajaxFormAnswer([ + 'error' => join('
', $errors), + 'code' => Response::HTTP_BAD_REQUEST, + ]); + } + } + return $this->render('task/task.html.twig', [ - 'task' => $task + 'task' => $task, + 'taskDeleteForm' => $taskDeleteForm, ]); } } \ No newline at end of file diff --git a/src/Repository/TaskRepository.php b/src/Repository/TaskRepository.php index 4f161cd..0f7c96e 100644 --- a/src/Repository/TaskRepository.php +++ b/src/Repository/TaskRepository.php @@ -3,6 +3,7 @@ use Doctrine\ORM\EntityRepository; use Doctrine\ORM\QueryBuilder; +use App\Entity\TaskEntity; class TaskRepository extends EntityRepository { @@ -17,6 +18,14 @@ /** * {@inheritdoc} */ + public function find($id, $lockMode = null, $lockVersion = null): ?TaskEntity + { + return parent::find($id, $lockMode, $lockVersion); + } + + /** + * {@inheritdoc} + */ public function findBy(array $criteria, ?array $orderBy = self::DEFAULT_ORDER, $limit = null, $offset = null) { return parent::findBy($criteria, $orderBy, $limit, $offset); diff --git a/templates/task/task.html.twig b/templates/task/task.html.twig index 8325ae3..98fe9e6 100644 --- a/templates/task/task.html.twig +++ b/templates/task/task.html.twig @@ -13,7 +13,19 @@ {% set returnPath=returnPath|merge([{label: task.activity.name, url: url('activity_activity', {id: task.activity.id}, false), title: 'Editer l\'activité'}]) %} {% endif %} - - {% block pageContent %} +
+
+

Editer

+
+
+
+
+
+

Supprimer

+
+
+ {% include '_includes/html/genericForm.html.twig' with {'form': taskDeleteForm, 'data': {task: task, variant: 'full'}} %} +
+
{% endblock %} \ No newline at end of file