<?php $app->get('/problemas', 'auth', function () use($app) { $model = new models\Problem(); $problemas = $model->getAll(); $app->render('problems/index.html', ['problemas' => $problemas]); }); $app->get('/problemas/novo', 'auth', function () use($app) { $client = new models\Client(); $clientes = $client->getAll(); $category = new models\Category(); $categorias = $category->getAll('titulo', 'ASC'); $app->render('problems/form.html', ['clientes' => $clientes, 'categorias' => $categorias]); }); $app->post('/problemas/novo', 'auth', function () use($app) { $data = $app->request()->post(); $helpers = new lib\Helpers(); $data['cliente_id'] = $data['cliente_id']; $data['categoria_id'] = $data['categoria_id']; $data['data_hora'] = $helpers->dateTimeDB($data['data'], $data['hora']); unset($data['data']); unset($data['hora']); unset($data['_wysihtml5_mode']); $data['usuario_id'] = $_SESSION['user']['id']; $problem = new models\Problem(); $problem->insert($data); $app->redirect($app->url . '/problemas'); }); $app->post('/problemas/:id/editar', 'auth', function ($id) use($app) { $data = $app->request()->post(); $data['id'] = $id;
$app->get('/categorias/:id/editar', 'auth', function ($id) use($app) { $model = new models\Category(); $categoria = $model->getId($id); $app->render('categories/form.html', ['categoria' => $categoria]); }); $app->post('/categorias/:id/editar', 'auth', function ($id) use($app) { $data = $app->request()->post(); $data['id'] = $id; $category = new models\Category(); $category->update($data); $app->redirect($app->url . '/categorias'); }); $app->get('/categorias/:id/delete', 'auth', function ($id) use($app) { $model = new models\Category(); $model->delete($id); $app->redirect($app->url . '/categorias'); }); $app->get('/categorias/modal/novo', 'auth', function () use($app) { $app->render('categories/modal.html'); }); $app->post('/categorias/modal/novo', 'auth', function () use($app) { $data = $app->request()->post(); $category = new models\Category(); $category->insert($data); }); $app->get('/categorias/select', 'auth', function () use($app) { $model = new models\Category(); $categorias = $model->getAll('titulo', 'ASC'); $last = $model->get(); $app->render('categories/select.html', ['categorias' => $categorias, 'id' => $last[0]['id']]); });