diff --git a/classes/Documento.php b/classes/Documento.php index ff09b60c..c6651ce6 100755 --- a/classes/Documento.php +++ b/classes/Documento.php @@ -1,57 +1,71 @@ -idPessoa=$idPessoa; - $this->imagem=$imagem; - $this->descricao=$descricao; - $this->extensao=$extensao; - } - public function getImagem() - { - return $this->imagem; - } - public function getExtensao() - { - return $this->extensao; - } - public function getDescricao() - { - return $this->descricao; - } - public function getIdPessoa() - { - return $this->idPessoa; - } - public function getIdDocumento() - { - return $this->idDocumento; - } - public function setImagem($imagem) - { - $this->imagem=$imagem; +setIdPessoa($idPessoa); + $this->setImagem($imagem); + $this->setExtensao($extensao); + $this->setDescricao($descricao); + } + public function getImagem() + { + return $this->imagem; + } + public function getExtensao() + { + return $this->extensao; + } + public function getDescricao() + { + return $this->descricao; + } + public function getIdPessoa() + { + return $this->idPessoa; + } + public function getIdDocumento() + { + return $this->idDocumento; + } + public function setImagem(string $imagem) + { + if (empty($imagem)) { + throw new InvalidArgumentException('A imagem de um documento não pode ser vazia.'); } - public function setExtensao($extensao) - { - $this->extensao=$extensao; + $this->imagem = $imagem; + } + public function setExtensao(string $extensao) + { + if (empty($extensao)) { + throw new InvalidArgumentException('A extensão de um documento não pode ser vazia.'); } - public function setDescricao($descricao) - { - $this->descricao=$descricao; + $this->extensao = $extensao; + } + public function setDescricao(string $descricao) + { + if (empty($descricao)) { + throw new InvalidArgumentException('A descrição de um documento não pode ser vazia.'); } - public function setIdPessoa($idPessoa) - { - $this->idPessoa=$idPessoa; + $this->descricao = $descricao; + } + public function setIdPessoa(int $idPessoa) + { + if ($idPessoa < 1) { + throw new InvalidArgumentException('O id de uma pessoa não pode ser menor que 1.'); } - public function setIdDocumento($idDocumento) - { - $this->idDocumento=$idDocumento; + $this->idPessoa = $idPessoa; + } + public function setIdDocumento(int $idDocumento) + { + if ($idDocumento < 1) { + throw new InvalidArgumentException('O id de um documento não pode ser menor que 1.'); } - } -?> \ No newline at end of file + $this->idDocumento = $idDocumento; + } +} diff --git a/controle/DocumentoControle.php b/controle/DocumentoControle.php index b568283d..20e62fba 100755 --- a/controle/DocumentoControle.php +++ b/controle/DocumentoControle.php @@ -1,48 +1,46 @@ -incluir($documento); - } catch (PDOException $e) { - echo $e->getMessage(); - } +incluir($documento); + } catch (PDOException $e) { + echo $e->getMessage(); } - public function alterar() - { - extract($_REQUEST); - $docuDAO=new DocumentoDAO(); - try { - $imagem=file_get_contents($_FILES['doc']['tmp_name']); - $extensao=pathinfo($_FILES['doc']['name'],PATHINFO_EXTENSION); - $documento=new Documento(1,$imagem,$extensao,$descricao); - $documento->setIdDocumento($id_documento); - $docuDAO->alterar($documento); - header('Location: ../controle/control.php?metodo=listarUm&nomeClasse=AtendidoControle&nextPage=../html/atendido/Profile_Atendido.php?id='.$id.'&id='.$id); - } catch (PDOException $e) { - echo $e->getMessage(); - } + } + public function alterar() + { + extract($_REQUEST); + $docuDAO = new DocumentoDAO(); + try { + $imagem = file_get_contents($_FILES['doc']['tmp_name']); + $extensao = pathinfo($_FILES['doc']['name'], PATHINFO_EXTENSION); + $documento = new Documento(1, $imagem, $extensao, $descricao); + $documento->setIdDocumento($id_documento); + $docuDAO->alterar($documento); + header('Location: ../controle/control.php?metodo=listarUm&nomeClasse=AtendidoControle&nextPage=../html/atendido/Profile_Atendido.php?id=' . $id . '&id=' . $id); + } catch (Exception $e) { + echo 'Erro ao tentar alterar documentação: ' . $e->getMessage(); } - public function excluir() - { - extract($_REQUEST); - $docuDAO=new DocumentoDAO(); - try { - $docuDAO->excluir($id_documento); - header('Location: ../controle/control.php?metodo=listarUm&nomeClasse=AtendidoControle&nextPage=../html/atendido/Profile_Atendido.php?id='.$id.'&id='.$id); - } catch (Exception $e) { - echo $e->getMessage(); - } + } + public function excluir() + { + extract($_REQUEST); + $docuDAO = new DocumentoDAO(); + try { + $docuDAO->excluir($id_documento); + header('Location: ../controle/control.php?metodo=listarUm&nomeClasse=AtendidoControle&nextPage=../html/atendido/Profile_Atendido.php?id=' . $id . '&id=' . $id); + } catch (Exception $e) { + echo $e->getMessage(); } } -?> \ No newline at end of file +}