find(TipoCuenta::class)->array(); if ($tipos) { usort($tipos, function($a, $b) { return strcmp($a['descripcion'], $b['descripcion']); }); } $output = [ 'tipos' => $tipos ]; return $this->withJson($response, $output); } public function show(Request $request, Response $response, Factory $factory, $tipo_id): Response { $tipo = $factory->find(TipoCuenta::class)->one($tipo_id); $output = [ 'input' => $tipo_id, 'tipo' => $tipo?->toArray() ]; return $this->withJson($response, $output); } public function add(Request $request, Response $response, Factory $factory): Response { $input = json_decode($request->getBody()); $results = []; if (is_array($input)) { foreach ($input as $in) { $tipo = TipoCuenta::add($factory, $in); $results []= ['tipo' => $tipo?->toArray(), 'agregado' => $tipo?->save()]; } } else { $tipo = TipoCuenta::add($factory, $input); $results []= ['tipo' => $tipo?->toArray(), 'agregado' => $tipo?->save()]; } $output = [ 'input' => $input, 'tipos' => $results ]; return $this->withJson($response, $output); } public function edit(Request $request, Response $response, Factory $factory, $tipo_id): Response { $tipo = $factory->find(TipoCuenta::class)->one($tipo_id); $output = [ 'input' => $tipo_id, 'old' => $tipo->toArray() ]; $input = json_decode($request->getBody()); $tipo->edit($input); $output['tipo'] = $tipo->toArray(); return $this->withJson($response, $output); } public function delete(Request $request, Response $response, Factory $factory, $tipo_id): Response { $tipo = $factory->find(TipoCuenta::class)->one($tipo_id); $output = [ 'input' => $tipo_id, 'tipo' => $tipo->toArray(), 'eliminado' => $tipo->delete() ]; return $this->withJson($response, $output); } }