use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice in project openolat by klemens.
the class AssessmentObjectVelocityRenderDecorator method getVisibleOrderedSimpleChoices.
public List<SimpleChoice> getVisibleOrderedSimpleChoices(OrderInteraction interaction) {
List<SimpleChoice> choices;
if (interaction.getShuffle()) {
// <xsl:variable name="shuffledChoiceOrders" select="$itemSessionState/qw:shuffledInteractionChoiceOrder"
// as="element(qw:shuffledInteractionChoiceOrder)*"/>
// <xsl:variable name="choiceSequence" as="xs:string?"
// select="$shuffledChoiceOrders[@responseIdentifier=$interaction/@responseIdentifier]/@choiceSequence"/>
List<Identifier> choiceOrders = itemSessionState.getShuffledInteractionChoiceOrder(interaction.getResponseIdentifier());
choices = new ArrayList<>();
for (Identifier choiceOrder : choiceOrders) {
choices.add(interaction.getSimpleChoice(choiceOrder));
}
} else {
choices = interaction.getSimpleChoices();
}
return choices.stream().filter((choice) -> isVisible(choice, itemSessionState)).collect(Collectors.toList());
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice in project openolat by klemens.
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 klemens.
the class SingleChoiceEditorController 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_sc");
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);
textEl.setEnabled(!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);
}
// 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);
}
// layout
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 + "/simple_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.setRootForm(mainForm);
buttonsContainer.setElementCssClass("o_sel_choices_save");
buttonsContainer.setVisible(!readOnly);
formLayout.add(buttonsContainer);
formLayout.add("buttons", buttonsContainer);
if (!readOnly) {
uifactory.addFormSubmitButton("submit", buttonsContainer);
}
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.choice.SimpleChoice in project openolat by klemens.
the class SingleChoiceEditorController method formOK.
@Override
protected void formOK(UserRequest ureq) {
if (readOnly)
return;
// title
itemBuilder.setTitle(titleEl.getValue());
// question
String questionText = textEl.getRawValue();
itemBuilder.setQuestion(questionText);
Identifier correctAnswerIdentifier = null;
if (!restrictedEdit) {
// correct response
String correctAnswer = ureq.getParameter("correct");
correctAnswerIdentifier = Identifier.parseString(correctAnswer);
itemBuilder.setCorrectAnswer(correctAnswerIdentifier);
// shuffle
itemBuilder.setShuffle(shuffleEl.isOneSelected() && shuffleEl.isSelected(0));
// orientation
itemBuilder.setOrientation(Orientation.valueOf(orientationEl.getSelectedKey()));
// alignment
if (alignmentEl.isOneSelected() && alignmentEl.isSelected(1)) {
itemBuilder.addClass(QTI21Constants.CHOICE_ALIGN_RIGHT);
} else {
itemBuilder.removeClass(QTI21Constants.CHOICE_ALIGN_RIGHT);
}
}
// replace simple choices
List<SimpleChoice> choiceList = new ArrayList<>();
for (SimpleChoiceWrapper choiceWrapper : choiceWrappers) {
SimpleChoice choice = choiceWrapper.getSimpleChoice();
// text
String answer = choiceWrapper.getAnswer().getRawValue();
itemBuilder.getHtmlHelper().appendHtml(choice, answer);
choiceList.add(choice);
}
itemBuilder.setSimpleChoices(choiceList);
fireEvent(ureq, new AssessmentItemEvent(AssessmentItemEvent.ASSESSMENT_ITEM_CHANGED, itemBuilder.getAssessmentItem(), QTI21QuestionType.sc));
}
Aggregations