0
votes

I started my project 1 year ago and never had to post in forums, 1 week ago i started developing with google calendar api and this is my 3rd post :s

I already create sucessfully single and recurring events, reminders for single events but now i need to know how to create reminders for recurring events with the Zend Gdata api.

This is the code i use to create reminders for single events:

function setReminder($client, $eventId, $minutes=15, $methods)
{
    $gc = new Zend_Gdata_Calendar($client);
    $reminder_types = array();
    if ($event = getEvent($client, $eventId)) {
        $times = $event->when;
        var_dump($event);
        foreach ($times as $when) 
        {
            if(in_array('alert',$methods))
            {
                var_dump('alert');
                $reminder_alert = $gc->newReminder();
                $reminder_alert->setMinutes($minutes);
                $reminder_alert->setMethod("alert");
                array_push($reminder_types,$reminder_alert);
            }
            if(in_array('email',$methods))
            {
                var_dump('email');
                $reminder_email = $gc->newReminder();
                $reminder_email->setMinutes($minutes);
                $reminder_email->setMethod("email");
                array_push($reminder_types,$reminder_email);
            }

            $when->reminders = $reminder_types;
        }
        $eventNew = $event->save();
        //var_dump($eventNew);
        return $eventNew;
    } else {
        return null;
    }
}

The problem is, for recurring events $event->when is empty.

Thanks in advance!

1

1 Answers

0
votes

Ok after a lot of search and trial and error i found the solution to create recurring events with reminders.

Austin from Google wrote:

At the moment, the Zend GData client library does not provide the ability to directly add reminder when it is dealing with recurring event. This exceptional case is caused by the fact that there is no gd:when element within a recurring event entry, and typically a gd:reminder would exist inside a gd:when element. The Zend client library handle the general case and thus does not provide a way to add reminder when there is no gd:when specified.

But there is an hack :) here it is how i did it:

function createRecurringEvent ($client, $calendar, $title, $desc, $where, $startDate, $startTime, $endDate, $endTime, $repeat, $endRepeatDate, $endRepeatTime, $tzOffset, $minutes=15, $methods)
{
    $frequence = "";
    $recurData = null;
    $gc = new Zend_Gdata_Calendar($client);
    $newEntry = $gc->newEventEntry();
    $newEntry->title = $gc->newTitle(trim($title));
    $newEntry->where = array($gc->newWhere($where));

    $newEntry->content = $gc->newContent($desc);
    $newEntry->content->type = 'text';


    switch ($repeat) {
        case "d":
            $frequence = "DAILY";
            break;
        case "w":
            $frequence = "WEEKLY";
            break;
        case "m":
            $frequence = "MONTHLY";
            break;
        case "y":
            $frequence = "YEARLY";
            break;
    }

    $startDateTime = getIcalDate($startDate . " " . $startTime);
    $endDateTime = getIcalDate($endDate . " " . $endTime);
    $endRepeatDateTime = getIcalDate($endRepeatDate . " " . $endRepeatTime);

    if ($recurData == null) 
    {
        $recurData =
            "DTSTART:{$startDateTime}\r\n" .
            "DTEND:{$endDateTime}\r\n" .
            "RRULE:FREQ={$frequence};UNTIL={$endRepeatDateTime}\r\n";

    }

    $newEntry->recurrence = $gc->newRecurrence($recurData);

    $event_xml = simplexml_load_string($newEntry->saveXML());

    if(in_array('alert',$methods))
        $event_xml->addChild('gd:reminder  xmlns:gd="http://schemas.google.com/g/2005" minutes="15" method="alert"');
    if(in_array('email',$methods))
        $event_xml->addChild('gd:reminder  xmlns:gd="http://schemas.google.com/g/2005" minutes="15" method="email"');
    $xml = str_replace("atom:reminder","gd:reminder",$event_xml->asXML());

    $gc->post($xml, $calendar);
}

The 100 parameters will be replaced by an object this is only for test. I hope this helps someone else since this api is a nightmare. I'm thinking in creating a tutorial about this in the future.