List<KalendarRenderWrapper> calendars = new ArrayList<KalendarRenderWrapper>();
CalendarManager calendarManager = CalendarManagerFactory.getInstance().getCalendarManager();
// add course calendar
ICourse course = CourseFactory.loadCourse(ores);
KalendarRenderWrapper courseKalendarWrapper = calendarManager.getCourseCalendar(course);
CourseGroupManager cgm = course.getCourseEnvironment().getCourseGroupManager();
Identity identity = ureq.getIdentity();
boolean isPrivileged = cgm.isIdentityCourseAdministrator(identity)
|| cgm.hasRight(identity, CourseRights.RIGHT_COURSEEDITOR)
|| RepositoryManager.getInstance().isInstitutionalRessourceManagerFor(
RepositoryManager.getInstance().lookupRepositoryEntry(course, false), identity);
if (isPrivileged) {
courseKalendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_WRITE);
} else {
courseKalendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_ONLY);
}
KalendarConfig config = calendarManager.findKalendarConfigForIdentity(courseKalendarWrapper.getKalendar(), ureq);
if (config != null) {
courseKalendarWrapper.getKalendarConfig().setCss(config.getCss());
courseKalendarWrapper.getKalendarConfig().setVis(config.isVis());
}
// add link provider
CourseLinkProviderController clpc = new CourseLinkProviderController(course, ureq, wControl);
courseKalendarWrapper.setLinkProvider(clpc);
calendars.add(courseKalendarWrapper);
// add course group calendars
boolean isGroupManager = cgm.isIdentityCourseAdministrator(identity) || cgm.hasRight(identity, CourseRights.RIGHT_GROUPMANAGEMENT);
if (isGroupManager) {
// learning groups
List<BusinessGroup> allGroups = cgm.getAllLearningGroupsFromAllContexts();
addCalendars(ureq, allGroups, true, clpc, calendars);
// right groups
allGroups = cgm.getAllRightGroupsFromAllContexts();
addCalendars(ureq, allGroups, true, clpc, calendars);
} else {
// learning groups
List<BusinessGroup> ownerGroups = cgm.getOwnedLearningGroupsFromAllContexts(identity);
addCalendars(ureq, ownerGroups, true, clpc, calendars);
List<BusinessGroup> attendedGroups = cgm.getParticipatingLearningGroupsFromAllContexts(identity);
for (BusinessGroup ownerGroup : ownerGroups) {
if (attendedGroups.contains(ownerGroup)) attendedGroups.remove(ownerGroup);
}
addCalendars(ureq, attendedGroups, false, clpc, calendars);
// right groups
List<BusinessGroup> rightGroups = cgm.getParticipatingRightGroupsFromAllContexts(identity);
addCalendars(ureq, rightGroups, false, clpc, calendars);
}
return new CourseCalendars(courseKalendarWrapper, calendars);
}