Jump to:

10928 Posts in 2612 Topics by 1809 members

All other Modules

SilverStripe Forums » All other Modules » EventCalendar - Individual event list on homepage

Discuss all other Modules here.

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

Page: 1 2
Go to End
Author Topic: 1345 Views
  • seah0rse
    Avatar
    Community Member
    5 Posts

    EventCalendar - Individual event list on homepage Link to this post

    Hi,

    I am trying to display a list of upcoming events and announcements on a homepage. I can display all events and announcements for multiple calendars by using the rss feed option combo. But I do not want to do that as I would like to list each calendars title and then a list underneath.
    eg
    Seniors events (cal name)

    • event 1
    • announce 1
    • event 2
    • announce 2

    Masters events (cal name)
    • event 1
    • announce 1
    • event 2
    • announce 2

    I have the following functions in my homepage controller
    public function SeniorEvents() {
    $where = "ParentID = 23";
    return DataObject::get_one("Calendar")->upcomingEvents(10, $where);
    }

    public function AllCalendars() {
    return DataObject::get('Calendar');
    }

    The last method lists each calendar but I cant get the events and I get an error if i try to call the upcoming events on the datalist..
    The first function always pulls the data from the first calendar it comes across even if i use the filter clause.
    Here is the where clause WHERE ("Recursion" = '1') AND ("ParentID" = '24') AND (ParentID = 23) AND ("SiteTree_Live"."ClassName" IN ('CalendarEvent')) ORDER BY "SiteTree_Live"."Sort" ASC,256) Calendar id 24 is always in the clause. If I use the template to pass the url frag to the function this does not appear to do anything..

    If anyone can help me I appreciate it..
    Also one other thing there is an incomplete url formed with any announcements listed via the upcoming events method...
    announcement url = http://localhost/site/?date=2013-01-05
    event url = http://localhost/site/surf-sports/surf-boat-rowing/senior-calendar/event-name/

    Many thanks in anticipation.. (Uncle Cheese...help please)

    cheers Tim

  • seah0rse
    Avatar
    Community Member
    5 Posts

    Re: EventCalendar - Individual event list on homepage Link to this post

    oops forgot...

    If I do this in my AllCalendars template then I get close to what I am after nut no announcements and no dates..

    <h4>All Calendars</h4>
    <ul>
    <% control AllCalendars %>
    <li>$ID <a href="{$Link}" title="More Details about {$Title}">$Title</a></li>
    <ul>
    <% control children %>
    <li>$ID $DateRange<a href="{$Link}" title="More Details about {$Title}">$Title</a></li>
    <% end_control %>
    </ul>
    <% end_control %>
    </ul>

  • UncleCheese
    Avatar
    4085 Posts

    Re: EventCalendar - Individual event list on homepage Link to this post

    Is this EventCalendar 3 or 2.4?

  • seah0rse
    Avatar
    Community Member
    5 Posts

    Re: EventCalendar - Individual event list on homepage Link to this post

    oops sorry this is 3.x. I see you have added a upcoming announcements method... Also my template example above does not have the dates var in it but I have been using $Debug to test. I understand that with the announcements VS the events that the events have dedicated pages whilst the announcements are on the same page as the calendar.. Just need to inject the url segment for the cal to the announcement link (absoluteLink())?

    For the all calendars list and upcoming events and announcements - I was thinking if I could do a get on the calendar object and then for each call get_one and call the upcomingEvents method and then add the resulting array as children?

    Thanks for your help.

  • seah0rse
    Avatar
    Community Member
    5 Posts

    Re: EventCalendar - Individual event list on homepage Link to this post

    I can do this but not sure if it the right thing to do..? Also how do I template it?

    public function AllCalendars() {
    $set = new ArrayList;
    $calendars = Calendar::get()->sort('Title');
    $set->push($calendars);

    foreach ($calendars as $calendar) {
    $set->push($calendar->upcomingEvents(10));
    }

    //print_r($set);
    return $set;
    }

  • UncleCheese
    Avatar
    4085 Posts

    Re: EventCalendar - Individual event list on homepage Link to this post

    On the "Feeds" tab of your calendar, you can select other calendars to pipe into your main calendar. Just check off the ones you want, and then when you run UpcomingEvents() on your main calendar, it will include the events of all the other calendars that you selected.

    ---------------
    Silverstripe tips, tutorials, screencasts, and more. http://www.leftandmain.com

  • UncleCheese
    Avatar
    4085 Posts

    Re: EventCalendar - Individual event list on homepage Link to this post

    FYI, <% control %> is deprecated. Use <% loop %>.

    ---------------
    Silverstripe tips, tutorials, screencasts, and more. http://www.leftandmain.com

  • seah0rse
    Avatar
    Community Member
    5 Posts

    Re: EventCalendar - Individual event list on homepage Link to this post

    Thanks for the reply.. Ok so I can create a 'master' cal and then use the rss option to 'integrate' all my 'real' cal events and announcements into that cal. I do not want to display that cal on the site. Do I select the master cal dataobject in the home page controller like so?

    So I need something like...

    public function AllCalendars() {
    return Calendar::get_by_id('Calendar', 11)->upcomingEvents(20);
    }

    and in my template

    <% if AllCalendars %>
    <h4>All Calendars</h4>
    <ul>
    <% loop AllCalendars %>
    <% if Announcement %>
    <li>$DateRange - $Title<br/>$Content.BigSummary(20)</li>
    <% else %>
    <li>$DateRange - <a href="{$Link}" title="More Details about {$Title}">$Title</a><br/>$Content.BigSummary(20)</li>
    <% end_if %>
    <% end_loop %>
    </ul>
    <% end_if %>

    This works but I still have broken links in my announcements - they are formatted like: http://sitename/?date=2013-01-03
    But I can fix this with some conditional code in my template to remove the link - (not great).

    It would be nicer but trickier to have a summary of each cals up coming events and cals like I posted before..

    Seniors events (cal name)
    s event 1
    s announce 1
    s event 2
    s announce 2
    Masters events (cal name)
    m event 1
    m announce 1
    m event 2
    m announce 2
    Juniors events (cal name)
    j event 1
    j announce 1
    j event 2
    j announce 2
    etc...

    1345 Views
Page: 1 2
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.