use of uk.ac.ed.ph.jqtiplus.node.content.basic.TextRun in project openolat by klemens.
the class AssessmentItemFactory method appendMatchInteractionForKPrim.
public static MatchInteraction appendMatchInteractionForKPrim(ItemBody itemBody, Identifier responseDeclarationId, String defaultAnswer) {
MatchInteraction matchInteraction = new MatchInteraction(itemBody);
matchInteraction.setResponseIdentifier(responseDeclarationId);
matchInteraction.setMaxAssociations(4);
matchInteraction.setShuffle(false);
itemBody.getBlocks().add(matchInteraction);
PromptGroup prompts = new PromptGroup(matchInteraction);
matchInteraction.getNodeGroups().add(prompts);
SimpleMatchSet questionMatchSet = new SimpleMatchSet(matchInteraction);
matchInteraction.getSimpleMatchSets().add(questionMatchSet);
String[] classic = new String[] { "a", "b", "c", "d" };
for (int i = 0; i < 4; i++) {
SimpleAssociableChoice correctChoice = new SimpleAssociableChoice(questionMatchSet);
correctChoice.setMatchMax(1);
correctChoice.setMatchMin(1);
correctChoice.setIdentifier(IdentifierGenerator.newNumberAsIdentifier(classic[i]));
P question = getParagraph(correctChoice, defaultAnswer + " " + classic[i]);
correctChoice.getFlowStatics().add(question);
questionMatchSet.getSimpleAssociableChoices().add(correctChoice);
}
SimpleMatchSet correctWrongMatchSet = new SimpleMatchSet(matchInteraction);
matchInteraction.getSimpleMatchSets().add(correctWrongMatchSet);
SimpleAssociableChoice correctChoice = new SimpleAssociableChoice(correctWrongMatchSet);
correctChoice.setMatchMax(4);
correctChoice.setFixed(Boolean.TRUE);
correctChoice.setIdentifier(QTI21Constants.CORRECT_IDENTIFIER);
correctChoice.getFlowStatics().add(new TextRun(correctChoice, "+"));
correctWrongMatchSet.getSimpleAssociableChoices().add(correctChoice);
SimpleAssociableChoice wrongChoice = new SimpleAssociableChoice(correctWrongMatchSet);
wrongChoice.setMatchMax(4);
wrongChoice.setFixed(Boolean.TRUE);
wrongChoice.setIdentifier(QTI21Constants.WRONG_IDENTIFIER);
wrongChoice.getFlowStatics().add(new TextRun(correctChoice, "-"));
correctWrongMatchSet.getSimpleAssociableChoices().add(wrongChoice);
return matchInteraction;
}
use of uk.ac.ed.ph.jqtiplus.node.content.basic.TextRun in project openolat by klemens.
the class AssessmentItemFactory method appendHottext.
public static Hottext appendHottext(P parent, Identifier responseId, String text) {
Hottext hottext = new Hottext(parent);
hottext.setIdentifier(responseId);
hottext.getInlineStatics().add(new TextRun(hottext, text));
parent.getInlines().add(hottext);
return hottext;
}
use of uk.ac.ed.ph.jqtiplus.node.content.basic.TextRun in project openolat by klemens.
the class AssessmentItemFactory method getParagraph.
public static P getParagraph(QtiNode parent, String content) {
P paragraph = new P(parent);
TextRun text = new TextRun(paragraph, content);
paragraph.getInlines().add(text);
return paragraph;
}
use of uk.ac.ed.ph.jqtiplus.node.content.basic.TextRun in project openolat by klemens.
the class AssessmentObjectComponentRenderer method renderMath.
protected void renderMath(AssessmentRenderer renderer, StringOutput out, AssessmentObjectComponent component, ResolvedAssessmentItem resolvedAssessmentItem, ItemSessionState itemSessionState, QtiNode mathElement) {
if (mathElement instanceof ForeignElement) {
ForeignElement fElement = (ForeignElement) mathElement;
boolean mi = fElement.getQtiClassName().equals("mi");
boolean ci = fElement.getQtiClassName().equals("ci");
if (ci || mi) {
AssessmentItem assessmentItem = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful();
String text = contentAsString(fElement);
Identifier identifier = Identifier.assumedLegal(text);
Value templateValue = getTemplateValue(itemSessionState, text);
Value outcomeValue = getOutcomeValue(itemSessionState, text);
Value responseValue = getResponseValue(assessmentItem, itemSessionState, identifier, renderer.isSolutionMode());
if (templateValue != null && isTemplateDeclarationAMathVariable(assessmentItem, text)) {
if (ci) {
substituteCi(out, templateValue);
} else if (mi) {
substituteMi(out, templateValue);
}
} else if (outcomeValue != null) {
if (ci) {
substituteCi(out, outcomeValue);
} else if (mi) {
substituteMi(out, outcomeValue);
}
} else if (responseValue != null) {
if (ci) {
substituteCi(out, responseValue);
} else if (mi) {
substituteMi(out, responseValue);
}
} else {
renderStartHtmlTag(out, component, resolvedAssessmentItem, fElement, null);
fElement.getChildren().forEach((child) -> renderMath(renderer, out, component, resolvedAssessmentItem, itemSessionState, child));
renderEndTag(out, fElement);
}
} else {
renderStartHtmlTag(out, component, resolvedAssessmentItem, fElement, null);
fElement.getChildren().forEach((child) -> renderMath(renderer, out, component, resolvedAssessmentItem, itemSessionState, child));
renderEndTag(out, fElement);
}
} else if (mathElement instanceof TextRun) {
out.append(((TextRun) mathElement).getTextContent());
}
}
Aggregations