See also: Extending the calendar
The Event Calendar module was developed to facilitate the display and creation of date-based content in Silverstripe from simple calendar announcements to complex events. It features:
Requires a minimum of 2.2.0 version of Silverstripe.
Module Installation
1. Download the Event Calendar module
2. After extraction, place the event_calendar folder at the root of your Silverstripe installation.
3. Run db/build?flush=1
4. The CMS should now have Calendar and Calendar Event page types.
This is the principal class that manages the Calendar page type. It contains many functions for getting CalendarEvents, browsing the calendar, and rendering UI components. Its only allowed children are CalendarEvent.
The CalendarEvent object is a subclass of Page that lives under a Calendar in the SiteTree. CalendarEvent objects will show up on the main Calendar view, but also have their own detail pages with custom templates.
Contains all the Date and Time information for a CalendarEvent. One CalendarEvent may have many CalendarDateTime objects associated with it. The CalendarDateTime class is also responsible for handling a lot of the display functions including $_Dates, $_ICSLink, and Microformat.
Contains UI components CalendarWidget and MonthNavigator
A static class that handles a lot of the commonly used date parsing or formatting tasks.
A subclass of FieldSet used to contain FormFields that are part of the CalendarFilterForm.
Objects associated with CalendarEvents that repeat.
The sfDate plugin for Symfony has been decoupled from the PHP framework to work with the EventCalendar module. It contains many robust methods for manipulating dates and touts a very user-friendly API.
You can pass any custom date range into the URL of any Calendar page using the Y-M-D format (with or without dashes). If you leave out part of the date, the Calendar will automatically set the missing components for you. Examples:
After you create a Calendar page, you will notice two unique tabs.
Here you can set the default number of events to display on the calendar landing page. This is a fixed number of events that is not bound by months or years. This way, the default view of your calendar will always show a generous list of events, rather than being constrained by a specific month view.
Each calendar varies in the amount of content that is associated with each event. For that reason, calendars have configurable behaviors for handling event descriptions. Users can choose from:
Sometimes, an event is so sparse with content, it may not be necessary to include it in the site tree as a whole new page. Announcements are designed to fulfill the need for lightweight calendar insertions such as “Thanksgiving – CLOSED” or “John’s birthday.” These are calendar items that do not need their own pages or lengthy content blocks.
An event is just like any other page type, only it has a Dates and Times tab. There, you can add any number of dates, consecutive or non-consecutive, to associate with the event.
If there is more than one time associated with your event, just add a duplicate date with a different time. For instance, for an event on 10/31/2008 (US Format) with times of 1:00PM and 3:00PM, create two rows for 10/31/2008, and set one start time to 1:00PM and one to 3:00PM. The calendar will automatically collapse the date into one entry when viewed on the frontend.
If your event only has one day, you’ll be able to click the “Repeat this event” checkbox. This will expose some configuration options that will allow you to repeat an event at just about any regular pattern imaginable.
If there are any exceptions to the pattern, enter those dates in the Exceptions table below. For instance, if you have an event that occurs every other Thursday, and you’re in the US, you might want to add the date of Thanksgiving as an exception.
The template that comes with the Event Calendar module is a good resource for all the tools you’ll need to create a customized template for your website.
The Events control is the engine that drives the list of dates on all calendar views. While it may seem like a simple database query, it actually does a lot of legwork behind the scenes to account for announcements and repeating events, parse date ranges passed through the URL, handle the event search form, etc. The most counter-intuitive characteristic of the Events control is that it does not return CalendarEvent objects. Because the calendar is date-centric, it returns CalendarDateTime objects. These objects can be inserted by a repeating event, announcement, or one or many dates associated with a CalendarEvent. Therefore, to access the Page properties of an entry in the calendar it is necessary to refer first to the related event. For example, $Event.Title or $Event.URLSegment.
Note: $Event.Link is not necessary because the CalendarDateTime object has its own $Link method. Other Controls
There are a number of functions available for the proper display logic in the template. Because the event description behavior can be configured in the CMS, it is often necessary to evaluate which of those options was chosen. These functions include Blind, LinkTo, ShowAll, BlindOrLink, BlindOrShowAll, and ShowAllOrLink. It is important to remember that once in a control statement, these controls are only available through the CurrentPage property. Example:
<% control Events %> <% if Announcement %> $Title <% else_if CurrentPage.BlindOrLink %> <a rel="toggle" href="$Link" class="toggle-$ID">$Event.Title</a> <% else %> $Event.Title <% end_if %> <% end_control %>
Note: Because it is commonly used the above logic can all be handled transparently by the $_Title method. (see magic methods)
Also valuable is the Announcement boolean which will allow you to handle announcements differently than standard events. For example, you do not want to give an announcement a hyperlink, since it is not a page.
<% if Announcement %> $Description <% else %> $Event.Content <% end_if %>
There are a few UI tools bundled with the EventCalendar module to give your calendar a heightened user experience.
– Based on a simple jQuery date picker, this javascript calendar has been expanded to allow day, week, and month selection for the displayed date range. It is stateful, date aware, and makes browsing the calendar quite snappy.
– Renders a search form for your calendar. By default, it provides fields for start date and end date, but can be expanded to hold additional fields, as well.
- A separate include file that gives a calendar the functionality to show or hide all the event descriptions.
Microformats are increasingly popular XML data formats on the web that make the syndication of content easy using widely adopted standards. For more information, visit microformats.org.
For the purposes of the EventCalendar module, the bulk of microformatting tasks are handled by the Magic methods in the CalendarDateTime class, however there are a few things a developer should be aware of when creating a custom template for your calendar.
There are several “magic” methods in the CalendarDateTime class that help streamline a lot of the common display logic on the template. Identified by the $_ prefix, magic methods also write out some of the markup that has specific requirements, such as microformats and the blind-down effect.
While the EventCalendar module is feature-rich on its own, it is intended to provide a starting point for a more customized calendar. Its easy-to-use API makes extending the calendar very simple. See Extending your Calendar for more information.
Please raise issues, bugs, contributions in the silverstripe.com forum.
Add a static variable the CalendarDateTime class that determines US or European date format
Currently, the only date display available through the MagicDates method is M j, Y (in the PHP date() syntax).
If a CalendarDateField appears on a TableField and is later used on a ComplexTableField, clicking on the calendar icon will open a popup window throwing an error.
If you have installed the EventCalendar module and you are not seeing events correctly on your calendar check the following:
1. Are event properties being accessed with the $Event accessor? E.g. $Event.Title, $Event.Content, etc?
2. Is the date range in your URL invalid? Proper format is YMD format with no dashes or spaces with leading zeros. For instance www.mysite.com/my-calendar/20081002/20081020 for date range October 2-20.
3. Did you set up a repeating event with a start date that is not part of the pattern? E.g. an event that is set up to repeat every Monday should not have a start date that is a Wednesday.
4. Rebuild the Silverstripe database with /db/build?flush=1
5. Flush the template cache with ?flush=1
Please use comments for notes, tips and corrections about the described
functionality.
Use the Silverstripe Forum to
ask questions.