Index: messageforums-component-impl/src/java/org/sakaiproject/component/app/messageforums/MessageForumsMessageManagerImpl.java =================================================================== --- messageforums-component-impl/src/java/org/sakaiproject/component/app/messageforums/MessageForumsMessageManagerImpl.java (revision 89226) +++ messageforums-component-impl/src/java/org/sakaiproject/component/app/messageforums/MessageForumsMessageManagerImpl.java (working copy) @@ -384,6 +384,38 @@ return (List)getHibernateTemplate().execute(hcb); } + public List findAuthoredMessagesForStudentByTopicId(final String studentId, final Long topicId) { + if (LOG.isDebugEnabled()) LOG.debug("findReadMessagesForCurrentStudentByTopicId()"); + + HibernateCallback hcb = new HibernateCallback() { + public Object doInHibernate(Session session) throws HibernateException, SQLException { + Query q = session.getNamedQuery("findAuthoredMessagesForStudentByTopicId"); + q.setParameter("contextId", getContextId(), Hibernate.STRING); + q.setParameter("userId", studentId, Hibernate.STRING); + q.setParameter("topicId", topicId, Hibernate.LONG); + return q.list(); + } + }; + + return (List)getHibernateTemplate().execute(hcb); + } + + public List findAuthoredMessagesForStudentByForumId(final String studentId, final Long forumId) { + if (LOG.isDebugEnabled()) LOG.debug("findAuthoredMessagesForStudentByForumId()"); + + HibernateCallback hcb = new HibernateCallback() { + public Object doInHibernate(Session session) throws HibernateException, SQLException { + Query q = session.getNamedQuery("findAuthoredMessagesForStudentByForumId"); + q.setParameter("contextId", getContextId(), Hibernate.STRING); + q.setParameter("userId", studentId, Hibernate.STRING); + q.setParameter("forumId", forumId, Hibernate.LONG); + return q.list(); + } + }; + + return (List)getHibernateTemplate().execute(hcb); + } + public List findAuthoredMessageCountForAllStudents() { if (LOG.isDebugEnabled()) LOG.debug("findAuthoredMessageCountForAllStudents executing"); @@ -398,6 +430,36 @@ return (List)getHibernateTemplate().execute(hcb); } + public List findAuthoredMessageCountForAllStudentsByTopicId(final Long topicId) { + if (LOG.isDebugEnabled()) LOG.debug("findAuthoredMessageCountForAllStudentsByTopicId executing"); + + HibernateCallback hcb = new HibernateCallback() { + public Object doInHibernate(Session session) throws HibernateException, SQLException { + Query q = session.getNamedQuery("findAuthoredMessageCountForAllStudentsByTopicId"); + q.setParameter("contextId", getContextId(), Hibernate.STRING); + q.setParameter("topicId", topicId, Hibernate.LONG); + return q.list(); + } + }; + + return (List)getHibernateTemplate().execute(hcb); + } + + public List findAuthoredMessageCountForAllStudentsByForumId(final Long forumId) { + if (LOG.isDebugEnabled()) LOG.debug("findAuthoredMessageCountForAllStudentsByForumId executing"); + + HibernateCallback hcb = new HibernateCallback() { + public Object doInHibernate(Session session) throws HibernateException, SQLException { + Query q = session.getNamedQuery("findAuthoredMessageCountForAllStudentsByForumId"); + q.setParameter("contextId", getContextId(), Hibernate.STRING); + q.setParameter("forumId", forumId, Hibernate.LONG); + return q.list(); + } + }; + + return (List)getHibernateTemplate().execute(hcb); + } + public int findReadMessageCountByTopicIdByUserId(final Long topicId, final String userId) { if (topicId == null || userId == null) { LOG.error("findReadMessageCountByTopicIdByUserId failed with topicId: " + topicId + @@ -459,6 +521,38 @@ return (List)getHibernateTemplate().execute(hcb); } + public List findReadMessagesForStudentByTopicId(final String studentId, final Long topicId) { + if (LOG.isDebugEnabled()) LOG.debug("findReadMessagesForCurrentStudentByTopicId()"); + + HibernateCallback hcb = new HibernateCallback() { + public Object doInHibernate(Session session) throws HibernateException, SQLException { + Query q = session.getNamedQuery("findReadMessagesForStudentByTopicId"); + q.setParameter("contextId", getContextId(), Hibernate.STRING); + q.setParameter("userId", studentId, Hibernate.STRING); + q.setParameter("topicId", topicId, Hibernate.LONG); + return q.list(); + } + }; + + return (List)getHibernateTemplate().execute(hcb); + } + + public List findReadMessagesForStudentByForumId(final String studentId, final Long forumId) { + if (LOG.isDebugEnabled()) LOG.debug("findReadMessagesForStudentByForumId()"); + + HibernateCallback hcb = new HibernateCallback() { + public Object doInHibernate(Session session) throws HibernateException, SQLException { + Query q = session.getNamedQuery("findReadMessagesForStudentByForumId"); + q.setParameter("contextId", getContextId(), Hibernate.STRING); + q.setParameter("userId", studentId, Hibernate.STRING); + q.setParameter("forumId", forumId, Hibernate.LONG); + return q.list(); + } + }; + + return (List)getHibernateTemplate().execute(hcb); + } + public List findReadMessageCountForAllStudents() { if (LOG.isDebugEnabled()) LOG.debug("findReadMessageCountForAllStudentsInSite executing"); @@ -473,6 +567,36 @@ return (List)getHibernateTemplate().execute(hcb); } + public List findReadMessageCountForAllStudentsByTopicId(final Long topicId) { + if (LOG.isDebugEnabled()) LOG.debug("findReadMessageCountForAllStudentsByTopicId executing"); + + HibernateCallback hcb = new HibernateCallback() { + public Object doInHibernate(Session session) throws HibernateException, SQLException { + Query q = session.getNamedQuery("findReadMessageCountForAllStudentsByTopicId"); + q.setParameter("contextId", getContextId(), Hibernate.STRING); + q.setParameter("topicId", topicId, Hibernate.LONG); + return q.list(); + } + }; + + return (List)getHibernateTemplate().execute(hcb); + } + + public List findReadMessageCountForAllStudentsByForumId(final Long forumId) { + if (LOG.isDebugEnabled()) LOG.debug("findReadMessageCountForAllStudentsByForumId executing"); + + HibernateCallback hcb = new HibernateCallback() { + public Object doInHibernate(Session session) throws HibernateException, SQLException { + Query q = session.getNamedQuery("findReadMessageCountForAllStudentsByForumId"); + q.setParameter("contextId", getContextId(), Hibernate.STRING); + q.setParameter("forumId", forumId, Hibernate.LONG); + return q.list(); + } + }; + + return (List)getHibernateTemplate().execute(hcb); + } + /** * Returns count of all messages in a topic that have been approved or were authored by given user */ @@ -687,6 +811,25 @@ return ((Integer) getHibernateTemplate().execute(hcb)).intValue(); } + public int findMessageCountByForumId(final Long forumId) { + if (forumId == null) { + LOG.error("findMessageCountByForumId failed with forumId: " + forumId); + throw new IllegalArgumentException("Null Argument"); + } + + LOG.debug("findMessageCountByForumId executing with forumId: " + forumId); + + HibernateCallback hcb = new HibernateCallback() { + public Object doInHibernate(Session session) throws HibernateException, SQLException { + Query q = session.getNamedQuery("findMessageCountByForumId"); + q.setParameter("forumId", forumId, Hibernate.LONG); + return q.uniqueResult(); + } + }; + + return ((Integer) getHibernateTemplate().execute(hcb)).intValue(); + } + /* + * (non-Javadoc) + * @see org.sakaiproject.api.app.messageforums.MessageForumsForumManager#findMessageCountsForMainPage(java.util.List) Index: messageforums-hbm/src/java/org/sakaiproject/component/app/messageforums/dao/hibernate/MessageImpl.hbm.xml =================================================================== --- messageforums-hbm/src/java/org/sakaiproject/component/app/messageforums/dao/hibernate/MessageImpl.hbm.xml (revision 89226) +++ messageforums-hbm/src/java/org/sakaiproject/component/app/messageforums/dao/hibernate/MessageImpl.hbm.xml (working copy) @@ -158,6 +158,9 @@ + + + + + + + + + + + + + + + + + + + Index: messageforums-api/src/java/org/sakaiproject/api/app/messageforums/MessageForumsMessageManager.java =================================================================== --- messageforums-api/src/java/org/sakaiproject/api/app/messageforums/MessageForumsMessageManager.java (revision 89226) +++ messageforums-api/src/java/org/sakaiproject/api/app/messageforums/MessageForumsMessageManager.java (working copy) @@ -64,6 +64,7 @@ public void deleteUnreadStatus(Long topicId, Long messageId); public int findMessageCountByTopicId(Long topicId); + public int findMessageCountByForumId(Long forumId); public int findMessageCountTotal(); @@ -81,6 +82,8 @@ * as DRAFT or DELETED. */ public List findAuthoredMessagesForStudent(String studentId); + public List findAuthoredMessagesForStudentByTopicId(String studentId, final Long topicId); + public List findAuthoredMessagesForStudentByForumId(String studentId, final Long forumId); /** * @return Each item in the list will be an array consisting of two elements. The element @@ -88,6 +91,8 @@ * to the number of messages that student has authored in the site. */ public List findAuthoredMessageCountForAllStudents(); + public List findAuthoredMessageCountForAllStudentsByTopicId(final Long topicId); + public List findAuthoredMessageCountForAllStudentsByForumId(final Long forumId); public int findUnreadMessageCountByTopicIdByUserId(Long topicId, String userId); @@ -109,13 +114,19 @@ * to the number of messages that student has read in the site. */ public List findReadMessageCountForAllStudents(); + public List findReadMessageCountForAllStudentsByTopicId(final Long topicId); + public List findReadMessageCountForAllStudentsByForumId(final Long forumId); + + /** * @param studentId The id of the student whose read messages we are searching for. * @return A list of all of the messages that the student has read and are not flagged * as DRAFT or DELETED. */ public List findReadMessagesForStudent(String studentId); + public List findReadMessagesForStudentByTopicId(String studentId, final Long topicId); + public List findReadMessagesForStudentByForumId(String studentId, final Long forumId); public int findReadViewableMessageCountByTopicId(Long topicId); Index: messageforums-api/src/bundle/org/sakaiproject/api/app/messagecenter/bundle/Messages.properties =================================================================== --- messageforums-api/src/bundle/org/sakaiproject/api/app/messagecenter/bundle/Messages.properties (revision 89226) +++ messageforums-api/src/bundle/org/sakaiproject/api/app/messagecenter/bundle/Messages.properties (working copy) @@ -52,13 +52,25 @@ cdfm_moderate = Moderate cdfm_mark_as_read=Mark as Read cdfm_readby= - Read by: -stat_list = Statistics +stat_list = Statistics & Grading stat_name = Name stat_authored = Authored stat_read = Read stat_unread = Unread stat_percent_read = Percent Read stat_forum_title = Forum Title +stat_forum_word_count=Word Count +stat_forum_comments=Comments +stat_forum_na=N/A +stat_forum_comments_hide=Hide Comments +stat_forum_comments_show=Show Comments +stat_forum_comments_hidden=--Hidden-- +stat_forum_no_gbitem=------- +stat_forum_submit_grades=Submit Grades +stat_forum_submit_grades_cancel=Cancel Changes +stat_forum_default_grade=Apply Grade to all Ungraded +stat_forum_default_grade_info=You must submit the grades to save your changes. +stat_forum_details=Details stat_topic_title = Topic Title stat_forum_date = Date stat_forum_subject = Subject @@ -77,8 +89,10 @@ stat_display_in_thread=[display in thread] stat_sort_by_topic=Sort by Topic stat_sort_by_date=Sort by Date +stat_byUser=by User +stat_byTopic=by Topic +stat_totalMessages=Total Messages - cdfm_labels=Labels cdfm_newflag=New! cdfm_gotonewtitle=Go to next new message @@ -104,7 +118,7 @@ cdfm_duplicate_forum_confirm=Are you sure you wish to duplicate this forum? cdfm_insufficient_privileges_duplicate=You do not have privileges to duplicate this. cdfm_organize=Organize -cdfm_statistics=Statistics +cdfm_statistics=Statistics & Grading cdfm_template_setting=Template Settings cdfm_default_template_settings=Default Settings Template cdfm_default_template_settings_instruction=Settings from this template will apply each time a new Forum or Topic is created. You can override these settings for a specific Forum or Topic after it has been created. @@ -673,3 +687,9 @@ #properties pvt_properties_desc=Set permissions for the Messages tool pvt_permissions=Permissions + + +#group filtering: +all_users=All Participants +filter_by_group=Filter by group +confirm_navigation=All unsaved grades will be lost Index: messageforums-app/src/java/org/sakaiproject/tool/messageforums/DiscussionForumTool.java =================================================================== --- messageforums-app/src/java/org/sakaiproject/tool/messageforums/DiscussionForumTool.java (revision 89226) +++ messageforums-app/src/java/org/sakaiproject/tool/messageforums/DiscussionForumTool.java (working copy) @@ -162,6 +162,7 @@ private DiscussionTopicBean selectedTopic; private DiscussionTopicBean searchResults; private DiscussionMessageBean selectedMessage; + private String selectedGradedUserId; private DiscussionAreaBean template; private DiscussionMessageBean selectedThreadHead; private List selectedThread = new ArrayList(); @@ -178,6 +179,7 @@ private static final String TOPIC_ID = "topicId"; private static final String FORUM_ID = "forumId"; + private static final String USER_ID = "userId"; private static final String MESSAGE_ID = "messageId"; private static final String REDIRECT_PROCESS_ACTION = "redirectToProcessAction"; private static final String FROMPAGE = "fromPage"; @@ -338,8 +340,17 @@ private int selectedMessageCount = 0; private int functionClick = 0; + private boolean dialogGradeSavedSuccessfully = false; - // email notification options + public boolean isDialogGradeSavedSuccessfully() { + return dialogGradeSavedSuccessfully; + } + + public void setDialogGradeSavedSuccessfully(boolean dialogGradeSavedSuccessfully) { + this.dialogGradeSavedSuccessfully = dialogGradeSavedSuccessfully; + } + +// email notification options private EmailNotificationBean watchSettingsBean; private boolean needToPostFirst; @@ -2584,6 +2595,7 @@ public void getThreadFromMessage() { + if(selectedMessage != null){ Message mes = selectedMessage.getMessage(); String messageId = mes.getId().toString(); while( mes.getInReplyTo() != null) { @@ -2624,6 +2636,7 @@ } } refreshSelectedMessageSettings(selectedMessage.getMessage()); + } } @@ -3976,72 +3989,72 @@ { String messageId = getExternalParameterByKey(MESSAGE_ID); String topicId = getExternalParameterByKey(TOPIC_ID); - if (messageId == null) - { - setErrorMessage(getResourceBundleString(MESSAGE_REFERENCE_NOT_FOUND)); - return gotoMain(); - } + String forumId = getExternalParameterByKey(FORUM_ID); + String userId = getExternalParameterByKey(USER_ID); if (topicId == null) { setErrorMessage(getResourceBundleString(TOPC_REFERENCE_NOT_FOUND)); return gotoMain(); } - // Message message=forumManager.getMessageById(Long.valueOf(messageId)); - Message message = messageManager.getMessageByIdWithAttachments(Long.valueOf( - messageId)); - if (message == null) - { - setErrorMessage(getResourceBundleString(MESSAGE_WITH_ID) + messageId + getResourceBundleString(NOT_FOUND_WITH_QUOTE)); - return gotoMain(); + if((messageId == null || "".equals(messageId)) && (userId == null || "".equals(userId))){ + setErrorMessage(getResourceBundleString(TOPC_REFERENCE_NOT_FOUND)); + return gotoMain(); } + return processDfMsgGrdFromThread(messageId, topicId, forumId, userId); + } + + public String processDfMsgGrdFromThread(String messageId, String topicId, String forumId, String userId){ + + selectedGradedUserId = userId; + + // Message message=forumManager.getMessageById(Long.valueOf(messageId)); + if(messageId != null && !"".equals(messageId)){ + Message message = messageManager.getMessageByIdWithAttachments(Long.valueOf( + messageId)); + if (message == null) + { + setErrorMessage(getResourceBundleString(MESSAGE_WITH_ID) + messageId + getResourceBundleString(NOT_FOUND_WITH_QUOTE)); + return gotoMain(); + } - selectedMessage = new DiscussionMessageBean(message, messageManager); - return processDfMsgGrd(); + selectedMessage = new DiscussionMessageBean(message, messageManager); + + }else{ + selectedMessage = null; + } + + if(selectedForum == null || (forumId != null && !selectedForum.getForum().getId().equals(forumId))){ + DiscussionForum forum = forumManager.getForumById(Long.parseLong(forumId)); + selectedForum = new DiscussionForumBean(forum, uiPermissionsManager, forumManager); + } + + if(topicId == null || "".equals(topicId)){ + selectedTopic = null; + }else if(selectedTopic == null || !selectedTopic.getTopic().getId().equals(topicId)){ + DiscussionTopic topic = forumManager.getTopicById(Long.parseLong(topicId)); + selectedTopic = getDecoratedTopic(topic); + } + + if(selectedMessage != null){ + return processDfMsgGrd(); + }else{ + return processDfMsgGrdHelper(userId, null); + } } public String processDfMsgGrd() { - selectedMessageCount = 0; - functionClick ++; - - if(selectedTopic == null) - { - LOG.debug("selectedTopic is null in processDfMsgGrd"); - return gotoMain(); - } - - grade_too_large_make_sure = false; - - selectedAssign = DEFAULT_GB_ITEM; - resetGradeInfo(); - try { String createdById = UserDirectoryService.getUser(selectedMessage.getMessage().getCreatedBy()).getId(); - String gradebookUid = ToolManager.getCurrentPlacement().getContext(); String msgAssignmentName = selectedMessage.getMessage().getGradeAssignmentName(); - String topicDefaultAssignment = selectedTopic.getTopic().getDefaultAssignName(); - String forumDefaultAssignment = selectedForum.getForum().getDefaultAssignName(); - - String selAssignmentName = null; - if (msgAssignmentName !=null && msgAssignmentName.trim().length()>0) { - selAssignmentName = msgAssignmentName; - } else if (topicDefaultAssignment != null && topicDefaultAssignment.trim().length() > 0) { - selAssignmentName = topicDefaultAssignment; - } else if (forumDefaultAssignment != null && forumDefaultAssignment.trim().length() > 0) { - selAssignmentName = forumDefaultAssignment; - } - - if (selAssignmentName != null) { - setUpGradeInformation(gradebookUid, selAssignmentName, createdById); - } else { - // this is the "Select a gradebook item" selection - allowedToGradeItem = false; - selGBItemRestricted = true; - } - + + String returnStr = processDfMsgGrdHelper(createdById, msgAssignmentName); + // mark this message as read messageManager.markMessageReadForUser(selectedTopic.getTopic().getId(), selectedMessage.getMessage().getId(), true); + + return returnStr; } catch(Exception e) { @@ -4049,7 +4062,43 @@ e.printStackTrace(); return null; } + } + + private String processDfMsgGrdHelper(String userId, String msgAssignmentName){ + selectedMessageCount = 0; + functionClick ++; + + grade_too_large_make_sure = false; + + selectedAssign = DEFAULT_GB_ITEM; + resetGradeInfo(); + + String gradebookUid = ToolManager.getCurrentPlacement().getContext(); + + String topicDefaultAssignment = null; + if(selectedTopic != null){ + topicDefaultAssignment = selectedTopic.getTopic().getDefaultAssignName(); + } + String forumDefaultAssignment = selectedForum.getForum().getDefaultAssignName(); + + String selAssignmentName = null; + if (msgAssignmentName !=null && msgAssignmentName.trim().length()>0) { + selAssignmentName = msgAssignmentName; + } else if (topicDefaultAssignment != null && topicDefaultAssignment.trim().length() > 0) { + selAssignmentName = topicDefaultAssignment; + } else if (forumDefaultAssignment != null && forumDefaultAssignment.trim().length() > 0) { + selAssignmentName = forumDefaultAssignment; + } + + if (selAssignmentName != null) { + setUpGradeInformation(gradebookUid, selAssignmentName, userId); + } else { + // this is the "Select a gradebook item" selection + allowedToGradeItem = false; + selGBItemRestricted = true; + } + return GRADE_MESSAGE; } @@ -4830,7 +4879,7 @@ * @param message * @return */ - private String getEventReference(Message message) + private String getEventReference(Object obj) { String eventMessagePrefix = ""; final String toolId = ToolManager.getCurrentTool().getId(); @@ -4842,7 +4891,7 @@ else eventMessagePrefix = "/forums"; - return eventMessagePrefix + getContextSiteId() + "/" + message.toString() + "/" + SessionManager.getCurrentSessionUserId(); + return eventMessagePrefix + getContextSiteId() + "/" + obj.toString() + "/" + SessionManager.getCurrentSessionUserId(); } /** @@ -5862,8 +5911,13 @@ if(!DEFAULT_GB_ITEM.equalsIgnoreCase(selectedAssign)) { String gradebookUid = ToolManager.getCurrentPlacement().getContext(); - String selAssignName = ((SelectItem)assignments.get((Integer.valueOf(selectedAssign)).intValue())).getLabel(); - String studentId = UserDirectoryService.getUser(selectedMessage.getMessage().getCreatedBy()).getId(); + String selAssignName = ((SelectItem)assignments.get((Integer.valueOf(selectedAssign)).intValue())).getLabel(); + String studentId; + if(selectedMessage == null && selectedGradedUserId != null && !"".equals(selectedGradedUserId)){ + studentId = selectedGradedUserId; + }else{ + studentId = UserDirectoryService.getUser(selectedMessage.getMessage().getCreatedBy()).getId(); + } setUpGradeInformation(gradebookUid, selAssignName, studentId); } else { @@ -5941,6 +5995,15 @@ return true; } + public String processDfGradeSubmitFromDialog(){ + String result = processDfGradeSubmit(); + if(MESSAGE_VIEW.equals(result)){ + //success + dialogGradeSavedSuccessfully = true; + } + return null; + } + public String processDfGradeSubmit() { GradebookService gradebookService = getGradebookService(); @@ -5955,12 +6018,6 @@ } functionClick = 0; selectedMessageCount = 0; - - if(selectedTopic == null) - { - LOG.debug("selectedTopic is null in processDfGradeSubmit"); - return gotoMain(); - } gbItemScore = gradePoint; gbItemComment = gradeComment; @@ -6007,8 +6064,13 @@ { String selectedAssignName = ((SelectItem)assignments.get((Integer.valueOf(selectedAssign)).intValue())).getLabel(); String gradebookUuid = ToolManager.getCurrentPlacement().getContext(); - String studentUid = UserDirectoryService.getUser(selectedMessage.getMessage().getCreatedBy()).getId(); - + String studentUid; + if(selectedMessage == null && selectedGradedUserId != null && !"".equals(selectedGradedUserId)){ + studentUid = selectedGradedUserId; + }else{ + studentUid = UserDirectoryService.getUser(selectedMessage.getMessage().getCreatedBy()).getId(); + } + gradebookService.setAssignmentScore(gradebookUuid, selectedAssignName, studentUid, gradeAsDouble, ""); if (gradeComment != null && gradeComment.trim().length() > 0) @@ -6017,11 +6079,13 @@ selectedAssignName, studentUid, gradeComment); } - Message msg = selectedMessage.getMessage(); - msg.setGradeAssignmentName(selectedAssignName); - msg.setTopic((DiscussionTopic) forumManager - .getTopicByIdWithMessages(selectedTopic.getTopic().getId())); - forumManager.saveMessage(msg, false); + if(selectedMessage != null){ + Message msg = selectedMessage.getMessage(); + msg.setGradeAssignmentName(selectedAssignName); + msg.setTopic((DiscussionTopic) forumManager + .getTopicByIdWithMessages(selectedTopic.getTopic().getId())); + forumManager.saveMessage(msg, false); + } setSuccessMessage(getResourceBundleString(GRADE_SUCCESSFUL)); } @@ -6035,7 +6099,15 @@ e.printStackTrace(); } - EventTrackingService.post(EventTrackingService.newEvent(DiscussionForumService.EVENT_FORUMS_GRADE, getEventReference(selectedMessage.getMessage()), true)); + String eventRef = ""; + if(selectedMessage != null){ + eventRef = getEventReference(selectedMessage.getMessage()); + }else if(selectedTopic != null){ + eventRef = getEventReference(selectedTopic.getTopic()); + }else if(selectedForum != null){ + eventRef = getEventReference(selectedForum.getForum()); + } + EventTrackingService.post(EventTrackingService.newEvent(DiscussionForumService.EVENT_FORUMS_GRADE, eventRef, true)); gradeNotify = false; selectedAssign = DEFAULT_GB_ITEM; Index: messageforums-app/src/java/org/sakaiproject/tool/messageforums/ui/MessageForumStatisticsBean.java =================================================================== --- messageforums-app/src/java/org/sakaiproject/tool/messageforums/ui/MessageForumStatisticsBean.java (revision 89226) +++ messageforums-app/src/java/org/sakaiproject/tool/messageforums/ui/MessageForumStatisticsBean.java (working copy) @@ -21,32 +21,53 @@ package org.sakaiproject.tool.messageforums.ui; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import java.util.TreeMap; +import javax.faces.application.FacesMessage; import javax.faces.context.ExternalContext; import javax.faces.context.FacesContext; +import javax.faces.event.ValueChangeEvent; +import javax.faces.model.SelectItem; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.sakaiproject.api.app.messageforums.Attachment; import org.sakaiproject.api.app.messageforums.DiscussionForum; +import org.sakaiproject.api.app.messageforums.DiscussionForumService; +import org.sakaiproject.api.app.messageforums.DiscussionTopic; import org.sakaiproject.api.app.messageforums.MembershipManager; import org.sakaiproject.api.app.messageforums.Message; import org.sakaiproject.api.app.messageforums.MessageForumsMessageManager; import org.sakaiproject.api.app.messageforums.Topic; import org.sakaiproject.api.app.messageforums.ui.DiscussionForumManager; import org.sakaiproject.api.app.messageforums.ui.UIPermissionsManager; +import org.sakaiproject.authz.api.Member; import org.sakaiproject.component.app.messageforums.MembershipItem; +import org.sakaiproject.component.cover.ComponentManager; import org.sakaiproject.component.cover.ServerConfigurationService; +import org.sakaiproject.event.cover.EventTrackingService; +import org.sakaiproject.exception.IdUnusedException; +import org.sakaiproject.site.api.Group; +import org.sakaiproject.site.api.Site; +import org.sakaiproject.site.cover.SiteService; +import org.sakaiproject.service.gradebook.shared.Assignment; +import org.sakaiproject.service.gradebook.shared.CommentDefinition; +import org.sakaiproject.service.gradebook.shared.GradeDefinition; +import org.sakaiproject.service.gradebook.shared.GradebookService; import org.sakaiproject.tool.cover.SessionManager; +import org.sakaiproject.tool.cover.ToolManager; import org.sakaiproject.user.api.User; import org.sakaiproject.user.api.UserNotDefinedException; import org.sakaiproject.user.cover.UserDirectoryService; @@ -69,8 +90,8 @@ private int readForumsAmt; private int unreadForumsAmt; private Double percentReadForumsAmt; - - + private DecoratedGradebookAssignment gradebookAssignment; + public String getSiteName(){ return this.siteName; } @@ -138,6 +159,15 @@ public void setPercentReadFOrumsAmt(Double newValue){ this.percentReadForumsAmt = newValue; } + + public DecoratedGradebookAssignment getGradebookAssignment() { + return gradebookAssignment; + } + + public void setGradebookAssignment( + DecoratedGradebookAssignment gradebookAssignment) { + this.gradebookAssignment = gradebookAssignment; + } } /* === End DecoratedCompiledMessageStatistics === */ @@ -272,6 +302,134 @@ } /* === End DecoratedCompiledUserStatistics == */ + public class DecoratedGradebookAssignment{ + private String userUuid; + private String name; + private String score; + private String comment; + private String pointsPossible; + private boolean allowedToGrade = false; + + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public String getScore() { + return score; + } + public void setScore(String score) { + this.score = score; + } + public String getComment() { + return comment; + } + public void setComment(String comment) { + this.comment = comment; + } + public String getPointsPossible() { + return pointsPossible; + } + public void setPointsPossible(String pointsPossible) { + this.pointsPossible = pointsPossible; + } + public boolean isAllowedToGrade() { + return allowedToGrade; + } + public void setAllowedToGrade(boolean allowedToGrade) { + this.allowedToGrade = allowedToGrade; + } + public String getUserUuid() { + return userUuid; + } + public void setUserUuid(String userUuid) { + this.userUuid = userUuid; + } + } + + public class DecoratedCompiledStatisticsByTopic{ + private Long topicId; + private Long forumId; + private String forumTitle; + private String topicTitle; + private Date forumDate; + private Date topicDate; + private int authoredForumsAmt; + private int totalTopicMessages; + private int unreadTopicMessages; + private Double percentReadForumsAmt; + private DecoratedGradebookAssignment gradebookAssignment; + + public String getForumTitle() { + return forumTitle; + } + public void setForumTitle(String forumTitle) { + this.forumTitle = forumTitle; + } + public String getTopicTitle() { + return topicTitle; + } + public void setTopicTitle(String topicTitle) { + this.topicTitle = topicTitle; + } + public Date getForumDate() { + return forumDate; + } + public void setForumDate(Date forumDate) { + this.forumDate = forumDate; + } + public int getAuthoredForumsAmt() { + return authoredForumsAmt; + } + public void setAuthoredForumsAmt(int authoredForumsAmt) { + this.authoredForumsAmt = authoredForumsAmt; + } + public Double getPercentReadForumsAmt() { + return percentReadForumsAmt; + } + public void setPercentReadForumsAmt(Double percentReadForumsAmt) { + this.percentReadForumsAmt = percentReadForumsAmt; + } + public int getTotalTopicMessages() { + return totalTopicMessages; + } + public void setTotalTopicMessages(int totalTopicMessages) { + this.totalTopicMessages = totalTopicMessages; + } + public int getUnreadTopicMessages() { + return unreadTopicMessages; + } + public void setUnreadTopicMessages(int unreadTopicMessages) { + this.unreadTopicMessages = unreadTopicMessages; + } + public Date getTopicDate() { + return topicDate; + } + public void setTopicDate(Date topicDate) { + this.topicDate = topicDate; + } + public Long getTopicId() { + return topicId; + } + public void setTopicId(Long topicId) { + this.topicId = topicId; + } + public Long getForumId() { + return forumId; + } + public void setForumId(Long forumId) { + this.forumId = forumId; + } + public DecoratedGradebookAssignment getGradebookAssignment() { + return gradebookAssignment; + } + public void setGradebookAssignment( + DecoratedGradebookAssignment gradebookAssignment) { + this.gradebookAssignment = gradebookAssignment; + } + } + /** Decorated Bean to store stats for user **/ public DecoratedCompiledMessageStatistics userInfo = null; public DecoratedCompiledUserStatistics userAuthoredInfo = null; @@ -281,10 +439,12 @@ protected boolean ascendingForUser = false; protected boolean ascendingForUser2 = false; protected boolean ascendingForUser3 = false; + protected boolean ascendingForAllTopics = false; protected String sortBy = NAME_SORT; protected String sortByUser = FORUM_DATE_SORT; protected String sortByUser2 = FORUM_DATE_SORT2; protected String sortByUser3 = FORUM_DATE_SORT3; + protected String sortByAllTopics = ALL_TOPICS_FORUM_TITLE_SORT; private static final String LIST_PAGE = "dfStatisticsList"; @@ -293,6 +453,7 @@ private static final String READ_SORT = "sort_by_num_read"; private static final String UNREAD_SORT = "sort_by_num_unread"; private static final String PERCENT_READ_SORT = "sort_by_percent_read"; + private static final String GRADE_SORT = "sort_by_grade"; private static final String SITE_USER_ID = "siteUserId"; private static final String SITE_USER = "siteUser"; private static final String FORUM_TITLE_SORT = "sort_by_forum_title"; @@ -305,12 +466,23 @@ private static final String FORUM_SUBJECT_SORT2 = "sort_by_forum_subject_2"; private static final String FORUM_DATE_SORT3 = "sort_by_forum_date_3"; private static final String TOPIC_TITLE_SORT3 = "sort_by_forum_subject_3"; + private static final String ALL_TOPICS_FORUM_TITLE_SORT = "sort_by_all_topics_forum_title"; + private static final String ALL_TOPICS_FORUM_DATE_SORT = "sort_by_all_topics_forum_date"; + private static final String ALL_TOPICS_TOPIC_DATE_SORT = "sort_by_all_topics_topic_date"; + private static final String ALL_TOPICS_TOPIC_TITLE_SORT = "sort_by_all_topics_topic_title"; + private static final String ALL_TOPICS_TOPIC_TOTAL_MESSAGES_SORT = "sort_by_all_topics_topic_total_messages"; + private static final String TOPIC_ID = "topicId"; + private static final String FORUM_ID = "forumId"; + private static final String TOPIC_TITLE = "topicTitle"; + private static final String FORUM_TITLE = "forumTitle"; private static final String MESSAGECENTER_BUNDLE = "org.sakaiproject.api.app.messagecenter.bundle.Messages"; private static final String FORUM_STATISTICS = "dfStatisticsList"; + private static final String FORUM_STATISTICS_BY_ALL_TOPICS = "dfStatisticsListByAllTopics"; + private static final String FORUM_STATISTICS_BY_TOPIC = "dfStatisticsListByTopic"; private static final String FORUM_STATISTICS_USER = "dfStatisticsUser"; private static final String FORUM_STATISTICS_ALL_AUTHORED_MSG = "dfStatisticsAllAuthoredMessageForOneUser"; private static final String FORUM_STATISTICS_MSG = "dfStatisticsFullTextForOne"; @@ -323,6 +495,10 @@ public String selectedForumTitle= null; public String selectedTopicTitle= null; public String selectedTopicId= null; + public String selectedAllTopicsTopicId = null; + public String selectedAllTopicsForumId = null; + public String selectedAllTopicsTopicTitle = null; + public String selectedAllTopicsForumTitle = null; private String buttonUserName; private boolean isFirstParticipant = false; @@ -334,12 +510,14 @@ public static Comparator readComparatorAsc; public static Comparator unreadComparatorAsc; public static Comparator percentReadComparatorAsc; + public static Comparator GradeComparatorAsc; public static Comparator nameComparatorDesc; public static Comparator authoredComparatorDesc; public static Comparator readComparatorDesc; public static Comparator unreadComparatorDesc; public static Comparator percentReadComparatorDesc; public static Comparator dateComparaterDesc; + public static Comparator GradeComparatorDesc; public static Comparator forumTitleComparatorAsc; public static Comparator forumTitleComparatorDesc; public static Comparator topicTitleComparatorAsc; @@ -348,6 +526,36 @@ public static Comparator forumDateComparatorDesc; public static Comparator forumSubjectComparatorAsc; public static Comparator forumSubjectComparatorDesc; + public static Comparator AllTopicsForumDateComparatorAsc; + public static Comparator AllTopicsTopicDateComparatorAsc; + public static Comparator AllTopicsTopicTitleComparatorAsc; + public static Comparator AllTopicsTopicTotalMessagesComparatorAsc; + public static Comparator AllTopicsForumTitleComparatorAsc; + public static Comparator AllTopicsForumDateComparatorDesc; + public static Comparator AllTopicsTopicDateComparatorDesc; + public static Comparator AllTopicsTopicTitleComparatorDesc; + + public static Comparator AllTopicsTopicTotalMessagesComparatorDesc; + public static Comparator AllTopicsForumTitleComparatorDesc; + + private static final String DEFAULT_GB_ITEM = "Default_0"; + private static final String DEFAULT_ALL_GROUPS = "all_participants_desc"; + private static final String SELECT_ASSIGN = "stat_forum_no_gbitem"; + private boolean gradebookExistChecked = false; + private boolean gradebookExist = false; + private List assignments = null; + private List groups = null; + private String selectedAssign = DEFAULT_GB_ITEM; + private String selectedGroup = DEFAULT_GB_ITEM; + private boolean gradebookItemChosen = false; + private String selAssignName; + private String gbItemPointsPossible; + private List gradeStatistics = null; + private static final String NO_ASSGN = "cdfm_no_assign_for_grade"; + private static final String ALERT = "cdfm_alert"; + private static final String GRADE_SUCCESSFUL = "cdfm_grade_successful"; + private static final String GRADE_GREATER_ZERO = "cdfm_grade_greater_than_zero"; + private static final String GRADE_DECIMAL_WARN = "cdfm_grade_decimal_warn"; public Map getCourseMemberMap(){ @@ -410,6 +618,12 @@ public List getAllUserStatistics(){ + selectedAllTopicsTopicId = null; + selectedAllTopicsForumId = null; + selectedAllTopicsForumTitle = null; + selectedAllTopicsTopicTitle = null; + //clear any gradebook info: + resetGradebookVariables(); int totalForum = messageManager.findMessageCountTotal(); Map tmpStatistics = new TreeMap(); @@ -485,7 +699,15 @@ public List getUserAuthoredStatistics(){ final List statistics = new ArrayList(); - List messages = messageManager.findAuthoredMessagesForStudent(selectedSiteUserId); + List messages; + if((selectedAllTopicsTopicId == null || "".equals(selectedAllTopicsTopicId)) + && (selectedAllTopicsForumId != null && !"".equals(selectedAllTopicsForumId))){ + messages = messageManager.findAuthoredMessagesForStudentByForumId(selectedSiteUserId, Long.parseLong(selectedAllTopicsForumId)); + }else if(selectedAllTopicsTopicId != null && !"".equals(selectedAllTopicsTopicId)){ + messages = messageManager.findAuthoredMessagesForStudentByTopicId(selectedSiteUserId, Long.parseLong(selectedAllTopicsTopicId)); + }else{ + messages = messageManager.findAuthoredMessagesForStudent(selectedSiteUserId); + } if (messages == null) return statistics; for (Message msg: messages) { @@ -498,17 +720,213 @@ userAuthoredInfo.setMsgId(Long.toString(msg.getId())); userAuthoredInfo.setTopicId(Long.toString(msg.getTopic().getId())); userAuthoredInfo.setForumId(Long.toString(msg.getTopic().getOpenForum().getId())); + userAuthoredInfo.setMessage(msg.getBody()); statistics.add(userAuthoredInfo); } sortStatisticsByUser(statistics); return statistics; } + + public List getTopicStatistics(){ + final List statistics = new ArrayList(); + + if((selectedAllTopicsTopicId != null && !"".equals(selectedAllTopicsTopicId)) || selectedAllTopicsForumId != null && !"".equals(selectedAllTopicsForumId)){ + int totalForum = 0; + if(selectedAllTopicsTopicId != null && !"".equals(selectedAllTopicsTopicId)){ + totalForum = messageManager.findMessageCountByTopicId(Long.parseLong(selectedAllTopicsTopicId)); + }else{ + totalForum = messageManager.findMessageCountByForumId(Long.parseLong(selectedAllTopicsForumId)); + } + Map tmpStatistics = new TreeMap(); + + // process the returned read statistics for the students to get them sorted by user id + List studentReadStats; + if(selectedAllTopicsTopicId != null && !"".equals(selectedAllTopicsTopicId)){ + studentReadStats = messageManager.findReadMessageCountForAllStudentsByTopicId(Long.parseLong(selectedAllTopicsTopicId)); + }else{ + studentReadStats = messageManager.findReadMessageCountForAllStudentsByForumId(Long.parseLong(selectedAllTopicsForumId)); + } + + for (Object[] readStat: studentReadStats) { + DecoratedCompiledMessageStatistics userStats = tmpStatistics.get(readStat[0]); + if (userStats == null) { + userStats = new DecoratedCompiledMessageStatistics(); + tmpStatistics.put((String)readStat[0], userStats); + } + + if (totalForum > 0) { + userStats.setReadForumsAmt((Integer)readStat[1]); + } else { + userStats.setReadForumsAmt(0); + } + } + + // process the returned authored statistics for the students to get them sorted by user id + List studentAuthoredStats; + if(selectedAllTopicsTopicId != null && !"".equals(selectedAllTopicsTopicId)){ + studentAuthoredStats = messageManager.findAuthoredMessageCountForAllStudentsByTopicId(Long.parseLong(selectedAllTopicsTopicId)); + }else{ + studentAuthoredStats = messageManager.findAuthoredMessageCountForAllStudentsByForumId(Long.parseLong(selectedAllTopicsForumId)); + } + + for (Object[] authoredStat: studentAuthoredStats) { + DecoratedCompiledMessageStatistics userStats = tmpStatistics.get(authoredStat[0]); + if (userStats == null) { + userStats = new DecoratedCompiledMessageStatistics(); + tmpStatistics.put((String)authoredStat[0], userStats); + } + + if (totalForum > 0) { + userStats.setAuthoredForumsAmt((Integer)authoredStat[1]); + } else { + userStats.setAuthoredForumsAmt(0); + } + } + + // now process the users from the list of site members to add display information + // this will also prune the list of members so only the papropriate ones are displayed + courseMemberMap = membershipManager.getAllCourseMembers(true,false,false); + Map convertedMap = convertMemberMapToUserIdMap(courseMemberMap); + Map studentGradesMap = getGradebookAssignment(); + List dUsers = new ArrayList(); + + if(!DEFAULT_GB_ITEM.equals(selectedGroup)){ + try{ + Site currentSite = SiteService.getSite(ToolManager.getCurrentPlacement().getContext()); + if(currentSite.hasGroups()){ + Group group = currentSite.getGroup(selectedGroup); + + for (Iterator i = group.getMembers().iterator(); i.hasNext();) { + Member item = (Member) i.next(); + if(convertedMap.containsKey(item.getUserId())){ + MembershipItem memItem = (MembershipItem) convertedMap.get(item.getUserId()); + if (null != memItem.getUser()) { + dUsers.add(new DecoratedUser(memItem.getUser().getId(), memItem.getName())); + } + } + } + } + }catch (IdUnusedException e) { + LOG.error(e); + } + }else{ + for (Iterator i = courseMemberMap.entrySet().iterator(); i.hasNext();) { + Entry entry = (Entry) i.next(); + MembershipItem item = (MembershipItem) entry.getValue(); + if (null != item.getUser()) { + dUsers.add(new DecoratedUser(item.getUser().getId(), item.getName())); + } + } + } + + for (Iterator i = dUsers.iterator(); i.hasNext();) { + DecoratedUser item = (DecoratedUser) i.next(); + userInfo = tmpStatistics.get(item.getId()); + if (userInfo == null) { + userInfo = new DecoratedCompiledMessageStatistics(); + userInfo.setReadForumsAmt(0); + userInfo.setAuthoredForumsAmt(0); + } + + userInfo.setSiteUserId(item.getId()); + userInfo.setSiteUser(item.getName()); + + if (totalForum > 0) { + userInfo.setUnreadForumsAmt(totalForum - userInfo.getReadForumsAmt()); + userInfo.setPercentReadFOrumsAmt((double)userInfo.getReadForumsAmt() / (double)totalForum); + } else { + userInfo.setUnreadForumsAmt(0); + userInfo.setPercentReadFOrumsAmt((double)0); + } + + DecoratedGradebookAssignment decoGradeAssgn = studentGradesMap.get(item.getId()); + if(decoGradeAssgn == null){ + decoGradeAssgn = new DecoratedGradebookAssignment(); + decoGradeAssgn.setAllowedToGrade(false); + decoGradeAssgn.setUserUuid(item.getId()); + } + + userInfo.setGradebookAssignment(decoGradeAssgn); + + statistics.add(userInfo); + } + + sortStatistics(statistics); + } + gradeStatistics = statistics; + return gradeStatistics; + } + + private Map convertMemberMapToUserIdMap(Map origMap){ + Map returnMap = new HashMap(); + for (Iterator i = origMap.entrySet().iterator(); i.hasNext();) { + Entry entry = (Entry) i.next(); + MembershipItem item = (MembershipItem) entry.getValue(); + if (null != item.getUser()) { + returnMap.put(item.getUser().getId(), item); + } + } + return returnMap; + } + + public List getAllTopicStatistics(){ + //clear any gradebook info: + resetGradebookVariables(); + + final Map statisticsMap = new HashMap(); + + List tempForums = forumManager.getForumsForMainPage(); + Set topicIdsForCounts = new HashSet(); + + DecoratedCompiledStatisticsByTopic dCompiledStatsByTopic = null; + //grab the info for forums and topics in the site + for (DiscussionForum forum: tempForums) { + for (Iterator itor = forum.getTopicsSet().iterator(); itor.hasNext(); ) { + DiscussionTopic currTopic = (DiscussionTopic)itor.next(); + + dCompiledStatsByTopic = new DecoratedCompiledStatisticsByTopic(); + dCompiledStatsByTopic.setForumDate(forum.getModified()); + dCompiledStatsByTopic.setForumId(forum.getId()); + dCompiledStatsByTopic.setTopicDate(currTopic.getModified()); + dCompiledStatsByTopic.setForumTitle(forum.getTitle()); + dCompiledStatsByTopic.setTopicTitle(currTopic.getTitle()); + dCompiledStatsByTopic.setTopicId(currTopic.getId()); + + statisticsMap.put(currTopic.getId(), dCompiledStatsByTopic); + + topicIdsForCounts.add(currTopic.getId()); + } + } + //get counts + List topicMessageCounts = forumManager.getMessageCountsForMainPage(topicIdsForCounts); + for (Object[] counts: topicMessageCounts) { + dCompiledStatsByTopic = statisticsMap.get(counts[0]); + if(dCompiledStatsByTopic != null){ + dCompiledStatsByTopic.setTotalTopicMessages((Integer) counts[1]); + } + } + + final List statistics = new ArrayList(statisticsMap.values()); + + sortStatisticsByAllTopics(statistics); + return statistics; + } + public List getUserAuthoredStatistics2(){ final List statistics = new ArrayList(); - List messages = messageManager.findAuthoredMessagesForStudent(selectedSiteUserId); + List messages; + if((selectedAllTopicsTopicId == null || "".equals(selectedAllTopicsTopicId)) + && (selectedAllTopicsForumId != null && !"".equals(selectedAllTopicsForumId))){ + messages = messageManager.findAuthoredMessagesForStudentByForumId(selectedSiteUserId, Long.parseLong(selectedAllTopicsForumId)); + }else if(selectedAllTopicsTopicId != null && !"".equals(selectedAllTopicsTopicId)){ + messages = messageManager.findAuthoredMessagesForStudentByTopicId(selectedSiteUserId, Long.parseLong(selectedAllTopicsTopicId)); + }else{ + messages = messageManager.findAuthoredMessagesForStudent(selectedSiteUserId); + } + if (messages == null) return statistics; for (Message msg: messages) { @@ -535,7 +953,7 @@ userAuthoredInfo.setForumId(Long.toString(msg.getTopic().getOpenForum().getId())); userAuthoredInfo.setMsgDeleted(msg.getDeleted()); userAuthoredInfo.setDecoAttachmentsList(decoAttachList); - + userAuthoredInfo.setMessage(msg.getBody()); messageManager.markMessageReadForUser(msg.getTopic().getId(), msg.getId(), true, getCurrentUserId()); statistics.add(userAuthoredInfo); @@ -597,7 +1015,16 @@ public List getUserReadStatistics(){ final List statistics = new ArrayList(); - List messages = messageManager.findReadMessagesForStudent(selectedSiteUserId); + List messages; + + if((selectedAllTopicsTopicId == null || "".equals(selectedAllTopicsTopicId)) + && (selectedAllTopicsForumId != null && !"".equals(selectedAllTopicsForumId))){ + messages = messageManager.findReadMessagesForStudentByForumId(selectedSiteUserId, Long.parseLong(selectedAllTopicsForumId)); + }else if(selectedAllTopicsTopicId != null && !"".equals(selectedAllTopicsTopicId)){ + messages = messageManager.findReadMessagesForStudentByTopicId(selectedSiteUserId, Long.parseLong(selectedAllTopicsTopicId)); + }else{ + messages = messageManager.findReadMessagesForStudent(selectedSiteUserId); + } if (messages == null) return statistics; for (Message msg: messages) { @@ -679,7 +1106,13 @@ return statistics; } + private List sortStatisticsByAllTopics(List statistics){ + Comparator comparator = determineComparatorByAllTopics(); + Collections.sort(statistics, comparator); + return statistics; + } + public void toggleSort(String sortByType) { if (sortBy.equals(sortByType)) { if (ascending) { @@ -721,7 +1154,7 @@ public void toggleSortByUser3(String sortByType) { if (sortByUser3.equals(sortByType)) { - if (ascendingForUser3) { + if (ascendingForAllTopics) { ascendingForUser3 = false; } else { ascendingForUser3 = true; @@ -732,6 +1165,16 @@ } } + public void toggleSortByAllTopics(String sortByType){ + if(sortByAllTopics.equals(sortByType)){ + ascendingForAllTopics = !ascendingForAllTopics; + }else{ + sortByAllTopics = sortByType; + ascendingForAllTopics = true; + } + } + + public String toggleNameSort() { toggleSort(NAME_SORT); return LIST_PAGE; @@ -757,7 +1200,12 @@ return LIST_PAGE; } + public String toggleGradeSort() { + toggleSort(GRADE_SORT); + return LIST_PAGE; + } + public String toggleForumTitleSort() { toggleSortByUser(FORUM_TITLE_SORT); return FORUM_STATISTICS_USER; @@ -868,6 +1316,82 @@ return false; } + public String toggleAllTopicsForumTitleSort(){ + toggleSortByAllTopics(ALL_TOPICS_FORUM_TITLE_SORT); + return FORUM_STATISTICS_BY_ALL_TOPICS; + } + + public boolean isAllTopicsForumTitleSort(){ + return ALL_TOPICS_FORUM_TITLE_SORT.equals(sortByAllTopics); + } + + public String toggleAllTopicsForumDateSort(){ + toggleSortByAllTopics(ALL_TOPICS_FORUM_DATE_SORT); + return FORUM_STATISTICS_BY_ALL_TOPICS; + } + + public boolean isAllTopicsForumDateSort(){ + return ALL_TOPICS_FORUM_DATE_SORT.equals(sortByAllTopics); + } + + public String toggleAllTopicsTopicDateSort(){ + toggleSortByAllTopics(ALL_TOPICS_TOPIC_DATE_SORT); + return FORUM_STATISTICS_BY_ALL_TOPICS; + } + + public boolean isAllTopicsTopicDateSort(){ + return ALL_TOPICS_TOPIC_DATE_SORT.equals(sortByAllTopics); + } + + public String toggleAllTopicsTopicTitleSort(){ + toggleSortByAllTopics(ALL_TOPICS_TOPIC_TITLE_SORT); + return FORUM_STATISTICS_BY_ALL_TOPICS; + } + + public boolean isAllTopicsTopicTitleSort(){ + return ALL_TOPICS_TOPIC_TITLE_SORT.equals(sortByAllTopics); + } + + public String toggleAllTopicsTopicTotalMessagesSort(){ + toggleSortByAllTopics(ALL_TOPICS_TOPIC_TOTAL_MESSAGES_SORT); + return FORUM_STATISTICS_BY_ALL_TOPICS; + } + + public boolean isAllTopicsTopicTotalMessagesSort(){ + return ALL_TOPICS_TOPIC_TOTAL_MESSAGES_SORT.equals(sortByAllTopics); + } + + public String toggleTopicNameSort() { + toggleSort(NAME_SORT); + return FORUM_STATISTICS_BY_TOPIC; + } + + public String toggleTopicAuthoredSort() { + toggleSort(AUTHORED_SORT); + return FORUM_STATISTICS_BY_TOPIC; + } + + public String toggleTopicReadSort() { + toggleSort(READ_SORT); + return FORUM_STATISTICS_BY_TOPIC; + } + + public String toggleTopicUnreadSort() { + toggleSort(UNREAD_SORT); + return FORUM_STATISTICS_BY_TOPIC; + } + + public String toggleTopicPercentReadSort() { + toggleSort(PERCENT_READ_SORT); + return FORUM_STATISTICS_BY_TOPIC; + } + + public String toggleTopicGradeSort() { + toggleSort(GRADE_SORT); + return FORUM_STATISTICS_BY_TOPIC; + } + + public boolean isNameSort() { if (sortBy.equals(NAME_SORT)) return true; @@ -898,6 +1422,12 @@ return false; } + public boolean isGradeSort() { + if (sortBy.equals(GRADE_SORT)) + return true; + return false; + } + public boolean isAscending() { return ascending; } @@ -914,6 +1444,10 @@ return ascendingForUser3; } + public boolean isAscendingForAllTopics(){ + return ascendingForAllTopics; + } + private Comparator determineComparator(){ if(ascending){ if (sortBy.equals(NAME_SORT)){ @@ -926,6 +1460,8 @@ return unreadComparatorAsc; }else if (sortBy.equals(PERCENT_READ_SORT)){ return percentReadComparatorAsc; + }else if(sortBy.equals(GRADE_SORT)){ + return GradeComparatorAsc; } }else{ if (sortBy.equals(NAME_SORT)){ @@ -938,6 +1474,8 @@ return unreadComparatorDesc; }else if (sortBy.equals(PERCENT_READ_SORT)){ return percentReadComparatorDesc; + }else if(sortBy.equals(GRADE_SORT)){ + return GradeComparatorDesc; } } //default return NameComparatorAsc @@ -1013,6 +1551,36 @@ //default return NameComparatorAsc return forumDateComparatorDesc; } + + private Comparator determineComparatorByAllTopics(){ + if(ascendingForAllTopics){ + if (sortByAllTopics.equals(ALL_TOPICS_FORUM_DATE_SORT)){ + return AllTopicsForumDateComparatorAsc; + }else if (sortByAllTopics.equals(ALL_TOPICS_FORUM_TITLE_SORT)){ + return AllTopicsForumTitleComparatorAsc; + }else if (sortByAllTopics.equals(ALL_TOPICS_TOPIC_TITLE_SORT)){ + return AllTopicsTopicTitleComparatorAsc; + }else if (sortByAllTopics.equals(ALL_TOPICS_TOPIC_TOTAL_MESSAGES_SORT)){ + return AllTopicsTopicTotalMessagesComparatorAsc; + }else if(sortByAllTopics.equals(ALL_TOPICS_TOPIC_DATE_SORT)){ + return AllTopicsTopicDateComparatorAsc; + } + }else{ + if (sortByAllTopics.equals(ALL_TOPICS_FORUM_DATE_SORT)){ + return AllTopicsForumDateComparatorDesc; + }else if (sortByAllTopics.equals(ALL_TOPICS_FORUM_TITLE_SORT)){ + return AllTopicsForumTitleComparatorDesc; + }else if (sortByAllTopics.equals(ALL_TOPICS_TOPIC_TITLE_SORT)){ + return AllTopicsTopicTitleComparatorDesc; + }else if (sortByAllTopics.equals(ALL_TOPICS_TOPIC_TOTAL_MESSAGES_SORT)){ + return AllTopicsTopicTotalMessagesComparatorDesc; + }else if(sortByAllTopics.equals(ALL_TOPICS_TOPIC_DATE_SORT)){ + return AllTopicsTopicDateComparatorDesc; + } + } + //default return NameComparatorAsc + return AllTopicsForumTitleComparatorDesc; + } static { @@ -1189,6 +1757,160 @@ return subject2.compareTo(subject1); } }; + + AllTopicsForumDateComparatorDesc = new Comparator(){ + public int compare(Object item, Object anotherItem){ + Date date1 = ((DecoratedCompiledStatisticsByTopic) item).getForumDate(); + Date date2 = ((DecoratedCompiledStatisticsByTopic) anotherItem).getForumDate(); + return date2.compareTo(date1); + } + }; + + AllTopicsForumDateComparatorAsc = new Comparator(){ + public int compare(Object item, Object anotherItem){ + Date date1 = ((DecoratedCompiledStatisticsByTopic) item).getForumDate(); + Date date2 = ((DecoratedCompiledStatisticsByTopic) anotherItem).getForumDate(); + return date1.compareTo(date2); + } + }; + + AllTopicsTopicDateComparatorDesc = new Comparator(){ + public int compare(Object item, Object anotherItem){ + Date date1 = ((DecoratedCompiledStatisticsByTopic) item).getTopicDate(); + Date date2 = ((DecoratedCompiledStatisticsByTopic) anotherItem).getTopicDate(); + return date2.compareTo(date1); + } + }; + + AllTopicsTopicDateComparatorAsc = new Comparator(){ + public int compare(Object item, Object anotherItem){ + Date date1 = ((DecoratedCompiledStatisticsByTopic) item).getTopicDate(); + Date date2 = ((DecoratedCompiledStatisticsByTopic) anotherItem).getTopicDate(); + return date1.compareTo(date2); + } + }; + + AllTopicsTopicTitleComparatorAsc = new Comparator(){ + public int compare(Object item, Object anotherItem){ + String title1 = ((DecoratedCompiledStatisticsByTopic) item).getTopicTitle().toUpperCase(); + String title2 = ((DecoratedCompiledStatisticsByTopic) anotherItem).getTopicTitle().toUpperCase(); + return title1.compareTo(title2); + } + }; + + AllTopicsTopicTitleComparatorDesc = new Comparator(){ + public int compare(Object item, Object anotherItem){ + String title1 = ((DecoratedCompiledStatisticsByTopic) item).getTopicTitle().toUpperCase(); + String title2 = ((DecoratedCompiledStatisticsByTopic) anotherItem).getTopicTitle().toUpperCase(); + return title2.compareTo(title1); + } + }; + + AllTopicsForumTitleComparatorAsc = new Comparator(){ + public int compare(Object item, Object anotherItem){ + String title1 = ((DecoratedCompiledStatisticsByTopic) item).getForumTitle().toUpperCase(); + String title2 = ((DecoratedCompiledStatisticsByTopic) anotherItem).getForumTitle().toUpperCase(); + return title1.compareTo(title2); + } + }; + + AllTopicsForumTitleComparatorDesc = new Comparator(){ + public int compare(Object item, Object anotherItem){ + String title1 = ((DecoratedCompiledStatisticsByTopic) item).getForumTitle().toUpperCase(); + String title2 = ((DecoratedCompiledStatisticsByTopic) anotherItem).getForumTitle().toUpperCase(); + return title2.compareTo(title1); + } + }; + + AllTopicsTopicTotalMessagesComparatorAsc = new Comparator(){ + public int compare(Object item, Object anotherItem){ + int read1 = ((DecoratedCompiledStatisticsByTopic) item).getTotalTopicMessages(); + int read2 = ((DecoratedCompiledStatisticsByTopic) anotherItem).getTotalTopicMessages(); + return read1 - read2; + } + }; + + AllTopicsTopicTotalMessagesComparatorDesc = new Comparator(){ + public int compare(Object item, Object anotherItem){ + int read1 = ((DecoratedCompiledStatisticsByTopic) item).getTotalTopicMessages(); + int read2 = ((DecoratedCompiledStatisticsByTopic) anotherItem).getTotalTopicMessages(); + return read2 - read1; + } + }; + + GradeComparatorAsc = new Comparator(){ + public int compare(Object item, Object anotherItem){ + DecoratedCompiledMessageStatistics stat = ((DecoratedCompiledMessageStatistics) item); + DecoratedCompiledMessageStatistics stat2 = ((DecoratedCompiledMessageStatistics) anotherItem); + + if(stat.getGradebookAssignment() == null || !stat.getGradebookAssignment().isAllowedToGrade()) + return -1; + + if(stat2.getGradebookAssignment() == null || !stat2.getGradebookAssignment().isAllowedToGrade()) + return 1; + + if(stat.getGradebookAssignment().getScore() == null || "".equals(stat.getGradebookAssignment().getScore())) + return -1; + + if(stat2.getGradebookAssignment().getScore() == null || "".equals(stat.getGradebookAssignment().getScore())) + return 1; + + if(!isNumber(stat.getGradebookAssignment().getScore())) + return -1; + + if(!isNumber(stat2.getGradebookAssignment().getScore())) + return 1; + + try{ + double val = Double.valueOf(stat.getGradebookAssignment().getScore()).doubleValue() - Double.valueOf(stat2.getGradebookAssignment().getScore()).doubleValue(); + if(val > 0){ + return 1; + }else{ + return -1; + } + }catch(NumberFormatException e){ + } + + return 0; + } + }; + + GradeComparatorDesc = new Comparator(){ + public int compare(Object item, Object anotherItem){ + DecoratedCompiledMessageStatistics stat = ((DecoratedCompiledMessageStatistics) item); + DecoratedCompiledMessageStatistics stat2 = ((DecoratedCompiledMessageStatistics) anotherItem); + + if(stat.getGradebookAssignment() == null || !stat.getGradebookAssignment().isAllowedToGrade()) + return 1; + + if(stat2.getGradebookAssignment() == null || !stat2.getGradebookAssignment().isAllowedToGrade()) + return -1; + + if(stat.getGradebookAssignment().getScore() == null || "".equals(stat.getGradebookAssignment().getScore())) + return 1; + + if(stat2.getGradebookAssignment().getScore() == null || "".equals(stat.getGradebookAssignment().getScore())) + return -1; + + if(!isNumber(stat.getGradebookAssignment().getScore())) + return 1; + + if(!isNumber(stat2.getGradebookAssignment().getScore())) + return -1; + + try{ + double val = Double.valueOf(stat.getGradebookAssignment().getScore()).doubleValue() - Double.valueOf(stat2.getGradebookAssignment().getScore()).doubleValue(); + if(val < 0){ + return 1; + }else{ + return -1; + } + }catch(NumberFormatException e){ + } + + return 0; + } + }; } /** @@ -1203,6 +1925,11 @@ LOG.debug("processActionStatisticsUser"); selectedSiteUserId = getExternalParameterByKey(SITE_USER_ID); + + return processActionStatisticsUserHelper(); + } + + public String processActionStatisticsUserHelper(){ selectedSiteUser = getUserName(selectedSiteUserId); isLastParticipant = false; @@ -1346,13 +2073,15 @@ public Map getUserIdName() { Map idNameMap = new LinkedHashMap(); - List allUserInfo = getAllUserStatistics(); - Iterator allUserInfoIter = allUserInfo.iterator(); + + Map courseMemberMap = membershipManager.getAllCourseMembers(true,false,false); + List members = membershipManager.convertMemberMapToList(courseMemberMap); - while(allUserInfoIter.hasNext() ) { - DecoratedCompiledMessageStatistics userInfo = (DecoratedCompiledMessageStatistics) allUserInfoIter.next(); - - idNameMap.put(userInfo.getSiteUserId(), userInfo.getSiteUser()); + for (Iterator i = members.iterator(); i.hasNext();) { + MembershipItem item = (MembershipItem) i.next(); + if (null != item.getUser()) { + idNameMap.put(item.getUser().getId(), item.getName()); + } } return idNameMap; } @@ -1425,4 +2154,536 @@ public void setLastParticipant(boolean isLastParticipant) { this.isLastParticipant = isLastParticipant; } + + public String processActionStatisticsByAllTopics(){ + return FORUM_STATISTICS_BY_ALL_TOPICS; + } + + public String processActionStatisticsByTopic() + { + LOG.debug("processActionStatisticsByTopic"); + + //to save some speed, only update if the values have changed + boolean newTopic = !getExternalParameterByKey(TOPIC_ID).equals(selectedAllTopicsTopicId); + boolean newForum = !getExternalParameterByKey(FORUM_ID).equals(selectedAllTopicsForumId); + + selectedAllTopicsTopicId = getExternalParameterByKey(TOPIC_ID); + selectedAllTopicsForumId = getExternalParameterByKey(FORUM_ID); + if(newForum){ + if(selectedAllTopicsForumId != null && !"".equals(selectedAllTopicsForumId)){ + try{ + DiscussionForum df = forumManager.getForumById(Long.parseLong(selectedAllTopicsForumId)); + selectedAllTopicsForumTitle = df.getTitle(); + }catch (Exception e) { + LOG.warn("MessageForumStatisticsBean.processActionStatisticsByTopic: Wasn't able to find discussion forum for id: " + selectedAllTopicsForumId); + } + } + } + if(newTopic){ + if(selectedAllTopicsTopicId != null && !"".equals(selectedAllTopicsTopicId)){ + try{ + DiscussionTopic dt = forumManager.getTopicById(Long.parseLong(selectedAllTopicsTopicId)); + selectedAllTopicsTopicTitle = dt.getTitle(); + }catch (Exception e) { + LOG.warn("MessageForumStatisticsBean.processActionStatisticsByTopic: Wasn't able to find discussion topic for id: " + selectedAllTopicsForumId); + } + } + } + + return FORUM_STATISTICS_BY_TOPIC; + } + + public String getSelectedAllTopicsTopicTitle() { + return selectedAllTopicsTopicTitle; + } + + public void setSelectedAllTopicsTopicTitle(String selectedAllTopicsTopicTitle) { + this.selectedAllTopicsTopicTitle = selectedAllTopicsTopicTitle; + } + + public String getSelectedAllTopicsForumTitle() { + return selectedAllTopicsForumTitle; + } + + public void setSelectedAllTopicsForumTitle(String selectedAllTopicsForumTitle) { + this.selectedAllTopicsForumTitle = selectedAllTopicsForumTitle; + } + + public String getSelectedAllTopicsForumId() { + return selectedAllTopicsForumId; + } + + public void setSelectedAllTopicsForumId(String selectedAllTopicsForumId) { + this.selectedAllTopicsForumId = selectedAllTopicsForumId; + } + + public String getSelectedAllTopicsTopicId() { + return selectedAllTopicsTopicId; + } + + public void setSelectedAllTopicsTopicId(String selectedAllTopicsTopicId) { + this.selectedAllTopicsTopicId = selectedAllTopicsTopicId; + } + + public void setUpGradebookAssignments(){ + try { + assignments = new ArrayList(); + assignments.add(new SelectItem(DEFAULT_GB_ITEM, getResourceBundleString(SELECT_ASSIGN))); + + //Code to get the gradebook service from ComponentManager + + GradebookService gradebookService = getGradebookService(); + + if(getGradebookExist()) { + List gradeAssignmentsBeforeFilter = gradebookService.getAssignments(ToolManager.getCurrentPlacement().getContext()); + for(int i=0; i getAssignments() + { + if(assignments == null){ + setUpGradebookAssignments(); + } + return assignments; + } + + public void setAssignments(List assignments) + { + this.assignments = assignments; + } + + public void setDefaultSelectedAssign(){ + if(!gradebookItemChosen){ + if(selectedAllTopicsTopicId != null && !"".equals(selectedAllTopicsTopicId)){ + String defaultAssignName = forumManager.getTopicById(Long.parseLong(selectedAllTopicsTopicId)).getDefaultAssignName(); + setDefaultSelectedAssign(defaultAssignName); + }else{ + String defaultAssignName = forumManager.getForumById(Long.parseLong(selectedAllTopicsForumId)).getDefaultAssignName(); + setDefaultSelectedAssign(defaultAssignName); + } + } + gradebookItemChosen = false; + } + + public String getSelectedAssign() + { + return selectedAssign; + } + + public void setSelectedAssign(String selectedAssign) + { + this.selectedAssign = selectedAssign; + } + + private void resetGradebookVariables(){ + gradebookExistChecked = false; + gradebookExist = false; + assignments = null; + selectedAssign = DEFAULT_GB_ITEM; + selectedGroup = DEFAULT_GB_ITEM; + gradebookItemChosen = false; + selAssignName = ""; + } + + private void setDefaultSelectedAssign(String assign){ + selectedAssign = DEFAULT_GB_ITEM; + selAssignName = ""; + if(assign != null){ + for (SelectItem item : getAssignments()) { + if(assign.equals(item.getLabel())){ + selectedAssign = item.getValue().toString(); + selAssignName = assign; + } + } + } + + } + + private Map getGradebookAssignment(){ + Map returnVal = new HashMap(); + + if(!DEFAULT_GB_ITEM.equalsIgnoreCase(selectedAssign)) { + String gradebookUid = ToolManager.getCurrentPlacement().getContext(); + selAssignName = ((SelectItem)assignments.get((Integer.valueOf(selectedAssign)).intValue())).getLabel(); + + + GradebookService gradebookService = getGradebookService(); + if (gradebookService == null) return returnVal; + + Assignment assignment = gradebookService.getAssignment(gradebookUid, selAssignName); + if(assignment != null){ + gbItemPointsPossible = assignment.getPoints().toString(); + + //grab all grades for the id's that the user is able to grade: + Map studentIdFunctionMap = gradebookService.getViewableStudentsForItemForCurrentUser(gradebookUid, assignment.getId()); + List grades = gradebookService.getGradesForStudentsForItem(gradebookUid, assignment.getId(), new ArrayList(studentIdFunctionMap.keySet())); + //add grade values to return map + for(GradeDefinition gradeDef : grades){ + String studentUuid = gradeDef.getStudentUid(); + DecoratedGradebookAssignment gradeAssignment = new DecoratedGradebookAssignment(); + gradeAssignment.setAllowedToGrade(true); + gradeAssignment.setScore(gradeDef.getGrade()); + gradeAssignment.setComment(gradeDef.getGradeComment()); + gradeAssignment.setName(selAssignName); + gradeAssignment.setPointsPossible(gbItemPointsPossible); + gradeAssignment.setUserUuid(studentUuid); + returnVal.put(studentUuid, gradeAssignment); + } + //now populate empty data for users who can be graded but don't have a grade yet: + for (Iterator iterator = studentIdFunctionMap.entrySet().iterator(); iterator.hasNext();) { + Entry entry = (Entry) iterator.next(); + if(!returnVal.containsKey(entry.getKey().toString())){ + //this user needs to be added a gradeable: + DecoratedGradebookAssignment gradeAssignment = new DecoratedGradebookAssignment(); + gradeAssignment.setAllowedToGrade(true); + gradeAssignment.setName(selAssignName); + gradeAssignment.setPointsPossible(gbItemPointsPossible); + gradeAssignment.setUserUuid(entry.getKey().toString()); + returnVal.put(entry.getKey().toString(), gradeAssignment); + } + } + } + } + + return returnVal; + } + + public String getSelAssignName() { + return selAssignName; + } + + public void setSelAssignName(String selAssignName) { + this.selAssignName = selAssignName; + } + + public String getGbItemPointsPossible() { + return gbItemPointsPossible; + } + + public void setGbItemPointsPossible(String gbItemPointsPossible) { + this.gbItemPointsPossible = gbItemPointsPossible; + } + + public String proccessActionSubmitGrades(){ + GradebookService gradebookService = getGradebookService(); + if (gradebookService == null) { + return null; + } + + if(gradeStatistics != null){ + + if(selectedAssign == null || selectedAssign.trim().length()==0 || DEFAULT_GB_ITEM.equalsIgnoreCase(selectedAssign)) + { + setErrorMessage(getResourceBundleString(NO_ASSGN)); + return null; + } + + if(!validateGradeInput()) + return null; + + try + { + String selectedAssignName = ((SelectItem)assignments.get((Integer.valueOf(selectedAssign)).intValue())).getLabel(); + String gradebookUuid = ToolManager.getCurrentPlacement().getContext(); + + for (DecoratedCompiledMessageStatistics gradeStatistic : gradeStatistics) { + if(gradeStatistic.getGradebookAssignment() != null && gradeStatistic.getGradebookAssignment().isAllowedToGrade()){ + //ignore empty grades + if(gradeStatistic.getGradebookAssignment().getScore() != null && + !"".equals(gradeStatistic.getGradebookAssignment().getScore())){ + + gradebookService.setAssignmentScore(gradebookUuid, + selectedAssignName, gradeStatistic.getGradebookAssignment().getUserUuid(), Double.valueOf(gradeStatistic.getGradebookAssignment().getScore()), ""); + if (gradeStatistic.getGradebookAssignment().getComment() != null + && gradeStatistic.getGradebookAssignment().getComment().trim().length() > 0) + { + gradebookService.setAssignmentScoreComment(gradebookUuid, + selectedAssignName, gradeStatistic.getGradebookAssignment().getUserUuid(), gradeStatistic.getGradebookAssignment().getComment()); + } + } + } + } + + setSuccessMessage(getResourceBundleString(GRADE_SUCCESSFUL)); + } + catch(SecurityException se) { + LOG.error("MessageForumStatisticsBean Security Exception - proccessActionSubmitGrades:" + se); + setErrorMessage(getResourceBundleString("cdfm_no_gb_perm")); + } + catch(Exception e) + { + LOG.error("MessageForumStatisticsBean - proccessActionSubmitGrades:" + e); + e.printStackTrace(); + } + + String eventRef = ""; + if(selectedAllTopicsTopicId != null && !"".equals(selectedAllTopicsTopicId)){ + eventRef = getEventReference(selectedAllTopicsTopicId); + }else{ + eventRef = getEventReference(selectedAllTopicsForumId); + } + + EventTrackingService.post(EventTrackingService.newEvent(DiscussionForumService.EVENT_FORUMS_GRADE, eventRef, true)); + + } + + //to stop it from going back to the default gradebook item, set gradebookItemChosen flag: + gradebookItemChosen = true; + return null; + } + + private String getEventReference(String ref) + { + String eventMessagePrefix = ""; + final String toolId = ToolManager.getCurrentTool().getId(); + + if (toolId.equals(DiscussionForumService.MESSAGE_CENTER_ID)) + eventMessagePrefix = "/messagesAndForums"; + else if (toolId.equals(DiscussionForumService.MESSAGES_TOOL_ID)) + eventMessagePrefix = "/messages"; + else + eventMessagePrefix = "/forums"; + + return eventMessagePrefix + getContextSiteId() + "/" + ref + "/" + SessionManager.getCurrentSessionUserId(); + } + + private boolean validateGradeInput(){ + boolean validated = true; + + for (DecoratedCompiledMessageStatistics gradeStatistic : gradeStatistics) { + if(gradeStatistic.getGradebookAssignment() != null && gradeStatistic.getGradebookAssignment().isAllowedToGrade()){ + //ignore empty grades + if(gradeStatistic.getGradebookAssignment().getScore() != null && + !"".equals(gradeStatistic.getGradebookAssignment().getScore())){ + if(!isNumber(gradeStatistic.getGradebookAssignment().getScore())) + { + setErrorMessage(getResourceBundleString(GRADE_GREATER_ZERO)); + return false; + } + else if(!isFewerDigit(gradeStatistic.getGradebookAssignment().getScore())) + { + setErrorMessage(getResourceBundleString(GRADE_DECIMAL_WARN)); + return false; + } + } + } + } + return validated; + } + + private void setErrorMessage(String errorMsg) + { + LOG.debug("setErrorMessage(String " + errorMsg + ")"); + FacesContext.getCurrentInstance().addMessage(null, + new FacesMessage(FacesMessage.SEVERITY_ERROR, getResourceBundleString(ALERT) + errorMsg, null)); + } + + private void setSuccessMessage(String successMsg) + { + LOG.debug("setSuccessMessage(String " + successMsg + ")"); + FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, successMsg, null)); + } + + private String getContextSiteId() + { + LOG.debug("getContextSiteId()"); + return ("/site/" + ToolManager.getCurrentPlacement().getContext()); + } + + public static boolean isNumber(String validateString) + { + try + { + double d = Double.valueOf(validateString).doubleValue(); + if(d >= 0) + return true; + else + return false; + } + catch (NumberFormatException e) + { + //e.printStackTrace(); + return false; + } + } + + public boolean isFewerDigit(String validateString) + { + String stringValue = Double.valueOf(validateString).toString(); + if(stringValue.lastIndexOf(".") >= 0) + { + String subString = stringValue.substring(stringValue.lastIndexOf(".")); + if(subString != null && subString.length() > 3) + return false; + } + + return true; + } + + public List getGroups() { + if(groups == null){ + groups = new ArrayList(); + try{ + Site currentSite = SiteService.getSite(ToolManager.getCurrentPlacement().getContext()); + if(currentSite.hasGroups()){ + groups.add(new SelectItem(DEFAULT_GB_ITEM, getResourceBundleString(DEFAULT_ALL_GROUPS))); + Collection siteGroups = currentSite.getGroups(); + for (Iterator groupIterator = siteGroups.iterator(); groupIterator.hasNext();){ + Group currentGroup = (Group) groupIterator.next(); + groups.add(new SelectItem(currentGroup.getId(), currentGroup.getTitle())); + } + } + }catch (IdUnusedException e){ + LOG.error(e); + } + } + return groups; + } + + public void setGroups(List groups) { + this.groups = groups; + } + + public String getSelectedGroup() { + return selectedGroup; + } + + public void setSelectedGroup(String selectedGroup) { + this.selectedGroup = selectedGroup; + } + + private class DecoratedUser{ + private String id; + private String name; + + public DecoratedUser(String id, String name){ + this.id = id; + this.name = name; + } + + public String getId() { + return id; + } + public void setId(String id) { + this.id = id; + } + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + + } } Index: messageforums-app/src/webapp/WEB-INF/faces-config.xml =================================================================== --- messageforums-app/src/webapp/WEB-INF/faces-config.xml (revision 89226) +++ messageforums-app/src/webapp/WEB-INF/faces-config.xml (working copy) @@ -314,6 +314,16 @@ + dfStatisticsListByAllTopics + /jsp/discussionForum/statistics/dfStatisticsListByAllTopics.jsp + + + + dfStatisticsListByTopic + /jsp/discussionForum/statistics/dfStatisticsListByTopic.jsp + + + dfStatisticsUser /jsp/discussionForum/statistics/dfStatisticsUser.jsp Index: messageforums-app/src/webapp/css/dialog.css =================================================================== --- messageforums-app/src/webapp/css/dialog.css (revision 0) +++ messageforums-app/src/webapp/css/dialog.css (revision 0) @@ -0,0 +1,61 @@ + +/* + * Styles for our confirmation dialogs using JQuery UI Dialog + */ + + +.ui-dialog { + border: solid 1px #525252; + background-color: white; + padding: 10px; +} + +.ui-dialog-container { + +} + +.ui-dialog-content { + +} + + +.ui-dialog-titlebar-close { + display: none; +} + +.ui-dialog-titlebar { + display: none; +} + +.ui-dialog-buttonpane { + display: none; +} + +.ui-dialog-msg-list { + margin:0; + padding:0; + list-style-type:none; + list-style-position: outside; + list-style: none; +} + +/* The default settings on jQuery UI Dialog 1.7 cause the overlay to appear + * under the regular body content and cause major resizing issues when coupled + * with our Sakai-RSF DOM Page Resizer. Copying these style settings from the + * older version. + */ +.ui-widget-overlay { + border-width: 0pt; + margin: 0pt; + padding: 0pt; + position: absolute; + top: 0pt; + left: 0pt; +/* width: 1390px; + height: 899px; */ + opacity: 0.50; + filter:alpha(opacity=50); + -moz-opacity: 0.50; + background-color: rgb(238, 238, 238); + /* z-index: 1001;*/ +} Index: messageforums-app/src/webapp/js/forum.js =================================================================== --- messageforums-app/src/webapp/js/forum.js (revision 89226) +++ messageforums-app/src/webapp/js/forum.js (working copy) @@ -452,17 +452,22 @@ } function fckeditor_word_count(editorInstance) { - - var matches = editorInstance.GetData().replace(/<[^<|>]+?>| /gi,' ').match(/\b/g); + document.getElementById('counttotal').innerHTML = "(" + getWordCount(editorInstance.GetData()) + ")"; +} + + function fckeditor_word_count_fromMessage(msgStr, countSpan){ + document.getElementById(countSpan).innerHTML = "(" + getWordCount(msgStr) + ")"; + } + + function getWordCount(msgStr) { + + var matches = msgStr.replace(/<[^<|>]+?>| /gi,' ').match(/\b/g); var count = 0; if(matches) { count = matches.length/2; } - if(document.getElementById('counttotal')){ - document.getElementById('counttotal').innerHTML = "(" + count + ")"; - } - + return count; } function InsertHTML(header) { Index: messageforums-app/src/webapp/js/dialog.js =================================================================== --- messageforums-app/src/webapp/js/dialog.js (revision 0) +++ messageforums-app/src/webapp/js/dialog.js (revision 0) @@ -0,0 +1,103 @@ +var dialogutil = dialogutil || {}; + +(function(jQuery, dialogutil) { + + dialogutil.openDialog = function(divId, frameId, yPos) { + var vHeight = 300; + + + + $("#" + divId).dialog({ + resizable: false, + autoOpen:false, + draggable:false, + modal: true, + width: 600, + height: vHeight, + close: function(event, ui) { + dialogutil.closeDialog(divId, frameId); + }, + open: function() { + $("#" + divId).delay(500, function(){dialogutil.turnOnPortalOverlay();}); + dialogutil.updateMainFrameHeight(window.name, frameId, vHeight); + + } + }); + + $("#" + divId).dialog( "option", "position", ['center', yPos - vHeight/2]); + $("#" + divId).dialog("open"); + }; + + /** + * Turns on the 2.x portals background overlay + */ + dialogutil.turnOnPortalOverlay = function() { + $("body", parent.document).append('
'); + $("#" + iframeId, parent.document).parent().css("z-index", "9001").css("position", "relative").css("background", "#fff"); + }; + + /** + * Turns off the 2.x portal background overlay + */ + dialogutil.turnOffPortalOverlay = function() { + $("#portalMask", parent.document).trigger("unload").unbind().remove(); + $("#" + iframeId, parent.document).parent().css("z-index", "0"); + }; + + dialogutil.closeDialog = function(divId, frameId) { + $("#" + frameId).removeAttr("src"); + $("#" + divId).dialog('destroy'); + $("#" + divId).hide(); + dialogutil.turnOffPortalOverlay(); + }; + + dialogutil.showDiv = function(divId) { + $("#" + divId).show(); + $("#" + divId).delay(5000, function(){$("#" + divId).fadeOut(1000)}); + }; + + $.fn.delay = function(time, func) { + return this.each(function(){ + setTimeout(func,time); + }); + }; + + dialogutil.updateMainFrameHeight = function (theParentFrame, frameId, vHeight) { + var frame = parent.document.getElementById(theParentFrame); + if (frame) + { + var objToResize = (frame.style) ? frame.style : frame; + + // reset the scroll + // parent.window.scrollTo(0,0); + + // Mozilla way to detect height + var localHeight = document.body.offsetHeight; + + // Internet Explorer way to detect height + if (document.body.scrollHeight) + { + localHeight = document.body.scrollHeight; + } + + var jqFrame = $("#" + frameId); + + var innerIframe = document.getElementById(jqFrame[0].id); + var innerObjToResize = (innerIframe.style) ? innerIframe.style : innerIframe; + + innerObjToResize.height = vHeight + "px"; + + localHeight += vHeight; + if (frame) + { + objToResize.height = localHeight + "px"; + } + } + } + + dialogutil.replaceBodyOnLoad = function (newOnLoad, contextObject) { + $("body", contextObject.document).attr("onload", newOnLoad); + } + + +})(jQuery, dialogutil); Index: messageforums-app/src/webapp/jsp/discussionForum/message/dfViewSearchBarThread.jsp =================================================================== --- messageforums-app/src/webapp/jsp/discussionForum/message/dfViewSearchBarThread.jsp (revision 89226) +++ messageforums-app/src/webapp/jsp/discussionForum/message/dfViewSearchBarThread.jsp (working copy) @@ -12,3 +12,10 @@ + + + Index: messageforums-app/src/webapp/jsp/discussionForum/message/dfViewMessage.jsp =================================================================== --- messageforums-app/src/webapp/jsp/discussionForum/message/dfViewMessage.jsp (revision 89226) +++ messageforums-app/src/webapp/jsp/discussionForum/message/dfViewMessage.jsp (working copy) @@ -10,6 +10,7 @@ + @@ -120,8 +124,11 @@ hideBorder="true"/> - - + + +   + +
-
Index: messageforums-app/src/webapp/jsp/discussionForum/message/dfViewThreadBodyInclude.jsp =================================================================== --- messageforums-app/src/webapp/jsp/discussionForum/message/dfViewThreadBodyInclude.jsp (revision 89226) +++ messageforums-app/src/webapp/jsp/discussionForum/message/dfViewThreadBodyInclude.jsp (working copy) @@ -1,5 +1,29 @@ <%-- Display single message in threaded view. (included for each message). --%> <%-- designNote: what does read/unread mean in this context since I am seeing the whole message?--%> + +<% + String thisId = request.getParameter("panel"); + if (thisId == null) + { + thisId = "Main" + org.sakaiproject.tool.cover.ToolManager.getCurrentPlacement().getId(); + } + +%> + + " />
<%-- a deleted message --%> @@ -83,11 +107,17 @@ <%-- link to grade --%> - - - - - + + + + + + + + + + <%-- Revise other action --%> Index: messageforums-app/src/webapp/jsp/discussionForum/message/dfMsgGrade.jsp =================================================================== --- messageforums-app/src/webapp/jsp/discussionForum/message/dfMsgGrade.jsp (revision 89226) +++ messageforums-app/src/webapp/jsp/discussionForum/message/dfMsgGrade.jsp (working copy) @@ -1,3 +1,8 @@ +<%@ page import="java.util.*, javax.faces.context.*, javax.faces.application.*, + javax.faces.el.*, org.sakaiproject.tool.messageforums.*, + org.sakaiproject.api.app.messageforums.*, + org.sakaiproject.site.cover.SiteService, + org.sakaiproject.tool.cover.ToolManager;"%> <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> <%@ taglib uri="http://sakaiproject.org/jsf/sakai" prefix="sakai" %> @@ -6,21 +11,98 @@ + + + + <% + FacesContext context = FacesContext.getCurrentInstance(); + Application app = context.getApplication(); + ValueBinding binding = app.createValueBinding("#{ForumTool}"); + DiscussionForumTool forumTool = (DiscussionForumTool) binding.getValue(context); + + + + //Check if user called this page with a popup dialog + + String messageId = request.getParameter("messageId"); + String topicId = request.getParameter("topicId"); + String forumId = request.getParameter("forumId"); + String userId = request.getParameter("userId"); + String frameId = request.getParameter("frameId"); + String dialogDivId = request.getParameter("dialogDivId"); + String gradesSavedDiv = request.getParameter("gradesSavedDiv"); + + boolean isDialogBox = false; + if( + //messageId != null && !"".equals(messageId) && + userId != null && !"".equals(userId) && + forumId != null && !"".equals(forumId)){ + //message info was passed via parameters... + //set up this information in DiscussionForumTool + //All permission will be hanlded in "rendered" fields in this page below + + isDialogBox = true; + + + + String noProcessing = request.getParameter("noProccessing"); + if(noProcessing == null || "". equals(noProcessing)){ + //this will set all the variables that need to be set + String result = forumTool.processDfMsgGrdFromThread(messageId, topicId, forumId, userId); + } + %> + + + <% + } + %> + + + +

- +

- + +
+ @@ -39,9 +121,11 @@ -
+ +
+
+ -

@@ -89,10 +173,30 @@ - - + <% if(isDialogBox){ %> + + <% }else {%> + + <%}%> + + + <% if(isDialogBox){ %> + + + + + + + + + + + + + <%}%> Index: messageforums-app/src/webapp/jsp/discussionForum/message/dfViewThread.jsp =================================================================== --- messageforums-app/src/webapp/jsp/discussionForum/message/dfViewThread.jsp (revision 89226) +++ messageforums-app/src/webapp/jsp/discussionForum/message/dfViewThread.jsp (working copy) @@ -17,7 +17,10 @@ - + + + + @@ -48,6 +51,7 @@ }); }); + // element into which the value gets insert and retrieved from //--%> @@ -116,7 +120,13 @@ - + + +

+ + <%@include file="dfViewSearchBarThread.jsp"%> Index: messageforums-app/src/webapp/jsp/discussionForum/includes/dfAreaInclude.jsp =================================================================== --- messageforums-app/src/webapp/jsp/discussionForum/includes/dfAreaInclude.jsp (revision 89226) +++ messageforums-app/src/webapp/jsp/discussionForum/includes/dfAreaInclude.jsp (working copy) @@ -32,6 +32,13 @@ + + + + + + + @@ -130,6 +137,13 @@ + + + + + + + @@ -140,6 +154,7 @@ + <%-- delete this topic link, a string now - needs a real rendered attribute --%> <%-- Index: messageforums-app/src/webapp/jsp/discussionForum/forum/dfForumDetail.jsp =================================================================== --- messageforums-app/src/webapp/jsp/discussionForum/forum/dfForumDetail.jsp (revision 89226) +++ messageforums-app/src/webapp/jsp/discussionForum/forum/dfForumDetail.jsp (working copy) @@ -41,6 +41,12 @@ title=" #{msgs.cdfm_forum_settings}"> + + + + + + <%-- @@ -127,6 +133,13 @@ + + + + + + + + + @@ -28,8 +39,25 @@ - + + + + + + + + + + + + + + + + + + @@ -39,6 +67,14 @@ + + " style="display: none" class="messageBody"> + + + + +  "> +

Index: messageforums-app/src/webapp/jsp/discussionForum/statistics/dfStatisticsListByAllTopics.jsp =================================================================== --- messageforums-app/src/webapp/jsp/discussionForum/statistics/dfStatisticsListByAllTopics.jsp (revision 0) +++ messageforums-app/src/webapp/jsp/discussionForum/statistics/dfStatisticsListByAllTopics.jsp (revision 0) @@ -0,0 +1,90 @@ +<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> +<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> +<%@ taglib uri="http://sakaiproject.org/jsf/sakai" prefix="sakai" %> +<%@ taglib uri="http://sakaiproject.org/jsf/messageforums" prefix="mf" %> + + + + + + + + + + + +

+ + + + +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Index: messageforums-app/src/webapp/jsp/discussionForum/statistics/dfStatisticsAllAuthoredMsgForOneUser.jsp =================================================================== --- messageforums-app/src/webapp/jsp/discussionForum/statistics/dfStatisticsAllAuthoredMsgForOneUser.jsp (revision 89226) +++ messageforums-app/src/webapp/jsp/discussionForum/statistics/dfStatisticsAllAuthoredMsgForOneUser.jsp (working copy) @@ -1,3 +1,9 @@ +<%@ page import="java.util.*, javax.faces.context.*, javax.faces.application.*, + javax.faces.el.*, org.sakaiproject.tool.messageforums.*, + org.sakaiproject.api.app.messageforums.*, + org.sakaiproject.site.cover.SiteService, + org.sakaiproject.tool.messageforums.ui.MessageForumStatisticsBean, + org.sakaiproject.tool.cover.ToolManager;"%> <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> <%@ taglib uri="http://sakaiproject.org/jsf/sakai" prefix="sakai" %> @@ -5,32 +11,215 @@ + +<% + String thisId = request.getParameter("panel"); + if (thisId == null) + { + thisId = "Main" + org.sakaiproject.tool.cover.ToolManager.getCurrentPlacement().getId(); + } + + + + + FacesContext context = FacesContext.getCurrentInstance(); + Application app = context.getApplication(); + ValueBinding binding = app.createValueBinding("#{mfStatisticsBean}"); + MessageForumStatisticsBean statsBean = (MessageForumStatisticsBean) binding.getValue(context); + + + + //Check if user called this page with a popup dialog + + String selectedUserId = request.getParameter("siteUserId"); + String frameId = request.getParameter("frameId"); + String dialogDivId = request.getParameter("dialogDivId"); + boolean isDialogBox = false; + + if(selectedUserId != null && !"".equals(selectedUserId)){ + isDialogBox = true; + statsBean.selectedSiteUserId = selectedUserId; + //set up default settings: + statsBean.processActionStatisticsUserHelper(); + } +%> + + + + + - - + + + + + + + + + <% if(isDialogBox){ %> + +
+ "/> +
+ + +
+ <% }else {%> + <%}%> + + + + + +
@@ -46,9 +235,18 @@
+ -

-

+ + " style="display: none" class="messageBody"> + + + + +

+  "> +
+

@@ -58,7 +256,21 @@

- + <% if(!isDialogBox){ %> + + + + + + + + + + + + + @@ -66,6 +278,7 @@ + <%}%>

@@ -119,10 +332,19 @@ - - + <% if(isDialogBox){ %> + +
+ "/> +
+
+ <% }else {%> + + + <%}%>
+ Index: messageforums-app/src/webapp/jsp/discussionForum/statistics/dfStatisticsDisplayInThread.jsp =================================================================== --- messageforums-app/src/webapp/jsp/discussionForum/statistics/dfStatisticsDisplayInThread.jsp (revision 89226) +++ messageforums-app/src/webapp/jsp/discussionForum/statistics/dfStatisticsDisplayInThread.jsp (working copy) @@ -12,6 +12,16 @@ + + @@ -25,8 +35,25 @@ - - + + + + + + + + + + + + + + + + + + + @@ -73,6 +100,14 @@
+ + + + + +   +

Index: messageforums-app/src/webapp/jsp/discussionForum/statistics/dfStatisticsListByTopic.jsp =================================================================== --- messageforums-app/src/webapp/jsp/discussionForum/statistics/dfStatisticsListByTopic.jsp (revision 0) +++ messageforums-app/src/webapp/jsp/discussionForum/statistics/dfStatisticsListByTopic.jsp (revision 0) @@ -0,0 +1,348 @@ +<%@ page import="java.util.*, javax.faces.context.*, javax.faces.application.*, + javax.faces.el.*, org.sakaiproject.tool.messageforums.*, + org.sakaiproject.api.app.messageforums.*, + org.sakaiproject.site.cover.SiteService, + org.sakaiproject.tool.messageforums.ui.MessageForumStatisticsBean, + org.sakaiproject.tool.cover.ToolManager;"%> +<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> +<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> +<%@ taglib uri="http://sakaiproject.org/jsf/sakai" prefix="sakai" %> +<%@ taglib uri="http://sakaiproject.org/jsf/messageforums" prefix="mf" %> + + + +<% + String thisId = request.getParameter("panel"); + if (thisId == null) + { + thisId = "Main" + org.sakaiproject.tool.cover.ToolManager.getCurrentPlacement().getId(); + } + + FacesContext context = FacesContext.getCurrentInstance(); + Application app = context.getApplication(); + ValueBinding binding = app.createValueBinding("#{mfStatisticsBean}"); + MessageForumStatisticsBean statsBean = (MessageForumStatisticsBean) binding.getValue(context); + statsBean.setDefaultSelectedAssign(); + +%> + + + + + + + + + + + + +

+
+ + + + + + + + + + +

+ + + + + + + + + + + + + + +

+
+ + + + + + + + + + + + + + + +
+ + + + +
+ + + "/> + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Index: messageforums-app/src/webapp/jsp/discussionForum/statistics/dfStatisticsList.jsp =================================================================== --- messageforums-app/src/webapp/jsp/discussionForum/statistics/dfStatisticsList.jsp (revision 89226) +++ messageforums-app/src/webapp/jsp/discussionForum/statistics/dfStatisticsList.jsp (working copy) @@ -11,7 +11,7 @@ - +

+ + + + +
Index: messageforums-app/src/webapp/jsp/discussionForum/statistics/dfStatisticsUser.jsp =================================================================== --- messageforums-app/src/webapp/jsp/discussionForum/statistics/dfStatisticsUser.jsp (revision 89226) +++ messageforums-app/src/webapp/jsp/discussionForum/statistics/dfStatisticsUser.jsp (working copy) @@ -5,13 +5,122 @@ + +<% + String thisId = request.getParameter("panel"); + if (thisId == null) + { + thisId = "Main" + org.sakaiproject.tool.cover.ToolManager.getCurrentPlacement().getId(); + } + +%> + - - + + + + + + + + + + + +

@@ -20,7 +129,24 @@ - + + + + + + + + + + + + + + + + + +

@@ -45,7 +171,13 @@
- + + +

@@ -104,15 +236,40 @@ + + + + + + " style="display: none" class="messageBody"> + + + + + "> + + + - - - - - - - - + + + + + + + + + + + + + + + + + +