use of uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction in project openolat by klemens.
the class MatchInteractionArchive method writeHeader1.
@Override
public int writeHeader1(AssessmentItem item, Interaction interaction, int itemNumber, int interactionNumber, Row dataRow, int col, OpenXMLWorkbook workbook) {
if (interactionNumber == 0) {
String header = item.getTitle();
dataRow.addCell(col++, header, workbook.getStyles().getHeaderStyle());
}
MatchInteraction matchInteraction = (MatchInteraction) interaction;
int numOfChoices = matchInteraction.getSimpleMatchSets().get(0).getSimpleAssociableChoices().size();
if (numOfChoices > 0) {
col += (numOfChoices - 1);
}
return col;
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction in project openolat by klemens.
the class AssessmentItemBuilderTest method buildAssessmentItem_kprim.
@Test
public void buildAssessmentItem_kprim() throws IOException, URISyntaxException {
QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
KPrimAssessmentItemBuilder itemBuilder = new KPrimAssessmentItemBuilder("Kprim", "New answer", qtiSerializer);
if (build.booleanValue()) {
itemBuilder.build();
}
AssessmentItem singleChoiceItem = itemBuilder.getAssessmentItem();
ItemValidationResult itemResult = serializeAndReload(singleChoiceItem);
AssessmentItem reloadedItem = itemResult.getResolvedAssessmentItem().getItemLookup().extractIfSuccessful();
List<Interaction> interactions = reloadedItem.getItemBody().findInteractions();
Assert.assertNotNull(interactions);
Assert.assertEquals(1, interactions.size());
Assert.assertTrue(interactions.get(0) instanceof MatchInteraction);
MatchInteraction interaction = (MatchInteraction) interactions.get(0);
Assert.assertNotNull(interaction.getResponseIdentifier());
ResponseDeclaration responseDeclaration = reloadedItem.getResponseDeclaration(interaction.getResponseIdentifier());
Assert.assertNotNull(responseDeclaration);
Assert.assertEquals(2, interaction.getSimpleMatchSets().size());
SimpleMatchSet matchSet = interaction.getSimpleMatchSets().get(0);
Assert.assertEquals(4, matchSet.getSimpleAssociableChoices().size());
SimpleMatchSet correctWrongSet = interaction.getSimpleMatchSets().get(1);
Assert.assertEquals(2, correctWrongSet.getSimpleAssociableChoices().size());
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction in project openolat by klemens.
the class AssessmentObjectVelocityRenderDecorator method getVisibleOrderedChoices.
public List<SimpleAssociableChoice> getVisibleOrderedChoices(MatchInteraction interaction, int pos) {
try {
List<SimpleAssociableChoice> choices;
if (interaction.getShuffle()) {
List<Identifier> choiceOrders = itemSessionState.getShuffledInteractionChoiceOrder(interaction.getResponseIdentifier());
Map<Identifier, SimpleAssociableChoice> idTochoice = new HashMap<>();
List<SimpleAssociableChoice> allChoices = interaction.getSimpleMatchSets().get(pos).getSimpleAssociableChoices();
for (SimpleAssociableChoice allChoice : allChoices) {
idTochoice.put(allChoice.getIdentifier(), allChoice);
}
choices = new ArrayList<>();
for (Identifier choiceOrder : choiceOrders) {
SimpleAssociableChoice choice = idTochoice.get(choiceOrder);
if (choice != null) {
choices.add(choice);
}
}
} else {
choices = interaction.getSimpleMatchSets().get(pos).getSimpleAssociableChoices();
}
return choices.stream().filter((choice) -> isVisible(choice, itemSessionState)).collect(Collectors.toList());
} catch (Exception e) {
log.error("", e);
return null;
}
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.MatchInteraction in project openolat by klemens.
the class MatchEditorController 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);
}
// 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);
}
// single choice / multiple choice
String[] singleMultiValues = new String[] { translate("form.imd.match.single.choice"), translate("form.imd.match.multiple.choice") };
singleMultiEl = uifactory.addRadiosHorizontal("singleMulti", "form.imd.match.single.multiple", metadata, singleMultiKeys, singleMultiValues);
singleMultiEl.setElementCssClass("o_sel_match_single");
singleMultiEl.setEnabled(!restrictedEdit && !readOnly);
singleMultiEl.addActionListener(FormEvent.ONCHANGE);
if (itemBuilder.isMultipleChoice()) {
singleMultiEl.select(singleMultiKeys[1], true);
} else {
singleMultiEl.select(singleMultiKeys[0], true);
}
if (itemBuilder.getQuestionType() == QTI21QuestionType.matchdraganddrop) {
String[] layoutValues = new String[] { translate("form.imd.layout.left"), translate("form.imd.layout.top"), translate("form.imd.layout.right"), translate("form.imd.layout.bottom") };
layoutEl = uifactory.addRadiosHorizontal("layout", "form.imd.layout", metadata, layoutKeys, layoutValues);
layoutEl.setElementCssClass("o_sel_match_layout");
layoutEl.setEnabled(!restrictedEdit && !readOnly);
boolean found = false;
for (String layoutKey : layoutKeys) {
if (itemBuilder.hasMatchInteractionClass(layoutKey)) {
layoutEl.select(layoutKey, true);
found = true;
}
}
if (!found) {
layoutEl.select(layoutKeys[0], true);
}
}
// responses
String page = velocity_root + "/match_choices.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) {
wrapAnswer(ureq, sourceChoice, sourceWrappers);
}
List<SimpleAssociableChoice> targetChoices = itemBuilder.getTargetChoices();
for (SimpleAssociableChoice targetChoice : targetChoices) {
wrapAnswer(ureq, targetChoice, targetWrappers);
}
}
answersCont.contextPut("sourceChoices", sourceWrappers);
answersCont.contextPut("targetChoices", targetWrappers);
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) {
addColumnButton = uifactory.addFormLink("add.match.column", answersCont, Link.BUTTON);
addColumnButton.setElementCssClass("o_sel_match_add_column");
addColumnButton.setIconLeftCSS("o_icon o_icon_add");
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.MatchInteraction in project openolat by klemens.
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");
}
}
Aggregations