Search in sources :

Example 21 with CheckboxList

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

the class CheckListExcelExport method writeHeaders.

private void writeHeaders(OpenXMLWorksheet exportSheet, OpenXMLWorkbook workbook) {
    CellStyle headerStyle = workbook.getStyles().getHeaderStyle();
    // second header
    // reset column counter
    int col = 0;
    Row header2Row = exportSheet.newRow();
    String sequentialNumber = translator.translate("column.header.seqnum");
    header2Row.addCell(col++, sequentialNumber, headerStyle);
    for (UserPropertyHandler userPropertyHandler : userPropertyHandlers) {
        if (userPropertyHandler == null) {
            continue;
        }
        String header = translator.translate(userPropertyHandler.i18nFormElementLabelKey());
        header2Row.addCell(col++, header, headerStyle);
    }
    // add other user and session information
    header2Row.addCell(col++, translator.translate("column.header.homepage"), headerStyle);
    // course node points and passed
    if (courseNode.hasScoreConfigured()) {
        header2Row.addCell(col++, translator.translate("column.header.node.points"), headerStyle);
    }
    if (courseNode.hasPassedConfigured()) {
        header2Row.addCell(col++, translator.translate("column.header.node.passed"), headerStyle);
    }
    ModuleConfiguration config = courseNode.getModuleConfiguration();
    CheckboxList list = (CheckboxList) config.get(CheckListCourseNode.CONFIG_KEY_CHECKBOX);
    if (list != null && list.getList() != null) {
        List<Checkbox> checkboxList = list.getList();
        for (Checkbox checkbox : checkboxList) {
            String boxTitle = checkbox.getTitle();
            header2Row.addCell(col++, boxTitle, headerStyle);
            if (courseNode.hasScoreConfigured() && checkbox.getPoints() != null) {
                header2Row.addCell(col++, translator.translate("column.header.points"), headerStyle);
            }
        }
    }
}
Also used : CheckboxList(org.olat.course.nodes.cl.model.CheckboxList) ModuleConfiguration(org.olat.modules.ModuleConfiguration) Checkbox(org.olat.course.nodes.cl.model.Checkbox) CellStyle(org.olat.core.util.openxml.workbookstyle.CellStyle) Row(org.olat.core.util.openxml.OpenXMLWorksheet.Row) UserPropertyHandler(org.olat.user.propertyhandlers.UserPropertyHandler)

Example 22 with CheckboxList

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

the class CheckListCourseNode method archiveNodeData.

/**
 * Make an archive of all datas.
 */
@Override
public boolean archiveNodeData(Locale locale, ICourse course, ArchiveOptions options, ZipOutputStream exportStream, String charset) {
    String dirName = "cl_" + StringHelper.transformDisplayNameToFileSystemName(getShortName()) + "_" + Formatter.formatDatetimeFilesystemSave(new Date(System.currentTimeMillis()));
    ModuleConfiguration config = getModuleConfiguration();
    CheckboxList list = (CheckboxList) config.get(CONFIG_KEY_CHECKBOX);
    CheckboxManager checkboxManager = CoreSpringFactory.getImpl(CheckboxManager.class);
    if (list != null && list.getList() != null) {
        Set<String> usedNames = new HashSet<>();
        for (Checkbox checkbox : list.getList()) {
            VFSContainer dir = checkboxManager.getFileContainer(course.getCourseEnvironment(), this);
            if (dir != null) {
                VFSItem item = dir.resolve(checkbox.getFilename());
                if (item instanceof VFSLeaf) {
                    String path = dirName + "/" + Formatter.makeStringFilesystemSave(checkbox.getTitle());
                    if (usedNames.contains(checkbox.getTitle())) {
                        path += "_" + checkbox.getCheckboxId();
                    } else {
                        usedNames.add(checkbox.getTitle());
                    }
                    ZipUtil.addToZip(item, path, exportStream);
                }
            }
        }
    }
    String filename = dirName + "/" + StringHelper.transformDisplayNameToFileSystemName(getShortName());
    new CheckListExcelExport(this, course, locale).exportAll(filename, exportStream);
    // assessment documents
    if (hasIndividualAsssessmentDocuments()) {
        List<AssessmentEntry> assessmentEntries = course.getCourseEnvironment().getAssessmentManager().getAssessmentEntries(this);
        if (assessmentEntries != null && !assessmentEntries.isEmpty()) {
            String assessmentDirName = dirName + "/Assessment_documents";
            for (AssessmentEntry assessmentEntry : assessmentEntries) {
                Identity assessedIdentity = assessmentEntry.getIdentity();
                List<File> assessmentDocuments = course.getCourseEnvironment().getAssessmentManager().getIndividualAssessmentDocuments(this, assessedIdentity);
                String name = assessedIdentity.getUser().getLastName() + "_" + assessedIdentity.getUser().getFirstName() + "_" + assessedIdentity.getName();
                String userDirName = assessmentDirName + "/" + StringHelper.transformDisplayNameToFileSystemName(name);
                if (assessmentDocuments != null && !assessmentDocuments.isEmpty()) {
                    for (File document : assessmentDocuments) {
                        String path = userDirName + "/" + document.getName();
                        ZipUtil.addFileToZip(path, document, exportStream);
                    }
                }
            }
        }
    }
    return super.archiveNodeData(locale, course, options, exportStream, charset);
}
Also used : CheckboxList(org.olat.course.nodes.cl.model.CheckboxList) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) ModuleConfiguration(org.olat.modules.ModuleConfiguration) VFSContainer(org.olat.core.util.vfs.VFSContainer) CheckListExcelExport(org.olat.course.nodes.cl.ui.CheckListExcelExport) VFSItem(org.olat.core.util.vfs.VFSItem) AssessmentEntry(org.olat.modules.assessment.AssessmentEntry) Date(java.util.Date) CheckboxManager(org.olat.course.nodes.cl.CheckboxManager) Checkbox(org.olat.course.nodes.cl.model.Checkbox) Identity(org.olat.core.id.Identity) File(java.io.File) HashSet(java.util.HashSet)

Example 23 with CheckboxList

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

the class CheckListCourseNode method doUpdateAssessmentBySum.

private void doUpdateAssessmentBySum(Identity identity, UserCourseEnvironment assessedUserCourseEnv, Identity assessedIdentity, Role by) {
    OLATResourceable courseOres = OresHelper.createOLATResourceableInstance("CourseModule", assessedUserCourseEnv.getCourseEnvironment().getCourseResourceableId());
    ModuleConfiguration config = getModuleConfiguration();
    CheckboxManager checkboxManager = CoreSpringFactory.getImpl(CheckboxManager.class);
    int checkedBox = checkboxManager.countChecked(assessedIdentity, courseOres, getIdent());
    CheckboxList checkboxList = (CheckboxList) config.get(CONFIG_KEY_CHECKBOX);
    Integer cut = (Integer) config.get(CheckListCourseNode.CONFIG_KEY_PASSED_SUM_CUTVALUE);
    int minNumOfCheckbox = cut == null ? checkboxList.getNumOfCheckbox() : cut.intValue();
    boolean passed = checkedBox >= minNumOfCheckbox;
    Float score = null;
    if (passed) {
        Boolean scoreGrantedBool = (Boolean) config.get(MSCourseNode.CONFIG_KEY_HAS_SCORE_FIELD);
        if (scoreGrantedBool != null && scoreGrantedBool.booleanValue()) {
            score = checkboxManager.calculateScore(assessedIdentity, courseOres, getIdent());
            Float maxScore = (Float) config.get(MSCourseNode.CONFIG_KEY_SCORE_MAX);
            if (maxScore != null && maxScore.floatValue() < score) {
                score = maxScore.floatValue();
            }
        }
    }
    ScoreEvaluation sceval = new ScoreEvaluation(score, new Boolean(passed));
    AssessmentManager am = assessedUserCourseEnv.getCourseEnvironment().getAssessmentManager();
    am.saveScoreEvaluation(this, identity, assessedIdentity, sceval, assessedUserCourseEnv, false, by);
}
Also used : CheckboxManager(org.olat.course.nodes.cl.CheckboxManager) CheckboxList(org.olat.course.nodes.cl.model.CheckboxList) ScoreEvaluation(org.olat.course.run.scoring.ScoreEvaluation) ModuleConfiguration(org.olat.modules.ModuleConfiguration) OLATResourceable(org.olat.core.id.OLATResourceable) AssessmentManager(org.olat.course.assessment.AssessmentManager)

Example 24 with CheckboxList

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

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 CheckboxList

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

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)

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