show fini !
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
package DAO;
|
||||
|
||||
import jakarta.persistence.EntityTransaction;
|
||||
import metier.Question;
|
||||
import metier.Quizz;
|
||||
import metier.Session;
|
||||
import metier.Utilisateur;
|
||||
|
||||
public class QuizzDAO extends AbstractJpaDao<Integer, Quizz> {
|
||||
public QuizzDAO(){
|
||||
@@ -15,4 +18,19 @@ public class QuizzDAO extends AbstractJpaDao<Integer, Quizz> {
|
||||
em.createQuery("delete from Quizz").executeUpdate();
|
||||
et.commit();
|
||||
}
|
||||
|
||||
public void addQuestion(Quizz quizz, Question question) {
|
||||
System.out.println("ajout de question dans le quizz");
|
||||
EntityTransaction t = em.getTransaction();
|
||||
t.begin();
|
||||
question.setQuizz(quizz);
|
||||
quizz.getQuestions().add(question);
|
||||
em.merge(quizz);
|
||||
t.commit();
|
||||
em.refresh(quizz);
|
||||
}
|
||||
|
||||
public void refresh(Quizz quizz) {
|
||||
em.refresh(quizz);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
package DAO;
|
||||
|
||||
import jakarta.persistence.EntityTransaction;
|
||||
import metier.Choix;
|
||||
import metier.Question;
|
||||
import metier.Reponse;
|
||||
import metier.Session;
|
||||
import metier.Utilisateur;
|
||||
|
||||
public class ReponseDAO extends AbstractJpaDao<Integer, Reponse> {
|
||||
public ReponseDAO(){
|
||||
@@ -8,12 +13,17 @@ public class ReponseDAO extends AbstractJpaDao<Integer, Reponse> {
|
||||
this.setClass(Reponse.class);
|
||||
}
|
||||
|
||||
/*public List<String> getGoodResponses(){
|
||||
EntityTransaction t=em.getTransaction();
|
||||
|
||||
public void addToQuestion(Reponse r, Question q) {
|
||||
EntityTransaction t = em.getTransaction();
|
||||
t.begin();
|
||||
Query query=em.createQuery("select r from Reponse r where r.reponses");
|
||||
List<String> lString=query.getResultList();
|
||||
|
||||
q.setReponse(r);
|
||||
r.setQuestion(q);
|
||||
em.merge(r);
|
||||
t.commit();
|
||||
return lString;
|
||||
}*/
|
||||
em.refresh(q);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package DAO;
|
||||
|
||||
import jakarta.persistence.EntityTransaction;
|
||||
import jakarta.persistence.Query;
|
||||
import metier.Quizz;
|
||||
import metier.Session;
|
||||
|
||||
import java.util.List;
|
||||
@@ -26,4 +27,19 @@ public class SessionDAO extends AbstractJpaDao<Integer, Session> {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void refresh(Session session) {
|
||||
em.refresh(session);
|
||||
}
|
||||
|
||||
public void addQuizz(Quizz q, Session s) {
|
||||
EntityTransaction t = em.getTransaction();
|
||||
t.begin();
|
||||
|
||||
q.setSession(s);
|
||||
s.getQuizzs().add(q);
|
||||
em.merge(s);
|
||||
t.commit();
|
||||
em.refresh(s);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ public class Choix extends Reponse{
|
||||
String res = "";
|
||||
|
||||
for (String val : this.choix) {
|
||||
res+=val+"<br/>";
|
||||
res+= val+"<br/>";
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ public class Quizz implements Serializable {
|
||||
@JoinColumn(name="id_utilisateur")
|
||||
private Utilisateur utilisateur;
|
||||
|
||||
@OneToMany(mappedBy = "quizz")
|
||||
@OneToMany(mappedBy = "quizz", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
private List<Question> questions=new ArrayList<Question>();
|
||||
|
||||
public void addQuestion(Question question) {
|
||||
|
||||
@@ -16,6 +16,6 @@ public class ReponseCourte extends Reponse{
|
||||
|
||||
@Override
|
||||
public String valHTML(){
|
||||
return "INPUT";
|
||||
return "TEXT INPUT<br/>";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ public class Session implements Serializable {
|
||||
|
||||
@Column(unique=true)
|
||||
private int codePIN;
|
||||
|
||||
@OneToMany(mappedBy="session")
|
||||
private List<Quizz> quizzs = new ArrayList<>();
|
||||
|
||||
|
||||
@@ -23,49 +23,68 @@ public class QuestionInfo extends HttpServlet {
|
||||
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
QuizzDAO qDAO = new QuizzDAO();
|
||||
QuizzDAO quizzDAO = new QuizzDAO();
|
||||
QuestionDAO questionDAO = new QuestionDAO();
|
||||
ReponseDAO reponseDAO = new ReponseDAO();
|
||||
|
||||
|
||||
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));
|
||||
Quizz quizz = quizzDAO.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 question = new 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);
|
||||
|
||||
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);
|
||||
|
||||
reponseDAO.create(choix);
|
||||
reponseDAO.addToQuestion(choix, question);
|
||||
|
||||
}
|
||||
else if (type.equals("courte")){
|
||||
ReponseCourte reponseCourte = new ReponseCourte();
|
||||
//question.setReponse(reponseCourte);
|
||||
reponseCourte.setReponses(listRep);
|
||||
|
||||
reponseDAO.create(reponseCourte);
|
||||
reponseDAO.addToQuestion(reponseCourte, question);
|
||||
}
|
||||
else{
|
||||
resp.getWriter().println(
|
||||
"<HTML>\n<BODY>\n" +
|
||||
"<H1> Type de question non trouvé </H1>" +
|
||||
"</BODY></HTML>"
|
||||
);
|
||||
return ;
|
||||
}
|
||||
quizzDAO.addQuestion(quizz,question);
|
||||
|
||||
|
||||
|
||||
|
||||
resp.getWriter().println(
|
||||
"<HTML>\n<BODY>\n" +
|
||||
"<H1> Success </H1>" +
|
||||
"</BODY></HTML>"
|
||||
);
|
||||
return ;
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,7 @@ public class QuizzInfo extends HttpServlet {
|
||||
UtilisateurDAO uDAO = new UtilisateurDAO();
|
||||
String email_user = req.getParameter("email_User");
|
||||
String id_User = req.getParameter("id_User");
|
||||
String id_session = req.getParameter("code_pin");
|
||||
// String id_session = req.getParameter("code_pin");
|
||||
|
||||
Utilisateur u_cree_quizz = null;
|
||||
|
||||
@@ -46,22 +46,9 @@ public class QuizzInfo extends HttpServlet {
|
||||
"</BODY></HTML>");
|
||||
return ;
|
||||
}
|
||||
|
||||
//Session
|
||||
SessionDAO sDAO = new SessionDAO();
|
||||
Session s_attached = null;
|
||||
s_attached=sDAO.findById(Integer.parseInt(id_session));
|
||||
|
||||
if(s_attached==null){
|
||||
resp.getWriter().println("<HTML>\n<BODY>\n" +
|
||||
"<H1> Session non trouvable </H1>" +
|
||||
"</BODY></HTML>");
|
||||
return ;
|
||||
}
|
||||
|
||||
Quizz quizz = new Quizz();
|
||||
quizz.setUtilisateur(u_cree_quizz);
|
||||
quizz.setSession(s_attached);
|
||||
//quizz.setSession(s_attached);
|
||||
quizzDAO.create(quizz);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import jakarta.servlet.annotation.WebServlet;
|
||||
import jakarta.servlet.http.HttpServlet;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
import metier.Quizz;
|
||||
import metier.Session;
|
||||
import metier.Utilisateur;
|
||||
|
||||
@@ -25,17 +25,37 @@ public class SessionInfo extends HttpServlet {
|
||||
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
// Créer une nouvelle session
|
||||
String theme = req.getParameter("theme");
|
||||
String codePin = req.getParameter("codePIN");
|
||||
Session s = new Session();
|
||||
s.setCodePIN(Integer.parseInt(codePin));
|
||||
s.setTheme(theme);
|
||||
sessionDAO.create(s);
|
||||
String action = req.getParameter("action");
|
||||
if (action.equals("createSession")) {
|
||||
// Créer une nouvelle session
|
||||
String theme = req.getParameter("theme");
|
||||
String codePin = req.getParameter("codePIN");
|
||||
Session s = new Session();
|
||||
s.setCodePIN(Integer.parseInt(codePin));
|
||||
s.setTheme(theme);
|
||||
sessionDAO.create(s);
|
||||
|
||||
resp.getWriter().println("<h1>Session creee avec id: " +
|
||||
s.getId() + "</h1>");
|
||||
resp.getWriter().println("<h1>Session creee avec code PIN: " +
|
||||
s.getCodePIN() + "</h1>");
|
||||
resp.getWriter().println("<h1>Session creee avec id: " +
|
||||
s.getId() + "</h1>");
|
||||
resp.getWriter().println("<h1>Session creee avec code PIN: " +
|
||||
s.getCodePIN() + "</h1>");
|
||||
}
|
||||
else if (action.equals("addQuizz")){
|
||||
String idQuizz = req.getParameter("idQuizz");
|
||||
String sessionID = req.getParameter("sessionID");
|
||||
QuizzDAO quizzDAO = new QuizzDAO();
|
||||
SessionDAO sessionDAO = new SessionDAO();
|
||||
|
||||
Quizz quizz = quizzDAO.findById(Integer.parseInt(idQuizz));
|
||||
if(quizz==null) resp.getWriter().println("<h1>Ce quizz n'existe pas !</h1>");
|
||||
if(quizz==null) resp.getWriter().println("<h1>Cette session n'existe pas !</h1>");
|
||||
Session session = sessionDAO.findById(Integer.parseInt(sessionID));
|
||||
|
||||
sessionDAO.addQuizz(quizz,session);
|
||||
|
||||
|
||||
resp.getWriter().println("<h1>Quizz"+ idQuizz +" et ajouté à la session " + sessionID + " !</h1>");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,11 +21,13 @@ public class Show extends HttpServlet {
|
||||
QuizzDAO quizzDAO = new QuizzDAO();
|
||||
SessionDAO sessionDAO = new SessionDAO();
|
||||
UtilisateurDAO utilisateurDAO = new UtilisateurDAO();
|
||||
QuestionDAO questionDAO = new QuestionDAO();
|
||||
|
||||
UtilisateurMapper mapper_u = Mappers.getMapper(UtilisateurMapper.class);
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
|
||||
response.setContentType("text/html");
|
||||
|
||||
String result = "<!DOCTYPE html>" +
|
||||
@@ -43,12 +45,12 @@ public class Show extends HttpServlet {
|
||||
result += "<H2>Utilisateurs :</H2>";
|
||||
result +=
|
||||
"<table class=\"show\">" +
|
||||
"<thead class=\"show\">" +
|
||||
"<thead class=\"show\">" +
|
||||
"<tr>" +
|
||||
"<th class=\"show\">Nom</th><th class=\"show\">mail</th>" +
|
||||
"<th class=\"show\">Nom</th><th class=\"show\">mail</th>" +
|
||||
"</tr>" +
|
||||
"</thead>" +
|
||||
"<tbody>";
|
||||
"</thead>" +
|
||||
"<tbody>";
|
||||
for (Utilisateur u : listUser) {
|
||||
UtilisateurDTO dto = mapper_u.toDTO(u);
|
||||
result +=
|
||||
@@ -66,20 +68,31 @@ public class Show extends HttpServlet {
|
||||
|
||||
result += "<H2>Quizz :</H2>";
|
||||
for (Quizz quizz : listQuizz) {
|
||||
quizzDAO.refresh(quizz);
|
||||
result += "<div class=\"quizz\">";
|
||||
result += "quizz n°" + quizz.getId() + "<br/>";
|
||||
result += "<div class=\"tabulation\">";
|
||||
result += "Admin" + quizz.getUtilisateur().getEmail() + " (id: " + quizz.getUtilisateur().getId() + ") <br/>";
|
||||
result += "nb Question :" + quizz.getQuestions().size() +"<br/>";
|
||||
|
||||
|
||||
for (Question question : quizz.getQuestions()) {
|
||||
result += question.getQuestion() + "<br/>";
|
||||
result += "<div class=\"question\">";
|
||||
result += "Q" + question.getId() + " Ennoncé : "+ question.getQuestion() + "<br/>";
|
||||
|
||||
result += "choix de réponse : <br/>";
|
||||
|
||||
result += "<b>Choix de réponse : </b><br/>";
|
||||
result += "<div class=\"tabulation\">";
|
||||
result += question.getReponse().valHTML();
|
||||
|
||||
result += "Reponses corrects :<br/>";
|
||||
result += "</div>";
|
||||
result += "<b>Reponses corrects :</b><br/>";
|
||||
result += "<div class=\"tabulation\">";
|
||||
for (String reponse : question.getReponse().getReponses()) {
|
||||
result += reponse;
|
||||
}
|
||||
result += "</div></div>";
|
||||
}
|
||||
result += "</div></div>";
|
||||
}
|
||||
|
||||
//SESSION
|
||||
@@ -89,12 +102,13 @@ public class Show extends HttpServlet {
|
||||
"<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>"+
|
||||
"<th class=\"show\">ID</th><th class=\"show\">Theme</th><th class=\"show\">Code PIN</th><th class=\"show\">Quizzs</th><th class=\"show\">Participants</th>"+
|
||||
"</tr>"+
|
||||
"</thead>"+
|
||||
"<tbody>";
|
||||
|
||||
for(Session session : listSession){
|
||||
sessionDAO.refresh(session);
|
||||
result+=
|
||||
"<tr>"+
|
||||
"<th class=\"show\">"+session.getId()+"</th>"+"<th class=\"show\">"+session.getTheme()+"</th>"+"<th class=\"show\">"+session.getCodePIN()+"</th>";
|
||||
@@ -104,7 +118,7 @@ public class Show extends HttpServlet {
|
||||
}
|
||||
String UtilisateurID = "";
|
||||
for(Utilisateur utilisateur : session.getUtilisateurs()){
|
||||
UtilisateurID += utilisateur.getId() + " ; ";
|
||||
UtilisateurID += utilisateur.getEmail() + " ; ";
|
||||
}
|
||||
result += "<th class=\"show\">"+quizzsID+"</th>"+"<th class=\"show\">"+UtilisateurID+"</th>";
|
||||
result+="</tr>";
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
<h1>Creer des quizz</h1>
|
||||
Create from user id : <INPUT type="number" name="id_User" size="20"><BR>
|
||||
Create from user email : <INPUT type="text" name="email_User" size="20"><BR>
|
||||
Enter code pin of session: <INPUT type="number" name="code_pin" size="20"><BR>
|
||||
<INPUT type="submit" value="Creer Quizz"></INPUT>
|
||||
</form>
|
||||
</body>
|
||||
|
||||
@@ -10,6 +10,13 @@
|
||||
<input type="submit" value="Creer Session">
|
||||
</form>
|
||||
|
||||
<form action="SessionInfo" method="POST">
|
||||
<input type="hidden" name="action" value="addQuizz">
|
||||
session ID <input type="number" name="sessionID">
|
||||
ID Quizz <input type="number" name="idQuizz">
|
||||
<input type="submit" value="Add Quizz">
|
||||
</form>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,5 +1,5 @@
|
||||
body{
|
||||
|
||||
|
||||
}
|
||||
|
||||
table.show{
|
||||
@@ -18,3 +18,22 @@ th.show{
|
||||
padding-right: 5px;
|
||||
border: 1px solid #C0C0C0
|
||||
}
|
||||
|
||||
|
||||
.tabulation{
|
||||
padding-left: 10px;
|
||||
}
|
||||
|
||||
.question{
|
||||
border: solid;
|
||||
border-color: #C0C0C0;
|
||||
margin: 5px;
|
||||
padding: 5px;
|
||||
}
|
||||
|
||||
.quizz{
|
||||
border: solid;
|
||||
border-color: #909090;
|
||||
margin: 5px;
|
||||
padding: 5px;
|
||||
}
|
||||
Reference in New Issue
Block a user