Hi,

Thank you for the module. I am experiencing some issues implementing AddtoCal for repeating dates. Wondering if anyone else has this implemented without the below issues.

I have Add to Cal format selected for a repeating date field in the display settings for an event content type. In the display settings for the field, when I enter 'now' in the starting from option (so that only future dates are shown for the event), select 'Show repeat rule' under Repeat rule(please see attached screenshot) and save the settings, I see the below errors and nothing else when I go to an individual event page.

Warning: array_key_exists() expects parameter 2 to be array, null given in addtocal_extract_event_info() (line 414 of /var/www/mysite/sites/all/modules/contrib/addtocal/addtocal.module).
Exception: DateTimeZone::__construct(): Unknown or bad timezone () in DateTimeZone->__construct() (line 519 of /var/www/mysite/sites/all/modules/contrib/addtocal/addtocal.module).

Thank you.

Comments

saratt’s picture

StatusFileSize
new1.1 KB

Hi,

I think I was able to identify the issue. In the function addtocal_extract_event_info start date is set to the first value in the dates array. But if its a repeating date and if the first occurrence of the date has passed, the $dates[0]['value'] is not valid anymore. The first value will be $dates[1]['value'], likewise if the first two occurrences of the date have passed, the first value in the dates array will be $dates[2]['value'].

For example, if there is a repeating date field and it occurs every sunday starting April 12th 2015 until May 24th 2015, if today is April 22nd, the dates array will not have April 12th at $dates[0]['value']. The dates array will start at $dates[2]['value], which will be the April 26th, since the starting from option in the field displaying settings is 'now'.

I am attaching a patch, that always uses the first value in the array, instead of assuming it to be $dates[0]['value'], which would solve this particular issue.

Could you please take a look and let me know if you see any issues.

Thank you.

saratt’s picture

Status: Active » Needs review
pjbarry21’s picture

I've been wanting this same functionality -- thanks!

Unfortunately, it doesn't fully work for me. I have a dev version of Date from 3/27/15 and the latest Add to Cal.

After I apply the patch, I get the Add to Calendar button, but the date of the current/next event (that should be triggered by "now" in the start date field) never appears in the node view (I am using Display Suite). It's either blank or it shows the start of the first event (depending on the settings I've set in the field display settings).

Any thoughts?

saratt’s picture

pjbarry21, yes, that part still doesn't work. I have started looking into it. All I was trying to do, to start with was to overcome those errors.

pjbarry21’s picture

Thanks for the clarification. The patch doesn't change much for me (but also doesn't break anything, if that helps, at all) -- my events displayed before applying the patch. The issue I currently have is just the general functionality of the module with repeating events.

lisa.rae’s picture

This patch resolves the error in question for me. We applied this patch to the dev version of the codebase, pinned at commit #b39b69f, nearly two years ago.

govind.maloo’s picture

StatusFileSize
new1.23 KB
govind.maloo’s picture

StatusFileSize
new1.25 KB
govind.maloo’s picture

StatusFileSize
new1.72 KB
banoodle’s picture

StatusFileSize
new3.07 KB

Repeating dates weren't working for me either: attempts to add them to calendars like google resulted in the date reflecting the fist occurrence of the repeating event, even if in the past. The soonest future date is what we want for our use case and I imagine it is what most people would want.

I tried the patch in #1 and it didn't help, but it did give me inspiration on how to fix the problem (thanks!).

I've tested the attached patch and it works well for my needs, but community review and feedback is greatly appreciated.

banoodle’s picture

The patch I added in comment #10 works well for google calendar, but I am now realizing work remains to be done in order for repeating events to work the same way in iCal and yahoo (and possibly Outlook - I don't own that program so can't validate it).

In iCal it displays the first occurrence of the event even if in the past (like google did before my patch).

In Yahoo, it gets close to showing the correct date, but it's offset -12 hours.

I will try to work on these remaining issues this weekend.

banoodle’s picture

StatusFileSize
new4.97 KB

OK this patch includes fix for google included in patch for comment #10, plus fixes repeating dates for iCal and yahoo.

Feedback appreciated.

banoodle’s picture

Just to clarify: my fix in comment #12 "fixes" repeating date events in the sense that it ensures the soonest future occurrence is transmitted to your calendar, but it does not transmit the recurrence rules, so it only adds the one occurrence to your calendar. Without the patch, you also just add one event to your calendar, but the date and time was off.

I would like to attempt a patch that truly supports recurring dates so that the entire series of events is transmitted to your calendar. Watch this space.

banoodle’s picture

StatusFileSize
new4.97 KB

This patch builds on my last two patches, adding better support for repeating dates for google, iCal and Outlook.

I now have repeating dates transmitting properly to google calendar, but I was not able to get excluded dates to be transmitted.

For iCal and Outlook, I have repeating dates fully working including the excluded dates (or maybe I should say excluding the excluded dates - lol).

I was not able to get repeating dates to show up in yahoo calendar (does anyone even use yahoo calendar any more?).

If anyone is interested, I wrote a custom hook_addtocal_extract_event_info_alter function that adds a "PLEASE NOTE: This event will NOT occur on the following date(s):" message with a list of excluded dates to the event description. It's not ideal, but it at least provides some indication of excluded events in google calendar.

You'll need to modify this for your unique situation...

function hook_addtocal_extract_event_info_alter(&$info, $entity_type, $node) {

  // Get body, strip html tags, truncate.
  $text = $node->body[LANGUAGE_NONE][0]['value'];
  $text = decode_entities(strip_tags($text));
  $text = preg_replace('/\s+?(\S+)?$/', '', substr($text, 0, 300));

  // Display excluded repeating dates in the description since we can't transmit them.
  $excluded = $node->field_event_date[LANGUAGE_NONE][0]['rrule'];
  $excluded_clean = str_replace("\r\n", '|', $excluded);
  $exdates = explode('|', $excluded_clean);
  $just_exdates = str_replace('EXDATE:', '', $exdates[1]);
  $exdates_array = explode(',', $just_exdates);
  $formatted_exdates = [];
  $current_date = new DateTime();
  foreach ($exdates_array as $exdate) {
    $exdate_object = new DateTime($exdate);
    if ($exdate_object > $current_date) {
      $exdate_formatted = $exdate_object->format('F j, Y');
      $formatted_exdates[] .= $exdate_formatted;
    }
  }
  $new_exdates = '';
  if (!empty($formatted_exdates)) {
    $new_exdates = "\n\n" . t('PLEASE NOTE: This event will NOT occur on the following date(s): ') . implode(', ', $formatted_exdates);
  }

  $info['description'] = $text . $new_exdates;
}
banoodle’s picture

StatusFileSize
new12.88 KB

Uploading new patch that fixes problem I noticed with non-repeating dates.

very_random_man’s picture

StatusFileSize
new13.04 KB

I ran that last patch. It works better but I noticed the delta was missing in a couple of places. Here's a new version of the patch but with the addition of swapping out the hard-coded zero delta in the base url with the first key and also including that in the info extraction above that. Now the ical file contains the forthcoming date.

very_random_man’s picture

I was looking at how this works currently after patching and it seems to generate a single calendar event for the next forthcoming date. I think it would be nice to have the option to either behave like this or add something like this to add repeats into the calendar too:

RRULE:FREQ=WEEKLY;UNTIL=20211031T235959Z;INTERVAL=1;BYDAY=MO;WKST=MO

This is taken from how events are rendered if you create an ical feed in Views. Would be nice to enable it or not in the field config and give the end user a choice of all events or just the next one. Maybe via some more menu entries?

I'll have a look at it if I get a moment but it's out of scope for me currently so i don't have much time to spend.

wjackson’s picture

StatusFileSize
new13.13 KB

Hello,

When applying the most recent patch, we noticed that the first hunk didn't apply cleanly as well as there is a warning that is introduced:

Warning: A non-numeric value encountered in addtocal_render() (line 503 of /var/www/sites/all/modules/contrib/addtocal/addtocal.module).

The attached patch resolve the issue with the first hunk applying cleanly and resolve the warning.

kristen pol’s picture

Status: Needs review » Needs work

Thanks for the update. I scanned the code quickly and noticed some commented-out code that should be removed if it's not needed anymore.

  1. +++ b/addtocal.module
    @@ -10,9 +10,10 @@
    +  // foreach (addtocal_get_addtocal_entities() as $entity_name => $values) {
    
  2. +++ b/addtocal.module
    @@ -36,7 +37,7 @@ function addtocal_menu() {
    +  // }
    
  3. +++ b/addtocal.module
    @@ -678,21 +712,35 @@ function addtocal_yahoo_link($entity, $field_name, $view_mode) {
    +//  $timezone = $entity->field_event_date['und'][$delta]['timezone'];
    
awset’s picture

StatusFileSize
new3.1 KB
new13.42 KB

in this patch, I have removed the commented code also the modification to addtocal.info file,
I don't think we need to add those information to the info file.

I also attached the the interdiff 18 vs 20.

kristen pol’s picture

Status: Needs work » Needs review
Issue tags: +Bug Smash Initiative, +Needs manual testing

Moving to needs review.

kristen pol’s picture

Thanks for the patch and the interdiff. I have confirmed that the commented-out code has been removed. Also, good catch on the info file as that shouldn't be in there. This still needs manual testing.

ameymudras’s picture

Status: Needs review » Needs work

Did a review and tested on Drupal 7 and 7.x-1.x of addtocal. The patch applies cleanly and works as expected but I noticed some issues with the code which could be a good addition:

1. can we directly use $view_mode = $display['settings']['view_mode'] ? $display['settings']['view_mode'] : 'full'; instead of

-      $view_mode = $display['settings']['view_mode'];
+      $view_mode = ($display['settings']['view_mode']) != NULL ? $display['settings']['view_mode'] : 'full';

2. Inline comments must end with a full stop

+        // Set pointer to top of array
+        reset($date_element);

3. the following comment exceeds 80 chars

        // If $info array doesn't have date data, this is a non-repeating event and we need to get data elsewhere.

Apart from this there are various other issues with phpcs which can be fixed

dylan donkersgoed’s picture

StatusFileSize
new13.91 KB
new628 bytes

Here's another patch that includes RRULE in the ics file when it's available.

I also noticed when testing this patch that there was a change to the behaviour of the addtocal_field_formatter_view() function that broke some functionality my site had that relied on it. I'm not sure it's actually incorrect though or if it's reasonable to treat this as a public API, so I've fixed it in my code rather than in the patch. Basically, in this check:

if (strtotime($start_date) >= time() ||
          ($display['settings']['past_events'] == TRUE && strtotime($start_date) < time())) {

due to changes in how the start date is loaded in earlier logic the start_date is now the very first date instead of the last date. This results in the addtocal link not being rendered in the element for nodes that have a first date before the current date, even if they have an upcoming recurring instance of the date. In my case this was being invoked by a custom block, but I suspect it might happen for the normal field formatter as well. I solved it by updating my field configuration to show the link on past events as well. But I wanted to flag it since it might cause issues for other sites.

dylan donkersgoed’s picture

StatusFileSize
new13.99 KB
new556 bytes

Please disregard that last patch, I accidentally removed the URL: line from the ICS file. This one does not have that error. Interdiff is against patch 20 again.