use of org.olat.ims.qti.editor.beecom.objects.Question in project OpenOLAT by OpenOLAT.
the class QTI12To21Converter method convertKPrim.
private AssessmentItemBuilder convertKPrim(Item item) {
KPrimAssessmentItemBuilder itemBuilder = new KPrimAssessmentItemBuilder("Kprim", "New answer", qtiSerializer);
convertItemBasics(item, itemBuilder);
Question question = item.getQuestion();
itemBuilder.setShuffle(question.isShuffle());
List<Response> responses = question.getResponses();
List<SimpleAssociableChoice> choices = itemBuilder.getKprimChoices();
for (int i = 0; i < 4; i++) {
Response response = responses.get(i);
SimpleAssociableChoice choice = choices.get(i);
String answer = response.getContent().renderAsHtmlForEditor();
answer = blockedHtml(answer);
if (StringHelper.isHtml(answer)) {
htmlBuilder.appendHtml(choice, answer);
} else {
P firstChoiceText = AssessmentItemFactory.getParagraph(choice, answer);
choice.getFlowStatics().clear();
choice.getFlowStatics().add(firstChoiceText);
}
if (response.isCorrect()) {
itemBuilder.setAssociation(choice.getIdentifier(), QTI21Constants.CORRECT_IDENTIFIER);
} else {
itemBuilder.setAssociation(choice.getIdentifier(), QTI21Constants.WRONG_IDENTIFIER);
}
}
double score = question.getMaxValue();
itemBuilder.setMinScore(0.0d);
itemBuilder.setMaxScore(score);
return itemBuilder;
}
use of org.olat.ims.qti.editor.beecom.objects.Question in project OpenOLAT by OpenOLAT.
the class QTI12To21Converter method convertSingleChoice.
private AssessmentItemBuilder convertSingleChoice(Item item) {
SingleChoiceAssessmentItemBuilder itemBuilder = new SingleChoiceAssessmentItemBuilder("Single choice", "New answer", qtiSerializer);
convertItemBasics(item, itemBuilder);
itemBuilder.clearMapping();
itemBuilder.clearSimpleChoices();
itemBuilder.setScoreEvaluationMode(ScoreEvaluation.allCorrectAnswers);
ChoiceInteraction interaction = itemBuilder.getChoiceInteraction();
Question question = item.getQuestion();
itemBuilder.setShuffle(question.isShuffle());
convertOrientation(question, itemBuilder);
List<Response> responses = question.getResponses();
Map<String, Identifier> identToIdentifier = new HashMap<>();
for (Response response : responses) {
String responseText = response.getContent().renderAsHtmlForEditor();
responseText = blockedHtml(responseText);
SimpleChoice newChoice;
if (StringHelper.isHtml(responseText)) {
newChoice = AssessmentItemFactory.createSimpleChoice(interaction, "", itemBuilder.getQuestionType().getPrefix());
htmlBuilder.appendHtml(newChoice, responseText);
} else {
newChoice = AssessmentItemFactory.createSimpleChoice(interaction, responseText, itemBuilder.getQuestionType().getPrefix());
}
itemBuilder.addSimpleChoice(newChoice);
identToIdentifier.put(response.getIdent(), newChoice.getIdentifier());
if (response.isCorrect()) {
itemBuilder.setCorrectAnswer(newChoice.getIdentifier());
}
}
convertFeedbackPerAnswers(item, itemBuilder, identToIdentifier);
double correctScore = question.getSingleCorrectScore();
if (correctScore >= 0.0d) {
itemBuilder.setMinScore(0.0d);
itemBuilder.setMaxScore(correctScore);
}
return itemBuilder;
}
use of org.olat.ims.qti.editor.beecom.objects.Question in project OpenOLAT by OpenOLAT.
the class QTI12To21Converter method convertFIB.
private AssessmentItemBuilder convertFIB(Item item) {
FIBAssessmentItemBuilder itemBuilder = new FIBAssessmentItemBuilder("Gap text", EntryType.text, qtiSerializer);
itemBuilder.setQuestion("");
itemBuilder.clearTextEntries();
convertItemBasics(item, itemBuilder);
Question question = item.getQuestion();
boolean singleCorrect = question.isSingleCorrect();
if (singleCorrect) {
itemBuilder.setScoreEvaluationMode(ScoreEvaluation.allCorrectAnswers);
} else {
itemBuilder.setScoreEvaluationMode(ScoreEvaluation.perAnswer);
}
itemBuilder.getMinScoreBuilder().setScore(new Double(question.getMinValue()));
itemBuilder.getMaxScoreBuilder().setScore(new Double(question.getMaxValue()));
List<Response> responses = question.getResponses();
StringBuilder sb = new StringBuilder();
for (Response response : responses) {
if (response instanceof FIBResponse) {
FIBResponse gap = (FIBResponse) response;
if (FIBResponse.TYPE_BLANK.equals(gap.getType())) {
String responseId = itemBuilder.generateResponseIdentifier();
StringBuilder entryString = new StringBuilder();
entryString.append(" <textentryinteraction responseidentifier=\"").append(responseId).append("\"");
TextEntry entry = itemBuilder.createTextEntry(responseId);
entry.setCaseSensitive("Yes".equals(gap.getCaseSensitive()));
if (gap.getMaxLength() > 0) {
entry.setExpectedLength(gap.getMaxLength());
entryString.append(" expectedlength=\"").append(gap.getMaxLength()).append("\"");
} else if (gap.getSize() > 0) {
entry.setExpectedLength(gap.getSize());
entryString.append(" expectedlength=\"").append(gap.getSize()).append("\"");
}
parseAlternatives(gap.getCorrectBlank(), gap.getPoints(), entry);
entryString.append("></textentryinteraction>");
sb.append(entryString);
} else if (FIBResponse.TYPE_CONTENT.equals(gap.getType())) {
Material text = gap.getContent();
String htmltext = text.renderAsHtmlForEditor();
htmltext = blockedHtml(htmltext);
sb.append(htmltext);
}
}
}
String fib = "<div>" + sb.toString() + "</div>";
itemBuilder.setQuestion(fib);
return itemBuilder;
}
use of org.olat.ims.qti.editor.beecom.objects.Question in project openolat by klemens.
the class QTI12MetadataController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
Question question = item.getQuestion();
FormLayoutContainer layoutCont = (FormLayoutContainer) formLayout;
if (question != null) {
layoutCont.contextPut("hasQuestion", Boolean.TRUE);
// settings
String shuffleStr = translate(question.isShuffle() ? "editor.true" : "editor.false");
uifactory.addStaticTextElement("form.imd.shuffle", shuffleStr, formLayout);
String duration = "";
if (item.getDuration() != null) {
duration = item.getDuration().getMin() + ":" + item.getDuration().getSec();
}
uifactory.addStaticTextElement("form.metadata.duration", duration, formLayout);
if (question instanceof ChoiceQuestion) {
ChoiceQuestion choice = (ChoiceQuestion) question;
if (item.getQuestion().getType() == Question.TYPE_SC) {
String score = Float.toString(question.getSingleCorrectScore());
uifactory.addStaticTextElement("score", score, formLayout);
} else if (item.getQuestion().getType() == Question.TYPE_MC) {
String minVal = Float.toString(choice.getMinValue());
String maxVal = Float.toString(choice.getMaxValue());
uifactory.addStaticTextElement("score.min", minVal, formLayout);
uifactory.addStaticTextElement("score.max", maxVal, formLayout);
}
}
// correct responses
List<Response> responses = question.getResponses();
if (question.getType() == Question.TYPE_MC || question.getType() == Question.TYPE_SC) {
setMCAndSCCorrectResponses(question, responses, layoutCont);
} else if (question.getType() == Question.TYPE_KPRIM) {
setKPrimCorrectResponses(responses, layoutCont);
}
}
// feedbacks
boolean hasFeedbacks = false;
Material masteryMat = QTIEditHelper.getFeedbackMasteryMaterial(item);
if (masteryMat != null) {
layoutCont.contextPut("item_feedback_mastery", masteryMat.renderAsText());
hasFeedbacks = true;
}
Material failureMat = QTIEditHelper.getFeedbackFailMaterial(item);
if (failureMat != null) {
layoutCont.contextPut("item_feedback_fail", failureMat.renderAsText());
hasFeedbacks = true;
}
List<String> responsesFeedback = new ArrayList<>();
if (question != null && question.getType() <= Question.TYPE_MC) {
for (Object obj : question.getResponses()) {
ChoiceResponse response = (ChoiceResponse) obj;
Material responseFeedbackMat = QTIEditHelper.getFeedbackOlatRespMaterial(item, response.getIdent());
if (responseFeedbackMat != null) {
responsesFeedback.add(responseFeedbackMat.renderAsText());
}
}
hasFeedbacks |= responsesFeedback.size() > 0;
}
layoutCont.contextPut("responsesFeedback", responsesFeedback);
layoutCont.contextPut("hasFeedbacks", new Boolean(hasFeedbacks));
}
use of org.olat.ims.qti.editor.beecom.objects.Question in project openolat by klemens.
the class QTIEditorMainController method doCopy.
private void doCopy(UserRequest ureq, TreePosition tp) {
// user chose a position to insert the node to be copied
int targetPos = tp.getChildpos();
ItemNode selectedNode = (ItemNode) menuTree.getSelectedNode();
// only items are moveable
// use XStream instead of ObjectCloner
// Item qtiItem =
// (Item)xstream.fromXML(xstream.toXML(selectedNode.getUnderlyingQTIObject()));
Item toClone = (Item) selectedNode.getUnderlyingQTIObject();
Item qtiItem = (Item) XStreamHelper.xstreamClone(toClone);
// copy flow label class too, olat-2791
Question orgQuestion = toClone.getQuestion();
if (orgQuestion instanceof ChoiceQuestion) {
String flowLabelClass = ((ChoiceQuestion) orgQuestion).getFlowLabelClass();
Question copyQuestion = qtiItem.getQuestion();
if (copyQuestion instanceof ChoiceQuestion) {
((ChoiceQuestion) copyQuestion).setFlowLabelClass(flowLabelClass);
} else {
throw new AssertException("Could not copy flow-label-class, wrong type of copy question , must be 'ChoiceQuestion' but is " + copyQuestion);
}
}
String editorIdentPrefix = "";
if (qtiItem.getIdent().startsWith(ItemParser.ITEM_PREFIX_SCQ))
editorIdentPrefix = ItemParser.ITEM_PREFIX_SCQ;
else if (qtiItem.getIdent().startsWith(ItemParser.ITEM_PREFIX_MCQ))
editorIdentPrefix = ItemParser.ITEM_PREFIX_MCQ;
else if (qtiItem.getIdent().startsWith(ItemParser.ITEM_PREFIX_KPRIM))
editorIdentPrefix = ItemParser.ITEM_PREFIX_KPRIM;
else if (qtiItem.getIdent().startsWith(ItemParser.ITEM_PREFIX_FIB))
editorIdentPrefix = ItemParser.ITEM_PREFIX_FIB;
else if (qtiItem.getIdent().startsWith(ItemParser.ITEM_PREFIX_ESSAY))
editorIdentPrefix = ItemParser.ITEM_PREFIX_ESSAY;
// set new ident... this is all it needs for our engine to recognise it
// as a new item.
qtiItem.setIdent(editorIdentPrefix + CodeHelper.getForeverUniqueID());
// insert into menutree (insert on GenericNode do a remove from parent)
GenericQtiNode parentTargetNode = (GenericQtiNode) tp.getParentTreeNode();
GenericQtiNode newNode = new ItemNode(qtiItem, qtiPackage);
parentTargetNode.insert(newNode, targetPos);
// insert into model
parentTargetNode.insertQTIObjectAt(qtiItem, targetPos);
// activate copied node
menuTree.setSelectedNodeId(newNode.getIdent());
event(ureq, menuTree, new Event(MenuTree.COMMAND_TREENODE_CLICKED));
qtiPackage.serializeQTIDocument();
parentTargetNode.childNodeChanges();
}
Aggregations