use of org.olat.ims.qti.editor.beecom.objects.FIBQuestion in project openolat by klemens.
the class CSVToQuestionConverter method processChoice.
private void processChoice(String[] parts) {
if (currentItem == null || parts.length < 2) {
return;
}
try {
Question question = currentItem.getItem().getQuestion();
int type = question.getType();
if (type == Question.TYPE_MC || type == Question.TYPE_SC) {
float point = parseFloat(parts[0], 1.0f);
String content = parts[1];
ChoiceQuestion choice = (ChoiceQuestion) question;
List<Response> choices = choice.getResponses();
ChoiceResponse newChoice = new ChoiceResponse();
newChoice.getContent().add(createMattext(content));
newChoice.setCorrect(point > 0.0f);
newChoice.setPoints(point);
choices.add(newChoice);
} else if (type == Question.TYPE_FIB) {
String firstPart = parts[0].toLowerCase();
FIBQuestion fib = (FIBQuestion) question;
if ("text".equals(firstPart) || "texte".equals(firstPart)) {
String text = parts[1];
FIBResponse response = new FIBResponse();
response.setType(FIBResponse.TYPE_CONTENT);
Material mat = createMaterialWithText(text);
response.setContent(mat);
fib.getResponses().add(response);
} else {
float point = parseFloat(parts[0], 1.0f);
String correctBlank = parts[1];
FIBResponse response = new FIBResponse();
response.setType(FIBResponse.TYPE_BLANK);
response.setCorrectBlank(correctBlank);
response.setPoints(point);
if (parts.length > 2) {
String sizes = parts[2];
String[] sizeArr = sizes.split(",");
if (sizeArr.length >= 2) {
int size = Integer.parseInt(sizeArr[0]);
int maxLength = Integer.parseInt(sizeArr[1]);
response.setSize(size);
response.setMaxLength(maxLength);
}
}
fib.getResponses().add(response);
}
}
} catch (NumberFormatException e) {
log.warn("Cannot parse point for: " + parts[0] + " / " + parts[1], e);
}
}
use of org.olat.ims.qti.editor.beecom.objects.FIBQuestion in project openolat by klemens.
the class QTIWordExport method renderItem.
public static void renderItem(Item item, OpenXMLDocument document, boolean withResponses, Translator translator) {
Element el = DocumentFactory.getInstance().createElement("dummy");
item.addToElement(el);
Element itemEl = (Element) el.elements().get(0);
org.olat.ims.qti.container.qtielements.Item foo = new org.olat.ims.qti.container.qtielements.Item(itemEl);
RenderInstructions renderInstructions = new RenderInstructions();
renderInstructions.put(RenderInstructions.KEY_STATICS_PATH, "/");
renderInstructions.put(RenderInstructions.KEY_LOCALE, translator.getLocale());
renderInstructions.put(RenderInstructions.KEY_RENDER_TITLE, Boolean.TRUE);
if (item.getQuestion() != null) {
Map<String, String> iinput = new HashMap<String, String>();
String questionType = null;
String questionScore = null;
Question question = item.getQuestion();
if (question instanceof ChoiceQuestion) {
ChoiceQuestion choice = (ChoiceQuestion) question;
if (question.getType() == Question.TYPE_SC) {
questionType = translator.translate("item.type.sc");
fetchPointsOfMultipleChoices(itemEl, choice, iinput);
} else if (question.getType() == Question.TYPE_MC) {
questionType = translator.translate("item.type.mc");
fetchPointsOfMultipleChoices(itemEl, choice, iinput);
} else if (question.getType() == Question.TYPE_KPRIM) {
questionType = translator.translate("item.type.kprim");
fetchPointsOfKPrim(itemEl, choice, iinput);
}
} else if (question instanceof FIBQuestion) {
questionType = translator.translate("item.type.sc");
for (Response response : question.getResponses()) {
FIBResponse fibResponse = (FIBResponse) response;
if ("BLANK".equals(fibResponse.getType())) {
iinput.put(fibResponse.getIdent(), fibResponse.getCorrectBlank());
}
}
} else if (question instanceof EssayQuestion) {
questionType = translator.translate("item.type.essay");
}
if (question != null && question.getMaxValue() > 0.0f) {
questionScore = AssessmentHelper.getRoundedScore(question.getMaxValue());
questionScore = translator.translate("item.score.long", new String[] { questionScore });
}
renderInstructions.put(RenderInstructions.KEY_RENDER_CORRECT_RESPONSES, new Boolean(withResponses));
renderInstructions.put(RenderInstructions.KEY_CORRECT_RESPONSES_MAP, iinput);
renderInstructions.put(RenderInstructions.KEY_QUESTION_TYPE, questionType);
renderInstructions.put(RenderInstructions.KEY_QUESTION_SCORE, questionScore);
renderInstructions.put(RenderInstructions.KEY_QUESTION_OO_TYPE, new Integer(question.getType()));
}
foo.renderOpenXML(document, renderInstructions);
}
Aggregations