Search in sources :

Example 21 with Checkbox

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

the class CheckedPDFExport method create.

public void create(CheckboxList checkboxList, List<CheckListAssessmentRow> rows) throws IOException, COSVisitorException, TransformerException {
    addMetadata(courseNodeTitle, courseTitle, author);
    int i = 0;
    for (Checkbox checkbox : checkboxList.getList()) {
        create(checkbox, i++, rows);
    }
    addPageNumbers();
}
Also used : Checkbox(org.olat.course.nodes.cl.model.Checkbox)

Example 22 with Checkbox

use of org.olat.course.nodes.cl.model.Checkbox 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 23 with Checkbox

use of org.olat.course.nodes.cl.model.Checkbox 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 24 with Checkbox

use of org.olat.course.nodes.cl.model.Checkbox 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 25 with Checkbox

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

the class CheckboxManagerTest method syncCheckBox.

@Test
public void syncCheckBox() {
    // build a list of checkbox to sync
    CheckboxList list = new CheckboxList();
    Checkbox checkbox1 = new Checkbox();
    checkbox1.setCheckboxId(UUID.randomUUID().toString());
    checkbox1.setTitle("Sync me");
    list.add(checkbox1);
    Checkbox checkbox2 = new Checkbox();
    checkbox2.setCheckboxId(UUID.randomUUID().toString());
    checkbox2.setTitle("Sync me too");
    list.add(checkbox2);
    // sync them to the database
    OLATResourceable ores = OresHelper.createOLATResourceableInstance("checkbox-4", 2348l);
    String resSubPath = UUID.randomUUID().toString();
    checkboxManager.syncCheckbox(list, ores, resSubPath);
    dbInstance.commitAndCloseSession();
    // load them
    List<DBCheckbox> dbCheckboxList = checkboxManager.loadCheckbox(ores, resSubPath);
    Assert.assertNotNull(dbCheckboxList);
    Assert.assertEquals(2, dbCheckboxList.size());
    for (DBCheckbox dbCheckbox : dbCheckboxList) {
        Assert.assertNotNull(dbCheckbox);
        Assert.assertNotNull(dbCheckbox.getKey());
        Assert.assertNotNull(dbCheckbox.getCheckboxId());
        Assert.assertTrue(dbCheckbox.getCheckboxId().equals(checkbox1.getCheckboxId()) || dbCheckbox.getCheckboxId().equals(checkbox2.getCheckboxId()));
    }
}
Also used : CheckboxList(org.olat.course.nodes.cl.model.CheckboxList) OLATResourceable(org.olat.core.id.OLATResourceable) Checkbox(org.olat.course.nodes.cl.model.Checkbox) DBCheckbox(org.olat.course.nodes.cl.model.DBCheckbox) DBCheckbox(org.olat.course.nodes.cl.model.DBCheckbox) Test(org.junit.Test)

Aggregations

Checkbox (org.olat.course.nodes.cl.model.Checkbox)58 CheckboxList (org.olat.course.nodes.cl.model.CheckboxList)24 ArrayList (java.util.ArrayList)16 CheckboxManager (org.olat.course.nodes.cl.CheckboxManager)14 ModuleConfiguration (org.olat.modules.ModuleConfiguration)14 File (java.io.File)12 HashMap (java.util.HashMap)12 DBCheckbox (org.olat.course.nodes.cl.model.DBCheckbox)12 Identity (org.olat.core.id.Identity)10 HashSet (java.util.HashSet)8 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)8 ICourse (org.olat.course.ICourse)8 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)8 MultipleSelectionElement (org.olat.core.gui.components.form.flexible.elements.MultipleSelectionElement)6 VFSContainer (org.olat.core.util.vfs.VFSContainer)6 VFSItem (org.olat.core.util.vfs.VFSItem)6 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)6 DBCheck (org.olat.course.nodes.cl.model.DBCheck)6 Date (java.util.Date)4 DefaultFlexiColumnModel (org.olat.core.gui.components.form.flexible.impl.elements.table.DefaultFlexiColumnModel)4