use of org.olat.ims.qti.container.ItemsInput in project OpenOLAT by OpenOLAT.
the class CourseAssessmentWebService method importTestItems.
private void importTestItems(ICourse course, String nodeKey, Identity identity, AssessableResultsVO resultsVO) {
try {
IQManager iqManager = CoreSpringFactory.getImpl(IQManager.class);
// load the course and the course node
CourseNode courseNode = getParentNode(course, nodeKey);
ModuleConfiguration modConfig = courseNode.getModuleConfiguration();
// check if the result set is already saved
QTIResultSet set = iqManager.getLastResultSet(identity, course.getResourceableId(), courseNode.getIdent());
if (set == null) {
String resourcePathInfo = course.getResourceableId() + File.separator + courseNode.getIdent();
// The use of these classes AssessmentInstance, AssessmentContext and
// Navigator
// allow the use of the persistence mechanism of OLAT without
// duplicating the code.
// The consequence is that we must loop on section and items and set the
// navigator on
// the right position before submitting the inputs.
AssessmentInstance ai = AssessmentFactory.createAssessmentInstance(identity, "", modConfig, false, course.getResourceableId(), courseNode.getIdent(), resourcePathInfo, null);
Navigator navigator = ai.getNavigator();
navigator.startAssessment();
// The type of the navigator depends on the setting of the course node
boolean perItem = (navigator instanceof MenuItemNavigator);
Map<String, ItemInput> datas = convertToHttpItemInput(resultsVO.getResults());
AssessmentContext ac = ai.getAssessmentContext();
int sectioncnt = ac.getSectionContextCount();
// loop on the sections
for (int i = 0; i < sectioncnt; i++) {
SectionContext sc = ac.getSectionContext(i);
navigator.goToSection(i);
ItemsInput iips = new ItemsInput();
int itemcnt = sc.getItemContextCount();
// loop on the items
for (int j = 0; j < itemcnt; j++) {
ItemContext it = sc.getItemContext(j);
if (datas.containsKey(it.getIdent())) {
if (perItem) {
// save the datas on a per item base
navigator.goToItem(i, j);
// the navigator can give informations on its current status
Info info = navigator.getInfo();
if (info.containsError()) {
// some items cannot processed twice
} else {
iips.addItemInput(datas.get(it.getIdent()));
navigator.submitItems(iips);
iips = new ItemsInput();
}
} else {
// put for a section
iips.addItemInput(datas.get(it.getIdent()));
}
}
}
if (!perItem) {
// save the inputs of the section. In a section based navigation,
// we must saved the inputs of the whole section at once
navigator.submitItems(iips);
}
}
navigator.submitAssessment();
// persist the QTIResultSet (o_qtiresultset and o_qtiresult) on the
// database
// TODO iqManager.persistResults(ai, course.getResourceableId(),
// courseNode.getIdent(), identity, "127.0.0.1");
// write the reporting file on the file system
// The path is <olatdata> / resreporting / <username> / Assessment /
// <assessId>.xml
// TODO Document docResReporting = iqManager.getResultsReporting(ai,
// identity, Locale.getDefault());
// TODO FilePersister.createResultsReporting(docResReporting, identity,
// ai.getFormattedType(), ai.getAssessID());
// prepare all instances needed to save the score at the course node
// level
CourseEnvironment cenv = course.getCourseEnvironment();
IdentityEnvironment identEnv = new IdentityEnvironment();
identEnv.setIdentity(identity);
UserCourseEnvironment userCourseEnv = new UserCourseEnvironmentImpl(identEnv, cenv);
// update scoring overview for the user in the current course
Float score = ac.getScore();
Boolean passed = ac.isPassed();
// perhaps don't pass this key directly
ScoreEvaluation sceval = new ScoreEvaluation(score, passed, passed, new Long(nodeKey));
AssessableCourseNode acn = (AssessableCourseNode) courseNode;
// assessment nodes are assessable
boolean incrementUserAttempts = true;
acn.updateUserScoreEvaluation(sceval, userCourseEnv, identity, incrementUserAttempts, Role.coach);
} else {
log.error("Result set already saved");
}
} catch (Exception e) {
log.error("", e);
}
}
use of org.olat.ims.qti.container.ItemsInput in project OpenOLAT by OpenOLAT.
the class IQManager method getItemsInput.
/**
* Extract item inputs from http request
*
* @param ureq The request to extract item responses from.
* @return ItemsInput
*/
public ItemsInput getItemsInput(UserRequest ureq) {
ItemsInput result = new ItemsInput();
Enumeration<String> params = ureq.getHttpReq().getParameterNames();
while (params.hasMoreElements()) {
String paramKey = params.nextElement();
StringTokenizer st = new StringTokenizer(paramKey, "§", false);
String value = ureq.getParameter(paramKey);
if (st.countTokens() == 4) {
String itemType = st.nextToken();
String itemIdent = st.nextToken();
String responseID = st.nextToken();
HttpItemInput itemInput = (HttpItemInput) result.getItemInput(itemIdent);
if (itemInput == null) {
itemInput = new HttpItemInput(itemIdent);
result.addItemInput(itemInput);
}
// all items. it does not provide any response data
if (itemType.equals("qti"))
itemInput.putSingle(responseID, value);
}
// refactoring to new setFormDirty() javascript method sends now an additional param "olat_fosm" which has no tokens inside
// so assertExc. is useless.
// else {
// throw new AssertException ("not 4 tokens in form name: orig='"+paramKey+"'");
// }
// <input id="QTI_1098869464495" type="checkbox"
// name="qti§QTIEDIT:MCQ:1098869464490§1098869464492§1098869464495" ....
}
return result;
}
use of org.olat.ims.qti.container.ItemsInput in project openolat by klemens.
the class IQDisplayController method event.
@Override
public void event(UserRequest ureq, Component source, Event event) {
if (retrievedFlag) {
fireEvent(ureq, new IQEvent(IQEvent.TEST_PULLED));
return;
} else if (retrievedFlag || stoppedFlag) {
fireEvent(ureq, new IQEvent(IQEvent.TEST_STOPPED));
return;
}
if (source == myContent || source == qticomp) {
// those must be links
String wfCommand = event.getCommand();
// process workflow
AssessmentInstance ai = qticomp.getAssessmentInstance();
if (qticomp == null || ai == null) {
throw new RuntimeException("AssessmentInstance not valid.");
}
Navigator navig = ai.getNavigator();
if (wfCommand.equals("mark")) {
ai.mark(ureq.getParameter("id"), "true".equals(ureq.getParameter("p")));
ai.persist();
return;
}
if (wfCommand.equals("memo")) {
try {
String memo = java.net.URLDecoder.decode(ureq.getParameter("p"), "UTF-8");
ai.setMemo(ureq.getParameter("id"), memo);
ai.persist();
return;
} catch (UnsupportedEncodingException ex) {
log.info("Could not decode memo text " + ureq.getParameter("p"));
}
}
logAudit(ureq);
if (wfCommand.equals("sitse")) {
// submitItemorSection
ItemsInput iInp = iqm.getItemsInput(ureq);
if (iInp.getItemCount() > 0) {
navig.submitItems(iInp);
}
if (ai.isClosed()) {
// do all the finishing stuff
if (navig.getInfo().isFeedback()) {
// render the feedback
} else {
event(ureq, source, new Event(QTIConstants.QTI_WF_SUBMIT));
return;
}
}
} else if (wfCommand.equals("sitsec")) {
// submit
if (ai.isClosed()) {
// do all the finishing stuff
if (!qtistatus.isSurvey()) {
// for test and self-assessment, generate detailed results
generateDetailsResults(ureq, ai);
} else {
// Send also finished event in case of survey
fireEvent(ureq, new IQSubmittedEvent());
}
return;
}
} else if (wfCommand.equals("sflash")) {
// submit flash answer
//
navig.submitItems(iqm.getItemsInput(ureq));
if (ai.isClosed()) {
// do all the finishing stuff
event(ureq, source, new Event(QTIConstants.QTI_WF_SUBMIT));
return;
}
} else if (wfCommand.equals("git")) {
// goToItem
String seid = ureq.getParameter("seid");
String itid = ureq.getParameter("itid");
if (seid != null && seid.length() != 0 && itid != null && itid.length() != 0) {
int sectionPos = Integer.parseInt(seid);
int itemPos = Integer.parseInt(itid);
navig.goToItem(sectionPos, itemPos);
// fxdiff BAKS-7 Resume function
OLATResourceable sres = OresHelper.createOLATResourceableInstance("gse", new Long(sectionPos));
WindowControl bwControl = addToHistory(ureq, sres, null, getWindowControl(), false);
OLATResourceable ires = OresHelper.createOLATResourceableInstance("git", new Long(itemPos));
addToHistory(ureq, ires, null, bwControl, true);
}
} else if (wfCommand.equals("gse")) {
// goToSection
String seid = ureq.getParameter("seid");
if (seid != null && seid.length() != 0) {
int sectionPos = Integer.parseInt(seid);
navig.goToSection(sectionPos);
// fxdiff BAKS-7 Resume function
OLATResourceable sres = OresHelper.createOLATResourceableInstance("gse", new Long(sectionPos));
addToHistory(ureq, sres, null);
}
} else if (wfCommand.equals(QTIConstants.QTI_WF_SUBMIT)) {
// submit
// Assessment
navig.submitAssessment();
postSubmitAssessment(ureq, ai);
} else if (wfCommand.equals(QTIConstants.QTI_WF_CANCEL)) {
// cancel
// assessment
navig.cancelAssessment();
} else if (wfCommand.equals(QTIConstants.QTI_WF_SUSPEND)) {
// suspend
// assessment
// just close the controller
fireEvent(ureq, Event.DONE_EVENT);
return;
} else if (wfCommand.equals("close")) {
qtistatus.update(null);
// Parent controller need to pop, if they pushed previously
fireEvent(ureq, Event.DONE_EVENT);
return;
}
qtistatus.update(ai);
if (!qtistatus.isSurvey())
qtiscoreprogress.setActual(ai.getAssessmentContext().getScore());
updateQuestionProgressDisplay(ai);
} else if (source == closeButton) {
// close component
qtistatus.update(null);
// Parent controller need to pop, if they pushed previously
fireEvent(ureq, Event.DONE_EVENT);
return;
}
}
use of org.olat.ims.qti.container.ItemsInput in project openolat by klemens.
the class IQManager method getItemsInput.
/**
* Extract item inputs from http request
*
* @param ureq The request to extract item responses from.
* @return ItemsInput
*/
public ItemsInput getItemsInput(UserRequest ureq) {
ItemsInput result = new ItemsInput();
Enumeration<String> params = ureq.getHttpReq().getParameterNames();
while (params.hasMoreElements()) {
String paramKey = params.nextElement();
StringTokenizer st = new StringTokenizer(paramKey, "§", false);
String value = ureq.getParameter(paramKey);
if (st.countTokens() == 4) {
String itemType = st.nextToken();
String itemIdent = st.nextToken();
String responseID = st.nextToken();
HttpItemInput itemInput = (HttpItemInput) result.getItemInput(itemIdent);
if (itemInput == null) {
itemInput = new HttpItemInput(itemIdent);
result.addItemInput(itemInput);
}
// all items. it does not provide any response data
if (itemType.equals("qti"))
itemInput.putSingle(responseID, value);
}
// refactoring to new setFormDirty() javascript method sends now an additional param "olat_fosm" which has no tokens inside
// so assertExc. is useless.
// else {
// throw new AssertException ("not 4 tokens in form name: orig='"+paramKey+"'");
// }
// <input id="QTI_1098869464495" type="checkbox"
// name="qti§QTIEDIT:MCQ:1098869464490§1098869464492§1098869464495" ....
}
return result;
}
use of org.olat.ims.qti.container.ItemsInput in project OpenOLAT by OpenOLAT.
the class IQDisplayController method event.
@Override
public void event(UserRequest ureq, Component source, Event event) {
if (retrievedFlag) {
fireEvent(ureq, new IQEvent(IQEvent.TEST_PULLED));
return;
} else if (retrievedFlag || stoppedFlag) {
fireEvent(ureq, new IQEvent(IQEvent.TEST_STOPPED));
return;
}
if (source == myContent || source == qticomp) {
// those must be links
String wfCommand = event.getCommand();
// process workflow
AssessmentInstance ai = qticomp.getAssessmentInstance();
if (qticomp == null || ai == null) {
throw new RuntimeException("AssessmentInstance not valid.");
}
Navigator navig = ai.getNavigator();
if (wfCommand.equals("mark")) {
ai.mark(ureq.getParameter("id"), "true".equals(ureq.getParameter("p")));
ai.persist();
return;
}
if (wfCommand.equals("memo")) {
try {
String memo = java.net.URLDecoder.decode(ureq.getParameter("p"), "UTF-8");
ai.setMemo(ureq.getParameter("id"), memo);
ai.persist();
return;
} catch (UnsupportedEncodingException ex) {
log.info("Could not decode memo text " + ureq.getParameter("p"));
}
}
logAudit(ureq);
if (wfCommand.equals("sitse")) {
// submitItemorSection
ItemsInput iInp = iqm.getItemsInput(ureq);
if (iInp.getItemCount() > 0) {
navig.submitItems(iInp);
}
if (ai.isClosed()) {
// do all the finishing stuff
if (navig.getInfo().isFeedback()) {
// render the feedback
} else {
event(ureq, source, new Event(QTIConstants.QTI_WF_SUBMIT));
return;
}
}
} else if (wfCommand.equals("sitsec")) {
// submit
if (ai.isClosed()) {
// do all the finishing stuff
if (!qtistatus.isSurvey()) {
// for test and self-assessment, generate detailed results
generateDetailsResults(ureq, ai);
} else {
// Send also finished event in case of survey
fireEvent(ureq, new IQSubmittedEvent());
}
return;
}
} else if (wfCommand.equals("sflash")) {
// submit flash answer
//
navig.submitItems(iqm.getItemsInput(ureq));
if (ai.isClosed()) {
// do all the finishing stuff
event(ureq, source, new Event(QTIConstants.QTI_WF_SUBMIT));
return;
}
} else if (wfCommand.equals("git")) {
// goToItem
String seid = ureq.getParameter("seid");
String itid = ureq.getParameter("itid");
if (seid != null && seid.length() != 0 && itid != null && itid.length() != 0) {
int sectionPos = Integer.parseInt(seid);
int itemPos = Integer.parseInt(itid);
navig.goToItem(sectionPos, itemPos);
// fxdiff BAKS-7 Resume function
OLATResourceable sres = OresHelper.createOLATResourceableInstance("gse", new Long(sectionPos));
WindowControl bwControl = addToHistory(ureq, sres, null, getWindowControl(), false);
OLATResourceable ires = OresHelper.createOLATResourceableInstance("git", new Long(itemPos));
addToHistory(ureq, ires, null, bwControl, true);
}
} else if (wfCommand.equals("gse")) {
// goToSection
String seid = ureq.getParameter("seid");
if (seid != null && seid.length() != 0) {
int sectionPos = Integer.parseInt(seid);
navig.goToSection(sectionPos);
// fxdiff BAKS-7 Resume function
OLATResourceable sres = OresHelper.createOLATResourceableInstance("gse", new Long(sectionPos));
addToHistory(ureq, sres, null);
}
} else if (wfCommand.equals(QTIConstants.QTI_WF_SUBMIT)) {
// submit
// Assessment
navig.submitAssessment();
postSubmitAssessment(ureq, ai);
} else if (wfCommand.equals(QTIConstants.QTI_WF_CANCEL)) {
// cancel
// assessment
navig.cancelAssessment();
} else if (wfCommand.equals(QTIConstants.QTI_WF_SUSPEND)) {
// suspend
// assessment
// just close the controller
fireEvent(ureq, Event.DONE_EVENT);
return;
} else if (wfCommand.equals("close")) {
qtistatus.update(null);
// Parent controller need to pop, if they pushed previously
fireEvent(ureq, Event.DONE_EVENT);
return;
}
qtistatus.update(ai);
if (!qtistatus.isSurvey())
qtiscoreprogress.setActual(ai.getAssessmentContext().getScore());
updateQuestionProgressDisplay(ai);
} else if (source == closeButton) {
// close component
qtistatus.update(null);
// Parent controller need to pop, if they pushed previously
fireEvent(ureq, Event.DONE_EVENT);
return;
}
}
Aggregations