Search in sources :

Example 41 with KalendarEvent

use of org.olat.commons.calendar.model.KalendarEvent in project openolat by klemens.

the class DENManager method addDateInUserCalendar.

/**
 * Add this event in the calendar of an enrolled user
 * @param newEvent
 */
private void addDateInUserCalendar(KalendarEvent newEvent) {
    String[] participants = newEvent.getParticipants();
    // no users to update, cancel
    if (participants == null)
        return;
    BaseSecurity manager = BaseSecurityManager.getInstance();
    CalendarManager calManager = CoreSpringFactory.getImpl(CalendarManager.class);
    for (String participant : participants) {
        Identity identity = manager.findIdentityByName(participant);
        if (identity != null) {
            Kalendar userCal = calManager.getPersonalCalendar(identity).getKalendar();
            List<KalendarEvent> userEvents = new ArrayList<>();
            userEvents.addAll(userCal.getEvents());
            String eventId = CodeHelper.getGlobalForeverUniqueID();
            KalendarEvent userNewEvent = new KalendarEvent(eventId, null, newEvent.getSubject(), newEvent.getBegin(), newEvent.getEnd());
            userNewEvent.setLocation(newEvent.getLocation());
            userNewEvent.setSourceNodeId(newEvent.getSourceNodeId());
            userNewEvent.setClassification(KalendarEvent.CLASS_PRIVATE);
            List<KalendarEventLink> kalendarEventLinks = userNewEvent.getKalendarEventLinks();
            kalendarEventLinks.clear();
            kalendarEventLinks.addAll(newEvent.getKalendarEventLinks());
            calManager.addEventTo(userCal, userNewEvent);
        }
    }
}
Also used : CalendarManager(org.olat.commons.calendar.CalendarManager) Kalendar(org.olat.commons.calendar.model.Kalendar) ArrayList(java.util.ArrayList) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) KalendarEventLink(org.olat.commons.calendar.model.KalendarEventLink) Identity(org.olat.core.id.Identity) BaseSecurity(org.olat.basesecurity.BaseSecurity)

Example 42 with KalendarEvent

use of org.olat.commons.calendar.model.KalendarEvent in project openolat by klemens.

the class DENManager method updateMultipleDatesInList.

/**
 * Update multiple dates in a list of KalendarEvents with the given informations from a manage dates form
 * @param datesForm of type DENEditManageDatesForm
 * @param dataList
 * @param selectedDates
 * @return list with actualized KalendarEvents
 */
protected List<KalendarEvent> updateMultipleDatesInList(String subjectStr, String commentStr, String locationStr, String movementGapStr, int numParticipants, List<KalendarEvent> dataList, BitSet selectedDates) {
    for (int i = 0; i < dataList.size(); i++) {
        if (selectedDates.get(i)) {
            KalendarEvent oldEvent = dataList.get(i);
            StringTokenizer strTok = new StringTokenizer(movementGapStr.substring(1), ":", false);
            int gap = 1000 * 60 * 60 * Integer.parseInt(strTok.nextToken()) + 1000 * 60 * Integer.parseInt(strTok.nextToken());
            Date newBegin, newEnd;
            if (movementGapStr.startsWith("+")) {
                newBegin = new Date(oldEvent.getBegin().getTime() + gap);
                newEnd = new Date(oldEvent.getEnd().getTime() + gap);
            } else {
                newBegin = new Date(oldEvent.getBegin().getTime() - gap);
                newEnd = new Date(oldEvent.getEnd().getTime() - gap);
            }
            String eventId = oldEvent.getID();
            KalendarEvent newEvent = new KalendarEvent(eventId, null, subjectStr.equals(new String()) ? oldEvent.getSubject() : subjectStr, newBegin, newEnd);
            if (numParticipants != 0)
                newEvent.setNumParticipants(numParticipants);
            else
                newEvent.setNumParticipants(oldEvent.getNumParticipants());
            if (!locationStr.equals(new String()))
                newEvent.setLocation(locationStr);
            else
                newEvent.setLocation(oldEvent.getLocation());
            if (!commentStr.equals(new String()))
                newEvent.setComment(commentStr);
            else
                newEvent.setComment(oldEvent.getComment());
            newEvent.setParticipants(oldEvent.getParticipants());
            newEvent.setSourceNodeId(oldEvent.getSourceNodeId());
            dataList.remove(i);
            dataList.add(i, newEvent);
        }
    }
    return dataList;
}
Also used : StringTokenizer(java.util.StringTokenizer) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) Date(java.util.Date)

Example 43 with KalendarEvent

use of org.olat.commons.calendar.model.KalendarEvent in project openolat by klemens.

the class DENManager method getEventParticipants.

/**
 * Little helper method, that gives you all participants of a specific event
 * @param event
 * @return list of Identities
 */
protected List<Identity> getEventParticipants(KalendarEvent event) {
    List<Identity> identities = new ArrayList<Identity>();
    List<KalendarEvent> lstEvent = new ArrayList<KalendarEvent>();
    lstEvent.add(event);
    BitSet selection = new BitSet(1);
    selection.set(0);
    identities = getSelectedEventParticipants(lstEvent, selection);
    return identities;
}
Also used : ArrayList(java.util.ArrayList) BitSet(java.util.BitSet) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) Identity(org.olat.core.id.Identity)

Example 44 with KalendarEvent

use of org.olat.commons.calendar.model.KalendarEvent in project openolat by klemens.

the class DENRunTableDataModel method getValueAt.

@Override
public Object getValueAt(int row, int col) {
    KalendarEvent event = getObject(row);
    switch(col) {
        case 0:
            // subject
            return event.getSubject();
        case 1:
            return event.getBegin();
        case 2:
            Date begin = event.getBegin();
            Date end = event.getEnd();
            long milliSeconds = denManager.getDuration(begin, end);
            return denManager.formatDuration(milliSeconds, translator);
        case 3:
            // location
            return event.getLocation();
        case 4:
            // comment
            return event.getComment();
        case 5:
            // enrolled & total
            StringBuilder numStrBuf = new StringBuilder();
            String[] participants = event.getParticipants();
            numStrBuf.append(participants == null ? "0" : participants.length).append("/").append(event.getNumParticipants());
            return numStrBuf.toString();
        case 6:
            // status
            boolean isEnrolled = denManager.isEnrolledInDate(identity, event);
            if (isEnrolled)
                return translator.translate("dates.table.run.enrolled");
            else if (denManager.isDateFull(event))
                return translator.translate("dates.table.run.full");
            else
                return translator.translate("dates.table.run.notenrolled");
        case 7:
            if (!enrollmentEnabled)
                return Boolean.FALSE;
            // enroll
            if (denManager.isAlreadyEnrolled(identity, objects, courseNode)) {
                return Boolean.FALSE;
            }
            if ((event.getParticipants() != null) && (event.getParticipants().length >= event.getNumParticipants())) {
                return Boolean.FALSE;
            }
            return Boolean.TRUE;
        case 8:
            if (!enrollmentEnabled) {
                return denManager.isEnrolledInDate(identity, event);
            }
            // cancel enrollment
            if (cancelEnrollEnabled)
                return denManager.isEnrolledInDate(identity, event);
            return Boolean.FALSE;
        default:
            return "error";
    }
}
Also used : KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) Date(java.util.Date)

Example 45 with KalendarEvent

use of org.olat.commons.calendar.model.KalendarEvent in project openolat by klemens.

the class DENCourseNode method cleanupOnDelete.

@Override
public void cleanupOnDelete(ICourse course) {
    super.cleanupOnDelete(course);
    CoursePropertyManager cpm = PersistingCoursePropertyManager.getInstance(course);
    cpm.deleteNodeProperties(this, CONF_CANCEL_ENROLL_ENABLED);
    DENManager denManager = DENManager.getInstance();
    // empty List as first argument, so all dates for this course node are going to delete
    denManager.persistDENSettings(new ArrayList<KalendarEvent>(), course, this);
}
Also used : DENManager(de.bps.course.nodes.den.DENManager) KalendarEvent(org.olat.commons.calendar.model.KalendarEvent) CoursePropertyManager(org.olat.course.properties.CoursePropertyManager) PersistingCoursePropertyManager(org.olat.course.properties.PersistingCoursePropertyManager)

Aggregations

KalendarEvent (org.olat.commons.calendar.model.KalendarEvent)172 Date (java.util.Date)80 Kalendar (org.olat.commons.calendar.model.Kalendar)68 Test (org.junit.Test)48 KalendarRenderWrapper (org.olat.commons.calendar.ui.components.KalendarRenderWrapper)46 Identity (org.olat.core.id.Identity)46 ArrayList (java.util.ArrayList)42 Calendar (java.util.Calendar)40 CalendarImportTest (org.olat.commons.calendar.CalendarImportTest)34 CalendarManager (org.olat.commons.calendar.CalendarManager)32 OLATResourceable (org.olat.core.id.OLATResourceable)20 CalendarGUIModifiedEvent (org.olat.commons.calendar.ui.events.CalendarGUIModifiedEvent)18 File (java.io.File)16 ExDate (net.fortuna.ical4j.model.property.ExDate)16 ICourse (org.olat.course.ICourse)16 URI (java.net.URI)14 HttpResponse (org.apache.http.HttpResponse)14 URL (java.net.URL)12 KalendarRecurEvent (org.olat.commons.calendar.model.KalendarRecurEvent)12 EventVO (org.olat.commons.calendar.restapi.EventVO)12