Search in sources :

Example 1 with CourseLinkProviderController

use of org.olat.course.run.calendar.CourseLinkProviderController in project openolat by klemens.

the class CollaborationTools method createCalendarController.

/**
 * Creates a calendar controller
 * @param ureq
 * @param wControl
 * @param resourceableId
 * @return Configured WeeklyCalendarController
 */
public CalendarController createCalendarController(UserRequest ureq, WindowControl wControl, BusinessGroup businessGroup, boolean isAdmin, boolean isMember) {
    CollaborationManager collaborationManager = CoreSpringFactory.getImpl(CollaborationManager.class);
    KalendarRenderWrapper calRenderWrapper = collaborationManager.getCalendar(businessGroup, ureq, isAdmin);
    calRenderWrapper.setPrivateEventsVisible(isAdmin || isMember);
    // add linking
    List<RepositoryEntry> repoEntries = CoreSpringFactory.getImpl(BusinessGroupService.class).findRepositoryEntries(Collections.singleton(businessGroup), 0, -1);
    List<ICourse> courses = new ArrayList<>(repoEntries.size());
    for (RepositoryEntry repoEntry : repoEntries) {
        if (repoEntry.getOlatResource().getResourceableTypeName().equals(CourseModule.getCourseTypeName())) {
            ICourse course = CourseFactory.loadCourse(repoEntry);
            courses.add(course);
        }
    }
    if (!courses.isEmpty()) {
        CourseLinkProviderController clp = new CourseLinkProviderController(null, courses, ureq, wControl);
        calRenderWrapper.setLinkProvider(clp);
    }
    List<KalendarRenderWrapper> calendars = new ArrayList<>();
    calendars.add(calRenderWrapper);
    return new WeeklyCalendarController(ureq, wControl, calendars, WeeklyCalendarController.CALLER_COLLAB, businessGroup, false);
}
Also used : BusinessGroupService(org.olat.group.BusinessGroupService) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse) CourseLinkProviderController(org.olat.course.run.calendar.CourseLinkProviderController) WeeklyCalendarController(org.olat.commons.calendar.ui.WeeklyCalendarController) RepositoryEntry(org.olat.repository.RepositoryEntry) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper)

Example 2 with CourseLinkProviderController

use of org.olat.course.run.calendar.CourseLinkProviderController in project OpenOLAT by OpenOLAT.

the class CollaborationTools method createCalendarController.

/**
 * Creates a calendar controller
 * @param ureq
 * @param wControl
 * @param resourceableId
 * @return Configured WeeklyCalendarController
 */
public CalendarController createCalendarController(UserRequest ureq, WindowControl wControl, BusinessGroup businessGroup, boolean isAdmin, boolean isMember) {
    CollaborationManager collaborationManager = CoreSpringFactory.getImpl(CollaborationManager.class);
    KalendarRenderWrapper calRenderWrapper = collaborationManager.getCalendar(businessGroup, ureq, isAdmin);
    calRenderWrapper.setPrivateEventsVisible(isAdmin || isMember);
    // add linking
    List<RepositoryEntry> repoEntries = CoreSpringFactory.getImpl(BusinessGroupService.class).findRepositoryEntries(Collections.singleton(businessGroup), 0, -1);
    List<ICourse> courses = new ArrayList<>(repoEntries.size());
    for (RepositoryEntry repoEntry : repoEntries) {
        if (repoEntry.getOlatResource().getResourceableTypeName().equals(CourseModule.getCourseTypeName())) {
            ICourse course = CourseFactory.loadCourse(repoEntry);
            courses.add(course);
        }
    }
    if (!courses.isEmpty()) {
        CourseLinkProviderController clp = new CourseLinkProviderController(null, courses, ureq, wControl);
        calRenderWrapper.setLinkProvider(clp);
    }
    List<KalendarRenderWrapper> calendars = new ArrayList<>();
    calendars.add(calRenderWrapper);
    return new WeeklyCalendarController(ureq, wControl, calendars, WeeklyCalendarController.CALLER_COLLAB, businessGroup, false);
}
Also used : BusinessGroupService(org.olat.group.BusinessGroupService) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse) CourseLinkProviderController(org.olat.course.run.calendar.CourseLinkProviderController) WeeklyCalendarController(org.olat.commons.calendar.ui.WeeklyCalendarController) RepositoryEntry(org.olat.repository.RepositoryEntry) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper)

Example 3 with CourseLinkProviderController

use of org.olat.course.run.calendar.CourseLinkProviderController in project openolat by klemens.

the class HomeCalendarManager method appendCourseCalendars.

private void appendCourseCalendars(UserRequest ureq, WindowControl wControl, List<KalendarRenderWrapper> calendars, Map<CalendarKey, CalendarUserConfiguration> configMap) {
    if (calendarModule.isEnableCourseElementCalendar() || calendarModule.isEnableCourseToolCalendar()) {
        // add course calendars
        List<Object[]> resources = getCourses(ureq.getIdentity());
        Set<OLATResource> editoredResources = getEditorGrants(ureq.getIdentity());
        Set<Long> duplicates = new HashSet<>();
        for (Object[] resource : resources) {
            RepositoryEntry courseEntry = (RepositoryEntry) resource[0];
            if (duplicates.contains(courseEntry.getKey())) {
                continue;
            }
            duplicates.add(courseEntry.getKey());
            String role = (String) resource[1];
            Long courseResourceableID = courseEntry.getOlatResource().getResourceableId();
            try {
                ICourse course = CourseFactory.loadCourse(courseEntry);
                if (isCourseCalendarEnabled(course)) {
                    // 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);
                    boolean isPrivileged = GroupRoles.owner.name().equals(role) || editoredResources.contains(courseEntry.getOlatResource());
                    if (isPrivileged) {
                        courseCalendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_WRITE);
                    } else {
                        courseCalendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_ONLY);
                    }
                    if (role != null && (GroupRoles.owner.name().equals(role) || GroupRoles.coach.name().equals(role) || GroupRoles.participant.name().equals(role))) {
                        courseCalendarWrapper.setPrivateEventsVisible(true);
                    }
                    CalendarUserConfiguration config = configMap.get(courseCalendarWrapper.getCalendarKey());
                    if (config != null) {
                        courseCalendarWrapper.setConfiguration(config);
                    }
                    courseCalendarWrapper.setLinkProvider(new CourseLinkProviderController(course, Collections.singletonList(course), ureq, wControl));
                    calendars.add(courseCalendarWrapper);
                }
            } catch (CorruptedCourseException e) {
                OLATResource olatResource = courseEntry.getOlatResource();
                log.error("Corrupted course: " + olatResource.getResourceableTypeName() + " :: " + courseResourceableID, null);
            } catch (Exception e) {
                OLATResource olatResource = courseEntry.getOlatResource();
                log.error("Cannor read calendar of course: " + olatResource.getResourceableTypeName() + " :: " + courseResourceableID, null);
            }
        }
    }
}
Also used : OLATResource(org.olat.resource.OLATResource) ICourse(org.olat.course.ICourse) CourseLinkProviderController(org.olat.course.run.calendar.CourseLinkProviderController) RepositoryEntry(org.olat.repository.RepositoryEntry) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) CorruptedCourseException(org.olat.course.CorruptedCourseException) CorruptedCourseException(org.olat.course.CorruptedCourseException) CalendarUserConfiguration(org.olat.commons.calendar.model.CalendarUserConfiguration) HashSet(java.util.HashSet)

Example 4 with CourseLinkProviderController

use of org.olat.course.run.calendar.CourseLinkProviderController in project OpenOLAT by OpenOLAT.

the class CourseCalendars method createCourseCalendarsWrapper.

public static CourseCalendars createCourseCalendarsWrapper(UserRequest ureq, WindowControl wControl, UserCourseEnvironment courseEnv, NodeEvaluation ne) {
    List<KalendarRenderWrapper> calendars = new ArrayList<>();
    ICourse course = CourseFactory.loadCourse(courseEnv.getCourseEnvironment().getCourseResourceableId());
    KalendarRenderWrapper courseKalendarWrapper = getCourseCalendarWrapper(ureq, courseEnv, ne);
    // add link provider
    CourseLinkProviderController clpc = new CourseLinkProviderController(course, Collections.singletonList(course), ureq, wControl);
    courseKalendarWrapper.setLinkProvider(clpc);
    calendars.add(courseKalendarWrapper);
    Identity identity = ureq.getIdentity();
    CourseGroupManager cgm = course.getCourseEnvironment().getCourseGroupManager();
    // add course group calendars
    boolean isGroupManager = ureq.getUserSession().getRoles().isOLATAdmin() || ureq.getUserSession().getRoles().isGroupManager() || cgm.isIdentityCourseAdministrator(identity) || cgm.hasRight(identity, CourseRights.RIGHT_GROUPMANAGEMENT);
    boolean readOnly = courseEnv.isCourseReadOnly();
    if (isGroupManager) {
        // learning groups
        List<BusinessGroup> allGroups = cgm.getAllBusinessGroups();
        addCalendars(ureq, courseEnv, allGroups, !readOnly, clpc, calendars);
    } else {
        // learning groups
        List<BusinessGroup> ownerGroups = cgm.getOwnedBusinessGroups(identity);
        addCalendars(ureq, courseEnv, ownerGroups, !readOnly, clpc, calendars);
        List<BusinessGroup> attendedGroups = cgm.getParticipatingBusinessGroups(identity);
        for (BusinessGroup ownerGroup : ownerGroups) {
            if (attendedGroups.contains(ownerGroup)) {
                attendedGroups.remove(ownerGroup);
            }
        }
        addCalendars(ureq, courseEnv, attendedGroups, false, clpc, calendars);
    }
    return new CourseCalendars(courseKalendarWrapper, calendars);
}
Also used : CourseGroupManager(org.olat.course.groupsandrights.CourseGroupManager) BusinessGroup(org.olat.group.BusinessGroup) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse) CourseLinkProviderController(org.olat.course.run.calendar.CourseLinkProviderController) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) Identity(org.olat.core.id.Identity)

Example 5 with CourseLinkProviderController

use of org.olat.course.run.calendar.CourseLinkProviderController in project OpenOLAT by OpenOLAT.

the class HomeCalendarManager method appendCourseCalendars.

private void appendCourseCalendars(UserRequest ureq, WindowControl wControl, List<KalendarRenderWrapper> calendars, Map<CalendarKey, CalendarUserConfiguration> configMap) {
    if (calendarModule.isEnableCourseElementCalendar() || calendarModule.isEnableCourseToolCalendar()) {
        // add course calendars
        List<Object[]> resources = getCourses(ureq.getIdentity());
        Set<OLATResource> editoredResources = getEditorGrants(ureq.getIdentity());
        Set<Long> duplicates = new HashSet<>();
        for (Object[] resource : resources) {
            RepositoryEntry courseEntry = (RepositoryEntry) resource[0];
            if (duplicates.contains(courseEntry.getKey())) {
                continue;
            }
            duplicates.add(courseEntry.getKey());
            String role = (String) resource[1];
            Long courseResourceableID = courseEntry.getOlatResource().getResourceableId();
            try {
                ICourse course = CourseFactory.loadCourse(courseEntry);
                if (isCourseCalendarEnabled(course)) {
                    // 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);
                    boolean isPrivileged = GroupRoles.owner.name().equals(role) || editoredResources.contains(courseEntry.getOlatResource());
                    if (isPrivileged) {
                        courseCalendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_WRITE);
                    } else {
                        courseCalendarWrapper.setAccess(KalendarRenderWrapper.ACCESS_READ_ONLY);
                    }
                    if (role != null && (GroupRoles.owner.name().equals(role) || GroupRoles.coach.name().equals(role) || GroupRoles.participant.name().equals(role))) {
                        courseCalendarWrapper.setPrivateEventsVisible(true);
                    }
                    CalendarUserConfiguration config = configMap.get(courseCalendarWrapper.getCalendarKey());
                    if (config != null) {
                        courseCalendarWrapper.setConfiguration(config);
                    }
                    courseCalendarWrapper.setLinkProvider(new CourseLinkProviderController(course, Collections.singletonList(course), ureq, wControl));
                    calendars.add(courseCalendarWrapper);
                }
            } catch (CorruptedCourseException e) {
                OLATResource olatResource = courseEntry.getOlatResource();
                log.error("Corrupted course: " + olatResource.getResourceableTypeName() + " :: " + courseResourceableID, null);
            } catch (Exception e) {
                OLATResource olatResource = courseEntry.getOlatResource();
                log.error("Cannor read calendar of course: " + olatResource.getResourceableTypeName() + " :: " + courseResourceableID, null);
            }
        }
    }
}
Also used : OLATResource(org.olat.resource.OLATResource) ICourse(org.olat.course.ICourse) CourseLinkProviderController(org.olat.course.run.calendar.CourseLinkProviderController) RepositoryEntry(org.olat.repository.RepositoryEntry) KalendarRenderWrapper(org.olat.commons.calendar.ui.components.KalendarRenderWrapper) CorruptedCourseException(org.olat.course.CorruptedCourseException) CorruptedCourseException(org.olat.course.CorruptedCourseException) CalendarUserConfiguration(org.olat.commons.calendar.model.CalendarUserConfiguration) HashSet(java.util.HashSet)

Aggregations

KalendarRenderWrapper (org.olat.commons.calendar.ui.components.KalendarRenderWrapper)6 ICourse (org.olat.course.ICourse)6 CourseLinkProviderController (org.olat.course.run.calendar.CourseLinkProviderController)6 ArrayList (java.util.ArrayList)4 RepositoryEntry (org.olat.repository.RepositoryEntry)4 HashSet (java.util.HashSet)2 CalendarUserConfiguration (org.olat.commons.calendar.model.CalendarUserConfiguration)2 WeeklyCalendarController (org.olat.commons.calendar.ui.WeeklyCalendarController)2 Identity (org.olat.core.id.Identity)2 CorruptedCourseException (org.olat.course.CorruptedCourseException)2 CourseGroupManager (org.olat.course.groupsandrights.CourseGroupManager)2 BusinessGroup (org.olat.group.BusinessGroup)2 BusinessGroupService (org.olat.group.BusinessGroupService)2 OLATResource (org.olat.resource.OLATResource)2