use of org.olat.commons.calendar.model.KalendarEvent in project OpenOLAT by OpenOLAT.
the class CalendarPrintMapper method renderEvent.
private void renderEvent(StringBuilder sb, KalendarEventRenderWrapper eventWrapper, Date dayStart, Date dayEnd) {
KalendarEvent event = eventWrapper.getEvent();
// check if event is private and user allowed to see it
if (event.getClassification() == KalendarEvent.CLASS_PRIVATE && !eventWrapper.getKalendarRenderWrapper().isPrivateEventsVisible()) {
return;
}
// Show all PUBLIC and FREEBUSY events
String escapedSubject = Formatter.escWithBR(event.getSubject()).toString();
escapedSubject = escapedSubject.replace('\r', ' ');
sb.append("<li class=\"o_cal_event\">\n");
sb.append("<div class=\"o_cal_class " + eventWrapper.getCssClass() + "\"> </div>\n");
// time
sb.append("<div class=\"o_cal_time\"><span>\n");
if (event.isAllDayEvent()) {
sb.append(translator.translate("cal.form.allday"));
} else {
// set start and end times for events spanning more than one day
Date begin = event.getBegin();
Date end = event.getEnd();
if (begin.before(dayStart)) {
begin = dayStart;
}
if (end == null || end.after(dayEnd)) {
end = dayEnd;
}
sb.append(StringHelper.formatLocaleTime(begin, translator.getLocale()));
sb.append(" - ");
sb.append(StringHelper.formatLocaleTime(end, translator.getLocale()));
}
sb.append("</span></div>\n");
// and should not be applied to imported calendars)
if (eventWrapper.getKalendarRenderWrapper().isPrivateEventsVisible() || event.getClassification() == KalendarEvent.CLASS_PUBLIC || eventWrapper.getKalendarRenderWrapper().isImported()) {
// event name (subject)
// firefox doesn't break lines with only <br />, we need <p>
sb.append("<div class=\"o_cal_subject\"><p>");
sb.append(escapedSubject.replace("<br />", "</p><p>"));
sb.append("</p></div>\n");
// location
if (StringHelper.containsNonWhitespace(event.getLocation())) {
sb.append("<div class=\"o_cal_location\"><span>\n<strong>");
sb.append(translator.translate("cal.form.location") + "</strong>: ");
sb.append(StringHelper.escapeHtml(event.getLocation()));
sb.append("</span></div>\n");
}
// description
if (StringHelper.containsNonWhitespace(event.getDescription())) {
sb.append("<div class=\"o_cal_description\"><span>\n<strong>");
sb.append(translator.translate("cal.form.description") + "</strong>: ");
sb.append(StringHelper.escapeHtml(event.getDescription()));
sb.append("</span></div>\n");
}
} else {
// for free-busy events where user has not the right to see the private stuff
// show only a message
sb.append("<div class=\"o_cal_freebusy\"><p>");
sb.append(translator.translate("cal.form.subject.hidden"));
sb.append("</p></div>\n");
}
sb.append("</li>\n");
}
use of org.olat.commons.calendar.model.KalendarEvent in project OpenOLAT by OpenOLAT.
the class UserCalendarWebService method getEvents.
@GET
@Path("events")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getEvents(@PathParam("identityKey") Long identityKey, @QueryParam("start") @DefaultValue("0") Integer start, @QueryParam("limit") @DefaultValue("25") Integer limit, @QueryParam("onlyFuture") @DefaultValue("false") Boolean onlyFuture, @Context HttpServletRequest httpRequest, @Context Request request) {
UserRequest ureq = getUserRequest(httpRequest);
if (ureq.getIdentity() == null || !ureq.getUserSession().isAuthenticated()) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
} else if (!ureq.getIdentity().getKey().equals(identityKey) && !isAdmin(httpRequest)) {
return Response.serverError().status(Status.UNAUTHORIZED).build();
}
CollectCalendars visitor = new CollectCalendars();
getCalendars(visitor, ureq);
List<KalendarRenderWrapper> wrappers = visitor.getWrappers();
List<EventVO> events = new ArrayList<>();
for (KalendarRenderWrapper wrapper : wrappers) {
Collection<KalendarEvent> kalEvents = wrapper.getKalendar().getEvents();
for (KalendarEvent kalEvent : kalEvents) {
EventVO eventVo = new EventVO(kalEvent);
events.add(eventVo);
}
}
return processEvents(events, onlyFuture, start, limit, httpRequest, request);
}
use of org.olat.commons.calendar.model.KalendarEvent in project OpenOLAT by OpenOLAT.
the class FullCalendarElement method doSelect.
private void doSelect(UserRequest ureq, String eventId, String targetDomId) {
KalendarEvent event = component.getCalendarEvent(eventId);
if (component.isOccurenceOfCalendarEvent(eventId)) {
String uid = component.getCalendarEventUid(eventId);
KalendarRenderWrapper cal = component.getCalendarById(uid);
KalendarRecurEvent recurEvent = getCurrenceKalendarEvent(cal, eventId);
getRootForm().fireFormEvent(ureq, new CalendarGUISelectEvent(this, recurEvent, cal, targetDomId));
} else if (component.isReccurenceOfCalendarEvent(eventId)) {
String uid = component.getCalendarEventUid(eventId);
KalendarRenderWrapper cal = component.getCalendarById(uid);
KalendarRecurEvent recurEvent = getCurrenceKalendarEvent(cal, eventId);
getRootForm().fireFormEvent(ureq, new CalendarGUISelectEvent(this, recurEvent, cal, targetDomId));
} else {
KalendarRenderWrapper calWrapper = component.getCalendarByNormalizedId(eventId);
getRootForm().fireFormEvent(ureq, new CalendarGUISelectEvent(this, event, calWrapper, targetDomId));
}
}
use of org.olat.commons.calendar.model.KalendarEvent in project OpenOLAT by OpenOLAT.
the class FullCalendarElement method getCurrenceKalendarEvent.
private KalendarRecurEvent getCurrenceKalendarEvent(KalendarRenderWrapper cal, String eventId) {
boolean privateEventsVisible = cal.isPrivateEventsVisible();
CalendarManager calendarManager = CoreSpringFactory.getImpl(CalendarManager.class);
Date currentDate = component.getCurrentDate();
Calendar calendar = Calendar.getInstance();
calendar.setTime(currentDate);
calendar.add(Calendar.MONTH, -2);
Date from = calendar.getTime();
calendar.add(Calendar.MONTH, +4);
Date to = calendar.getTime();
List<KalendarEvent> events = calendarManager.getEvents(cal.getKalendar(), from, to, privateEventsVisible);
for (KalendarEvent event : events) {
if (event instanceof KalendarRecurEvent) {
KalendarRecurEvent kEvent = (KalendarRecurEvent) event;
if (eventId.equals(FullCalendarComponent.normalizeId(event))) {
return kEvent;
}
}
}
return null;
}
use of org.olat.commons.calendar.model.KalendarEvent in project OpenOLAT by OpenOLAT.
the class ICalFileCalendarManager method removeFutureOfEvent.
@Override
public boolean removeFutureOfEvent(Kalendar cal, KalendarRecurEvent kalendarEvent) {
OLATResourceable calOres = getOresHelperFor(cal);
Boolean removeSuccessful = CoordinatorManager.getInstance().getCoordinator().getSyncer().doInSync(calOres, new SyncerCallback<Boolean>() {
@Override
public Boolean execute() {
boolean successfullyPersist = false;
try {
String uid = kalendarEvent.getID();
Date occurenceDate = kalendarEvent.getOccurenceDate();
Kalendar loadedCal = getCalendarFromCache(cal.getType(), cal.getCalendarID());
KalendarEvent rootEvent = loadedCal.getEvent(kalendarEvent.getID(), null);
String rRule = rootEvent.getRecurrenceRule();
Recur recur = new Recur(rRule);
recur.setUntil(CalendarUtils.createDate(occurenceDate));
RRule rrule = new RRule(recur);
rootEvent.setRecurrenceRule(rrule.getValue());
for (KalendarEvent kEvent : loadedCal.getEvents()) {
if (uid.equals(kEvent.getID()) && StringHelper.containsNonWhitespace(kEvent.getRecurrenceID()) && occurenceDate.before(kEvent.getBegin())) {
loadedCal.removeEvent(kEvent);
}
}
successfullyPersist = persistCalendar(loadedCal);
} catch (ParseException e) {
log.error("", e);
}
return new Boolean(successfullyPersist);
}
});
// inform all controller about calendar change for reload
CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(new CalendarGUIModifiedEvent(cal), OresHelper.lookupType(CalendarManager.class));
return removeSuccessful.booleanValue();
}
Aggregations