/home/desid573/cf.desidrivers.com.au/google/api
Edit: /home/desid573/cf.desidrivers.com.au/google/api/calendarGetNew.php (7360B)
setAssertionCredentials($cred);
// if($client->getAuth()->isAccessTokenExpired()) {
// $client->getAuth()->refreshTokenWithAssertion($cred);
// }
$client = new Google_Client();
// set the scope(s) that will be used
$client->setApplicationName('Chapel Farm Calendar');
$client->setScopes(Google_Service_Calendar::CALENDAR);
$client->setAccessType('offline');
// set the authorization configuration using the 2.0 style
$client->setAuthConfig(array(
$key
));
return $client;
}
/**
* Expands the home directory alias '~' to the full path.
* @param string $path the path to expand.
* @return string the expanded path.
*/
function expandHomeDirectory($path)
{
$homeDirectory = getenv('HOME');
if (empty($homeDirectory)) {
$homeDirectory = getenv('HOMEDRIVE') . getenv('HOMEPATH');
}
return str_replace('~', realpath($homeDirectory), $path);
}
// Get the API client and construct the service object.
$client = getClient();
$service = new Google_Service_Calendar($client);
date_default_timezone_set("Australia/Perth");
$calendarId = "54ihu71fo4adsvh6avt8s2lrnk@group.calendar.google.com";
$optParams = array('timeMin' => date("c", strtotime("now")), 'singleEvents' => true, 'orderBy' => "startTime");
error_log($calendarId." ".$ref);
$events = $service->events->listEvents($calendarId, $optParams);
//print_r($events);
$dateStart = null;
$dateEnd = null;
$nextDay = null;
$dateArray = array();
$length = count($events);
//print_r($events->getItems());
foreach ($events->getItems() as $event) {
$date = new DateTime($event->getStart()->getDate());
$length = $length - 1;
error_log($length);
if($dateStart == null) {
$dateStart = $date;
$nextDay = $date->format("Y-m-d");
error_log("start date ".$nextDay);
// echo "found start date
";
} else {
//error_log($date->format("Y-m-d")."!=".$nextDay);
error_log(strtotime($date->format("Y-m-d")) .">". strtotime($nextDay));
if($date->format("Y-m-d") != $nextDay) {
$lastDay = $nextDay;
$nextDay = date("Y-m-d", strtotime($nextDay.' 00:01 +1 day'));
error_log($date->format("Y-m-d")." > ".$nextDay);
if(strtotime($date->format("Y-m-d")) > strtotime($nextDay)) {
$dateEnd = $date;
error_log("found not next day");
// if($dateStart->format("Y-m-d") != $lastDay) {
array_push($dateArray, ["start" => $dateStart->format("Y-m-d"), "end" => $lastDay, "type" => "CF"]);
// } else {
// array_push($dateArray, ["start" => $dateStart->format("Y-m-d"), "end" => ""]);
// }
$dateStart = $date;
$nextDay = $date->format("Y-m-d");
} else {
error_log("found next day");
}
} else {
error_log("found same date");
}
if($length == 0) {
// if($dateStart->format("Y-m-d") != $date->format("Y-m-d")) {
array_push($dateArray, ["start" => $dateStart->format("Y-m-d"), "end" => $date->format("Y-m-d"), "type" => "CF"]);
// } else {
// array_push($dateArray, ["start" => $dateStart->format("Y-m-d"), "end" => ""]);
// }
// echo "found end";
}
}
}
$calendarId = "s1rio4cc0b8ru7nckidvv9or1c@group.calendar.google.com";
$optParams = array('timeMin' => date("c", strtotime("now")), 'singleEvents' => true, 'orderBy' => "startTime");
error_log($calendarId." ".$ref);
$events = $service->events->listEvents($calendarId, $optParams);
//print_r($events);
$dateStart = null;
$dateEnd = null;
$nextDay = null;
$length = count($events);
foreach ($events->getItems() as $event) {
$date = new DateTime($event->getStart()->getDate());
$length = $length - 1;
error_log($length);
if($dateStart == null) {
$dateStart = $date;
$nextDay = $date->format("Y-m-d");
error_log("start date ".$nextDay);
// echo "found start date
";
} else {
//error_log($date->format("Y-m-d")."!=".$nextDay);
error_log(strtotime($date->format("Y-m-d")) .">". strtotime($nextDay));
if($date->format("Y-m-d") != $nextDay) {
$lastDay = $nextDay;
$nextDay = date("Y-m-d", strtotime($nextDay.' 00:01 +1 day'));
error_log($date->format("Y-m-d")." > ".$nextDay);
if(strtotime($date->format("Y-m-d")) > strtotime($nextDay)) {
$dateEnd = $date;
error_log("found not next day");
// if($dateStart->format("Y-m-d") != $lastDay) {
array_push($dateArray, ["start" => $dateStart->format("Y-m-d"), "end" => $lastDay, "type" => "JB"]);
// } else {
// array_push($dateArray, ["start" => $dateStart->format("Y-m-d"), "end" => ""]);
// }
$dateStart = $date;
$nextDay = $date->format("Y-m-d");
} else {
error_log("found next day");
}
} else {
error_log("found same date");
}
if($length == 0) {
// if($dateStart->format("Y-m-d") != $date->format("Y-m-d")) {
array_push($dateArray, ["start" => $dateStart->format("Y-m-d"), "end" => $date->format("Y-m-d"), "type" => "JB"]);
// } else {
// array_push($dateArray, ["start" => $dateStart->format("Y-m-d"), "end" => ""]);
// }
// echo "found end";
}
}
}
echo json_encode($dateArray, true);
//echo $events->items->id;
?>