Esempio n. 1
0
 /**
  * 
  * Atualiza ou insere os telefones
  * @return void
  */
 private function atualizaTelefones(funcionariosModel $funcionario)
 {
     //excluir
     $telefonesExcluir = array();
     foreach ($funcionario->getTelefones() as $telefones) {
         if ($telefones->getId() != '') {
             array_push($telefonesExcluir, $telefones->getId());
         }
     }
     $cond = '';
     if (!empty($telefonesExcluir)) {
         $telefonesExcluir = implode(',', $telefonesExcluir);
         $this->db->clear();
         $cond = " AND id_telefone not in (" . $telefonesExcluir . ")";
     }
     $sql = "DELETE FROM telefones WHERE id_telefone in( SELECT B.id_telefone FROM telefones_funcionarios AS B WHERE B.id_funcionario = '" . $funcionario->getId() . "' AND id_telefone = B.id_telefone) {$cond}";
     $this->db->query($sql);
     $this->db->clear();
     $this->db->setTabela('telefones');
     foreach ($funcionario->getTelefones() as $telefones) {
         if (!empty($telefones)) {
             $data = array('categoria_telefone' => $telefones->getCategoria(), 'numero_telefone' => $telefones->getNumero(), 'tipo_telefone' => $telefones->getTipo(), 'operadora_telefone' => $telefones->getOperadora());
             if ($telefones->getId() != '') {
                 $this->db->setCondicao('id_telefone = "' . $telefones->getId() . '"');
                 $this->db->update($data);
             } else {
                 $this->db->insert($data);
                 $idTelefone = $this->db->getUltimoId();
                 $idFuncionario = $funcionario->getId();
                 $this->db->query("INSERT INTO telefones_funcionarios VALUES ('{$idFuncionario}','{$idTelefone}')");
             }
             if ($this->db->rowCount() > 0) {
                 $this->nUpdates++;
             }
         }
     }
 }