use of org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion 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.ChoiceQuestion in project OpenOLAT by OpenOLAT.
the class QTIEditHelper method createKPRIMItem.
/**
* Creates a new Kprim item
* @param trans
* @return New Kprim item.
*/
public static Item createKPRIMItem(Translator trans) {
// create item
Item newItem = new Item();
newItem.setIdent(EDITOR_IDENT + ":" + ITEM_TYPE_KPRIM + ":" + String.valueOf(CodeHelper.getRAMUniqueID()));
newItem.setTitle(trans.translate("editor.newquestion"));
newItem.setLabel("");
// controls
Control control = new Control();
List<Control> controls = new ArrayList<Control>();
controls.add(control);
newItem.setItemcontrols(controls);
// prepare question
float maxValue = 1;
ChoiceQuestion question = new ChoiceQuestion();
question.setLable(trans.translate("editor.newquestion"));
question.getQuestion().getElements().add(new Mattext(trans.translate("editor.newquestiontext")));
question.setType(Question.TYPE_KPRIM);
question.setSingleCorrect(false);
// Kprim has always 4 answers, each of them score 1/4 of the maximum value
ChoiceResponse newChoice = new ChoiceResponse();
newChoice.getContent().add(new Mattext(trans.translate("editor.newresponsetext")));
newChoice.setCorrect(false);
newChoice.setPoints(maxValue / 4);
question.getResponses().add(newChoice);
ChoiceResponse newChoice2 = new ChoiceResponse();
newChoice2.getContent().add(new Mattext(trans.translate("editor.newresponsetext")));
newChoice2.setCorrect(false);
newChoice2.setPoints(maxValue / 4);
question.getResponses().add(newChoice2);
ChoiceResponse newChoice3 = new ChoiceResponse();
newChoice3.getContent().add(new Mattext(trans.translate("editor.newresponsetext")));
newChoice3.setCorrect(false);
newChoice3.setPoints(maxValue / 4);
question.getResponses().add(newChoice3);
ChoiceResponse newChoice4 = new ChoiceResponse();
newChoice4.getContent().add(new Mattext(trans.translate("editor.newresponsetext")));
newChoice4.setCorrect(false);
newChoice4.setPoints(maxValue / 4);
question.getResponses().add(newChoice4);
question.setMaxValue(maxValue);
newItem.setQuestion(question);
QTIEditHelper.setFeedbackMastery(newItem, "");
QTIEditHelper.setFeedbackFail(newItem, "");
return newItem;
}
use of org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion in project OpenOLAT by OpenOLAT.
the class ItemMetadataFormController method initForm.
/**
* @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#initForm(org.olat.core.gui.components.form.flexible.FormItemContainer,
* org.olat.core.gui.control.Controller, org.olat.core.gui.UserRequest)
*/
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
setFormTitle("fieldset.legend.metadata");
int t = item.getQuestion().getType();
if (!isSurvey && t == Question.TYPE_ESSAY) {
setFormWarning("warning.essay.test");
}
if (isSurvey) {
setFormContextHelp("Test and Questionnaire Editor in Detail#details_testeditor_test_konf_frage");
} else {
setFormContextHelp("Test and Questionnaire Editor in Detail#details_testeditor_test_konf_frage");
}
// Title
title = uifactory.addTextElement("title", "form.imd.title", -1, item.getTitle(), formLayout);
title.setMandatory(true);
title.setNotEmptyCheck("form.imd.error.empty.title");
// Question Type
String typeName = getType();
uifactory.addStaticTextElement("type", "form.imd.type", typeName, formLayout);
// Description
desc = uifactory.addRichTextElementForStringData("desc", "form.imd.descr", item.getObjectives(), 8, -1, true, null, null, formLayout, ureq.getUserSession(), getWindowControl());
desc.getEditorConfiguration().setFigCaption(false);
RichTextConfiguration richTextConfig = desc.getEditorConfiguration();
// set upload dir to the media dir
richTextConfig.setFileBrowserUploadRelPath("media");
// Layout/Alignment
Question q = item.getQuestion();
// alignment of KPRIM is only horizontal
if (q instanceof ChoiceQuestion && item.getQuestion().getType() != Question.TYPE_KPRIM) {
String[] layoutKeys = new String[] { "h", "v" };
String[] layoutValues = new String[] { translate("form.imd.layout.horizontal"), translate("form.imd.layout.vertical") };
// layout = uifactory.addDropdownSingleselect("form.imd.layout", formLayout, layoutKeys, layoutValues, null);
layout = uifactory.addRadiosHorizontal("layout", "form.imd.layout", formLayout, layoutKeys, layoutValues);
layout.select(((ChoiceQuestion) q).getFlowLabelClass().equals(ChoiceQuestion.BLOCK) ? "h" : "v", true);
}
if (!isSurvey) {
String[] yesnoKeys = new String[] { "y", "n" };
String[] yesnoValues = new String[] { translate("yes"), translate("no") };
// Attempts
limitAttempts = uifactory.addRadiosHorizontal("form.imd.limittries", formLayout, yesnoKeys, yesnoValues);
limitAttempts.setEnabled(!isRestrictedEditMode);
// Radios/Checkboxes need onclick because of IE bug OLAT-5753
limitAttempts.addActionListener(FormEvent.ONCLICK);
attempts = uifactory.addIntegerElement("form.imd.tries", 0, formLayout);
attempts.setEnabled(!isRestrictedEditMode);
attempts.setDisplaySize(3);
if (item.getMaxattempts() > 0) {
limitAttempts.select("y", true);
attempts.setIntValue(item.getMaxattempts());
} else {
limitAttempts.select("n", true);
attempts.setVisible(false);
}
// Time Limit
limitTime = uifactory.addRadiosHorizontal("form.imd.limittime", formLayout, yesnoKeys, yesnoValues);
// Radios/Checkboxes need onclick because of IE bug OLAT-5753
limitTime.addActionListener(FormEvent.ONCLICK);
limitTime.setEnabled(!isRestrictedEditMode);
timeMin = uifactory.addIntegerElement("form.imd.time.min", 0, formLayout);
timeMin.setEnabled(!isRestrictedEditMode);
timeMin.setDisplaySize(3);
timeSec = uifactory.addIntegerElement("form.imd.time.sek", 0, formLayout);
timeSec.setEnabled(!isRestrictedEditMode);
timeSec.setDisplaySize(3);
if (item.getDuration() != null && item.getDuration().isSet()) {
limitTime.select("y", true);
timeMin.setIntValue(item.getDuration().getMin());
timeSec.setIntValue(item.getDuration().getSec());
} else {
limitTime.select("n", true);
timeMin.setVisible(false);
timeSec.setVisible(false);
}
// Shuffle Answers
shuffle = uifactory.addRadiosHorizontal("shuffle", "form.imd.shuffle", formLayout, yesnoKeys, yesnoValues);
shuffle.setEnabled(!isRestrictedEditMode);
shuffle.setVisible(t != Question.TYPE_ESSAY && t != Question.TYPE_FIB);
if (item.getQuestion().isShuffle()) {
shuffle.select("y", true);
} else {
shuffle.select("n", true);
}
// Hints
Control itemControl = item.getItemcontrols().get(0);
showHints = uifactory.addRadiosHorizontal("showHints", "form.imd.solutionhints.show", formLayout, yesnoKeys, yesnoValues);
showHints.setEnabled(!isRestrictedEditMode);
// Radios/Checkboxes need onclick because of IE bug OLAT-5753
showHints.addActionListener(FormEvent.ONCLICK);
showHints.setVisible(t != Question.TYPE_ESSAY);
hint = uifactory.addRichTextElementForStringData("hint", "form.imd.solutionhints", item.getQuestion().getHintText(), 8, -1, true, qti.getBaseDir(), null, formLayout, ureq.getUserSession(), getWindowControl());
hint.setEnabled(!isRestrictedEditMode);
hint.getEditorConfiguration().setFigCaption(false);
// set upload dir to the media dir
hint.getEditorConfiguration().setFileBrowserUploadRelPath("media");
if (itemControl.isHint()) {
showHints.select("y", true);
} else {
showHints.select("n", true);
hint.setVisible(false);
}
// Solution
showSolution = uifactory.addRadiosHorizontal("showSolution", "form.imd.correctsolution.show", formLayout, yesnoKeys, yesnoValues);
showSolution.setEnabled(!isRestrictedEditMode);
// Radios/Checkboxes need onclick because of IE bug OLAT-5753
showSolution.addActionListener(FormEvent.ONCLICK);
boolean essay = (q.getType() == Question.TYPE_ESSAY);
String solLabel = essay ? "form.imd.correctsolution.word" : "form.imd.correctsolution";
solution = uifactory.addRichTextElementForStringData("solution", solLabel, item.getQuestion().getSolutionText(), 8, -1, true, qti.getBaseDir(), null, formLayout, ureq.getUserSession(), getWindowControl());
solution.setEnabled(!isRestrictedEditMode);
solution.getEditorConfiguration().setFigCaption(false);
// set upload dir to the media dir
solution.getEditorConfiguration().setFileBrowserUploadRelPath("media");
if (itemControl.isSolution()) {
showSolution.select("y", true);
} else {
showSolution.select("n", true);
showSolution.setVisible(!essay);
// solution always visible for essay
solution.setVisible(essay);
}
}
// Submit Button
uifactory.addFormSubmitButton("submit", formLayout);
}
use of org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion in project OpenOLAT by OpenOLAT.
the class QTI12To21Converter method convertMultipleChoice.
private AssessmentItemBuilder convertMultipleChoice(Item item) {
MultipleChoiceAssessmentItemBuilder itemBuilder = new MultipleChoiceAssessmentItemBuilder("Multiple choice", "New answer", qtiSerializer);
convertItemBasics(item, itemBuilder);
itemBuilder.clearMapping();
itemBuilder.clearSimpleChoices();
ChoiceInteraction interaction = itemBuilder.getChoiceInteraction();
Question question = item.getQuestion();
itemBuilder.setShuffle(question.isShuffle());
convertOrientation(question, itemBuilder);
boolean hasNegative = false;
List<Response> responses = question.getResponses();
for (Response response : responses) {
if (response.getPoints() < 0.0f) {
hasNegative = true;
}
}
boolean singleCorrect = question.isSingleCorrect();
Map<String, Identifier> identToIdentifier = new HashMap<>();
for (Response response : responses) {
String responseText = response.getContent().renderAsHtmlForEditor();
responseText = blockedHtml(responseText);
SimpleChoice newChoice;
if (StringHelper.isHtml(responseText)) {
newChoice = AssessmentItemFactory.createSimpleChoice(interaction, "", itemBuilder.getQuestionType().getPrefix());
htmlBuilder.appendHtml(newChoice, responseText);
} else {
newChoice = AssessmentItemFactory.createSimpleChoice(interaction, responseText, itemBuilder.getQuestionType().getPrefix());
}
itemBuilder.addSimpleChoice(newChoice);
identToIdentifier.put(response.getIdent(), newChoice.getIdentifier());
double score = response.getPoints();
if (singleCorrect) {
if (response.isCorrect()) {
itemBuilder.addCorrectAnswer(newChoice.getIdentifier());
}
if (score > 0.0f) {
itemBuilder.setMaxScore(score);
}
} else {
if ((hasNegative && response.getPoints() >= 0.0f) || (!hasNegative && response.getPoints() > 0.0f)) {
itemBuilder.addCorrectAnswer(newChoice.getIdentifier());
}
itemBuilder.setMapping(newChoice.getIdentifier(), score);
}
}
convertFeedbackPerAnswers(item, itemBuilder, identToIdentifier);
if (singleCorrect) {
itemBuilder.setScoreEvaluationMode(ScoreEvaluation.allCorrectAnswers);
} else {
itemBuilder.setScoreEvaluationMode(ScoreEvaluation.perAnswer);
if (question instanceof ChoiceQuestion) {
ChoiceQuestion choice = (ChoiceQuestion) question;
itemBuilder.setMinScore(new Double(choice.getMinValue()));
itemBuilder.setMaxScore(new Double(choice.getMaxValue()));
}
}
return itemBuilder;
}
use of org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion in project openolat by klemens.
the class QTI12To21Converter method convertMultipleChoice.
private AssessmentItemBuilder convertMultipleChoice(Item item) {
MultipleChoiceAssessmentItemBuilder itemBuilder = new MultipleChoiceAssessmentItemBuilder("Multiple choice", "New answer", qtiSerializer);
convertItemBasics(item, itemBuilder);
itemBuilder.clearMapping();
itemBuilder.clearSimpleChoices();
ChoiceInteraction interaction = itemBuilder.getChoiceInteraction();
Question question = item.getQuestion();
itemBuilder.setShuffle(question.isShuffle());
convertOrientation(question, itemBuilder);
boolean hasNegative = false;
List<Response> responses = question.getResponses();
for (Response response : responses) {
if (response.getPoints() < 0.0f) {
hasNegative = true;
}
}
boolean singleCorrect = question.isSingleCorrect();
Map<String, Identifier> identToIdentifier = new HashMap<>();
for (Response response : responses) {
String responseText = response.getContent().renderAsHtmlForEditor();
responseText = blockedHtml(responseText);
SimpleChoice newChoice;
if (StringHelper.isHtml(responseText)) {
newChoice = AssessmentItemFactory.createSimpleChoice(interaction, "", itemBuilder.getQuestionType().getPrefix());
htmlBuilder.appendHtml(newChoice, responseText);
} else {
newChoice = AssessmentItemFactory.createSimpleChoice(interaction, responseText, itemBuilder.getQuestionType().getPrefix());
}
itemBuilder.addSimpleChoice(newChoice);
identToIdentifier.put(response.getIdent(), newChoice.getIdentifier());
double score = response.getPoints();
if (singleCorrect) {
if (response.isCorrect()) {
itemBuilder.addCorrectAnswer(newChoice.getIdentifier());
}
if (score > 0.0f) {
itemBuilder.setMaxScore(score);
}
} else {
if ((hasNegative && response.getPoints() >= 0.0f) || (!hasNegative && response.getPoints() > 0.0f)) {
itemBuilder.addCorrectAnswer(newChoice.getIdentifier());
}
itemBuilder.setMapping(newChoice.getIdentifier(), score);
}
}
convertFeedbackPerAnswers(item, itemBuilder, identToIdentifier);
if (singleCorrect) {
itemBuilder.setScoreEvaluationMode(ScoreEvaluation.allCorrectAnswers);
} else {
itemBuilder.setScoreEvaluationMode(ScoreEvaluation.perAnswer);
if (question instanceof ChoiceQuestion) {
ChoiceQuestion choice = (ChoiceQuestion) question;
itemBuilder.setMinScore(new Double(choice.getMinValue()));
itemBuilder.setMaxScore(new Double(choice.getMaxValue()));
}
}
return itemBuilder;
}
Aggregations