show fini, formulaire pour créer une question PT
This commit is contained in:
@@ -23,7 +23,7 @@ classDiagram
|
|||||||
-codePIN : int
|
-codePIN : int
|
||||||
-quizzs : List<Quizz>
|
-quizzs : List<Quizz>
|
||||||
-utilisateurs : List<Utilisateur>
|
-utilisateurs : List<Utilisateur>
|
||||||
-theme : int
|
-theme : String
|
||||||
}
|
}
|
||||||
class Quizz{
|
class Quizz{
|
||||||
-session: Session
|
-session: Session
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package metier;
|
package metier;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.List;
|
||||||
|
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.PrimaryKeyJoinColumn;
|
import jakarta.persistence.PrimaryKeyJoinColumn;
|
||||||
@@ -14,7 +14,7 @@ import lombok.Setter;
|
|||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@PrimaryKeyJoinColumn(name = "Choix_Id")
|
@PrimaryKeyJoinColumn(name = "Choix_Id")
|
||||||
public class Choix extends Reponse{
|
public class Choix extends Reponse{
|
||||||
ArrayList<String> choix;
|
List<String> choix;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String valHTML(){
|
public String valHTML(){
|
||||||
|
|||||||
@@ -27,4 +27,8 @@ public class Quizz implements Serializable {
|
|||||||
|
|
||||||
@OneToMany(mappedBy = "quizz")
|
@OneToMany(mappedBy = "quizz")
|
||||||
private List<Question> questions=new ArrayList<Question>();
|
private List<Question> questions=new ArrayList<Question>();
|
||||||
|
|
||||||
|
public void addQuestion(Question question) {
|
||||||
|
this.questions.add(question);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
71
src/main/java/servlet/QuestionInfo.java
Normal file
71
src/main/java/servlet/QuestionInfo.java
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
package servlet;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import jakarta.servlet.ServletException;
|
||||||
|
import jakarta.servlet.annotation.WebServlet;
|
||||||
|
import jakarta.servlet.http.HttpServlet;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import DAO.*;
|
||||||
|
import metier.*;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
@WebServlet(name="question",
|
||||||
|
urlPatterns={"/QuestionInfo"})
|
||||||
|
public class QuestionInfo extends HttpServlet {
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
|
req.getRequestDispatcher("/Question.html").forward(req, resp);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
|
QuizzDAO qDAO = new QuizzDAO();
|
||||||
|
QuestionDAO questionDAO = new QuestionDAO();
|
||||||
|
String ennonce = req.getParameter("question");
|
||||||
|
String type = req.getParameter("type");
|
||||||
|
String choixPossible = req.getParameter("choixPossible");
|
||||||
|
String reponse = req.getParameter("reponse");
|
||||||
|
String idQuizz = req.getParameter("idQuizz");
|
||||||
|
|
||||||
|
Question question = new Question();
|
||||||
|
Quizz quizz = qDAO.findById(Integer.parseInt(idQuizz));
|
||||||
|
if(quizz==null){
|
||||||
|
resp.getWriter().println("<HTML>\n<BODY>\n" +
|
||||||
|
"<H1> Quizz non trouvable </H1>" +
|
||||||
|
"</BODY></HTML>");
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
quizz.addQuestion(question);
|
||||||
|
question.setQuestion(ennonce);
|
||||||
|
|
||||||
|
|
||||||
|
List<String> listRep = Arrays.asList(reponse.split("\n"));
|
||||||
|
|
||||||
|
|
||||||
|
if(type.equals("choix")){
|
||||||
|
Choix choix = new Choix();
|
||||||
|
question.setReponse(choix);
|
||||||
|
List<String> listChoix = Arrays.asList(choixPossible.split("\n"));
|
||||||
|
choix.setChoix(listChoix);
|
||||||
|
choix.setReponses(listRep);
|
||||||
|
}
|
||||||
|
else if (type.equals("courte")){
|
||||||
|
ReponseCourte reponseCourte = new ReponseCourte();
|
||||||
|
question.setReponse(reponseCourte);
|
||||||
|
reponseCourte.setReponses(listRep);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
resp.getWriter().println("<HTML>\n<BODY>\n" +
|
||||||
|
"<H1> Type de question non trouvé </H1>" +
|
||||||
|
"</BODY></HTML>");
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
|
questionDAO.create(question);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -27,10 +27,14 @@ public class SessionInfo extends HttpServlet {
|
|||||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
// Créer une nouvelle session
|
// Créer une nouvelle session
|
||||||
String theme = req.getParameter("theme");
|
String theme = req.getParameter("theme");
|
||||||
|
String codePin = req.getParameter("codePIN");
|
||||||
Session s = new Session();
|
Session s = new Session();
|
||||||
|
s.setCodePIN(Integer.parseInt(codePin));
|
||||||
s.setTheme(theme);
|
s.setTheme(theme);
|
||||||
sessionDAO.create(s);
|
sessionDAO.create(s);
|
||||||
|
|
||||||
|
resp.getWriter().println("<h1>Session creee avec id: " +
|
||||||
|
s.getId() + "</h1>");
|
||||||
resp.getWriter().println("<h1>Session creee avec code PIN: " +
|
resp.getWriter().println("<h1>Session creee avec code PIN: " +
|
||||||
s.getCodePIN() + "</h1>");
|
s.getCodePIN() + "</h1>");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ import jakarta.servlet.http.HttpServletResponse;
|
|||||||
|
|
||||||
@WebServlet(name="Show", urlPatterns={"/Show"})
|
@WebServlet(name="Show", urlPatterns={"/Show"})
|
||||||
public class Show extends HttpServlet {
|
public class Show extends HttpServlet {
|
||||||
Utilisateur u;
|
QuizzDAO quizzDAO = new QuizzDAO();
|
||||||
QuizzDAO quizzDAI = new QuizzDAO();
|
SessionDAO sessionDAO = new SessionDAO();
|
||||||
UtilisateurDAO utilisateurDAO = new UtilisateurDAO();
|
UtilisateurDAO utilisateurDAO = new UtilisateurDAO();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -52,14 +52,15 @@ public class Show extends HttpServlet {
|
|||||||
result +=
|
result +=
|
||||||
"</tbody>"+
|
"</tbody>"+
|
||||||
"</table>";
|
"</table>";
|
||||||
result += "</body>\n</html>";
|
|
||||||
|
|
||||||
//QUIZZ
|
//QUIZZ
|
||||||
List<Quizz> listQuizz = quizzDAI.findAll();
|
List<Quizz> listQuizz = quizzDAO.findAll();
|
||||||
|
|
||||||
result += "<H2>Quizz :</H2>";
|
result += "<H2>Quizz :</H2>";
|
||||||
for (Quizz quizz : listQuizz) {
|
for (Quizz quizz : listQuizz) {
|
||||||
result += "quizz n°" + quizz.getId() + "<br/>";
|
result += "quizz n°" + quizz.getId() + "<br/>";
|
||||||
|
result += "Admin" + quizz.getUtilisateur().getEmail() + " (id: " + quizz.getUtilisateur().getId() + ") <br/>";
|
||||||
|
result += "nb Question :" + quizz.getQuestions().size() +"<br/>";
|
||||||
for (Question question : quizz.getQuestions()) {
|
for (Question question : quizz.getQuestions()) {
|
||||||
result += question.getQuestion() + "<br/>";
|
result += question.getQuestion() + "<br/>";
|
||||||
|
|
||||||
@@ -73,6 +74,45 @@ public class Show extends HttpServlet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//SESSION
|
||||||
|
List<Session> listSession = sessionDAO.findAll();
|
||||||
|
result += "<H2>Session : </H2>";
|
||||||
|
result +=
|
||||||
|
"<table class=\"show\">"+
|
||||||
|
"<thead class=\"show\">"+
|
||||||
|
"<tr>"+
|
||||||
|
"<th class=\"show\">ID</th><th class=\"show\">Theme</th><th class=\"show\">Code PIN</th><th class=\"show\">Qizzs</th><th class=\"show\">Participants</th>"+
|
||||||
|
"</tr>"+
|
||||||
|
"</thead>"+
|
||||||
|
"<tbody>";
|
||||||
|
|
||||||
|
for(Session session : listSession){
|
||||||
|
result+=
|
||||||
|
"<tr>"+
|
||||||
|
"<th class=\"show\">"+session.getId()+"</th>"+"<th class=\"show\">"+session.getTheme()+"</th>"+"<th class=\"show\">"+session.getCodePIN()+"</th>";
|
||||||
|
String quizzsID = "";
|
||||||
|
for(Quizz quizz : session.getQuizzs()){
|
||||||
|
quizzsID += quizz.getId() + " ; ";
|
||||||
|
}
|
||||||
|
String UtilisateurID = "";
|
||||||
|
for(Utilisateur utilisateur : session.getUtilisateurs()){
|
||||||
|
UtilisateurID += utilisateur.getId() + " ; ";
|
||||||
|
}
|
||||||
|
result += "<th class=\"show\">"+quizzsID+"</th>"+"<th class=\"show\">"+UtilisateurID+"</th>";
|
||||||
|
result+="</tr>";
|
||||||
|
}
|
||||||
|
|
||||||
|
result +=
|
||||||
|
"</tbody>"+
|
||||||
|
"</table>";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//HTML END
|
||||||
|
result += "</body>\n</html>";
|
||||||
|
|
||||||
response.getWriter().write(result);
|
response.getWriter().write(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
41
src/main/webapp/Question.html
Normal file
41
src/main/webapp/Question.html
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<html lang="fr">
|
||||||
|
<body>
|
||||||
|
<h1>Creer une Question</h1>
|
||||||
|
<form action="QuestionInfo" method="POST">
|
||||||
|
<input type="hidden" name="action" value="createSession">
|
||||||
|
Ennoncé de la question : <input type="text" name="question"><br/>
|
||||||
|
Type :
|
||||||
|
<select id="type" name="type">
|
||||||
|
<option value="choix">Choix multiple</option>
|
||||||
|
<option value="courte">Réponse courte</option>
|
||||||
|
</select><br/>
|
||||||
|
<div id="DivChoix">
|
||||||
|
Choix possible (séparez avec des retour à la ligne):<br/>
|
||||||
|
<textarea id="choixPossible" name="choixPossible" rows="5" cols="40"></textarea><br/>
|
||||||
|
</div>
|
||||||
|
Réponse autorisée (séparez avec des retour à la ligne):<br/>
|
||||||
|
<textarea id="reponse" name="reponse" rows="5" cols="40"></textarea><br/>
|
||||||
|
ID Quizz: <input type="number" name="idQuizz"><br/>
|
||||||
|
<input type="submit" value="Creer Session">
|
||||||
|
</form>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<script>
|
||||||
|
const select = document.getElementById('type');
|
||||||
|
const contenu1 = document.getElementById('DivChoix');
|
||||||
|
|
||||||
|
select.addEventListener('change', function () {
|
||||||
|
if (this.value === 'choix') {
|
||||||
|
contenu1.style.display = 'block';
|
||||||
|
} else{
|
||||||
|
contenu1.style.display = 'none';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
|
<meta charset="UTF-8">
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<body>
|
<body>
|
||||||
<form action="QuizzInfo" method="POST">
|
<form action="QuizzInfo" method="POST">
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
|
<meta charset="UTF-8">
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<body>
|
<body>
|
||||||
<h1>Creer une session</h1>
|
<h1>Creer une session</h1>
|
||||||
<form action="SessionInfo" method="POST">
|
<form action="SessionInfo" method="POST">
|
||||||
<input type="hidden" name="action" value="createSession">
|
<input type="hidden" name="action" value="createSession">
|
||||||
Theme: <input type="text" name="theme">
|
Theme: <input type="text" name="theme">
|
||||||
|
CodePin <input type="number" name="codePIN">
|
||||||
<input type="submit" value="Creer Session">
|
<input type="submit" value="Creer Session">
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,10 @@
|
|||||||
<body>
|
<body>
|
||||||
<h1>Hello World!</h1>
|
<h1>Hello World!</h1>
|
||||||
<a href =http://localhost:8080/UserInfo.html>myform</a>
|
<a href =http://localhost:8080/UserInfo.html>myform</a>
|
||||||
|
<a href =http://localhost:8080/Session.html>session</a>
|
||||||
<a href =http://localhost:8080/Quizz.html>Quizz</a>
|
<a href =http://localhost:8080/Quizz.html>Quizz</a>
|
||||||
|
<a href =http://localhost:8080/Question.html>Question</a>
|
||||||
|
|
||||||
|
|
||||||
<a href =Show>show</a>
|
<a href =Show>show</a>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in New Issue
Block a user