diff --git a/.gitignore b/.gitignore index 48b8bf9..9f33dd5 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ vendor/ +.idea/ \ No newline at end of file diff --git a/config/routes.php b/config/routes.php index e6bfc38..78ad26e 100644 --- a/config/routes.php +++ b/config/routes.php @@ -21,5 +21,5 @@ '/cursos/editar' => [CursoController::class, 'editar'], '/cursos/excluir' => [CursoController::class, 'excluir'], '/alunos/listar' => [AlunoController::class, 'listar'], - '/api/cursos' => [CursoApiController::class, 'listar'], -]; \ No newline at end of file + '/alunos/editar' => [AlunoController::class, 'editar'], +]; diff --git a/public/assets/img/edit_student.png b/public/assets/img/edit_student.png new file mode 100644 index 0000000..b724250 Binary files /dev/null and b/public/assets/img/edit_student.png differ diff --git a/src/Controller/AlunoController.php b/src/Controller/AlunoController.php index 4b11f1c..1ddd0fc 100644 --- a/src/Controller/AlunoController.php +++ b/src/Controller/AlunoController.php @@ -6,15 +6,44 @@ use App\Entity\Aluno; - final class AlunoController extends AbstractController { + public mixed $entityManager; + + public function __construct() + { + $this->entityManager = parent::entityManager(); + } + public function listar(): void { - $entityManager = parent::entityManager(); - $repository = $entityManager->getRepository(Aluno::class); + $repository = $this->entityManager->getRepository(Aluno::class); + + parent::render('alunos/listar', [ + 'alunos' => $repository->findAll(), + ]); + } + + public function editar(): void + { + if (true === empty($_POST)) { + parent::render('alunos/editar'); + return; + } + + $repository = $this->entityManager->getRepository(Aluno::class); + $aluno = $repository->findOneBy(['registry' => $_POST['registry']]); + + $aluno->name = $_POST['name']; + $aluno->cpf = $_POST['cpf']; + $aluno->email = $_POST['email']; + $aluno->created_at = new \DateTime($_POST['created_at']); + + //INSERT INTO + $this->entityManager->persist($aluno); + $this->entityManager->flush(); parent::render('alunos/listar', [ 'alunos' => $repository->findAll(), diff --git a/translations/pt-br.php b/translations/pt-br.php index 6e40661..4072333 100644 --- a/translations/pt-br.php +++ b/translations/pt-br.php @@ -15,6 +15,7 @@ 'new-course' => 'Novo Curso', 'course-description' => 'Descrição', 'status' => "Status", + 'student-id' => 'Matricula', 'student-name' => 'Nome', 'student-registry' => 'Matrícula', 'student-cpf' => 'CPF', diff --git a/views/alunos/editar.php b/views/alunos/editar.php new file mode 100644 index 0000000..1c4a7cc --- /dev/null +++ b/views/alunos/editar.php @@ -0,0 +1,56 @@ +
+
+ +
+
+
+ + + + + + + + + + + + + + + +
+
+
\ No newline at end of file diff --git a/views/alunos/listar.php b/views/alunos/listar.php index b969822..2c9d9ba 100644 --- a/views/alunos/listar.php +++ b/views/alunos/listar.php @@ -23,7 +23,7 @@ {$aluno->email} {$aluno->created_at->format('d/m/Y')} - {$buttonEdit} + {$buttonEdit} {$buttonDelete}