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.
The Bugs
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.
In Retrospect
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<br>http://<path>/ical?start=today&spanNum=2&spanType=Weeks&type=all<br><br># iCal - For those people who don't need a constant reminder of exhibitions<br>http://<path>/ical?start=today&spanNum=2&spanType=Weeks&type=events<br><br># <span class="caps">RSS</span><br>http://<path>/rss?start=today&spanNum=2&spanType=Weeks&type=all&format=default
The page that generates these events would look like this:
<span style="color: #000000"><span style="color: #0000BB"><?php<br> </span><span style="color: #FF8000">// Default to today and two weeks after today<br> </span><span style="color: #0000BB">$startDate </span><span style="color: #007700">= </span><span style="color: #0000BB">$_GET</span><span style="color: #007700">[</span><span style="color: #DD0000">'start'</span><span style="color: #007700">] ? </span><span style="color: #0000BB">$_GET</span><span style="color: #007700">[</span><span style="color: #DD0000">'start'</span><span style="color: #007700">] : </span><span style="color: #DD0000">'today'</span><span style="color: #007700">;<br> </span><span style="color: #0000BB">$spanNum </span><span style="color: #007700">= </span><span style="color: #0000BB">$_GET</span><span style="color: #007700">[</span><span style="color: #DD0000">'spanNum'</span><span style="color: #007700">] ? </span><span style="color: #0000BB">$_GET</span><span style="color: #007700">[</span><span style="color: #DD0000">'spanNum'</span><span style="color: #007700">] : </span><span style="color: #DD0000">'2'</span><span style="color: #007700">;<br> </span><span style="color: #0000BB">$spanType </span><span style="color: #007700">= </span><span style="color: #0000BB">$_GET</span><span style="color: #007700">[</span><span style="color: #DD0000">'spanType'</span><span style="color: #007700">] ? </span><span style="color: #0000BB">$_GET</span><span style="color: #007700">[</span><span style="color: #DD0000">'spanType'</span><span style="color: #007700">] : </span><span style="color: #DD0000">'Weeks'</span><span style="color: #007700">;<br> </span><span style="color: #0000BB">$eventType </span><span style="color: #007700">= </span><span style="color: #0000BB">$_GET</span><span style="color: #007700">[</span><span style="color: #DD0000">'type'</span><span style="color: #007700">] ? </span><span style="color: #0000BB">$_GET</span><span style="color: #007700">[</span><span style="color: #DD0000">'type'</span><span style="color: #007700">] : </span><span style="color: #DD0000">'all'</span><span style="color: #007700">;<br><br> </span><span style="color: #0000BB">$dates </span><span style="color: #007700">= </span><span style="color: #0000BB">get_span_dates</span><span style="color: #007700">(</span><span style="color: #0000BB">$startDate</span><span style="color: #007700">, </span><span style="color: #0000BB">$spanNum</span><span style="color: #007700">, </span><span style="color: #0000BB">$spanType</span><span style="color: #007700">);<br> </span><span style="color: #0000BB">$events </span><span style="color: #007700">= </span><span style="color: #0000BB">get_events</span><span style="color: #007700">(</span><span style="color: #0000BB">$dates</span><span style="color: #007700">[</span><span style="color: #DD0000">'start'</span><span style="color: #007700">], </span><span style="color: #0000BB">$dates</span><span style="color: #007700">[</span><span style="color: #DD0000">'end'</span><span style="color: #007700">], </span><span style="color: #0000BB">$eventType</span><span style="color: #007700">);<br><br> </span><span style="color: #0000BB">$output </span><span style="color: #007700">= </span><span style="color: #DD0000">''</span><span style="color: #007700">;<br> </span><span style="color: #0000BB">$output </span><span style="color: #007700">.= </span><span style="color: #0000BB">$events</span><span style="color: #007700">[</span><span style="color: #DD0000">'events'</span><span style="color: #007700">];<br> </span><span style="color: #0000BB">$output </span><span style="color: #007700">.= </span><span style="color: #0000BB">$events</span><span style="color: #007700">[</span><span style="color: #DD0000">'exhibitsStarting'</span><span style="color: #007700">];<br> </span><span style="color: #0000BB">$output </span><span style="color: #007700">.= </span><span style="color: #0000BB">$events</span><span style="color: #007700">[</span><span style="color: #DD0000">'exhibitsEnding'</span><span style="color: #007700">];<br><br> print </span><span style="color: #0000BB">$output</span><span style="color: #007700">;<br></span><span style="color: #0000BB">?></span></span>
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.