use of uk.ac.ed.ph.jqtiplus.types.Identifier in project openolat by klemens.
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.types.Identifier in project openolat by klemens.
the class MultipleChoiceEditorController 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) {
// correct response
String[] correctAnswers = ureq.getHttpReq().getParameterValues("correct");
List<Identifier> correctAnswerList = new ArrayList<>();
if (correctAnswers != null) {
for (String correctAnswer : correctAnswers) {
correctAnswerList.add(Identifier.parseString(correctAnswer));
}
}
itemBuilder.setCorrectAnswers(correctAnswerList);
// 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));
}
use of uk.ac.ed.ph.jqtiplus.types.Identifier in project openolat by klemens.
the class TrueFalseEditorController method commitAssociations.
private void commitAssociations(UserRequest ureq) {
if (restrictedEdit)
return;
temporaryAssociations.clear();
itemBuilder.clearAssociations();
for (SourceWrapper sourceWrapper : sourceWrappers) {
String[] targetParamIds = ureq.getHttpReq().getParameterValues(sourceWrapper.getIdentifierString());
if (targetParamIds != null && targetParamIds.length == 1) {
Identifier sourceChoiceId = sourceWrapper.getIdentifier();
Identifier targetChoiceId = Identifier.assumedLegal(targetParamIds[0]);
itemBuilder.addAssociation(sourceChoiceId, targetChoiceId);
}
}
}
use of uk.ac.ed.ph.jqtiplus.types.Identifier in project openolat by klemens.
the class HotspotChoiceScoreController method sync.
@Override
public void sync(UserRequest ureq, AssessmentItemBuilder assessmentItemBuilder) {
if (itemBuilder == assessmentItemBuilder) {
Set<Identifier> choiceIdentifiers = new HashSet<>();
for (HotspotChoice choice : itemBuilder.getHotspotChoices()) {
HotspotChoiceWrapper wrapper = getHotspotChoiceWrapper(choice);
if (wrapper == null) {
wrappers.add(createHotspotChoiceWrapper(choice));
}
choiceIdentifiers.add(choice.getIdentifier());
}
for (Iterator<HotspotChoiceWrapper> wrapperIt = wrappers.iterator(); wrapperIt.hasNext(); ) {
HotspotChoiceWrapper wrapper = wrapperIt.next();
if (!choiceIdentifiers.contains(wrapper.getChoice().getIdentifier())) {
wrapperIt.remove();
}
}
updateBackground();
}
}
use of uk.ac.ed.ph.jqtiplus.types.Identifier in project openolat by klemens.
the class KPrimEditorController method formOK.
@Override
protected void formOK(UserRequest ureq) {
if (readOnly)
return;
// title
itemBuilder.setTitle(titleEl.getValue());
// question
String questionText = textEl.getRawValue();
itemBuilder.setQuestion(questionText);
// shuffle
if (!restrictedEdit) {
itemBuilder.setShuffle(shuffleEl.isOneSelected() && shuffleEl.isSelected(0));
// alignment
if (alignmentEl.isOneSelected() && alignmentEl.isSelected(1)) {
itemBuilder.addClass(QTI21Constants.CHOICE_ALIGN_RIGHT);
} else {
itemBuilder.removeClass(QTI21Constants.CHOICE_ALIGN_RIGHT);
}
}
// update kprims
for (KprimWrapper choiceWrapper : choiceWrappers) {
SimpleAssociableChoice choice = choiceWrapper.getSimpleChoice();
String answer = choiceWrapper.getAnswer().getRawValue();
itemBuilder.getHtmlHelper().appendHtml(choice, answer);
}
// set associations
if (!restrictedEdit) {
List<SimpleAssociableChoice> choices = new ArrayList<>();
for (KprimWrapper choiceWrapper : choiceWrappers) {
SimpleAssociableChoice choice = choiceWrapper.getSimpleChoice();
Identifier choiceIdentifier = choice.getIdentifier();
String association = ureq.getHttpReq().getParameter(choiceIdentifier.toString());
if ("correct".equals(association)) {
itemBuilder.setAssociation(choiceIdentifier, QTI21Constants.CORRECT_IDENTIFIER);
} else if ("wrong".equals(association)) {
itemBuilder.setAssociation(choiceIdentifier, QTI21Constants.WRONG_IDENTIFIER);
}
choices.add(choice);
}
itemBuilder.setKprimChoices(choices);
}
fireEvent(ureq, new AssessmentItemEvent(AssessmentItemEvent.ASSESSMENT_ITEM_CHANGED, itemBuilder.getAssessmentItem(), QTI21QuestionType.kprim));
}
Aggregations