use of org.olat.ims.qti.editor.beecom.objects.Material in project OpenOLAT by OpenOLAT.
the class FeedbackFormController method initForm.
/**
* @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#initForm(org.olat.core.gui.components.form.flexible.FormItemContainer,
* org.olat.core.gui.control.Controller, org.olat.core.gui.UserRequest)
*/
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
setFormTitle("fieldset.legend.feedback");
setFormContextHelp("Test and Questionnaire Editor in Detail#details_testeditor_feedback");
FormLayoutContainer switchLayout = FormLayoutContainer.createDefaultFormLayout("switchLayout", getTranslator());
overallFeedbackLayout = FormLayoutContainer.createDefaultFormLayout("overallFeedbackLayout", getTranslator());
responseLevelHintsLayout = FormLayoutContainer.createCustomFormLayout("responseLevelHintsLayout", getTranslator(), Util.getPackageVelocityRoot(this.getClass()) + "/response_level_feedback.html");
// add the layouts to the custom layout
formLayout.add(switchLayout);
formLayout.add(overallFeedbackLayout);
formLayout.add(responseLevelHintsLayout);
String[] yesNoKeys, yesNoValues;
yesNoKeys = new String[] { YES, NO };
yesNoValues = new String[] { translate(YES), translate(NO) };
feedbackSwitch = uifactory.addRadiosHorizontal("feedbackswitch", switchLayout, yesNoKeys, yesNoValues);
feedbackSwitch.addActionListener(FormEvent.ONCLICK);
if (control.isFeedback()) {
feedbackSwitch.select(yesNoKeys[0], true);
} else {
// defaults to 'not showing feedback'
feedbackSwitch.select(yesNoKeys[1], true);
}
responseLevelHintsLayout.contextPut("mediaBaseUrl", mediaBaseUrl);
masteryMat = QTIEditHelper.getFeedbackMasteryMaterial(item);
masteryMat = masteryMat == null ? new Material() : masteryMat;
failureMat = QTIEditHelper.getFeedbackFailMaterial(item);
failureMat = failureMat == null ? new Material() : failureMat;
VFSContainer baseContainer = qtiPackage.getBaseDir();
// Mastery Layout
FormLayoutContainer masteryEditLayout = FormLayoutContainer.createCustomFormLayout("masteryEditLayout", getTranslator(), Util.getPackageVelocityRoot(this.getClass()) + "/rich_text_and_edit_link.html");
masteryEditLayout.setLabel("item_feedback_mastery", null);
overallFeedbackLayout.add(masteryEditLayout);
RichTextElement masteryFeedback = uifactory.addRichTextElementForStringData("richTextElement", "item_feedback_mastery", masteryMat.renderAsHtml(mediaBaseUrl), 4, -1, true, baseContainer, null, masteryEditLayout, ureq.getUserSession(), getWindowControl());
masteryFeedback.getEditorConfiguration().setFigCaption(false);
FormLink editLink = uifactory.addFormLink("editLink", masteryEditLayout, Link.NONTRANSLATED + Link.LINK_CUSTOM_CSS);
editLink.getComponent().setCustomDisplayText(" ");
editLink.getComponent().setIconLeftCSS("o_icon o_icon_edit o_icon-lg qti_edit_link");
registerFeedbackElement(masteryMat, masteryFeedback, editLink);
// One Failure Layout
FormLayoutContainer failureEditLayout = FormLayoutContainer.createCustomFormLayout("failureEditLayout", getTranslator(), Util.getPackageVelocityRoot(this.getClass()) + "/rich_text_and_edit_link.html");
failureEditLayout.setLabel("item_feedback_fail", null);
overallFeedbackLayout.add(failureEditLayout);
RichTextElement failureFeedback = uifactory.addRichTextElementForStringData("richTextElement", "item_feedback_fail", failureMat.renderAsHtml(mediaBaseUrl), 4, -1, true, baseContainer, null, failureEditLayout, ureq.getUserSession(), getWindowControl());
failureFeedback.getEditorConfiguration().setFigCaption(false);
failureFeedback.setLabel("item_feedback_fail", null);
FormLink failureLink = uifactory.addFormLink("editLink", failureEditLayout, Link.NONTRANSLATED + Link.LINK_CUSTOM_CSS);
failureLink.getComponent().setCustomDisplayText("");
failureLink.getComponent().setIconLeftCSS("o_icon o_icon_edit o_icon-lg");
registerFeedbackElement(failureMat, failureFeedback, failureLink);
// Feedback for each response when single or multiple choice question
List<Material> responses = new ArrayList<Material>();
boolean hasResponseLevelHints = false;
if (item.getQuestion().getType() <= Question.TYPE_MC) {
int i = 1;
for (Object obj : item.getQuestion().getResponses()) {
ChoiceResponse response = (ChoiceResponse) obj;
// response-level feedback
Material responseFeedbackMat = QTIEditHelper.getFeedbackOlatRespMaterial(item, response.getIdent());
responseFeedbackMat = responseFeedbackMat == null ? new Material() : responseFeedbackMat;
identities.put(responseFeedbackMat, response.getIdent());
RichTextElement responseHintText = uifactory.addRichTextElementForStringData("feedback_" + i, null, responseFeedbackMat.renderAsHtml(mediaBaseUrl), 4, -1, true, baseContainer, null, responseLevelHintsLayout, ureq.getUserSession(), getWindowControl());
responseHintText.getEditorConfiguration().setFigCaption(false);
FormLink link = uifactory.addFormLink("link_" + i, responseLevelHintsLayout, Link.NONTRANSLATED + Link.LINK_CUSTOM_CSS);
link.getComponent().setCustomDisplayText(" ");
link.getComponent().setIconLeftCSS("o_icon o_icon_edit o_icon-lg");
registerFeedbackElement(responseFeedbackMat, responseHintText, link);
// get response for displaying
Material responseMat = response.getContent();
responses.add(responseMat);
i++;
}
// If 'i' is strictly greater than the initial value, there's at least one
// response.
hasResponseLevelHints = i > 1;
}
flc.contextPut("hasResponseLevelHints", hasResponseLevelHints);
responseLevelHintsLayout.contextPut("responses", responses);
showHideFeedbackFields();
}
use of org.olat.ims.qti.editor.beecom.objects.Material in project OpenOLAT by OpenOLAT.
the class QTI12To21Converter method convertFeedbackPerAnswers.
private void convertFeedbackPerAnswers(Item item, AssessmentItemBuilder itemBuilder, Map<String, Identifier> identToIdentifier) {
Question question = item.getQuestion();
List<ModalFeedbackBuilder> additionalFeedbacks = new ArrayList<>();
for (Response response : question.getResponses()) {
if (response instanceof ChoiceResponse) {
Material responseFeedbackMat = QTIEditHelper.getFeedbackOlatRespMaterial(item, response.getIdent());
if (responseFeedbackMat != null) {
String feedbackCondition = responseFeedbackMat.renderAsHtmlForEditor();
feedbackCondition = blockedHtml(feedbackCondition);
ModalFeedbackCondition condition = new ModalFeedbackCondition();
condition.setVariable(Variable.response);
condition.setOperator(Operator.equals);
condition.setValue(identToIdentifier.get(response.getIdent()).toString());
List<ModalFeedbackCondition> conditions = new ArrayList<>(1);
conditions.add(condition);
ModalFeedbackBuilder feedback = new ModalFeedbackBuilder(itemBuilder.getAssessmentItem(), ModalFeedbackType.additional);
feedback.setFeedbackConditions(conditions);
feedback.setText(feedbackCondition);
additionalFeedbacks.add(feedback);
}
}
}
itemBuilder.setAdditionalFeedbackBuilders(additionalFeedbacks);
}
use of org.olat.ims.qti.editor.beecom.objects.Material in project openolat by klemens.
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.Material in project openolat by klemens.
the class CSVToQuestionConverterTest method importMultipleChoice.
@Test
public void importMultipleChoice() throws IOException, URISyntaxException {
URL importTxtUrl = CSVToQuestionConverterTest.class.getResource("question_import_mc.txt");
Assert.assertNotNull(importTxtUrl);
File importTxt = new File(importTxtUrl.toURI());
String input = FileUtils.readFileToString(importTxt, "UTF-8");
Translator translator = new KeyTranslator(Locale.ENGLISH);
ImportOptions options = new ImportOptions();
options.setShuffle(true);
CSVToQuestionConverter converter = new CSVToQuestionConverter(translator, options);
converter.parse(input);
List<ItemAndMetadata> items = converter.getItems();
Assert.assertNotNull(items);
Assert.assertEquals(1, items.size());
ItemAndMetadata importedItem = items.get(0);
Item item = importedItem.getItem();
Assert.assertNotNull(item);
Assert.assertEquals("Fussball: Austragungsort", item.getTitle());
Assert.assertEquals("Die Fussball WM wird alle vier Jahre von einem anderen Land ausgerichtet.", item.getObjectives());
Assert.assertEquals(Question.TYPE_MC, item.getQuestion().getType());
Assert.assertTrue(item.getQuestion() instanceof ChoiceQuestion);
Material questionMat = item.getQuestion().getQuestion();
Assert.assertNotNull(questionMat);
Assert.assertNotNull(questionMat.getElements());
Assert.assertEquals(1, questionMat.getElements().size());
QTIObject questionMatEl = questionMat.getElements().get(0);
Assert.assertTrue(questionMatEl instanceof Mattext);
String text = ((Mattext) questionMatEl).getContent();
Assert.assertEquals("In welchen L\u00E4ndern wurde zwischen dem Jahr 2000 und 2015 eine Fussball Weltmeisterschaft ausgetragen?", text);
ChoiceQuestion question = (ChoiceQuestion) item.getQuestion();
Assert.assertNotNull(question.getResponses());
Assert.assertEquals(7, question.getResponses().size());
List<Response> responses = question.getResponses();
Assert.assertEquals(1.0f, responses.get(0).getPoints(), 0.0001);
Assert.assertEquals(1.0f, responses.get(1).getPoints(), 0.0001);
Assert.assertEquals(1.0f, responses.get(2).getPoints(), 0.0001);
Assert.assertEquals(-1.0f, responses.get(3).getPoints(), 0.0001);
Assert.assertEquals(-1.0f, responses.get(4).getPoints(), 0.0001);
Assert.assertEquals(-1.0f, responses.get(5).getPoints(), 0.0001);
Assert.assertEquals(-1.0f, responses.get(6).getPoints(), 0.0001);
// after it will be set to true for all of them
Assert.assertTrue(responses.get(0).isCorrect());
Assert.assertTrue(responses.get(1).isCorrect());
Assert.assertTrue(responses.get(2).isCorrect());
Assert.assertFalse(responses.get(3).isCorrect());
Assert.assertFalse(responses.get(4).isCorrect());
Assert.assertFalse(responses.get(5).isCorrect());
Assert.assertFalse(responses.get(6).isCorrect());
String feedbackMastery = QTIEditHelper.getFeedbackMasteryText(item);
Assert.assertEquals("Bravo! Die Antwort ich absolut korrekt.", feedbackMastery);
String feedbackFail = QTIEditHelper.getFeedbackFailText(item);
Assert.assertEquals("Leider falsch. Probieren Sie es noch einmal.", feedbackFail);
}
use of org.olat.ims.qti.editor.beecom.objects.Material in project openolat by klemens.
the class CSVToQuestionConverter method processQuestion.
private void processQuestion(String[] parts) {
if (currentItem == null)
return;
Question question = currentItem.getItem().getQuestion();
Material mat = question.getQuestion();
String content = parts[1];
Mattext matText = new Mattext(content);
List<QTIObject> elements = new ArrayList<QTIObject>(1);
elements.add(matText);
mat.setElements(elements);
}
Aggregations