authorize(); $this->oauth2Connector = $oauth2Connector; $client = new Google_Client(); $client->setClientId($this->oauth2Connector->getClientId()); $client->setClientSecret($this->oauth2Connector->getClientSecret()); $client->setAccessToken($this->oauth2Connector->getAccessToken()); $client->setRedirectUri($this->oauth2Connector->getRedirectUri()); $client->addScope($this->oauth2Connector->getScope()); $client->setAccessType($this->oauth2Connector->getAccessType()); $this->client = $client; } public function isLogged() { return $this->is_logged; } public function setRequest(Vtiger_Request $request) { $this->request = $request; } public function getClient() { return $this->client; } public function getCalendarList() { $service = $this->getCalendarService(); $calendarList = $service->calendarList->listCalendarList(); $userCalendars = array(); while (true) { /** * @var $calendarListEntry Google_Service_Calendar_CalendarListEntry */ foreach ($calendarList->getItems() as $calendarListEntry) { array_push($userCalendars, $calendarListEntry); } $pageToken = $calendarList->getNextPageToken(); if ($pageToken) { $optParams = array('pageToken' => $pageToken); $calendarList = $service->calendarList->listCalendarList($optParams); } else { break; } } return $userCalendars; } public function getCalendarService() { if (!isset($this->calendarService)) { $this->calendarService = new Google_Service_Calendar($this->client); } return $this->calendarService; } public function getCalendarById($calendarId) { $myCalendarInstance = null; if (!empty($calendarId)) { $service = $this->getCalendarService(); $calendarInstance = $service->calendarList->get($calendarId); $myCalendarInstance = ITS4YouGoogleCalendarSync_GoogleCalendar_Model::getInstanceFromGoogleCalendarInstace($calendarInstance); } return $myCalendarInstance; } }