function cloud_scrivi_calendar($evento_descr, $evento_start, $evento_durata = '+2 hours', $evento_location = '', $event_id = null) { $evento_descr = $evento_descr; $evento_start1 = strtotime($evento_start); $evento_end1 = strtotime($evento_start . $evento_durata); $evento_location = $evento_location; /*************** DA QUI IN GIU NON TOCCHEREI PIU NULLA... ******************/ $app_name = 'allarrembaggio'; $client_id = '1034795448812-gghclbbghnvnmotg6as7524fraeojfnh.apps.googleusercontent.com'; $email_address = '*****@*****.**'; $key_file = plugin_dir_path(__FILE__) . 'google-api-php-client/allarrembaggio-85318f0a4e9d.p12'; $calendar_id = '*****@*****.**'; $evento_start = gmdate('Y-m-d\\TH:i:s', $evento_start1); $evento_end = gmdate('Y-m-d\\TH:i:s', $evento_end1); require_once "google-api-php-client/src/Google_Client.php"; require_once "google-api-php-client/src/contrib/Google_CalendarService.php"; $client = new Google_Client(); $client->setUseObjects(true); $client->setApplicationName($app_name); $client->setClientId($client_id); $client->setAssertionCredentials(new Google_AssertionCredentials($email_address, array("https://www.googleapis.com/auth/calendar"), file_get_contents($key_file))); //setAssertionCredentials $service = new Google_CalendarService($client); $event = new Google_Event(); $event->setSummary($evento_descr); $event->setLocation($evento_location); $start = new Google_EventDateTime(); $start->setDateTime($evento_start); $start->setTimeZone('Europe/Rome'); $event->setStart($start); $end = new Google_EventDateTime(); $end->setDateTime($evento_end); $end->setTimeZone('Europe/Rome'); $event->setEnd($end); //--prima di crearlo, elimino eventuali eventi if ($event_id != null) { $service->events->delete($calendar_id, $event_id); } //--creo l'evento $new_event = null; try { $new_event = $service->events->insert($calendar_id, $event); $new_event_id = $new_event->getId(); } catch (Google_ServiceException $e) { syslog(LOG_ERR, $e->getMessage()); } $output = null; $output = $service->events->get($calendar_id, $new_event->getId()); $output = $output->getId(); return $output; }
/** * up to date event recently created */ function updateDateEvent($_service, $_event, $_tampon) { try { //actual date $datetime = new DateTime('now'); //end event date $end = new Google_EventDateTime(); $end->setDateTime($datetime->format("Y-m-d\TH:i:s")); $end->setTimeZone('Europe/Paris'); $_event->setEnd($end); //event description (cronjob output) $_event->setDescription($_tampon); //update event $_service->events->update(SolrSafeOperatorHelper::clusterIni('ConfigCalendar', 'CalendarId', 'calendar.ini'), $_event->getId(), $_event); $cli = eZCLI::instance(); $cli->output('Event id : ' . $_event->getId() . ' updated'); } catch(Exception $e) { $cli = eZCLI::instance(); $cli->output($e->getMessage()); } }
function newDateTime($date, $time) { date_default_timezone_set('America/Los_Angeles'); $datetime = new Google_EventDateTime(); $date = date('c', strtotime("{$date} {$time}")); $datetime->setDateTime($date); $datetime->setTimeZone('America/Los_Angeles'); return $datetime; }