122 lines
3.0 KiB
PHP
122 lines
3.0 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
require_once APPPATH . '/libraries/SPARQ_Model.php';
|
|
class GC_Event_Model extends SPARQ_Model {
|
|
|
|
public function __construct()
|
|
{
|
|
|
|
parent::__construct();
|
|
$this->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->Googleapi->calendar->events->listEvents('primary', $optParams);
|
|
print_r($results);die();
|
|
|
|
$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)
|
|
);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
} |