Search in sources :

Example 6 with CheckboxManager

use of org.olat.course.nodes.cl.CheckboxManager in project openolat by klemens.

the class CheckListCourseNode method createInstanceForCopy.

@Override
public CourseNode createInstanceForCopy(boolean isNewTitle, ICourse course, Identity author) {
    CheckListCourseNode cNode = (CheckListCourseNode) super.createInstanceForCopy(isNewTitle, course, author);
    CheckboxManager checkboxManager = CoreSpringFactory.getImpl(CheckboxManager.class);
    CheckboxList list = (CheckboxList) cNode.getModuleConfiguration().get(CONFIG_KEY_CHECKBOX);
    if (list != null) {
        for (Checkbox checkbox : list.getList()) {
            checkbox.setCheckboxId(UUID.randomUUID().toString());
        }
    }
    // the ident of the course node is the same
    File sourceDir = checkboxManager.getFileDirectory(course.getCourseEnvironment(), this);
    if (sourceDir.exists()) {
        File targetDir = checkboxManager.getFileDirectory(course.getCourseEnvironment(), cNode);
        if (!targetDir.exists()) {
            targetDir.mkdirs();
            FileUtils.copyDirContentsToDir(sourceDir, targetDir, false, "copy files of checkbox");
        }
    }
    return cNode;
}
Also used : CheckboxManager(org.olat.course.nodes.cl.CheckboxManager) CheckboxList(org.olat.course.nodes.cl.model.CheckboxList) Checkbox(org.olat.course.nodes.cl.model.Checkbox) File(java.io.File)

Example 7 with CheckboxManager

use of org.olat.course.nodes.cl.CheckboxManager in project openolat by klemens.

the class CheckListCourseNode method importNode.

@Override
public void importNode(File importDirectory, ICourse course, Identity owner, Locale locale, boolean withReferences) {
    CheckboxManager checkboxManager = CoreSpringFactory.getImpl(CheckboxManager.class);
    ModuleConfiguration config = getModuleConfiguration();
    CheckboxList list = (CheckboxList) config.get(CONFIG_KEY_CHECKBOX);
    if (list != null && list.getList() != null) {
        for (Checkbox checkbox : list.getList()) {
            File fFileImportDir = new File(importDirectory, "checklistfiles/" + getIdent() + "/" + checkbox.getCheckboxId());
            String newCheckboxId = UUID.randomUUID().toString();
            checkbox.setCheckboxId(newCheckboxId);
            if (fFileImportDir.exists()) {
                File dir = checkboxManager.getFileDirectory(course.getCourseEnvironment(), this);
                dir.mkdirs();
                FileUtils.copyDirContentsToDir(fFileImportDir, dir, false, "import file of checkbox");
            }
        }
    }
}
Also used : CheckboxManager(org.olat.course.nodes.cl.CheckboxManager) CheckboxList(org.olat.course.nodes.cl.model.CheckboxList) ModuleConfiguration(org.olat.modules.ModuleConfiguration) Checkbox(org.olat.course.nodes.cl.model.Checkbox) File(java.io.File)

Example 8 with CheckboxManager

use of org.olat.course.nodes.cl.CheckboxManager in project openolat by klemens.

the class CheckListCourseNode method updateOnPublish.

@Override
public void updateOnPublish(Locale locale, ICourse course, Identity publisher, PublishEvents publishEvents) {
    ModuleConfiguration config = getModuleConfiguration();
    // sync the checkbox with the database
    CheckboxList list = (CheckboxList) config.get(CONFIG_KEY_CHECKBOX);
    CheckboxManager checkboxManager = CoreSpringFactory.getImpl(CheckboxManager.class);
    checkboxManager.syncCheckbox(list, course, getIdent());
    CoursePropertyManager pm = course.getCourseEnvironment().getCoursePropertyManager();
    List<Identity> assessedUsers = pm.getAllIdentitiesWithCourseAssessmentData(null);
    int count = 0;
    for (Identity assessedIdentity : assessedUsers) {
        updateScorePassedOnPublish(assessedIdentity, publisher, checkboxManager, course);
        if (++count % 10 == 0) {
            DBFactory.getInstance().commitAndCloseSession();
        }
    }
    DBFactory.getInstance().commitAndCloseSession();
    super.updateOnPublish(locale, course, publisher, publishEvents);
}
Also used : CheckboxManager(org.olat.course.nodes.cl.CheckboxManager) CheckboxList(org.olat.course.nodes.cl.model.CheckboxList) ModuleConfiguration(org.olat.modules.ModuleConfiguration) Identity(org.olat.core.id.Identity) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager)

Example 9 with CheckboxManager

use of org.olat.course.nodes.cl.CheckboxManager in project openolat by klemens.

the class CheckListCourseNode method postCopy.

@Override
public void postCopy(CourseEnvironmentMapper envMapper, Processing processType, ICourse course, ICourse sourceCourse) {
    ModuleConfiguration config = getModuleConfiguration();
    CheckboxManager checkboxManager = CoreSpringFactory.getImpl(CheckboxManager.class);
    CheckboxList list = (CheckboxList) config.get(CONFIG_KEY_CHECKBOX);
    if (list != null && list.getList().size() > 0) {
        for (Checkbox checkbox : list.getList()) {
            String sourceId = checkbox.getCheckboxId();
            String targetId = envMapper.getTargetUniqueKey(getIdent(), sourceId);
            if (targetId == null) {
                targetId = UUID.randomUUID().toString();
                envMapper.addUniqueKeyPair(getIdent(), sourceId, targetId);
            }
            checkbox.setCheckboxId(targetId);
        }
    }
    // the ident of the course node is the same
    File sourceDir = checkboxManager.getFileDirectory(sourceCourse.getCourseEnvironment(), this);
    if (sourceDir.exists()) {
        File targetDir = checkboxManager.getFileDirectory(course.getCourseEnvironment(), this);
        if (!targetDir.exists()) {
            targetDir.mkdirs();
            FileUtils.copyDirContentsToDir(sourceDir, targetDir, false, "copy files of checkbox");
        }
    }
    checkboxManager.syncCheckbox(list, course, getIdent());
    super.postCopy(envMapper, processType, course, sourceCourse);
}
Also used : CheckboxManager(org.olat.course.nodes.cl.CheckboxManager) CheckboxList(org.olat.course.nodes.cl.model.CheckboxList) ModuleConfiguration(org.olat.modules.ModuleConfiguration) Checkbox(org.olat.course.nodes.cl.model.Checkbox) File(java.io.File)

Example 10 with CheckboxManager

use of org.olat.course.nodes.cl.CheckboxManager in project OpenOLAT by OpenOLAT.

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)

Aggregations

CheckboxManager (org.olat.course.nodes.cl.CheckboxManager)20 CheckboxList (org.olat.course.nodes.cl.model.CheckboxList)16 ModuleConfiguration (org.olat.modules.ModuleConfiguration)14 File (java.io.File)12 Checkbox (org.olat.course.nodes.cl.model.Checkbox)12 OLATResourceable (org.olat.core.id.OLATResourceable)6 AssessmentManager (org.olat.course.assessment.AssessmentManager)6 ScoreEvaluation (org.olat.course.run.scoring.ScoreEvaluation)6 Identity (org.olat.core.id.Identity)4 VFSContainer (org.olat.core.util.vfs.VFSContainer)4 VFSItem (org.olat.core.util.vfs.VFSItem)4 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)4 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 HashSet (java.util.HashSet)2 LocalFolderImpl (org.olat.core.util.vfs.LocalFolderImpl)2 ICourse (org.olat.course.ICourse)2 CheckListCourseNode (org.olat.course.nodes.CheckListCourseNode)2 CourseNode (org.olat.course.nodes.CourseNode)2 STCourseNode (org.olat.course.nodes.STCourseNode)2