Ejemplo n.º 1
0
	public function recuperarTipoPergunta($id_tipo_pergunta){

		$query ="SELECT tipo_pergunta        AS tipo_pergunta,
						descricao            AS descricao,
						qtde_respostas       AS qtde_respostas,
						imagem               AS imagem
				FROM tbl_tipo_pergunta
				WHERE tipo_pergunta = $id_tipo_pergunta ";

		$banco = $this->getBancoDados(); 
		$tipo_pergunta = NULL; 
		$retorno = $banco->executaSQL($query); 
		if($retorno != NULL) {

			if ($banco->numRows($retorno) == 0){
				throw new Exception("Nenhuma tipo_pergunta encontrado.",0);
			}

			while($linha = $banco->fetchArray($retorno)) { 
				$tipo_pergunta = new TipoPergunta(); 
				$tipo_pergunta->setId($linha['tipo_pergunta']);
				$tipo_pergunta->setDescricao($linha["descricao"]);
				$tipo_pergunta->setQtdeRespostas($linha["qtde_respostas"]);
				$tipo_pergunta->setImagem($linha["imagem"]);
			}
			return $tipo_pergunta; 
		} else {
			throw new Exception("Erro ao recuperar TipoPergunta ($query)"); 
		}
	}
Ejemplo n.º 2
0
function Main()
{
    $codigo = base64_decode($_POST['txtCodigo']);
    $txt = urldecode($_POST['txtDescricao']);
    $clsAtual = $_POST['selClasse'];
    $nivAtual = $_POST['selNivel'];
    $tipAtual = $_POST['selTipo'];
    $ativo = $_POST['selAtivo'];
    $expGeral = urldecode($_POST['txtExplicacaoGeral']);
    if (trim($codigo) == "") {
        $codigo = null;
    } else {
        if (!is_numeric($codigo)) {
            echo Comuns::Idioma("@lng[Código informado não é válido]");
        }
    }
    $p = new Pergunta();
    if (!is_null($codigo)) {
        $p->setCodigo($codigo);
    }
    $p->setTexto($txt);
    $p->setClasse($clsAtual);
    $p->setNivel($nivAtual);
    $p->setTipo(TipoPergunta::RetornaTipo($tipAtual));
    $p->setAtivo($ativo);
    if ($expGeral != "") {
        $p->setTextoExplicacaoGeral($expGeral);
    }
    if ($p->getCodigo() === 0) {
        if ($p->AdicionaPergunta() === true) {
            $_SESSION['perg'] = $p->getCodigo();
            echo "OK";
        } else {
            $_SESSION['perg'] = 0;
            echo Comuns::Idioma("@lng[Erro ao adicionar a pergunta:]");
        }
    } else {
        if ($p->AtualizaPergunta() === true) {
            $_SESSION['perg'] = $p->getCodigo();
            echo "OK";
        } else {
            $erros = "@lng[Erros ocorreram.]";
            foreach ($p->msg_erro as $err) {
                $erros .= "<br />" . $err;
            }
            echo Comuns::Idioma($erros);
        }
    }
}
Ejemplo n.º 3
0
 public static function RetornaTipo($codigo)
 {
     $sql = "SELECT Codigo, Descricao ";
     $sql .= "FROM mestipopergunta WHERE Codigo = :pCod;";
     $cnn = Conexao2::getInstance();
     $rs = $cnn->prepare($sql);
     $rs->bindParam(":pCod", $codigo, PDO::PARAM_INT);
     $rs->execute();
     $t = new TipoPergunta();
     while ($tip = $rs->fetch(PDO::FETCH_OBJ)) {
         $t->setCodigo($tip->Codigo);
         $t->setDescricao($tip->Descricao);
     }
     return $t;
 }
Ejemplo n.º 4
0
 public function Carregar($codigo)
 {
     if (!isset($codigo)) {
         throw new Exception("@lng[Código inválido]", 05);
     }
     $this->codigo = $codigo;
     $sql = "select p.Codigo, p.CodClass, p.CodUsuario, p.Ativo, p.CodNivel, p.CodTipo, p.ExplicacaoGeral, pt.Linha, pt.Texto ";
     $sql .= "from mespergunta p inner join mesperguntatexto pt on pt.codpergunta = p.codigo ";
     $sql .= "where p.Codigo = :codigo;";
     $cnn = Conexao2::getInstance();
     $q = $cnn->prepare($sql);
     $q->bindParam(":codigo", $this->codigo, PDO::PARAM_INT);
     $q->execute();
     if ($q->errorCode() == Comuns::QUERY_OK) {
         if ($q->rowCount() > 0) {
             $cont = 1;
             while ($perg = $q->fetch(PDO::FETCH_OBJ)) {
                 if ($cont == 1) {
                     $this->ativo = $perg->Ativo;
                     $this->nivel = $perg->CodNivel;
                     $this->tipo = TipoPergunta::RetornaTipo($perg->CodTipo);
                     $this->classe = $perg->CodClass;
                     $this->usuario = $perg->CodUsuario;
                     $this->expgeral = $perg->ExplicacaoGeral;
                 }
                 $this->texto .= $perg->Texto;
                 $cont++;
             }
             $this->CarregarAlternativas();
             return true;
         } else {
             $this->msg_erro = "@lng[Nenhum registro encontrado]";
             return false;
         }
     } else {
         $msg = $q->errorInfo();
         $this->msg_erro = $msg[2];
         return false;
     }
 }
Ejemplo n.º 5
0
	function gravarTipoPergunta(TipoPergunta $tipo_pergunta){

		if (strlen($tipo_pergunta->getDescricao())==0){
			throw new Exception('Informe a descricao!');
		}else{
			$tipo_pergunta->Xdescricao = $tipo_pergunta->getDescricao();
		}

		if (strlen($tipo_pergunta->getQtdeRespostas())==0){
			$tipo_pergunta->Xdescricao = 1;
		}else{
			$tipo_pergunta->Xdescricao = $tipo_pergunta->getDescricao();
		}

		if (strlen($tipo_pergunta->getImagem())==0){
			$tipo_pergunta->Ximagem = " NULL ";
		}else{
			$tipo_pergunta->Ximagem = $tipo_pergunta->getImagem();
		}

		$tipoPerguntaDAO = new TipoPerguntaDAO(); 
		$tipoPerguntaDAO->setBancoDados($this->banco); 
		$tipoPerguntaDAO->gravaDadosTipoPergunta($tipo_pergunta); 
	}