diff --git a/src/Controller/CursoController.php b/src/Controller/CursoController.php index 2199b62..b491e82 100644 --- a/src/Controller/CursoController.php +++ b/src/Controller/CursoController.php @@ -37,7 +37,7 @@ public function add(): void $errors = $this->validator->validateRequest(); - if (false === empty($errors)) { + if (false === empty($errors)) { $_SESSION['errors'] = $errors; parent::render('curso/add'); @@ -59,7 +59,25 @@ public function add(): void public function editar(): void { - echo "Editar"; + + $id = $_GET['id']; + + if (true === empty($_POST)) { + $curso = $this->entityManager->find(Curso::class, $id); + parent::render('curso/editar', [ + 'curso' => $curso, + ]); + return; + } + + $curso = $this->entityManager->find(Curso::class, $id); + $curso->name = $_POST['name']; + $curso->description = $_POST['description']; + + $this->entityManager->persist($curso); + $this->entityManager->flush(); + + parent::redirect('/cursos/listar'); } public function excluir(): void @@ -67,11 +85,11 @@ public function excluir(): void $id = $_GET['id']; $curso = $this->entityManager->find(Curso::class, $id); - if($curso !== null) { + if ($curso !== null) { $this->entityManager->remove($curso); $this->entityManager->flush(); } parent::redirect("/cursos/listar"); } -} \ No newline at end of file +} diff --git a/translations/pt-br.php b/translations/pt-br.php index 6e40661..47508b6 100644 --- a/translations/pt-br.php +++ b/translations/pt-br.php @@ -11,6 +11,7 @@ 'button-delete' => 'Excluir', 'page-title' => 'Inicio', 'text-confirm' => 'Pronto', + 'text-save' => 'Salvar', 'input-type-here' => 'Digite aqui', 'new-course' => 'Novo Curso', 'course-description' => 'Descrição', diff --git a/views/curso/editar.php b/views/curso/editar.php index 4867877..83503b2 100644 --- a/views/curso/editar.php +++ b/views/curso/editar.php @@ -1 +1,20 @@ -

Editar curso

\ No newline at end of file +
+
+ +
+
+
id}" ?> method="post"> + + name; ?> id="name" type="text" class="form-control mb-3" name="name" placeholder=""> + + + + description; ?> id="description" type="text" class="form-control mb-3" name="description" placeholder=""> + + + +
+
+
\ No newline at end of file diff --git a/views/curso/listar.php b/views/curso/listar.php index e774d99..24381d4 100644 --- a/views/curso/listar.php +++ b/views/curso/listar.php @@ -5,31 +5,28 @@ - - - - + + + - - - - - - - "; - } + echo " + + + + + + "; + } ?>
{$cada->name}{$cada->description}{$cada->status} - {$buttonEdit} - {$buttonDelete} -
{$cada->name}{$cada->description} + {$buttonEdit} + {$buttonDelete} +
@@ -37,5 +34,4 @@ function confirmDelete() { return confirm("Tem certeza que deseja excluir este curso?"); } - \ No newline at end of file