Search in sources :

Example 1 with CourseNode

use of org.olat.course.nodes.CourseNode in project OpenOLAT by OpenOLAT.

the class NavigationHandler method convertToTreeNodeId.

private String convertToTreeNodeId(TreeEvaluation treeEval, String courseNodeId) {
    if (courseNodeId == null)
        return null;
    CourseNode courseNode = userCourseEnv.getCourseEnvironment().getRunStructure().getNode(courseNodeId);
    TreeNode newCalledTreeNode = treeEval.getCorrespondingTreeNode(courseNode);
    if (newCalledTreeNode == null) {
        return courseNodeId;
    } else {
        return newCalledTreeNode.getIdent();
    }
}
Also used : GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) TreeNode(org.olat.core.gui.components.tree.TreeNode) CourseNode(org.olat.course.nodes.CourseNode) AbstractAccessableCourseNode(org.olat.course.nodes.AbstractAccessableCourseNode) STCourseNode(org.olat.course.nodes.STCourseNode)

Example 2 with CourseNode

use of org.olat.course.nodes.CourseNode in project OpenOLAT by OpenOLAT.

the class NavigationHandler method doEvaluateJumpTo.

private NodeClickedRef doEvaluateJumpTo(UserRequest ureq, WindowControl wControl, CourseNode courseNode, ControllerEventListener listeningController, String nodecmd, String nodeSubCmd, Controller currentNodeController) {
    NodeClickedRef nclr;
    if (log.isDebug()) {
        log.debug("evaluateJumpTo courseNode = " + courseNode.getIdent() + ", " + courseNode.getShortName());
    }
    // build the new treemodel by evaluating the preconditions
    TreeEvaluation treeEval = new TreeEvaluation();
    GenericTreeModel treeModel = new GenericTreeModel();
    CourseNode rootCn = userCourseEnv.getCourseEnvironment().getRunStructure().getRootNode();
    NodeEvaluation rootNodeEval = rootCn.eval(userCourseEnv.getConditionInterpreter(), treeEval, filter);
    TreeNode treeRoot = rootNodeEval.getTreeNode();
    treeModel.setRootNode(treeRoot);
    // find the treenode that corresponds to the node (!= selectedTreeNode since
    // we built the TreeModel anew in the meantime
    TreeNode newCalledTreeNode = treeEval.getCorrespondingTreeNode(courseNode);
    if (newCalledTreeNode == null) {
        // the clicked node is not visible anymore!
        // if the new calculated model does not contain the selected node anymore
        // (because of visibility changes of at least one of the ancestors
        // -> issue an user infomative msg
        // nclr: the new treemodel, not visible, no selected nodeid, no
        // calledcoursenode, no nodeconstructionresult
        nclr = new NodeClickedRef(treeModel, false, null, null, null, null, false);
    } else {
        // calculate the NodeClickedRef
        // 1. get the correct (new) nodeevaluation
        NodeEvaluation nodeEval = (NodeEvaluation) newCalledTreeNode.getUserObject();
        if (nodeEval.getCourseNode() != courseNode) {
            throw new AssertException("error in structure");
        }
        if (!nodeEval.isVisible()) {
            throw new AssertException("node eval not visible!!");
        }
        // 2. start with the current NodeEvaluation, evaluate overall accessiblity
        // per node bottom-up to see if all ancestors still grant access to the
        // desired node
        boolean mayAccessWholeTreeUp = mayAccessWholeTreeUp(nodeEval);
        String newSelectedNodeId = newCalledTreeNode.getIdent();
        Controller controller;
        AdditionalConditionManager addMan = null;
        if (courseNode instanceof AbstractAccessableCourseNode) {
            Long courseId = userCourseEnv.getCourseEnvironment().getCourseResourceableId();
            CourseNodePasswordManager cnpm = CourseNodePasswordManagerImpl.getInstance();
            Identity identity = userCourseEnv.getIdentityEnvironment().getIdentity();
            AdditionalConditionAnswerContainer answerContainer = cnpm.getAnswerContainer(identity);
            addMan = new AdditionalConditionManager((AbstractAccessableCourseNode) courseNode, courseId, answerContainer);
        }
        if (!mayAccessWholeTreeUp || (addMan != null && !addMan.evaluateConditions())) {
            if (nodeEval.oldStyleConditionsOk()) {
                controller = addMan.nextUserInputController(ureq, wControl, userCourseEnv);
                if (listeningController != null) {
                    controller.addControllerListener(listeningController);
                }
            } else {
                // NOTE: we do not take into account what node caused the non-access by
                // being !isAtLeastOneAccessible, but always state the
                // NoAccessExplanation of the Node originally called by the user
                String explan = courseNode.getNoAccessExplanation();
                String sExplan = (explan == null ? "" : Formatter.formatLatexFormulas(explan));
                controller = MessageUIFactory.createInfoMessage(ureq, wControl, null, sExplan);
                // write log information
                ThreadLocalUserActivityLogger.log(CourseLoggingAction.COURSE_NAVIGATION_NODE_NO_ACCESS, getClass(), LoggingResourceable.wrap(courseNode));
            }
            NodeRunConstructionResult ncr = new NodeRunConstructionResult(controller, null, null, null);
            // nclr: the new treemodel, visible, selected nodeid, calledcoursenode,
            // nodeconstructionresult
            nclr = new NodeClickedRef(treeModel, true, newSelectedNodeId, null, courseNode, ncr, false);
        } else if (!CourseNodeFactory.getInstance().getCourseNodeConfigurationEvenForDisabledBB(courseNode.getType()).isEnabled()) {
            Translator pT = Util.createPackageTranslator(EditorMainController.class, ureq.getLocale());
            controller = MessageUIFactory.createInfoMessage(ureq, wControl, null, pT.translate("course.building.block.disabled.user"));
            NodeRunConstructionResult ncr = new NodeRunConstructionResult(controller, null, null, null);
            nclr = new NodeClickedRef(treeModel, true, newSelectedNodeId, null, courseNode, ncr, false);
        } else {
            if (STCourseNode.isDelegatingSTCourseNode(courseNode) && (courseNode.getChildCount() > 0)) {
                // the clicked node is a STCourse node and is set to "delegate", so
                // delegate to its first visible child; if no child is visible, just skip and do normal eval
                INode child;
                for (int i = 0; i < courseNode.getChildCount(); i++) {
                    child = courseNode.getChildAt(i);
                    if (child instanceof CourseNode) {
                        CourseNode cn = (CourseNode) child;
                        NodeEvaluation cnEval = cn.eval(userCourseEnv.getConditionInterpreter(), treeEval, filter);
                        if (cnEval.isVisible()) {
                            return doEvaluateJumpTo(ureq, wControl, cn, listeningController, nodecmd, nodeSubCmd, currentNodeController);
                        }
                    }
                }
            }
            // access the node, display its result in the right pane
            NodeRunConstructionResult ncr;
            // calculate the new businesscontext for the coursenode being called.
            // type: class of node; key = node.getIdent;
            // don't use the concrete instance since for the course: to jump to a coursenode with a given id is all there is to know
            Class<CourseNode> oresC = CourseNode.class;
            Long oresK = new Long(Long.parseLong(courseNode.getIdent()));
            final OLATResourceable ores = OresHelper.createOLATResourceableInstance(oresC, oresK);
            ContextEntry ce = BusinessControlFactory.getInstance().createContextEntry(ores);
            WindowControl bwControl = BusinessControlFactory.getInstance().createBusinessWindowControl(ce, wControl);
            if (previewMode) {
                ncr = new NodeRunConstructionResult(courseNode.createPreviewController(ureq, bwControl, userCourseEnv, nodeEval));
            } else {
                // cleanup already existing controllers with external models for this node first, never disposed otherwise
                if (externalTreeModels.containsKey(courseNode.getIdent()) && !(TreeEvent.COMMAND_TREENODE_OPEN.equals(nodeSubCmd) || TreeEvent.COMMAND_TREENODE_CLOSE.equals(nodeSubCmd))) {
                    SubTree subTree = externalTreeModels.get(courseNode.getIdent());
                    ControllerEventListener existingSubtreemodelListener = subTree.getTreeModelListener();
                    if (existingSubtreemodelListener != null && currentNodeController != null && !currentNodeController.isDisposed()) {
                        currentNodeController.dispose();
                    }
                }
                ncr = courseNode.createNodeRunConstructionResult(ureq, bwControl, userCourseEnv, nodeEval, nodecmd);
                // remember as instance variable for next click
                ControllerEventListener subtreemodelListener = ncr.getSubTreeListener();
                if (subtreemodelListener != null) {
                    GenericTreeModel subTreeModel = (GenericTreeModel) ncr.getSubTreeModel();
                    externalTreeModels.put(courseNode.getIdent(), new SubTree(ncr.getRunController(), subTreeModel, subtreemodelListener));
                    if (!newSelectedNodeId.equals(ncr.getSelectedTreeNodeId())) {
                        if (ncr.getSelectedTreeNodeId() != null) {
                            TreeNode selectedNode = subTreeModel.getNodeById(ncr.getSelectedTreeNodeId());
                            if (selectedNode != null && selectedNode.getUserObject() instanceof String) {
                                openCourseNodeIds.add((String) selectedNode.getUserObject());
                            }
                        }
                    }
                }
            }
            if (TreeEvent.COMMAND_TREENODE_OPEN.equals(nodeSubCmd)) {
                openCourseNodeIds.add(courseNode.getIdent());
                newSelectedNodeId = convertToTreeNodeId(treeEval, selectedCourseNodeId);
            } else if (TreeEvent.COMMAND_TREENODE_CLOSE.equals(nodeSubCmd)) {
                removeChildrenFromOpenNodes(courseNode);
                newSelectedNodeId = convertToTreeNodeId(treeEval, selectedCourseNodeId);
                if (!isInParentLine(courseNode)) {
                    selectedCourseNodeId = courseNode.getIdent();
                } else {
                    selectedCourseNodeId = null;
                    newSelectedNodeId = null;
                }
            } else {
                // add the selected node to the open one, if not, strange behaviour
                selectedCourseNodeId = courseNode.getIdent();
                openCourseNodeIds.add(selectedCourseNodeId);
                if (ncr != null) {
                    String subNodeId = ncr.getSelectedTreeNodeId();
                    if (subNodeId != null) {
                        openCourseNodeIds.add(subNodeId);
                    }
                }
            }
            openTreeNodeIds = convertToTreeNodeIds(treeEval, openCourseNodeIds);
            reattachExternalTreeModels(treeEval);
            if ((TreeEvent.COMMAND_TREENODE_OPEN.equals(nodeSubCmd) || TreeEvent.COMMAND_TREENODE_CLOSE.equals(nodeSubCmd)) && currentNodeController != null && !currentNodeController.isDisposed()) {
                nclr = new NodeClickedRef(treeModel, true, null, openTreeNodeIds, null, null, false);
            } else {
                // nclr: the new treemodel, visible, selected nodeid, calledcoursenode,
                // nodeconstructionresult
                nclr = new NodeClickedRef(treeModel, true, newSelectedNodeId, openTreeNodeIds, courseNode, ncr, false);
                // attach listener; we know we have a runcontroller here
                if (listeningController != null) {
                    nclr.getRunController().addControllerListener(listeningController);
                }
            }
            // write log information
            ThreadLocalUserActivityLogger.log(CourseLoggingAction.COURSE_NAVIGATION_NODE_ACCESS, getClass(), LoggingResourceable.wrap(courseNode));
        }
    }
    return nclr;
}
Also used : INode(org.olat.core.util.nodes.INode) OLATResourceable(org.olat.core.id.OLATResourceable) AdditionalConditionManager(org.olat.course.condition.additionalconditions.AdditionalConditionManager) WindowControl(org.olat.core.gui.control.WindowControl) ContextEntry(org.olat.core.id.context.ContextEntry) ControllerEventListener(org.olat.core.gui.control.ControllerEventListener) Translator(org.olat.core.gui.translator.Translator) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) TreeNode(org.olat.core.gui.components.tree.TreeNode) GenericTreeModel(org.olat.core.gui.components.tree.GenericTreeModel) CourseNode(org.olat.course.nodes.CourseNode) AbstractAccessableCourseNode(org.olat.course.nodes.AbstractAccessableCourseNode) STCourseNode(org.olat.course.nodes.STCourseNode) Identity(org.olat.core.id.Identity) EditorMainController(org.olat.course.editor.EditorMainController) AssertException(org.olat.core.logging.AssertException) EditorMainController(org.olat.course.editor.EditorMainController) TitledWrapperController(org.olat.core.gui.control.generic.title.TitledWrapperController) CPRunController(org.olat.course.nodes.cp.CPRunController) Controller(org.olat.core.gui.control.Controller) CourseNodePasswordManager(de.bps.course.nodes.CourseNodePasswordManager) TreeEvaluation(org.olat.course.run.userview.TreeEvaluation) AbstractAccessableCourseNode(org.olat.course.nodes.AbstractAccessableCourseNode) NodeEvaluation(org.olat.course.run.userview.NodeEvaluation) AdditionalConditionAnswerContainer(org.olat.course.condition.additionalconditions.AdditionalConditionAnswerContainer)

Example 3 with CourseNode

use of org.olat.course.nodes.CourseNode in project OpenOLAT by OpenOLAT.

the class NavigationHandler method reattachExternalTreeModels.

private void reattachExternalTreeModels(TreeEvaluation treeEval) {
    if (externalTreeModels == null || externalTreeModels.isEmpty())
        return;
    for (Map.Entry<String, SubTree> entry : externalTreeModels.entrySet()) {
        String courseNodeId = entry.getKey();
        SubTree subTree = entry.getValue();
        TreeModel treeModel = subTree.getTreeModel();
        CourseNode courseNode = userCourseEnv.getCourseEnvironment().getRunStructure().getNode(courseNodeId);
        TreeNode treeNode = treeEval.getCorrespondingTreeNode(courseNode);
        if (treeNode != null) {
            addSubTreeModel(treeNode, treeModel);
        }
    }
}
Also used : TreeModel(org.olat.core.gui.components.tree.TreeModel) GenericTreeModel(org.olat.core.gui.components.tree.GenericTreeModel) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) TreeNode(org.olat.core.gui.components.tree.TreeNode) CourseNode(org.olat.course.nodes.CourseNode) AbstractAccessableCourseNode(org.olat.course.nodes.AbstractAccessableCourseNode) STCourseNode(org.olat.course.nodes.STCourseNode) Map(java.util.Map) HashMap(java.util.HashMap)

Example 4 with CourseNode

use of org.olat.course.nodes.CourseNode in project OpenOLAT by OpenOLAT.

the class InitialAttemptsRuleEditor method initForm.

@Override
public FormItem initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    String page = Util.getPackageVelocityRoot(this.getClass()) + "/initial_attempts.html";
    String id = Long.toString(CodeHelper.getRAMUniqueID());
    Translator trans = formLayout.getTranslator();
    FormLayoutContainer ruleCont = FormLayoutContainer.createCustomFormLayout("attempts.".concat(id), formLayout.getTranslator(), page);
    ruleCont.setRootForm(formLayout.getRootForm());
    formLayout.add(ruleCont);
    ruleCont.getFormItemComponent().contextPut("id", id);
    ICourse course = CourseFactory.loadCourse(entry);
    String currentValue = null;
    String currentUnit = null;
    String currentCourseNode = null;
    if (rule instanceof ReminderRuleImpl) {
        ReminderRuleImpl r = (ReminderRuleImpl) rule;
        currentUnit = r.getRightUnit();
        currentValue = r.getRightOperand();
        currentCourseNode = r.getLeftOperand();
    }
    List<CourseNode> attemptableNodes = new ArrayList<>();
    searchAttemptableNodes(course.getRunStructure().getRootNode(), attemptableNodes);
    String[] nodeKeys = new String[attemptableNodes.size()];
    String[] nodeValues = new String[attemptableNodes.size()];
    for (int i = 0; i < attemptableNodes.size(); i++) {
        CourseNode attemptableNode = attemptableNodes.get(i);
        nodeKeys[i] = attemptableNode.getIdent();
        nodeValues[i] = attemptableNode.getShortTitle() + " ( " + attemptableNode.getIdent() + " )";
    }
    courseNodeEl = uifactory.addDropdownSingleselect("coursenodes.".concat(id), null, ruleCont, nodeKeys, nodeValues, null);
    courseNodeEl.setDomReplacementWrapperRequired(false);
    boolean nodeSelected = false;
    if (currentCourseNode != null) {
        for (String nodeKey : nodeKeys) {
            if (currentCourseNode.equals(nodeKey)) {
                courseNodeEl.select(nodeKey, true);
                nodeSelected = true;
            }
        }
    }
    if (!nodeSelected && nodeKeys.length > 0) {
        courseNodeEl.select(nodeKeys[0], true);
    }
    if (StringHelper.containsNonWhitespace(currentCourseNode) && !nodeSelected) {
        courseNodeEl.setErrorKey("error.course.node.found", null);
    }
    valueEl = uifactory.addTextElement("attemptvalue.".concat(id), null, 128, currentValue, ruleCont);
    valueEl.setDomReplacementWrapperRequired(false);
    valueEl.setDisplaySize(3);
    String[] unitValues = new String[] { trans.translate(LaunchUnit.day.name()), trans.translate(LaunchUnit.week.name()), trans.translate(LaunchUnit.month.name()), trans.translate(LaunchUnit.year.name()) };
    unitEl = uifactory.addDropdownSingleselect("attemptunit.".concat(id), null, ruleCont, unitKeys, unitValues, null);
    unitEl.setDomReplacementWrapperRequired(false);
    boolean selected = false;
    if (currentUnit != null) {
        for (String unitKey : unitKeys) {
            if (currentUnit.equals(unitKey)) {
                unitEl.select(unitKey, true);
                selected = true;
            }
        }
    }
    if (!selected) {
        unitEl.select(unitKeys[1], true);
    }
    return ruleCont;
}
Also used : Translator(org.olat.core.gui.translator.Translator) ReminderRuleImpl(org.olat.modules.reminder.model.ReminderRuleImpl) ArrayList(java.util.ArrayList) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) ICourse(org.olat.course.ICourse) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) CourseNode(org.olat.course.nodes.CourseNode)

Example 5 with CourseNode

use of org.olat.course.nodes.CourseNode in project OpenOLAT by OpenOLAT.

the class InitialAttemptsRuleEditor method searchAttemptableNodes.

private void searchAttemptableNodes(CourseNode courseNode, List<CourseNode> nodes) {
    if (courseNode instanceof AssessableCourseNode) {
        AssessableCourseNode assessableCourseNode = (AssessableCourseNode) courseNode;
        if (assessableCourseNode.hasAttemptsConfigured()) {
            nodes.add(courseNode);
        }
    }
    for (int i = 0; i < courseNode.getChildCount(); i++) {
        CourseNode child = (CourseNode) courseNode.getChildAt(i);
        searchAttemptableNodes(child, nodes);
    }
}
Also used : AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) CourseNode(org.olat.course.nodes.CourseNode)

Aggregations

CourseNode (org.olat.course.nodes.CourseNode)402 ICourse (org.olat.course.ICourse)182 AssessableCourseNode (org.olat.course.nodes.AssessableCourseNode)98 Identity (org.olat.core.id.Identity)74 STCourseNode (org.olat.course.nodes.STCourseNode)72 ArrayList (java.util.ArrayList)68 RepositoryEntry (org.olat.repository.RepositoryEntry)64 CourseEditorTreeNode (org.olat.course.tree.CourseEditorTreeNode)54 INode (org.olat.core.util.nodes.INode)44 GTACourseNode (org.olat.course.nodes.GTACourseNode)44 UserCourseEnvironment (org.olat.course.run.userview.UserCourseEnvironment)42 TACourseNode (org.olat.course.nodes.TACourseNode)40 TreeNode (org.olat.core.gui.components.tree.TreeNode)38 IQTESTCourseNode (org.olat.course.nodes.IQTESTCourseNode)36 MSCourseNode (org.olat.course.nodes.MSCourseNode)36 ScormCourseNode (org.olat.course.nodes.ScormCourseNode)30 Test (org.junit.Test)28 AbstractAccessableCourseNode (org.olat.course.nodes.AbstractAccessableCourseNode)28 ScoreEvaluation (org.olat.course.run.scoring.ScoreEvaluation)28 CourseEditorTreeModel (org.olat.course.tree.CourseEditorTreeModel)26