Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
Re: [Liferay Forums][3. Development]Get list of next Calendar Events via Li
Hi
I'm developing a small Portlet that is supposed to show me the next upcoming Events. The Events are normal CalEvents created with the liferay Calendar Portlet.
So what I want to do is retrieve the events via the API (CalEventLocalServiceUtil.getEvents()). But I find the API is not very efficient. You seem to can only get the events for one day at a time. So if I want to look ahead 3 years into the future a would have 1095 API Calls and hence 1095 DB calls. Is there a more efficient way to do this?
I'm thinking something where I can provide the groupID, start- and end-date and I get all Events in a list.
There also is the API:
But I would need something like this not type specific. Also the begin and end parameters are int and I could't figure out what they are really doing.
I'm developing a small Portlet that is supposed to show me the next upcoming Events. The Events are normal CalEvents created with the liferay Calendar Portlet.
So what I want to do is retrieve the events via the API (CalEventLocalServiceUtil.getEvents()). But I find the API is not very efficient. You seem to can only get the events for one day at a time. So if I want to look ahead 3 years into the future a would have 1095 API Calls and hence 1095 DB calls. Is there a more efficient way to do this?
I'm thinking something where I can provide the groupID, start- and end-date and I get all Events in a list.
There also is the API:
CalEventLocalServiceUtil.getEvents(groupId, type, begin, end);But I would need something like this not type specific. Also the begin and end parameters are int and I could't figure out what they are really doing.
> There also is the API:
>
>
>
> But I would need something like this not type specific. Also the begin and end parameters are int and I could't figure out what they are really doing.
The body of
is:
So, using
CalEventLocalServiceUtil.getEvents(10023, null, 0, 1000);
works fine. Problem is still that you can't specify a time interval.
I'll see if we can add this in as it really sounds reasonable.
>
>
CalEventLocalServiceUtil.getEvents(groupId, type, begin, end);>
> But I would need something like this not type specific. Also the begin and end parameters are int and I could't figure out what they are really doing.
The body of
CalEventLocalServiceUtil.getEvents(groupId, type, begin,
end);is:
public List<calevent> getEvents(
long groupId, String type, int begin, int end)
throws SystemException {
if (Validator.isNull(type)) {
return calEventPersistence.findByGroupId(groupId, begin, end);
}
else {
return calEventPersistence.findByG_T(groupId, type, begin, end);
}
}
</calevent>So, using
CalEventLocalServiceUtil.getEvents(10023, null, 0, 1000);
works fine. Problem is still that you can't specify a time interval.
I'll see if we can add this in as it really sounds reasonable.
Hello,
are there any news regarding this topic. Has this item been implemented?
are there any news regarding this topic. Has this item been implemented?
Is there any progress with this issue?
Hello, I got pretty far with an 'events' web-content-display velocity based portlet (see picture/attachment; btw - is velocity a good idea for that? no portlet building skills) but also stuck at the point of needing to only see events from today forward. I thought those begin, end were dates so it was looking like a piece of cake. The type set to null retrieves all values (as Ray stated), begin/end of -1 gets everything as well.
Plan B: looks like that service can be called with a date as the second parm. Date type "cal" - anyone know how to get/set that via velocity?
Plan B: looks like that service can be called with a date as the second parm. Date type "cal" - anyone know how to get/set that via velocity?
Attachments:
Ok, figured out how to get a 'calendar' data type. I'm a boy-genius 
If interest, I'll publish the working velocity when it gets that far. Gotta figure every website needs one of these right? Is it me or does our Liferay 'community' seem to need a breath of life?
#set ($realcal = $dateTool.getCalendar())If interest, I'll publish the working velocity when it gets that far. Gotta figure every website needs one of these right? Is it me or does our Liferay 'community' seem to need a breath of life?
I'm interested
Go to event_iterator.jspf
1. Copy the selCal value to a new tempCalender Object
2. start a for loop initialized with 0, its max limit 'n' can be ur wish.
3. replace CalEventLocalServiceUtil.getEvents's Date object parameter with our new tempCalender Object.
--------
exixting code
--------
4. atlast increment tempCalender's Date field, repeat the loop
This ll display events from selectedDate/currentDate to selectedDate/currentDate + n days.
1. Copy the selCal value to a new tempCalender Object
2. start a for loop initialized with 0, its max limit 'n' can be ur wish.
3. replace CalEventLocalServiceUtil.getEvents's Date object parameter with our new tempCalender Object.
--------
exixting code
--------
4. atlast increment tempCalender's Date field, repeat the loop
This ll display events from selectedDate/currentDate to selectedDate/currentDate + n days.
it sounds good..thnx..:-)
You can try something similar to this right now:
@SuppressWarnings({ "unchecked", "rawtypes" })
private List<CalEvent> getEvents(ClientDataRequest portletRequest, RetrieveEventsAction action) throws SystemException {
ThemeDisplay themeDisplay = (ThemeDisplay) requestProvider.getPortletRequest().getAttribute(WebKeys.THEME_DISPLAY);
Long groupId = themeDisplay.getScopeGroupId();
DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(CalEvent.class);
Conjunction primaryCriteria = RestrictionsFactoryUtil.conjunction();
primaryCriteria.add(PropertyFactoryUtil.forName("startDate").between(action.getStartDate(), action.getEndDate()));
primaryCriteria.add(PropertyFactoryUtil.forName("groupId").eq(groupId));
dynamicQuery.add(primaryCriteria);
return (List) CalEventLocalServiceUtil.dynamicQuery(dynamicQuery);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
private List<CalEvent> getEvents(ClientDataRequest portletRequest, RetrieveEventsAction action) throws SystemException {
ThemeDisplay themeDisplay = (ThemeDisplay) requestProvider.getPortletRequest().getAttribute(WebKeys.THEME_DISPLAY);
Long groupId = themeDisplay.getScopeGroupId();
DynamicQuery dynamicQuery = DynamicQueryFactoryUtil.forClass(CalEvent.class);
Conjunction primaryCriteria = RestrictionsFactoryUtil.conjunction();
primaryCriteria.add(PropertyFactoryUtil.forName("startDate").between(action.getStartDate(), action.getEndDate()));
primaryCriteria.add(PropertyFactoryUtil.forName("groupId").eq(groupId));
dynamicQuery.add(primaryCriteria);
return (List) CalEventLocalServiceUtil.dynamicQuery(dynamicQuery);
}