use of org.olat.ims.qti.container.SectionContext in project openolat by klemens.
the class IQDisplayController method init.
private void init(IQSecurityCallback secCallback, UserRequest ureq) {
this.iqsec = secCallback;
this.translator = Util.createPackageTranslator(IQDisplayController.class, ureq.getLocale());
this.ready = false;
retrieveListenerOres = new IQRetrievedEvent(ureq.getIdentity(), courseResId, courseNodeIdent);
CoordinatorManager.getInstance().getCoordinator().getEventBus().registerFor(this, ureq.getIdentity(), retrieveListenerOres);
iqm = CoreSpringFactory.getImpl(IQManager.class);
myContent = new VelocityContainer("olatmodiqrun", VELOCITY_ROOT + "/qti.html", translator, this);
// Check if fibautocompl.js and fibautocompl.css exists for enhance FIB autocomplete feature
Resolver autcompResolver = null;
if (resolver == null) {
RepositoryEntry re = RepositoryManager.getInstance().lookupRepositoryEntryBySoftkey(repositorySoftkey, true);
autcompResolver = new ImsRepositoryResolver(re);
} else {
autcompResolver = this.resolver;
}
if (autcompResolver != null && autcompResolver.hasAutocompleteFiles()) {
// Add Autocomplte JS and CSS file to header
StringBuilder sb = new StringBuilder();
// must be like <script type="text/javascript" src="/olat/secstatic/qti/74579818809617/_unzipped_/fibautocompl.js"></script>
sb.append("<script type=\"text/javascript\" src=\"").append(autcompResolver.getStaticsBaseURI()).append("/").append(ImsRepositoryResolver.QTI_FIB_AUTOCOMPLETE_JS_FILE).append("\"></script>\n");
// must be like <link rel="StyleSheet" href="/olat/secstatic/qti/74579818809617/_unzipped_/fibautocompl.css" type="text/css" media="screen, print">
sb.append("<link rel=\"StyleSheet\" href=\"").append(autcompResolver.getStaticsBaseURI()).append("/").append(ImsRepositoryResolver.QTI_FIB_AUTOCOMPLETE_CSS_FILE).append("\" type=\"text/css\" media=\"screen\" >\n");
JSAndCSSComponent autoCompleteJsCss = new JSAndCSSComponent("auto_complete_js_css", this.getClass(), true, sb.toString());
myContent.put("autoCompleteJsCss", autoCompleteJsCss);
}
closeButton = LinkFactory.createButton("close", myContent, this);
closeButton.setPrimary(true);
qtiscoreprogress = new ProgressBar("qtiscoreprogress", 150, 0, 0, "");
myContent.put("qtiscoreprogress", qtiscoreprogress);
Boolean displayScoreProgress = modConfig.getBooleanEntry(IQEditController.CONFIG_KEY_SCOREPROGRESS);
// migration,
if (displayScoreProgress == null)
displayScoreProgress = Boolean.TRUE;
// menu
if (!displayScoreProgress.booleanValue())
qtiscoreprogress.setVisible(false);
myContent.contextPut("displayScoreProgress", displayScoreProgress);
qtiquestionprogress = new ProgressBar("qtiquestionprogress", 150, 0, 0, "");
myContent.put("qtiquestionprogress", qtiquestionprogress);
Boolean displayQuestionProgress = modConfig.getBooleanEntry(IQEditController.CONFIG_KEY_QUESTIONPROGRESS);
// migration,
if (displayQuestionProgress == null)
displayQuestionProgress = Boolean.FALSE;
if (!displayQuestionProgress.booleanValue())
qtiquestionprogress.setVisible(false);
myContent.contextPut("displayQuestionProgress", displayQuestionProgress);
Boolean displayMenu = modConfig.getBooleanEntry(IQEditController.CONFIG_KEY_DISPLAYMENU);
// migration
if (displayMenu == null)
displayMenu = Boolean.TRUE;
myContent.contextPut("displayMenu", displayMenu);
Boolean enableCancel = modConfig.getBooleanEntry(IQEditController.CONFIG_KEY_ENABLECANCEL);
if (enableCancel == null) {
if (// migration:
modConfig.get(IQEditController.CONFIG_KEY_TYPE).equals(AssessmentInstance.QMD_ENTRY_TYPE_ASSESS))
// migration:
enableCancel = Boolean.FALSE;
else
// disable
// cancel
// for
// assessments
// migration: enable otherwise
enableCancel = Boolean.TRUE;
}
myContent.contextPut("enableCancel", enableCancel);
Boolean enableSuspend = modConfig.getBooleanEntry(IQEditController.CONFIG_KEY_ENABLESUSPEND);
// migration
if (enableSuspend == null)
enableSuspend = Boolean.FALSE;
myContent.contextPut("enableSuspend", enableSuspend);
qtistatus = new IQStatus(translator);
qtistatus.setPreview(iqsec.isPreview());
myContent.contextPut("qtistatus", qtistatus);
setInitialComponent(myContent);
// get the assessment
AssessmentInstance ai = null;
if (repositorySoftkey != null) {
// instantiate from repository
// build path information which will be used to store tempory qti file
String resourcePathInfo = courseResId + File.separator + courseNodeIdent;
ai = AssessmentFactory.createAssessmentInstance(ureq.getIdentity(), ureq.getHttpReq().getRemoteAddr(), modConfig, iqsec.isPreview(), courseResId, courseNodeIdent, resourcePathInfo, this);
} else if (resolver != null) {
// instantiate from given resolver
ai = AssessmentFactory.createAssessmentInstance(ureq.getIdentity(), ureq.getHttpReq().getRemoteAddr(), courseResId, courseNodeIdent, resolver, persister, modConfig, this);
}
// check for null instance or instance with no items
if (ai == null || ai.getAssessmentContext().getSectionContext(0).getItemContextCount() == 0)
throw new AssertException("Assessment Instance was null or no sections/items found.");
if (!iqsec.isAllowed(ai)) {
// security check
getWindowControl().setError(translator.translate("status.notallowed"));
return;
}
if (iqsec.attemptsLeft(ai) < 1) {
// security check
// note: important: do not check on == 0 since the nr of attempts can be
// republished for the same test with a smaller number as the latest time.
getWindowControl().setInfo(translator.translate(ai.isSurvey() ? "status.survey.nomoreattempts" : "status.assess.nomoreattempts"));
return;
}
if (ai.isResuming()) {
getWindowControl().setInfo(translator.translate(ai.isSurvey() ? "status.survey.resumed" : "status.assess.resumed"));
}
ai.setPreview(iqsec.isPreview());
/*
* menu render option: render only section titles or titles and questions.
*/
Object tmp = modConfig.get(IQEditController.CONFIG_KEY_RENDERMENUOPTION);
Boolean renderSectionsOnly;
if (tmp == null) {
// migration
modConfig.set(IQEditController.CONFIG_KEY_RENDERMENUOPTION, Boolean.FALSE);
renderSectionsOnly = Boolean.FALSE;
} else {
renderSectionsOnly = (Boolean) tmp;
}
boolean enabledMenu = modConfig.getBooleanEntry(IQEditController.CONFIG_KEY_ENABLEMENU).booleanValue();
boolean itemPageSequence = ((String) modConfig.get(IQEditController.CONFIG_KEY_SEQUENCE)).equals(AssessmentInstance.QMD_ENTRY_SEQUENCE_ITEM);
IQMenuDisplayConf mdc = new IQMenuDisplayConf(renderSectionsOnly.booleanValue(), enabledMenu, itemPageSequence);
Boolean tmpMemo = modConfig.getBooleanEntry(IQEditController.CONFIG_KEY_MEMO);
boolean memo = tmpMemo == null ? false : tmpMemo.booleanValue();
qticomp = new IQComponent("qticomponent", translator, ai, mdc, memo);
qticomp.addListener(this);
myContent.put("qticomp", qticomp);
if (!ai.isResuming()) {
Navigator navigator = ai.getNavigator();
navigator.startAssessment();
} else {
// fxdiff BAKS-7 Resume function
AssessmentContext act = ai.getAssessmentContext();
if (act.getCurrentSectionContextPos() >= 0) {
int sectionPos = act.getCurrentSectionContextPos();
OLATResourceable sres = OresHelper.createOLATResourceableInstance("gse", new Long(sectionPos));
WindowControl bwControl = addToHistory(ureq, sres, null, getWindowControl(), false);
if (!ai.isSectionPage()) {
SectionContext sct = act.getCurrentSectionContext();
int itemPos = sct.getCurrentItemContextPos();
if (itemPos >= 0) {
OLATResourceable ires = OresHelper.createOLATResourceableInstance("git", new Long(itemPos));
addToHistory(ureq, ires, null, bwControl, true);
}
}
}
}
qtistatus.update(ai);
if (!qtistatus.isSurvey()) {
qtiscoreprogress.setMax(ai.getAssessmentContext().getMaxScore());
qtiscoreprogress.setActual(ai.getAssessmentContext().getScore());
}
qtiquestionprogress.setMax(Integer.parseInt(qtistatus.getMaxQuestions()));
updateQuestionProgressDisplay(ai);
ready = true;
}
use of org.olat.ims.qti.container.SectionContext in project openolat by klemens.
the class IQManager method persistResults.
/**
* Create the QTIResults on the database for a given assessments,
* self-assessment or survey. These database entries can be used for
* statistical downloads.
*
* @param ai
* @param resId
* @param resDetail
* @param ureq
*/
public void persistResults(AssessmentInstance ai) {
AssessmentContext ac = ai.getAssessmentContext();
QTIResultSet qtiResultSet = new QTIResultSet();
qtiResultSet.setLastModified(new Date(System.currentTimeMillis()));
qtiResultSet.setOlatResource(ai.getCallingResId());
qtiResultSet.setOlatResourceDetail(ai.getCallingResDetail());
qtiResultSet.setRepositoryRef(ai.getRepositoryEntryKey());
qtiResultSet.setIdentity(ai.getAssessedIdentity());
qtiResultSet.setQtiType(ai.getType());
qtiResultSet.setAssessmentID(ai.getAssessID());
qtiResultSet.setDuration(new Long(ai.getAssessmentContext().getDuration()));
if (ai.isSurvey()) {
qtiResultSet.setScore(0);
qtiResultSet.setIsPassed(true);
} else {
qtiResultSet.setScore(ac.getScore());
qtiResultSet.setIsPassed(ac.isPassed());
}
dbInstance.getCurrentEntityManager().persist(qtiResultSet);
// Loop over all sections in this assessment
int sccnt = ac.getSectionContextCount();
for (int i = 0; i < sccnt; i++) {
// Loop over all items in this section
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(ai.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<String, List<String>> im = inp.getInputMap();
// Create answer block
Set<String> keys = im.keySet();
Iterator<String> iter = keys.iterator();
while (iter.hasNext()) {
String ident = iter.next();
// response_lid ident
sb.append(ident);
sb.append("[");
List<String> answers = inp.getAsList(ident);
for (int y = 0; y < answers.size(); y++) {
sb.append("[");
String answer = 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
dbInstance.getCurrentEntityManager().persist(qtiResult);
}
}
}
use of org.olat.ims.qti.container.SectionContext in project openolat by klemens.
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.SectionContext in project openolat by klemens.
the class MenuItemNavigator method goToSection.
/**
* go to the section (not the item yet): display the objectives of the section
* @see org.olat.qti.process.Navigator#goToSection(int)
*/
public void goToSection(int sectionPos) {
if (getInfo().getStatus() != QTIConstants.ASSESSMENT_RUNNING)
throw new RuntimeException("assessment is NOT running yet or anymore");
clearInfo();
AssessmentContext ac = getAssessmentContext();
ac.setCurrentSectionContextPos(sectionPos);
SectionContext sc = ac.getCurrentSectionContext();
if (!ac.isOpen()) {
getInfo().setError(QTIConstants.ERROR_ASSESSMENT_OUTOFTIME);
getInfo().setRenderItems(false);
} else if (!sc.isOpen()) {
getInfo().setError(QTIConstants.ERROR_SECTION_OUTOFTIME);
getInfo().setRenderItems(false);
} else {
// no current item position, since we display section info only
sc.setCurrentItemContextPos(-1);
sc.start();
getInfo().setStatus(QTIConstants.ASSESSMENT_RUNNING);
// only section info
getInfo().setRenderItems(false);
getInfo().setMessage(QTIConstants.MESSAGE_SECTION_INFODEMANDED);
}
getAssessmentInstance().persist();
}
use of org.olat.ims.qti.container.SectionContext in project openolat by klemens.
the class MenuSectionNavigator method goToSection.
/**
* @see org.olat.qti.process.Navigator#goToSection(int)
*/
public void goToSection(int sectionPos) {
clearInfo();
AssessmentContext ac = getAssessmentContext();
SectionContext sc = ac.getSectionContext(sectionPos);
// check if section still open
if (!ac.isOpen()) {
getInfo().setError(QTIConstants.ERROR_ASSESSMENT_OUTOFTIME);
getInfo().setRenderItems(false);
} else if (!sc.isOpen()) {
getInfo().setError(QTIConstants.ERROR_SECTION_OUTOFTIME);
getInfo().setRenderItems(false);
} else {
getInfo().setStatus(QTIConstants.ASSESSMENT_RUNNING);
// show section info (title and description)
getInfo().setMessage(QTIConstants.MESSAGE_SECTION_INFODEMANDED);
getInfo().setRenderItems(true);
ac.setCurrentSectionContextPos(sectionPos);
sc = ac.getCurrentSectionContext();
startSection(sc);
}
getAssessmentInstance().persist();
}
Aggregations