Location: PHPKode > scripts > Google Calendar > google-calendar/class.google.calendar.inc.php
<?php
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_AuthSub');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Calendar');
Zend_Loader::loadClass('Zend_Gdata_Extension_When');
Zend_Loader::loadClass('Zend_Gdata_Extension_Who');
Zend_Loader::loadClass('Zend_Gdata_Extension_Reminder');

/*
	EXAMPLE:
	$event = new GoogleCalendar;
	$event->title = "Simple Test";
	$event->content = "Full description";
	$event->where = "Address";
	$event->start = array(Date => "2009-10-06", Time => "10:00");
	$event->end = array(Date => "2009-10-06", Time => "12:00");
	$event->who = array("hide@address.com", "hide@address.com");
	
	$event->sendNotification = true;
	$event->sendReminder = true;
	
	$event->create();
	
	print $event."\n";
*/
class GoogleCalendar {

	private $_user = 'hide@address.com';
	private $_pass = 'password';
	private $_client;
	private $_newEvent;
	private $_event;
	private $data;

	function __construct() {
		$service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME; // predefined service name for calendar
		$this->_client = Zend_Gdata_ClientLogin::getHttpClient($this->_user, $this->_pass, $service);
		
		// default value
		$this->start = date("Y-m-d h:i");
		$this->end = date("Y-m-d h:i");
		$this->reminder = array("minutes" => 60, "method" => "email");
		$this->tzOffset = "-03";
	}
	
	function __set ($key, $value) {
		$this->data[$key] = $value;
	}

	function __get ($key) {
		return $this->data[$key];
	}

	function __toString () {
		return $this->_event->id->text;
	}

	function create () {

		$gdataCal = new Zend_Gdata_Calendar($this->_client);
		$this->_newEvent = $gdataCal->newEventEntry();

		$this->_newEvent->title = $gdataCal->newTitle($this->title);
		$this->_newEvent->where = array($gdataCal->newWhere($this->where));
		$this->_newEvent->content = $gdataCal->newContent($this->content);

		$when = $gdataCal->newWhen();
		$when->startTime = $this->start["Date"]."T".$this->start["Time"].":00.000".$this->tzOffset.":00";
		$when->endTime   = $this->end["Date"]."T".$this->end["Time"].":00.000".$this->tzOffset.":00";
		
		if ($this->sendReminder) {
			$reminder = $gdataCal->newReminder();
			$reminder->setMinutes($this->reminder[minutes]);
			$reminder->setMethod($this->reminder[method]);
			$when->setReminders(array($reminder));
		}
		$this->_newEvent->when  = array($when);

		if (is_array($this->who)) {
			while (list(,$mail) = each($this->data["who"])) {
				$who = $gdataCal->newWho(); 
				$who->setEmail($mail); 
				$status = new Zend_Gdata_Extension_AttendeeStatus();
				$status->setValue("http://schemas.google.com/g/2005#event.accepted");
				$who->setAttendeeStatus($status);
				$whoArray[] = $who;
			}
			if (is_array($whoArray)) { $this->_newEvent->setWho($whoArray); }
		}
		
		if ($this->sendNotification) {
			$sendEventNotifications = new Zend_Gdata_Calendar_Extension_SendEventNotifications();
			$sendEventNotifications->setValue( true );
			$this->_newEvent->setSendEventNotifications( $sendEventNotifications );
		}

		$this->_event = $gdataCal->insertEvent($this->_newEvent);
		return $this->_event;
	}
}

?>
Return current item: Google Calendar