Search in sources :

Example 1 with QTIExportFormatterCSVType3

use of org.olat.ims.qti.export.QTIExportFormatterCSVType3 in project OpenOLAT by OpenOLAT.

the class IQEditReplaceWizard method doStep2.

private void doStep2(UserRequest ureq) {
    String nodeTitle = courseNode.getShortTitle();
    if (results != null && !results.isEmpty()) {
        exportDir = CourseFactory.getOrCreateDataExportDirectory(ureq.getIdentity(), course.getCourseTitle());
        UserManager um = UserManager.getInstance();
        String charset = um.getUserCharset(ureq.getIdentity());
        QTIExportManager qem = QTIExportManager.getInstance();
        Long repositoryRef = results.get(0).getResultSet().getRepositoryRef();
        List<QTIItemObject> qtiItemObjectList = new QTIObjectTreeBuilder().getQTIItemObjectList(repositoryRef);
        QTIExportFormatter formatter;
        if (courseNode instanceof IQTESTCourseNode) {
            formatter = new QTIExportFormatterCSVType1(ureq.getLocale(), "\t", "\"", "\r\n", false);
        } else if (courseNode instanceof IQSELFCourseNode) {
            formatter = new QTIExportFormatterCSVType1(ureq.getLocale(), "\t", "\"", "\r\n", false);
            ((QTIExportFormatterCSVType1) formatter).setAnonymous(true);
        } else {
            formatter = new QTIExportFormatterCSVType3(ureq.getLocale(), null, "\t", "\"", "\r\n", false);
        }
        Map<Class<?>, QTIExportItemFormatConfig> qtiItemConfigs = getQTIItemConfigs(qtiItemObjectList);
        formatter.setMapWithExportItemConfigs(qtiItemConfigs);
        resultExportFile = qem.exportResults(formatter, results, qtiItemObjectList, courseNode.getShortTitle(), exportDir, charset, ".xls");
        vcStep2 = createVelocityContainer("replacewizard_step2");
        String[] args1 = new String[] { Integer.toString(learners.size()) };
        vcStep2.contextPut("information", translate("replace.wizard.information.paragraph1", args1));
        String[] args2 = new String[] { exportDir.getName(), resultExportFile };
        vcStep2.contextPut("information_par2", translate("replace.wizard.information.paragraph2", args2));
        vcStep2.contextPut("nodetitle", nodeTitle);
        showFileButton = LinkFactory.createButton("replace.wizard.showfile", vcStep2, this);
    } else {
        // it exists no result
        String[] args = new String[] { Integer.toString(numberOfQtiSerEntries) };
        vcStep2 = createVelocityContainer("replacewizard_step2");
        vcStep2.contextPut("information", translate("replace.wizard.information.empty.results", args));
        vcStep2.contextPut("nodetitle", nodeTitle);
    }
    nextBtn = LinkFactory.createButton("replace.wizard.next", vcStep2, this);
    setNextWizardStep(translate("replace.wizard.title.step2"), vcStep2);
}
Also used : QTIExportFormatterCSVType1(org.olat.ims.qti.export.QTIExportFormatterCSVType1) QTIExportFormatterCSVType3(org.olat.ims.qti.export.QTIExportFormatterCSVType3) QTIExportFormatter(org.olat.ims.qti.export.QTIExportFormatter) IQTESTCourseNode(org.olat.course.nodes.IQTESTCourseNode) QTIItemObject(org.olat.ims.qti.export.helper.QTIItemObject) UserManager(org.olat.user.UserManager) QTIExportManager(org.olat.ims.qti.export.QTIExportManager) QTIObjectTreeBuilder(org.olat.ims.qti.export.helper.QTIObjectTreeBuilder) IQSELFCourseNode(org.olat.course.nodes.IQSELFCourseNode) QTIExportItemFormatConfig(org.olat.ims.qti.export.QTIExportItemFormatConfig)

Example 2 with QTIExportFormatterCSVType3

use of org.olat.ims.qti.export.QTIExportFormatterCSVType3 in project openolat by klemens.

the class QTIStatisticsResource method prepare.

@Override
public void prepare(HttpServletResponse hres) {
    try {
        hres.setCharacterEncoding(encoding);
    } catch (Exception e) {
        log.error("", e);
    }
    CourseNode courseNode = resourceResult.getTestCourseNode();
    String label = courseNode.getType() + "_" + StringHelper.transformDisplayNameToFileSystemName(courseNode.getShortName()) + "_" + Formatter.formatDatetimeFilesystemSave(new Date(System.currentTimeMillis())) + ".csv";
    String urlEncodedLabel = StringHelper.urlEncodeUTF8(label);
    hres.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + urlEncodedLabel);
    hres.setHeader("Content-Description", urlEncodedLabel);
    try {
        // fields separated by
        String sep = "\\t";
        // fields embedded by
        String emb = "\"";
        // carriage return
        String car = "\\r\\n";
        sep = QTIArchiver.convert2CtrlChars(sep);
        car = QTIArchiver.convert2CtrlChars(car);
        int exportType = 1;
        QTIExportFormatter formatter;
        if (QTIType.test.equals(resourceResult.getType())) {
            exportType = 1;
            formatter = new QTIExportFormatterCSVType1(locale, sep, emb, car, true);
        } else if (QTIType.survey.equals(resourceResult.getType())) {
            exportType = 2;
            formatter = new QTIExportFormatterCSVType3(locale, null, sep, emb, car, true);
        } else {
            return;
        }
        Long qtiRepoEntryKey = resourceResult.getQTIRepositoryEntry().getKey();
        List<QTIItemObject> itemList = new QTIObjectTreeBuilder().getQTIItemObjectList(resourceResult.getResolver());
        formatter.setMapWithExportItemConfigs(getQTIItemConfigs(itemList));
        QTIResultManager qrm = QTIResultManager.getInstance();
        QTIStatisticSearchParams params = resourceResult.getSearchParams();
        List<Group> limitToGroups = params.isMayViewAllUsersAssessments() ? null : params.getLimitToGroups();
        List<QTIResult> results = qrm.selectResults(resourceResult.getCourseOres().getResourceableId(), courseNode.getIdent(), qtiRepoEntryKey, limitToGroups, exportType);
        QTIExportManager.getInstance().exportResults(formatter, results, itemList, hres.getOutputStream());
    } catch (Exception e) {
        log.error("", e);
    }
}
Also used : QTIResult(org.olat.ims.qti.QTIResult) Group(org.olat.basesecurity.Group) QTIResultManager(org.olat.ims.qti.QTIResultManager) QTIExportFormatterCSVType1(org.olat.ims.qti.export.QTIExportFormatterCSVType1) QTIExportFormatterCSVType3(org.olat.ims.qti.export.QTIExportFormatterCSVType3) QTIExportFormatter(org.olat.ims.qti.export.QTIExportFormatter) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) Date(java.util.Date) QTIItemObject(org.olat.ims.qti.export.helper.QTIItemObject) QTIObjectTreeBuilder(org.olat.ims.qti.export.helper.QTIObjectTreeBuilder) CourseNode(org.olat.course.nodes.CourseNode)

Example 3 with QTIExportFormatterCSVType3

use of org.olat.ims.qti.export.QTIExportFormatterCSVType3 in project OpenOLAT by OpenOLAT.

the class QTIStatisticsResource method prepare.

@Override
public void prepare(HttpServletResponse hres) {
    try {
        hres.setCharacterEncoding(encoding);
    } catch (Exception e) {
        log.error("", e);
    }
    CourseNode courseNode = resourceResult.getTestCourseNode();
    String label = courseNode.getType() + "_" + StringHelper.transformDisplayNameToFileSystemName(courseNode.getShortName()) + "_" + Formatter.formatDatetimeFilesystemSave(new Date(System.currentTimeMillis())) + ".csv";
    String urlEncodedLabel = StringHelper.urlEncodeUTF8(label);
    hres.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + urlEncodedLabel);
    hres.setHeader("Content-Description", urlEncodedLabel);
    try {
        // fields separated by
        String sep = "\\t";
        // fields embedded by
        String emb = "\"";
        // carriage return
        String car = "\\r\\n";
        sep = QTIArchiver.convert2CtrlChars(sep);
        car = QTIArchiver.convert2CtrlChars(car);
        int exportType = 1;
        QTIExportFormatter formatter;
        if (QTIType.test.equals(resourceResult.getType())) {
            exportType = 1;
            formatter = new QTIExportFormatterCSVType1(locale, sep, emb, car, true);
        } else if (QTIType.survey.equals(resourceResult.getType())) {
            exportType = 2;
            formatter = new QTIExportFormatterCSVType3(locale, null, sep, emb, car, true);
        } else {
            return;
        }
        Long qtiRepoEntryKey = resourceResult.getQTIRepositoryEntry().getKey();
        List<QTIItemObject> itemList = new QTIObjectTreeBuilder().getQTIItemObjectList(resourceResult.getResolver());
        formatter.setMapWithExportItemConfigs(getQTIItemConfigs(itemList));
        QTIResultManager qrm = QTIResultManager.getInstance();
        QTIStatisticSearchParams params = resourceResult.getSearchParams();
        List<Group> limitToGroups = params.isMayViewAllUsersAssessments() ? null : params.getLimitToGroups();
        List<QTIResult> results = qrm.selectResults(resourceResult.getCourseOres().getResourceableId(), courseNode.getIdent(), qtiRepoEntryKey, limitToGroups, exportType);
        QTIExportManager.getInstance().exportResults(formatter, results, itemList, hres.getOutputStream());
    } catch (Exception e) {
        log.error("", e);
    }
}
Also used : QTIResult(org.olat.ims.qti.QTIResult) Group(org.olat.basesecurity.Group) QTIResultManager(org.olat.ims.qti.QTIResultManager) QTIExportFormatterCSVType1(org.olat.ims.qti.export.QTIExportFormatterCSVType1) QTIExportFormatterCSVType3(org.olat.ims.qti.export.QTIExportFormatterCSVType3) QTIExportFormatter(org.olat.ims.qti.export.QTIExportFormatter) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) Date(java.util.Date) QTIItemObject(org.olat.ims.qti.export.helper.QTIItemObject) QTIObjectTreeBuilder(org.olat.ims.qti.export.helper.QTIObjectTreeBuilder) CourseNode(org.olat.course.nodes.CourseNode)

Example 4 with QTIExportFormatterCSVType3

use of org.olat.ims.qti.export.QTIExportFormatterCSVType3 in project OpenOLAT by OpenOLAT.

the class IQSURVCourseNode method archiveNodeData.

@Override
public boolean archiveNodeData(Locale locale, ICourse course, ArchiveOptions options, ZipOutputStream exportStream, String charset) {
    QTIExportManager qem = QTIExportManager.getInstance();
    String repositorySoftKey = (String) getModuleConfiguration().get(IQEditController.CONFIG_KEY_REPOSITORY_SOFTKEY);
    RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntryBySoftkey(repositorySoftKey, true);
    QTIExportFormatter qef = new QTIExportFormatterCSVType3(locale, null, "\t", "\"", "\r\n", false);
    try {
        return qem.selectAndExportResults(qef, course.getResourceableId(), getShortTitle(), getIdent(), re, exportStream, locale, ".xls");
    } catch (IOException e) {
        log.error("", e);
        return false;
    }
}
Also used : QTIExportManager(org.olat.ims.qti.export.QTIExportManager) QTIExportFormatterCSVType3(org.olat.ims.qti.export.QTIExportFormatterCSVType3) RepositoryEntry(org.olat.repository.RepositoryEntry) IOException(java.io.IOException) QTIExportFormatter(org.olat.ims.qti.export.QTIExportFormatter)

Example 5 with QTIExportFormatterCSVType3

use of org.olat.ims.qti.export.QTIExportFormatterCSVType3 in project openolat by klemens.

the class IQEditReplaceWizard method doStep2.

private void doStep2(UserRequest ureq) {
    String nodeTitle = courseNode.getShortTitle();
    if (results != null && !results.isEmpty()) {
        exportDir = CourseFactory.getOrCreateDataExportDirectory(ureq.getIdentity(), course.getCourseTitle());
        UserManager um = UserManager.getInstance();
        String charset = um.getUserCharset(ureq.getIdentity());
        QTIExportManager qem = QTIExportManager.getInstance();
        Long repositoryRef = results.get(0).getResultSet().getRepositoryRef();
        List<QTIItemObject> qtiItemObjectList = new QTIObjectTreeBuilder().getQTIItemObjectList(repositoryRef);
        QTIExportFormatter formatter;
        if (courseNode instanceof IQTESTCourseNode) {
            formatter = new QTIExportFormatterCSVType1(ureq.getLocale(), "\t", "\"", "\r\n", false);
        } else if (courseNode instanceof IQSELFCourseNode) {
            formatter = new QTIExportFormatterCSVType1(ureq.getLocale(), "\t", "\"", "\r\n", false);
            ((QTIExportFormatterCSVType1) formatter).setAnonymous(true);
        } else {
            formatter = new QTIExportFormatterCSVType3(ureq.getLocale(), null, "\t", "\"", "\r\n", false);
        }
        Map<Class<?>, QTIExportItemFormatConfig> qtiItemConfigs = getQTIItemConfigs(qtiItemObjectList);
        formatter.setMapWithExportItemConfigs(qtiItemConfigs);
        resultExportFile = qem.exportResults(formatter, results, qtiItemObjectList, courseNode.getShortTitle(), exportDir, charset, ".xls");
        vcStep2 = createVelocityContainer("replacewizard_step2");
        String[] args1 = new String[] { Integer.toString(learners.size()) };
        vcStep2.contextPut("information", translate("replace.wizard.information.paragraph1", args1));
        String[] args2 = new String[] { exportDir.getName(), resultExportFile };
        vcStep2.contextPut("information_par2", translate("replace.wizard.information.paragraph2", args2));
        vcStep2.contextPut("nodetitle", nodeTitle);
        showFileButton = LinkFactory.createButton("replace.wizard.showfile", vcStep2, this);
    } else {
        // it exists no result
        String[] args = new String[] { Integer.toString(numberOfQtiSerEntries) };
        vcStep2 = createVelocityContainer("replacewizard_step2");
        vcStep2.contextPut("information", translate("replace.wizard.information.empty.results", args));
        vcStep2.contextPut("nodetitle", nodeTitle);
    }
    nextBtn = LinkFactory.createButton("replace.wizard.next", vcStep2, this);
    setNextWizardStep(translate("replace.wizard.title.step2"), vcStep2);
}
Also used : QTIExportFormatterCSVType1(org.olat.ims.qti.export.QTIExportFormatterCSVType1) QTIExportFormatterCSVType3(org.olat.ims.qti.export.QTIExportFormatterCSVType3) QTIExportFormatter(org.olat.ims.qti.export.QTIExportFormatter) IQTESTCourseNode(org.olat.course.nodes.IQTESTCourseNode) QTIItemObject(org.olat.ims.qti.export.helper.QTIItemObject) UserManager(org.olat.user.UserManager) QTIExportManager(org.olat.ims.qti.export.QTIExportManager) QTIObjectTreeBuilder(org.olat.ims.qti.export.helper.QTIObjectTreeBuilder) IQSELFCourseNode(org.olat.course.nodes.IQSELFCourseNode) QTIExportItemFormatConfig(org.olat.ims.qti.export.QTIExportItemFormatConfig)

Aggregations

QTIExportFormatter (org.olat.ims.qti.export.QTIExportFormatter)6 QTIExportFormatterCSVType3 (org.olat.ims.qti.export.QTIExportFormatterCSVType3)6 QTIExportFormatterCSVType1 (org.olat.ims.qti.export.QTIExportFormatterCSVType1)4 QTIExportManager (org.olat.ims.qti.export.QTIExportManager)4 QTIItemObject (org.olat.ims.qti.export.helper.QTIItemObject)4 QTIObjectTreeBuilder (org.olat.ims.qti.export.helper.QTIObjectTreeBuilder)4 IOException (java.io.IOException)2 Date (java.util.Date)2 Group (org.olat.basesecurity.Group)2 OLATRuntimeException (org.olat.core.logging.OLATRuntimeException)2 CourseNode (org.olat.course.nodes.CourseNode)2 IQSELFCourseNode (org.olat.course.nodes.IQSELFCourseNode)2 IQTESTCourseNode (org.olat.course.nodes.IQTESTCourseNode)2 QTIResult (org.olat.ims.qti.QTIResult)2 QTIResultManager (org.olat.ims.qti.QTIResultManager)2 QTIExportItemFormatConfig (org.olat.ims.qti.export.QTIExportItemFormatConfig)2 RepositoryEntry (org.olat.repository.RepositoryEntry)2 UserManager (org.olat.user.UserManager)2