Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/dto/MessageDTO.java =================================================================== diff -u -r2700025047410d38f40b3bd7c56966a9fc08bb29 -r86ef0c92b6e5b8a3915fcc960b918ab95b629503 --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/dto/MessageDTO.java (.../MessageDTO.java) (revision 2700025047410d38f40b3bd7c56966a9fc08bb29) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/dto/MessageDTO.java (.../MessageDTO.java) (revision 86ef0c92b6e5b8a3915fcc960b918ab95b629503) @@ -45,6 +45,10 @@ private String comment; private boolean released; + // number of posts the learner has made in this topic. + // used when this message is a root topic. + private int numOfPosts; + //2 fields use for export portfolio function private String attachmentName; private String attachmentLocalUrl; @@ -190,5 +194,12 @@ this.attachmentName = attachmentName; } - + public int getNumOfPosts() { + return numOfPosts; + } + + public void setNumOfPosts(int numOfPosts) { + this.numOfPosts = numOfPosts; + } + } Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/MessageSeqDao.java =================================================================== diff -u -r08950e1090443c3423a3d1c587416a2fccd8bbdf -r86ef0c92b6e5b8a3915fcc960b918ab95b629503 --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/MessageSeqDao.java (.../MessageSeqDao.java) (revision 08950e1090443c3423a3d1c587416a2fccd8bbdf) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/persistence/MessageSeqDao.java (.../MessageSeqDao.java) (revision 86ef0c92b6e5b8a3915fcc960b918ab95b629503) @@ -34,7 +34,10 @@ + " where root_message_uid = ?"; private static final String SQL_QUERY_FIND_TOPIC_ID = "from " + MessageSeq.class.getName() + " where message_uid = ?"; - + + private static final String SQL_QUERY_NUM_POSTS_BY_TOPIC = "select count(*) from " + + MessageSeq.class.getName() + " ms where ms.message.createdBy.userId=? and ms.message.isAuthored = false and ms.rootMessage=?"; + public List getTopicThread(Long rootTopicId) { return this.getHibernateTemplate().find(SQL_QUERY_FIND_TOPIC_THREAD,rootTopicId); } @@ -55,6 +58,14 @@ if(seq != null) this.getHibernateTemplate().delete(seq); } + + public int getNumOfPostsByTopic(Long userID, Long topicID) { + List list = this.getHibernateTemplate().find(SQL_QUERY_NUM_POSTS_BY_TOPIC, new Object[]{userID,topicID}); + if(list != null && list.size() > 0) + return ((Number)list.get(0)).intValue(); + else + return 0; + } } Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/ForumService.java =================================================================== diff -u -rd9543a9d4e613ea6deffacaeb239d8649707f965 -r86ef0c92b6e5b8a3915fcc960b918ab95b629503 --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/ForumService.java (.../ForumService.java) (revision d9543a9d4e613ea6deffacaeb239d8649707f965) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/ForumService.java (.../ForumService.java) (revision 86ef0c92b6e5b8a3915fcc960b918ab95b629503) @@ -400,6 +400,10 @@ public int getTopicsNum(Long userID, Long sessionId) { return messageDao.getTopicsNum(userID,sessionId); } + + public int getNumOfPostsByTopic(Long userId, Long topicId) { + return messageSeqDao.getNumOfPostsByTopic(userId, topicId); + } public ForumUser getUserByID(Long userId) { return forumUserDao.getByUserId(userId); Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/IForumService.java =================================================================== diff -u -r5cf94a873af22670c1bcfb832c7e868ef168333a -r86ef0c92b6e5b8a3915fcc960b918ab95b629503 --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/IForumService.java (.../IForumService.java) (revision 5cf94a873af22670c1bcfb832c7e868ef168333a) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/service/IForumService.java (.../IForumService.java) (revision 86ef0c92b6e5b8a3915fcc960b918ab95b629503) @@ -212,6 +212,13 @@ * @return */ public int getTopicsNum(Long userID, Long sessionId); + /** + * Returns the number of posts this user has made in this topic. + * @param userId + * @param topicId + * @return + */ + public int getNumOfPostsByTopic(Long userId, Long topicId); //************************************************************************************ // Session Method Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/util/ForumConstants.java =================================================================== diff -u -rdba3e6022ca1e0478e053c415095b14db37576c7 -r86ef0c92b6e5b8a3915fcc960b918ab95b629503 --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/util/ForumConstants.java (.../ForumConstants.java) (revision dba3e6022ca1e0478e053c415095b14db37576c7) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/util/ForumConstants.java (.../ForumConstants.java) (revision 86ef0c92b6e5b8a3915fcc960b918ab95b629503) @@ -102,6 +102,7 @@ public static final String PARAM_UPDATE_MODE = "updateMode"; public static final String ATTR_NO_MORE_POSTS = "noMorePosts"; + public static final String ATTR_NUM_OF_POSTS = "numOfPosts"; public static final String ATTR_SESSION_MAP_ID = "sessionMapID"; @@ -114,6 +115,9 @@ public static final String ATTR_REFLECTION_ON = "reflectOn"; public static final String ATTR_REFLECTION_INSTRUCTION = "reflectInstructions"; public static final String ATTR_REFLECTION_ENTRY = "reflectEntry"; + + public static final String ATTR_MINIMUM_REPLY = "minimumReply"; + public static final String ATTR_MAXIMUM_REPLY = "maximumReply"; public static final String MARK_UPDATE_FROM_SESSION = "listAllMarks"; public static final String MARK_UPDATE_FROM_USER = "listMarks"; @@ -122,6 +126,7 @@ public static final String ATTR_HIDE_REFLECTION = "hideReflection"; + } Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/LearningAction.java =================================================================== diff -u -rdba3e6022ca1e0478e053c415095b14db37576c7 -r86ef0c92b6e5b8a3915fcc960b918ab95b629503 --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/LearningAction.java (.../LearningAction.java) (revision dba3e6022ca1e0478e053c415095b14db37576c7) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/actions/LearningAction.java (.../LearningAction.java) (revision 86ef0c92b6e5b8a3915fcc960b918ab95b629503) @@ -68,7 +68,6 @@ import org.lamsfoundation.lams.web.session.SessionManager; import org.lamsfoundation.lams.web.util.AttributeNames; import org.lamsfoundation.lams.web.util.SessionMap; -import org.springframework.orm.ObjectOptimisticLockingFailureException; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.WebApplicationContextUtils; @@ -88,7 +87,7 @@ String param = mapping.getParameter(); // --------------Forum Level ------------------ if (param.equals("viewForum")) { - return viewForm(mapping, form, request, response); + return viewForum(mapping, form, request, response); } if (param.equals("finish")) { return finish(mapping, form, request, response); @@ -146,7 +145,7 @@ * @throws Exception * */ - private ActionForward viewForm(ActionMapping mapping, ActionForm form, + private ActionForward viewForum(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { //initial Session Map @@ -210,6 +209,8 @@ sessionMap.put(AttributeNames.PARAM_TOOL_SESSION_ID, sessionId); sessionMap.put(ForumConstants.ATTR_FORUM_TITLE,forum.getTitle()); sessionMap.put(ForumConstants.ATTR_FORUM_INSTRCUTION,forum.getInstructions()); + sessionMap.put(ForumConstants.ATTR_MINIMUM_REPLY, forum.getMinimumReply()); + sessionMap.put(ForumConstants.ATTR_MAXIMUM_REPLY, forum.getMaximumReply()); // Should we show the reflection or not? We shouldn't show it when the screen is accessed // from the Monitoring Summary screen, but we should when accessed from the Learner Progress screen. @@ -248,11 +249,22 @@ // get all root topic to display on init page List rootTopics = forumService.getRootTopics(sessionId); + if (!forum.isAllowNewTopic()) { + // add the number post the learner has made for each topic. + updateNumOfPosts(rootTopics, forumUser); + } request.setAttribute(ForumConstants.AUTHORING_TOPICS_LIST, rootTopics); return mapping.findForward("success"); } + private void updateNumOfPosts(List rootTopics, ForumUser forumUser) { + for (Iterator iterator = rootTopics.iterator(); iterator.hasNext();) { + MessageDTO messageDTO = (MessageDTO) iterator.next(); + int numOfPosts = forumService.getNumOfPostsByTopic(forumUser.getUserId(), messageDTO.getMessage().getUid()); + messageDTO.setNumOfPosts(numOfPosts); + } + } /** * Learner click "finish" button in forum page, this method will turn on @@ -400,16 +412,28 @@ private ActionForward viewTopic(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { - Long rootTopicId = WebUtil.readLongParam(request, ForumConstants.ATTR_TOPIC_ID); forumService = getForumManager(); + + Long rootTopicId = WebUtil.readLongParam(request, ForumConstants.ATTR_TOPIC_ID); + + String sessionMapID = WebUtil.readStrParam(request, ForumConstants.ATTR_SESSION_MAP_ID); + SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID); + sessionMap.put(ForumConstants.ATTR_ROOT_TOPIC_UID, rootTopicId); + + // get forum user and forum + ForumUser forumUser = getCurrentUser(request, (Long)sessionMap.get(AttributeNames.PARAM_TOOL_SESSION_ID)); + Forum forum = forumUser.getSession().getForum(); + // get root topic list List msgDtoList = forumService.getTopicThread(rootTopicId); updateMesssageFlag(msgDtoList); request.setAttribute(ForumConstants.AUTHORING_TOPIC_THREAD, msgDtoList); - String sessionMapID = WebUtil.readStrParam(request, ForumConstants.ATTR_SESSION_MAP_ID); - SessionMap sessionMap = (SessionMap) request.getSession().getAttribute(sessionMapID); - sessionMap.put(ForumConstants.ATTR_ROOT_TOPIC_UID, rootTopicId); + // check if we can still make posts in this topic + int numOfPosts = forumService.getNumOfPostsByTopic(forumUser.getUserId(), ((MessageDTO)msgDtoList.get(0)).getMessage().getUid()); + boolean noMorePosts = (numOfPosts >= forum.getMaximumReply())?Boolean.TRUE:Boolean.FALSE; + request.setAttribute(ForumConstants.ATTR_NO_MORE_POSTS, noMorePosts); + request.setAttribute(ForumConstants.ATTR_NUM_OF_POSTS, numOfPosts); //transfer SessionMapID as well request.setAttribute(ForumConstants.ATTR_SESSION_MAP_ID, sessionMapID); @@ -581,13 +605,11 @@ //check whether allow more posts for this user ForumToolSession session = forumService.getSessionBySessionId(sessionId); Forum forum = session.getForum(); - if(forum != null){ - if(!forum.isAllowNewTopic()){ - int posts = forumService.getTopicsNum(forumUser.getUserId(), sessionId); - if(forum.getMaximumReply() != 0 && (posts >= forum.getMaximumReply())) - sessionMap.put(ForumConstants.ATTR_NO_MORE_POSTS, Boolean.TRUE); - } - } + int numOfPosts = forumService.getNumOfPostsByTopic(forumUser.getUserId(), ((MessageDTO)msgDtoList.get(0)).getMessage().getUid()); + boolean noMorePosts = (numOfPosts >= forum.getMaximumReply())?Boolean.TRUE:Boolean.FALSE; + request.setAttribute(ForumConstants.ATTR_NO_MORE_POSTS, noMorePosts); + request.setAttribute(ForumConstants.ATTR_NUM_OF_POSTS, numOfPosts); + sessionMap.remove(ForumConstants.ATTR_ORIGINAL_MESSAGE); return mapping.findForward("success"); @@ -711,6 +733,14 @@ List msgDtoList = forumService.getTopicThread(rootTopicId); updateMesssageFlag(msgDtoList); + // check if we can still make posts in this topic + ForumUser forumUser = getCurrentUser(request, (Long)sessionMap.get(AttributeNames.PARAM_TOOL_SESSION_ID)); + Forum forum = forumUser.getSession().getForum(); + int numOfPosts = forumService.getNumOfPostsByTopic(forumUser.getUserId(), ((MessageDTO)msgDtoList.get(0)).getMessage().getUid()); + boolean noMorePosts = (numOfPosts >= forum.getMaximumReply())?Boolean.TRUE:Boolean.FALSE; + request.setAttribute(ForumConstants.ATTR_NO_MORE_POSTS, noMorePosts); + request.setAttribute(ForumConstants.ATTR_NUM_OF_POSTS, numOfPosts); + request.setAttribute(ForumConstants.AUTHORING_TOPIC_THREAD, msgDtoList); request.setAttribute(ForumConstants.ATTR_SESSION_MAP_ID,messageForm.getSessionMapID()); @@ -752,15 +782,14 @@ // log.info(currentUser + "does not have permission to hide/show postings in forum: " + forum.getUid()); // log.info("Forum created by :" + forumCreatedBy.getUid() + ", Current User is: " + currentUser.getUid()); // } - // echo back this topic thread into page Long rootTopicId = forumService.getRootTopicId(msgId); List msgDtoList = forumService.getTopicThread(rootTopicId); updateMesssageFlag(msgDtoList); request.setAttribute(ForumConstants.AUTHORING_TOPIC_THREAD, msgDtoList); request.setAttribute(ForumConstants.ATTR_SESSION_MAP_ID,WebUtil.readStrParam(request,ForumConstants.ATTR_SESSION_MAP_ID)); - + return mapping.findForward("success"); } @@ -781,18 +810,24 @@ UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER); Long userID = new Long(user.getUserID().longValue()); if(!forum.getRunOffline() && !forum.isAllowNewTopic()){ - int postNum = forumService.getTopicsNum(userID,sessionId); - if(postNum < forum.getMinimumReply()){ - //create error - ActionMessages errors = new ActionMessages(); - errors.add(ActionMessages.GLOBAL_MESSAGE,new ActionMessage("error.less.mini.post",(forum.getMinimumReply() - postNum))); - saveErrors(request, errors); - - // get all root topic to display on init page - List rootTopics = forumService.getRootTopics(sessionId); - request.setAttribute(ForumConstants.AUTHORING_TOPICS_LIST, rootTopics); - request.setAttribute(ForumConstants.ATTR_SESSION_MAP_ID, sessionMapID ); - return false; + + List list = forumService.getRootTopics(sessionId); + for (MessageDTO msgDto: list) { + Long topicId = msgDto.getMessage().getUid(); + int numOfPostsInTopic = forumService.getNumOfPostsByTopic(userID, topicId); + if (numOfPostsInTopic < forum.getMinimumReply()) { + //create error + ActionMessages errors = new ActionMessages(); + errors.add(ActionMessages.GLOBAL_MESSAGE,new ActionMessage("error.less.mini.post",(forum.getMinimumReply()))); + saveErrors(request, errors); + + // get all root topic to display on init page + List rootTopics = forumService.getRootTopics(sessionId); + request.setAttribute(ForumConstants.AUTHORING_TOPICS_LIST, rootTopics); + request.setAttribute(ForumConstants.ATTR_SESSION_MAP_ID, sessionMapID ); + return false; + } + } } return true; Index: lams_tool_forum/web/jsps/learning/message/topiclist.jsp =================================================================== diff -u -rdba3e6022ca1e0478e053c415095b14db37576c7 -r86ef0c92b6e5b8a3915fcc960b918ab95b629503 --- lams_tool_forum/web/jsps/learning/message/topiclist.jsp (.../topiclist.jsp) (revision dba3e6022ca1e0478e053c415095b14db37576c7) +++ lams_tool_forum/web/jsps/learning/message/topiclist.jsp (.../topiclist.jsp) (revision 86ef0c92b6e5b8a3915fcc960b918ab95b629503) @@ -15,6 +15,12 @@ + + +   + + @@ -45,6 +51,12 @@ + + + ${topic.numOfPosts} / ${sessionMap.minimumReply} + + Index: lams_tool_forum/web/jsps/learning/message/topicview.jsp =================================================================== diff -u -rdba3e6022ca1e0478e053c415095b14db37576c7 -r86ef0c92b6e5b8a3915fcc960b918ab95b629503 --- lams_tool_forum/web/jsps/learning/message/topicview.jsp (.../topicview.jsp) (revision dba3e6022ca1e0478e053c415095b14db37576c7) +++ lams_tool_forum/web/jsps/learning/message/topicview.jsp (.../topicview.jsp) (revision 86ef0c92b6e5b8a3915fcc960b918ab95b629503) @@ -62,7 +62,6 @@ - @@ -147,7 +146,7 @@ + test="${(not sessionMap.finishedLock) && (not noMorePosts) && (sessionMap.mode ne 'teacher')}"> Index: lams_tool_forum/web/jsps/learning/viewforum.jsp =================================================================== diff -u -rdba3e6022ca1e0478e053c415095b14db37576c7 -r86ef0c92b6e5b8a3915fcc960b918ab95b629503 --- lams_tool_forum/web/jsps/learning/viewforum.jsp (.../viewforum.jsp) (revision dba3e6022ca1e0478e053c415095b14db37576c7) +++ lams_tool_forum/web/jsps/learning/viewforum.jsp (.../viewforum.jsp) (revision 86ef0c92b6e5b8a3915fcc960b918ab95b629503) @@ -1,5 +1,6 @@ <%@ include file="/common/taglibs.jsp"%> - +
@@ -12,20 +13,32 @@
- - -
- - - - - - - - -
+ + +
+ + + + + + + + +
+
+ + +
+ + + + +
+
+
-
<%@ include file="/common/messages.jsp"%> @@ -72,7 +85,8 @@ - +

${sessionMap.reflectInstructions} Index: lams_tool_forum/web/jsps/learning/viewtopic.jsp =================================================================== diff -u -rdba3e6022ca1e0478e053c415095b14db37576c7 -r86ef0c92b6e5b8a3915fcc960b918ab95b629503 --- lams_tool_forum/web/jsps/learning/viewtopic.jsp (.../viewtopic.jsp) (revision dba3e6022ca1e0478e053c415095b14db37576c7) +++ lams_tool_forum/web/jsps/learning/viewtopic.jsp (.../viewtopic.jsp) (revision 86ef0c92b6e5b8a3915fcc960b918ab95b629503) @@ -14,6 +14,7 @@

${sessionMap.title}

+
@@ -25,15 +26,29 @@ styleClass="button"> -

- + + +
+ + + + + + +
+
+
+
+ <%@ include file="message/topicview.jsp"%> @@ -50,14 +65,10 @@ styleClass="button"> -
- - -