// get the personal calendar
CalendarManager calendarManager = CalendarManagerFactory.getInstance().getCalendarManager();
KalendarRenderWrapper calendarWrapper = calendarManager.getPersonalCalendar(ureq.getIdentity());
calendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_WRITE);
KalendarConfig personalKalendarConfig = calendarManager.findKalendarConfigForIdentity(
calendarWrapper.getKalendar(), ureq);
if (personalKalendarConfig != null) {
calendarWrapper.getKalendarConfig().setCss(personalKalendarConfig.getCss());
calendarWrapper.getKalendarConfig().setVis(personalKalendarConfig.isVis());
}
calendars.add(calendarWrapper);
// get group calendars
BusinessGroupManager bgManager = BusinessGroupManagerImpl.getInstance();
List<BusinessGroup> ownerGroups = bgManager.findBusinessGroupsOwnedBy(null, ureq.getIdentity(), null);
addCalendars(ureq, ownerGroups, true, calendars);
List<BusinessGroup> attendedGroups = bgManager.findBusinessGroupsAttendedBy(null, ureq.getIdentity(), null);
for (Iterator<BusinessGroup> ownerGroupsIterator = ownerGroups.iterator(); ownerGroupsIterator.hasNext();) {
BusinessGroup ownerGroup = ownerGroupsIterator.next();
if (attendedGroups.contains(ownerGroup))
attendedGroups.remove(ownerGroup);
}
addCalendars(ureq, attendedGroups, false, calendars);
// add course calendars
List<String> subscribedCourseCalendarIDs = CourseCalendarSubscription.getSubscribedCourseCalendarIDs(
ureq.getUserSession().getGuiPreferences());
RepositoryManager repoManager = RepositoryManager.getInstance();
List<String> calendarIDsToBeRemoved = new ArrayList<String>();
for (Iterator<String> iter = subscribedCourseCalendarIDs.iterator(); iter.hasNext();) {
String courseCalendarID = iter.next();
final long courseResourceableID = Long.parseLong(courseCalendarID);
RepositoryEntry repoEntry = repoManager.lookupRepositoryEntry(new OLATResourceable() {
public Long getResourceableId() { return new Long(courseResourceableID); }
public String getResourceableTypeName() { return CourseModule.getCourseTypeName(); }
}, false);
if (repoEntry == null) {
// mark calendar ID for cleanup
calendarIDsToBeRemoved.add(courseCalendarID);
continue;
}
ICourse course = CourseFactory.loadCourse(new Long(courseResourceableID));
//calendar course aren't enabled per default but course node of type calendar are always possible
//REVIEW if (!course.getCourseEnvironment().getCourseConfig().isCalendarEnabled()) continue;
// add course calendar
KalendarRenderWrapper courseCalendarWrapper = calendarManager.getCourseCalendar(course);
CourseGroupManager cgm = course.getCourseEnvironment().getCourseGroupManager();
boolean isPrivileged = cgm.isIdentityCourseAdministrator(ureq.getIdentity())
|| cgm.hasRight(ureq.getIdentity(), CourseRights.RIGHT_COURSEEDITOR);
if (isPrivileged) {
courseCalendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_WRITE);
} else {
courseCalendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_ONLY);
}
KalendarConfig courseKalendarConfig = calendarManager.findKalendarConfigForIdentity(courseCalendarWrapper.getKalendar(), ureq);
if (courseKalendarConfig != null) {
courseCalendarWrapper.getKalendarConfig().setCss(courseKalendarConfig.getCss());
courseCalendarWrapper.getKalendarConfig().setVis(courseKalendarConfig.isVis());
}
courseCalendarWrapper.setLinkProvider(new CourseLinkProviderController(course, ureq, wControl));
calendars.add(courseCalendarWrapper);
}