nextcloud/apps/calendar/ajax/events.php

84 lines
2.9 KiB
PHP
Raw Normal View History

<?php
/**
* Copyright (c) 2011 Georg Ehrke <ownclouddev at georgswebsite dot de>
* This file is licensed under the Affero General Public License version 3 or
* later.
* See the COPYING-README file.
*/
2011-11-13 01:02:04 +04:00
require_once ('../../../lib/base.php');
require_once('../../../3rdparty/when/When.php');
function addoutput($event, $vevent, $return_event){
$return_event['id'] = (int)$event['id'];
$return_event['title'] = $event['summary'];
$return_event['description'] = isset($vevent->DESCRIPTION)?$vevent->DESCRIPTION->value:'';
$last_modified = $vevent->__get('LAST-MODIFIED');
if ($last_modified){
$lastmodified = $last_modified->getDateTime()->format('U');
}else{
$lastmodified = 0;
}
$return_event['lastmodified'] = (int)$lastmodified;
return $return_event;
}
2011-11-13 01:02:04 +04:00
OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('calendar');
$start = DateTime::createFromFormat('U', $_GET['start']);
$end = DateTime::createFromFormat('U', $_GET['end']);
$events = OC_Calendar_Object::allInPeriod($_GET['calendar_id'], $start, $end);
$user_timezone = OC_Preferences::getValue(OC_USER::getUser(), "calendar", "timezone", "Europe/London");
$return = array();
2011-11-13 01:02:04 +04:00
foreach($events as $event){
2011-11-10 01:16:24 +04:00
$object = OC_Calendar_Object::parse($event['calendardata']);
$vevent = $object->VEVENT;
$dtstart = $vevent->DTSTART;
$dtend = OC_Calendar_Object::getDTEndFromVEvent($vevent);
2011-11-13 01:02:04 +04:00
$return_event = array();
$start_dt = $dtstart->getDateTime();
2011-11-13 01:30:09 +04:00
$start_dt->setTimezone(new DateTimeZone($user_timezone));
$end_dt = $dtend->getDateTime();
2011-11-13 01:30:09 +04:00
$end_dt->setTimezone(new DateTimeZone($user_timezone));
2011-11-13 01:02:04 +04:00
if ($dtstart->getDateType() == Sabre_VObject_Element_DateTime::DATE){
$return_event['allDay'] = true;
2011-10-22 00:47:31 +04:00
}else{
$return_event['allDay'] = false;
}
2011-11-13 01:02:04 +04:00
//Repeating Events
if($event['repeating'] == 1){
$duration = (double) $end_dt->format('U') - (double) $start_dt->format('U');
$r = new When();
2011-11-13 01:30:09 +04:00
$r->recur((string) $start_dt->format('Ymd\THis'))->rrule((string) $vevent->RRULE);
2011-11-13 01:02:04 +04:00
while($result = $r->next()){
if($result->format('U') > $_GET['end']){
break;
}
if($return_event['allDay'] == true){
$return_event['start'] = $result->format('Y-m-d');
$return_event['end'] = date('Y-m-d', $result->format('U') + $duration--);
}else{
$return_event['start'] = $result->format('Y-m-d H:i:s');
$return_event['end'] = date('Y-m-d H:i:s', $result->format('U') + $duration);
}
$return[] = addoutput($event, $vevent, $return_event);
}
}else{
2011-11-13 01:02:04 +04:00
$return_event = array();
if ($dtstart->getDateType() == Sabre_VObject_Element_DateTime::DATE){
$return_event['allDay'] = true;
$return_event['start'] = $start_dt->format('Y-m-d');
$end_dt->modify('-1 sec');
$return_event['end'] = $end_dt->format('Y-m-d');
}else{
$return_event['start'] = $start_dt->format('Y-m-d H:i:s');
$return_event['end'] = $end_dt->format('Y-m-d H:i:s');
$return_event['allDay'] = false;
}
$return[] = addoutput($event, $vevent, $return_event);
}
}
OC_JSON::encodedPrint($return);
2011-11-13 01:02:04 +04:00
?>