use of org.olat.ims.qti.editor.beecom.objects.FIBQuestion in project OpenOLAT by OpenOLAT.
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);
}
use of org.olat.ims.qti.editor.beecom.objects.FIBQuestion in project openolat by klemens.
the class CSVToQuestionConverterTest method importFillInBlanck_en_metadata.
@Test
public void importFillInBlanck_en_metadata() throws IOException, URISyntaxException {
URL importTxtUrl = CSVToQuestionConverterTest.class.getResource("question_import_fib_en_metadata.txt");
Assert.assertNotNull(importTxtUrl);
File importTxt = new File(importTxtUrl.toURI());
String input = FileUtils.readFileToString(importTxt, "UTF-8");
Translator translator = new KeyTranslator(Locale.ENGLISH);
ImportOptions options = new ImportOptions();
options.setShuffle(true);
CSVToQuestionConverter converter = new CSVToQuestionConverter(translator, options);
converter.parse(input);
List<ItemAndMetadata> items = converter.getItems();
Assert.assertNotNull(items);
Assert.assertEquals(1, items.size());
ItemAndMetadata importedItem = items.get(0);
Item item = importedItem.getItem();
Assert.assertNotNull(item);
Assert.assertEquals(Question.TYPE_FIB, item.getQuestion().getType());
Assert.assertTrue(item.getQuestion() instanceof FIBQuestion);
FIBQuestion question = (FIBQuestion) item.getQuestion();
List<Response> responses = question.getResponses();
Assert.assertNotNull(responses);
Assert.assertEquals(2, responses.size());
// check java type
for (Response response : responses) {
Assert.assertTrue(response instanceof FIBResponse);
}
// check type
Assert.assertEquals(FIBResponse.TYPE_CONTENT, ((FIBResponse) responses.get(0)).getType());
Assert.assertEquals(FIBResponse.TYPE_BLANK, ((FIBResponse) responses.get(1)).getType());
// check size
Assert.assertEquals(20, ((FIBResponse) responses.get(1)).getSize());
// check max length
Assert.assertEquals(50, ((FIBResponse) responses.get(1)).getMaxLength());
}
use of org.olat.ims.qti.editor.beecom.objects.FIBQuestion in project openolat by klemens.
the class FIBItemController method event.
/**
* @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
* org.olat.core.gui.components.Component, org.olat.core.gui.control.Event)
*/
@Override
public void event(UserRequest ureq, Component source, Event event) {
if (source == main) {
// olat::: as: improve easy fix since almost all operations change the main vc.
main.setDirty(true);
String cmd = event.getCommand();
String sPosid = ureq.getParameter("posid");
int posid = 0;
if (sPosid != null)
posid = Integer.parseInt(sPosid);
if (cmd.equals("up")) {
List<Response> elements = item.getQuestion().getResponses();
if (posid > 0 && posid < item.getQuestion().getResponses().size()) {
Response obj = elements.remove(posid);
elements.add(posid - 1, obj);
} else {
logError("posid doesn't match responses length: " + posid + "/" + elements.size(), null);
}
} else if (cmd.equals("down")) {
List<Response> elements = item.getQuestion().getResponses();
if (posid >= 0 && posid < elements.size() - 1) {
Response obj = elements.remove(posid);
elements.add(posid + 1, obj);
} else {
logError("posid doesn't match responses length: " + posid + "/" + elements.size(), null);
}
} else if (cmd.equals("editq")) {
editQuestion = item.getQuestion().getQuestion();
displayMaterialFormController(ureq, editQuestion, restrictedEdit);
} else if (cmd.equals("editr")) {
List<Response> elements = item.getQuestion().getResponses();
if (posid >= 0 && posid < elements.size()) {
editResponse = elements.get(posid);
Material responseMat = elements.get(posid).getContent();
displayMaterialFormController(ureq, responseMat, restrictedEdit);
} else {
logError("posid doesn't match responses length: " + posid + "/" + elements.size(), null);
}
} else if (cmd.equals("addtext")) {
FIBQuestion fib = (FIBQuestion) item.getQuestion();
FIBResponse response = new FIBResponse();
response.setType(FIBResponse.TYPE_CONTENT);
Material mat = new Material();
mat.add(new Mattext(translate("newtextelement")));
response.setContent(mat);
fib.getResponses().add(response);
} else if (cmd.equals("addblank")) {
FIBQuestion fib = (FIBQuestion) item.getQuestion();
FIBResponse response = new FIBResponse();
response.setType(FIBResponse.TYPE_BLANK);
response.setCorrectBlank("");
// default value
response.setPoints(1f);
fib.getResponses().add(response);
} else if (cmd.equals("del")) {
delYesNoCtrl = DialogBoxUIFactory.createYesNoDialog(ureq, getWindowControl(), null, translate("confirm.delete.element"));
listenTo(delYesNoCtrl);
delYesNoCtrl.setUserObject(new Integer(posid));
delYesNoCtrl.activate();
} else if (cmd.equals("sfib")) {
// submit fib
FIBQuestion question = (FIBQuestion) item.getQuestion();
// Survey specific variables
if (surveyMode) {
List<Response> responses = question.getResponses();
for (int i = 0; i < responses.size(); i++) {
FIBResponse response = (FIBResponse) responses.get(i);
if (FIBResponse.TYPE_BLANK.equals(response.getType())) {
// Set size of input field
String size = ureq.getParameter("size_q" + i);
if (size != null)
response.setSizeFromString(size);
String maxLength = ureq.getParameter("maxl_q" + i);
if (maxLength != null)
response.setMaxLengthFromString(maxLength);
}
}
} else {
// set min/max values before single_correct !!
if (!restrictedEdit) {
// only in full edit mode the following fields are available:
// min_value, max_value, valuation_method
question.setMinValue(ureq.getParameter("min_value"));
question.setMaxValue(ureq.getParameter("max_value"));
question.setSingleCorrect("single".equals(ureq.getParameter("valuation_method")));
if (question.isSingleCorrect()) {
question.setSingleCorrectScore(ureq.getParameter("single_score"));
} else {
question.setSingleCorrectScore(0.0f);
}
}
NodeBeforeChangeEvent nce = new NodeBeforeChangeEvent();
nce.setItemIdent(item.getIdent());
List<Response> responses = question.getResponses();
for (int i = 0; i < responses.size(); i++) {
FIBResponse response = (FIBResponse) responses.get(i);
nce.setResponseIdent(response.getIdent());
fireEvent(ureq, nce);
response.setPoints(ureq.getParameter("points_q" + i));
if (FIBResponse.TYPE_BLANK.equals(response.getType())) {
response.setCorrectBlank(ureq.getParameter("content_q" + i));
// Set case sensitiveness
String caseSensitive = ureq.getParameter("case_q" + i);
if (caseSensitive == null)
caseSensitive = "No";
response.setCaseSensitive(caseSensitive);
// Set size of input field
String size = ureq.getParameter("size_q" + i);
if (size != null)
response.setSizeFromString(size);
String maxLength = ureq.getParameter("maxl_q" + i);
if (maxLength != null)
response.setMaxLengthFromString(maxLength);
// find longest correct blank in all synonyms of
// correct answers, fix max lenght if a longer value
// is found
String[] allCorrect = response.getCorrectBlank().split(";");
int longestCorrect = 0;
for (int j = 0; j < allCorrect.length; j++) {
String singleCorrect = allCorrect[j];
if (singleCorrect.length() > longestCorrect) {
longestCorrect = singleCorrect.length();
}
}
if (longestCorrect > response.getMaxLength())
response.setMaxLength(longestCorrect);
}
}
}
}
qtiPackage.serializeQTIDocument();
}
}
use of org.olat.ims.qti.editor.beecom.objects.FIBQuestion in project OpenOLAT by OpenOLAT.
the class CSVToQuestionConverterTest method importFillInBlanck_en_metadata.
@Test
public void importFillInBlanck_en_metadata() throws IOException, URISyntaxException {
URL importTxtUrl = CSVToQuestionConverterTest.class.getResource("question_import_fib_en_metadata.txt");
Assert.assertNotNull(importTxtUrl);
File importTxt = new File(importTxtUrl.toURI());
String input = FileUtils.readFileToString(importTxt, "UTF-8");
Translator translator = new KeyTranslator(Locale.ENGLISH);
ImportOptions options = new ImportOptions();
options.setShuffle(true);
CSVToQuestionConverter converter = new CSVToQuestionConverter(translator, options);
converter.parse(input);
List<ItemAndMetadata> items = converter.getItems();
Assert.assertNotNull(items);
Assert.assertEquals(1, items.size());
ItemAndMetadata importedItem = items.get(0);
Item item = importedItem.getItem();
Assert.assertNotNull(item);
Assert.assertEquals(Question.TYPE_FIB, item.getQuestion().getType());
Assert.assertTrue(item.getQuestion() instanceof FIBQuestion);
FIBQuestion question = (FIBQuestion) item.getQuestion();
List<Response> responses = question.getResponses();
Assert.assertNotNull(responses);
Assert.assertEquals(2, responses.size());
// check java type
for (Response response : responses) {
Assert.assertTrue(response instanceof FIBResponse);
}
// check type
Assert.assertEquals(FIBResponse.TYPE_CONTENT, ((FIBResponse) responses.get(0)).getType());
Assert.assertEquals(FIBResponse.TYPE_BLANK, ((FIBResponse) responses.get(1)).getType());
// check size
Assert.assertEquals(20, ((FIBResponse) responses.get(1)).getSize());
// check max length
Assert.assertEquals(50, ((FIBResponse) responses.get(1)).getMaxLength());
}
use of org.olat.ims.qti.editor.beecom.objects.FIBQuestion in project OpenOLAT by OpenOLAT.
the class CSVToQuestionConverterTest method importFillInBlanck.
@Test
public void importFillInBlanck() throws IOException, URISyntaxException {
URL importTxtUrl = CSVToQuestionConverterTest.class.getResource("question_import_fib.txt");
Assert.assertNotNull(importTxtUrl);
File importTxt = new File(importTxtUrl.toURI());
String input = FileUtils.readFileToString(importTxt, "UTF-8");
Translator translator = new KeyTranslator(Locale.ENGLISH);
ImportOptions options = new ImportOptions();
options.setShuffle(true);
CSVToQuestionConverter converter = new CSVToQuestionConverter(translator, options);
converter.parse(input);
List<ItemAndMetadata> items = converter.getItems();
Assert.assertNotNull(items);
Assert.assertEquals(1, items.size());
ItemAndMetadata importedItem = items.get(0);
Item item = importedItem.getItem();
Assert.assertNotNull(item);
Assert.assertEquals(Question.TYPE_FIB, item.getQuestion().getType());
Assert.assertTrue(item.getQuestion() instanceof FIBQuestion);
FIBQuestion question = (FIBQuestion) item.getQuestion();
List<Response> responses = question.getResponses();
Assert.assertNotNull(responses);
Assert.assertEquals(7, responses.size());
// check java type
for (Response response : responses) {
Assert.assertTrue(response instanceof FIBResponse);
}
// check type
Assert.assertEquals(FIBResponse.TYPE_CONTENT, ((FIBResponse) responses.get(0)).getType());
Assert.assertEquals(FIBResponse.TYPE_BLANK, ((FIBResponse) responses.get(1)).getType());
Assert.assertEquals(FIBResponse.TYPE_CONTENT, ((FIBResponse) responses.get(2)).getType());
Assert.assertEquals(FIBResponse.TYPE_BLANK, ((FIBResponse) responses.get(3)).getType());
Assert.assertEquals(FIBResponse.TYPE_CONTENT, ((FIBResponse) responses.get(4)).getType());
Assert.assertEquals(FIBResponse.TYPE_BLANK, ((FIBResponse) responses.get(5)).getType());
Assert.assertEquals(FIBResponse.TYPE_CONTENT, ((FIBResponse) responses.get(6)).getType());
// check size
Assert.assertEquals(2, ((FIBResponse) responses.get(1)).getSize());
Assert.assertEquals(2, ((FIBResponse) responses.get(3)).getSize());
Assert.assertEquals(2, ((FIBResponse) responses.get(5)).getSize());
// check max length
Assert.assertEquals(2, ((FIBResponse) responses.get(1)).getMaxLength());
Assert.assertEquals(2, ((FIBResponse) responses.get(3)).getMaxLength());
Assert.assertEquals(2, ((FIBResponse) responses.get(5)).getMaxLength());
}
Aggregations