I'm completely stuck and no where there seems to be a guide. I want to add multiple Google Calendar events at once thru Batch Request. But I don't know where to start. I've tried the code from Google Calendar API batch request PHP from this site, but I don't understand it.
I have a form where I can select a month, year and for every day of the month a work appointment.
The appointment is looked up in the database and returns start and end time. It's constructed in the Google DateTime.
if (isset($_POST['submit']))
{
$year = $_POST['year'];
$month =$_POST['month'];
$day1 = $_POST['1'];
$day2 = $_POST['2'];
$day3 = $_POST['3'];
if($day1 !="")
{
//... database lookup....
addEvent($title,$desc,$locat,$from,$until,$calendar);
}
if($day2 !="")
{
//... database lookup....
addEvent($title,$desc,$locat,$from,$until,$calendar);
}
if($day3 !="")
{
//... database lookup....
addEvent($title,$desc,$locat,$from,$until,$calendar);
}
//... until day 31 ...
}
The event creation happens by function addEvent
function addEvent($title,$desc,$locat,$from,$until,$calendar)
{
$event = new Google_Event();
$event->setSummary($title);
$event->setDescription($desc);
$event->setLocation($locat);
$start = new Google_EventDateTime();
$start->setDateTime($from);
$event->setStart($start);
$end = new Google_EventDateTime();
$end->setDateTime($until);
$event->setEnd($end);
$createdEvent = $service->events->insert( $calendar, $event);
}
To insert 1 event at a time is not a problem. But more than a few gives a white screen. How can I do a batch request to create up to 31 events? Any help is welcome.