SectionContext sc = ac.getSectionContext(i);
int iccnt = sc.getItemContextCount();
for (int j = 0; j < iccnt; j++) {
ItemContext ic = sc.getItemContext(j);
// Create new result item for this item
QTIResult qtiResult = new QTIResult();
qtiResult.setResultSet(qtiResultSet);
qtiResult.setItemIdent(ic.getIdent());
qtiResult.setDuration(new Long(ic.getTimeSpent()));
if (ai.isSurvey()) qtiResult.setScore(0);
else qtiResult.setScore(ic.getScore());
qtiResult.setTstamp(new Date(ic.getLatestAnswerTime()));
qtiResult.setLastModified(new Date(System.currentTimeMillis()));
qtiResult.setIp(ureq.getHttpReq().getRemoteAddr());
// Get user answers for this item
StringBuilder sb = new StringBuilder();
if (ic.getItemInput() == null) {} else {
ItemInput inp = ic.getItemInput();
if (inp.isEmpty()) {
sb.append("[]");
} else {
Map im = inp.getInputMap();
// Create answer block
Set keys = im.keySet();
Iterator iter = keys.iterator();
while (iter.hasNext()) {
String ident = (String) iter.next();
sb.append(ident); // response_lid ident
sb.append("[");
List answers = inp.getAsList(ident);
for (int y = 0; y < answers.size(); y++) {
sb.append("[");
String answer = (String) answers.get(y);
// answer is referenced to response_label ident, if
// render_choice
// answer is userinput, if render_fib
answer = quoteSpecialQTIResultCharacters(answer);
sb.append(answer);
sb.append("]");
}
sb.append("]");
}
}
}
qtiResult.setAnswer(sb.toString());
// Persist result data in database
DBFactory.getInstance().saveObject(qtiResult);
}
}
}