Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

EventCalendar 3 - Loading announcements with UpcomingEvents()


Go to End


6 Posts   2404 Views

Avatar
cmc

Community Member, 33 Posts

6 November 2012 at 3:35pm

I'm trying to show upcoming events, including announcements, on a home page. I've found a few old threads about this, but those solutions no longer work. For one thing is_announcement is no longer a field in the CalendarDateTime table. It looks like the UpcomingEvents function in Events Calendar 3 should grab announcements by default, but I'm not getting any.

Also, $EventTitle and $_Dates no longer work in templates. $Title and $DateRange are working for me in their place.

As far as pulling announcements, I've got the first function below in my Page_Controller class. It works for pulling events, but not announcements.

public function MyUpcomingEvents($numEvents=5) {
	return DataObject::get_one("Calendar")->upcomingEvents($numEvents, );
	}

I tried this version from the older threads. It throws an error and the page won't load at all.

public function MyUpcomingEvents($numEvents=5) {
	return DataObject::get_one("Calendar")->upcomingEvents($numEvents, "is_announcements = 1");
}

This version does the same as the first, loads events only, no announcements.

public function MyUpcomingEvents($numEvents=5) {
		return DataObject::get_one("Calendar")->upcomingEvents($numEvents, "(CalendarDateTime.ClassName LIKE 'CalendarAnnouncement' OR CalendarDateTime.ClassName LIKE 'CalendarDateTime')");
}

This is what I have in my HomePage.ss

<% control MyUpcomingEvents(5) %>
       <% if Event %>
               $DateRange
                <a href="{$Link}" title="More Details about {$Title}">$Title</a>
        <% end_if %>
<% end_control %>

Any ideas how I can get announcements ?

Thanks,
Cathy

Avatar
cmc

Community Member, 33 Posts

13 November 2012 at 4:30pm

Thanks to Bstarr in this thread -
http://www.silverstripe.org/all-other-modules/show/17306

I changed the code in the HomePage.ss template to the following and the first function is now working.

                            <% if Announcement %>
                                $DateRange
                                <a href="{$Link}" title="More Details about {$Title}">$Title</a>
                            <% else %>
                                <% if Event %>
                                    $DateRange
                                    <a href="{$Event.Link}" title="More Details about {$Event.Title}">$Event.Title</a>
                                <% else %>
                                    No events to display
                                <% end_if %>
                            <% end_if %>

Avatar
Lime Blast

Community Member, 22 Posts

21 July 2013 at 1:21am

I'm trying to do the same as cmc here, but it isn't working for me..

Rather than getting the upcoming events, I'm just getting the message "No events to display"

I've got events in the database, both past and future, but this isn't working.

can anyone help me out? Thank you.

Avatar
octopuscreative

Community Member, 10 Posts

30 July 2013 at 2:59am

Edited: 30/07/2013 2:59am

Lime Blast, I'm working through a web design project for a customer and have used the following code to get my Calendar widget displaying the forthcoming events as a list of items on the Home page:

mysite/code/Page.php:

function UpcomingEvents()
{
return DataObject::get_one("Calendar")->upcomingEvents(5);
}

function GlobalCalendarWidget()
{
$calendarPage = DataObject::get_one("Calendar"); // If you have multiple calendars, specify an id or url segment.
return new CalendarWidget($calendarPage);
}

blackcandy/templates/Page.ss:

<h4>$_Dates</h4>
<h5><a href=$Event.Link" title="Click here to view this event">$Event.Title</a></h5>
<p>$Event.Content.FirstSentence</p>
<a href="$Event.Link" >view more</a>

You'll need to add the necessary CSS styles to the above but works fine. Hope this helps.

Avatar
Lime Blast

Community Member, 22 Posts

11 August 2013 at 10:42pm

Thank you for your reply octopuscreative, but I still can't get this thing to work. I have no idea what I'm doing wrong. :(

Avatar
Riposte

Community Member, 10 Posts

18 August 2013 at 5:11pm

Edited: 18/08/2013 5:28pm

I managed to get it working using this in my Page.php (I'm using SS 3.1 code if that makes any difference):

public function MyUpcomingEvents($numEvents=5) {
return DataObject::get_one("Calendar")->UpcomingEvents($numEvents, );
}

Note the uppercase 'U' in UpcomingEvents - as per the function in Calendar.php.

Also used this in Page.ss:
<% if Announcement %>
$DateRange
<a href="{$Link}" title="More Details about {$Title}">$Title</a>
<% else %>
<% if Event %>
$DateRange
<a href="{$Event.Link}" title="More Details about {$Event.Title}">$Event.Title</a>
<% else %>
No events to display
<% end_if %>
<% end_if %>

But for me I can't get the$Link in the Announcement section to produce a useful URL - it just displays the base URL with a date
e.g. mysite.org.nz/?date=2013-08-28

Any ideas?

One other thing: I got the ICS file thing working for single events - any idea how to do one for the whole calendar?