use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice in project OpenOLAT by OpenOLAT.
the class MultipleChoiceEditorController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
FormLayoutContainer metadata = FormLayoutContainer.createDefaultFormLayout_2_10("metadata", getTranslator());
metadata.setFormContextHelp("Test editor QTI 2.1 in detail#details_testeditor_fragetypen_mc");
metadata.setRootForm(mainForm);
formLayout.add(metadata);
formLayout.add("metadata", metadata);
titleEl = uifactory.addTextElement("title", "form.imd.title", -1, itemBuilder.getTitle(), metadata);
titleEl.setElementCssClass("o_sel_assessment_item_title");
titleEl.setMandatory(true);
titleEl.setEnabled(!readOnly);
String description = itemBuilder.getQuestion();
textEl = uifactory.addRichTextElementForQTI21("desc", "form.imd.descr", description, 8, -1, itemContainer, metadata, ureq.getUserSession(), getWindowControl());
textEl.setVisible(!readOnly);
if (readOnly) {
FlowFormItem choiceReadOnlyEl = new FlowFormItem("descro", itemFile);
choiceReadOnlyEl.setLabel("form.imd.descr", null);
choiceReadOnlyEl.setBlocks(itemBuilder.getQuestionBlocks());
choiceReadOnlyEl.setMapperUri(mapperUri);
metadata.add(choiceReadOnlyEl);
}
// shuffle
String[] yesnoValues = new String[] { translate("yes"), translate("no") };
shuffleEl = uifactory.addRadiosHorizontal("shuffle", "form.imd.shuffle", metadata, yesnoKeys, yesnoValues);
shuffleEl.setEnabled(!restrictedEdit && !readOnly);
if (itemBuilder.isShuffle()) {
shuffleEl.select("y", true);
} else {
shuffleEl.select("n", true);
}
// layout
String[] layoutValues = new String[] { translate("form.imd.layout.vertical"), translate("form.imd.layout.horizontal") };
orientationEl = uifactory.addRadiosHorizontal("layout", "form.imd.layout", metadata, layoutKeys, layoutValues);
orientationEl.setEnabled(!restrictedEdit && !readOnly);
if (itemBuilder.getOrientation() == null || Orientation.VERTICAL.equals(itemBuilder.getOrientation())) {
orientationEl.select(Orientation.VERTICAL.name(), true);
} else {
orientationEl.select(Orientation.HORIZONTAL.name(), true);
}
// alignment
String[] alignmentValues = new String[] { translate("form.imd.alignment.left"), translate("form.imd.alignment.right") };
alignmentEl = uifactory.addRadiosHorizontal("alignment", "form.imd.alignment", metadata, alignmentKeys, alignmentValues);
alignmentEl.setEnabled(!restrictedEdit && !readOnly);
if (itemBuilder.hasClassAttr(QTI21Constants.CHOICE_ALIGN_RIGHT)) {
alignmentEl.select(alignmentKeys[1], true);
} else {
alignmentEl.select(alignmentKeys[0], true);
}
// responses
String page = velocity_root + "/multiple_choices.html";
answersCont = FormLayoutContainer.createCustomFormLayout("answers", getTranslator(), page);
answersCont.setRootForm(mainForm);
formLayout.add(answersCont);
formLayout.add("answers", answersCont);
ChoiceInteraction interaction = itemBuilder.getChoiceInteraction();
if (interaction != null) {
List<SimpleChoice> choices = itemBuilder.getChoices();
for (SimpleChoice choice : choices) {
wrapAnswer(ureq, choice);
}
}
answersCont.contextPut("choices", choiceWrappers);
answersCont.contextPut("restrictedEdit", restrictedEdit || readOnly);
recalculateUpDownLinks();
// Submit Button
FormLayoutContainer buttonsContainer = FormLayoutContainer.createDefaultFormLayout_2_10("buttons", getTranslator());
buttonsContainer.setElementCssClass("o_sel_choices_save");
buttonsContainer.setRootForm(mainForm);
buttonsContainer.setVisible(!readOnly);
formLayout.add(buttonsContainer);
formLayout.add("buttons", buttonsContainer);
uifactory.addFormSubmitButton("submit", buttonsContainer);
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice in project OpenOLAT by OpenOLAT.
the class MultipleChoiceEditorController method doAddSimpleChoice.
private void doAddSimpleChoice(UserRequest ureq) {
ChoiceInteraction interaction = itemBuilder.getChoiceInteraction();
SimpleChoice newChoice = new SimpleChoice(interaction);
newChoice.setIdentifier(IdentifierGenerator.newAsIdentifier("mc"));
P firstChoiceText = AssessmentItemFactory.getParagraph(newChoice, translate("new.answer"));
newChoice.getFlowStatics().add(firstChoiceText);
wrapAnswer(ureq, newChoice);
flc.setDirty(true);
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice in project OpenOLAT by OpenOLAT.
the class SimpleChoiceAssessmentItemBuilder method getAnswers.
@Override
public List<Answer> getAnswers() {
List<SimpleChoice> simpleChoices = getChoices();
List<Answer> answers = new ArrayList<>(simpleChoices.size());
for (SimpleChoice choice : simpleChoices) {
String choiceContent = getHtmlHelper().flowStaticString(choice.getFlowStatics());
String label = FilterFactory.getHtmlTagAndDescapingFilter().filter(choiceContent);
answers.add(new Answer(choice.getIdentifier(), label));
}
return answers;
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice 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 uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice in project OpenOLAT by OpenOLAT.
the class AssessmentItemFactory method appendSimpleChoice.
public static SimpleChoice appendSimpleChoice(ChoiceInteraction choiceInteraction, String text, Identifier identifier) {
SimpleChoice newChoice = new SimpleChoice(choiceInteraction);
newChoice.setIdentifier(identifier);
P firstChoiceText = AssessmentItemFactory.getParagraph(newChoice, text);
newChoice.getFlowStatics().add(firstChoiceText);
choiceInteraction.getNodeGroups().getSimpleChoiceGroup().getSimpleChoices().add(newChoice);
return newChoice;
}
Aggregations