2011-08-31 19:29:38 +04:00
|
|
|
<?php
|
2011-09-11 18:45:58 +04:00
|
|
|
/*************************************************
|
|
|
|
* ownCloud - Calendar Plugin *
|
|
|
|
* *
|
|
|
|
* (c) Copyright 2011 Bart Visscher *
|
|
|
|
* License: GNU AFFERO GENERAL PUBLIC LICENSE *
|
|
|
|
* *
|
|
|
|
* If you are not able to view the License, *
|
|
|
|
* <http://www.gnu.org/licenses/> *
|
|
|
|
* please write to the Free Software Foundation. *
|
|
|
|
* Address: *
|
|
|
|
* 59 Temple Place, Suite 330, Boston, *
|
|
|
|
* MA 02111-1307 USA *
|
|
|
|
*************************************************/
|
2011-08-31 19:29:38 +04:00
|
|
|
$calendars = OC_Calendar_Calendar::allCalendars(OC_User::getUser(), 1);
|
2011-09-15 12:14:47 +04:00
|
|
|
$events = OC_Calendar_Object::all($calendars[0]['id']);
|
2011-08-31 19:29:38 +04:00
|
|
|
$select_year = $_GET["year"];
|
|
|
|
$return_events = array();
|
|
|
|
$user_timezone = OC_Preferences::getValue(OC_USER::getUser(), "calendar", "timezone", "Europe/London");
|
|
|
|
foreach($events as $event)
|
|
|
|
{
|
|
|
|
if ($select_year != substr($event['startdate'], 0, 4))
|
|
|
|
continue;
|
|
|
|
$start_dt = new DateTime($event['startdate'], new DateTimeZone('UTC'));
|
|
|
|
$start_dt->setTimezone(new DateTimeZone($user_timezone));
|
|
|
|
$end_dt = new DateTime($event['enddate'], new DateTimeZone('UTC'));
|
|
|
|
$end_dt->setTimezone(new DateTimeZone($user_timezone));
|
2011-08-31 22:20:46 +04:00
|
|
|
$year = $start_dt->format('Y');
|
2011-08-31 19:29:38 +04:00
|
|
|
$month = $start_dt->format('n') - 1; // return is 0 based
|
2011-08-31 22:20:46 +04:00
|
|
|
$day = $start_dt->format('j');
|
|
|
|
$hour = $start_dt->format('G');
|
2011-08-31 19:29:38 +04:00
|
|
|
|
|
|
|
// hack
|
|
|
|
if (strstr($event['calendardata'], 'DTSTART;VALUE=DATE:')) {
|
|
|
|
$hour = 'allday';
|
|
|
|
}
|
|
|
|
$return_event = array();
|
|
|
|
foreach(array('id', 'calendarid', 'objecttype', 'repeating') as $prop)
|
|
|
|
{
|
|
|
|
$return_event[$prop] = $event[$prop];
|
|
|
|
}
|
2011-09-03 16:05:20 +04:00
|
|
|
$return_event['startdate'] = explode('|', $start_dt->format('Y|m|d|H|i'));
|
|
|
|
$return_event['enddate'] = explode('|', $end_dt->format('Y|m|d|H|i'));
|
2011-08-31 19:29:38 +04:00
|
|
|
$return_event['description'] = $event['summary'];
|
2011-09-03 16:05:20 +04:00
|
|
|
if ($hour == 'allday')
|
|
|
|
{
|
|
|
|
$return_event['allday'] = true;
|
|
|
|
}
|
2011-08-31 22:20:46 +04:00
|
|
|
if (isset($return_events[$year][$month][$day][$hour]))
|
|
|
|
{
|
2011-08-31 19:29:38 +04:00
|
|
|
$return_events[$year][$month][$day][$hour][] = $return_event;
|
2011-08-31 22:20:46 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-08-31 19:29:38 +04:00
|
|
|
$return_events[$year][$month][$day][$hour] = array(1 => $return_event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
echo json_encode($return_events);
|
2011-08-31 22:20:46 +04:00
|
|
|
?>
|