aboutsummaryrefslogtreecommitdiffstats
path: root/apps/calendar/templates/part.getcal.php
blob: aaa43c4950709185040d42eb464ef91400e23631 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
/*************************************************
 * 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                             *
 *************************************************/
$calendars = OC_Calendar_Calendar::allCalendars(OC_User::getUser(), 1);
$events = array();
foreach($calendars as $calendar) {
	$tmp = OC_Calendar_Object::all($calendar['id']);
	$events = array_merge($events, $tmp);
}
$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));
	$year  = $start_dt->format('Y');
	$month = $start_dt->format('n') - 1; // return is 0 based
	$day   = $start_dt->format('j');
	$hour  = $start_dt->format('G');

	// 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];
	}
	$return_event['startdate'] = explode('|', $start_dt->format('Y|m|d|H|i'));
	$return_event['enddate'] = explode('|', $end_dt->format('Y|m|d|H|i'));
	$return_event['description'] = $event['summary'];
	if ($hour == 'allday')
	{
		$return_event['allday'] = true;
	}
	if (isset($return_events[$year][$month][$day][$hour]))
	{
		$return_events[$year][$month][$day][$hour][] = $return_event;
	}
	else
	{
		$return_events[$year][$month][$day][$hour] = array(1 => $return_event);
	}
}
echo json_encode($return_events);
?>