/** * Metodo que faz o cadastro dos idiomas do candidato * @param Candidato $candidato */ public function insert(Candidato $candidato) { if (!$candidato->getId()) { throw new BTAlentoException("O candidato informado é inválido"); } if (count($candidato->getIdiomas())) { $query = "insert into {$this->tg->getTabela()}"; $query .= "(idioma_nome, idioma_nivel, idioma_instituicao, "; $query .= "idioma_pais, idioma_pk_candidato)"; $query .= " values "; foreach ($candidato->getIdiomas() as $idioma) { $idioma = new Idioma(); $query .= "({$idioma->getNome()}, {$idioma->getNivel()}, "; $query .= "{$idioma->getInstituicao()}, {$idioma->getIntercambioPais()}, "; $query .= "{$candidato->getId()}),"; } $queryInsert = substr($query, 0, -1); $prepare = $this->tg->getPDO()->prepare($queryInsert); if (!$prepare->execute()) { $sqlCandidato = new SqlCandidato(); $sqlCandidato->delete($candidato); throw new BTAlentoException("Ocorreu um erro ao tentar cadastrar o currículo." . "Tente novamente mais tarde"); } } }
/** * Metodo que retorna um candidato para os metodos de cadastro e edição. * * @param bool $isEdit Define se o metodo será usado para inclusão ou edição * * @return Candidato Um candidato com os cósidogs preenchidos */ private function getCandidato($isEdit = false) { $INT = FILTER_VALIDATE_INT; $STR = FILTER_SANITIZE_MAGIC_QUOTES; $endereco = new Endereco(); $area = new AreaInteresse(); $rg = new Rg(); $cpf = new Cpf(); $telefone = new TelFixo(); $celular = new TelCelular(); $dtNascim = new Date(); // $candidato = new Candidato(); $candidato->setNome(filter_input(INPUT_POST, 'nome', $STR)); $dtNascim->setDateBr(filter_input(INPUT_POST, 'data_nascimento', $STR)); $candidato->setDtNascimento($dtNascim); $candidato->setEstadoCivil(filter_input(INPUT_POST, 'estado_civil', $STR)); $candidato->setSexo(filter_input(INPUT_POST, 'sexo', $STR)); $rg->setNumero(filter_input(INPUT_POST, 'rg', $STR)); $rg->setOrgaoExpedidor(filter_input(INPUT_POST, 'rg_orgao', $STR)); $rg->setOrgaoUf(filter_input(INPUT_POST, 'rg_orgaoUf', $STR)); $candidato->setRg($rg); $cpf->setNumero(filter_input(INPUT_POST, 'cpf', $STR)); $candidato->setCpf($cpf); $candidato->setEmail(filter_input(INPUT_POST, 'email', $STR)); $telefone->setValue(filter_input(INPUT_POST, 'telefone', $STR)); $candidato->setTelefone($telefone); $celular->setValue(filter_input(INPUT_POST, 'celular', $STR)); $candidato->setCelular($celular); // $endereco->setCep(filter_input(INPUT_POST, 'cep', $STR)); $endereco->setLogradoro(filter_input(INPUT_POST, 'logradouro', $STR)); $endereco->setBairro(filter_input(INPUT_POST, 'bairro', $STR)); $endereco->setCidade(filter_input(INPUT_POST, 'cidade', $STR)); $endereco->setUf(filter_input(INPUT_POST, 'uf', $STR)); // $candidato->setTipoCurriculo(filter_input(INPUT_POST, 'tipo_curriculo', $INT)); $candidato->setEndereco($endereco); $candidato->setObservacoes(filter_input(INPUT_POST, 'observacoes', $STR)); $area->setId(filter_input(INPUT_POST, 'area_interesse', $INT)); $candidato->setAreaDeInteresse($area); $candidato->setObjetivoProfissional(filter_input(INPUT_POST, 'obetivo', $STR)); $candidato->setSenha(filter_input(INPUT_POST, 'senha1')); $senha2 = filter_input(INPUT_POST, 'senha2'); if ($candidato->getSenha() != md5($senha2)) { throw new BTAlentoException('As senha não conferem'); } //Preenchendo os arrays $exp = Arrays::retArray($_POST, 'exp_tipo'); $for = Arrays::retArray($_POST, 'form_tipo'); $cur = Arrays::retArray($_POST, 'curso_nome'); $idi = Arrays::retArray($_POST, 'idioma_nome'); for ($index = 0; $index < count($exp); ++$index) { $tmp = new ExpProficional(); $tmpPeriodo = new Periodo(); $tmp->setTipo($_POST['exp_tipo'][$index]); $tmp->setNome($_POST['exp_empresa'][$index]); $tmp->setCargo($_POST['exp_cargo'][$index]); $tmpPeriodo->setDeBr($_POST['exp_dt_entrada'][$index]); $tmpPeriodo->setAteBr($_POST['exp_dt_saida'][$index]); $tmp->setPeriodo($tmpPeriodo); $tmp->setAtividades($_POST['exp_atividades'][$index]); $candidato->appendExpProfissional($tmp); } for ($index = 0; $index < count($for); ++$index) { $tmp = new FormAcademica(); $tmp->setTipo($_POST['form_tipo'][$index]); $tmp->setInstituicao($_POST['form_instituicao'][$index]); $tmp->setCurso($_POST['form_curso'][$index]); $tmp->setStatus($_POST['form_status'][$index]); $tmp->setPeriodoAtual((int) $_POST['form_periodo'][$index]); $candidato->appendFormacao($tmp); } for ($index = 0; $index < count($cur); ++$index) { $tmp = new CursoComplementar(); $tmp->setConhecimento($_POST['curso_nome'][$index]); $tmp->setInstituicao($_POST['curso_instituicao'][$index]); $candidato->appendCursosCompl($tmp); } for ($index = 0; $index < count($idi); ++$index) { $tmp = new Idioma(); $tmp->setNivel($_POST['idioma_nivel'][$index]); $tmp->setNome($_POST['idioma_nome'][$index]); $tmp->setInstituicao($_POST['idioma_inistituicao'][$index]); $tmp->setIntercambioPais($_POST['idioma_intercambio'][$index]); $candidato->appendIdioma($tmp); } //Fazendo o tratametno especifico para edição if (isset($_FILES['candidato-foto'])) { $candidato->setFoto($_FILES['candidato-foto']); } return $candidato; }