use of uk.ac.ed.ph.jqtiplus.node.content.variable.RubricBlock in project OpenOLAT by OpenOLAT.
the class BigAssessmentTestPackageBuilder method createAssessmentTest.
@Test
public void createAssessmentTest() throws URISyntaxException {
String date = format.format(new Date());
File directory = new File("/HotCoffee/qti/" + date + "/");
directory.mkdirs();
ManifestBuilder manifest = ManifestBuilder.createAssessmentTestBuilder();
System.out.println(directory);
// test
File testFile = new File(directory, IdentifierGenerator.newAssessmentTestFilename());
AssessmentTest assessmentTest = AssessmentTestFactory.createAssessmentTest("Big test " + date, "Section");
manifest.appendAssessmentTest(testFile.getName());
TestPart part = assessmentTest.getTestParts().get(0);
part.getAssessmentSections().clear();
// section
for (int i = 0; i < numOfSections; i++) {
AssessmentSection section = new AssessmentSection(part);
section.setFixed(Boolean.TRUE);
section.setVisible(Boolean.TRUE);
section.setTitle((i + 1) + ". Section");
section.setIdentifier(IdentifierGenerator.newAsIdentifier("sec"));
part.getAssessmentSections().add(section);
Ordering ordering = new Ordering(section);
ordering.setShuffle(true);
section.setOrdering(ordering);
Selection selection = new Selection(section);
selection.setSelect(4);
section.setSelection(selection);
ItemSessionControl itemSessionControl = new ItemSessionControl(section);
itemSessionControl.setAllowSkipping(Boolean.TRUE);
itemSessionControl.setAllowComment(Boolean.FALSE);
itemSessionControl.setShowFeedback(Boolean.FALSE);
section.setItemSessionControl(itemSessionControl);
RubricBlock rubrickBlock = new RubricBlock(section);
rubrickBlock.setViews(Collections.singletonList(View.CANDIDATE));
section.getRubricBlocks().add(rubrickBlock);
for (int j = 0; j < numOfQuestions; j++) {
// single choice
String itemId = IdentifierGenerator.newAsString(QTI21QuestionType.sc.getPrefix());
File itemFile = new File(directory, itemId + ".xml");
AssessmentItem assessmentItem = AssessmentItemFactory.createSingleChoice("Single choice", "New answer");
assessmentItem.setTitle((i + 1) + "." + (j + 1) + ". Question SC");
AssessmentTestFactory.appendAssessmentItem(section, itemFile.getName());
manifest.appendAssessmentItem(itemFile.getName());
try (FileOutputStream out = new FileOutputStream(itemFile)) {
qtiSerializer.serializeJqtiObject(assessmentItem, out);
} catch (Exception e) {
log.error("", e);
}
}
}
try (FileOutputStream out = new FileOutputStream(testFile)) {
qtiSerializer.serializeJqtiObject(assessmentTest, out);
} catch (Exception e) {
log.error("", e);
}
manifest.write(new File(directory, "imsmanifest.xml"));
}
use of uk.ac.ed.ph.jqtiplus.node.content.variable.RubricBlock in project OpenOLAT by OpenOLAT.
the class AssessmentSectionOptionsEditorController method formOK.
@Override
protected void formOK(UserRequest ureq) {
section.setTitle(titleEl.getValue());
// rubrics
List<RubricBlock> rubricBlocks = new ArrayList<>();
for (RichTextElement rubricEl : rubricEls) {
String rubric = rubricEl.getRawValue();
if (htmlBuilder.containsSomething(rubric)) {
RubricBlock rubricBlock = (RubricBlock) rubricEl.getUserObject();
if (rubricBlock == null) {
rubricBlock = new RubricBlock(section);
rubricBlock.setViews(Collections.singletonList(View.CANDIDATE));
}
rubricBlock.getBlocks().clear();
htmlBuilder.appendHtml(rubricBlock, rubric);
rubricBlocks.add(rubricBlock);
}
}
section.getRubricBlocks().clear();
section.getRubricBlocks().addAll(rubricBlocks);
// shuffle
boolean shuffle = (shuffleEl.isOneSelected() && shuffleEl.isSelected(0));
if (shuffle) {
if (section.getOrdering() == null) {
section.setOrdering(new Ordering(section));
}
section.getOrdering().setShuffle(shuffle);
} else {
section.setOrdering(null);
}
// number of selected questions
Integer randomSelection = null;
if (StringHelper.containsNonWhitespace(randomSelectedEl.getSelectedKey())) {
randomSelection = new Integer(randomSelectedEl.getSelectedKey());
}
if (randomSelection == null || randomSelection.intValue() < 1) {
section.setSelection(null);
} else {
if (section.getSelection() == null) {
section.setSelection(new Selection(section));
}
section.getSelection().setSelect(randomSelection);
}
fireEvent(ureq, new AssessmentSectionEvent(AssessmentSectionEvent.ASSESSMENT_SECTION_CHANGED, section));
}
use of uk.ac.ed.ph.jqtiplus.node.content.variable.RubricBlock in project OpenOLAT by OpenOLAT.
the class AssessmentSectionOptionsEditorController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
formLayout.setElementCssClass("o_sel_assessment_section_options");
setFormContextHelp("Test editor QTI 2.1 in detail#details_testeditor_section");
if (!editable) {
setFormWarning("warning.alien.assessment.test");
}
String title = section.getTitle();
titleEl = uifactory.addTextElement("title", "form.metadata.title", 255, title, formLayout);
titleEl.setEnabled(editable);
titleEl.setMandatory(true);
String relativePath = rootDirectory.toPath().relativize(testFile.toPath().getParent()).toString();
VFSContainer itemContainer = (VFSContainer) rootContainer.resolve(relativePath);
if (section.getRubricBlocks().isEmpty()) {
RichTextElement rubricEl = uifactory.addRichTextElementForQTI21("rubric" + counter++, "form.imd.rubric", "", 12, -1, itemContainer, formLayout, ureq.getUserSession(), getWindowControl());
rubricEl.getEditorConfiguration().setFileBrowserUploadRelPath("media");
rubricEl.setEnabled(editable);
rubricEls.add(rubricEl);
} else {
for (RubricBlock rubricBlock : section.getRubricBlocks()) {
String rubric = htmlBuilder.blocksString(rubricBlock.getBlocks());
RichTextElement rubricEl = uifactory.addRichTextElementForQTI21("rubric" + counter++, "form.imd.rubric", rubric, 12, -1, itemContainer, formLayout, ureq.getUserSession(), getWindowControl());
rubricEl.getEditorConfiguration().setFileBrowserUploadRelPath("media");
rubricEl.setEnabled(editable);
rubricEl.setUserObject(rubricBlock);
rubricEls.add(rubricEl);
}
}
// shuffle
String[] yesnoValues = new String[] { translate("yes"), translate("no") };
shuffleEl = uifactory.addRadiosHorizontal("shuffle", "form.section.shuffle", formLayout, yesnoKeys, yesnoValues);
if (section.getOrdering() != null && section.getOrdering().getShuffle()) {
shuffleEl.select("y", true);
} else {
shuffleEl.select("n", true);
}
shuffleEl.setEnabled(!restrictedEdit && editable);
int numOfItems = getNumOfQuestions(section);
String[] theKeys = new String[numOfItems + 1];
String[] theValues = new String[numOfItems + 1];
theKeys[0] = "0";
theValues[0] = translate("form.section.selection_all");
for (int i = 0; i < numOfItems; i++) {
theKeys[i + 1] = Integer.toString(i + 1);
theValues[i + 1] = Integer.toString(i + 1);
}
randomSelectedEl = uifactory.addDropdownSingleselect("form.section.selection_pre", formLayout, theKeys, theValues, null);
randomSelectedEl.setHelpText(translate("form.section.selection_pre.hover"));
randomSelectedEl.setEnabled(!restrictedEdit && editable);
int currentNum = section.getSelection() != null ? section.getSelection().getSelect() : 0;
if (currentNum <= numOfItems) {
randomSelectedEl.select(theKeys[currentNum], true);
} else if (currentNum > numOfItems) {
randomSelectedEl.select(theKeys[numOfItems], true);
} else {
randomSelectedEl.select(theKeys[0], true);
}
FormLayoutContainer buttonsCont = FormLayoutContainer.createButtonLayout("butons", getTranslator());
formLayout.add(buttonsCont);
FormSubmit submit = uifactory.addFormSubmitButton("save", "save", buttonsCont);
submit.setEnabled(editable);
}
use of uk.ac.ed.ph.jqtiplus.node.content.variable.RubricBlock in project OpenOLAT by OpenOLAT.
the class QTI12To21Converter method convert.
private void convert(Section section, TestPart testPart) throws URISyntaxException {
AssessmentSection assessmentSection = AssessmentTestFactory.appendAssessmentSection("Section", testPart);
assessmentSection.setTitle(section.getTitle());
convertDuration(section.getDuration(), assessmentSection);
RubricBlock rubricBlock = assessmentSection.getRubricBlocks().get(0);
rubricBlock.getBlocks().clear();
String objectives = section.getObjectives();
htmlBuilder.appendHtml(rubricBlock, blockedHtml(objectives));
boolean shuffle = SelectionOrdering.RANDOM.equals(section.getSelection_ordering().getOrderType());
assessmentSection.getOrdering().setShuffle(shuffle);
int selectionNum = section.getSelection_ordering().getSelectionNumber();
if (selectionNum > 0) {
Selection selection = new Selection(assessmentSection);
selection.setSelect(selectionNum);
assessmentSection.setSelection(selection);
}
List<Item> items = section.getItems();
for (Item item : items) {
AssessmentItemBuilder itemBuilder = null;
if (item != null && item.getQuestion() != null) {
int questionType = item.getQuestion().getType();
switch(questionType) {
case Question.TYPE_SC:
itemBuilder = convertSingleChoice(item);
break;
case Question.TYPE_MC:
itemBuilder = convertMultipleChoice(item);
break;
case Question.TYPE_KPRIM:
itemBuilder = convertKPrim(item);
break;
case Question.TYPE_FIB:
itemBuilder = convertFIB(item);
break;
case Question.TYPE_ESSAY:
itemBuilder = convertEssay(item);
break;
}
} else {
errors.add(item.getTitle());
log.error("Item without question: " + item);
}
if (itemBuilder != null) {
itemBuilder.build();
AssessmentItem assessmentItem = itemBuilder.getAssessmentItem();
AssessmentItemRef itemRef = new AssessmentItemRef(assessmentSection);
String itemId = IdentifierGenerator.newAsString(itemBuilder.getQuestionType().getPrefix());
itemRef.setIdentifier(Identifier.parseString(itemId));
convertItemBasics(item, itemRef);
File itemFile = new File(unzippedDirRoot, itemId + ".xml");
itemRef.setHref(new URI(itemFile.getName()));
assessmentSection.getSectionParts().add(itemRef);
persistAssessmentObject(itemFile, assessmentItem);
appendResourceAndMetadata(item, itemBuilder, itemFile);
// collect max score
Double maxScore = QtiNodesExtractor.extractMaxScore(assessmentItem);
if (maxScore != null && maxScore.doubleValue() > 0.0d) {
atomicMaxScore.add(maxScore.doubleValue());
}
}
}
}
use of uk.ac.ed.ph.jqtiplus.node.content.variable.RubricBlock in project OpenOLAT by OpenOLAT.
the class AssessmentTestComponentRenderer method renderSectionRubrics.
private void renderSectionRubrics(AssessmentRenderer renderer, StringOutput sb, AssessmentTestComponent component, TestPlanNode itemRefNode, URLBuilder ubu, Translator translator) {
boolean writeRubrics = false;
boolean writeTitles = false;
List<AssessmentSection> sectionParentLine = new ArrayList<>();
for (TestPlanNode parentNode = itemRefNode.getParent(); parentNode.getParent() != null; parentNode = parentNode.getParent()) {
AssessmentSection selectedSection = component.getAssessmentSection(parentNode.getIdentifier());
if (selectedSection != null && selectedSection.getVisible()) {
sectionParentLine.add(selectedSection);
if (selectedSection.getRubricBlocks().size() > 0) {
for (RubricBlock rubric : selectedSection.getRubricBlocks()) {
if (rubric.getBlocks().size() > 0) {
writeRubrics = true;
}
}
}
if (StringHelper.containsNonWhitespace(selectedSection.getTitle())) {
writeTitles = true;
}
}
}
if (writeRubrics) {
boolean show = true;
for (int i = sectionParentLine.size(); i-- > 0; ) {
AssessmentSection selectedSection = sectionParentLine.get(i);
if (component.getCandidateSessionContext().isRubricHidden(selectedSection.getIdentifier())) {
show = false;
}
}
String key = sectionParentLine.get(0).getIdentifier().toString();
Form form = component.getQtiItem().getRootForm();
String dispatchId = component.getQtiItem().getFormDispatchId();
sb.append("<a href='javascript:;' onclick=\"").append(FormJSHelper.getXHRNFFnCallFor(form, dispatchId, 1, new NameValuePair("cid", Event.rubric.name()), new NameValuePair("section", key))).append("; return false;\" class='o_toogle_rubrics translated'><i class='o_icon o_icon-fw ");
if (show) {
sb.append("o_icon_close_togglebox'> </i> <span>").append(translator.translate("hide.rubric"));
} else {
sb.append("o_icon_open_togglebox'> </i> <span>").append(translator.translate("show.rubric"));
}
sb.append("</span></a>");
sb.append("<div class='o_info o_assessmentsection_rubrics clearfix");
if (show) {
sb.append(" o_show");
} else {
sb.append(" o_hide");
}
sb.append("'>");
// write the titles first
if (writeTitles) {
sb.append("<h4>");
for (int i = 0; i < sectionParentLine.size(); i++) {
if (i == 1) {
sb.append("<small>");
} else if (i > 1) {
sb.append(" / ");
}
sb.append(sectionParentLine.get(i).getTitle());
}
if (sectionParentLine.size() > 1) {
sb.append("</small>");
}
sb.append("</h4>");
}
for (int i = sectionParentLine.size(); i-- > 0; ) {
AssessmentSection selectedSection = sectionParentLine.get(i);
for (RubricBlock rubricBlock : selectedSection.getRubricBlocks()) {
// @view (candidate)
sb.append("<div class='rubric'>");
rubricBlock.getBlocks().forEach(block -> renderBlock(renderer, sb, component, null, null, block, ubu, translator));
sb.append("</div>");
}
}
sb.append("<a href='javascript:;' onclick=\"").append(FormJSHelper.getXHRNFFnCallFor(form, dispatchId, 1, new NameValuePair("cid", Event.rubric.name()), new NameValuePair("section", key))).append("; return false;\" class='o_toogle_rubrics o_hide'><span>").append(translator.translate("hide.rubric.short")).append("</span></a>");
// script to show/hide the rubrics with the translated linked
sb.append("<script type=\"text/javascript\">\n").append("/* <![CDATA[ */ \n").append("jQuery(function() {\n").append(" jQuery('.o_toogle_rubrics').on('click', function() {\n").append(" jQuery('.o_assessmentsection_rubrics').each(function(index, el) {\n").append(" var current = jQuery(el).attr('class');\n").append(" if(current.indexOf('o_hide') >= 0) {\n").append(" jQuery(el).removeClass('o_hide').addClass('o_show');\n").append(" jQuery('a.o_toogle_rubrics.translated i').removeClass('o_icon_open_togglebox').addClass('o_icon_close_togglebox');\n").append(" jQuery('a.o_toogle_rubrics.translated span').html('").append(translator.translate("hide.rubric")).append("');").append(" } else {\n").append(" jQuery(el).removeClass('o_show').addClass('o_hide');\n").append(" jQuery('a.o_toogle_rubrics.translated i').removeClass('o_icon_close_togglebox').addClass('o_icon_open_togglebox');\n").append(" jQuery('a.o_toogle_rubrics.translated span').html('").append(translator.translate("show.rubric")).append("');").append(" }\n").append(" });").append(" });").append("});\n /* ]]> */").append("</script>").append("</div>");
}
}
Aggregations