List calendars = new ArrayList();
CalendarManager calendarManager = CalendarManagerFactory.getInstance().getCalendarManager();
// add course calendar
ICourse course = CourseFactory.loadCourse(ores);
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, getWindowControl());
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 allGroups = cgm.getAllLearningGroupsFromAllContexts();
addCalendars(ureq, allGroups, true, clpc, calendars);
// right groups
allGroups = cgm.getAllRightGroupsFromAllContexts();
addCalendars(ureq, allGroups, true, clpc, calendars);
} else {
// learning groups
List ownerGroups = cgm.getOwnedLearningGroupsFromAllContexts(identity);
addCalendars(ureq, ownerGroups, true, clpc, calendars);
List attendedGroups = cgm.getParticipatingLearningGroupsFromAllContexts(identity);
for (Iterator ownerGroupsIterator = ownerGroups.iterator(); ownerGroupsIterator.hasNext();) {
BusinessGroup ownerGroup = (BusinessGroup) ownerGroupsIterator.next();
if (attendedGroups.contains(ownerGroup))
attendedGroups.remove(ownerGroup);
}
addCalendars(ureq, attendedGroups, false, clpc, calendars);
// right groups
List rightGroups = cgm.getParticipatingRightGroupsFromAllContexts(identity);
addCalendars(ureq, rightGroups, false, clpc, calendars);
}
return calendars;
}