From 813e4675e9638395785a18848720b2ee2333df92 Mon Sep 17 00:00:00 2001 From: David Amorim Date: Thu, 11 Apr 2024 20:56:22 -0300 Subject: [PATCH 1/3] =?UTF-8?q?(Update=20Curso)=3D>=20Tela=20de=20cria?= =?UTF-8?q?=C3=A7=C3=A3o=20de=20curso=20e=20edi=C3=A7=C3=A3o=20de=20nome?= =?UTF-8?q?=20e=20descri=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Controller/CursoController.php | 28 ++++++++++++++++++++-- translations/pt-br.php | 1 + views/curso/editar.php | 38 +++++++++++++++++++++++++++++- views/curso/listar.php | 36 +++++++++++++++------------- 4 files changed, 83 insertions(+), 20 deletions(-) diff --git a/src/Controller/CursoController.php b/src/Controller/CursoController.php index e677e09..0096db8 100644 --- a/src/Controller/CursoController.php +++ b/src/Controller/CursoController.php @@ -58,10 +58,34 @@ public function add(): void } public function editar(): void - { - echo "Editar"; +{ + + $id = $_GET['id']; + $entityManager = require_once dirname(__DIR__, 2).'/bootstrap.php'; + + if (true === empty($_POST)) { + $curso = $entityManager->find(Curso::class, $id); + parent::render('curso/editar', [ + 'curso' => $curso, + ]); + return; } + $curso = $entityManager->find(Curso::class, $id); + $curso->name = $_POST['name']; + $curso->description = $_POST['description']; + + $entityManager->persist($curso); + $entityManager->flush(); + + header('location: /cursos/listar'); + + + + + +} + public function excluir(): void { echo "Excluir"; diff --git a/translations/pt-br.php b/translations/pt-br.php index d0d3a34..57ba42f 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', ]; diff --git a/views/curso/editar.php b/views/curso/editar.php index 4867877..ca44e2f 100644 --- a/views/curso/editar.php +++ b/views/curso/editar.php @@ -1 +1,37 @@ -

Editar curso

\ No newline at end of file +
+
+ +
+
+
id}"?> method="post"> + + name;?> + id="name" + type="text" + class="form-control mb-3" + name="name" + placeholder="" + > + id; + ?> + + + + 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 6e872b3..6e5011a 100644 --- a/views/curso/listar.php +++ b/views/curso/listar.php @@ -2,27 +2,29 @@ - + - - {$cada->name} - {$cada->description} - - {$buttonEdit} - {$buttonDelete} - - - "; - } - ?> + if (is_object($cada) && property_exists($cada, 'description')) { + echo " + + {$cada->name} + {$cada->description} + + {$buttonEdit} + {$buttonDelete} + + + "; + } + } +?> From defef1d80cea2f74e7ec67e6121793ac59f2cc85 Mon Sep 17 00:00:00 2001 From: David Amorim Date: Fri, 12 Apr 2024 20:16:26 -0300 Subject: [PATCH 2/3] =?UTF-8?q?(CursoCOntroller)=3D>=20Ajuste=20de=20ident?= =?UTF-8?q?a=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Controller/CursoController.php | 43 +++++++++++++----------------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/src/Controller/CursoController.php b/src/Controller/CursoController.php index f235a01..b99046e 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'); @@ -58,43 +58,38 @@ public function add(): void } public function editar(): void -{ - - $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(); + $id = $_GET['id']; - header('location: /cursos/listar'); + 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(); - -} + header('location: /cursos/listar'); + } 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(); } header('location: /cursos/listar'); } -} \ No newline at end of file +} From e790688096cfa46679120ef5240055efd8f827e2 Mon Sep 17 00:00:00 2001 From: David Amorim Date: Fri, 12 Apr 2024 20:30:24 -0300 Subject: [PATCH 3/3] =?UTF-8?q?(Listar,=20Editar)=20=3D>=20Retirada=20do?= =?UTF-8?q?=20if=20desnecessario=20e=20identa=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- views/curso/editar.php | 33 ++++++++------------------------- views/curso/listar.php | 19 ++++++++----------- 2 files changed, 16 insertions(+), 36 deletions(-) diff --git a/views/curso/editar.php b/views/curso/editar.php index ca44e2f..83503b2 100644 --- a/views/curso/editar.php +++ b/views/curso/editar.php @@ -3,34 +3,17 @@
-
id}"?> method="post"> - - name;?> - id="name" - type="text" - class="form-control mb-3" - name="name" - placeholder="" - > - id; - ?> - + 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=""> - - description;?> - id="description" - type="text" - class="form-control mb-3" - name="description" - placeholder="" - > -
diff --git a/views/curso/listar.php b/views/curso/listar.php index 6e59c11..24381d4 100644 --- a/views/curso/listar.php +++ b/views/curso/listar.php @@ -5,18 +5,17 @@ - - - + + + - @@ -28,13 +27,11 @@ "; } - } -?> + ?>
{$cada->name}
\ No newline at end of file