use of org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion in project OpenOLAT by OpenOLAT.
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.ChoiceQuestion 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.ChoiceQuestion in project openolat by klemens.
the class QTIEditHelper method createKPRIMItem.
/**
* Creates a new Kprim item
* @param trans
* @return New Kprim item.
*/
public static Item createKPRIMItem(Translator trans) {
// create item
Item newItem = new Item();
newItem.setIdent(EDITOR_IDENT + ":" + ITEM_TYPE_KPRIM + ":" + String.valueOf(CodeHelper.getRAMUniqueID()));
newItem.setTitle(trans.translate("editor.newquestion"));
newItem.setLabel("");
// controls
Control control = new Control();
List<Control> controls = new ArrayList<Control>();
controls.add(control);
newItem.setItemcontrols(controls);
// prepare question
float maxValue = 1;
ChoiceQuestion question = new ChoiceQuestion();
question.setLable(trans.translate("editor.newquestion"));
question.getQuestion().getElements().add(new Mattext(trans.translate("editor.newquestiontext")));
question.setType(Question.TYPE_KPRIM);
question.setSingleCorrect(false);
// Kprim has always 4 answers, each of them score 1/4 of the maximum value
ChoiceResponse newChoice = new ChoiceResponse();
newChoice.getContent().add(new Mattext(trans.translate("editor.newresponsetext")));
newChoice.setCorrect(false);
newChoice.setPoints(maxValue / 4);
question.getResponses().add(newChoice);
ChoiceResponse newChoice2 = new ChoiceResponse();
newChoice2.getContent().add(new Mattext(trans.translate("editor.newresponsetext")));
newChoice2.setCorrect(false);
newChoice2.setPoints(maxValue / 4);
question.getResponses().add(newChoice2);
ChoiceResponse newChoice3 = new ChoiceResponse();
newChoice3.getContent().add(new Mattext(trans.translate("editor.newresponsetext")));
newChoice3.setCorrect(false);
newChoice3.setPoints(maxValue / 4);
question.getResponses().add(newChoice3);
ChoiceResponse newChoice4 = new ChoiceResponse();
newChoice4.getContent().add(new Mattext(trans.translate("editor.newresponsetext")));
newChoice4.setCorrect(false);
newChoice4.setPoints(maxValue / 4);
question.getResponses().add(newChoice4);
question.setMaxValue(maxValue);
newItem.setQuestion(question);
QTIEditHelper.setFeedbackMastery(newItem, "");
QTIEditHelper.setFeedbackFail(newItem, "");
return newItem;
}
use of org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion in project openolat by klemens.
the class QTIEditHelper method createSCItem.
/**
* Creates a new Single Choice item
* @param trans
* @return New Singe Choice item.
*/
public static Item createSCItem(Translator trans) {
Item newItem = new Item();
newItem.setIdent(EDITOR_IDENT + ":" + ITEM_TYPE_SC + ":" + String.valueOf(CodeHelper.getRAMUniqueID()));
newItem.setTitle(trans.translate("editor.newquestion"));
newItem.setLabel("");
// controls
Control control = new Control();
List<Control> controls = new ArrayList<Control>();
controls.add(control);
newItem.setItemcontrols(controls);
// pepare question
ChoiceQuestion question = new ChoiceQuestion();
question.setLable(trans.translate("editor.newquestion"));
question.getQuestion().getElements().add(new Mattext(trans.translate("editor.newquestiontext")));
question.setType(Question.TYPE_SC);
question.setSingleCorrect(true);
question.setSingleCorrectScore(1);
ChoiceResponse newChoice = new ChoiceResponse();
newChoice.setCorrect(true);
newChoice.getContent().add(new Mattext(trans.translate("editor.newresponsetext")));
question.getResponses().add(newChoice);
QTIEditHelper.setFeedbackMastery(newItem, "");
QTIEditHelper.setFeedbackFail(newItem, "");
newItem.setQuestion(question);
return newItem;
}
use of org.olat.ims.qti.editor.beecom.objects.ChoiceQuestion 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