public static function inserir($instituto) { if (is_null(InstitutoService::getByNome($instituto->getNome()))) { InstitutoDao::inserir($instituto); return 0; } else { return NULL; } }
$retornoJSON = json_encode($arrayretorno); echo $retornoJSON; } else { $retornoJSON = json_encode(NULL); echo $retornoJSON; } } else { if ($funcao == "atualizar") { $novonome = $_POST['novonome']; $iddept = $_POST['iddept']; $novoinst = $_POST['novoinst']; $pode = DepartamentoService::getByNome($novonome); if (is_null($pode)) { $departamentoatualizar = DepartamentoService::getById($iddept); $departamentoatualizar->setNome($novonome); $departamentoatualizar->setInst_id(InstitutoService::getByNome($novoinst)->getId()); DepartamentoService::alterar($departamentoatualizar); $arrayretorno['novonome'] = $departamentoatualizar->getNome(); $arrayretorno['iddept'] = $departamentoatualizar->getId(); $arrayretorno['novoinst'] = InstitutoService::getByNome($novoinst)->getNome(); $retornoJSON = json_encode($arrayretorno); echo $retornoJSON; } else { $retornoJSON = json_encode(NULL); echo $retornoJSON; } } } } } }
$criou = InstitutoService::inserir($institutocriar); if (!is_null($criou)) { $institutocriado = InstitutoService::getByNome($nomeinst); $arrayretorno['nomeinst'] = $nomeinst; $arrayretorno['idinst'] = $institutocriado->getId(); $retornoJSON = json_encode($arrayretorno); echo $retornoJSON; } else { $retornoJSON = json_encode(NULL); echo $retornoJSON; } } else { if ($funcao == "atualizar") { $novonome = $_POST['novonome']; $idinst = $_POST['idinst']; $pode = InstitutoService::getByNome($novonome); if (is_null($pode)) { $institutoatualizar = InstitutoService::getById($idinst); $institutoatualizar->setNome($novonome); InstitutoService::alterar($institutoatualizar); $arrayretorno['novonome'] = $institutoatualizar->getNome(); $arrayretorno['idinst'] = $institutoatualizar->getId(); $retornoJSON = json_encode($arrayretorno); echo $retornoJSON; } else { $retornoJSON = json_encode(NULL); echo $retornoJSON; } } } }