10377 Posts in 2192 Topics by 1709 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 490 Views |
-
Event Calendar selecting upcoming events from every calendar on a site

9 April 2010 at 6:05am
I know I can use code like this to specify an individual calendar
function NewEvents() {
return DataObject::get_by_id("Cal","814")->upcomingEvents(4, "ShowEventOnHome = 1", "ShowOnHome = 1");
}But is it possible to run something like below in order to grab upcoming events/announcements that are set to show on home for every calendar throughout a site?
function NewEvents() {
return DataObject::get("Cal")->upcomingEvents(4, "ShowEventOnHome = 1", "ShowOnHome = 1");
}Thanks in advance for any advice in the right direction.
Andrew
-
Re: Event Calendar selecting upcoming events from every calendar on a site

9 April 2010 at 8:05am Last edited: 9 April 2010 8:05am
Sure, but it's a bit ugly..
pubclic function NewEvents()
{
$set = new DataObjectSet();
foreach(DataObject::get("Cal") as $cal) {
$set->merge($cal->UpcomingEvents(4, "ShowEventOnHome = 1", "ShowOnHome = 1"));
}
$arr = $set->toArray();
CalendarUtil::date_sort($arr);
return new DataObjectSet($arr);
} -
Re: Event Calendar selecting upcoming events from every calendar on a site

9 April 2010 at 8:11am
Awesome, thanks for the help!
-
Re: Event Calendar selecting upcoming events from every calendar on a site

13 April 2010 at 1:18am
I just noticed that this script grabs a limit of 4 events from every calendar. So, if I had 10 calendars, and all of them had upcoming events, it would get a set of 40 events instead of just 4. Any ideas how to set the limit for a total of only 4 events?
Thanks,
Andy -
Re: Event Calendar selecting upcoming events from every calendar on a site

13 April 2010 at 2:46am
I think after I posted that code, I realized I had left that out. I meant to edit the message, but I must have gotten distracted.
public function NewEvents($max = 5)
{
$set = new DataObjectSet();
foreach(DataObject::get("Cal") as $cal) {
$set->merge($cal->UpcomingEvents(4, "ShowEventOnHome = 1", "ShowOnHome = 1"));
}
$arr = $set->toArray();
CalendarUtil::date_sort($arr);
if($set->Count() > $max) {
$arr = array_slice($arr, 0, $max);
}
return new DataObjectSet($arr);
} -
Re: Event Calendar selecting upcoming events from every calendar on a site

13 April 2010 at 3:19am
Perfect, thanks!
Andrew
| 490 Views | ||
|
Page:
1
|
Go to Top |

