Import data from iCalendar to Drupal website. Case study
We usually give some pieces of advice in our blog posts to show you which aspects of your websites can be improved, in what way, and why. We’ve shared easy methods for optimizing site loading speed, performance and SEO, how to make web design more up to date, and more.
These were generalized tips, based on the whole sum of our experiences. This time we decided that it would be a nice idea to write in detail about one of our real-world cases that one of our teams worked on. This will give you some insights into the daily work of our Drudesk specialists. We hope it’ll be useful to show you how we practically help clients on one exact example.
Shortly about client’s website
Our client is a Drupal real estate site owner, which he uses to rent out apartments. Using this website, users can see images of many homes and choose the one they like, then book it for a day or more at advance.
The customer wanted to manage booking scheduling in more convenient way, namely by using iCalendar. Our task was to set up the process of importing data from his iCal account to the website schedule to synchronize the data. This way site users could see up to date information for each house about already booked weeks and free weeks when they can book. Also, we had to provide autoimport every week while keeping the opportunity to manually import the calendar in any time if needed.
The minimum time that users can book houses is one day. However, whole weeks are displayed as available/unavailable on the website. So, data from iCal must run over a week (7-10 days) to identify and mark that week as completely booked. If the minority of days (only 1-3 days out of 7) are booked, the system won’t allow customers to book the next week until the majority of days in the current week are booked.
Challenges we faced
The issue we faced was finding out how to match data. All houses titles almost coincided with URLs in iCal. So out of the iCalendar data we would need the houses’ IDs and the start and end dates of their booking.
There was no Drupal module and no other ready-made contribute solution freely available to the public that we could download and install. That’s why we needed to write a custom code to meet the client’s needs.
The solutions we offered
In order to match the data, we suggested adding the new field "iCal ID" to the node which will contain IDs from the iCalendar.
After that, the updates using Cron should start. This will check all data and send the request. After that, we will parse the results with the help of PHP ICS Parser library to add changes to the database.
The scope of work
1. Task analysis and finding needed tools
2. Task execution.
- Write a batch (custom code) that will receive the weeks updates according to dragged out values of houses’ IDs and IDs from iCalendar and will update statuses of weeks
- Add a new field id_ical
- Create job for Cron and attach custom batch
- Plug in library for parsing data from iCalendar
4. Implementing on the development version and then on the live site
The final result
As a result, we got the functionality that automatically changes each week’s status for each house on the website, based on information from iCalendar. Cron runs iCal migration once a week. Also, it’s possible to force run iCal-migration from the admin page. To do this our client enters his iCal API key in the admin page and run data migration manually when needed.
Our client was satisfied with the result we delivered. Now, when all updates and synchronization is automatic, he can can focus on his main business, not being distracted by technical details.
Our support team is ready to help everyone with Drupal website optimization that positively impact your business success. Drop us a message and get professional support from Drupal experts.