use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice in project OpenOLAT by OpenOLAT.
the class TrueFalseEditorController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
FormLayoutContainer metadata = FormLayoutContainer.createDefaultFormLayout("metadata", getTranslator());
if (itemBuilder.getQuestionType() == QTI21QuestionType.matchdraganddrop) {
metadata.setFormContextHelp("Test editor QTI 2.1 in detail#details_testeditor_fragetypen_draganddrop");
} else {
metadata.setFormContextHelp("Test editor QTI 2.1 in detail#details_testeditor_fragetypen_match");
}
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.setEnabled(!readOnly);
textEl.setVisible(!readOnly);
if (readOnly) {
FlowFormItem textReadOnlyEl = new FlowFormItem("descro", itemFile);
textReadOnlyEl.setLabel("form.imd.descr", null);
textReadOnlyEl.setBlocks(itemBuilder.getQuestionBlocks());
textReadOnlyEl.setMapperUri(mapperUri);
metadata.add(textReadOnlyEl);
}
// responses
String page = velocity_root + "/match_truefalse.html";
answersCont = FormLayoutContainer.createCustomFormLayout("answers", getTranslator(), page);
answersCont.setRootForm(mainForm);
answersCont.contextPut("showHeaders", (itemBuilder.getQuestionType() == QTI21QuestionType.matchdraganddrop));
formLayout.add(answersCont);
formLayout.add("answers", answersCont);
MatchInteraction interaction = itemBuilder.getMatchInteraction();
if (interaction != null) {
List<SimpleAssociableChoice> sourceChoices = itemBuilder.getSourceChoices();
for (SimpleAssociableChoice sourceChoice : sourceChoices) {
wrapSource(ureq, sourceChoice, sourceWrappers);
}
List<TargetWrapper> targetChoices = itemBuilder.getTargetChoices().stream().map(c -> new TargetWrapper(c)).collect(Collectors.toList());
answersCont.contextPut("targetChoices", targetChoices);
}
answersCont.contextPut("sourceChoices", sourceWrappers);
answersCont.contextPut("restrictedEdit", restrictedEdit || readOnly);
answersCont.contextPut("responseIdentifier", itemBuilder.getResponseIdentifier());
int maxAssociations = itemBuilder.getMatchInteraction().getMaxAssociations();
answersCont.contextPut("interactionMaxAssociations", maxAssociations);
JSAndCSSFormItem js = new JSAndCSSFormItem("js", new String[] { "js/jquery/qti/jquery.match.js" });
formLayout.add(js);
if (!readOnly) {
uifactory.addFormSubmitButton("submit", answersCont);
}
if (!restrictedEdit && !readOnly) {
addRowButton = uifactory.addFormLink("add.match.row", answersCont, Link.BUTTON);
addRowButton.setElementCssClass("o_sel_match_add_row");
addRowButton.setIconLeftCSS("o_icon o_icon_add");
}
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice in project OpenOLAT by OpenOLAT.
the class TrueFalseEditorController method doAddSourceRow.
private void doAddSourceRow(UserRequest ureq) {
SimpleAssociableChoice newChoice = createSimpleAssociableChoice("Text", itemBuilder.getSourceMatchSet());
itemBuilder.getSourceMatchSet().getSimpleAssociableChoices().add(newChoice);
wrapSource(ureq, newChoice, sourceWrappers);
answersCont.setDirty(true);
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice in project OpenOLAT by OpenOLAT.
the class TrueFalseEditorController method formOK.
@Override
protected void formOK(UserRequest ureq) {
if (readOnly)
return;
// title
itemBuilder.setTitle(titleEl.getValue());
// question
String questionText = textEl.getRawValue();
itemBuilder.setQuestion(questionText);
if (!restrictedEdit) {
itemBuilder.setMultipleChoice(false);
itemBuilder.setShuffle(false);
}
// update
for (SourceWrapper sourceWrapper : sourceWrappers) {
SimpleAssociableChoice choice = sourceWrapper.getSimpleChoice();
String answer = sourceWrapper.getText().getRawValue();
itemBuilder.getHtmlHelper().appendHtml(choice, answer);
}
// correct answers
commitAssociations(ureq);
fireEvent(ureq, new AssessmentItemEvent(AssessmentItemEvent.ASSESSMENT_ITEM_CHANGED, itemBuilder.getAssessmentItem(), QTI21QuestionType.match));
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice in project OpenOLAT by OpenOLAT.
the class MatchScoreController method sync.
private List<MatchWrapper> sync(SimpleMatchSet matchSet, List<MatchWrapper> wrappers) {
Map<Identifier, MatchWrapper> currentMapping = wrappers.stream().collect(Collectors.toMap(w -> w.getChoiceIdentifier(), w -> w));
List<MatchWrapper> newWrappers = new ArrayList<>();
List<SimpleAssociableChoice> choices = matchSet.getSimpleAssociableChoices();
for (SimpleAssociableChoice choice : choices) {
if (currentMapping.containsKey(choice.getIdentifier())) {
newWrappers.add(currentMapping.get(choice.getIdentifier()));
} else {
newWrappers.add(createMatchWrapper(choice));
}
}
return newWrappers;
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleAssociableChoice in project OpenOLAT by OpenOLAT.
the class KPrimAssessmentItemBuilder method createAssessmentItem.
private static AssessmentItem createAssessmentItem(String title, String defaultAnswer) {
AssessmentItem assessmentItem = AssessmentItemFactory.createAssessmentItem(QTI21QuestionType.kprim, title);
NodeGroupList nodeGroups = assessmentItem.getNodeGroups();
double maxScore = 1.0d;
Identifier responseDeclarationId = Identifier.assumedLegal("KPRIM_RESPONSE_1");
// define correct answer
ResponseDeclaration responseDeclaration = createKPrimResponseDeclaration(assessmentItem, responseDeclarationId, new HashMap<>(), maxScore);
nodeGroups.getResponseDeclarationGroup().getResponseDeclarations().add(responseDeclaration);
appendDefaultOutcomeDeclarations(assessmentItem, maxScore);
// the single choice interaction
ItemBody itemBody = appendDefaultItemBody(assessmentItem);
MatchInteraction matchInteraction = appendMatchInteractionForKPrim(itemBody, responseDeclarationId, defaultAnswer);
List<String> cssClasses = new ArrayList<>();
cssClasses.add(QTI21Constants.CSS_MATCH_KPRIM);
matchInteraction.setClassAttr(cssClasses);
SimpleMatchSet matchSet = matchInteraction.getSimpleMatchSets().get(0);
Map<Identifier, Identifier> associations = new HashMap<>();
for (SimpleAssociableChoice choice : matchSet.getSimpleAssociableChoices()) {
associations.put(choice.getIdentifier(), QTI21Constants.WRONG_IDENTIFIER);
}
appendAssociationKPrimResponseDeclaration(responseDeclaration, associations, 1.0);
// response processing
ResponseProcessing responseProcessing = createResponseProcessing(assessmentItem, responseDeclarationId);
assessmentItem.getNodeGroups().getResponseProcessingGroup().setResponseProcessing(responseProcessing);
return assessmentItem;
}
Aggregations