Event Distribution: Create a custom span of events
For the Brown University Featured Events website, I needed to develop a means to use their events for other purposes around the Brown.edu websites. I ultimately created a basic way of exporting iCal, RSS and HTML of a selected span of events.
The goal was to create a self service center for Brown University webmasters to grab a feed of events and use them on their own websites. I had to create a UI where a webmaster could create a feed based on event type, time constraints and tags. This would allow the drama department to display on their website events of all plays occurring in the next three months. The feed would automatically update as new events are added to the Featured Events website.
The User Interface
My first assumption was to generate the iCal and RSS feeds using views and expose date fields to allow a user to pick custom time constraints. Unfortunately, that method created an extremely cumbersome interface.
In order to display events for a desired time span, I needed four exposed date fields: ‘start date before,’ ‘start date after,’ ‘end date before’ and ‘end date after.’ All of those in addition to event type and tag selection fields! To make it even more kludgey and cumbersome, the view was cloned to have one sorting by start date, and the other by end date in order to support exhibitions.
Despite its cumbersomeness, we went with it anyway. Only initially, though.
We really banged our heads against that UI. We hit two critical bugs for this attempt: the inability to expose the same field twice and the date module rejecting valid date formats. In order to support exhibitions, we needed to use the start date twice because the end date would be after and the start date before the beginning of the given time span.
Although we spent a lot of time tracking down and solving the above bugs, we ended up with some rather simple patches for them: [inline:views_query.inc.patch] and [inline:date_views.inc.patch] (However, they won’t work for all websites).
Despite the patches, the UI was still clunky, and it was difficult for a webmaster to create a dynamic feed that will shift dates automatically (say, always showing the next month of events).
The Birth of wholly using a Custom Script
I wanted a UI that was simple and straight forward. I allowed the editor to only enter a start day (which defaults to today) and a time span from the start date. The custom script then automatically generated the events and exhibitions in proper order. It was a very simple interface, asking two questions: start date and time span. Great!
In the end, the new UI would only ask the start date, time span, event type and display format for RSS feeds. Much simpler.
Gather Events in the Time Span
Since I am generating the appropriate events for a given time span, I don’t encounter the issue dealing with exhibitions because I can group and sort the returned events in whatever means is the most appropriate.
For my use the appropriate order was:
- events in ascending ordered by start date
- exhibitions that start in the time span ordered by start date
- exhibitions ending after the beginning of the time span ordered by end date, positioned below exhibitions starting in the time span
This is the script I ended up with: custom_span_events.php.
My script involves writing a script to query the database directly. However, it could be done by integrating views, and inputting arguments and exposed filters directly into the views_build_view() function.
Utilize URI Fragments
Different events can then be served depending upon the URI. A webmaster can use the self serve interface to generate the URI’s, or just manipulate the URI themselves:
# iCal - All Events
# iCal - For those people who don't need a constant reminder of exhibitions
The page that generates these events would look like this:
// Default to today and two weeks after today
$startDate = $_GET['start'] ? $_GET['start'] : 'today';
$spanNum = $_GET['spanNum'] ? $_GET['spanNum'] : '2';
$spanType = $_GET['spanType'] ? $_GET['spanType'] : 'Weeks';
$eventType = $_GET['type'] ? $_GET['type'] : 'all';
$dates = get_span_dates($startDate, $spanNum, $spanType);
$events = get_events($dates['start'], $dates['end'], $eventType);
$output = '';
$output .= $events['events'];
$output .= $events['exhibitsStarting'];
$output .= $events['exhibitsEnding'];
Ultimately this becomes a cleaner UI because it involves much fewer input options from the user. Using the dynamic start time, ‘today’, will create a consistently updated feed of events.