* @param locale The users locale
* @param identity
* @return Document The XML document
*/
public Document getResDoc(AssessmentInstance ai, Locale locale, Identity identity) {
AssessmentContext ac = ai.getAssessmentContext();
DocumentFactory df = DocumentFactory.getInstance();
Document res_doc = df.createDocument();
Element root = df.createElement("qti_result_report");
res_doc.setRootElement(root);
Element result = root.addElement("result");
Element extension_result = result.addElement("extension_result");
// add items (not qti standard, but nice to display original questions ->
// put it into extensions)
//extension_result.
int sectioncnt = ac.getSectionContextCount();
for (int i = 0; i < sectioncnt; i++) {
SectionContext sc = ac.getSectionContext(i);
int itemcnt = sc.getItemContextCount();
for (int j = 0; j < itemcnt; j++) {
ItemContext it = sc.getItemContext(j);
Element el_item = it.getEl_item();
extension_result.add(el_item);
}
}
// add ims cp id for any media references
addStaticsPath(extension_result, ai);
// add assessment_result
// Add User information
Element context = result.addElement("context");
User user = identity.getUser();
String name = user.getProperty(UserConstants.LASTNAME, locale) + " " + user.getProperty(UserConstants.FIRSTNAME, locale) + " (" + identity.getName() + ")";
String instId = user.getProperty(UserConstants.INSTITUTIONALUSERIDENTIFIER, locale);
String instName = user.getProperty(UserConstants.INSTITUTIONALNAME, locale);
if (instId == null) instId = "N/A";
context.addElement("name").addText(name);
String institution;
if (instName == null) institution = "N/A";
else institution = instName;
if (institution == null) institution = "N/A";
// Add institutional identifier (e.g. Matrikelnummer)
Element generic_identifier = context.addElement("generic_identifier");
generic_identifier.addElement("type_label").addText(institution);
generic_identifier.addElement("identifier_string").addText(instId);
// Add start and stop date formatted as datetime
Element beginDate = context.addElement("date");
beginDate.addElement("type_label").addText("Start");
beginDate.addElement("datetime").addText(Formatter.formatDatetime(new Date(ac.getTimeOfStart())));
Element stopDate = context.addElement("date");
stopDate.addElement("type_label").addText("Stop");
stopDate.addElement("datetime").addText(Formatter.formatDatetime(new Date(ac.getTimeOfStop())));
Element ares = result.addElement("assessment_result");
ares.addAttribute("ident_ref", ac.getIdent());
if (ac.getTitle() != null) {
ares.addAttribute("asi_title", ac.getTitle());
}
// process assessment score
Element a_score = ares.addElement("outcomes").addElement("score");
a_score.addAttribute("varname", "SCORE");
String strVal = StringHelper.formatFloat(ac.getScore(), 2);
a_score.addElement("score_value").addText(strVal);
strVal = ac.getMaxScore() == -1.0f ? "N/A" : StringHelper.formatFloat(ac.getMaxScore(), 2);
a_score.addElement("score_max").addText(strVal);
strVal = ac.getCutvalue() == -1.0f ? "N/A" : StringHelper.formatFloat(ac.getCutvalue(), 2);
a_score.addElement("score_cut").addText(strVal);
addElementText(ares, "duration", QTIHelper.getISODuration(ac.getDuration()));
addElementText(ares, "num_sections", "" + ac.getSectionContextCount());
addElementText(ares, "num_sections_presented", "0");
addElementText(ares, "num_items", "" + ac.getItemContextCount());
addElementText(ares, "num_items_presented", "" + ac.getItemsPresentedCount());
addElementText(ares, "num_items_attempted", "" + ac.getItemsAttemptedCount());
// add section_result
int secnt = ac.getSectionContextCount();
for (int i = 0; i < secnt; i++) {
SectionContext secc = ac.getSectionContext(i);
Element secres = ares.addElement("section_result");
secres.addAttribute("ident_ref", secc.getIdent());
if (secc.getTitle() != null) {
secres.addAttribute("asi_title", secc.getTitle());
}