use of org.olat.course.nodes.CourseNode in project OpenOLAT by OpenOLAT.
the class SelectForumStepForm method formInnerEvent.
@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
if (tableEl == source) {
if (event instanceof SelectionEvent) {
SelectionEvent se = (SelectionEvent) event;
int index = se.getIndex();
CourseNode node = tableModel.getObject(index);
addToRunContext(SendMailStepForm.FORUM, node);
fireEvent(ureq, StepsEvent.ACTIVATE_NEXT);
}
}
super.formInnerEvent(ureq, source, event);
}
use of org.olat.course.nodes.CourseNode in project OpenOLAT by OpenOLAT.
the class FeedNotificationsHandler method createSubscriptionInfo.
@Override
public SubscriptionInfo createSubscriptionInfo(Subscriber subscriber, Locale locale, Date compareDate) {
SubscriptionInfo si;
Publisher p = subscriber.getPublisher();
Date latestNews = p.getLatestNewsDate();
try {
final Translator translator = Util.createPackageTranslator(FeedMainController.class, locale);
if (notificationsManager.isPublisherValid(p) && compareDate.before(latestNews)) {
String title;
try {
RepositoryEntry re = repoManager.lookupRepositoryEntry(OresHelper.createOLATResourceableInstance(p.getResName(), p.getResId()), false);
if (re.getAccess() == RepositoryEntry.DELETED || re.getRepositoryEntryStatus().isClosed() || re.getRepositoryEntryStatus().isUnpublished()) {
return notificationsManager.getNoSubscriptionInfo();
}
String displayName = re.getDisplayname();
if ("CourseModule".equals(p.getResName())) {
ICourse course = CourseFactory.loadCourse(re);
CourseNode node = course.getRunStructure().getNode(p.getSubidentifier());
if (node == null) {
notificationsManager.deactivate(p);
return notificationsManager.getNoSubscriptionInfo();
}
title = translator.translate(NOTIFICATIONS_HEADER_COURSE, new String[] { displayName });
} else {
title = getHeader(translator, displayName);
}
} catch (Exception e) {
log.error("Unknown Exception", e);
return notificationsManager.getNoSubscriptionInfo();
}
OLATResourceable feedOres = OresHelper.createOLATResourceableInstance(p.getType(), new Long(p.getData()));
Feed feed = feedManager.loadFeed(feedOres);
List<Item> listItems = feedManager.loadItems(feed);
List<SubscriptionListItem> items = new ArrayList<>();
for (Item item : listItems) {
if (!item.isDraft()) {
appendSubscriptionItem(item, p, compareDate, translator, items);
}
}
si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(title, getCssClassIcon()), items);
} else {
// no news
si = notificationsManager.getNoSubscriptionInfo();
}
} catch (Exception e) {
log.error("Unknown Exception", e);
si = notificationsManager.getNoSubscriptionInfo();
}
return si;
}
use of org.olat.course.nodes.CourseNode 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.course.nodes.CourseNode in project OpenOLAT by OpenOLAT.
the class CourseAssessmentWebService method attachAssessableResults.
private void attachAssessableResults(Long courseResourceableId, String nodeKey, Identity requestIdentity, AssessableResultsVO resultsVO) {
try {
ICourse course = CourseFactory.openCourseEditSession(courseResourceableId);
CourseNode node = getParentNode(course, nodeKey);
if (!(node instanceof AssessableCourseNode)) {
throw new IllegalArgumentException("The supplied node key does not refer to an AssessableCourseNode");
}
BaseSecurity securityManager = BaseSecurityManager.getInstance();
Identity userIdentity = securityManager.loadIdentityByKey(resultsVO.getIdentityKey());
// create an identenv with no roles, no attributes, no locale
IdentityEnvironment ienv = new IdentityEnvironment();
ienv.setIdentity(userIdentity);
UserCourseEnvironment userCourseEnvironment = new UserCourseEnvironmentImpl(ienv, course.getCourseEnvironment());
// Fetch all score and passed and calculate score accounting for the
// entire course
userCourseEnvironment.getScoreAccounting().evaluateAll();
if (node instanceof IQTESTCourseNode) {
importTestItems(course, nodeKey, requestIdentity, resultsVO);
} else {
AssessableCourseNode assessableNode = (AssessableCourseNode) node;
// not directly pass this key
ScoreEvaluation scoreEval = new ScoreEvaluation(resultsVO.getScore(), Boolean.TRUE, Boolean.TRUE, new Long(nodeKey));
assessableNode.updateUserScoreEvaluation(scoreEval, userCourseEnvironment, requestIdentity, true, Role.coach);
}
CourseFactory.saveCourseEditorTreeModel(course.getResourceableId());
CourseFactory.closeCourseEditSession(course.getResourceableId(), true);
} catch (Throwable e) {
throw new WebApplicationException(e);
}
}
use of org.olat.course.nodes.CourseNode in project OpenOLAT by OpenOLAT.
the class CourseElementWebService method getTestConfiguration.
/**
* Retrieves configuration of the test course node
* @response.representation.200.qname {http://www.example.com}testConfigVO
* @response.representation.200.mediaType application/xml, application/json
* @response.representation.200.doc The course node configuration
* @response.representation.200.example {@link org.olat.restapi.support.vo.Examples#SAMPLE_COURSENODEVO}
* @response.representation.401.doc The roles of the authenticated user are not sufficient
* @response.representation.404.doc The course or test node not found
* @param courseId
* @param nodeId
* @return test course node configuration
*/
@GET
@Path("test/{nodeId}/configuration")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getTestConfiguration(@PathParam("courseId") Long courseId, @PathParam("nodeId") String nodeId) {
TestConfigVO config = new TestConfigVO();
ICourse course = CoursesWebService.loadCourse(courseId);
CourseNode courseNode = getParentNode(course, nodeId);
// build configuration with fallback to default values
ModuleConfiguration moduleConfig = courseNode.getModuleConfiguration();
Boolean allowCancel = (Boolean) moduleConfig.get(IQEditController.CONFIG_KEY_ENABLECANCEL);
config.setAllowCancel(allowCancel == null ? false : allowCancel);
Boolean allowNavi = (Boolean) moduleConfig.get(IQEditController.CONFIG_KEY_ENABLEMENU);
config.setAllowNavigation(allowNavi == null ? false : allowNavi);
Boolean allowSuspend = (Boolean) moduleConfig.get(IQEditController.CONFIG_KEY_ENABLESUSPEND);
config.setAllowSuspend(allowSuspend == null ? false : allowSuspend);
config.setNumAttempts(moduleConfig.getIntegerSafe(IQEditController.CONFIG_KEY_ATTEMPTS, 0));
config.setSequencePresentation(moduleConfig.getStringValue(IQEditController.CONFIG_KEY_SEQUENCE, AssessmentInstance.QMD_ENTRY_SEQUENCE_ITEM));
Boolean showNavi = (Boolean) moduleConfig.get(IQEditController.CONFIG_KEY_DISPLAYMENU);
config.setShowNavigation(showNavi == null ? true : showNavi);
Boolean showQuestionTitle = (Boolean) moduleConfig.get(IQEditController.CONFIG_KEY_QUESTIONTITLE);
config.setShowQuestionTitle(showQuestionTitle == null ? true : showQuestionTitle);
Boolean showResFinish = (Boolean) moduleConfig.get(IQEditController.CONFIG_KEY_RESULT_ON_FINISH);
config.setShowResultsAfterFinish(showResFinish == null ? true : showResFinish);
Boolean showResDate = (Boolean) moduleConfig.get(IQEditController.CONFIG_KEY_DATE_DEPENDENT_RESULTS);
config.setShowResultsDependendOnDate(showResDate == null ? false : showResDate);
config.setShowResultsStartDate((Date) moduleConfig.get(IQEditController.CONFIG_KEY_RESULTS_START_DATE));
config.setShowResultsEndDate((Date) moduleConfig.get(IQEditController.CONFIG_KEY_RESULTS_END_DATE));
Boolean showResHomepage = (Boolean) moduleConfig.get(IQEditController.CONFIG_KEY_RESULT_ON_HOME_PAGE);
config.setShowResultsOnHomepage(showResHomepage == null ? false : showResHomepage);
Boolean showScoreInfo = (Boolean) moduleConfig.get(IQEditController.CONFIG_KEY_ENABLESCOREINFO);
config.setShowScoreInfo(showScoreInfo == null ? true : showScoreInfo);
Boolean showQuestionProgress = (Boolean) moduleConfig.get(IQEditController.CONFIG_KEY_QUESTIONPROGRESS);
config.setShowQuestionProgress(showQuestionProgress == null ? true : showQuestionProgress);
Boolean showScoreProgress = (Boolean) moduleConfig.get(IQEditController.CONFIG_KEY_SCOREPROGRESS);
config.setShowScoreProgress(showScoreProgress == null ? true : showScoreProgress);
Boolean showSectionsOnly = (Boolean) moduleConfig.get(IQEditController.CONFIG_KEY_RENDERMENUOPTION);
config.setShowSectionsOnly(showSectionsOnly == null ? false : showSectionsOnly);
config.setSummeryPresentation(moduleConfig.getStringValue(IQEditController.CONFIG_KEY_SUMMARY, AssessmentInstance.QMD_ENTRY_SUMMARY_COMPACT));
return Response.ok(config).build();
}
Aggregations