Skip to content
Snippets Groups Projects
Commit 3a5df7e4 authored by andres's avatar andres
Browse files

Valoraciones propias con media y autor propio a perfil

parent ac510ba1
No related branches found
No related tags found
No related merge requests found
......@@ -59,7 +59,28 @@ public class valoracionesComentarioDB {
}
public static int getValoracionUsuarioComentario(String usuario, int idComentario){
ConnectionPool pool = ConnectionPool.getInstance();
Connection connection = pool.getConnection();
ResultSet rs = null;
int puntuacion = -1;
String consulta ="SELECT puntuacion FROM ValoracionesComentario WHERE comentario = ? AND usuario = ?";
try{
PreparedStatement ps = connection.prepareStatement(consulta);
ps.setInt(1, idComentario);
ps.setString(2, usuario);
rs = ps.executeQuery();
while(rs.next()){
puntuacion = rs.getInt("puntuacion");
}
rs.close();
ps.close();
pool.freeConnection(connection);
return puntuacion;
}catch (SQLException e){
return -1;
}
}
public static double valoracionMediaComentario(int comentario){
......
......@@ -62,8 +62,29 @@ public class valoracionesNookDB {
}
public static int getValoracionUsuarioNook(String usuario, int idNook){
ConnectionPool pool = ConnectionPool.getInstance();
Connection connection = pool.getConnection();
ResultSet rs = null;
int puntuacion = -1;
String consulta ="SELECT puntuacion FROM ValoracionesNook WHERE nook = ? AND usuario = ?";
try{
PreparedStatement ps = connection.prepareStatement(consulta);
ps.setInt(1, idNook);
ps.setString(2, usuario);
rs = ps.executeQuery();
while(rs.next()){
puntuacion = rs.getInt(1);
}
rs.close();
ps.close();
pool.freeConnection(connection);
return puntuacion;
}catch (SQLException e){
e.printStackTrace();
return -1;
}
}
public static double valoracionMediaNook(int idNook){
ConnectionPool pool = ConnectionPool.getInstance();
......
......@@ -8,6 +8,7 @@ package servlet;
import conexionDB.clasificacionCategoriasDB;
import conexionDB.nookDB;
import conexionDB.usuarioDB;
import conexionDB.valoracionesNookDB;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
......@@ -17,6 +18,7 @@ import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import modelo.Nook;
import modelo.Usuario;
......@@ -40,6 +42,7 @@ public class autorSV extends HttpServlet {
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
HttpSession session = request.getSession(false);
String nombre = request.getParameter("nombre");
Usuario usuario = usuarioDB.getUsuario(nombre);
......@@ -48,10 +51,12 @@ public class autorSV extends HttpServlet {
ArrayList<String> categoriasNook;
ArrayList<String> categorias = new ArrayList<>();
ArrayList<Nook> nooks= nookDB.getNooksUsuario(nombre);
ArrayList<Integer> valoracionesNook = new ArrayList<>();
for(int i=0; i < nooks.size(); i++){
str = new StringBuilder();
categoriasNook = clasificacionCategoriasDB.getCategoriasNook(nooks.get(i).getIdNook());
valoracionesNook.add(valoracionesNookDB.getValoracionUsuarioNook((String) session.getAttribute("usuario"), nooks.get(i).getIdNook()));
for(int j = 0; j < categoriasNook.size(); j++ ){
str.append(categoriasNook.get(j));
str.append(',');
......@@ -67,6 +72,8 @@ public class autorSV extends HttpServlet {
request.setAttribute("autor",usuario);
request.setAttribute("nooksCategorias", categorias);
request.setAttribute("nooks", nooks);
request.setAttribute("valoraciones", valoracionesNook);
String url = "/autor.jsp";
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(url);
......
......@@ -72,7 +72,7 @@ public class crearComentarioSV extends HttpServlet {
request.setAttribute("nook", nook);
request.setAttribute("comentarios",comentarios);
String url = "/paginaNook.jsp";
String url = request.getParameter("url");
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(url);
dispatcher.forward(request, response);
......
......@@ -7,6 +7,7 @@ package servlet;
import conexionDB.clasificacionCategoriasDB;
import conexionDB.nookDB;
import conexionDB.valoracionesNookDB;
import java.io.IOException;
import java.util.ArrayList;
import javax.servlet.RequestDispatcher;
......@@ -48,10 +49,12 @@ public class misNooksSV extends HttpServlet {
ArrayList<String> categoriasNook;
ArrayList<String> categorias = new ArrayList<>();
ArrayList<Nook> nooks= nookDB.getNooksUsuario(nombre);
ArrayList<Integer> valoracionesNook = new ArrayList<>();
for(int i=0; i < nooks.size(); i++){
str = new StringBuilder();
categoriasNook = clasificacionCategoriasDB.getCategoriasNook(nooks.get(i).getIdNook());
valoracionesNook.add(valoracionesNookDB.getValoracionUsuarioNook(nombre, nooks.get(i).getIdNook()));
for(int j = 0; j < categoriasNook.size(); j++ ){
str.append(categoriasNook.get(j));
str.append(',');
......@@ -66,6 +69,7 @@ public class misNooksSV extends HttpServlet {
request.setAttribute("misNooksCategorias", categorias);
request.setAttribute("misNooks", nooks);
request.setAttribute("valoraciones", valoracionesNook);
String url = "/misNooks.jsp";
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(url);
......
......@@ -7,6 +7,8 @@ package servlet;
import conexionDB.comentarioDB;
import conexionDB.nookDB;
import conexionDB.valoracionesComentarioDB;
import conexionDB.valoracionesNookDB;
import java.io.IOException;
import java.sql.Date;
import java.util.ArrayList;
......@@ -40,16 +42,21 @@ public class nookSV extends HttpServlet {
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
HttpSession session = request.getSession(false);
int idNook = Integer.parseInt(request.getParameter("idNook"));
Nook nook = nookDB.getNook(idNook);
int valoracion = valoracionesNookDB.getValoracionUsuarioNook((String) session.getAttribute("usuario"), idNook);
ArrayList<Comentario> comentarios=comentarioDB.getComentariosNook(idNook);
ArrayList<Integer> cValoraciones = new ArrayList();
for(int i=0; i<comentarios.size(); i++){
cValoraciones.add(valoracionesComentarioDB.getValoracionUsuarioComentario((String) session.getAttribute("usuario"), comentarios.get(i).getIdComentario()));
}
request.setAttribute("nook", nook);
request.setAttribute("comentarios",comentarios);
request.setAttribute("valoracion", valoracion);
request.setAttribute("cValoraciones", cValoraciones);
String url = "/paginaNook.jsp";
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(url);
......
......@@ -75,10 +75,6 @@ public class valorarNookSV extends HttpServlet {
dispatcher.forward(request, response);
}
private static void actualizarMedia(int idNook){
}
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP <code>GET</code> method.
......
......@@ -57,8 +57,8 @@ and open the template in the editor.
<%
ArrayList<Nook> nooks = (ArrayList<Nook>) request.getAttribute("nooks");
ArrayList<String> nooksCategorias = (ArrayList<String>) request.getAttribute("nooksCategorias");
ArrayList<Integer> valoraciones = (ArrayList<Integer>) request.getAttribute("valoraciones");
for(int i = 0; i < nooks.size(); i++){
double valoracion = Math.round(nooks.get(i).getValoracionMedia());
%>
<div class="nook_n">
......@@ -79,17 +79,18 @@ and open the template in the editor.
<div class="star1">
<form class="valoracion" method="post" action="/valorarNookSV?idNook=<%=nooks.get(i).getIdNook()%>&urlPagina=/autorSV?nombre=<%=autor%>">
<p class="clasificacion">
<input id="<%=nooks.get(i).getIdNook()%>,5" type="radio" name="estrellas<%=nooks.get(i).getIdNook()%>" value="5" onclick="this.form.submit();" <%if(valoracion==5){%> checked <%}%> >
<input id="<%=nooks.get(i).getIdNook()%>,5" type="radio" name="estrellas<%=nooks.get(i).getIdNook()%>" value="5" onclick="this.form.submit();" <%if(valoraciones.get(i)==5){%> checked <%}%> >
<label for="<%=nooks.get(i).getIdNook()%>,5">&#9733;</label>
<input id="<%=nooks.get(i).getIdNook()%>,4" type="radio" name="estrellas<%=nooks.get(i).getIdNook()%>" value="4" onclick="this.form.submit();" <%if(valoracion==4){%> checked <%}%> >
<input id="<%=nooks.get(i).getIdNook()%>,4" type="radio" name="estrellas<%=nooks.get(i).getIdNook()%>" value="4" onclick="this.form.submit();" <%if(valoraciones.get(i)==4){%> checked <%}%> >
<label for="<%=nooks.get(i).getIdNook()%>,4">&#9733;</label>
<input id="<%=nooks.get(i).getIdNook()%>,3" type="radio" name="estrellas<%=nooks.get(i).getIdNook()%>" value="3" onclick="this.form.submit();" <%if(valoracion==3){%> checked <%}%> >
<input id="<%=nooks.get(i).getIdNook()%>,3" type="radio" name="estrellas<%=nooks.get(i).getIdNook()%>" value="3" onclick="this.form.submit();" <%if(valoraciones.get(i)==3){%> checked <%}%> >
<label for="<%=nooks.get(i).getIdNook()%>,3">&#9733;</label>
<input id="<%=nooks.get(i).getIdNook()%>,2" type="radio" name="estrellas<%=nooks.get(i).getIdNook()%>" value="2" onclick="this.form.submit();" <%if(valoracion==2){%> checked <%}%> >
<input id="<%=nooks.get(i).getIdNook()%>,2" type="radio" name="estrellas<%=nooks.get(i).getIdNook()%>" value="2" onclick="this.form.submit();" <%if(valoraciones.get(i)==2){%> checked <%}%> >
<label for="<%=nooks.get(i).getIdNook()%>,2">&#9733;</label>
<input id="<%=nooks.get(i).getIdNook()%>,1" type="radio" name="estrellas<%=nooks.get(i).getIdNook()%>" value="1" onclick="this.form.submit();" <%if(valoracion==1){%> checked <%}%> >
<input id="<%=nooks.get(i).getIdNook()%>,1" type="radio" name="estrellas<%=nooks.get(i).getIdNook()%>" value="1" onclick="this.form.submit();" <%if(valoraciones.get(i)==1){%> checked <%}%> >
<label for="<%=nooks.get(i).getIdNook()%>,1">&#9733;</label>
</p>
<p class="vMedia"><%=nooks.get(i).getValoracionMedia()%></p>
</form>
</div>
</div>
......
......@@ -53,8 +53,8 @@ and open the template in the editor.
<%
ArrayList<Nook> misNooks = (ArrayList<Nook>) request.getAttribute("misNooks");
ArrayList<String> misNooksCategorias = (ArrayList<String>) request.getAttribute("misNooksCategorias");
ArrayList<Integer> valoraciones = (ArrayList<Integer>) request.getAttribute("valoraciones");
for(int i = 0; i < misNooks.size(); i++){
double valoracion = Math.round(misNooks.get(i).getValoracionMedia());
%>
<div class="nook_n">
<div class="nook_n_img">
......@@ -72,17 +72,18 @@ and open the template in the editor.
<div class="star">
<form class="valoracion" method="post" action="/valorarNookSV?idNook=<%=misNooks.get(i).getIdNook()%>&urlPagina=/misNooksSV">
<p class="clasificacion">
<input id="<%=misNooks.get(i).getIdNook()%>,5" type="radio" name="estrellas<%=misNooks.get(i).getIdNook()%>" value="5" onclick="this.form.submit();" <%if(valoracion==5){%> checked <%}%> >
<input id="<%=misNooks.get(i).getIdNook()%>,5" type="radio" name="estrellas<%=misNooks.get(i).getIdNook()%>" value="5" onclick="this.form.submit();" <%if(valoraciones.get(i)==5){%> checked <%}%> >
<label for="<%=misNooks.get(i).getIdNook()%>,5">&#9733;</label>
<input id="<%=misNooks.get(i).getIdNook()%>,4" type="radio" name="estrellas<%=misNooks.get(i).getIdNook()%>" value="4" onclick="this.form.submit();" <%if(valoracion==4){%> checked <%}%>>
<input id="<%=misNooks.get(i).getIdNook()%>,4" type="radio" name="estrellas<%=misNooks.get(i).getIdNook()%>" value="4" onclick="this.form.submit();" <%if(valoraciones.get(i)==4){%> checked <%}%>>
<label for="<%=misNooks.get(i).getIdNook()%>,4">&#9733;</label>
<input id="<%=misNooks.get(i).getIdNook()%>,3" type="radio" name="estrellas<%=misNooks.get(i).getIdNook()%>" value="3" onclick="this.form.submit();" <%if(valoracion==3){%> checked <%}%>>
<input id="<%=misNooks.get(i).getIdNook()%>,3" type="radio" name="estrellas<%=misNooks.get(i).getIdNook()%>" value="3" onclick="this.form.submit();" <%if(valoraciones.get(i)==3){%> checked <%}%>>
<label for="<%=misNooks.get(i).getIdNook()%>,3">&#9733;</label>
<input id="<%=misNooks.get(i).getIdNook()%>,2" type="radio" name="estrellas<%=misNooks.get(i).getIdNook()%>" value="2" onclick="this.form.submit();" <%if(valoracion==2){%> checked <%}%>>
<input id="<%=misNooks.get(i).getIdNook()%>,2" type="radio" name="estrellas<%=misNooks.get(i).getIdNook()%>" value="2" onclick="this.form.submit();" <%if(valoraciones.get(i)==2){%> checked <%}%>>
<label for="<%=misNooks.get(i).getIdNook()%>,2">&#9733;</label>
<input id="<%=misNooks.get(i).getIdNook()%>,1" type="radio" name="estrellas<%=misNooks.get(i).getIdNook()%>" value="1" onclick="this.form.submit();" <%if(valoracion==1){%> checked <%}%>>
<input id="<%=misNooks.get(i).getIdNook()%>,1" type="radio" name="estrellas<%=misNooks.get(i).getIdNook()%>" value="1" onclick="this.form.submit();" <%if(valoraciones.get(i)==1){%> checked <%}%>>
<label for="<%=misNooks.get(i).getIdNook()%>,1">&#9733;</label>
</p>
<p class="vMedia"><%=misNooks.get(i).getValoracionMedia()%></p>
</form>
</div>
</div>
......
......@@ -22,7 +22,7 @@ and open the template in the editor.
String userName = (String) sesion.getAttribute("usuario");
Nook nook = (Nook) request.getAttribute("nook");
double valoracion = Math.round(nook.getValoracionMedia());
int valoracion = (Integer) request.getAttribute("valoracion");
String nombre = nook.getNombre();
Date fecha = nook.getFechaCreacion();
String resumen = nook.getResumen();
......@@ -62,10 +62,17 @@ and open the template in the editor.
<div class="opciones">
<ul>
<li><a href="autorSV?nombre=<%=autor%>"><img <img src="recuperarimagenOtroSV?autor=<%=autor%>"
<%if(userName.equals(autor)){%>
<li><a href="perfil.jsp"><img src="recuperarimagenOtroSV?autor=<%=autor%>"
class="imagenesUsuarios"
alt="Imagen del perfil de usuario"></a></li>
<li><a href="perfil.jsp"><%=autor%></a></li>
<%}else{%>
<li><a href="autorSV?nombre=<%=autor%>"><img src="recuperarimagenOtroSV?autor=<%=autor%>"
class="imagenesUsuarios"
alt="Imagen del perfil de usuario"></a></li>
<li><a href="autorSV?nombre=<%=autor%>"><%=autor%></a></li>
<%}%>
<li><%=fecha%></li>
<li><button type="button">Descargar</button></li>
<li><button type="button" onclick="window.location.href='/documentosSV?idNook=<%=nook.getIdNook()%>'">Ver archivos</button></li>
......@@ -86,10 +93,11 @@ and open the template in the editor.
<input id="<%=nook.getIdNook()%>,1" type="radio" name="estrellas<%=nook.getIdNook()%>" value="1" onclick="this.form.submit();" <%if(valoracion==1){%> checked <%}%>>
<label for="<%=nook.getIdNook()%>,1">&#9733;</label>
</p>
<p class="vMedia"><%=nook.getValoracionMedia()%></p>
</form>
</div>
<div class="comentarios">
<form method="post" action="/crearComentarioSV?idNook=<%=nook.getIdNook()%>" >
<form method="post" action="/crearComentarioSV?idNook=<%=nook.getIdNook()%>&url=/nookSV?<%=nook.getIdNook()%>" >
<ul>
<li><input id="comentario" type="text" placeholder="Aada un comentario..." name="comentario"></li>
......@@ -104,29 +112,44 @@ and open the template in the editor.
<ul>
<%
ArrayList<Comentario> comentarios = (ArrayList<Comentario>) request.getAttribute("comentarios");
ArrayList<Integer> cValoraciones = (ArrayList<Integer>) request.getAttribute("cValoraciones");
for(int i = 0; i < comentarios.size(); i++){
double valoracionCo = Math.round(comentarios.get(i).getValoracionMedia());
%>
<li>
<div class="comentarioTexto" method="post" action="/valorarComentarioSV?">
<p class="usuario"><a href="autorSV?nombre=<%=comentarios.get(i).getAutor()%>"><img src="recuperarImagenesSV?userName=<%=comentarios.get(i).getAutor()%>"
<p class="usuario">
<%if(userName.equals(autor)){%>
<a href="perfil.jsp">
<img src="recuperarImagenesSV?userName=<%=comentarios.get(i).getAutor()%>"
class="imagenesUsuariosComentarios"
alt="Imagen del perfil de usuario"></a><%=comentarios.get(i).getAutor()%><p>
alt="Imagen del perfil de usuario">
</a>
<%=comentarios.get(i).getAutor()%>
<%} else {%>
<a href="autorSV?nombre=<%=comentarios.get(i).getAutor()%>">
<img src="recuperarImagenesSV?userName=<%=comentarios.get(i).getAutor()%>"
class="imagenesUsuariosComentarios"
alt="Imagen del perfil de usuario">
</a>
<%=comentarios.get(i).getAutor()%>
<%}%>
</p>
<p><%=comentarios.get(i).getTexto()%></p>
<div class="star1">
<form class="valoracion" method="post" action="/valorarComentarioSV?comentario=<%=comentarios.get(i).getIdComentario()%>&urlPagina=/nookSV?idNook=<%=nook.getIdNook()%>">
<p class="clasificacion">
<input id="c<%=comentarios.get(i).getIdComentario()%>,5" type="radio" name="cestrellas<%=comentarios.get(i).getIdComentario()%>" onclick="this.form.submit();" <%if(valoracionCo==5){%> checked <%}%> value="5">
<input id="c<%=comentarios.get(i).getIdComentario()%>,5" type="radio" name="cestrellas<%=comentarios.get(i).getIdComentario()%>" onclick="this.form.submit();" <%if(cValoraciones.get(i)==5){%> checked <%}%> value="5">
<label for="c<%=comentarios.get(i).getIdComentario()%>,5">&#9733;</label>
<input id="c<%=comentarios.get(i).getIdComentario()%>,4" type="radio" name="cestrellas<%=comentarios.get(i).getIdComentario()%>" onclick="this.form.submit();" <%if(valoracionCo==4){%> checked <%}%> value="4">
<input id="c<%=comentarios.get(i).getIdComentario()%>,4" type="radio" name="cestrellas<%=comentarios.get(i).getIdComentario()%>" onclick="this.form.submit();" <%if(cValoraciones.get(i)==4){%> checked <%}%> value="4">
<label for="c<%=comentarios.get(i).getIdComentario()%>,4">&#9733;</label>
<input id="c<%=comentarios.get(i).getIdComentario()%>,3" type="radio" name="cestrellas<%=comentarios.get(i).getIdComentario()%>" onclick="this.form.submit();" <%if(valoracionCo==3){%> checked <%}%> value="3">
<input id="c<%=comentarios.get(i).getIdComentario()%>,3" type="radio" name="cestrellas<%=comentarios.get(i).getIdComentario()%>" onclick="this.form.submit();" <%if(cValoraciones.get(i)==3){%> checked <%}%> value="3">
<label for="c<%=comentarios.get(i).getIdComentario()%>,3">&#9733;</label>
<input id="c<%=comentarios.get(i).getIdComentario()%>,2" type="radio" name="cestrellas<%=comentarios.get(i).getIdComentario()%>" onclick="this.form.submit();" <%if(valoracionCo==2){%> checked <%}%> value="2">
<input id="c<%=comentarios.get(i).getIdComentario()%>,2" type="radio" name="cestrellas<%=comentarios.get(i).getIdComentario()%>" onclick="this.form.submit();" <%if(cValoraciones.get(i)==2){%> checked <%}%> value="2">
<label for="c<%=comentarios.get(i).getIdComentario()%>,2">&#9733;</label>
<input id="c<%=comentarios.get(i).getIdComentario()%>,1" type="radio" name="cestrellas<%=comentarios.get(i).getIdComentario()%>" onclick="this.form.submit();" <%if(valoracionCo==1){%> checked <%}%> value="1">
<input id="c<%=comentarios.get(i).getIdComentario()%>,1" type="radio" name="cestrellas<%=comentarios.get(i).getIdComentario()%>" onclick="this.form.submit();" <%if(cValoraciones.get(i)==1){%> checked <%}%> value="1">
<label for="c<%=comentarios.get(i).getIdComentario()%>,1">&#9733;</label>
</p>
<p class="vMedia"><%=comentarios.get(i).getValoracionMedia()%></p>
</form>
</div>
</div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment