My company is getting ready to switch over to Office 365. We're looking to use exchange calendars for events (we're a school system of three schools and there a lot of calendars with a lot of events). In the hope of not having to double enter most of our events, we are trying to use exchange's publish feature (which creates an ics file) with feeds and Date ical to directly import the whole mess.

Now to my question, since I'm fairly certain microsoft has not provided me a way to change what gets put into the ics file (which does not include categories) I am hoping to find a way to use the X-WR-CALNAME to map as a taxonomy term. Problem, this module looks at each event and maps only the items that exist for each event. Is there a way to get the X-WR-CALNAME and apply it to all events mapped by the feed?

CommentFileSizeAuthor
#8 calendar_categorizer.zip1.79 KBcoredumperror
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

coredumperror’s picture

You sure can! Date iCal provides a number of alter hooks for the import process, which you can implement in a custom module to tweak the data before it gets processed into nodes.

Your best bet is probably to implement hook_date_ical_import_component_alter() to change each component (event) in the calendar. That hook gets passed the full calendar object as part of its context (check out the date_ical.api.php file for the full docs on this hook), so you'd be able to extract the X-WR-CALNAME from it and place it into the CATEGORIES property of each event.

Since you'll be messing around with the objects provided by iCalcreator, you'll need to learn a bit about how they're laid out. If you check out the code in includes/DateiCalFeedsParser.inc, you'll see how I interact with those objects (vcalendar and vevent objects, mostly), which should be a good starting point. You may also want to read the iCalcreator documentation.

modulo49’s picture

Thanks for the quick reply. This is further than I normally go into php, but I'll give it a go.

coredumperror’s picture

If you have trouble, please let me know.

modulo49’s picture

I would appreciate any help you can give. I can write a few little php scripts, but hooks and custom modules are completely new to me.

modulo49’s picture

Yeah, pretty much completely lost. Here's a sample output from exchange's ical feed. If I understand your function right, I can alter components... but there is no category component to alter.

BEGIN:VCALENDAR
METHOD:PUBLISH
PRODID:Microsoft Exchange Server 2010
VERSION:2.0
X-WR-CALNAME:VSB
BEGIN:VTIMEZONE
TZID:Pacific Standard Time
BEGIN:STANDARD
DTSTART:16010101T020000
TZOFFSETFROM:-0700
TZOFFSETTO:-0800
RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=11
END:STANDARD
BEGIN:DAYLIGHT
DTSTART:16010101T020000
TZOFFSETFROM:-0800
TZOFFSETTO:-0700
RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=2SU;BYMONTH=3
END:DAYLIGHT
END:VTIMEZONE
BEGIN:VEVENT
DESCRIPTION:VSB\n\n
SUMMARY:VSB @ Calvary Murrieta
DTSTART;TZID=Pacific Standard Time:20140325T150000
DTEND;TZID=Pacific Standard Time:20140325T163000
UID:040000008200E00074C5B7101A82E00800000000C09EFF9CCC48CF01000000000000000
 010000000A9CF613F17D27147A59CF0FBA96DD6D2
CLASS:PUBLIC
PRIORITY:5
DTSTAMP:20140328T153848Z
TRANSP:OPAQUE
STATUS:CONFIRMED
SEQUENCE:0
LOCATION:Local Field
X-MICROSOFT-CDO-APPT-SEQUENCE:0
X-MICROSOFT-CDO-BUSYSTATUS:BUSY
X-MICROSOFT-CDO-INTENDEDSTATUS:BUSY
X-MICROSOFT-CDO-ALLDAYEVENT:FALSE
X-MICROSOFT-CDO-IMPORTANCE:1
X-MICROSOFT-CDO-INSTTYPE:0
X-MICROSOFT-DISALLOW-COUNTER:FALSE
END:VEVENT
END:VCALENDAR
coredumperror’s picture

Sorry for the delay! I ended up being super busy all weekend and didn't have a chance to get to this. I'll sit down right now and work up a hook for you.

modulo49’s picture

No worry about delay, it's very kind of you to supply any kind of help to this degree.

coredumperror’s picture

FileSize
1.79 KB

Alright, here's a little one-function custom module that you can install into your Drupal site, which should do what you need. In addition to that, though, you'll need the latest dev release of Date iCal. In looking at your problem, I realized that the right way to solve it was to actually add another hook to Date iCal, which lets modules tweak the final parsed data before it gets sent to Feeds. That's how this custom module does its thing.

Unfortunately, Drupal.org is very slow about creating new Date iCal releases from recent pushes to the git repository. In fact, they appear to have just changed the system, making it far more confusing (it claims that a new dev release from today is already available, but it's actually still serving the old dev release). So you'll either need to wait until tomorrow to download the usual 7.x-3.x-dev release, or you can follow the instructions here to download the latest code from Date iCal's git repo.

Once you've installed both this custom module and the newest Date iCal dev release, clear your site's cache. Then you should be ready to go.

modulo49’s picture

It works exactly the way it should. Can't thank you enough. I would never have figured that out.

coredumperror’s picture

Status: Active » Fixed

Glad to hear it!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

rasmusknabe@gmail.com’s picture

Hi, just found this thread since I'm working on a project where i need to map the X-WR-CALNAME of an imported calendar to a taxonomy term reference on the imported node.

The solution listed here seem to add the calendar name to the CATEGORIES, but i simply need to be able to map the X-WR-CALNAME to a field, and not mix it up with what ever the categories contains.

I need this to be able to sort between different imported calendars in the calender view - is there a way to go about this?

NOTE: I'm unsure if i should ask here or open up a new issue?

coredumperror’s picture

Please do open a new issue. Commenting on an issue that was closed almost 3 years ago is called "necroing", and is highly discouraged.

rasmusknabe@gmail.com’s picture

Sorry about that, I'm not familiar with best practice here.

I'll open a new issue - thanks!