Search in sources :

Example 6 with MarkResourceStat

use of org.olat.core.commons.services.mark.MarkResourceStat in project openolat by klemens.

the class MessageListController method addMessageToCurrentMessagesAndVC.

private void addMessageToCurrentMessagesAndVC(UserRequest ureq, MessageLight m, MessageView messageView, Map<String, Mark> marks, Map<String, MarkResourceStat> stats, Map<String, Long> artefactStats, Set<Long> readSet) {
    // all values belonging to a message are stored in this map
    // these values can be accessed in velocity. make sure you clean up
    // everything
    // you create here in disposeCurrentMessages()!
    String keyString = m.getKey().toString();
    if (readSet == null || readSet.contains(m.getKey())) {
        messageView.setNewMessage(false);
    } else {
        // mark now as read
        markRead(m);
        messageView.setNewMessage(true);
    }
    // add some data now
    messageView.setFormattedCreationDate(formatter.formatDateAndTime(m.getCreationDate()));
    messageView.setFormattedLastModified(formatter.formatDateAndTime(m.getLastModified()));
    Identity creator = m.getCreator();
    Identity modifier = m.getModifier();
    if (modifier != null) {
        messageView.setModified(true);
        if (modifier.equals(creator) && StringHelper.containsNonWhitespace(m.getPseudonym())) {
            messageView.setModifierPseudonym(m.getPseudonym());
        } else {
            messageView.setModifierFirstName(modifier.getUser().getProperty(UserConstants.FIRSTNAME, getLocale()));
            messageView.setModifierLastName(modifier.getUser().getProperty(UserConstants.LASTNAME, getLocale()));
        }
    } else {
        messageView.setModified(false);
    }
    boolean userIsMsgCreator = false;
    // keeps the first 15 chars
    if (creator != null) {
        userIsMsgCreator = getIdentity().equals(creator);
        if (!StringHelper.containsNonWhitespace(m.getPseudonym())) {
            messageView.setCreatorFirstname(Formatter.truncate(creator.getUser().getProperty(UserConstants.FIRSTNAME, getLocale()), 18));
            messageView.setCreatorLastname(Formatter.truncate(creator.getUser().getProperty(UserConstants.LASTNAME, getLocale()), 18));
        }
    }
    // message attachments
    VFSContainer msgContainer = forumManager.getMessageContainer(forum.getKey(), m.getKey());
    messageView.setMessageContainer(msgContainer);
    List<VFSItem> attachments = new ArrayList<VFSItem>(msgContainer.getItems(new VFSItemMetaFilter()));
    messageView.setAttachments(attachments);
    // number of children and modify/delete permissions
    int numOfChildren = messageView.getNumOfChildren();
    messageView.setAuthor(userIsMsgCreator);
    boolean threadTop = m.getThreadtop() == null;
    messageView.setThreadTop(threadTop);
    boolean isThreadClosed;
    if (threadTop) {
        isThreadClosed = Status.getStatus(m.getStatusCode()).isClosed();
    } else {
        if (thread == null) {
            isThreadClosed = Status.getStatus(m.getThreadtop().getStatusCode()).isClosed();
        } else {
            isThreadClosed = Status.getStatus(thread.getStatusCode()).isClosed();
        }
    }
    messageView.setClosed(isThreadClosed);
    if (!guestOnly && !m.isGuest() && creator != null && !StringHelper.containsNonWhitespace(m.getPseudonym())) {
        // add portrait to map for later disposal and key for rendering in velocity
        DisplayPortraitController portrait = new DisplayPortraitController(ureq, getWindowControl(), creator, true, true, false, true);
        messageView.setPortrait(portrait);
        mainVC.put("portrait_".concat(keyString), portrait.getInitialComponent());
        // Add link with username that is clickable
        String creatorFullName = StringHelper.escapeHtml(UserManager.getInstance().getUserDisplayName(creator));
        Link visitingCardLink = LinkFactory.createCustomLink("vc_".concat(keyString), "vc", creatorFullName, Link.LINK_CUSTOM_CSS + Link.NONTRANSLATED, mainVC, this);
        visitingCardLink.setUserObject(creator);
        LinkPopupSettings settings = new LinkPopupSettings(800, 600, "_blank");
        visitingCardLink.setPopup(settings);
    }
    if (!isThreadClosed) {
        if ((numOfChildren == 0 && userIsMsgCreator && foCallback.mayDeleteOwnMessage()) || foCallback.mayDeleteMessageAsModerator()) {
            Link deleteLink = LinkFactory.createCustomLink("dl_".concat(keyString), "dl", "msg.delete", Link.BUTTON_SMALL, mainVC, this);
            deleteLink.setIconLeftCSS("o_icon o_icon-fw o_icon_delete_item");
            deleteLink.setUserObject(messageView);
        }
        if ((numOfChildren == 0 && userIsMsgCreator && foCallback.mayEditOwnMessage()) || foCallback.mayEditMessageAsModerator()) {
            Link editLink = LinkFactory.createCustomLink("ed_".concat(keyString), "ed", "msg.update", Link.BUTTON_SMALL, mainVC, this);
            editLink.setIconLeftCSS("o_icon o_icon-fw o_icon_edit");
            editLink.setUserObject(messageView);
        }
        if (foCallback.mayReplyMessage()) {
            Link quoteLink = LinkFactory.createCustomLink("qt_".concat(keyString), "qt", "msg.quote", Link.BUTTON_SMALL, mainVC, this);
            quoteLink.setElementCssClass("o_sel_forum_reply_quoted");
            quoteLink.setIconLeftCSS("o_icon o_icon-fw o_icon_reply_with_quote");
            quoteLink.setUserObject(messageView);
            Link replyLink = LinkFactory.createCustomLink("rp_".concat(keyString), "rp", "msg.reply", Link.BUTTON_SMALL, mainVC, this);
            replyLink.setElementCssClass("o_sel_forum_reply");
            replyLink.setIconLeftCSS("o_icon o_icon-fw o_icon_reply");
            replyLink.setUserObject(messageView);
        }
        if (foCallback.mayEditMessageAsModerator()) {
            if (!threadTop) {
                Link splitLink = LinkFactory.createCustomLink("split_".concat(keyString), "split", "msg.split", Link.LINK, mainVC, this);
                splitLink.setIconLeftCSS("o_icon o_icon-fw o_icon_split");
                splitLink.setUserObject(messageView);
                Link moveLink = LinkFactory.createCustomLink("move_".concat(keyString), "move", "msg.move", Link.LINK, mainVC, this);
                moveLink.setIconLeftCSS("o_icon o_icon-fw o_icon_move");
                moveLink.setUserObject(messageView);
            }
            Link exileLink = LinkFactory.createCustomLink("exile_".concat(keyString), "exile", "msg.exile", Link.LINK, mainVC, this);
            exileLink.setIconLeftCSS("o_icon o_icon-fw o_forum_status_thread_icon");
            exileLink.setUserObject(messageView);
        }
    }
    Mark currentMark = marks.get(keyString);
    MarkResourceStat stat = stats.get(keyString);
    if (!guestOnly) {
        String businessPath = currentMark == null ? getWindowControl().getBusinessControl().getAsString() + "[Message:" + m.getKey() + "]" : currentMark.getBusinessPath();
        Controller markCtrl = markingService.getMarkController(ureq, getWindowControl(), currentMark, stat, forumOres, keyString, businessPath);
        mainVC.put("mark_".concat(keyString), markCtrl.getInitialComponent());
    }
    if (userIsMsgCreator && !StringHelper.containsNonWhitespace(m.getPseudonym())) {
        OLATResourceable messageOres = OresHelper.createOLATResourceableInstance("Forum", m.getKey());
        String businessPath = BusinessControlFactory.getInstance().getAsString(getWindowControl().getBusinessControl()) + "[Message:" + m.getKey() + "]";
        Long artefact = artefactStats.get(businessPath);
        int numOfArtefact = artefact == null ? 0 : artefact.intValue();
        if (portfolioModule.isEnabled()) {
            String collectorId = "eportfolio_" + keyString;
            Component collectorCmp = new MediaCollectorComponent(collectorId, getWindowControl(), m, forumMediaHandler, businessPath);
            mainVC.put(collectorId, collectorCmp);
        } else {
            Controller ePFCollCtrl = EPUIFactory.createArtefactCollectWizzardController(ureq, getWindowControl(), numOfArtefact, messageOres, businessPath);
            if (ePFCollCtrl != null) {
                messageView.setArtefact(ePFCollCtrl);
                mainVC.put("eportfolio_" + keyString, ePFCollCtrl.getInitialComponent());
            }
        }
    }
}
Also used : VFSItemMetaFilter(org.olat.core.util.vfs.filters.VFSItemMetaFilter) DisplayPortraitController(org.olat.user.DisplayPortraitController) MarkResourceStat(org.olat.core.commons.services.mark.MarkResourceStat) MediaCollectorComponent(org.olat.modules.portfolio.ui.component.MediaCollectorComponent) OLATResourceable(org.olat.core.id.OLATResourceable) VFSContainer(org.olat.core.util.vfs.VFSContainer) ArrayList(java.util.ArrayList) VFSItem(org.olat.core.util.vfs.VFSItem) Mark(org.olat.core.commons.services.mark.Mark) DisplayPortraitController(org.olat.user.DisplayPortraitController) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) DialogBoxController(org.olat.core.gui.control.generic.modal.DialogBoxController) BasicController(org.olat.core.gui.control.controller.BasicController) StepsMainRunController(org.olat.core.gui.control.generic.wizard.StepsMainRunController) UserInfoMainController(org.olat.user.UserInfoMainController) Controller(org.olat.core.gui.control.Controller) LinkPopupSettings(org.olat.core.gui.components.link.LinkPopupSettings) Identity(org.olat.core.id.Identity) Component(org.olat.core.gui.components.Component) MediaCollectorComponent(org.olat.modules.portfolio.ui.component.MediaCollectorComponent) Link(org.olat.core.gui.components.link.Link)

Example 7 with MarkResourceStat

use of org.olat.core.commons.services.mark.MarkResourceStat in project openolat by klemens.

the class MessageListController method loadView.

private MessageView loadView(UserRequest ureq, MessageLight message) {
    Set<Long> rms = null;
    Map<String, Mark> marks = Collections.emptyMap();
    Map<String, Long> artefactStats = Collections.emptyMap();
    List<String> subPaths = Collections.singletonList(message.getKey().toString());
    if (!guestOnly) {
        String businessPath = BusinessControlFactory.getInstance().getAsString(getWindowControl().getBusinessControl()) + "[Message:" + message.getKey() + "]";
        artefactStats = epMgr.getNumOfArtefactsByStartingBusinessPath(businessPath, getIdentity());
        marks = new HashMap<>();
        List<Mark> markList = markingService.getMarkManager().getMarks(forumOres, getIdentity(), subPaths);
        for (Mark mark : markList) {
            marks.put(mark.getResSubPath(), mark);
        }
    }
    List<MarkResourceStat> statList = markingService.getMarkManager().getStats(forumOres, subPaths, getIdentity());
    Map<String, MarkResourceStat> stats = new HashMap<String, MarkResourceStat>(statList.size() * 2 + 1);
    for (MarkResourceStat stat : statList) {
        stats.put(stat.getSubPath(), stat);
    }
    MessageView view = new MessageView(message, userPropertyHandlers, getLocale());
    view.setNumOfChildren(0);
    addMessageToCurrentMessagesAndVC(ureq, message, view, marks, stats, artefactStats, rms);
    return view;
}
Also used : MarkResourceStat(org.olat.core.commons.services.mark.MarkResourceStat) HashMap(java.util.HashMap) Mark(org.olat.core.commons.services.mark.Mark)

Example 8 with MarkResourceStat

use of org.olat.core.commons.services.mark.MarkResourceStat in project OpenOLAT by OpenOLAT.

the class MarkManagerImpl method getStats.

@Override
public List<MarkResourceStat> getStats(OLATResourceable ores, List<String> subPaths, Identity identity) {
    if (subPaths == null || subPaths.isEmpty()) {
        // these stats are optimized
        if (identity == null) {
            return getStats(ores);
        } else {
            return getStats(ores, identity);
        }
    } else {
        StringBuilder sb = new StringBuilder();
        sb.append("select count(mark.resSubPath), mark.resSubPath from ").append(MarkImpl.class.getName()).append(" mark where ").append("mark.resId=:resId and mark.resName=:resName and mark.resSubPath in (:resSubPath)");
        if (identity != null) {
            sb.append(" and mark.creator=:creator");
        }
        sb.append(" group by mark.resSubPath");
        TypedQuery<Object[]> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class).setParameter("resName", ores.getResourceableTypeName()).setParameter("resId", ores.getResourceableId()).setParameter("resSubPath", subPaths);
        if (identity != null) {
            query.setParameter("creator", identity);
        }
        List<Object[]> rawStats = query.getResultList();
        List<MarkResourceStat> stats = new ArrayList<MarkResourceStat>(rawStats.size());
        for (Object[] rawStat : rawStats) {
            stats.add(new MarkResourceStat(ores, (String) rawStat[1], ((Number) rawStat[0]).intValue()));
        }
        return stats;
    }
}
Also used : MarkResourceStat(org.olat.core.commons.services.mark.MarkResourceStat) ArrayList(java.util.ArrayList)

Example 9 with MarkResourceStat

use of org.olat.core.commons.services.mark.MarkResourceStat in project OpenOLAT by OpenOLAT.

the class MarkManagerImpl method getStats.

private List<MarkResourceStat> getStats(OLATResourceable ores) {
    StringBuilder sb = new StringBuilder();
    sb.append("select count(mark.resSubPath), mark.resSubPath from ").append(MarkImpl.class.getName()).append(" mark where ").append("mark.resId=:resId and mark.resName=:resName").append(" group by mark.resSubPath");
    List<Object[]> rawStats = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class).setParameter("resName", ores.getResourceableTypeName()).setParameter("resId", ores.getResourceableId()).getResultList();
    List<MarkResourceStat> stats = new ArrayList<MarkResourceStat>(rawStats.size());
    for (Object[] rawStat : rawStats) {
        stats.add(new MarkResourceStat(ores, (String) rawStat[1], ((Number) rawStat[0]).intValue()));
    }
    return stats;
}
Also used : MarkResourceStat(org.olat.core.commons.services.mark.MarkResourceStat) ArrayList(java.util.ArrayList)

Example 10 with MarkResourceStat

use of org.olat.core.commons.services.mark.MarkResourceStat in project OpenOLAT by OpenOLAT.

the class MarkManagerImpl method getStats.

private List<MarkResourceStat> getStats(OLATResourceable ores, Identity identity) {
    StringBuilder sb = new StringBuilder();
    sb.append("select mark.resSubPath from ").append(MarkImpl.class.getName()).append(" mark where ").append("mark.resId=:resId and mark.resName=:resName").append(" and mark.creator=:creator");
    List<String> markedSubPaths = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), String.class).setParameter("resName", ores.getResourceableTypeName()).setParameter("resId", ores.getResourceableId()).setParameter("creator", identity).getResultList();
    List<MarkResourceStat> stats = new ArrayList<MarkResourceStat>(markedSubPaths.size());
    for (String markedSubPath : markedSubPaths) {
        stats.add(new MarkResourceStat(ores, markedSubPath, 1));
    }
    return stats;
}
Also used : MarkResourceStat(org.olat.core.commons.services.mark.MarkResourceStat) ArrayList(java.util.ArrayList)

Aggregations

MarkResourceStat (org.olat.core.commons.services.mark.MarkResourceStat)12 ArrayList (java.util.ArrayList)10 Mark (org.olat.core.commons.services.mark.Mark)6 HashMap (java.util.HashMap)4 Component (org.olat.core.gui.components.Component)2 Link (org.olat.core.gui.components.link.Link)2 LinkPopupSettings (org.olat.core.gui.components.link.LinkPopupSettings)2 Controller (org.olat.core.gui.control.Controller)2 BasicController (org.olat.core.gui.control.controller.BasicController)2 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)2 DialogBoxController (org.olat.core.gui.control.generic.modal.DialogBoxController)2 StepsMainRunController (org.olat.core.gui.control.generic.wizard.StepsMainRunController)2 Identity (org.olat.core.id.Identity)2 OLATResourceable (org.olat.core.id.OLATResourceable)2 VFSContainer (org.olat.core.util.vfs.VFSContainer)2 VFSItem (org.olat.core.util.vfs.VFSItem)2 VFSItemMetaFilter (org.olat.core.util.vfs.filters.VFSItemMetaFilter)2 MessageLight (org.olat.modules.fo.MessageLight)2 MediaCollectorComponent (org.olat.modules.portfolio.ui.component.MediaCollectorComponent)2 DisplayPortraitController (org.olat.user.DisplayPortraitController)2