Jump to:

10993 Posts in 2727 Topics by 1818 members

All other Modules

SilverStripe Forums » All other Modules » EventCalendar 3 - Loading announcements with UpcomingEvents()

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 928 Views
  • cmc
    Avatar
    Community Member
    23 Posts

    EventCalendar 3 - Loading announcements with UpcomingEvents() Link to this post

    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

  • cmc
    Avatar
    Community Member
    23 Posts

    Re: EventCalendar 3 - Loading announcements with UpcomingEvents() Link to this post

    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 %>

  • Lime Blast
    Avatar
    Community Member
    22 Posts

    Re: EventCalendar 3 - Loading announcements with UpcomingEvents() Link to this post

    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.

  • octopuscreative
    Avatar
    Community Member
    9 Posts

    Re: EventCalendar 3 - Loading announcements with UpcomingEvents() Link to this post

    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.

  • Lime Blast
    Avatar
    Community Member
    22 Posts

    Re: EventCalendar 3 - Loading announcements with UpcomingEvents() Link to this post

    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.

  • Riposte
    Avatar
    Community Member
    10 Posts

    Re: EventCalendar 3 - Loading announcements with UpcomingEvents() Link to this post

    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?

    928 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.