use of uk.ac.ed.ph.jqtiplus.node.content.variable.RubricBlock in project OpenOLAT by OpenOLAT.
the class AssessmentTestFactory method appendAssessmentSectionInternal.
private static final AssessmentSection appendAssessmentSectionInternal(String title, AbstractPart part) {
// section
AssessmentSection section = new AssessmentSection(part);
section.setFixed(Boolean.TRUE);
section.setVisible(Boolean.TRUE);
section.setTitle(title);
section.setIdentifier(IdentifierGenerator.newAsIdentifier("sect"));
if (part instanceof TestPart) {
((TestPart) part).getAssessmentSections().add(section);
} else if (part instanceof AssessmentSection) {
((AssessmentSection) part).getSectionParts().add(section);
}
// section ordering
Ordering ordering = new Ordering(section);
ordering.setShuffle(false);
section.setOrdering(ordering);
// section rubric block
RubricBlock rubricBlock = new RubricBlock(section);
rubricBlock.setViews(Collections.singletonList(View.CANDIDATE));
section.getRubricBlocks().add(rubricBlock);
ItemSessionControl itemSessionControl = new ItemSessionControl(section);
section.setItemSessionControl(itemSessionControl);
return section;
}
use of uk.ac.ed.ph.jqtiplus.node.content.variable.RubricBlock in project OpenOLAT by OpenOLAT.
the class QTI21WordExport method renderAssessmentSection.
public void renderAssessmentSection(AssessmentSection assessmentSection, OpenXMLDocument document, boolean withResponses, Translator translator) {
String title = assessmentSection.getTitle();
document.appendHeading1(title, null);
List<RubricBlock> rubricBlocks = assessmentSection.getRubricBlocks();
for (RubricBlock rubricBlock : rubricBlocks) {
String htmlRubric = htmlBuilder.blocksString(rubricBlock.getBlocks());
document.appendHtmlText(htmlRubric, true);
}
for (SectionPart sectionPart : assessmentSection.getChildAbstractParts()) {
if (sectionPart instanceof AssessmentSection) {
renderAssessmentSection((AssessmentSection) sectionPart, document, withResponses, translator);
} else if (sectionPart instanceof AssessmentItemRef) {
AssessmentItemRef itemRef = (AssessmentItemRef) sectionPart;
ResolvedAssessmentItem resolvedAssessmentItem = resolvedAssessmentTest.getResolvedAssessmentItem(itemRef);
AssessmentItem assessmentItem = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful();
URI itemUri = resolvedAssessmentTest.getSystemIdByItemRefMap().get(itemRef);
renderAssessmentItem(assessmentItem, new File(itemUri), mediaDir, document, withResponses, translator, htmlBuilder);
document.appendPageBreak();
}
}
}
use of uk.ac.ed.ph.jqtiplus.node.content.variable.RubricBlock in project openolat by klemens.
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 klemens.
the class AssessmentTestComponentRenderer method renderAssessmentSectionRubrickBlock.
private void renderAssessmentSectionRubrickBlock(AssessmentRenderer renderer, StringOutput sb, AssessmentTestComponent component, TestPlanNode sectionNode, URLBuilder ubu, Translator translator) {
AssessmentSection selectedSection = component.getAssessmentSection(sectionNode.getIdentifier());
if (selectedSection != null && selectedSection.getRubricBlocks().size() > 0) {
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>");
}
}
}
use of uk.ac.ed.ph.jqtiplus.node.content.variable.RubricBlock in project openolat by klemens.
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