use of org.olat.ims.qti.editor.beecom.objects.Mattext in project openolat by klemens.
the class QTIEditHelper method createFIBItem.
/**
* Creates a new FIB item
* @param trans
* @return New fib item.
*/
public static Item createFIBItem(Translator trans) {
// create item
Item newItem = new Item();
newItem.setIdent(EDITOR_IDENT + ":" + ITEM_TYPE_FIB + ":" + String.valueOf(CodeHelper.getRAMUniqueID()));
newItem.setTitle(trans.translate("editor.newquestion"));
newItem.setLabel("");
// conrols
Control control = new Control();
List<Control> controls = new ArrayList<Control>();
controls.add(control);
newItem.setItemcontrols(controls);
QTIEditHelper.setFeedbackMastery(newItem, "");
QTIEditHelper.setFeedbackFail(newItem, "");
FIBQuestion fibquestion = new FIBQuestion();
fibquestion.getQuestion().getElements().add(new Mattext(trans.translate("editor.newquestiontext")));
fibquestion.setSingleCorrect(true);
fibquestion.setSingleCorrectScore(1);
FIBResponse response = new FIBResponse();
response.setType(FIBResponse.TYPE_CONTENT);
Material mat = new Material();
mat.add(new Mattext(trans.translate("editor.newtextelement")));
response.setContent(mat);
fibquestion.getResponses().add(response);
newItem.setQuestion(fibquestion);
return newItem;
}
use of org.olat.ims.qti.editor.beecom.objects.Mattext 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.Mattext 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.Mattext in project openolat by klemens.
the class ChoiceItemController method event.
/**
* @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest,
* org.olat.core.gui.components.Component, org.olat.core.gui.control.Event)
*/
@Override
public void event(UserRequest ureq, Component source, Event event) {
if (source == main) {
// olat::: as: improve easy fix since almost all operations change the main vc.
main.setDirty(true);
String cmd = event.getCommand();
String sPosid = ureq.getParameter("posid");
int posid = 0;
if (sPosid != null)
posid = Integer.parseInt(sPosid);
if (cmd == null) {
// ignore null cmd
} else if (cmd.equals("up")) {
if (posid > 0) {
List<Response> elements = item.getQuestion().getResponses();
Response obj = elements.remove(posid);
elements.add(posid - 1, obj);
}
} else if (cmd.equals("down")) {
List<Response> elements = item.getQuestion().getResponses();
if (posid < elements.size() - 1) {
Response obj = elements.remove(posid);
elements.add(posid + 1, obj);
}
} else if (cmd.equals("editq")) {
editQuestion = item.getQuestion().getQuestion();
displayMaterialFormController(ureq, editQuestion, restrictedEdit, translate("fieldset.legend.question"));
} else if (cmd.equals("editr")) {
List<Response> elements = item.getQuestion().getResponses();
if (posid >= 0 && posid < elements.size()) {
editResponse = elements.get(posid);
Material responseMat = editResponse.getContent();
displayMaterialFormController(ureq, responseMat, restrictedEdit, translate("fieldset.legend.answers"));
}
} else if (cmd.equals("addchoice")) {
ChoiceQuestion question = (ChoiceQuestion) item.getQuestion();
List<Response> choices = question.getResponses();
ChoiceResponse newChoice = new ChoiceResponse();
newChoice.getContent().add(new Mattext(translate("newresponsetext")));
newChoice.setCorrect(false);
// default value is negative to make sure
newChoice.setPoints(-1f);
// people understand the meaning of this value
choices.add(newChoice);
} else if (cmd.equals("del")) {
delYesNoCtrl = DialogBoxUIFactory.createYesNoDialog(ureq, getWindowControl(), null, translate("confirm.delete.element"));
listenTo(delYesNoCtrl);
delYesNoCtrl.setUserObject(new Integer(posid));
delYesNoCtrl.activate();
} else if (cmd.equals("ssc")) {
// submit sc
if (!restrictedEdit) {
ChoiceQuestion question = (ChoiceQuestion) item.getQuestion();
List<Response> q_choices = question.getResponses();
String correctChoice = ureq.getParameter("correctChoice");
for (int i = 0; i < q_choices.size(); i++) {
ChoiceResponse choice = (ChoiceResponse) q_choices.get(i);
if (correctChoice != null && correctChoice.equals("value_q" + i)) {
choice.setCorrect(true);
} else {
choice.setCorrect(false);
}
choice.setPoints(ureq.getParameter("points_q" + i));
}
String score = ureq.getParameter("single_score");
float sc;
try {
sc = Float.parseFloat(score);
if (sc <= 0.0001f) {
getWindowControl().setWarning(translate("editor.info.mc.zero.points"));
}
} catch (Exception e) {
getWindowControl().setWarning(translate("editor.info.mc.zero.points"));
sc = 1.0f;
}
question.setSingleCorrectScore(sc);
}
} else if (cmd.equals("smc")) {
// submit mc
if (!restrictedEdit) {
ChoiceQuestion question = (ChoiceQuestion) item.getQuestion();
List<Response> choices = question.getResponses();
boolean hasZeroPointChoice = false;
for (int i = 0; i < choices.size(); i++) {
ChoiceResponse choice = (ChoiceResponse) choices.get(i);
if (ureq.getParameter("value_q" + i) != null && ureq.getParameter("value_q" + i).equalsIgnoreCase("true")) {
choice.setCorrect(true);
} else {
choice.setCorrect(false);
}
choice.setPoints(ureq.getParameter("points_q" + i));
if (choice.getPoints() == 0)
hasZeroPointChoice = true;
}
if (hasZeroPointChoice && !question.isSingleCorrect()) {
getWindowControl().setInfo(translate("editor.info.mc.zero.points"));
}
// set min/max before single_correct score
// will be corrected by single_correct score afterwards
question.setMinValue(ureq.getParameter("min_value"));
question.setMaxValue(ureq.getParameter("max_value"));
question.setSingleCorrect(ureq.getParameter("valuation_method").equals("single"));
if (question.isSingleCorrect()) {
question.setSingleCorrectScore(ureq.getParameter("single_score"));
} else {
question.setSingleCorrectScore(0);
}
}
} else if (cmd.equals("skprim")) {
// submit kprim
if (!restrictedEdit) {
float maxValue = 0;
try {
maxValue = Float.parseFloat(ureq.getParameter("max_value"));
} catch (NumberFormatException e) {
// invalid input, set maxValue 0
}
ChoiceQuestion question = (ChoiceQuestion) item.getQuestion();
List<Response> q_choices = question.getResponses();
for (int i = 0; i < q_choices.size(); i++) {
String correctChoice = ureq.getParameter("correctChoice_q" + i);
ChoiceResponse choice = (ChoiceResponse) q_choices.get(i);
choice.setPoints(maxValue / 4);
if ("correct".equals(correctChoice)) {
choice.setCorrect(true);
} else {
choice.setCorrect(false);
}
}
question.setMaxValue(maxValue);
}
}
qtiPackage.serializeQTIDocument();
}
}
use of org.olat.ims.qti.editor.beecom.objects.Mattext in project openolat by klemens.
the class MaterialFormController method formOK.
/**
* @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#formOK(org.olat.core.gui.UserRequest)
*/
@Override
protected void formOK(UserRequest ureq) {
// trust authors, don't to XSS filtering
String newHtml = richText.getRawValue();
// the text fragment is saved in a cdata, remove cdata from movie plugin
newHtml = newHtml.replace("// <![CDATA[", "").replace("// ]]>", "");
// Use explicit return which create a P tag if you want a line break.
if (newHtml.startsWith("<br />") && newHtml.length() > 6)
newHtml = newHtml.substring(6);
if (newHtml.endsWith("<br />") && newHtml.length() > 6)
newHtml = newHtml.substring(0, newHtml.length() - 6);
// Remove any conditional comments due to strange behavior in test (OLAT-4518)
Filter conditionalCommentFilter = FilterFactory.getConditionalHtmlCommentsFilter();
newHtml = conditionalCommentFilter.filter(newHtml);
//
if (htmlContent.equals(newHtml)) {
// No changes. Cancel editing.
fireEvent(ureq, Event.CANCELLED_EVENT);
} else {
if (isRestrictedEditMode) {
// In restricted edit mode, if the content has changed, write a memento
// (by firing the before change event).
QTIObjectBeforeChangeEvent qobce = new QTIObjectBeforeChangeEvent();
qobce.init(mat.getId(), htmlContent);
fireEvent(ureq, qobce);
}
// Collect the content of all MatElements in a single text element
// (text/html) and save it (for Material objects with multiple elements
// such as images, videos, text, breaks, etc. this can be regarded as
// "lazy migration" to the new rich text style).
Mattext textHtml = new Mattext(newHtml);
// A single text/html element will be left over.
List<QTIObject> elements = new ArrayList<QTIObject>(1);
elements.add(textHtml);
mat.setElements(elements);
fireEvent(ureq, Event.DONE_EVENT);
}
}
Aggregations