Index: lams_tool_survey/conf/language/lams/ApplicationResources.properties =================================================================== diff -u -r73dcdda0fa796b4314929e175d161f7d0c400c94 -rb7ba7cccd2f8027169900a05b8799d3287429c4e --- lams_tool_survey/conf/language/lams/ApplicationResources.properties (.../ApplicationResources.properties) (revision 73dcdda0fa796b4314929e175d161f7d0c400c94) +++ lams_tool_survey/conf/language/lams/ApplicationResources.properties (.../ApplicationResources.properties) (revision b7ba7cccd2f8027169900a05b8799d3287429c4e) @@ -186,6 +186,6 @@ label.other.answers =Answers from other Learners label.total.responses =Total responses so far: {0} message.no.reflection.available =No notebook entry has been added. +label.search=Search... - #======= End labels: Exported 180 labels for en AU ===== Index: lams_tool_survey/conf/xdoclet/struts-actions.xml =================================================================== diff -u -r19c53ce28433c0e4d47c5f303be3e658c808329c -rb7ba7cccd2f8027169900a05b8799d3287429c4e --- lams_tool_survey/conf/xdoclet/struts-actions.xml (.../struts-actions.xml) (revision 19c53ce28433c0e4d47c5f303be3e658c808329c) +++ lams_tool_survey/conf/xdoclet/struts-actions.xml (.../struts-actions.xml) (revision b7ba7cccd2f8027169900a05b8799d3287429c4e) @@ -261,7 +261,16 @@ parameter="listAnswers" > + + + + + Index: lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/SurveyConstants.java =================================================================== diff -u -r19c53ce28433c0e4d47c5f303be3e658c808329c -rb7ba7cccd2f8027169900a05b8799d3287429c4e --- lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/SurveyConstants.java (.../SurveyConstants.java) (revision 19c53ce28433c0e4d47c5f303be3e658c808329c) +++ lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/SurveyConstants.java (.../SurveyConstants.java) (revision b7ba7cccd2f8027169900a05b8799d3287429c4e) @@ -65,6 +65,8 @@ public static final String ATTR_USER = "user"; + public static final String ATTR_USER_NAME = "userName"; + // error message keys public static final String ERROR_MSG_TITLE_BLANK = "error.survey.item.title.blank"; @@ -118,8 +120,6 @@ public static final String ATTR_QUESTION_LIST = "questionList"; - public static final String ATTR_ANSWER_LIST = "answerList"; - public static final String ATTR_QUESTION = "question"; public static final String ATTR_DELETED_QUESTION_LIST = "deletedQuestionList"; @@ -169,10 +169,12 @@ public static final String ATTR_IS_GROUPED_ACTIVITY = "isGroupedActivity"; public static final String ATTR_COUNT_FINISHED_USERS = "countFinishedUser"; - + public static final int SORT_BY_DEAFAULT = 0; public static final int SORT_BY_ANSWER_ASC = 1; public static final int SORT_BY_ANSWER_DESC = 2; + public static final int SORT_BY_NAME_ASC = 3; + public static final int SORT_BY_NAME_DESC = 4; // POSITION public static int POSITION_INSIDE = 0; Index: lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/dao/SurveyAnswerDAO.java =================================================================== diff -u -r19c53ce28433c0e4d47c5f303be3e658c808329c -rb7ba7cccd2f8027169900a05b8799d3287429c4e --- lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/dao/SurveyAnswerDAO.java (.../SurveyAnswerDAO.java) (revision 19c53ce28433c0e4d47c5f303be3e658c808329c) +++ lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/dao/SurveyAnswerDAO.java (.../SurveyAnswerDAO.java) (revision b7ba7cccd2f8027169900a05b8799d3287429c4e) @@ -24,7 +24,6 @@ import java.util.List; -import org.lamsfoundation.lams.tool.survey.SurveyConstants; import org.lamsfoundation.lams.tool.survey.model.SurveyAnswer; public interface SurveyAnswerDAO extends DAO { @@ -39,7 +38,11 @@ * @return */ List 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 -r19c53ce28433c0e4d47c5f303be3e658c808329c -rb7ba7cccd2f8027169900a05b8799d3287429c4e --- lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/dao/SurveyUserDAO.java (.../SurveyUserDAO.java) (revision 19c53ce28433c0e4d47c5f303be3e658c808329c) +++ lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/dao/SurveyUserDAO.java (.../SurveyUserDAO.java) (revision b7ba7cccd2f8027169900a05b8799d3287429c4e) @@ -36,4 +36,8 @@ 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); } Index: lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/dao/hibernate/SurveyAnswerDAOHibernate.java =================================================================== diff -u -r19c53ce28433c0e4d47c5f303be3e658c808329c -rb7ba7cccd2f8027169900a05b8799d3287429c4e --- lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/dao/hibernate/SurveyAnswerDAOHibernate.java (.../SurveyAnswerDAOHibernate.java) (revision 19c53ce28433c0e4d47c5f303be3e658c808329c) +++ lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/dao/hibernate/SurveyAnswerDAOHibernate.java (.../SurveyAnswerDAOHibernate.java) (revision b7ba7cccd2f8027169900a05b8799d3287429c4e) @@ -45,6 +45,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 = getHibernateTemplate().find(GET_LEARNER_ANSWER, new Object[] { questionUid, userUid }); @@ -96,4 +101,22 @@ } 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 = getHibernateTemplate().find(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 -r19c53ce28433c0e4d47c5f303be3e658c808329c -rb7ba7cccd2f8027169900a05b8799d3287429c4e --- lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/dao/hibernate/SurveyUserDAOHibernate.java (.../SurveyUserDAOHibernate.java) (revision 19c53ce28433c0e4d47c5f303be3e658c808329c) +++ lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/dao/hibernate/SurveyUserDAOHibernate.java (.../SurveyUserDAOHibernate.java) (revision b7ba7cccd2f8027169900a05b8799d3287429c4e) @@ -25,6 +25,11 @@ import java.util.List; +import org.apache.commons.lang.StringEscapeUtils; +import org.apache.commons.lang.StringUtils; +import org.hibernate.Hibernate; +import org.hibernate.SQLQuery; +import org.lamsfoundation.lams.tool.survey.SurveyConstants; import org.lamsfoundation.lams.tool.survey.dao.SurveyUserDAO; import org.lamsfoundation.lams.tool.survey.model.SurveyUser; @@ -66,4 +71,75 @@ 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", Hibernate.STRING) + .addScalar("answerText", Hibernate.STRING) + .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(); + } + } Index: lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/dto/SimpleAnswerDTO.java =================================================================== diff -u --- lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/dto/SimpleAnswerDTO.java (revision 0) +++ lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/dto/SimpleAnswerDTO.java (revision b7ba7cccd2f8027169900a05b8799d3287429c4e) @@ -0,0 +1,125 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ +package org.lamsfoundation.lams.tool.survey.dto; + +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; + +import org.apache.commons.beanutils.PropertyUtils; +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; +import org.lamsfoundation.lams.tool.survey.model.SurveyAnswer; +import org.lamsfoundation.lams.tool.survey.model.SurveyOption; +import org.lamsfoundation.lams.tool.survey.model.SurveyQuestion; +import org.lamsfoundation.lams.tool.survey.model.SurveyUser; +import org.lamsfoundation.lams.tool.survey.util.SurveyOptionComparator; + +public class SimpleAnswerDTO extends SurveyQuestion { + + private static final int SHORT_TITLE_LENGTH = 60; + + // *********************************************** + // DTO fields: + // this is DTO field. For answer, which is user and session level. For question, which is content level. + private SurveyAnswer answer; + // Open text entry response percentage if this question has open text entry. + private double openResponse; + private String openResponseFormatStr; + private int openResponseCount; + + // this field could have value even this user does not reply this question (the answer is null) + private SurveyUser replier; + + private static Logger logger = Logger.getLogger(SimpleAnswerDTO.class.getName()); + + public SimpleAnswerDTO(SurveyQuestion question) { + try { + PropertyUtils.copyProperties(this, question); + } catch (Exception e) { + logger.error("Error occurs during creating AnswerDTO"); + } + + // clone options + Set optList = question.getOptions(); + if (optList != null) { + SortedSet newOptions = new TreeSet(new SurveyOptionComparator()); + for (SurveyOption option : optList) { + SurveyOption newOption = (SurveyOption) option.clone(); + // clone does not copy the UID, here copy it back + newOption.setUid(option.getUid()); + newOptions.add(newOption); + } + this.setOptions(newOptions); + } + + String desc = this.getDescription(); + desc = desc.replaceAll("<(.|\n)*?>", ""); + this.setShortTitle(StringUtils.abbreviate(desc, SHORT_TITLE_LENGTH)); + + } + + // **************************************************************** + // DTO fields + // **************************************************************** + public SurveyAnswer getAnswer() { + return answer; + } + + public void setAnswer(SurveyAnswer answer) { + this.answer = answer; + } + + public double getOpenResponse() { + return openResponse; + } + + public void setOpenResponse(double openResponse) { + this.openResponse = openResponse; + } + + public int getOpenResponseCount() { + return openResponseCount; + } + + public void setOpenResponseCount(int openResponseCount) { + this.openResponseCount = openResponseCount; + } + + public String getOpenResponseFormatStr() { + return openResponseFormatStr; + } + + public void setOpenResponseFormatStr(String openResponseFormatStr) { + this.openResponseFormatStr = openResponseFormatStr; + } + + public SurveyUser getReplier() { + return replier; + } + + public void setReplier(SurveyUser replier) { + this.replier = replier; + } + +} Index: lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/service/ISurveyService.java =================================================================== diff -u -re980ad9a6281fd10d7935a7840ddfa200c5427ac -rb7ba7cccd2f8027169900a05b8799d3287429c4e --- lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/service/ISurveyService.java (.../ISurveyService.java) (revision e980ad9a6281fd10d7935a7840ddfa200c5427ac) +++ lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/service/ISurveyService.java (.../ISurveyService.java) (revision b7ba7cccd2f8027169900a05b8799d3287429c4e) @@ -280,6 +280,16 @@ */ Map> getReflectList(Long contentId, boolean setEntry); + /** + * Get Reflect DTO set for session. Called by getReflectList(contentId, setEntry) so has same + * effect as calling getReflectList(contentId, setEntry) + * and pulling out a single session. + * + * @param contentId + * @return + */ + Set getReflectList(Long sessionId, boolean setEntry, boolean hasReflection); + void notifyTeachersOnAnswerSumbit(Long sessionId, SurveyUser surveyUser); /** @@ -301,4 +311,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 -r9aad33f52b06632e7a8ed3705a7708338bcc00f8 -rb7ba7cccd2f8027169900a05b8799d3287429c4e --- lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/service/SurveyServiceImpl.java (.../SurveyServiceImpl.java) (revision 9aad33f52b06632e7a8ed3705a7708338bcc00f8) +++ lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/service/SurveyServiceImpl.java (.../SurveyServiceImpl.java) (revision b7ba7cccd2f8027169900a05b8799d3287429c4e) @@ -241,31 +241,37 @@ List sessionList = surveySessionDao.getByContentId(contentId); for (SurveySession session : sessionList) { Long sessionId = session.getSessionId(); - boolean hasRefection = session.getSurvey().isReflectOnActivity(); - Set list = new TreeSet(new ReflectDTOComparator()); - // get all users in this session - List users = surveyUserDao.getBySessionID(sessionId); - for (SurveyUser user : users) { - ReflectDTO ref = new ReflectDTO(user); - - if (setEntry) { - NotebookEntry entry = getEntry(sessionId, CoreNotebookConstants.NOTEBOOK_TOOL, - SurveyConstants.TOOL_SIGNATURE, user.getUserId().intValue()); - if (entry != null) { - ref.setReflect(entry.getEntry()); - } - } - - ref.setHasRefection(hasRefection); - list.add(ref); - } + boolean hasReflection = session.getSurvey().isReflectOnActivity(); + Set list = getReflectList(sessionId, setEntry, hasReflection); map.put(sessionId, list); } return map; } @Override + public Set getReflectList(Long sessionId, boolean setEntry, boolean hasReflection) { + Set list = new TreeSet(new ReflectDTOComparator()); + // get all users in this session + List users = surveyUserDao.getBySessionID(sessionId); + for (SurveyUser user : users) { + ReflectDTO ref = new ReflectDTO(user); + + if (setEntry) { + NotebookEntry entry = getEntry(sessionId, CoreNotebookConstants.NOTEBOOK_TOOL, + SurveyConstants.TOOL_SIGNATURE, user.getUserId().intValue()); + if (entry != null) { + ref.setReflect(entry.getEntry()); + } + } + + ref.setHasRefection(hasReflection); + list.add(ref); + } + return list; + } + + @Override public Long createNotebookEntry(Long sessionId, Integer notebookToolType, String toolSignature, Integer userId, String entryText) { return coreNotebookService.createNotebookEntry(sessionId, notebookToolType, toolSignature, userId, "", @@ -330,6 +336,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 +359,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) { Index: lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/web/action/MonitoringAction.java =================================================================== diff -u -re980ad9a6281fd10d7935a7840ddfa200c5427ac -rb7ba7cccd2f8027169900a05b8799d3287429c4e --- lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/web/action/MonitoringAction.java (.../MonitoringAction.java) (revision e980ad9a6281fd10d7935a7840ddfa200c5427ac) +++ lams_tool_survey/src/java/org/lamsfoundation/lams/tool/survey/web/action/MonitoringAction.java (.../MonitoringAction.java) (revision b7ba7cccd2f8027169900a05b8799d3287429c4e) @@ -33,14 +33,14 @@ 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,6 +53,9 @@ import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import org.apache.struts.action.ActionMessage; +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.notebook.model.NotebookEntry; import org.lamsfoundation.lams.notebook.service.CoreNotebookConstants; import org.lamsfoundation.lams.tool.survey.SurveyConstants; @@ -64,7 +67,6 @@ 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 +91,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,7 +101,13 @@ if (param.equals("listAnswers")) { return listAnswers(mapping, form, request, response); } + if (param.equals("getAnswersJSON")) { + return getAnswersJSON(mapping, form, request, response); + } + if (param.equals("listReflections")) { + return listReflections(mapping, form, request, response); + } if (param.equals("viewReflection")) { return viewReflection(mapping, form, request, response); } @@ -144,7 +152,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 +161,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,25 +193,70 @@ // 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(); + 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[] userAndReflection : users) { + + JSONObject responseRow = new JSONObject(); + + SurveyUser user = (SurveyUser) userAndReflection[0]; + responseRow.put(SurveyConstants.ATTR_USER_NAME, StringEscapeUtils.escapeHtml(user.getLastName() + " " + user.getFirstName())); + + if ( userAndReflection.length > 1 && userAndReflection[1] != null) { + responseRow.put("choices", SurveyWebUtils.getChoiceList((String)userAndReflection[1])); + } + if ( userAndReflection.length > 2 && userAndReflection[2] != null) { + responseRow.put("answerText", StringEscapeUtils.escapeHtml((String)userAndReflection[2])); + } + rows.put(responseRow); } - // set all attribute to request for show - request.setAttribute(SurveyConstants.ATTR_ANSWER_LIST, userAnswerMap); + responsedata.put("rows", rows); + response.setContentType("application/json;charset=utf-8"); + response.getWriter().print(new String(responsedata.toString())); + return null; + } + private ActionForward listReflections(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + + Long sessionId = WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_SESSION_ID); + + ISurveyService service = getSurveyService(); + Survey survey = service.getSurveyBySessionId(sessionId); + + Set reflectList = getSurveyService().getReflectList(sessionId, false, survey.isReflectOnActivity()); + request.setAttribute(SurveyConstants.ATTR_REFLECT_LIST, reflectList); + request.setAttribute(AttributeNames.PARAM_TOOL_SESSION_ID, sessionId); return mapping.findForward(SurveyConstants.SUCCESS); } - + private ActionForward viewReflection(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { Index: lams_tool_survey/web/pages/monitoring/listanswers.jsp =================================================================== diff -u -rc9845f2002ce96c641bb4334b237ef4744cd83c4 -rb7ba7cccd2f8027169900a05b8799d3287429c4e --- lams_tool_survey/web/pages/monitoring/listanswers.jsp (.../listanswers.jsp) (revision c9845f2002ce96c641bb4334b237ef4744cd83c4) +++ lams_tool_survey/web/pages/monitoring/listanswers.jsp (.../listanswers.jsp) (revision b7ba7cccd2f8027169900a05b8799d3287429c4e) @@ -7,106 +7,199 @@ <%@ 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 b7ba7cccd2f8027169900a05b8799d3287429c4e) @@ -0,0 +1,47 @@ + + +<%@ include file="/common/taglibs.jsp"%> + +<%@ page import="org.lamsfoundation.lams.tool.survey.SurveyConstants"%> + + + <%@ include file="/common/header.jsp" %> + + +
+

+ + <%-- Reflection list --%> + +

+
+ + + + + + + + + + + + + + + + +
+ + + + + +
+
+
+ +
+ +
Index: lams_tool_survey/web/pages/monitoring/summary.jsp =================================================================== diff -u -r8a78ed9d4fddacbbbe874998c08d2138ebd0917b -rb7ba7cccd2f8027169900a05b8799d3287429c4e --- lams_tool_survey/web/pages/monitoring/summary.jsp (.../summary.jsp) (revision 8a78ed9d4fddacbbbe874998c08d2138ebd0917b) +++ lams_tool_survey/web/pages/monitoring/summary.jsp (.../summary.jsp) (revision b7ba7cccd2f8027169900a05b8799d3287429c4e) @@ -152,55 +152,16 @@ - <%-- Reflection list --%> - - - - - - - - - - - - - - - - - - - - -
-

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