use of org.olat.ims.qti.export.helper.QTIItemObject 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);
}
use of org.olat.ims.qti.export.helper.QTIItemObject in project OpenOLAT by OpenOLAT.
the class QTIArchiver method getQTIItemConfigs.
public static Map<Class<?>, QTIExportItemFormatConfig> getQTIItemConfigs(List<QTIItemObject> itemList) {
Map<Class<?>, QTIExportItemFormatConfig> itConfigs = new HashMap<>();
for (Iterator<QTIItemObject> iter = itemList.iterator(); iter.hasNext(); ) {
QTIItemObject item = iter.next();
if (item.getItemIdent().startsWith(ItemParser.ITEM_PREFIX_SCQ)) {
if (itConfigs.get(QTIExportSCQItemFormatConfig.class) == null) {
QTIExportSCQItemFormatConfig confSCQ = new QTIExportSCQItemFormatConfig(true, false, false, false);
itConfigs.put(QTIExportSCQItemFormatConfig.class, confSCQ);
}
} else if (item.getItemIdent().startsWith(ItemParser.ITEM_PREFIX_MCQ)) {
if (itConfigs.get(QTIExportMCQItemFormatConfig.class) == null) {
QTIExportMCQItemFormatConfig confMCQ = new QTIExportMCQItemFormatConfig(true, false, false, false);
itConfigs.put(QTIExportMCQItemFormatConfig.class, confMCQ);
}
} else if (item.getItemIdent().startsWith(ItemParser.ITEM_PREFIX_KPRIM)) {
if (itConfigs.get(QTIExportKPRIMItemFormatConfig.class) == null) {
QTIExportKPRIMItemFormatConfig confKPRIM = new QTIExportKPRIMItemFormatConfig(true, false, false, false);
itConfigs.put(QTIExportKPRIMItemFormatConfig.class, confKPRIM);
}
} else if (item.getItemIdent().startsWith(ItemParser.ITEM_PREFIX_ESSAY)) {
if (itConfigs.get(QTIExportEssayItemFormatConfig.class) == null) {
QTIExportEssayItemFormatConfig confEssay = new QTIExportEssayItemFormatConfig(true, false);
itConfigs.put(QTIExportEssayItemFormatConfig.class, confEssay);
}
} else if (item.getItemIdent().startsWith(ItemParser.ITEM_PREFIX_FIB)) {
if (itConfigs.get(QTIExportFIBItemFormatConfig.class) == null) {
QTIExportFIBItemFormatConfig confFIB = new QTIExportFIBItemFormatConfig(true, false, false);
itConfigs.put(QTIExportFIBItemFormatConfig.class, confFIB);
}
} else // if cannot find the type via the ItemParser, look for the QTIItemObject type
if (item.getItemType().equals(QTIItemObject.TYPE.A)) {
QTIExportEssayItemFormatConfig confEssay = new QTIExportEssayItemFormatConfig(true, false);
itConfigs.put(QTIExportEssayItemFormatConfig.class, confEssay);
} else if (item.getItemType().equals(QTIItemObject.TYPE.R)) {
QTIExportSCQItemFormatConfig confSCQ = new QTIExportSCQItemFormatConfig(true, false, false, false);
itConfigs.put(QTIExportSCQItemFormatConfig.class, confSCQ);
} else if (item.getItemType().equals(QTIItemObject.TYPE.C)) {
QTIExportMCQItemFormatConfig confMCQ = new QTIExportMCQItemFormatConfig(true, false, false, false);
itConfigs.put(QTIExportMCQItemFormatConfig.class, confMCQ);
} else if (item.getItemType().equals(QTIItemObject.TYPE.B)) {
QTIExportFIBItemFormatConfig confFIB = new QTIExportFIBItemFormatConfig(true, false, false);
itConfigs.put(QTIExportFIBItemFormatConfig.class, confFIB);
} else {
throw new OLATRuntimeException(null, "Can not resolve QTIItem type", null);
}
}
return itConfigs;
}
use of org.olat.ims.qti.export.helper.QTIItemObject in project OpenOLAT by OpenOLAT.
the class QTIExportFormatterCSVType1 method closeReport.
public void closeReport() {
if (qtiItemObjectList == null) {
throw new OLATRuntimeException(null, "Can not format report when qtiItemObjectList is null", null);
}
String legend = translator.translate("legend");
sb.append(car + car);
sb.append(legend);
sb.append(car + car);
int y = 1;
for (Iterator<QTIItemObject> iter = qtiItemObjectList.iterator(); iter.hasNext(); ) {
QTIItemObject element = iter.next();
sb.append(element.getItemIdent());
sb.append(sep);
sb.append(emb);
sb.append(escape(element.getItemTitle()));
sb.append(emb);
sb.append(car);
sb.append(sep + sep);
sb.append("minValue");
sb.append(sep);
sb.append(element.getItemMinValue());
sb.append(car);
sb.append(sep + sep);
sb.append("maxValue");
sb.append(sep);
sb.append(element.getItemMaxValue());
sb.append(car);
sb.append(sep + sep);
sb.append("cutValue");
sb.append(sep);
sb.append(element.getItemCutValue());
sb.append(car);
// CELFI#107
sb.append(sep + sep + sep + sep);
String question = element.getQuestionText();
if (tagless) {
question = FilterFactory.getXSSFilter(-1).filter(question);
question = FilterFactory.getHtmlTagsFilter().filter(question);
}
question = StringEscapeUtils.unescapeHtml(question);
sb.append(question);
sb.append(car);
// CELFI#107 END
List<String> responseLabelMaterials = element.getResponseLabelMaterials();
for (int i = 0; i < element.getResponseIdentifier().size(); i++) {
sb.append(sep + sep);
sb.append(y);
sb.append("_");
sb.append(element.getItemType());
sb.append(i + 1);
sb.append(sep);
sb.append(element.getResponseIdentifier().get(i));
sb.append(sep);
if (responseLabelMaterials != null) {
String s = responseLabelMaterials.get(i);
s = StringEscapeUtils.unescapeHtml(s);
if (tagless) {
s = s.replaceAll("\\<.*?\\>", "");
}
sb.append(Formatter.stripTabsAndReturns(s));
}
sb.append(car);
}
y++;
}
sb.append(car + car);
sb.append("SCQ");
sb.append(sep);
sb.append("Single Choice Question");
sb.append(car);
sb.append("MCQ");
sb.append(sep);
sb.append("Multiple Choice Question");
sb.append(car);
sb.append("FIB");
sb.append(sep);
sb.append("Fill in the blank");
sb.append(car);
sb.append("ESS");
sb.append(sep);
sb.append("Essay");
sb.append(car);
sb.append("KPR");
sb.append(sep);
sb.append("Kprim (K-Type)");
sb.append(car + car);
sb.append("R:");
sb.append(sep);
sb.append("Radio button (SCQ)");
sb.append(car);
sb.append("C:");
sb.append(sep);
sb.append("Check box (MCQ or KPR)");
sb.append(car);
sb.append("B:");
sb.append(sep);
sb.append("Blank (FIB)");
sb.append(car);
sb.append("A:");
sb.append(sep);
sb.append("Area (ESS)");
sb.append(car + car);
sb.append("x_Ry");
sb.append(sep);
sb.append("Radio Button y of SCQ x, e.g. 1_R1");
sb.append(car);
sb.append("x_Cy");
sb.append(sep);
sb.append("Check Box y of MCQ x or two Radio Buttons y of KPR x, e.g. 3_C2");
sb.append(car);
sb.append("x_By");
sb.append(sep);
sb.append("Blank y of FIB x, e.g. 17_B2");
sb.append(car);
sb.append("x_Ay");
sb.append(sep);
sb.append("Area y of ESS x, e.g. 4_A1");
sb.append(car + car);
sb.append("Kprim:");
sb.append(sep);
sb.append("'+' = yes");
sb.append(sep);
sb.append("'-' = no");
sb.append(sep);
sb.append("'.' = no answer");
sb.append(sep);
}
use of org.olat.ims.qti.export.helper.QTIItemObject in project OpenOLAT by OpenOLAT.
the class QTIExportManager method createContentOfExportFile.
/**
* @param locale Locale used for export file headers / default values
* @param results
* @param type
* @param anonymizerCallback
* @return String
*/
private void createContentOfExportFile(List<QTIResult> qtiResults, List<QTIItemObject> qtiItemObjectList, QTIExportFormatter qef) {
qef.openReport();
// formatter has information about how to format the different qti objects
Map<Class<?>, QTIExportItemFormatConfig> mapWithConfigs = qef.getMapWithExportItemConfigs();
QTIExportItemFactory qeif = new QTIExportItemFactory(mapWithConfigs);
while (qtiResults.size() > 0) {
List<QTIResult> assessIDresults = stripNextAssessID(qtiResults);
qef.openResultSet(new QTIExportSet(assessIDresults.get(0)));
for (QTIItemObject element : qtiItemObjectList) {
QTIResult qtir = element.extractQTIResult(assessIDresults);
qef.visit(qeif.getExportItem(qtir, element));
}
qef.closeResultSet();
}
qef.closeReport();
}
use of org.olat.ims.qti.export.helper.QTIItemObject in project OpenOLAT by OpenOLAT.
the class QTIExportManager method selectAndExportResults.
public boolean selectAndExportResults(QTIExportFormatter qef, Long courseResId, String shortTitle, String olatResourceDetail, RepositoryEntry testRe, ZipOutputStream exportStream, Locale locale, String fileNameSuffix) throws IOException {
boolean resultsFoundAndExported = false;
QTIResultManager qrm = QTIResultManager.getInstance();
List<QTIResult> results = qrm.selectResults(courseResId, olatResourceDetail, testRe.getKey(), null, qef.getType());
if (results.size() > 0) {
List<QTIItemObject> qtiItemObjectList = new QTIObjectTreeBuilder().getQTIItemObjectList(testRe);
qef.setQTIItemObjectList(qtiItemObjectList);
if (results.size() > 0) {
createContentOfExportFile(results, qtiItemObjectList, qef);
String targetFileName = getFilename(shortTitle, fileNameSuffix);
exportStream.putNextEntry(new ZipEntry(targetFileName));
IOUtils.write(qef.getReport(), exportStream);
exportStream.closeEntry();
resultsFoundAndExported = true;
}
} else {
String targetFileName = getFilename(shortTitle, fileNameSuffix);
exportStream.putNextEntry(new ZipEntry(targetFileName));
Translator translator = Util.createPackageTranslator(QTIExportFormatter.class, locale);
IOUtils.write(translator.translate("archive.noresults.short"), exportStream);
exportStream.closeEntry();
resultsFoundAndExported = true;
}
return resultsFoundAndExported;
}
Aggregations