Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions src/Controller/CursoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -59,19 +59,37 @@ 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
{
$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");
}
}
}
1 change: 1 addition & 0 deletions translations/pt-br.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
21 changes: 20 additions & 1 deletion views/curso/editar.php
Original file line number Diff line number Diff line change
@@ -1 +1,20 @@
<h1>Editar curso</h1>
<section class="row">
<div class="col">
<img src="/assets/img/add_course.svg" width="100%">
</div>
<div class="col">
<form action=<?php echo "/cursos/editar?id={$curso->id}" ?> method="post">
<label for="name"><?= translate('course-name') ?></label>
<input value=<?php echo $curso->name; ?> id="name" type="text" class="form-control mb-3" name="name" placeholder="<?= translate('input-type-here') ?>">


<label for="description"><?= translate('course-description') ?></label>
<input value=<?php echo $curso->description; ?> id="description" type="text" class="form-control mb-3" name="description" placeholder="<?= translate('input-type-here') ?>">


<button type="submit" class="btn btn-outline-success w-100 mt-3">
<?= translate('text-save') ?>
</button>
</form>
</div>
</section>
38 changes: 17 additions & 21 deletions views/curso/listar.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,33 @@
<table class="table table-hover table-striped">
<thead class="table-dark">
<tr>
<th><?=translate('course-name')?></th>
<th><?=translate('course-description')?></th>
<th><?=translate('status')?></th>
<th><?=translate('table-actions')?></th>
<th><?= translate('course-name') ?></th>
<th><?= translate('description') ?></th>
<th><?= translate('table-actions') ?></th>
</tr>
</thead>
<tbody>

<?php
foreach ($cursos ?? [] as $cada) {
$buttonEdit = translate('button-edit');
$buttonDelete = translate('button-delete');
foreach ($cursos ?? [] as $cada) {
$buttonEdit = translate('button-edit');
$buttonDelete = translate('button-delete');

echo "
<tr>
<td>{$cada->name}</td>
<td>{$cada->description}</td>
<td>{$cada->status}</td>
<td>
<a href='' class='btn btn-warning btn-sm'>{$buttonEdit}</a>
<a href='/cursos/excluir?id={$cada->id}' onclick='return confirmDelete()' class='btn btn-danger btn-sm'>{$buttonDelete}</a>
</td>
</tr>
";
}
echo "
<tr>
<td>{$cada->name}</td>
<td>{$cada->description}</td>
<td>
<a href='/cursos/editar?id={$cada->id}' class='btn btn-warning btn-sm'>{$buttonEdit}</a>
<a href='' class='btn btn-danger btn-sm'>{$buttonDelete}</a>
</td>
</tr>
";
}
?>
</tbody>
</table>
<script>
function confirmDelete() {
return confirm("Tem certeza que deseja excluir este curso?");
}

</script>