public function CriarUsuario() { if (count($this->erros) > 0) { return false; } else { $v = new Crud(); $v->setTabela('users'); $ok = $v->inserir(array("nome" => $this->nome, "email" => $this->email, "senha" => $this->senha)); //echo_pre($ok); die; if ($ok) { $this->idInserido = $v->ultimoId(); return true; } else { return false; } } }
function avaliar() { $app = Slim::getInstance(); $user = $app->view()->getData('user'); //print_r($_POST);die; $titulo = $_POST['dados']['titulo']; $permalink = $_POST['dados']['permalink']; $data = $_POST['dados']['data']; $nota = $_POST['nota']; //1 - Verifica se a notícia já foi cadastrada $b_noticia = new Crud(); $b_noticia->setTabela("noticias"); $noticia_result = $b_noticia->consultar(array("id"), "permalink = '" . $permalink . "'"); $noticia_result = $noticia_result->fetch(PDO::FETCH_ASSOC); if ($noticia_result == "") { //Se não existir esta notícia cadastrada, cadastra Notícia $add_noticia = new Crud(); $add_noticia->setTabela("noticias"); $add = $add_noticia->inserir(array("titulo" => $titulo, "permalink" => $permalink, "pubDate" => $data)); if ($add) { //Se adicionou com sucesso, retorna ID da notícia adicionada $id_noticia = $add_noticia->ultimoId(); } else { //Se houver erro ao adicionar, retorna erro e encerra o script echo "Erro ao atribuir nota"; exit; } } else { //Se já existir notícia, busca seu ID $id_noticia = $noticia_result['id']; } //2 - Verifica se já deu a nota $b_nota = new Crud(); $b_nota->setTabela("notas"); $nota_result = $b_nota->consultar(array("id"), "id_user = "******" AND id_noticia = " . $id_noticia); $nota_result = $nota_result->fetch(PDO::FETCH_ASSOC); if ($nota_result == "") { //Se não deu nota ainda, dá a nota $add_nota = new Crud(); $add_nota->setTabela("notas"); $nota_add = $add_nota->inserir(array("nota" => $nota, "id_user" => $user['id'], "id_noticia" => $id_noticia)); if (!$nota_add) { //Se não conseguir add a nota, retorna um erro e encerra script echo "Erro ao atribuir nota"; exit; } } else { //Se já deu, então atualiza a nota $atualiza_nota = new Crud(); $atualiza_nota->setTabela("notas"); $up_nota = $atualiza_nota->atualizar(array("nota" => $nota), "id = " . $nota_result['id']); if ($up_nota != 1) { //Se não for possível atualizar a nota, retorna erro echo "Erro ao atribuir nota"; exit; } } $app->redirect(URL_BASE . '/templates/avaliacao.php?permalink=' . base64_encode($permalink) . '&iduser='******'id']); }