load->library('session'); $this->load->library('googleplus'); $this->calendar = new Google_Service_Calendar($this->googleplus->client()); } public function getEvents($calendarId = 'primary', $timeMin = false, $timeMax = false, $maxResults = 10) { if ( ! $timeMin) { $timeMin = date("c", strtotime(date('Y-m-d ').' 00:00:00')); } else { $timeMin = date("c", strtotime($timeMin)); } if ( ! $timeMax) { $timeMax = date("c", strtotime(date('Y-m-d ').' 23:59:59')); } else { $timeMax = date("c", strtotime($timeMax)); } $optParams = array( 'maxResults' => $maxResults, 'orderBy' => 'startTime', 'singleEvents' => true, 'timeMin' => $timeMin, 'timeMax' => $timeMax, 'timeZone' => 'Asia/Kolkata', ); $results = $this->googlecalendar->calendar->events->listEvents($calendarId, $optParams); $data = array(); foreach ($results->getItems() as $item) { $start = date('d-m-Y H:i', strtotime($item->getStart()->dateTime)); array_push( $data, array( 'id' => $item->getId(), 'summary' => $item->getSummary(), 'description' => $item->getDescription(), 'creator' => $item->getCreator(), 'start' => $item->getStart()->dateTime, 'end' => $item->getEnd()->dateTime, ) ); } return $data; } public function addEvent($calendarId = 'primary', $data) { //date format is => 2016-06-18T17:00:00+03:00 $event = new Google_Service_Calendar_Event( array( 'summary' => $data['summary'], 'description' => $data['description'], 'start' => array( 'dateTime' => $data['date'].'T'.$data['start'].':00+05:30', 'timeZone' => 'Asia/Kolkata', ), 'end' => array( 'dateTime' => $data['date'].'T'.$data['end'].':00+05:30', 'timeZone' => 'Asia/Kolkata', ), 'attendees' => array( array('email' => 'venbalap08@gmail.com'), ), ) ); $this->db->insert('t_se_team_vc_events',$data); return array( 'id' => $this->db->insert_id(), 'event_id' => $this->calendar->events->insert($calendarId, $event) ); } }