Index: lams_tool_survey/conf/language/lams/ApplicationResources.properties =================================================================== diff -u -rf7140a37e1b5b7a2d2e3fc6c80ecdb2fc6f76ccd -r0012f4c60038db0a2c4754b641f95c24ddd0d84a --- lams_tool_survey/conf/language/lams/ApplicationResources.properties (.../ApplicationResources.properties) (revision f7140a37e1b5b7a2d2e3fc6c80ecdb2fc6f76ccd) +++ lams_tool_survey/conf/language/lams/ApplicationResources.properties (.../ApplicationResources.properties) (revision 0012f4c60038db0a2c4754b641f95c24ddd0d84a) @@ -2,7 +2,7 @@ #language code: en #locale code: AU - # CVS ID: $Id$ Exported from the LAMS Community by Ernie Ghiglione on Thu Oct 30 14:01:29 CST 2014 + # CVS ID: $Id$ Exported from the LAMS Community by Ernie Ghiglione on Sun Mar 29 04:53:04 CST 2015 #=================== labels for Survey =================# @@ -185,7 +185,7 @@ label.sort.by.answer =Sort by answer label.other.answers =Answers from other Learners label.total.responses =Total responses so far: {0} -message.no.reflection.available =No notebook entry was added. +message.no.reflection.available =No notebook entry has been added. +label.search=Search... - -#======= End labels: Exported 179 labels for en AU ===== +#======= End labels: Exported 180 labels for en AU ===== Index: lams_tool_survey/conf/language/lams/ApplicationResources_el_GR.properties =================================================================== diff -u -r29e5e45f817329acdbfdada05a424015f0b52c50 -r0012f4c60038db0a2c4754b641f95c24ddd0d84a --- lams_tool_survey/conf/language/lams/ApplicationResources_el_GR.properties (.../ApplicationResources_el_GR.properties) (revision 29e5e45f817329acdbfdada05a424015f0b52c50) +++ lams_tool_survey/conf/language/lams/ApplicationResources_el_GR.properties (.../ApplicationResources_el_GR.properties) (revision 0012f4c60038db0a2c4754b641f95c24ddd0d84a) @@ -2,7 +2,7 @@ #language code: el #locale code: GR - # CVS ID: $Id$ Exported from the LAMS Community by Ernie Ghiglione on Thu Oct 30 13:51:47 CST 2014 + # CVS ID: $Id$ Exported from the LAMS Community by Ernie Ghiglione on Thu Mar 12 12:44:17 CST 2015 #=================== labels for Survey =================# @@ -180,6 +180,11 @@ label.copy =\u0391\u03bd\u03c4\u03b9\u03b3\u03c1\u03b1\u03c6\u03ae label.submit =\u039f\u03bb\u03bf\u03ba\u03bb\u03ae\u03c1\u03c9\u03c3\u03b7 label.monitoring.heading =\u0395\u03c0\u03bf\u03c0\u03c4\u03b5\u03af\u03b1 \u0388\u03c1\u03b5\u03c5\u03bd\u03b1\u03c2 +label.show.answers.from.other.users =\u03a0\u03c1\u03bf\u03b2\u03bf\u03bb\u03ae \u03b1\u03c0\u03b1\u03bd\u03c4\u03ae\u03c3\u03b5\u03c9\u03bd \u03c4\u03c9\u03bd \u03ac\u03bb\u03bb\u03c9\u03bd \u03b5\u03ba\u03c0\u03b1\u03b9\u03b4\u03b5\u03c5\u03cc\u03bc\u03b5\u03bd\u03c9\u03bd +label.view.all.responses =\u03a0\u03c1\u03bf\u03b2\u03bf\u03bb\u03ae \u03cc\u03bb\u03c9\u03bd \u03c4\u03c9\u03bd \u03b1\u03c0\u03b1\u03bd\u03c4\u03ae\u03c3\u03b5\u03c9\u03bd +label.sort.by.answer =\u03a4\u03b1\u03be\u03b9\u03bd\u03cc\u03bc\u03b7\u03c3\u03b7 \u03b1\u03bd\u03ac \u03b1\u03c0\u03ac\u03bd\u03c4\u03b7\u03c3\u03b7 +label.other.answers =\u0391\u03c0\u03b1\u03bd\u03c4\u03ae\u03c3\u03b5\u03b9\u03c2 \u03c4\u03c9\u03bd \u03ac\u03bb\u03bb\u03c9\u03bd \u03b5\u03ba\u03c0\u03b1\u03b9\u03b4\u03b5\u03c5\u03cc\u03bc\u03b5\u03bd\u03c9\u03bd +label.total.responses =\u03a3\u03c5\u03bd\u03bf\u03bb\u03b9\u03ba\u03ad\u03c2 \u03b1\u03c0\u03b1\u03bd\u03c4\u03ae\u03c3\u03b5\u03b9\u03c2 \u03ad\u03c9\u03c2 \u03c4\u03ce\u03c1\u03b1 {0} -#======= End labels: Exported 174 labels for el GR ===== +#======= End labels: Exported 179 labels for el GR ===== Index: lams_tool_survey/conf/language/lams/ApplicationResources_en_AU.properties =================================================================== diff -u -rf7140a37e1b5b7a2d2e3fc6c80ecdb2fc6f76ccd -r0012f4c60038db0a2c4754b641f95c24ddd0d84a --- lams_tool_survey/conf/language/lams/ApplicationResources_en_AU.properties (.../ApplicationResources_en_AU.properties) (revision f7140a37e1b5b7a2d2e3fc6c80ecdb2fc6f76ccd) +++ lams_tool_survey/conf/language/lams/ApplicationResources_en_AU.properties (.../ApplicationResources_en_AU.properties) (revision 0012f4c60038db0a2c4754b641f95c24ddd0d84a) @@ -2,7 +2,7 @@ #language code: en #locale code: AU - # CVS ID: $Id$ Exported from the LAMS Community by Ernie Ghiglione on Thu Oct 30 14:01:29 CST 2014 + # CVS ID: $Id$ Exported from the LAMS Community by Ernie Ghiglione on Sun Mar 29 04:53:04 CST 2015 #=================== labels for Survey =================# @@ -185,7 +185,7 @@ label.sort.by.answer =Sort by answer label.other.answers =Answers from other Learners label.total.responses =Total responses so far: {0} -message.no.reflection.available =No notebook entry was added. +message.no.reflection.available =No notebook entry has been added. -#======= End labels: Exported 179 labels for en AU ===== +#======= End labels: Exported 180 labels for en AU ===== Index: lams_tool_survey/conf/language/lams/ApplicationResources_es_ES.properties =================================================================== diff -u -r88f63737891cac3954ad9ff0892f08ac3efa0ffd -r0012f4c60038db0a2c4754b641f95c24ddd0d84a --- lams_tool_survey/conf/language/lams/ApplicationResources_es_ES.properties (.../ApplicationResources_es_ES.properties) (revision 88f63737891cac3954ad9ff0892f08ac3efa0ffd) +++ lams_tool_survey/conf/language/lams/ApplicationResources_es_ES.properties (.../ApplicationResources_es_ES.properties) (revision 0012f4c60038db0a2c4754b641f95c24ddd0d84a) @@ -2,7 +2,7 @@ #language code: es #locale code: ES - # CVS ID: $Id$ Exported from the LAMS Community by Ernie Ghiglione on Thu Oct 30 14:01:30 CST 2014 + # CVS ID: $Id$ Exported from the LAMS Community by Ernie Ghiglione on Sun Mar 29 04:53:05 CST 2015 #=================== labels for Survey =================# @@ -185,6 +185,7 @@ label.sort.by.answer =Ordernar por respuesta label.other.answers =Respuestas de otros label.total.responses =N\u00famero de respuestas hasta ahora: {0} +message.no.reflection.available =No hay reflexi\u00f3n disponible. -#======= End labels: Exported 179 labels for es ES ===== +#======= End labels: Exported 180 labels for es ES ===== Index: lams_tool_survey/conf/language/lams/ApplicationResources_no_NO.properties =================================================================== diff -u -r29e5e45f817329acdbfdada05a424015f0b52c50 -r0012f4c60038db0a2c4754b641f95c24ddd0d84a --- lams_tool_survey/conf/language/lams/ApplicationResources_no_NO.properties (.../ApplicationResources_no_NO.properties) (revision 29e5e45f817329acdbfdada05a424015f0b52c50) +++ lams_tool_survey/conf/language/lams/ApplicationResources_no_NO.properties (.../ApplicationResources_no_NO.properties) (revision 0012f4c60038db0a2c4754b641f95c24ddd0d84a) @@ -2,7 +2,7 @@ #language code: no #locale code: NO - # CVS ID: $Id$ Exported from the LAMS Community by Ernie Ghiglione on Thu Oct 30 13:51:51 CST 2014 + # CVS ID: $Id$ Exported from the LAMS Community by Ernie Ghiglione on Thu Mar 12 12:44:13 CST 2015 #=================== labels for Survey =================# @@ -180,6 +180,11 @@ label.copy =Kopi label.submit =Avslutt label.monitoring.heading =Oppf\u00f8lging - oversikt +label.show.answers.from.other.users =Vis svarene fra andre studenter +label.view.all.responses =Se alle svar +label.sort.by.answer =Sorter etter svar +label.other.answers =Svar fra andre studenter +label.total.responses =Antall svar til n\u00e5: {0} -#======= End labels: Exported 174 labels for no NO ===== +#======= End labels: Exported 179 labels for no NO ===== Index: lams_tool_survey/conf/xdoclet/struts-actions.xml =================================================================== diff -u -r098d686653002409f33aff0f69b1183e07c1eab3 -r0012f4c60038db0a2c4754b641f95c24ddd0d84a --- lams_tool_survey/conf/xdoclet/struts-actions.xml (.../struts-actions.xml) (revision 098d686653002409f33aff0f69b1183e07c1eab3) +++ lams_tool_survey/conf/xdoclet/struts-actions.xml (.../struts-actions.xml) (revision 0012f4c60038db0a2c4754b641f95c24ddd0d84a) @@ -261,12 +261,20 @@ parameter="listAnswers" > + + - - + parameter="listReflections"> + + + getSessionAnswer(Long sessionId, Long questionUid); + + /** Get a count of the number of times this particular choice has been selected for this question. */ + Integer getAnswerCount(Long sessionId, Long questionUid, String choice); + List getByToolContentIdAndUserId(Long toolContentId, Long userId); List getOpenResponsesForTablesorter(final Long sessionId, final Long questionUid, int page, int size, Index: lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/dao/SurveyUserDAO.java =================================================================== diff -u -r098d686653002409f33aff0f69b1183e07c1eab3 -r0012f4c60038db0a2c4754b641f95c24ddd0d84a --- lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/dao/SurveyUserDAO.java (.../SurveyUserDAO.java) (revision 098d686653002409f33aff0f69b1183e07c1eab3) +++ lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/dao/SurveyUserDAO.java (.../SurveyUserDAO.java) (revision 0012f4c60038db0a2c4754b641f95c24ddd0d84a) @@ -25,6 +25,7 @@ import java.util.List; +import org.lamsfoundation.lams.notebook.service.ICoreNotebookService; import org.lamsfoundation.lams.tool.survey.model.SurveyUser; public interface SurveyUserDAO extends DAO { @@ -36,4 +37,13 @@ List getBySessionID(Long sessionId); int getCountFinishedUsers(Long sessionId); + + List getUsersForTablesorter(final Long sessionId, final Long questionId, int page, int size, + int sorting, String searchString); + int getCountUsersBySession(final Long sessionId, String searchString); + + List getStatisticsBySession(final Long contentId); + + List getUserReflectionsForTablesorter(final Long sessionId, int page, int size, int sorting, + String searchString, ICoreNotebookService coreNotebookService); } Index: lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/dao/hibernate/SurveyAnswerDAOHibernate.java =================================================================== diff -u -r4754486f832fd32e8456943aa277d7b65c7520af -r0012f4c60038db0a2c4754b641f95c24ddd0d84a --- lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/dao/hibernate/SurveyAnswerDAOHibernate.java (.../SurveyAnswerDAOHibernate.java) (revision 4754486f832fd32e8456943aa277d7b65c7520af) +++ lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/dao/hibernate/SurveyAnswerDAOHibernate.java (.../SurveyAnswerDAOHibernate.java) (revision 0012f4c60038db0a2c4754b641f95c24ddd0d84a) @@ -48,6 +48,11 @@ + SurveyAnswer.class.getName() + " AS r " + "WHERE r.user.session.sessionId=? AND r.surveyQuestion.uid=? AND r.answerText<>''"; + private static final String GET_COUNT_RESPONSES_FOR_SESSION_QUESTION_CHOICE = "SELECT COUNT(*) FROM " + + SurveyAnswer.class.getName() + " AS r " + + " WHERE r.user.session.sessionId=? AND r.surveyQuestion.uid=? " + + " AND ( r.answerChoices like ? OR r.answerChoices like ? )"; + @Override public SurveyAnswer getAnswer(Long questionUid, Long userUid) { List list = doFind(GET_LEARNER_ANSWER, new Object[] { questionUid, userUid }); @@ -69,27 +74,27 @@ new Object[] { toolContentId, userId }); } - @Override - public List getOpenResponsesForTablesorter(final Long sessionId, final Long questionUid, final int page, - final int size, final int sorting) { - String sortingOrder = ""; - switch (sorting) { - case SurveyConstants.SORT_BY_DEAFAULT: - sortingOrder = "r.updateDate"; - break; - case SurveyConstants.SORT_BY_ANSWER_ASC: - sortingOrder = "r.answerText ASC"; - break; - case SurveyConstants.SORT_BY_ANSWER_DESC: - sortingOrder = "r.answerText DESC"; - break; - } - final String sqlQuery = LOAD_ATTEMPT_FOR_SESSION_AND_QUESTION_LIMIT + sortingOrder; - - return (List) getSession().createQuery(sqlQuery).setLong("sessionId", sessionId.longValue()) - .setLong("questionUid", questionUid.longValue()).setFirstResult(page * size).setMaxResults(size).list(); + @Override + public List getOpenResponsesForTablesorter(final Long sessionId, final Long questionUid, int page, + int size, int sorting) { + String sortingOrder = ""; + switch (sorting) { + case SurveyConstants.SORT_BY_DEAFAULT: + sortingOrder = "r.updateDate"; + break; + case SurveyConstants.SORT_BY_ANSWER_ASC: + sortingOrder = "r.answerText ASC"; + break; + case SurveyConstants.SORT_BY_ANSWER_DESC: + sortingOrder = "r.answerText DESC"; + break; } + String sqlQuery = LOAD_ATTEMPT_FOR_SESSION_AND_QUESTION_LIMIT + sortingOrder; + return getSession().createQuery(sqlQuery).setLong("sessionId", sessionId.longValue()) + .setLong("questionUid", questionUid.longValue()).setFirstResult(page * size).setMaxResults(size).list(); + } + @Override public int getCountResponsesBySessionAndQuestion(final Long sessionId, final Long questionId) { @@ -100,4 +105,21 @@ } return ((Number) list.get(0)).intValue(); } + + /** Get a count of the number of times this particular choice has been selected for this question. */ + @SuppressWarnings("rawtypes") + public Integer getAnswerCount(Long sessionId, Long questionId, String choice) { + + String choice1 = choice+"&%"; + String choice2 = "%&"+choice1; + + String sql = GET_COUNT_RESPONSES_FOR_SESSION_QUESTION_CHOICE; + List list = doFind(sql, new Object[] { sessionId, questionId, choice1, choice2 }); + if (list == null || list.size() == 0) { + return 0; + } + return ((Number) list.get(0)).intValue(); + } + + } Index: lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/dao/hibernate/SurveyUserDAOHibernate.java =================================================================== diff -u -r4754486f832fd32e8456943aa277d7b65c7520af -r0012f4c60038db0a2c4754b641f95c24ddd0d84a --- lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/dao/hibernate/SurveyUserDAOHibernate.java (.../SurveyUserDAOHibernate.java) (revision 4754486f832fd32e8456943aa277d7b65c7520af) +++ lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/dao/hibernate/SurveyUserDAOHibernate.java (.../SurveyUserDAOHibernate.java) (revision 0012f4c60038db0a2c4754b641f95c24ddd0d84a) @@ -25,8 +25,16 @@ import java.util.List; +import org.apache.commons.lang.StringEscapeUtils; +import org.apache.commons.lang.StringUtils; +import org.hibernate.SQLQuery; +import org.hibernate.type.IntegerType; +import org.hibernate.type.StringType; import org.lamsfoundation.lams.dao.hibernate.LAMSBaseDAO; +import org.lamsfoundation.lams.notebook.service.ICoreNotebookService; +import org.lamsfoundation.lams.tool.survey.SurveyConstants; import org.lamsfoundation.lams.tool.survey.dao.SurveyUserDAO; +import org.lamsfoundation.lams.tool.survey.model.SurveySession; import org.lamsfoundation.lams.tool.survey.model.SurveyUser; import org.springframework.stereotype.Repository; @@ -70,4 +78,135 @@ return ((Number) list.get(0)).intValue(); } + private static final String FIND_USER_ANSWERS_BY_SESSION_ID = "SELECT user.*, answer.answer_choices answerChoices , answer.answer_text answerText" + + " FROM tl_lasurv11_user user " + + " JOIN tl_lasurv11_session session ON user.session_uid = session.uid and session.session_id = :sessionId " + + " LEFT JOIN tl_lasurv11_answer answer ON user.uid = answer.user_uid and answer.question_uid = :questionId "; + + @SuppressWarnings("unchecked") + /** Will return List<[SurveyUser, String, String], [SurveyUser, String, String], ... , [SurveyUser, String, String]> + * where the first String is answer choices (for multiple choice) and the second String is the answer text for + * free entry choice. + */ + public List getUsersForTablesorter(final Long sessionId, final Long questionId, int page, int size, + int sorting, String searchString) { + String sortingOrder; + switch (sorting) { + case SurveyConstants.SORT_BY_NAME_ASC: + sortingOrder = "user.last_name ASC, user.first_name ASC"; + break; + case SurveyConstants.SORT_BY_NAME_DESC: + sortingOrder = "user.last_name DESC, user.first_name DESC"; + break; + default: + sortingOrder = "user.uid"; + } + + // Basic select for the user records + StringBuilder queryText = new StringBuilder(FIND_USER_ANSWERS_BY_SESSION_ID); + + // If filtering by name add a name based where clause + buildNameSearch(searchString, queryText); + + // Now specify the sort based on the switch statement above. + queryText.append(" ORDER BY " + sortingOrder); + + SQLQuery query = getSession().createSQLQuery(queryText.toString()); + query.addEntity("user", SurveyUser.class) + .addScalar("answerChoices", StringType.INSTANCE) + .addScalar("answerText", StringType.INSTANCE) + .setLong("sessionId", sessionId.longValue()) + .setLong("questionId", questionId.longValue()) + .setFirstResult(page * size).setMaxResults(size); + return query.list(); + } + + private void buildNameSearch(String searchString, StringBuilder sqlBuilder) { + if (!StringUtils.isBlank(searchString)) { + String[] tokens = searchString.trim().split("\\s+"); + for (String token : tokens) { + String escToken = StringEscapeUtils.escapeSql(token); + sqlBuilder.append(" WHERE (user.first_name LIKE '%").append(escToken) + .append("%' OR user.last_name LIKE '%").append(escToken) + .append("%' OR user.login_name LIKE '%").append(escToken).append("%') "); + } + } + } + + @SuppressWarnings("rawtypes") + public int getCountUsersBySession(final Long sessionId, String searchString) { + + StringBuilder queryText = new StringBuilder("SELECT count(*) FROM tl_lasurv11_user user "); + queryText + .append(" JOIN tl_lasurv11_session session ON user.session_uid = session.uid and session.session_id = :sessionId"); + buildNameSearch(searchString, queryText); + + List list = getSession().createSQLQuery(queryText.toString()).setLong("sessionId", sessionId.longValue()) + .list(); + if (list == null || list.size() == 0) { + return 0; + } + return ((Number) list.get(0)).intValue(); + } + + @SuppressWarnings("unchecked") + /** Will return List<[SurveyUser, String (notebook entry)], [SurveyUser, String (notebook entry)], ... , [SurveyUser, String (notebook entry)]> + */ + public List getUserReflectionsForTablesorter(final Long sessionId, int page, int size, int sorting, + String searchString, ICoreNotebookService coreNotebookService) { + String sortingOrder; + switch (sorting) { + case SurveyConstants.SORT_BY_NAME_ASC: + sortingOrder = "user.last_name ASC, user.first_name ASC"; + break; + case SurveyConstants.SORT_BY_NAME_DESC: + sortingOrder = "user.last_name DESC, user.first_name DESC"; + break; + default: + sortingOrder = "user.uid"; + } + + // If the session uses notebook, then get the sql to join across to get the entries + String[] notebookEntryStrings = coreNotebookService.getNotebookEntrySQLStrings(sessionId.toString(), + SurveyConstants.TOOL_SIGNATURE, "user.user_id"); + + // Basic select for the user records + StringBuilder queryText = new StringBuilder(); + queryText.append("SELECT user.* "); + queryText.append(notebookEntryStrings[0]); + queryText.append(" FROM tl_lasurv11_user user "); + queryText + .append(" JOIN tl_lasurv11_session session ON user.session_uid = session.uid and session.session_id = :sessionId "); + + // Add the notebook join + queryText.append(notebookEntryStrings[1]); + + // If filtering by name add a name based where clause + buildNameSearch(searchString, queryText); + + // Now specify the sort based on the switch statement above. + queryText.append(" ORDER BY " + sortingOrder); + + SQLQuery query = getSession().createSQLQuery(queryText.toString()); + query.addEntity("user", SurveyUser.class).addScalar("notebookEntry", StringType.INSTANCE) + .setLong("sessionId", sessionId.longValue()).setFirstResult(page * size).setMaxResults(size); + return query.list(); + } + + private static final String GET_STATISTICS = "SELECT session.*, COUNT(*) numUsers " + + " FROM tl_lasurv11_session session, tl_lasurv11_survey survey, tl_lasurv11_user user " + + " WHERE survey.content_id = :contentId and session.survey_uid = survey.uid and user.session_uid = session.uid " + + " GROUP BY session.session_id"; + + @SuppressWarnings("unchecked") + /** Returns < [surveySession, numUsers] ... [surveySession, numUsers]> */ + public List getStatisticsBySession(final Long contentId) { + + SQLQuery query = getSession().createSQLQuery(GET_STATISTICS); + query.addEntity(SurveySession.class) + .addScalar("numUsers", IntegerType.INSTANCE) + .setLong("contentId", contentId); + return query.list(); + } + } Index: lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/service/ISurveyService.java =================================================================== diff -u -r1d63c45a130f0978753bcb9a5e38f409dd1df295 -r0012f4c60038db0a2c4754b641f95c24ddd0d84a --- lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/service/ISurveyService.java (.../ISurveyService.java) (revision 1d63c45a130f0978753bcb9a5e38f409dd1df295) +++ lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/service/ISurveyService.java (.../ISurveyService.java) (revision 0012f4c60038db0a2c4754b641f95c24ddd0d84a) @@ -30,6 +30,7 @@ import java.util.SortedMap; import org.lamsfoundation.lams.notebook.model.NotebookEntry; +import org.lamsfoundation.lams.notebook.service.ICoreNotebookService; import org.lamsfoundation.lams.tool.survey.dto.AnswerDTO; import org.lamsfoundation.lams.tool.survey.dto.ReflectDTO; import org.lamsfoundation.lams.tool.survey.model.Survey; @@ -280,6 +281,9 @@ */ Map> getReflectList(Long contentId, boolean setEntry); + List getUserReflectionsForTablesorter(final Long sessionId, int page, int size, int sorting, + String searchString); + void notifyTeachersOnAnswerSumbit(Long sessionId, SurveyUser surveyUser); /** @@ -301,4 +305,14 @@ * @return */ boolean isGroupedActivity(long toolContentID); + + /** Gets the Answer information for the monitoring listAnswers tablesorter. + * Will return List<[SurveyUser, String, String], [SurveyUser, String, String], ... , [SurveyUser, String, String]> + * where the first String is answer choices (for multiple choice) and the second String is the answer text for + * free entry choice. + */ + List getQuestionAnswersForTablesorter(Long sessionId, Long questionId, + int page, int size, int sorting, String searchString); + int getCountUsersBySession(final Long sessionId, String searchString); + } Index: lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/service/SurveyServiceImpl.java =================================================================== diff -u -r708bd4d049ae0a59d70c964ef2f864d2b7a352e6 -r0012f4c60038db0a2c4754b641f95c24ddd0d84a --- lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/service/SurveyServiceImpl.java (.../SurveyServiceImpl.java) (revision 708bd4d049ae0a59d70c964ef2f864d2b7a352e6) +++ lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/service/SurveyServiceImpl.java (.../SurveyServiceImpl.java) (revision 0012f4c60038db0a2c4754b641f95c24ddd0d84a) @@ -265,6 +265,11 @@ return map; } + public List getUserReflectionsForTablesorter(final Long sessionId, int page, int size, int sorting, + String searchString) { + return surveyUserDao.getUserReflectionsForTablesorter(sessionId, page, size, sorting, searchString, coreNotebookService); + } + @Override public Long createNotebookEntry(Long sessionId, Integer notebookToolType, String toolSignature, Integer userId, String entryText) { @@ -330,6 +335,18 @@ } @Override + public List getQuestionAnswersForTablesorter(Long sessionId, Long questionId, + int page, int size, int sorting, String searchString) { + + return surveyUserDao.getUsersForTablesorter(sessionId, questionId, page, size, sorting, searchString); + } + + @Override + public int getCountUsersBySession(final Long sessionId, String searchString) { + return surveyUserDao.getCountUsersBySession(sessionId, searchString); + } + + @Override public void updateAnswerList(List answerList) { for (SurveyAnswer ans : answerList) { surveyAnswerDao.saveObject(ans); @@ -341,70 +358,49 @@ SurveyQuestion question = surveyQuestionDao.getByUid(questionUid); AnswerDTO answerDto = new AnswerDTO(question); - // get question all answer from this session - List answsers = surveyAnswerDao.getSessionAnswer(sessionId, questionUid); + // create a map to hold Option UID and the counts for that choice + Map optMap = new HashMap(); - // create a map to hold Option UID and sequenceID(start from 0); - Map optMap = new HashMap(); + // total number of answers - used for the percentage calculations + int numberAnswers = 0; + + // go through all the choices and find out how many options for the choices. Set options = answerDto.getOptions(); - int idx = 0; for (SurveyOption option : options) { - optMap.put(option.getUid().toString(), idx); - idx++; + Long optUid = option.getUid(); + int numChoice = surveyAnswerDao.getAnswerCount(sessionId, questionUid, optUid.toString()); + optMap.put(optUid, numChoice); + numberAnswers += numChoice; } - // initial a array to hold how many time chose has been done for a option or open text. - int numberAvailableOptions = options.size(); - // for appendText and open Text Entry will be the last one of choose[] array. - if (answerDto.isAppendText() || (answerDto.getType() == SurveyConstants.QUESTION_TYPE_TEXT_ENTRY)) { - numberAvailableOptions++; + Integer numFreeChoice = null; + if ( answerDto.isAppendText() || (answerDto.getType() == SurveyConstants.QUESTION_TYPE_TEXT_ENTRY) ) { + numFreeChoice = getCountResponsesBySessionAndQuestion(sessionId, questionUid); + numberAnswers += numFreeChoice; } - int[] choiceArray = new int[numberAvailableOptions]; - Arrays.fill(choiceArray, 0); - - // sum up all option and open text (if has) have been selected count list - int numberAnswers = 0; - if (answsers != null) { - for (SurveyAnswer answer : answsers) { - String[] choiceList = SurveyWebUtils.getChoiceList(answer.getAnswerChoices()); - for (String optUid : choiceList) { - // if option has been chosen, the relative index of choose[] array will increase. - if (optMap.containsKey(optUid)) { - choiceArray[optMap.get(optUid)]++; - numberAnswers++; - } - } - // handle appendText or Open Text Entry - if ((answerDto.isAppendText() || (answerDto.getType() == SurveyConstants.QUESTION_TYPE_TEXT_ENTRY)) - && !StringUtils.isBlank(answer.getAnswerText())) { - choiceArray[numberAvailableOptions - 1]++; - numberAnswers++; - } - } - } - // caculate the percentage of answer response - idx = 0; + // calculate the percentage of answer response if (numberAnswers == 0) { numberAnswers = 1; } for (SurveyOption option : options) { - double percentage = ((double) choiceArray[idx] / (double) numberAnswers) * 100d; + int count = optMap.get(option.getUid()); + double percentage = ((double) count / (double) numberAnswers) * 100d; option.setResponse(percentage); option.setResponseFormatStr(new Long(Math.round(percentage)).toString()); - option.setResponseCount(choiceArray[idx]); - idx++; + option.setResponseCount(count); } - if (answerDto.isAppendText() || (answerDto.getType() == SurveyConstants.QUESTION_TYPE_TEXT_ENTRY)) { - double percentage = ((double) choiceArray[idx] / (double) numberAnswers) * 100d; + if (numFreeChoice != null) { + double percentage = ((double) numFreeChoice / (double) numberAnswers) * 100d; answerDto.setOpenResponse(percentage); answerDto.setOpenResponseFormatStr(new Long(Math.round(percentage)).toString()); - answerDto.setOpenResponseCount(choiceArray[idx]); + answerDto.setOpenResponseCount(numFreeChoice); } return answerDto; } + @Override public List getOpenResponsesForTablesorter(final Long qaSessionId, final Long questionId, int page, int size, int sorting) { @@ -442,16 +438,13 @@ @Override public SortedMap getStatistic(Long contentId) { SortedMap result = new TreeMap(new SurveySessionComparator()); - List sessionList = surveySessionDao.getByContentId(contentId); - if (sessionList == null) { - return result; + + List stats = surveyUserDao.getStatisticsBySession(contentId); + for ( Object[] stat : stats) { + SurveySession session = (SurveySession) stat[0]; + Integer numUsers = (Integer) stat[1]; + result.put(session,numUsers); } - - for (SurveySession session : sessionList) { - List users = getSessionUsers(session.getSessionId()); - result.put(session, users != null ? users.size() : 0); - } - return result; } Index: lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/web/action/MonitoringAction.java =================================================================== diff -u -r1d63c45a130f0978753bcb9a5e38f409dd1df295 -r0012f4c60038db0a2c4754b641f95c24ddd0d84a --- lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/web/action/MonitoringAction.java (.../MonitoringAction.java) (revision 1d63c45a130f0978753bcb9a5e38f409dd1df295) +++ lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/web/action/MonitoringAction.java (.../MonitoringAction.java) (revision 0012f4c60038db0a2c4754b641f95c24ddd0d84a) @@ -28,19 +28,18 @@ import java.io.PrintWriter; import java.util.Date; import java.util.List; -import java.util.Map; import java.util.Map.Entry; import java.util.Set; import java.util.SortedMap; import java.util.TimeZone; -import java.util.TreeMap; import javax.servlet.ServletException; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; +import org.apache.commons.lang.StringEscapeUtils; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; import org.apache.poi.ss.usermodel.Cell; @@ -53,18 +52,17 @@ import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.action.ActionMessage; -import org.lamsfoundation.lams.notebook.model.NotebookEntry; -import org.lamsfoundation.lams.notebook.service.CoreNotebookConstants; +import org.apache.tomcat.util.json.JSONArray; +import org.apache.tomcat.util.json.JSONException; +import org.apache.tomcat.util.json.JSONObject; import org.lamsfoundation.lams.tool.survey.SurveyConstants; import org.lamsfoundation.lams.tool.survey.dto.AnswerDTO; -import org.lamsfoundation.lams.tool.survey.dto.ReflectDTO; import org.lamsfoundation.lams.tool.survey.model.Survey; import org.lamsfoundation.lams.tool.survey.model.SurveyOption; import org.lamsfoundation.lams.tool.survey.model.SurveyQuestion; import org.lamsfoundation.lams.tool.survey.model.SurveySession; import org.lamsfoundation.lams.tool.survey.model.SurveyUser; import org.lamsfoundation.lams.tool.survey.service.ISurveyService; -import org.lamsfoundation.lams.tool.survey.util.SurveyUserComparator; import org.lamsfoundation.lams.tool.survey.util.SurveyWebUtils; import org.lamsfoundation.lams.usermanagement.dto.UserDTO; import org.lamsfoundation.lams.util.DateUtil; @@ -89,7 +87,7 @@ @Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws IOException, ServletException { + HttpServletResponse response) throws IOException, ServletException, JSONException { String param = mapping.getParameter(); if (param.equals("summary")) { @@ -99,10 +97,16 @@ if (param.equals("listAnswers")) { return listAnswers(mapping, form, request, response); } + if (param.equals("getAnswersJSON")) { + return getAnswersJSON(mapping, form, request, response); + } - if (param.equals("viewReflection")) { - return viewReflection(mapping, form, request, response); + if (param.equals("listReflections")) { + return listReflections(mapping, form, request, response); } + if (param.equals("getReflectionsJSON")) { + return getReflectionsJSON(mapping, form, request, response); + } if (param.equals("exportSurvey")) { return exportSurvey(mapping, form, request, response); @@ -144,7 +148,7 @@ Long contentId = WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_CONTENT_ID); ISurveyService service = getSurveyService(); - // get summary + // get summary SortedMap> summary = service.getSummary(contentId); // get survey @@ -153,16 +157,12 @@ // get statistic SortedMap statis = service.getStatistic(contentId); - // get refection list - Map> relectList = service.getReflectList(contentId, false); - // cache into sessionMap sessionMap.put(SurveyConstants.ATTR_SUMMARY_LIST, summary); sessionMap.put(SurveyConstants.ATTR_STATISTIC_LIST, statis); sessionMap.put(SurveyConstants.PAGE_EDITABLE, new Boolean(SurveyWebUtils.isSurveyEditable(survey))); sessionMap.put(SurveyConstants.ATTR_SURVEY, survey); sessionMap.put(AttributeNames.PARAM_TOOL_CONTENT_ID, contentId); - sessionMap.put(SurveyConstants.ATTR_REFLECT_LIST, relectList); sessionMap.put(SurveyConstants.ATTR_IS_GROUPED_ACTIVITY, service.isGroupedActivity(contentId)); // check if there is submission deadline @@ -189,52 +189,124 @@ // get user list ISurveyService service = getSurveyService(); + SurveyQuestion question = service.getQuestion(questionUid); + request.setAttribute(SurveyConstants.ATTR_QUESTION, question); + request.setAttribute(AttributeNames.PARAM_TOOL_SESSION_ID, sessionId); + return mapping.findForward(SurveyConstants.SUCCESS); + } + private ActionForward getAnswersJSON(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws JSONException, IOException { + + Long sessionId = WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_SESSION_ID); + Long questionUid = WebUtil.readLongParam(request, SurveyConstants.ATTR_QUESTION_UID); - SortedMap userAnswerMap = new TreeMap(new SurveyUserComparator()); - // get all users with their answers whatever they answer or not - List users = service.getSessionUsers(sessionId); - for (SurveyUser user : users) { - List questionAnswers = service.getQuestionAnswers(sessionId, user.getUid()); - for (AnswerDTO questionAnswer : questionAnswers) { - if (questionUid.equals(questionAnswer.getUid())) { - userAnswerMap.put(user, questionAnswer); - break; + // paging parameters of tablesorter + int size = WebUtil.readIntParam(request, "size"); + int page = WebUtil.readIntParam(request, "page"); + Integer sortByName = WebUtil.readIntParam(request, "column[0]", true); + String searchString = request.getParameter("fcol[0]"); + + int sorting = SurveyConstants.SORT_BY_DEAFAULT; + if ( sortByName != null ) + sorting = sortByName.equals(0) ? SurveyConstants.SORT_BY_NAME_ASC : SurveyConstants.SORT_BY_NAME_DESC; + + //return user list according to the given sessionID + ISurveyService service = getSurveyService(); + SurveyQuestion question = service.getQuestion(questionUid); + List users = service.getQuestionAnswersForTablesorter(sessionId, questionUid, page, size, sorting, searchString); + + JSONArray rows = new JSONArray(); + JSONObject responsedata = new JSONObject(); + responsedata.put("total_rows", service.getCountUsersBySession(sessionId, searchString)); + + for (Object[] userAndAnswers: users) { + + JSONObject responseRow = new JSONObject(); + + SurveyUser user = (SurveyUser) userAndAnswers[0]; + responseRow.put(SurveyConstants.ATTR_USER_NAME, StringEscapeUtils.escapeHtml(user.getLastName() + " " + user.getFirstName())); + + if ( userAndAnswers.length > 1 && userAndAnswers[1] != null) { + responseRow.put("choices", SurveyWebUtils.getChoiceList((String)userAndAnswers[1])); + } + if ( userAndAnswers.length > 2 && userAndAnswers[2] != null) { + // Data is handled differently in learner depending on whether it is an extra text added + // to a multiple choice, or a free text entry. So need to handle the output differently. + // See learner/result.jsp and its handling of question.type == 3 vs question.appendText + String answer; + if ( question.getType() == SurveyConstants.QUESTION_TYPE_TEXT_ENTRY ) { + // don't escape as it was escaped & BR'd before saving + answer = (String)userAndAnswers[2]; + } else { + // need to escape it, as it isn't escaped in the database + answer = StringEscapeUtils.escapeHtml((String)userAndAnswers[2]); + answer = answer.replaceAll("\n", "
"); } - } + responseRow.put("answerText", answer); + } + rows.put(responseRow); } - // set all attribute to request for show - request.setAttribute(SurveyConstants.ATTR_ANSWER_LIST, userAnswerMap); - - return mapping.findForward(SurveyConstants.SUCCESS); + responsedata.put("rows", rows); + response.setContentType("application/json;charset=utf-8"); + response.getWriter().print(new String(responsedata.toString())); + return null; } - private ActionForward viewReflection(ActionMapping mapping, ActionForm form, HttpServletRequest request, + private ActionForward listReflections(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { - Long uid = WebUtil.readLongParam(request, SurveyConstants.ATTR_USER_UID); - Long sessionID = WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_SESSION_ID); + Long sessionId = WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_SESSION_ID); + + ISurveyService service = getSurveyService(); + Survey survey = service.getSurveyBySessionId(sessionId); + + request.setAttribute(AttributeNames.PARAM_TOOL_SESSION_ID, sessionId); + return mapping.findForward(SurveyConstants.SUCCESS); + } + + private ActionForward getReflectionsJSON(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws JSONException, IOException { + + Long sessionId = WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_SESSION_ID); + // paging parameters of tablesorter + int size = WebUtil.readIntParam(request, "size"); + int page = WebUtil.readIntParam(request, "page"); + Integer sortByName = WebUtil.readIntParam(request, "column[0]", true); + String searchString = request.getParameter("fcol[0]"); + + int sorting = SurveyConstants.SORT_BY_DEAFAULT; + if ( sortByName != null ) + sorting = sortByName.equals(0) ? SurveyConstants.SORT_BY_NAME_ASC : SurveyConstants.SORT_BY_NAME_DESC; + + //return user list according to the given sessionID ISurveyService service = getSurveyService(); - SurveyUser user = service.getUser(uid); - NotebookEntry notebookEntry = service.getEntry(sessionID, CoreNotebookConstants.NOTEBOOK_TOOL, - SurveyConstants.TOOL_SIGNATURE, user.getUserId().intValue()); + List users = service.getUserReflectionsForTablesorter(sessionId, page, size, sorting, searchString); + + JSONArray rows = new JSONArray(); + JSONObject responsedata = new JSONObject(); + responsedata.put("total_rows", service.getCountUsersBySession(sessionId, searchString)); - SurveySession session = service.getSurveySessionBySessionId(sessionID); + for (Object[] userAndReflection : users) { - ReflectDTO refDTO = new ReflectDTO(user); - if (notebookEntry == null) { - refDTO.setFinishReflection(false); - refDTO.setReflect(null); - } else { - refDTO.setFinishReflection(true); - refDTO.setReflect(notebookEntry.getEntry()); - } - refDTO.setReflectInstrctions(session.getSurvey().getReflectInstructions()); + JSONObject responseRow = new JSONObject(); + + SurveyUser user = (SurveyUser) userAndReflection[0]; + responseRow.put(SurveyConstants.ATTR_USER_NAME, StringEscapeUtils.escapeHtml(user.getLastName() + " " + user.getFirstName())); - request.setAttribute("userDTO", refDTO); - return mapping.findForward("success"); + if ( userAndReflection.length > 1 && userAndReflection[1] != null) { + String reflection = StringEscapeUtils.escapeHtml((String)userAndReflection[1]); + responseRow.put(SurveyConstants.ATTR_REFLECTION, reflection.replaceAll("\n", "
")); + } + + rows.put(responseRow); + } + responsedata.put("rows", rows); + response.setContentType("application/json;charset=utf-8"); + response.getWriter().print(new String(responsedata.toString())); + return null; } - + /** * Export Excel format survey data. * Index: lams_tool_survey/web/pages/monitoring/listanswers.jsp =================================================================== diff -u -r098d686653002409f33aff0f69b1183e07c1eab3 -r0012f4c60038db0a2c4754b641f95c24ddd0d84a --- lams_tool_survey/web/pages/monitoring/listanswers.jsp (.../listanswers.jsp) (revision 098d686653002409f33aff0f69b1183e07c1eab3) +++ lams_tool_survey/web/pages/monitoring/listanswers.jsp (.../listanswers.jsp) (revision 0012f4c60038db0a2c4754b641f95c24ddd0d84a) @@ -7,106 +7,204 @@ <%@ include file="/common/header.jsp" %> + + + + + + + + + - +

- - - - <%-- display question header --%> - -

- - - <%-- --%> - - - <%-- - - - - --%> +

+ +
+ + + + + + + + + + + + + + + +
+ <%= SurveyConstants.OPTION_SHORT_HEADER %>${optStatus.count} + + +
+ +  
+ +

+ + + + width="25%" + + + + + + +
+ + + + - - - - + - - - - - + + - -
+ +
- <%= SurveyConstants.OPTION_SHORT_HEADER %>${optStatus.count} - - -
+ <%= SurveyConstants.OPTION_SHORT_HEADER %>${optStatus.count} +
- -  
+ +
- <%-- End first check --%> - - -

-
- - - - - - - - - - - - <%-- User answer list --%> - - - - - - - - - - -
- <%= SurveyConstants.OPTION_SHORT_HEADER %>${optStatus.count} - - -
${user.loginName} - - - - - - - - - "> - - -   - - - - -   -
-
- <%-- End first check --%> -
- + + + + + + + +
+
+ + + + + + +
-
+
Index: lams_tool_survey/web/pages/monitoring/listreflections.jsp =================================================================== diff -u --- lams_tool_survey/web/pages/monitoring/listreflections.jsp (revision 0) +++ lams_tool_survey/web/pages/monitoring/listreflections.jsp (revision 0012f4c60038db0a2c4754b641f95c24ddd0d84a) @@ -0,0 +1,125 @@ + + +<%@ include file="/common/taglibs.jsp"%> + +<%@ page import="org.lamsfoundation.lams.tool.survey.SurveyConstants"%> + + + <%@ include file="/common/header.jsp" %> + + + + + + + + + + +
+

+ +
+ + + + + + + + + +
+ + +
+
+ + + + + + +
+
+
+ +
+ +
Fisheye: Tag 0012f4c60038db0a2c4754b641f95c24ddd0d84a refers to a dead (removed) revision in file `lams_tool_survey/web/pages/monitoring/notebook.jsp'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_tool_survey/web/pages/monitoring/summary.jsp =================================================================== diff -u -r0cf0d00e80ef05535a52247a471dd7db8d566fac -r0012f4c60038db0a2c4754b641f95c24ddd0d84a --- lams_tool_survey/web/pages/monitoring/summary.jsp (.../summary.jsp) (revision 0cf0d00e80ef05535a52247a471dd7db8d566fac) +++ lams_tool_survey/web/pages/monitoring/summary.jsp (.../summary.jsp) (revision 0012f4c60038db0a2c4754b641f95c24ddd0d84a) @@ -95,7 +95,7 @@ + onclick="javascript:drawChart('pie', 'chartDiv${surveySession.sessionId}_${queStatus.index}', '${chartURL}')"> @@ -120,7 +120,7 @@ - + @@ -152,55 +152,16 @@ - <%-- Reflection list --%> - - - - - - - - - - - - - - - - - - - - -
-

-
- - - - - -
- - - - - - - - - - -
-
-
-
-
+ + + + + +