vendredi 31 mai 2019

ics file : event not added to organizer's calendar

I am using a library that helps me to generate an ics file on laravel. I had to modify it a little bit so it works on outlook (problem with the dates & the time zones). Here's the code for the generation :

class Ics implements Generator
{
public function generate(Link $link): string
{
    $url = [
        'BEGIN:VCALENDAR',
        'PRODID:-//Google Inc//Google Calendar 70.9054//EN',
        'VERSION:2.0',
        'CALSCALE:GREGORIAN',
        'METHOD:REQUEST',
        'X-WR-TIMEZONE:Europe/Paris',
        'BEGIN:VEVENT',
    ];


    $dateTimeFormat = "Ymd\THis\Z";
    $url[] = 'DTSTART:'.gmdate($dateTimeFormat,strtotime($link->from->format('Y-m-d H:i')));
    $url[] = 'DTEND:'.gmdate($dateTimeFormat,strtotime($link->to->format('Y-m-d H:i')));
    $url[] = 'DTSTAMP:'.date('Ymd\THis');

    if ($link->organizer) {
        $url[] = 'ORGANIZER;CN=' . $this->escapeString($link->organizer) . ':mailto:' . $this->escapeString($link->organizer);
        $url[] = 'ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=ACCEPTED;RSVP=TRUE;CN=' . $this->escapeString($link->organizer) . ';X-NUM-GUESTS=0:mailto:' . $this->escapeString($link->organizer);
    }
    $url[] = 'UID:'.$this->generateEventUid($link);
    if ($link->attendee) {

        foreach ($link->attendee as $attendee) {
            $url[] = 'ATTENDEE;CUTYPE=INDIVIDUAL;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN=' . $this->escapeString($attendee) . ';X-NUM-GUESTS=0:mailto:' . $this->escapeString($attendee);
        }
    }
    if ($link->description) {
        $url[] = 'DESCRIPTION:'.$this->escapeString($link->description);
    }
    if ($link->address) {
        $url[] = 'LOCATION:'.$this->escapeString($link->address);
    }
    $url[] = 'SEQUENCE:0';
    $url[] = 'STATUS:CONFIRMED';
    $url[] = 'SUMMARY:'.$link->title;
    $url[] = 'TRANSP:OPAQUE';
    $url[] = 'END:VEVENT';
    $url[] = 'END:VCALENDAR';
    $redirectLink = implode('%0d%0a', $url);

    return 'data:text/calendar;charset=utf8,'.$redirectLink;
}

}

When I create my event, a mail is sent to all attendees (except the organizer) with the ics file atteched. With Gmail and Outlook, it makes the little confirmation box appear, and when I confirm with outlook, it even sends a confirmation mail to the organizer (not with Gmail, but I'm working on it).

The problem is that the event is added to the attendees' calendars, but not the organizer's. I found a post from '14 on SO saying that I should change METHOD from REQUEST to PUBLISH, but it makes outlook not recognize the ics file.

Does anyone have an idea? Thanks a lot.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire