1

I am really struggling to get the Solspace Calendar Module to do something that seems to me would be a fairly common requirement.

Use Case

  • I have a travel site which is centered around package tours, and I've created calendar events for each tour's departure schedule.
  • Tour departure events are multi-day, and have repeat rules to determine when the subsequent 'occurrences' will be scheduled.
  • Typically a given tour could have a range of departures that starts in say, January, and ends in December.

I need to output the following

  • day-by-day calendar template
  • listing tour departures ('occurrences') for each day, for the next month or so.
  • I do not want to show multi-day occurrences that already started as this is not useful information for someone who wants to join a tour at the point of departure.
  • I would prefer not to use in-template conditionals to filter out occurrences that already started, because I'm dealing with a lot of data - over 300 tours with 5-50 occurrences for each - and this will be resource intensive, as well as pretty clumsy.

What I've tried

  1. {exp:calendar:cal} template tag (and all other template tags) - eg:

    {exp:calendar:cal date_range_start="tomorrow" pad_short_weeks="n" date_range_end="1 month" first_day_of_week="1"}

    {display_each_day} output occurrence start dates here {/display_each_day}
    

    {/exp:calendar:cal}

    • Fails because it kicks out all occurrences that are in progress on the day specified, rather than just the occurrences that start on the day specified. So I'm seeing events that started before the date range, but are still in progress. Some tours are as long as 56 days, so results will be way out for a daily departure listing.
  2. Custom Query - I was sure this would solve it, but no joy so far.

    SELECT exp_channel_titles.title AS t_title, exp_channel_data.entry_id AS d_entry_id FROM exp_calendar_events_occurrences
    LEFT JOIN exp_calendar_events ON exp_calendar_events_occurrences.event_id = exp_calendar_events.event_id LEFT JOIN exp_channel_titles ON exp_calendar_events_occurrences.entry_id = exp_channel_titles.entry_id LEFT JOIN exp_channel_data ON exp_channel_titles.entry_id = exp_channel_data.entry_id WHERE exp_calendar_events_occurrences.start_date = '{date format="%Y%m%d"}' AND exp_calendar_events_occurrences.calendar_id = '887'

    • this fails because the exp_calendar_events_occurrences table does not appear to actually contain all occurrences. I'm guessing event rules are used by the module to output repeat occurrences that do not appear with this approach.
  • Just to summarize in other words: you're looking to loop through each day, and chronologically display only events whose first* occurrence falls on that day. In other words, if I'm looking at April 10th, an event whose first occurrence is on April 10th will display, but an event that repeats daily, from April 7 to 12, for example, would not display. Is that correct? If so, your first strategy of using {exp:calendar:cal} might be good, and I can elaborate in an answer (sorry, might require a conditional). – Solspace Apr 10 '14 at 6:10
  • Yes - loop through each day, but no, I want to display any occurrence, but only if it starts on the day in question. At the moment I am getting any occurrence that starts, ends or is in progress on that day. My users are only interested in start dates, as these are multi-day events (tours) that depart from the listing location. – Luke Hardiman Apr 12 '14 at 5:13
  • This use-case would of course also apply to many other scenarios - multi-day conferences, festivals, basically anything where the critical date to list by is the start date, and anything thereafter is not meaningful in the context of an 'upcoming events' type listing. – Luke Hardiman Apr 12 '14 at 5:31
1

{exp:calendar:cal} has the following tags that could be used:

  • {event_start_date}, which displays the occurrence's start date.
  • {event_first_date}, which displays the date of the event entry's first occurrence.

For example, if you have an event that starts and ends on April 11th, and repeats daily until April 17th, {event_first_date} will be April 11, but {event_start_date} will display the start date of each looping occurrence (April 11, 12, 13, 14, 15, 16, 17).

In your situation you need to check if {event_first_date} isn't before the first day of your {exp:calendar:cal} timeframe. For example:

{exp:calendar:cal 
     date_range_start="2014-04-11" 
     date_range_end="2014-04-17" 
     pad_short_weeks="n"}
  {display_each_day}
    {events}
       {if '{event_first_date format="%Y-%m-%d"}' >= '2014-04-11'}
           // Show occurrence data
       {/if}
    {/events}
  {/display_each_day}
{/exp:calendar:cal}

This will only display the occurrence if the event's first occurrence is on or after 2014-04-11. (You can tweak the conditional to check for {event_last_date} and the last day of your range as well if needed)

You might now think: "Great! But how to make the "2014-04-11" part dynamic?"

You can do this by using the {exp:calendar:date} tag: http://www.solspace.com/docs/calendar/date/

For example:

{exp:calendar:date base_date="today" output_date="today"}{date format="%Y-%m-%d"}{/exp:calendar:date}

This would turn the {exp:calendar:cal} above to something like this:

{exp:calendar:cal 
     date_range_start="today" 
     date_range_end="+7 days" 
     pad_short_weeks="n"}
  {display_each_day}
    {events}
       {if '{event_first_date format="%Y-%m-%d"}' >= '{exp:calendar:date base_date="today" output_date="today"}{date format="%Y-%m-%d"}{/exp:calendar:date}'}
           // Show occurrence data
       {/if}
    {/events}
  {/display_each_day}
{/exp:calendar:cal}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.