diff --git a/src/main/java/de/thm/arsnova/dao/CouchDBDao.java b/src/main/java/de/thm/arsnova/dao/CouchDBDao.java index 58f5ba49e22c348115c2e3dbab9635cfaaacc44f..252716b7147bf9b47186338d04706896dd4a1027 100644 --- a/src/main/java/de/thm/arsnova/dao/CouchDBDao.java +++ b/src/main/java/de/thm/arsnova/dao/CouchDBDao.java @@ -431,18 +431,8 @@ public class CouchDBDao implements IDatabaseDao { } else { view = new NovaView("skill_question/by_session_only_id_for_all"); } - view.setKey(session.get_id()); - ViewResults results = this.getDatabase().view(view); - if (results.getResults().size() == 0) { - return new ArrayList<String>(); - } - - List<String> ids = new ArrayList<String>(); - for (Document d : results.getResults()) { - ids.add(d.getId()); - } - return ids; + return collectQuestionIds(view); } @Override @@ -497,21 +487,7 @@ public class CouchDBDao implements IDatabaseDao { public final List<String> getUnAnsweredQuestionIds(final Session session, final User user) { NovaView view = new NovaView("answer/by_user"); view.setKey(user.getUsername(), session.get_id()); - ViewResults anseweredQuestions = this.getDatabase().view(view); - - List<String> answered = new ArrayList<String>(); - for (Document d : anseweredQuestions.getResults()) { - answered.add(d.getString("value")); - } - - List<String> questions = this.getQuestionIds(session, user); - List<String> unanswered = new ArrayList<String>(); - for (String questionId : questions) { - if (!answered.contains(questionId)) { - unanswered.add(questionId); - } - } - return unanswered; + return collectUnansweredQuestionIds(session, user, this.getQuestionIds(session, user), view); } @Override @@ -943,6 +919,7 @@ public class CouchDBDao implements IDatabaseDao { a.put("sessionId", answer.getSessionId()); a.put("questionId", answer.getQuestionId()); a.put("answerSubject", answer.getAnswerSubject()); + a.put("questionVariant", answer.getQuestionVariant()); a.put("answerText", answer.getAnswerText()); a.put("timestamp", answer.getTimestamp()); a.put("user", user.getUsername()); @@ -1243,13 +1220,68 @@ public class CouchDBDao implements IDatabaseDao { @Override public List<String> getUnAnsweredLectureQuestionIds(Session session, User user) { - // TODO Auto-generated method stub - return null; + NovaView view = new NovaView("answer/variant_by_user"); + view.setKey(user.getUsername(), session.get_id(), "lecture"); + return collectUnansweredQuestionIds(session, user, this.getLectureQuestionIds(session, user), view); + } + + private List<String> getLectureQuestionIds(Session session, User user) { + NovaView view; + if (user.getType().equals("thm")) { + view = new NovaView("skill_question/lecture_question_by_session_for_thm"); + } else { + view = new NovaView("skill_question/lecture_question_by_session_for_all"); + } + view.setStartKeyArray(session.get_id()); + view.setEndKeyArray(session.get_id(), "{}"); + return collectQuestionIds(view); } @Override public List<String> getUnAnsweredPreparationQuestionIds(Session session, User user) { - // TODO Auto-generated method stub - return null; + NovaView view = new NovaView("answer/variant_by_user"); + view.setKey(user.getUsername(), session.get_id(), "preparation"); + return collectUnansweredQuestionIds(session, user, this.getPreparationQuestionIds(session, user), view); + } + + private List<String> getPreparationQuestionIds(Session session, User user) { + NovaView view; + if (user.getType().equals("thm")) { + view = new NovaView("skill_question/preparation_question_by_session_for_thm"); + } else { + view = new NovaView("skill_question/preparation_question_by_session_for_all"); + } + view.setStartKeyArray(session.get_id()); + view.setEndKeyArray(session.get_id(), "{}"); + return collectQuestionIds(view); + } + + private List<String> collectUnansweredQuestionIds(Session session, User user, List<String> questions, NovaView view) { + ViewResults answeredQuestions = this.getDatabase().view(view); + + List<String> answered = new ArrayList<String>(); + for (Document d : answeredQuestions.getResults()) { + answered.add(d.getString("value")); + } + + List<String> unanswered = new ArrayList<String>(); + for (String questionId : questions) { + if (!answered.contains(questionId)) { + unanswered.add(questionId); + } + } + return unanswered; + } + + private List<String> collectQuestionIds(NovaView view) { + ViewResults results = this.getDatabase().view(view); + if (results.getResults().size() == 0) { + return new ArrayList<String>(); + } + List<String> ids = new ArrayList<String>(); + for (Document d : results.getResults()) { + ids.add(d.getId()); + } + return ids; } } diff --git a/src/main/java/de/thm/arsnova/entities/Answer.java b/src/main/java/de/thm/arsnova/entities/Answer.java index 278ac92d50b61363859b23a4133e836993b331a9..aed482cfba76aac0f3f915fcba3d21b117af4579 100644 --- a/src/main/java/de/thm/arsnova/entities/Answer.java +++ b/src/main/java/de/thm/arsnova/entities/Answer.java @@ -9,12 +9,13 @@ public class Answer { private String questionId; private String answerText; private String answerSubject; + private String questionVariant; private int piRound; private String user; private long timestamp; private int answerCount = 1; - private boolean abstention; // Currently available only for freetext and mc answers! - private int abstentionCount; // Currently available only for freetext and mc answers! + private boolean abstention; + private int abstentionCount; public Answer() { this.type = "skill_question_answer"; @@ -124,6 +125,14 @@ public class Answer { this.abstentionCount = abstentionCount; } + public String getQuestionVariant() { + return questionVariant; + } + + public void setQuestionVariant(String questionVariant) { + this.questionVariant = questionVariant; + } + @Override public final String toString() { return "Answer type:'" + type + "'"