Search in sources :

Example 16 with CheckboxList

use of org.olat.course.nodes.cl.model.CheckboxList 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)

Example 17 with CheckboxList

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

the class CheckListBoxListEditController method doEdit.

private void doEdit(UserRequest ureq, Checkbox checkbox) {
    CheckboxList list = (CheckboxList) config.get(CheckListCourseNode.CONFIG_KEY_CHECKBOX);
    if (list == null) {
        list = new CheckboxList();
    }
    list.add(checkbox);
    config.set(CheckListCourseNode.CONFIG_KEY_CHECKBOX, list);
    fireEvent(ureq, Event.DONE_EVENT);
    updateModel();
}
Also used : CheckboxList(org.olat.course.nodes.cl.model.CheckboxList)

Example 18 with CheckboxList

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

the class CheckListBoxListEditController method updateModel.

private void updateModel() {
    CheckboxList list = (CheckboxList) config.get(CheckListCourseNode.CONFIG_KEY_CHECKBOX);
    List<CheckboxConfigRow> boxList = new ArrayList<CheckboxConfigRow>();
    if (list != null && list.getList() != null) {
        for (Checkbox checkbox : list.getList()) {
            DownloadLink download = null;
            VFSContainer container = checkboxManager.getFileContainer(courseEnv, courseNode);
            if (container != null) {
                VFSItem item = container.resolve(checkbox.getFilename());
                if (item instanceof VFSLeaf) {
                    download = uifactory.addDownloadLink("file_" + checkbox.getCheckboxId(), checkbox.getFilename(), null, (VFSLeaf) item, boxTable);
                }
            }
            boxList.add(new CheckboxConfigRow(checkbox, download));
        }
    }
    model.setObjects(boxList);
    boxTable.reset();
}
Also used : DownloadLink(org.olat.core.gui.components.form.flexible.elements.DownloadLink) CheckboxList(org.olat.course.nodes.cl.model.CheckboxList) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) Checkbox(org.olat.course.nodes.cl.model.Checkbox) VFSContainer(org.olat.core.util.vfs.VFSContainer) ArrayList(java.util.ArrayList) VFSItem(org.olat.core.util.vfs.VFSItem)

Example 19 with CheckboxList

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

the class CheckListConfigurationController method getAvailableSumCutValues.

private String[] getAvailableSumCutValues() {
    int currentNumOfCheckbox;
    if (data == null) {
        CheckboxList list = (CheckboxList) config.get(CheckListCourseNode.CONFIG_KEY_CHECKBOX);
        currentNumOfCheckbox = list == null ? 0 : list.getNumOfCheckbox();
    } else {
        currentNumOfCheckbox = data.getNumOfCheckbox();
    }
    String[] numKeys = new String[currentNumOfCheckbox + 1];
    for (int i = 0; i <= currentNumOfCheckbox; i++) {
        numKeys[i] = Integer.toString(i);
    }
    return numKeys;
}
Also used : CheckboxList(org.olat.course.nodes.cl.model.CheckboxList)

Example 20 with CheckboxList

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

the class CheckListExcelExport method writeDataRow.

private void writeDataRow(AssessmentData data, AssessmentEntry entry, int num, OpenXMLWorksheet exportSheet) {
    int col = 0;
    Identity assessedIdentity = data.getIdentity();
    User assessedUser = assessedIdentity.getUser();
    Row dataRow = exportSheet.newRow();
    // sequence number
    dataRow.addCell(col++, num, null);
    for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
        if (userPropertyHandler != null) {
            String property = userPropertyHandler.getUserProperty(assessedUser, translator.getLocale());
            dataRow.addCell(col++, property, null);
        }
    }
    // homepage
    ContextEntry ce = BusinessControlFactory.getInstance().createContextEntry(assessedIdentity);
    String homepage = BusinessControlFactory.getInstance().getAsURIString(Collections.singletonList(ce), false);
    dataRow.addCell(col++, homepage, null);
    // course node points and passed
    if (courseNode.hasScoreConfigured()) {
        if (entry != null && entry.getScore() != null) {
            dataRow.addCell(col++, entry.getScore(), null);
        } else {
            col++;
        }
    }
    if (courseNode.hasPassedConfigured()) {
        if (entry != null && entry.getPassed() != null) {
            dataRow.addCell(col++, entry.getPassed().toString(), null);
        } else {
            col++;
        }
    }
    ModuleConfiguration config = courseNode.getModuleConfiguration();
    CheckboxList list = (CheckboxList) config.get(CheckListCourseNode.CONFIG_KEY_CHECKBOX);
    if (list != null && list.getList() != null && data.getChecks() != null) {
        Map<String, DBCheck> checkMap = data.getChecks().stream().collect(Collectors.toMap(c -> c.getCheckbox().getCheckboxId(), c -> c));
        List<Checkbox> checkboxList = list.getList();
        for (Checkbox checkbox : checkboxList) {
            String boxId = checkbox.getCheckboxId();
            DBCheck check = checkMap.get(boxId);
            if (check != null && check.getChecked() != null && check.getChecked().booleanValue()) {
                dataRow.addCell(col++, "x", null);
            } else {
                col++;
            }
            if (courseNode.hasScoreConfigured() && checkbox.getPoints() != null) {
                if (check != null && check.getScore() != null) {
                    dataRow.addCell(col++, check.getScore(), null);
                } else {
                    col++;
                }
            }
        }
    }
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) Util(org.olat.core.util.Util) OpenXMLWorksheet(org.olat.core.util.openxml.OpenXMLWorksheet) CoreSpringFactory(org.olat.core.CoreSpringFactory) HashMap(java.util.HashMap) DBCheck(org.olat.course.nodes.cl.model.DBCheck) OpenXMLWorkbook(org.olat.core.util.openxml.OpenXMLWorkbook) ModuleConfiguration(org.olat.modules.ModuleConfiguration) AssessmentEntry(org.olat.modules.assessment.AssessmentEntry) ContextEntry(org.olat.core.id.context.ContextEntry) CheckboxList(org.olat.course.nodes.cl.model.CheckboxList) Locale(java.util.Locale) Map(java.util.Map) AssessmentData(org.olat.course.nodes.cl.model.AssessmentData) ZipEntry(java.util.zip.ZipEntry) OLog(org.olat.core.logging.OLog) ICourse(org.olat.course.ICourse) OutputStream(java.io.OutputStream) Translator(org.olat.core.gui.translator.Translator) CellStyle(org.olat.core.util.openxml.workbookstyle.CellStyle) CheckListCourseNode(org.olat.course.nodes.CheckListCourseNode) Checkbox(org.olat.course.nodes.cl.model.Checkbox) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler) CheckboxManager(org.olat.course.nodes.cl.CheckboxManager) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ShieldOutputStream(org.olat.core.util.io.ShieldOutputStream) BusinessControlFactory(org.olat.core.id.context.BusinessControlFactory) UserManager(org.olat.user.UserManager) List(java.util.List) User(org.olat.core.id.User) Identity(org.olat.core.id.Identity) Row(org.olat.core.util.openxml.OpenXMLWorksheet.Row) Collections(java.util.Collections) Tracing(org.olat.core.logging.Tracing) CheckboxList(org.olat.course.nodes.cl.model.CheckboxList) DBCheck(org.olat.course.nodes.cl.model.DBCheck) User(org.olat.core.id.User) ModuleConfiguration(org.olat.modules.ModuleConfiguration) ContextEntry(org.olat.core.id.context.ContextEntry) Checkbox(org.olat.course.nodes.cl.model.Checkbox) Row(org.olat.core.util.openxml.OpenXMLWorksheet.Row) Identity(org.olat.core.id.Identity) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Aggregations

CheckboxList (org.olat.course.nodes.cl.model.CheckboxList)34 Checkbox (org.olat.course.nodes.cl.model.Checkbox)24 CheckboxManager (org.olat.course.nodes.cl.CheckboxManager)18 ModuleConfiguration (org.olat.modules.ModuleConfiguration)18 File (java.io.File)12 Identity (org.olat.core.id.Identity)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 ArrayList (java.util.ArrayList)4 OLATResourceable (org.olat.core.id.OLATResourceable)4 Row (org.olat.core.util.openxml.OpenXMLWorksheet.Row)4 CellStyle (org.olat.core.util.openxml.workbookstyle.CellStyle)4 ICourse (org.olat.course.ICourse)4 CheckListCourseNode (org.olat.course.nodes.CheckListCourseNode)4 AssessmentEntry (org.olat.modules.assessment.AssessmentEntry)4 UserPropertyHandler (org.olat.user.propertyhandlers.UserPropertyHandler)4 IOException (java.io.IOException)2 OutputStream (java.io.OutputStream)2 Collections (java.util.Collections)2