public function delete($id = null) { $dataPost = $this->request->getJsonRawBody(); foreach ($dataPost->anexos_id as $anexo_id) { $anexo = Anexo::findFirst($anexo_id); unlink($anexo->getCaminho()); $anexo->getProjetoAnexos()->delete(); $anexo->delete(); } return PostResponse::createResponse(true, "Anexos removidos com sucesso"); }
public function checkToken($token) { $m = $this->getDI()->get('memcached'); $data = $m->get($token); if ($m->getResultCode() == \Memcached::RES_NOTFOUND) { throw new \Exception('Login expirado', StatusCodes::NAO_AUTORIZADO); } else { $m->set($token, $data, time() + Settings::LOGIN_EXPIRATION); return PostResponse::createResponse(true, "Login ativo"); } }
public function delete($id) { $cliente = Cliente::findFirst($id); if ($cliente) { if ($cliente->delete()) { return PostResponse::createResponse(PostResponse::STATUS_OK, "Cliente removido com sucesso"); } else { throw new \Exception(PostResponse::createModelErrorMessages($cliente), StatusCodes::ERRO_CLI_CONFLICT); } } else { throw new \Exception("Cliente #{$id} não encontrado", StatusCodes::NAO_ENCONTRADO); } }
public function update($id) { $projeto = Projeto::findFirst($id); if ($projeto) { $projeto->deleteRelated(); $projeto = $this->createProjetoFromJsonRawData($projeto); if ($projeto->validation() && $projeto->save()) { return PostResponse::createResponse(PostResponse::STATUS_OK, "Projeto [#{$projeto->getId()} {$projeto->getNome()}] alterado com sucesso."); } else { throw new \Exception(PostResponse::createModelErrorMessages($projeto), StatusCodes::ERRO_CLI); } } else { throw new \Exception("Projeto #{$id} não encontrado", StatusCodes::NAO_ENCONTRADO); } }
public function createTarefaItens(Tarefa $tarefa, $dataPost) { foreach ($dataPost->add_itens as $postItem) { $item = new TarefaItens(); $item->setDescricao($postItem->descricao); $item->setPorcentagem($postItem->porcentagem); $item->setTitulo($postItem->titulo); $item->setStatus(TarefaItens::STATUS_NAO_CONCLUIDO); $item->setIdTarefa($tarefa->getId()); if (!$item->validation() || !$item->save()) { $this->db->rollback(); throw new \Exception(PostResponse::createModelErrorMessages($item), StatusCodes::ERRO_CLI); } } return true; }