use of org.olat.ims.qti.editor.beecom.objects.Control in project OpenOLAT by OpenOLAT.
the class ItemMetadataFormController method formOK.
/**
* @see org.olat.core.gui.components.form.flexible.impl.FormBasicController#formOK(org.olat.core.gui.UserRequest)
*/
protected void formOK(UserRequest ureq) {
// Fire Change Event
String newTitle = title.getValue();
String oldTitle = item.getTitle();
boolean hasTitleChange = newTitle != null && !newTitle.equals(oldTitle);
// trust authors, don't do XSS filtering
String newObjectives = desc.getRawValue();
// Remove any conditional comments due to strange behavior in test (OLAT-4518)
Filter conditionalCommentFilter = FilterFactory.getConditionalHtmlCommentsFilter();
newObjectives = conditionalCommentFilter.filter(newObjectives);
String oldObjectives = item.getObjectives();
boolean hasObjectivesChange = newObjectives != null && !newObjectives.equals(oldObjectives);
NodeBeforeChangeEvent nce = new NodeBeforeChangeEvent();
if (hasTitleChange) {
nce.setNewTitle(newTitle);
}
if (hasObjectivesChange) {
nce.setNewObjectives(newObjectives);
}
if (hasTitleChange || hasObjectivesChange) {
// create a memento first
nce.setItemIdent(item.getIdent());
nce.setQuestionIdent(item.getQuestion().getQuestion().getId());
fireEvent(ureq, nce);
}
// Update item
item.setTitle(newTitle);
// trust authors, don't to XSS filtering
item.setObjectives(newObjectives);
Question q = item.getQuestion();
if (layout != null && q instanceof ChoiceQuestion) {
((ChoiceQuestion) q).setFlowLabelClass("h".equals(layout.getSelectedKey()) ? ChoiceQuestion.BLOCK : ChoiceQuestion.LIST);
}
if (!isSurvey && !isRestrictedEditMode) {
q.setShuffle(shuffle.getSelected() == 0);
Control itemControl = item.getItemcontrols().get(0);
itemControl.setFeedback(itemControl.getFeedback() == Control.CTRL_UNDEF ? Control.CTRL_NO : itemControl.getFeedback());
itemControl.setHint(showHints.getSelected() == 0 ? Control.CTRL_YES : Control.CTRL_NO);
itemControl.setSolution(showSolution.getSelected() == 0 ? Control.CTRL_YES : Control.CTRL_NO);
String hintRawValue = hint.getRawValue();
// trust authors, don't to XSS filtering
q.setHintText(conditionalCommentFilter.filter(hintRawValue));
String solutionRawValue = solution.getRawValue();
// trust authors, don't to XSS filtering
q.setSolutionText(conditionalCommentFilter.filter(solutionRawValue));
if (limitTime.getSelectedKey().equals("y")) {
item.setDuration(new Duration(1000 * timeSec.getIntValue() + 1000 * 60 * timeMin.getIntValue()));
} else {
item.setDuration(null);
}
if (limitAttempts.getSelectedKey().equals("y")) {
item.setMaxattempts(attempts.getIntValue());
} else {
item.setMaxattempts(0);
}
}
fireEvent(ureq, Event.DONE_EVENT);
}
use of org.olat.ims.qti.editor.beecom.objects.Control in project OpenOLAT by OpenOLAT.
the class AssessmentParser method parse.
/**
* @see org.olat.ims.qti.editor.beecom.IParser#parse(org.dom4j.Element)
*/
public Object parse(Element element) {
// assert element.getName().equalsIgnoreCase("assessment");
Assessment assessment = new Assessment();
// attributes
Attribute attr = element.attribute("ident");
if (attr != null)
assessment.setIdent(attr.getValue());
attr = element.attribute("title");
if (attr != null)
assessment.setTitle(attr.getValue());
// elements
// DURATION
QTIObject duration = (QTIObject) parserManager.parse(element.element("duration"));
assessment.setDuration(duration);
// ASSESSMENTCONTROL
List assessmentcontrolsXML = element.elements("assessmentcontrol");
List assessmentcontrols = new ArrayList();
for (Iterator i = assessmentcontrolsXML.iterator(); i.hasNext(); ) {
assessmentcontrols.add(parserManager.parse((Element) i.next()));
assessment.setInheritControls(true);
}
if (assessmentcontrols.size() == 0) {
assessmentcontrols.add(new Control());
assessment.setInheritControls(false);
}
assessment.setAssessmentcontrols(assessmentcontrols);
// OUTCOMES PROCESSING
OutcomesProcessing outcomesProcessing = (OutcomesProcessing) parserManager.parse(element.element("outcomes_processing"));
if (outcomesProcessing != null)
assessment.setOutcomes_processing(outcomesProcessing);
// SELECTION ORDERING
SelectionOrdering selectionOrdering = (SelectionOrdering) parserManager.parse(element.element("selection_ordering"));
if (selectionOrdering != null) {
assessment.setSelection_ordering(selectionOrdering);
} else {
assessment.setSelection_ordering(new SelectionOrdering());
}
// SECTIONS
List sectionsXML = element.elements("section");
List sections = new ArrayList();
for (Iterator i = sectionsXML.iterator(); i.hasNext(); ) {
sections.add(parserManager.parse((Element) i.next()));
}
assessment.setSections(sections);
// ITEMS
List itemsXML = element.elements("item");
List items = new ArrayList();
for (Iterator i = itemsXML.iterator(); i.hasNext(); ) {
items.add(parserManager.parse((Element) i.next()));
}
assessment.setItems(items);
// OBJECTIVES
Element mattext = (Element) element.selectSingleNode("./objectives/material/mattext");
if (mattext != null)
assessment.setObjectives(mattext.getTextTrim());
// METADATA
Metadata metadata = (Metadata) parserManager.parse(element.element("qtimetadata"));
if (metadata != null)
assessment.setMetadata(metadata);
return assessment;
}
use of org.olat.ims.qti.editor.beecom.objects.Control in project OpenOLAT by OpenOLAT.
the class SectionParser method parse.
public Object parse(Element element) {
// assert element.getName().equalsIgnoreCase("questestinterop");
Section section = new Section();
// attributes
section.setIdent(element.attribute("ident").getValue());
section.setTitle(element.attribute("title").getValue());
// elements
// DURATION
Duration duration = (Duration) parserManager.parse(element.element("duration"));
section.setDuration(duration);
List sectioncontrolsXML = element.elements("sectioncontrol");
List<Object> sectioncontrols = new ArrayList<>();
for (Iterator i = sectioncontrolsXML.iterator(); i.hasNext(); ) {
sectioncontrols.add(parserManager.parse((Element) i.next()));
}
if (sectioncontrols.size() == 0) {
sectioncontrols.add(new Control());
}
section.setSectioncontrols(sectioncontrols);
// SELECTION ORDERING
SelectionOrdering selectionOrdering = (SelectionOrdering) parserManager.parse(element.element("selection_ordering"));
if (selectionOrdering != null) {
section.setSelection_ordering(selectionOrdering);
} else {
section.setSelection_ordering(new SelectionOrdering());
}
// SECTIONS
List sectionsXML = element.elements("section");
List<Object> sections = new ArrayList<>();
for (Iterator i = sectionsXML.iterator(); i.hasNext(); ) {
sections.add(parserManager.parse((Element) i.next()));
}
section.setSections(sections);
// ITEMS
List itemsXML = element.elements("item");
List<Object> items = new ArrayList<>();
for (Iterator i = itemsXML.iterator(); i.hasNext(); ) {
items.add(parserManager.parse((Element) i.next()));
}
section.setItems(items);
// OBJECTIVES
Element mattext = (Element) element.selectSingleNode("./objectives/material/mattext");
if (mattext != null)
section.setObjectives(mattext.getTextTrim());
// FEEDBACKS
List feedbacksXML = element.elements("sectionfeedback");
List<QTIObject> feedbacks = new ArrayList<>();
for (Iterator i = feedbacksXML.iterator(); i.hasNext(); ) {
QTIObject tmp = (QTIObject) parserManager.parse((Element) i.next());
feedbacks.add(tmp);
}
section.setSectionfeedbacks(feedbacks);
// OUTCOMES_PROCESSING
// TODO: maybe we should use the OutcomesProcessing object and parser here? Same as on
// assessment level?
QTIObject outcomes_processing = (QTIObject) parserManager.parse(element.element("outcomes_processing"));
section.setOutcomes_processing(outcomes_processing);
return section;
}
use of org.olat.ims.qti.editor.beecom.objects.Control in project OpenOLAT by OpenOLAT.
the class ItemNode method createMemento.
public Memento createMemento() {
Question question = item.getQuestion();
// special case switches as question types are encoded into integers!!
boolean isFIB = question.getType() == Question.TYPE_FIB;
boolean isESSAY = question.getType() == Question.TYPE_ESSAY;
// Item metadata
QtiNodeMemento qnm = new QtiNodeMemento();
Map<String, Object> qtiState = new HashMap<>();
qtiState.put("ID", item.getIdent());
qtiState.put("TITLE", item.getTitle());
qtiState.put("OBJECTIVES", item.getObjectives());
// question and responses
qtiState.put("QUESTION.ID", question.getIdent());
qtiState.put("QUESTION.HINTTEXT", question.getHintText());
Material questMaterial = question.getQuestion();
qtiState.put("QUESTION.MATERIAL.ASTEXT", questMaterial.renderAsText());
List<String> ids = new ArrayList<String>();
List<String> asTexts = new ArrayList<String>();
List<String> feedbacks = new ArrayList<String>();
List<Response> responses = question.getResponses();
for (Iterator<Response> iter = responses.iterator(); iter.hasNext(); ) {
Response resp = iter.next();
if (isFIB) {
if (FIBResponse.TYPE_BLANK.equals(((FIBResponse) resp).getType())) {
asTexts.add(formatFIBResponseAsText((FIBResponse) resp));
ids.add(resp.getIdent());
feedbacks.add(QTIEditHelper.getFeedbackOlatRespText(item, resp.getIdent()));
}
} else if (isESSAY) {
asTexts.add(formatESSAYResponseAsText((EssayResponse) resp));
ids.add(resp.getIdent());
feedbacks.add(QTIEditHelper.getFeedbackOlatRespText(item, resp.getIdent()));
} else {
// not a FIB or ESSAY response
asTexts.add(resp.getContent().renderAsText());
ids.add(resp.getIdent());
feedbacks.add(QTIEditHelper.getFeedbackOlatRespText(item, resp.getIdent()));
}
}
qtiState.put("QUESTION.RESPONSES.IDS", ids);
qtiState.put("QUESTION.RESPONSES.ASTEXT", asTexts);
qtiState.put("QUESTION.RESPONSES.FEEDBACK", feedbacks);
// feedback
qtiState.put("FEEDBACK.MASTERY", QTIEditHelper.getFeedbackMasteryText(item));
qtiState.put("FEEDBACK.FAIL", QTIEditHelper.getFeedbackFailText(item));
Control control = QTIEditHelper.getControl(item);
qtiState.put("FEEDBACK.ENABLED", control.getFeedback() == 1 ? Boolean.TRUE : Boolean.FALSE);
//
qnm.setQtiState(qtiState);
//
return qnm;
}
use of org.olat.ims.qti.editor.beecom.objects.Control in project OpenOLAT by OpenOLAT.
the class QTI12To21Converter method convert.
public AssessmentTest convert(VFSContainer originalContainer, QTIDocument doc, QTI21DeliveryOptions qti21Options) throws URISyntaxException {
Assessment assessment = doc.getAssessment();
AssessmentTest assessmentTest = new AssessmentTest();
String assessmentTestIdentifier = IdentifierGenerator.newAssessmentTestFilename();
File testFile = new File(unzippedDirRoot, assessmentTestIdentifier + ".xml");
manifest.appendAssessmentTest(testFile.getName());
assessmentTest.setIdentifier(assessmentTestIdentifier);
assessmentTest.setTitle(assessment.getTitle());
assessmentTest.setToolName(QTI21Constants.TOOLNAME);
assessmentTest.setToolVersion(Settings.getVersion());
convertDuration((Duration) assessment.getDuration(), assessmentTest);
TestPart testPart = AssessmentTestFactory.createTestPart(assessmentTest);
ItemSessionControl itemSessionControl = testPart.getItemSessionControl();
Control tmpControl = QTIEditHelper.getControl(assessment);
if (tmpControl.getSolution() == Control.CTRL_YES) {
itemSessionControl.setShowSolution(Boolean.TRUE);
}
if (qti21Options != null) {
qti21Options.setHideFeedbacks(false);
if (assessment.isInheritControls() && tmpControl.getFeedback() != Control.CTRL_YES) {
qti21Options.setHideFeedbacks(true);
}
}
AssessmentTestBuilder assessmentTestBuilder = new AssessmentTestBuilder(assessmentTest);
// root
List<Section> sections = assessment.getSections();
for (Section section : sections) {
convert(section, testPart);
}
// this are lost in QTI 2.1
// assessment.getSelection_ordering().getOrderType();
// assessment.getSelection_ordering().getSelectionNumber();
OutcomesProcessing outcomesProcessing = assessment.getOutcomes_processing();
if (outcomesProcessing != null) {
String cutValue = outcomesProcessing.getField(OutcomesProcessing.CUTVALUE);
if (StringHelper.containsNonWhitespace(cutValue)) {
try {
assessmentTestBuilder.setCutValue(Double.valueOf(cutValue));
} catch (NumberFormatException e) {
log.error("Cannot parse cut value: " + cutValue, e);
}
}
}
assessmentTestBuilder.setMaxScore(atomicMaxScore.doubleValue());
assessmentTest = assessmentTestBuilder.build();
persistAssessmentObject(testFile, assessmentTest);
manifest.write(new File(unzippedDirRoot, "imsmanifest.xml"));
copyMaterial(originalContainer);
return assessmentTest;
}
Aggregations