Index: lams_tool_scratchie/conf/language/lams/ApplicationResources_en_AU.properties =================================================================== diff -u -reab67f278cfa906781648c1742095e4bfb57b39c -rbc65717cc947dfd5b941ab4ac8f31a59c8f68bf4 --- lams_tool_scratchie/conf/language/lams/ApplicationResources_en_AU.properties (.../ApplicationResources_en_AU.properties) (revision eab67f278cfa906781648c1742095e4bfb57b39c) +++ lams_tool_scratchie/conf/language/lams/ApplicationResources_en_AU.properties (.../ApplicationResources_en_AU.properties) (revision bc65717cc947dfd5b941ab4ac8f31a59c8f68bf4) @@ -107,3 +107,13 @@ label.mark =Mark label.attempts =Attempts label.choice.number =Choice #{0} +label.group.leader =Group Leader: {0} +label.are.you.going.to.be.leader =Are you going to be a leader of this group? +label.leader.selection =Leader selection +label.users.from.group =Other users participating in current group: +label.yes.become.leader =Yes, I want to become a leader +label.no =No +label.refresh =Refresh +label.waiting.for.leader =Please, wait while somebody will become a group leader. +label.manage.leaders =Manage Leaders +label.plese.select.leaders =Please, select leaders Index: lams_tool_scratchie/conf/xdoclet/struts-actions.xml =================================================================== diff -u -r99545d1824fcf0b2ea23a6bdce46aab3b288bff5 -rbc65717cc947dfd5b941ab4ac8f31a59c8f68bf4 --- lams_tool_scratchie/conf/xdoclet/struts-actions.xml (.../struts-actions.xml) (revision 99545d1824fcf0b2ea23a6bdce46aab3b288bff5) +++ lams_tool_scratchie/conf/xdoclet/struts-actions.xml (.../struts-actions.xml) (revision bc65717cc947dfd5b941ab4ac8f31a59c8f68bf4) @@ -181,10 +181,20 @@ type="org.lamsfoundation.lams.tool.scratchie.web.action.LearningAction" parameter="start" > + + + + + + @@ -233,6 +243,15 @@ parameter="itemSummary" > + + + + + Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/ScratchieConstants.java =================================================================== diff -u -red23aef88626fa70acd34abbd3d044bec1b4a998 -rbc65717cc947dfd5b941ab4ac8f31a59c8f68bf4 --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/ScratchieConstants.java (.../ScratchieConstants.java) (revision ed23aef88626fa70acd34abbd3d044bec1b4a998) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/ScratchieConstants.java (.../ScratchieConstants.java) (revision bc65717cc947dfd5b941ab4ac8f31a59c8f68bf4) @@ -79,6 +79,8 @@ public static final String ATTR_ITEM_COUNT = "itemCount"; + public static final String ATTR_GROUP_USERS = "groupUsers"; + public static final String ATTR_ANSWER_LIST = "answerList"; public static final String ATTR_ANSWER_COUNT = "answerCount"; @@ -97,6 +99,8 @@ public static final String ATTR_SCRATCHIE = "scratchie"; + public static final String ATTR_IS_SCRATCHING_FINISHED = "isScratchingFinished"; + public static final String ATTR_LEARNERS = "learners"; public static final String ATTR_VISIT_LOGS = "visitLogs"; @@ -142,6 +146,10 @@ public static final String ATTR_USER_UID = "userUid"; public static final String ATTR_USER_ID = "userId"; + + public static final String ATTR_USER = "user"; + + public static final String ATTR_GROUP_LEADER = "groupLeader"; public static final String LEARNER_MARK = "learner.mark"; } Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/dao/ScratchieAnswerVisitDAO.java =================================================================== diff -u -r99545d1824fcf0b2ea23a6bdce46aab3b288bff5 -rbc65717cc947dfd5b941ab4ac8f31a59c8f68bf4 --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/dao/ScratchieAnswerVisitDAO.java (.../ScratchieAnswerVisitDAO.java) (revision 99545d1824fcf0b2ea23a6bdce46aab3b288bff5) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/dao/ScratchieAnswerVisitDAO.java (.../ScratchieAnswerVisitDAO.java) (revision bc65717cc947dfd5b941ab4ac8f31a59c8f68bf4) @@ -37,5 +37,7 @@ int getLogCountPerItem(Long toolSessionId, Long userId, Long itemUid); List getLogsByScratchieUserAndItem(Long userUid, Long itemUid); + + List getLogsByScratchieUser(Long userUid); } Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/dao/hibernate/ScratchieAnswerVisitDAOHibernate.java =================================================================== diff -u -r99545d1824fcf0b2ea23a6bdce46aab3b288bff5 -rbc65717cc947dfd5b941ab4ac8f31a59c8f68bf4 --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/dao/hibernate/ScratchieAnswerVisitDAOHibernate.java (.../ScratchieAnswerVisitDAOHibernate.java) (revision 99545d1824fcf0b2ea23a6bdce46aab3b288bff5) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/dao/hibernate/ScratchieAnswerVisitDAOHibernate.java (.../ScratchieAnswerVisitDAOHibernate.java) (revision bc65717cc947dfd5b941ab4ac8f31a59c8f68bf4) @@ -40,36 +40,48 @@ private static final String FIND_BY_SCRATCHIE_USER_AND_ITEM = "from " + ScratchieAnswerVisitLog.class.getName() + " as r where r.user.uid=? and r.scratchieAnswer.scratchieItem.uid = ? order by r.accessDate asc"; + + private static final String FIND_BY_SCRATCHIE_USER = "from " + ScratchieAnswerVisitLog.class.getName() + + " as r where r.user.uid=? order by r.accessDate asc"; private static final String FIND_VIEW_COUNT_BY_USER = "select count(*) from " + ScratchieAnswerVisitLog.class.getName() + " as r where r.sessionId=? and r.user.userId =?"; private static final String FIND_VIEW_COUNT_BY_USER_AND_ITEM = "select count(*) from " + ScratchieAnswerVisitLog.class.getName() + " as l where l.sessionId=? and l.user.userId =? and l.scratchieAnswer.scratchieItem.uid=?"; + @Override public ScratchieAnswerVisitLog getScratchieAnswerLog(Long answerUid, Long userId) { List list = getHibernateTemplate().find(FIND_BY_ANSWER_AND_USER, new Object[] { userId, answerUid }); if (list == null || list.size() == 0) return null; return (ScratchieAnswerVisitLog) list.get(0); } + @Override public int getLogCountTotal(Long toolSessionId, Long userId) { List list = getHibernateTemplate().find(FIND_VIEW_COUNT_BY_USER, new Object[] { toolSessionId, userId }); if (list == null || list.size() == 0) return 0; return ((Number) list.get(0)).intValue(); } + @Override public int getLogCountPerItem(Long toolSessionId, Long userId, Long itemUid) { List list = getHibernateTemplate().find(FIND_VIEW_COUNT_BY_USER_AND_ITEM, new Object[] { toolSessionId, userId, itemUid }); if (list == null || list.size() == 0) return 0; return ((Number) list.get(0)).intValue(); } + @Override public List getLogsByScratchieUserAndItem(Long userUid, Long itemUid) { return getHibernateTemplate().find(FIND_BY_SCRATCHIE_USER_AND_ITEM, new Object[] { userUid, itemUid }); } + + @Override + public List getLogsByScratchieUser(Long userUid) { + return getHibernateTemplate().find(FIND_BY_SCRATCHIE_USER, new Object[] { userUid }); + } } Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/dbupdates/patch20121004_wviCustomUpdate.sql =================================================================== diff -u --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/dbupdates/patch20121004_wviCustomUpdate.sql (revision 0) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/dbupdates/patch20121004_wviCustomUpdate.sql (revision bc65717cc947dfd5b941ab4ac8f31a59c8f68bf4) @@ -0,0 +1,13 @@ +-- Turn off autocommit, so nothing is committed if there is an error +SET AUTOCOMMIT = 0; + +----------------------Put all sql statements below here------------------------- + +-- LDEV-2657 Date and time restriction +ALTER TABLE tl_lascrt11_user ADD COLUMN leader smallint DEFAULT 0; + +----------------------Put all sql statements above here------------------------- + +-- If there were no errors, commit and restore autocommit to on +COMMIT; +SET AUTOCOMMIT = 1; \ No newline at end of file Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/model/ScratchieUser.java =================================================================== diff -u -red23aef88626fa70acd34abbd3d044bec1b4a998 -rbc65717cc947dfd5b941ab4ac8f31a59c8f68bf4 --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/model/ScratchieUser.java (.../ScratchieUser.java) (revision ed23aef88626fa70acd34abbd3d044bec1b4a998) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/model/ScratchieUser.java (.../ScratchieUser.java) (revision bc65717cc947dfd5b941ab4ac8f31a59c8f68bf4) @@ -48,6 +48,7 @@ private String loginName; private boolean sessionFinished; private boolean scratchingFinished; + private boolean leader; private ScratchieSession session; private Scratchie scratchie; @@ -222,7 +223,21 @@ public void setScratchingFinished(boolean scratchingFinished) { this.scratchingFinished = scratchingFinished; } + + /** + * Indicates whether user is leader of his group. + * + * @hibernate.property column="leader" + * @return + */ + public boolean isLeader() { + return leader; + } + public void setLeader(boolean leader) { + this.leader = leader; + } + public boolean equals(Object obj) { if (this == obj) return true; Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/scratchieApplicationContext.xml =================================================================== diff -u -rae0ac03f3bac4dadd58a6d0f57b85ad9ce8a719a -rbc65717cc947dfd5b941ab4ac8f31a59c8f68bf4 --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/scratchieApplicationContext.xml (.../scratchieApplicationContext.xml) (revision ae0ac03f3bac4dadd58a6d0f57b85ad9ce8a719a) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/scratchieApplicationContext.xml (.../scratchieApplicationContext.xml) (revision bc65717cc947dfd5b941ab4ac8f31a59c8f68bf4) @@ -121,6 +121,9 @@ PROPAGATION_REQUIRED,-java.lang.Exception PROPAGATION_REQUIRED,-java.lang.Exception PROPAGATION_REQUIRED,-java.lang.Exception + PROPAGATION_REQUIRED,-java.lang.Exception + PROPAGATION_REQUIRED,-java.lang.Exception + PROPAGATION_REQUIRED,-java.lang.Exception PROPAGATION_REQUIRED,-java.lang.Exception PROPAGATION_REQUIRED,-java.lang.Exception PROPAGATION_REQUIRED,-java.lang.Exception Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/IScratchieService.java =================================================================== diff -u -r99545d1824fcf0b2ea23a6bdce46aab3b288bff5 -rbc65717cc947dfd5b941ab4ac8f31a59c8f68bf4 --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/IScratchieService.java (.../IScratchieService.java) (revision 99545d1824fcf0b2ea23a6bdce46aab3b288bff5) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/IScratchieService.java (.../IScratchieService.java) (revision bc65717cc947dfd5b941ab4ac8f31a59c8f68bf4) @@ -58,7 +58,29 @@ */ Scratchie getScratchieByContentId(Long contentId); + /** + * @param toolSessionId + * @return group leader if available, null otherwise + */ + ScratchieUser getGroupLeader(Long toolSessionId); + + /** + * Set specified user as a leader. Also the previous leader (if any) is marked as non-leader. + * + * @param userId + * @param toolSessionId + */ + void setGroupLeader(Long userId, Long toolSessionId); + ScratchieAnswer getScratchieAnswerById (Long answerUid); + + /** + * Check user has the same scrathes logs as group leader. If not - creates missing ones. + * + * @param user + * @param leader + */ + void copyScratchesFromLeader(ScratchieUser user, ScratchieUser leader); /** * Get a cloned copy of tool default tool content (Scratchie) and assign the toolContentId of that copy as the given @@ -110,6 +132,22 @@ * @return */ ScratchieUser getUserByIDAndSession(Long long1, Long sessionId); + + /** + * Get users by given toolSessionId. + * + * @param long1 + * @return + */ + List getUsersBySession(Long toolSessionId); + + /** + * Save specified user. + * + * @param long1 + * @return + */ + void saveUser(ScratchieUser user); // ********** Repository methods *********************** /** @@ -178,17 +216,19 @@ */ void retrieveScratched(Collection scratchieItemList, ScratchieUser user); - void setAnswerAccess(Long scratchieItemUid, Long userId, Long sessionId); + /** + * Leader has scratched the specified answer. Will store this scratch for all users in his group. + */ + void setAnswerAccess(Long scratchieItemUid, Long sessionId); int getUserMark(Long sessionId, Long userId); /** - * Mark user as ScratchingFinished so that user can't continue scratching after this. + * Mark all users in agroup as ScratchingFinished so that users can't continue scratching after this. * * @param toolSessionId - * @param userId */ - void setScratchingFinished(Long toolSessionId, Long userId); + void setScratchingFinished(Long toolSessionId); /** * If success return next activity's url, otherwise return null. Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/ScratchieServiceImpl.java =================================================================== diff -u -r99545d1824fcf0b2ea23a6bdce46aab3b288bff5 -rbc65717cc947dfd5b941ab4ac8f31a59c8f68bf4 --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/ScratchieServiceImpl.java (.../ScratchieServiceImpl.java) (revision 99545d1824fcf0b2ea23a6bdce46aab3b288bff5) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/service/ScratchieServiceImpl.java (.../ScratchieServiceImpl.java) (revision bc65717cc947dfd5b941ab4ac8f31a59c8f68bf4) @@ -279,6 +279,7 @@ } + @Override public void deleteFromRepository(Long fileUuid, Long fileVersionId) throws ScratchieApplicationException { ITicket ticket = getRepositoryLoginTicket(); try { @@ -305,7 +306,69 @@ public void deleteScratchieItem(Long uid) { scratchieItemDao.removeObject(ScratchieItem.class, uid); } + + @Override + public ScratchieUser getGroupLeader(Long toolSessionId) { + List users = scratchieUserDao.getBySessionID(toolSessionId); + + ScratchieUser groupLeader = null; + for (ScratchieUser user : users) { + if (user.isLeader()) { + groupLeader = user; + break; + } + } + + return groupLeader; + } + + @Override + public void setGroupLeader(Long userId, Long toolSessionId) { + if (userId==null || toolSessionId==null) { + return; + } + + ScratchieUser leader = getUserByIDAndSession(userId, toolSessionId); + if (!leader.isLeader()) { + // set previous leader set as a non-leader + ScratchieUser previousGroupLeader = getGroupLeader(toolSessionId); + if ((previousGroupLeader != null) && !previousGroupLeader.equals(leader)) { + previousGroupLeader.setLeader(false); + saveUser(previousGroupLeader); + } + + //mark user as a leader + leader.setLeader(true); + saveUser(leader); + } + } + + @Override + public void copyScratchesFromLeader(ScratchieUser user, ScratchieUser leader) { + + if ((user == null) || (leader == null) || user.equals(leader)) { + return; + } + + List leaderLogs = scratchieAnswerVisitDao.getLogsByScratchieUser(leader.getUid()); + + for (ScratchieAnswerVisitLog leaderLog : leaderLogs) { + ScratchieAnswer answer = leaderLog.getScratchieAnswer(); + ScratchieAnswerVisitLog log = scratchieAnswerVisitDao.getScratchieAnswerLog(answer.getUid(), user.getUserId()); + + //create and save new ScratchieAnswerVisitLog + if (log == null) { + log = new ScratchieAnswerVisitLog(); + log.setScratchieAnswer(answer); + log.setUser(user); + log.setSessionId(user.getSession().getSessionId()); + log.setAccessDate(leaderLog.getAccessDate()); + scratchieAnswerVisitDao.saveObject(log); + } + } + } + @Override public List exportBySessionId(Long sessionId) { ScratchieSession session = scratchieSessionDao.getSessionBySessionId(sessionId); if (session == null) { @@ -337,6 +400,7 @@ return itemList; } + @Override public List> exportByContentId(Long contentId) { Scratchie scratchie = scratchieDao.getByContentId(contentId); List> groupList = new ArrayList(); @@ -390,30 +454,40 @@ scratchieSessionDao.saveObject(resSession); } - public void setAnswerAccess(Long answerUid, Long userId, Long sessionId) { - ScratchieAnswerVisitLog log = scratchieAnswerVisitDao.getScratchieAnswerLog(answerUid, userId); - if (log == null) { - log = new ScratchieAnswerVisitLog(); - ScratchieAnswer answer = getScratchieAnswerById(answerUid); - log.setScratchieAnswer(answer); - ScratchieUser user = scratchieUserDao.getUserByUserIDAndSessionID(userId, sessionId); - log.setUser(user); - log.setSessionId(sessionId); - log.setAccessDate(new Timestamp(new Date().getTime())); - scratchieAnswerVisitDao.saveObject(log); + @Override + public void setAnswerAccess(Long answerUid, Long sessionId) { + + List users = getUsersBySession(sessionId); + for (ScratchieUser user : users) { + ScratchieAnswerVisitLog log = scratchieAnswerVisitDao.getScratchieAnswerLog(answerUid, user.getUserId()); + if (log == null) { + log = new ScratchieAnswerVisitLog(); + ScratchieAnswer answer = getScratchieAnswerById(answerUid); + log.setScratchieAnswer(answer); + log.setUser(user); + log.setSessionId(sessionId); + log.setAccessDate(new Timestamp(new Date().getTime())); + scratchieAnswerVisitDao.saveObject(log); + } } + } + @Override public ScratchieAnswer getScratchieAnswerById (Long answerUid) { return (ScratchieAnswer) userManagementService.findById(ScratchieAnswer.class, answerUid); } - public void setScratchingFinished(Long toolSessionId, Long userId) { - ScratchieUser user = scratchieUserDao.getUserByUserIDAndSessionID(userId, toolSessionId); - user.setScratchingFinished(true); - scratchieUserDao.saveObject(user); + @Override + public void setScratchingFinished(Long toolSessionId) { + List users = getUsersBySession(toolSessionId); + for (ScratchieUser user : users) { + user.setScratchingFinished(true); + scratchieUserDao.saveObject(user); + } } + @Override public String finishToolSession(Long toolSessionId, Long userId) throws ScratchieApplicationException { String nextUrl = null; try { @@ -430,6 +504,7 @@ return nextUrl; } + @Override public ScratchieItem getScratchieItemByUid(Long itemUid) { return scratchieItemDao.getByUid(itemUid); } @@ -450,6 +525,17 @@ return users; } + @Override + public List getUsersBySession(Long toolSessionId) { + return scratchieUserDao.getBySessionID(toolSessionId); + } + + @Override + public void saveUser(ScratchieUser user) { + scratchieUserDao.saveObject(user); + } + + @Override public List getMonitoringSummary(Long contentId) { List groupSummaryList = new ArrayList(); @@ -479,6 +565,7 @@ return groupSummaryList; } + @Override public void retrieveScratchesOrder(Collection items, ScratchieUser user) { for (ScratchieItem item : items) { Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/action/LearningAction.java =================================================================== diff -u -r99545d1824fcf0b2ea23a6bdce46aab3b288bff5 -rbc65717cc947dfd5b941ab4ac8f31a59c8f68bf4 --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/action/LearningAction.java (.../LearningAction.java) (revision 99545d1824fcf0b2ea23a6bdce46aab3b288bff5) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/action/LearningAction.java (.../LearningAction.java) (revision bc65717cc947dfd5b941ab4ac8f31a59c8f68bf4) @@ -25,7 +25,6 @@ package org.lamsfoundation.lams.tool.scratchie.web.action; import java.io.IOException; -import java.util.ArrayList; import java.util.Collection; import java.util.Date; import java.util.List; @@ -83,6 +82,12 @@ if (param.equals("start")) { return start(mapping, form, request, response); } + if (param.equals("refreshQuestionList")) { + return refreshQuestionList(mapping, form, request, response); + } + if (param.equals("becomeLeader")) { + return becomeLeader(mapping, form, request, response); + } if (param.equals("scratchItem")) { return scratchItem(mapping, form, request, response); } @@ -114,17 +119,14 @@ private ActionForward start(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { - // initial Session Map - SessionMap sessionMap = new SessionMap(); - request.getSession().setAttribute(sessionMap.getSessionID(), sessionMap); - request.setAttribute(ScratchieConstants.ATTR_SESSION_MAP_ID, sessionMap.getSessionID()); - // save toolContentID into HTTPSession ToolAccessMode mode = WebUtil.readToolAccessModeParam(request, AttributeNames.PARAM_MODE, true); Long toolSessionId = new Long(request.getParameter(ScratchieConstants.PARAM_TOOL_SESSION_ID)); // get back the scratchie and item list and display them on page IScratchieService service = getScratchieService(); + Scratchie scratchie = service.getScratchieBySessionId(toolSessionId); + ScratchieUser user = null; if (mode != null && mode.isTeacher()) { // monitoring mode - user is specified in URL @@ -134,10 +136,32 @@ } else { user = getCurrentUser(service, toolSessionId); } + + ScratchieUser groupLeader = service.getGroupLeader(toolSessionId); + //forwards to the leaderSelection page + if ((groupLeader == null) && !mode.isTeacher()) { + List groupUsers = service.getUsersBySession(toolSessionId); + request.setAttribute(ScratchieConstants.ATTR_GROUP_USERS, groupUsers); + request.setAttribute(ScratchieConstants.PARAM_TOOL_SESSION_ID, toolSessionId); + request.setAttribute(ScratchieConstants.ATTR_SCRATCHIE, scratchie); + + //checks whether to display dialog prompting to become a leader + boolean nodialog = WebUtil.readBooleanParam(request, "nodialog", false); + request.setAttribute("nodialog", nodialog); + return mapping.findForward("leaderSelection"); + } + + //in case user joins the lesson after leader has scratched some answers already - we need to make sure he has the same scratches as leader + if (!mode.isTeacher()) { + service.copyScratchesFromLeader(user, groupLeader); + } + + // initial Session Map + SessionMap sessionMap = new SessionMap(); + request.getSession().setAttribute(sessionMap.getSessionID(), sessionMap); + request.setAttribute(ScratchieConstants.ATTR_SESSION_MAP_ID, sessionMap.getSessionID()); - Scratchie scratchie = service.getScratchieBySessionId(toolSessionId); - Set initialItems = scratchie.getScratchieItems(); - + // get notebook entry String entryText = new String(); if (user != null) { @@ -152,6 +176,8 @@ sessionMap.put(ScratchieConstants.ATTR_TITLE, scratchie.getTitle()); sessionMap.put(ScratchieConstants.ATTR_RESOURCE_INSTRUCTION, scratchie.getInstructions()); sessionMap.put(ScratchieConstants.ATTR_USER_ID, user.getUserId()); + sessionMap.put(ScratchieConstants.ATTR_USER, user); + sessionMap.put(ScratchieConstants.ATTR_GROUP_LEADER, groupLeader); boolean isUserFinished = user != null && user.isSessionFinished(); sessionMap.put(ScratchieConstants.ATTR_USER_FINISHED, isUserFinished); sessionMap.put(ScratchieConstants.ATTR_IS_SHOW_RESULTS_PAGE, scratchie.isShowResultsPage()); @@ -180,31 +206,33 @@ sessionMap.put(ScratchieConstants.PARAM_RUN_OFFLINE, false); } + Set initialItems = scratchie.getScratchieItems(); // becuase in webpage will use this login name. Here is just initialize it to avoid session close error in proxy object. for (ScratchieItem item : initialItems) { if (item.getCreateBy() != null) { item.getCreateBy().getLoginName(); } } - // for teacher in monitoring display the number of atempt. + // for teacher in monitoring display the number of attempt. if (mode.isTeacher()) { service.retrieveScratchesOrder(initialItems, user); } - // set complete flag for display purpose + // set scratched flag for display purpose if (user != null) { service.retrieveScratched(initialItems, user); } - //randomize order if needed Collection items = new TreeSet(new ScratchieItemComparator()); items.addAll(initialItems); sessionMap.put(ScratchieConstants.ATTR_ITEM_LIST, items); sessionMap.put(ScratchieConstants.ATTR_SCRATCHIE, scratchie); - boolean isScratchingFinished = user != null && user.isScratchingFinished(); - if (isScratchingFinished && !mode.isTeacher()) { + sessionMap.put(ScratchieConstants.ATTR_IS_SCRATCHING_FINISHED, isScratchingFinished); + + //decide whether to show results page or learning one + if (scratchie.isShowResultsPage() && isScratchingFinished && !mode.isTeacher()) { ActionRedirect redirect = new ActionRedirect(mapping.findForwardConfig("showResults")); redirect.addParameter(ScratchieConstants.ATTR_SESSION_MAP_ID, sessionMap.getSessionID()); redirect.addParameter(AttributeNames.ATTR_MODE, mode); @@ -216,8 +244,45 @@ } /** - * Display main frame to display instrcution and item content. + * Refresh * + */ + private ActionForward refreshQuestionList(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + + String sessionMapID = request.getParameter(ScratchieConstants.ATTR_SESSION_MAP_ID); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID); + request.setAttribute(ScratchieConstants.ATTR_SESSION_MAP_ID, sessionMapID); + IScratchieService service = getScratchieService(); + + Long toolSessionId = (Long) sessionMap.get(AttributeNames.PARAM_TOOL_SESSION_ID); + ScratchieUser user = getCurrentUser(service, toolSessionId); + + // get back the scratchie and item list and display them on page + Scratchie scratchie = service.getScratchieBySessionId(toolSessionId); + + Collection items = new TreeSet(new ScratchieItemComparator()); + items.addAll(scratchie.getScratchieItems()); + + // set scratched flag for display purpose + if (user != null) { + service.retrieveScratched(items, user); + } + + sessionMap.put(ScratchieConstants.ATTR_ITEM_LIST, items); + //refresh leadership status + sessionMap.put(ScratchieConstants.ATTR_USER, user); + //refresh ScratchingFinished status + boolean isScratchingFinished = user != null && user.isScratchingFinished(); + sessionMap.put(ScratchieConstants.ATTR_IS_SCRATCHING_FINISHED, isScratchingFinished); + + return mapping.findForward(ScratchieConstants.SUCCESS); + + } + + /** + * Sets current user as a leader of a group. + * * @param mapping * @param form * @param request @@ -226,31 +291,55 @@ * @throws JSONException * @throws IOException */ + private ActionForward becomeLeader(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws JSONException, IOException { + IScratchieService service = getScratchieService(); + Long toolSessionId = new Long(request.getParameter(ScratchieConstants.PARAM_TOOL_SESSION_ID)); + + ScratchieUser groupLeader = service.getGroupLeader(toolSessionId); + //check there is no leader yet. Just in case somebody has pressed "Yes" button faster + if (groupLeader == null) { + ScratchieUser user = getCurrentUser(service, toolSessionId); + service.setGroupLeader(user.getUserId(), toolSessionId); + } + + return null; + } + + /** + * Scratch specified answer. + * + * @param mapping + * @param form + * @param request + * @param response + * @return + * @throws JSONException + * @throws IOException + */ private ActionForward scratchItem(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws JSONException, IOException { + + IScratchieService service = getScratchieService(); String sessionMapID = WebUtil.readStrParam(request, ScratchieConstants.ATTR_SESSION_MAP_ID); SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID); + Long toolSessionId = (Long) sessionMap.get(AttributeNames.PARAM_TOOL_SESSION_ID); - ToolAccessMode mode = (ToolAccessMode) sessionMap.get(AttributeNames.ATTR_MODE); - - Long answerUid = NumberUtils.createLong(request.getParameter(ScratchieConstants.PARAM_ANSWER_UID)); - // get back the resource and item list and display them on page - ScratchieAnswer answer = getScratchieService().getScratchieAnswerById(answerUid); - - // mark this item access flag if it is learner - if (mode.isLearner()) { - HttpSession ss = SessionManager.getSession(); - // get back login user DTO - UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER); - Long toolSessionId = (Long) sessionMap.get(AttributeNames.PARAM_TOOL_SESSION_ID); - getScratchieService().setAnswerAccess(answer.getUid(), new Long(user.getUserID().intValue()), toolSessionId); + ScratchieUser user = getCurrentUser(service, toolSessionId); + //only leaders are allowed to scratch answers + if (!user.isLeader()) { + return null; } + Long answerUid = NumberUtils.createLong(request.getParameter(ScratchieConstants.PARAM_ANSWER_UID)); + ScratchieAnswer answer = service.getScratchieAnswerById(answerUid); if (answer == null) { return mapping.findForward(ScratchieConstants.ERROR); } - + + service.setAnswerAccess(answer.getUid(), toolSessionId); + JSONObject JSONObject = new JSONObject(); JSONObject.put(ScratchieConstants.ATTR_ANSWER_CORRECT, answer.isCorrect()); response.setContentType("application/x-json"); @@ -260,7 +349,7 @@ } /** - * Finish learning session. + * Leader presses button show results. All the users set scratchingFinished to true. * * @param mapping * @param form @@ -281,9 +370,8 @@ IScratchieService service = getScratchieService(); Long userId = (Long) sessionMap.get(ScratchieConstants.ATTR_USER_ID); - if (mode == null || !mode.isTeacher()) { - service.setScratchingFinished(toolSessionId, userId); - } + //only leaders should get to here to finalize scratching + service.setScratchingFinished(toolSessionId); Set items = service.populateItemsResults(toolSessionId, userId); request.setAttribute(ScratchieConstants.ATTR_ITEM_LIST, items); @@ -307,16 +395,17 @@ String sessionMapID = request.getParameter(ScratchieConstants.ATTR_SESSION_MAP_ID); SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID); Long toolSessionId = (Long) sessionMap.get(AttributeNames.PARAM_TOOL_SESSION_ID); - + ScratchieUser user = (ScratchieUser) sessionMap.get(AttributeNames.USER); IScratchieService service = getScratchieService(); - // get sessionId from HttpServletRequest + + //in case of the leader we should let all other learners see Next Activity button + if (user.isLeader()) { + service.setScratchingFinished(toolSessionId); + } + String nextActivityUrl = null; try { - HttpSession ss = SessionManager.getSession(); - UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER); - Long userID = new Long(user.getUserID().longValue()); - - nextActivityUrl = service.finishToolSession(toolSessionId, userID); + nextActivityUrl = service.finishToolSession(toolSessionId, user.getUserId()); request.setAttribute(ScratchieConstants.ATTR_NEXT_ACTIVITY_URL, nextActivityUrl); } catch (ScratchieApplicationException e) { LearningAction.log.error("Failed get next activity url:" + e.getMessage()); @@ -410,22 +499,6 @@ return (IScratchieService) wac.getBean(ScratchieConstants.RESOURCE_SERVICE); } - /** - * Get java.util.List from HttpSession by given name. - * - * @param request - * @param name - * @return - */ - private List getListFromSession(SessionMap sessionMap, String name) { - List list = (List) sessionMap.get(name); - if (list == null) { - list = new ArrayList(); - sessionMap.put(name, list); - } - return list; - } - private ScratchieUser getCurrentUser(IScratchieService service, Long sessionId) { // try to get form system session HttpSession ss = SessionManager.getSession(); @@ -444,9 +517,8 @@ private ScratchieUser getSpecifiedUser(IScratchieService service, Long sessionId, Integer userId) { ScratchieUser scratchieUser = service.getUserByIDAndSession(new Long(userId.intValue()), sessionId); if (scratchieUser == null) { - LearningAction.log - .error("Unable to find specified user for scratchie activity. Screens are likely to fail. SessionId=" - + sessionId + " UserId=" + userId); + log.error("Unable to find specified user for scratchie activity. Screens are likely to fail. SessionId=" + + sessionId + " UserId=" + userId); } return scratchieUser; } Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/action/MonitoringAction.java =================================================================== diff -u -r99545d1824fcf0b2ea23a6bdce46aab3b288bff5 -rbc65717cc947dfd5b941ab4ac8f31a59c8f68bf4 --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/action/MonitoringAction.java (.../MonitoringAction.java) (revision 99545d1824fcf0b2ea23a6bdce46aab3b288bff5) +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/action/MonitoringAction.java (.../MonitoringAction.java) (revision bc65717cc947dfd5b941ab4ac8f31a59c8f68bf4) @@ -70,6 +70,12 @@ if (param.equals("itemSummary")) { return itemSummary(mapping, form, request, response); } + if (param.equals("manageLeaders")) { + return manageLeaders(mapping, form, request, response); + } + if (param.equals("saveLeaders")) { + return saveLeaders(mapping, form, request, response); + } if (param.equals("viewReflection")) { return viewReflection(mapping, form, request, response); } @@ -125,6 +131,46 @@ request.setAttribute(ScratchieConstants.ATTR_SUMMARY_LIST, summaryList); return mapping.findForward(ScratchieConstants.SUCCESS); } + + /** + * Show leaders manage page + */ + private ActionForward manageLeaders(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + String sessionMapID = request.getParameter(ScratchieConstants.ATTR_SESSION_MAP_ID); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID); + request.setAttribute(ScratchieConstants.ATTR_SESSION_MAP_ID, sessionMap.getSessionID()); + return mapping.findForward(ScratchieConstants.SUCCESS); + } + + /** + * Save selected users as a leaders + */ + private ActionForward saveLeaders(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + String sessionMapID = request.getParameter(ScratchieConstants.ATTR_SESSION_MAP_ID); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID); + request.setAttribute(ScratchieConstants.ATTR_SESSION_MAP_ID, sessionMap.getSessionID()); + IScratchieService service = getScratchieService(); + + List summaryList = (List) sessionMap.get(ScratchieConstants.ATTR_SUMMARY_LIST); + for (GroupSummary summary: summaryList) { + Long toolSessionId = summary.getSessionId(); + Long leaderUserId = WebUtil.readLongParam(request, "sessionId" + toolSessionId, true); + + //save selected users as a leaders + if (leaderUserId != null) { + service.setGroupLeader(leaderUserId, toolSessionId); + } + } + + //refresh users leadership status in summaryList + Long contentId = (Long) sessionMap.get(ScratchieConstants.ATTR_TOOL_CONTENT_ID); + summaryList = service.getMonitoringSummary(contentId); + sessionMap.put(ScratchieConstants.ATTR_SUMMARY_LIST, summaryList); + + return null; + } private ActionForward viewReflection(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { Index: lams_tool_scratchie/web/pages/learning/leaderselection.jsp =================================================================== diff -u --- lams_tool_scratchie/web/pages/learning/leaderselection.jsp (revision 0) +++ lams_tool_scratchie/web/pages/learning/leaderselection.jsp (revision bc65717cc947dfd5b941ab4ac8f31a59c8f68bf4) @@ -0,0 +1,118 @@ + + +<%@ include file="/common/taglibs.jsp"%> + + + + <fmt:message key="label.learning.title" /> + <%@ include file="/common/header.jsp"%> + + + + + + + + + +
+

+ ${scratchie.title} +

+ +

+ +

+ +
+ +
+ +
+ +
+ ${user.firstName} ${user.lastName} +
+
+
+ +
+ + + +
+ +
+ + + + + +
+ +
+ +
+ +
+ +
+ +
+ +
+ ${user.firstName} ${user.lastName} +
+
+
+
+ + + +
Index: lams_tool_scratchie/web/pages/learning/learning.jsp =================================================================== diff -u -r087486f544304e7ab0112f9e622010421c7e2860 -rbc65717cc947dfd5b941ab4ac8f31a59c8f68bf4 --- lams_tool_scratchie/web/pages/learning/learning.jsp (.../learning.jsp) (revision 087486f544304e7ab0112f9e622010421c7e2860) +++ lams_tool_scratchie/web/pages/learning/learning.jsp (.../learning.jsp) (revision bc65717cc947dfd5b941ab4ac8f31a59c8f68bf4) @@ -10,6 +10,8 @@ + + @@ -74,6 +76,25 @@ function continueReflect(){ document.location.href=''; } + + if (${!isUserLeader && mode != "teacher"}) { + setInterval("refreshQuestionList();",10000);// Auto-Refresh every 30 seconds + } + + function refreshQuestionList() { + var url = ""; + $("#questionListArea").load( + url, + { + sessionMapID: "${sessionMapID}" + }, + function(){ + //reinitializePassingMarkSelect(false); + //refreshThickbox(); + } + ); + } + --> @@ -83,112 +104,23 @@

${scratchie.title}

+ +

+ + ${sessionMap.groupLeader.firstName} ${sessionMap.groupLeader.lastName} + +

-

+

${scratchie.instructions}

<%@ include file="/common/messages.jsp"%> - -

${item.title}

- ${item.description} - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
- - ${answer.attemptOrder} - -
-
-
- ${answer.description} -
- -
+
+ <%@ include file="questionlist.jsp"%> +
- - -
-

- ${sessionMap.reflectInstructions} -

- - - -

- - -

-
- -

- -

-
-
- - - - - - -
-
- - -
- - - - - - - - - - - - - - - - - - - - - - -
-
- Index: lams_tool_scratchie/web/pages/learning/questionlist.jsp =================================================================== diff -u --- lams_tool_scratchie/web/pages/learning/questionlist.jsp (revision 0) +++ lams_tool_scratchie/web/pages/learning/questionlist.jsp (revision bc65717cc947dfd5b941ab4ac8f31a59c8f68bf4) @@ -0,0 +1,111 @@ +<%@ include file="/common/taglibs.jsp"%> + + <%-- param has higher level for request attribute --%> + + + + + + + + + + + + +

${item.title}

+ ${item.description} + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ + ${answer.attemptOrder} + +
+
+
+ ${answer.description} +
+ +
+ + +
+

+ ${sessionMap.reflectInstructions} +

+ + + +

+ + +

+
+ +

+ +

+
+
+ + + + + + +
+
+ + +
+ + + + + + + + + + + + + + + + + + + + + + +
+
\ No newline at end of file Index: lams_tool_scratchie/web/pages/monitoring/manageLeaders.jsp =================================================================== diff -u --- lams_tool_scratchie/web/pages/monitoring/manageLeaders.jsp (revision 0) +++ lams_tool_scratchie/web/pages/monitoring/manageLeaders.jsp (revision bc65717cc947dfd5b941ab4ac8f31a59c8f68bf4) @@ -0,0 +1,90 @@ + + +<%@ include file="/common/taglibs.jsp"%> + + + + + + + + + <%@ include file="/common/header.jsp"%> + + + + + + + + + + + + + +
+ +

+ +

+
+ +
+ +

+
+ +
+ ${summary.sessionName} +
+
+ + +
+ checked="checked"/> + ${user.firstName} ${user.lastName} +
+
+
+
+
+ + + + + + + + + + + + +
+ + + + + + +
Index: lams_tool_scratchie/web/pages/monitoring/summary.jsp =================================================================== diff -u -red23aef88626fa70acd34abbd3d044bec1b4a998 -rbc65717cc947dfd5b941ab4ac8f31a59c8f68bf4 --- lams_tool_scratchie/web/pages/monitoring/summary.jsp (.../summary.jsp) (revision ed23aef88626fa70acd34abbd3d044bec1b4a998) +++ lams_tool_scratchie/web/pages/monitoring/summary.jsp (.../summary.jsp) (revision bc65717cc947dfd5b941ab4ac8f31a59c8f68bf4) @@ -14,6 +14,13 @@ height: 'auto', width: 900, shrinkToFit: true, + ondblClickRow: function(rowid) { + var userId = jQuery("#list${summary.sessionId}").getCell(rowid, 'userId'); + var toolSessionId = jQuery("#list${summary.sessionId}").getCell(rowid, 'sessionId'); + + var userSummaryUrl = "?userID=" + userId + "&toolSessionID=" + toolSessionId + "&mode=teacher&reqId=" + (new Date()).getTime(); + launchPopup(userSummaryUrl, "MonitoringReview"); + }, colNames:['#', 'userId', @@ -153,6 +160,12 @@ + +
+ > + + +