public static function inserir($departamento)
 {
     $departamentoexiste = DepartamentoService::getByNome($departamento->getNome());
     if (is_null($departamentoexiste)) {
         DepartamentoDao::inserir($departamento);
         return 0;
     } else {
         return NULL;
     }
 }
                if ($funcao == "atualizar") {
                    $novonome = $_POST['novonome'];
                    $idcurs = $_POST['idcurs'];
                    $novodept = $_POST['novodept'];
                    $novadura = $_POST['novadura'];
                    $novocred = $_POST['novocred'];
                    $pode = CursoService::getByNome($novonome);
                    if (is_null($pode)) {
                        $cursoatualizar = CursoService::getById($idcurs);
                        $cursoatualizar->setNome($novonome);
                        $cursoatualizar->setDept_id(DepartamentoService::getByNome($novodept)->getId());
                        $cursoatualizar->setDuracao($novadura);
                        $cursoatualizar->setCred_form($novocred);
                        CursoService::alterar($cursoatualizar);
                        $arrayretorno['novonome'] = $cursoatualizar->getNome();
                        $arrayretorno['idcurs'] = $cursoatualizar->getId();
                        $arrayretorno['iddept'] = $cursoatualizar->getDept_id();
                        $arrayretorno['duracao'] = $cursoatualizar->getDuracao();
                        $arrayretorno['creditos'] = $cursoatualizar->getCred_form();
                        $arrayretorno['novodept'] = DepartamentoService::getByNome($novodept)->getNome();
                        $retornoJSON = json_encode($arrayretorno);
                        echo $retornoJSON;
                    } else {
                        $retornoJSON = json_encode(NULL);
                        echo $retornoJSON;
                    }
                }
            }
        }
    }
}
             $idsinstitutos[$i] = $institutos[$i]->getId();
         }
         $arrayretorno['nomesinst'] = $nomesinstitutos;
         $arrayretorno['idsinst'] = $idsinstitutos;
         $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;
         }
     }