Search in sources :

Example 86 with CourseEditorTreeNode

use of org.olat.course.tree.CourseEditorTreeNode in project openolat by klemens.

the class CheckListStepRunnerCallback method execute.

@Override
public Step execute(UserRequest ureq, WindowControl wControl, StepsRunContext runContext) {
    GeneratorData data = (GeneratorData) runContext.get("data");
    List<Checkbox> templateCheckbox = data.getCheckboxList();
    ModuleConfiguration templateConfig = data.getModuleConfiguration();
    ICourse course = CourseFactory.getCourseEditSession(courseOres.getResourceableId());
    CourseEnvironment courseEnv = course.getCourseEnvironment();
    CheckboxManager checkboxManager = CoreSpringFactory.getImpl(CheckboxManager.class);
    CourseNode structureNode = createCourseNode(data.getStructureShortTitle(), data.getStructureTitle(), data.getStructureObjectives(), "st");
    CourseEditorTreeNode parentNode = (CourseEditorTreeNode) course.getEditorTreeModel().getRootNode();
    course.getEditorTreeModel().addCourseNode(structureNode, parentNode.getCourseNode());
    List<CheckListNode> nodes = data.getNodes();
    List<String> nodesIdent = new ArrayList<>();
    for (CheckListNode node : nodes) {
        String title = node.getTitle();
        CheckListCourseNode checkNode = (CheckListCourseNode) createCourseNode(title, title, null, "checklist");
        nodesIdent.add(checkNode.getIdent());
        ModuleConfiguration config = checkNode.getModuleConfiguration();
        config.putAll(templateConfig);
        CheckboxList checkboxList = new CheckboxList();
        List<Checkbox> boxes = new ArrayList<>();
        for (Checkbox templateBox : templateCheckbox) {
            Checkbox checkbox = templateBox.clone();
            boxes.add(checkbox);
            if (StringHelper.containsNonWhitespace(templateBox.getFilename())) {
                File path = new File(FolderConfig.getCanonicalTmpDir(), templateBox.getCheckboxId());
                VFSContainer tmpContainer = new LocalFolderImpl(path);
                VFSItem item = tmpContainer.resolve(templateBox.getFilename());
                if (item instanceof VFSLeaf) {
                    VFSContainer container = checkboxManager.getFileContainer(courseEnv, checkNode);
                    VFSManager.copyContent(tmpContainer, container);
                    tmpContainer.deleteSilently();
                }
            }
        }
        checkboxList.setList(boxes);
        config.set(CheckListCourseNode.CONFIG_KEY_CHECKBOX, checkboxList);
        boolean dueDate = node.getDueDate() != null;
        if (dueDate) {
            config.set(CheckListCourseNode.CONFIG_KEY_DUE_DATE, node.getDueDate());
        }
        config.set(CheckListCourseNode.CONFIG_KEY_CLOSE_AFTER_DUE_DATE, new Boolean(dueDate));
        course.getEditorTreeModel().addCourseNode(checkNode, structureNode);
    }
    setScoreCalculation(data, (STCourseNode) structureNode, nodesIdent);
    return StepsMainRunController.DONE_MODIFIED;
}
Also used : CheckboxList(org.olat.course.nodes.cl.model.CheckboxList) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) ModuleConfiguration(org.olat.modules.ModuleConfiguration) CourseEnvironment(org.olat.course.run.environment.CourseEnvironment) VFSContainer(org.olat.core.util.vfs.VFSContainer) CourseEditorTreeNode(org.olat.course.tree.CourseEditorTreeNode) ArrayList(java.util.ArrayList) VFSItem(org.olat.core.util.vfs.VFSItem) ICourse(org.olat.course.ICourse) CheckListCourseNode(org.olat.course.nodes.CheckListCourseNode) LocalFolderImpl(org.olat.core.util.vfs.LocalFolderImpl) CheckboxManager(org.olat.course.nodes.cl.CheckboxManager) Checkbox(org.olat.course.nodes.cl.model.Checkbox) CourseNode(org.olat.course.nodes.CourseNode) CheckListCourseNode(org.olat.course.nodes.CheckListCourseNode) STCourseNode(org.olat.course.nodes.STCourseNode) File(java.io.File)

Example 87 with CourseEditorTreeNode

use of org.olat.course.tree.CourseEditorTreeNode in project openolat by klemens.

the class ModifyCourseEvent method createCourse.

/**
 * Creates an empty course with a single root node. The course is linked to
 * the resourceable ores. The efficiency statment are enabled per default!
 *
 * @param ores
 * @param shortTitle Short title of root node
 * @param longTitle Long title of root node
 * @param learningObjectives Learning objectives of root node
 * @return An empty course with a single root node.
 */
public static ICourse createCourse(RepositoryEntry courseEntry, String shortTitle, String longTitle, String learningObjectives) {
    OLATResource courseResource = courseEntry.getOlatResource();
    PersistingCourseImpl newCourse = new PersistingCourseImpl(courseResource);
    // Put new course in course cache
    loadedCourses.put(newCourse.getResourceableId(), newCourse);
    Structure initialStructure = new Structure();
    CourseNode runRootNode = new STCourseNode();
    runRootNode.setShortTitle(shortTitle);
    runRootNode.setLongTitle(longTitle);
    runRootNode.setLearningObjectives(learningObjectives);
    initialStructure.setRootNode(runRootNode);
    newCourse.setRunStructure(initialStructure);
    newCourse.saveRunStructure();
    CourseEditorTreeModel editorTreeModel = new CourseEditorTreeModel();
    CourseEditorTreeNode editorRootNode = new CourseEditorTreeNode((CourseNode) ObjectCloner.deepCopy(runRootNode));
    editorTreeModel.setRootNode(editorRootNode);
    newCourse.setEditorTreeModel(editorTreeModel);
    newCourse.saveEditorTreeModel();
    // enable efficiency statement per default
    CourseConfig courseConfig = newCourse.getCourseConfig();
    courseConfig.setEfficencyStatementIsEnabled(true);
    newCourse.setCourseConfig(courseConfig);
    return newCourse;
}
Also used : CourseEditorTreeModel(org.olat.course.tree.CourseEditorTreeModel) STCourseNode(org.olat.course.nodes.STCourseNode) CourseEditorTreeNode(org.olat.course.tree.CourseEditorTreeNode) OLATResource(org.olat.resource.OLATResource) STCourseNode(org.olat.course.nodes.STCourseNode) BCCourseNode(org.olat.course.nodes.BCCourseNode) CourseNode(org.olat.course.nodes.CourseNode) TACourseNode(org.olat.course.nodes.TACourseNode) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) CourseConfig(org.olat.course.config.CourseConfig)

Example 88 with CourseEditorTreeNode

use of org.olat.course.tree.CourseEditorTreeNode in project openolat by klemens.

the class AssessmentHelper method getAssessableNodes.

/**
 * Get all assessable nodes including the root node (if assessable)
 *
 * @param editorModel
 * @param excludeNode Node that should be excluded in the list, e.g. the
 *          current node or null if all assessable nodes should be used
 * @return List of assessable course nodes
 */
public static List<CourseNode> getAssessableNodes(final CourseEditorTreeModel editorModel, final CourseNode excludeNode) {
    CourseEditorTreeNode rootNode = (CourseEditorTreeNode) editorModel.getRootNode();
    final List<CourseNode> nodes = new ArrayList<CourseNode>();
    // visitor class: takes all assessable nodes if not the exclude node and
    // puts
    // them into the nodes list
    Visitor visitor = new Visitor() {

        @Override
        public void visit(INode node) {
            CourseEditorTreeNode editorNode = (CourseEditorTreeNode) node;
            CourseNode courseNode = editorModel.getCourseNode(node.getIdent());
            if (!editorNode.isDeleted() && (courseNode != excludeNode)) {
                if (checkIfNodeIsAssessable(courseNode)) {
                    nodes.add(courseNode);
                }
            }
        }
    };
    // not visit beginning at the root node
    TreeVisitor tv = new TreeVisitor(visitor, rootNode, false);
    tv.visitAll();
    return nodes;
}
Also used : TreeVisitor(org.olat.core.util.tree.TreeVisitor) INode(org.olat.core.util.nodes.INode) TreeVisitor(org.olat.core.util.tree.TreeVisitor) Visitor(org.olat.core.util.tree.Visitor) CourseEditorTreeNode(org.olat.course.tree.CourseEditorTreeNode) ArrayList(java.util.ArrayList) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) CourseNode(org.olat.course.nodes.CourseNode) ProjectBrokerCourseNode(org.olat.course.nodes.ProjectBrokerCourseNode) STCourseNode(org.olat.course.nodes.STCourseNode) ScormCourseNode(org.olat.course.nodes.ScormCourseNode)

Aggregations

CourseEditorTreeNode (org.olat.course.tree.CourseEditorTreeNode)88 CourseNode (org.olat.course.nodes.CourseNode)54 ICourse (org.olat.course.ICourse)38 CourseEditorTreeModel (org.olat.course.tree.CourseEditorTreeModel)24 INode (org.olat.core.util.nodes.INode)22 Test (org.junit.Test)20 RepositoryEntry (org.olat.repository.RepositoryEntry)18 Identity (org.olat.core.id.Identity)14 TreeVisitor (org.olat.core.util.tree.TreeVisitor)14 Visitor (org.olat.core.util.tree.Visitor)14 CourseNodeVO (org.olat.restapi.support.vo.CourseNodeVO)12 TreeNode (org.olat.core.gui.components.tree.TreeNode)10 STCourseNode (org.olat.course.nodes.STCourseNode)10 ArrayList (java.util.ArrayList)9 File (java.io.File)8 URI (java.net.URI)8 HttpResponse (org.apache.http.HttpResponse)8 HttpPut (org.apache.http.client.methods.HttpPut)8 Structure (org.olat.course.Structure)8 BCCourseNode (org.olat.course.nodes.BCCourseNode)8