Search in sources :

Example 46 with PortfolioStructure

use of org.olat.portfolio.model.structel.PortfolioStructure in project OpenOLAT by OpenOLAT.

the class EPMultipleMapController method initOrUpdateMaps.

/**
 */
private void initOrUpdateMaps(UserRequest ureq) {
    if (isLogDebugEnabled()) {
        start = System.currentTimeMillis();
        logDebug("start loading map overview at : ", String.valueOf(start));
    }
    List<PortfolioStructure> allUsersStruct = getUsersStructsToDisplay();
    userMaps = new ArrayList<PortfolioStructureMap>();
    if (allUsersStruct.isEmpty()) {
        vC.contextPut("noMaps", true);
        return;
    } else
        vC.contextRemove("noMaps");
    // remove forward link (maybe it's not needed (last page) )
    if (forwardLink != null)
        vC.remove(forwardLink);
    // now add paging-components if necessary and wanted
    int elementCount = ePFMgr.countStructureElementsFromOthers(getIdentity(), mapOwner, ElementType.DEFAULT_MAP);
    if (pagingAvailable && elementCount > ITEMS_PER_PAGE) {
        vC.contextPut("showPaging", true);
        int additionalPage = ((elementCount % ITEMS_PER_PAGE) > 0) ? 1 : 0;
        int pageCount = (elementCount / ITEMS_PER_PAGE) + additionalPage;
        List<Component> pagingLinks = new ArrayList<Component>();
        for (int i = 1; i < pageCount + 1; i++) {
            Link pageLink = LinkFactory.createCustomLink(PAGING_LINK_PREFIX + i, "switchPage", String.valueOf(i), Link.NONTRANSLATED, vC, this);
            pageLink.setUserObject(new Integer(i));
            pagingLinks.add(pageLink);
            if (i == currentPageNum) {
                pageLink.setEnabled(false);
            }
        }
        vC.contextPut("pageLinks", pagingLinks);
        if (currentPageNum < pageCount) {
            forwardLink = LinkFactory.createCustomLink("forwardLink", "pagingFWD", "table.forward", Link.LINK, vC, this);
            forwardLink.setIconRightCSS("o_icon o_icon_next_page");
        }
    }
    // now display the maps
    List<String> artAmount = new ArrayList<String>(userMaps.size());
    List<Integer> childAmount = new ArrayList<Integer>(userMaps.size());
    List<String> mapStyles = new ArrayList<String>(userMaps.size());
    List<Date> deadLines = new ArrayList<Date>(userMaps.size());
    List<String> restriStats = new ArrayList<String>(userMaps.size());
    List<String> owners = new ArrayList<String>(userMaps.size());
    List<String> amounts = new ArrayList<String>(userMaps.size());
    int i = 1;
    for (PortfolioStructure portfolioStructure : allUsersStruct) {
        if (portfolioStructure.getRoot() == null) {
            // only show maps
            PortfolioStructureMap map = (PortfolioStructureMap) portfolioStructure;
            EPSecurityCallback secCallback = EPSecurityCallbackFactory.getSecurityCallback(ureq, map, ePFMgr);
            userMaps.add(map);
            Link vLink = LinkFactory.createCustomLink(VIEW_LINK_PREFIX + i, "viewMap" + map.getResourceableId(), "view.map", Link.LINK, vC, this);
            vLink.setUserObject(map);
            vLink.setElementCssClass("o_sel_ep_open_map");
            vLink.setIconRightCSS("o_icon o_icon-fw o_icon_start");
            // can always try to delete your own map, but exercise only if the course was deleted
            // remove as update could require hiding it
            vC.remove(vC.getComponent(DELETE_LINK_PREFIX + i));
            // can always try to delete your own map, but exercise only if the course was deleted
            final boolean myMaps = (option.equals(EPMapRunViewOption.MY_DEFAULTS_MAPS) || option.equals(EPMapRunViewOption.MY_EXERCISES_MAPS));
            boolean addDeleteLink = myMaps;
            if ((map instanceof EPStructuredMap) && (((EPStructuredMap) map).getReturnDate() != null)) {
                // it's a portfolio-task that was already handed in, so do not display delete-link
                addDeleteLink = false;
            }
            if (addDeleteLink) {
                final Link dLink = LinkFactory.createCustomLink(DELETE_LINK_PREFIX + i, "delMap" + map.getResourceableId(), "delete.map", Link.LINK, vC, this);
                dLink.setIconLeftCSS("o_icon o_icon-fw o_icon_delete_item");
                dLink.setUserObject(map);
            }
            Link cLink = LinkFactory.createCustomLink(COPY_LINK_PREFIX + i, "copyMap" + map.getResourceableId(), "copy.map", Link.LINK, vC, this);
            cLink.setIconLeftCSS("o_icon o_icon_copy");
            cLink.setUserObject(map);
            // its not allowed to copy maps from a portfolio-task
            if (map instanceof EPStructuredMap) {
                cLink.setVisible(false);
            }
            // remove as update could require hiding it
            vC.remove(vC.getComponent(SHARE_LINK_PREFIX + i));
            if (myMaps && secCallback.canShareMap()) {
                Link shareLink = LinkFactory.createCustomLink(SHARE_LINK_PREFIX + i, "shareMap" + map.getResourceableId(), "map.share", Link.LINK, vC, this);
                shareLink.setIconLeftCSS("o_icon o_icon-fw o_icon_share");
                shareLink.setUserObject(map);
                boolean shared = ePFMgr.isMapShared(map);
                if (shared || (map instanceof EPStructuredMap && ((EPStructuredMap) map).getTargetResource() != null)) {
                    shareLink.setCustomDisplayText(translate("map.share.shared"));
                }
            }
            if (isLogDebugEnabled()) {
                logDebug("  in loop : got share state at: ", String.valueOf(System.currentTimeMillis()));
            }
            // get deadline + link to course
            if (map instanceof EPStructuredMap) {
                EPStructuredMap structMap = (EPStructuredMap) map;
                Date deadLine = structMap.getDeadLine();
                deadLines.add(deadLine);
                EPTargetResource resource = structMap.getTargetResource();
                RepositoryEntry repoEntry = RepositoryManager.getInstance().lookupRepositoryEntry(resource.getOLATResourceable(), false);
                if (repoEntry != null) {
                    vC.contextPut("courseName" + i, StringHelper.escapeHtml(repoEntry.getDisplayname()));
                    String url = Settings.getServerContextPathURI();
                    url += "/url/RepositoryEntry/" + repoEntry.getKey() + "/CourseNode/" + resource.getSubPath();
                    vC.contextPut("courseLink" + i, url);
                }
                if (isLogDebugEnabled()) {
                    logDebug("  in loop : looked up course at : ", String.valueOf(System.currentTimeMillis()));
                }
                // get some stats about the restrictions if available
                String[] stats = ePFMgr.getRestrictionStatisticsOfMap(structMap);
                int toCollect = 0;
                if (stats != null) {
                    try {
                        toCollect = Integer.parseInt(stats[1]) - Integer.parseInt(stats[0]);
                    } catch (Exception e) {
                        // do nothing
                        toCollect = 0;
                    }
                }
                if (toCollect != 0) {
                    restriStats.add(String.valueOf(toCollect));
                } else {
                    restriStats.add(null);
                }
                if (isLogDebugEnabled()) {
                    logDebug("  in loop : calculated restriction statistics at : ", String.valueOf(System.currentTimeMillis()));
                }
            } else {
                deadLines.add(null);
                restriStats.add(null);
            }
            // show owner on shared maps
            if (!secCallback.isOwner()) {
                owners.add(ePFMgr.getAllOwnersAsString(map));
            } else
                owners.add(null);
            String artCount = String.valueOf(ePFMgr.countArtefactsInMap(map));
            artAmount.add(artCount);
            Integer childs = ePFMgr.countStructureChildren(map);
            childAmount.add(childs);
            amounts.add(translate("map.contains", new String[] { childs.toString(), artCount }));
            mapStyles.add(ePFMgr.getValidStyleName(map));
            if (isLogDebugEnabled()) {
                logDebug("  in loop : got map details (artefact-amount, child-struct-amount, style) at : ", String.valueOf(System.currentTimeMillis()));
            }
            i++;
        }
    }
    vC.contextPut("owners", owners);
    vC.contextPut("deadLines", deadLines);
    vC.contextPut("restriStats", restriStats);
    vC.contextPut("mapStyles", mapStyles);
    vC.contextPut("childAmount", childAmount);
    vC.contextPut("artefactAmount", artAmount);
    vC.contextPut("amounts", amounts);
    vC.contextPut("userMaps", userMaps);
    if (isLogDebugEnabled()) {
        long now = System.currentTimeMillis();
        logDebug("finished processing all maps at : ", String.valueOf(now));
        logDebug("Total processing time for " + (i - 1) + " maps was : ", String.valueOf(now - start));
    }
}
Also used : PortfolioStructureMap(org.olat.portfolio.model.structel.PortfolioStructureMap) EPTargetResource(org.olat.portfolio.model.structel.EPTargetResource) ArrayList(java.util.ArrayList) RepositoryEntry(org.olat.repository.RepositoryEntry) Date(java.util.Date) EPStructuredMap(org.olat.portfolio.model.structel.EPStructuredMap) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure) EPSecurityCallback(org.olat.portfolio.EPSecurityCallback) Component(org.olat.core.gui.components.Component) Link(org.olat.core.gui.components.link.Link)

Example 47 with PortfolioStructure

use of org.olat.portfolio.model.structel.PortfolioStructure in project OpenOLAT by OpenOLAT.

the class EPStructureElementsController method event.

/**
 * @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest, org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
 */
@Override
protected void event(UserRequest ureq, Controller source, Event event) {
    super.event(ureq, source, event);
    if (event instanceof EPStructureChangeEvent) {
        // update the elements
        EPStructureChangeEvent changeEvent = (EPStructureChangeEvent) event;
        PortfolioStructure changedEl = changeEvent.getPortfolioStructure();
        if (changedEl != null) {
            int index = 0;
            for (PortfolioStructure strucEl : structElements) {
                if (changedEl.getKey().equals(strucEl.getKey())) {
                    structElements.set(index, changedEl);
                    break;
                }
                index++;
            }
        }
        // something changed
        initForm(ureq);
        // pass it on, parent controllers (EPPageViewController)  might need to update
        fireEvent(ureq, changeEvent);
    }
}
Also used : PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure)

Example 48 with PortfolioStructure

use of org.olat.portfolio.model.structel.PortfolioStructure in project OpenOLAT by OpenOLAT.

the class EPTOCController method checkArtefactTarget.

private boolean checkArtefactTarget(AbstractArtefact artefact, Object targetObj) {
    PortfolioStructure newParStruct;
    if (targetObj instanceof EPAbstractMap) {
        return false;
    } else if (targetObj instanceof PortfolioStructure) {
        newParStruct = (PortfolioStructure) targetObj;
    } else {
        return false;
    }
    boolean sameTarget = ePFMgr.isArtefactInStructure(artefact, newParStruct);
    if (sameTarget) {
        return false;
    }
    return true;
}
Also used : EPAbstractMap(org.olat.portfolio.model.structel.EPAbstractMap) PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure)

Example 49 with PortfolioStructure

use of org.olat.portfolio.model.structel.PortfolioStructure in project OpenOLAT by OpenOLAT.

the class EPTOCController method reorder.

private boolean reorder(UserRequest ureq, AbstractArtefact artefact, TreeNode parentNode, Object target) {
    Object parentObj = parentNode.getUserObject();
    if (!(parentObj instanceof PortfolioStructure)) {
        return false;
    }
    int position = TreeHelper.indexOfByUserObject(target, parentNode);
    int current = TreeHelper.indexOfByUserObject(artefact, parentNode);
    if (current == position) {
        // nothing to do
        return false;
    } else {
        // drop after
        position++;
    }
    try {
        PortfolioStructure parStruct = (PortfolioStructure) parentObj;
        // translate in the position in the list of artefacts
        int numOfChildren = ePFMgr.countStructureChildren(parStruct);
        position = position - numOfChildren;
        if (position < 0) {
            position = 0;
        }
        if (ePFMgr.moveArtefactInStruct(artefact, parStruct, position)) {
            reloadTreeModel(parStruct, null);
            fireEvent(ureq, new EPMoveEvent());
            return true;
        }
    } catch (Exception e) {
        logError("could not load artefact, old and new parent", e);
    }
    return false;
}
Also used : PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure)

Example 50 with PortfolioStructure

use of org.olat.portfolio.model.structel.PortfolioStructure in project OpenOLAT by OpenOLAT.

the class EPTOCController method moveStructureToNewParent.

private boolean moveStructureToNewParent(UserRequest ureq, PortfolioStructure structToBeMvd, Object oldParent, Object newParent, int newPos) {
    if (oldParent instanceof PortfolioStructure && newParent instanceof PortfolioStructure) {
        PortfolioStructure oldParStruct = (PortfolioStructure) oldParent;
        PortfolioStructure newParStruct = (PortfolioStructure) newParent;
        if (oldParStruct.equals(newParStruct)) {
            // this is only a position move
            if (ePFMgr.moveStructureToPosition(structToBeMvd, newPos)) {
                reloadTreeModel(structToBeMvd, null);
                fireEvent(ureq, new EPMoveEvent());
                return true;
            }
        } else if (ePFMgr.moveStructureToNewParentStructure(structToBeMvd, oldParStruct, newParStruct, newPos)) {
            reloadTreeModel(oldParStruct, newParStruct);
            fireEvent(ureq, new EPMoveEvent());
            return true;
        }
    }
    return false;
}
Also used : PortfolioStructure(org.olat.portfolio.model.structel.PortfolioStructure)

Aggregations

PortfolioStructure (org.olat.portfolio.model.structel.PortfolioStructure)236 Test (org.junit.Test)90 AbstractArtefact (org.olat.portfolio.model.artefacts.AbstractArtefact)70 PortfolioStructureMap (org.olat.portfolio.model.structel.PortfolioStructureMap)54 ArrayList (java.util.ArrayList)40 OLATResource (org.olat.resource.OLATResource)30 Identity (org.olat.core.id.Identity)26 RepositoryEntry (org.olat.repository.RepositoryEntry)24 EPStructureElement (org.olat.portfolio.model.structel.EPStructureElement)22 EPMapPolicy (org.olat.portfolio.manager.EPMapPolicy)16 EPPage (org.olat.portfolio.model.structel.EPPage)16 EPAbstractMap (org.olat.portfolio.model.structel.EPAbstractMap)12 EPStructuredMap (org.olat.portfolio.model.structel.EPStructuredMap)12 DBQuery (org.olat.core.commons.persistence.DBQuery)10 EPFrontendManager (org.olat.portfolio.manager.EPFrontendManager)10 Date (java.util.Date)8 Document (org.apache.lucene.document.Document)8 Link (org.olat.core.gui.components.link.Link)8 GenericTreeNode (org.olat.core.gui.components.tree.GenericTreeNode)8 EPStructuredMapTemplate (org.olat.portfolio.model.structel.EPStructuredMapTemplate)8