Mass and Sacrament Times on the Archdiocese of St. Louis' Website
• Jeff Geerling
One question I’m often asked by many other diocesan web development teams/individuals is how we put together our online Mass Time search (also used for searching adoration and reconciliation times). We also get questions about how we do our online mapping—but I’ve already covered that (see: Beautiful, Easy Maps in Drupal using Views and Mapstraction).
We already have a database provided by the Archdiocesan IT department (they maintain it with the help of our diocesan Parish Support staff, and parish secretaries who can update their own schedules and information), so we needed to do the following on the web:
Import all the Sacrament time information and attach it to a parish node (so times/days could be affiliated with parishes).
Display the time information on parish node pages, in a meaningful way.
Allow users to search by Sacrament times, showing parishes on a map, and showing the Sacrament times in a list under the map.
I’ll cover each of these important aspects of our website’s functionality below.
Preliminary note: much of this code was provided originally by the great folks at Palantir, who helped us set up this and many other features on the Archdiocesan website…
Importing time information, attaching it to Parish nodes
The first step in the process is importing some 3,000+ parish event nodes (which contain data for each ‘event’ - the event time, the event type (Mass/Reconciliation/Adoration), whether the event is a ‘Normal Service’ or a special kind of Mass, the location of the event (often in a side chapel or somewhere else), the event day, and the reference for the parish to which the event is attached.
Our site uses the Migrate module to import all the data, and we have the module set up to import all the events first, then import the Parishes, attaching the events to parishes (through custom code) using a node reference.
The CSV file containing the parish event data contains over 3,000 lines of information like the following:
Our migrate import takes that line, creates a new node with the information, then later, while importing parish nodes, attaches all event nodes affiliated with that parish to the parish node itself. Then, as they say, the magic happens (via a nodereference field).
Here’s the code we use to prepare our parish event node via the migrate import process:
We basically sanitize the dates coming in from the database (we want them in standard time/0000 format), and then we add taxonomy terms to the dates.
While importing parish nodes, among other things, we attach the parish event nid to the parish node’s masstimes/adorationtimes/reconciliationtimes nodereference fields:
Displaying Event Time Information in the Nodes
To display the time information in a particular node, we simply did a bit of theming magic. It’s not the most highly performant bit of code in the world, but it works.
First, we set up a field_formatter and theme function for parish event times (the following code samples are all from our site’s custom.module):
These two functions just tell Drupal that we’re defining a custom display formatter for parish event times (that can be used in Views, on node teasers, and in full node displays), and then defines a theme function in which we’ll tell drupal how to format everything for display.
This next function is a doozy - it basically does all the display dirtywork, and causes a performance burden on the site—if we tried displaying the mass time information for all 200 parish nodes on the site at once, the queries/processing would probably take 20-30 seconds! Therefore, we cache everything aggressively so people don’t have to wait for the following theme function to do its work—after it’s been done once in a day, it doesn’t have to go again, as we cache the resulting page for 18 hours.
What we basically do here is load each referenced node, then grab all the metadata for that parish event from the parish event node. Then, we display all the metadata in a nice definition list, which gets themed to look like the following:
The final step in the process was to allow users to search on the website by Mass Time (or other Sacrament times), and since we were using Views for all our other search/filtering needs, we decided to use Views to do the time search as well.
Inside our dir_migrate.module (though this could live just as easily in our custom.module), we added a views handler, dir_migrate_views_handler_filter_inttime.
In dir_migrate/views/dir_migrate_views_handler_filter_inttime.inc (this is where we define our custom views filter…):
…and finally, some helpful functions for our integer/time CCK field/formatting, found in dir_migrate/dir_migrate.module:
Wow… this is probably the longest post/code-dump I’ve ever written… sorry about that! Complex issues demand complex solutions, I guess?
Some Things Could Be Improved…
Well, actually, a lot of things could be improved. For instance, we could avoid a lot of this custom code if there were a way to create Date fields without a month or year attached—basically, a timestamp without a fully-compliant ‘date’ attached to it—but this is currently not possible.
Right now, I’m focusing on a few other projects, but someday I really want to tackle issue #499 on our internal tracker: Create timefield module for Time CCK/Field. I envision a module that allows you to add time information to a node like “Saturday, from 4 p.m. to 5 p.m.,” and then be able to filter Views results by time values alone… but I don’t know if/when I’ll get the time to do this :(