2011-12-19 01:58:20 +04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Copyright (c) 2011 Bart Visscher <bartv@thisnet.nl>
|
2012-04-01 00:13:04 +04:00
|
|
|
* Copyright (c) 2012 Georg Ehrke <georg@owncloud.com>
|
2011-12-19 01:58:20 +04:00
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
2012-04-01 00:13:04 +04:00
|
|
|
*
|
2011-12-19 01:58:20 +04:00
|
|
|
* This class manages our app actions
|
|
|
|
*/
|
2012-04-08 06:45:44 +04:00
|
|
|
OC_Calendar_App::$l10n = new OC_L10N('calendar');
|
2012-07-21 02:45:13 +04:00
|
|
|
OC_Calendar_App::$tz = OC_Calendar_App::getTimezone();
|
2011-12-19 01:58:20 +04:00
|
|
|
class OC_Calendar_App{
|
2012-04-08 06:35:29 +04:00
|
|
|
const CALENDAR = 'calendar';
|
|
|
|
const EVENT = 'event';
|
2012-06-30 19:08:00 +04:00
|
|
|
/**
|
2012-04-08 06:35:29 +04:00
|
|
|
* @brief language object for calendar app
|
2012-04-01 00:13:04 +04:00
|
|
|
*/
|
2011-12-19 01:58:20 +04:00
|
|
|
public static $l10n;
|
2012-04-15 14:43:07 +04:00
|
|
|
|
2012-06-30 19:08:00 +04:00
|
|
|
/**
|
2012-04-15 14:43:07 +04:00
|
|
|
* @brief categories of the user
|
|
|
|
*/
|
2012-04-13 01:06:45 +04:00
|
|
|
protected static $categories = null;
|
2011-12-19 01:58:20 +04:00
|
|
|
|
2012-06-30 19:08:00 +04:00
|
|
|
/**
|
2012-04-08 06:35:29 +04:00
|
|
|
* @brief timezone of the user
|
|
|
|
*/
|
|
|
|
public static $tz;
|
|
|
|
|
2012-06-30 19:08:00 +04:00
|
|
|
/**
|
2012-04-08 06:35:29 +04:00
|
|
|
* @brief returns informations about a calendar
|
|
|
|
* @param int $id - id of the calendar
|
|
|
|
* @param bool $security - check access rights or not
|
|
|
|
* @param bool $shared - check if the user got access via sharing
|
|
|
|
* @return mixed - bool / array
|
2012-04-01 00:13:04 +04:00
|
|
|
*/
|
|
|
|
public static function getCalendar($id, $security = true, $shared = false){
|
2012-05-10 23:36:30 +04:00
|
|
|
if(! is_numeric($id)){
|
|
|
|
return false;
|
|
|
|
}
|
2012-04-08 06:35:29 +04:00
|
|
|
$calendar = OC_Calendar_Calendar::find($id);
|
2012-04-01 00:13:04 +04:00
|
|
|
if($shared === true){
|
2012-05-01 20:50:31 +04:00
|
|
|
if(OC_Calendar_Share::check_access(OCP\USER::getUser(), $id, OC_Calendar_Share::CALENDAR)){
|
2012-04-01 00:13:04 +04:00
|
|
|
return $calendar;
|
|
|
|
}
|
2011-12-19 01:58:20 +04:00
|
|
|
}
|
2012-04-01 00:13:04 +04:00
|
|
|
if($security === true){
|
2012-05-01 20:50:31 +04:00
|
|
|
if($calendar['userid'] != OCP\USER::getUser()){
|
2012-04-01 00:13:04 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2012-06-15 02:28:12 +04:00
|
|
|
return $calendar;
|
2011-12-19 01:58:20 +04:00
|
|
|
}
|
2012-04-01 00:13:04 +04:00
|
|
|
|
2012-06-30 19:08:00 +04:00
|
|
|
/**
|
2012-04-08 06:35:29 +04:00
|
|
|
* @brief returns informations about an event
|
|
|
|
* @param int $id - id of the event
|
|
|
|
* @param bool $security - check access rights or not
|
|
|
|
* @param bool $shared - check if the user got access via sharing
|
|
|
|
* @return mixed - bool / array
|
2012-04-01 00:13:04 +04:00
|
|
|
*/
|
|
|
|
public static function getEventObject($id, $security = true, $shared = false){
|
|
|
|
$event = OC_Calendar_Object::find($id);
|
|
|
|
if($shared === true){
|
2012-05-01 20:50:31 +04:00
|
|
|
if(OC_Calendar_Share::check_access(OCP\USER::getUser(), $id, OC_Calendar_Share::EVENT)){
|
2012-04-08 06:35:29 +04:00
|
|
|
return $event;
|
2012-04-01 00:13:04 +04:00
|
|
|
}
|
2012-03-26 17:24:43 +04:00
|
|
|
}
|
2012-04-01 00:13:04 +04:00
|
|
|
if($security === true){
|
|
|
|
$calendar = self::getCalendar($event['calendarid'], false);
|
2012-05-01 20:50:31 +04:00
|
|
|
if($calendar['userid'] != OCP\USER::getUser()){
|
2012-04-01 00:13:04 +04:00
|
|
|
return false;
|
2012-03-26 17:24:43 +04:00
|
|
|
}
|
|
|
|
}
|
2012-04-01 00:13:04 +04:00
|
|
|
if($event === false){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return $event;
|
2012-03-26 17:24:43 +04:00
|
|
|
}
|
2012-04-01 00:13:04 +04:00
|
|
|
|
2012-06-30 19:08:00 +04:00
|
|
|
/**
|
2012-04-08 06:35:29 +04:00
|
|
|
* @brief returns the parsed calendar data
|
|
|
|
* @param int $id - id of the event
|
|
|
|
* @param bool $security - check access rights or not
|
|
|
|
* @return mixed - bool / object
|
2012-04-01 00:13:04 +04:00
|
|
|
*/
|
2012-04-10 23:53:39 +04:00
|
|
|
public static function getVCalendar($id, $security = true, $shared = false){
|
|
|
|
$event_object = self::getEventObject($id, $security, $shared);
|
2012-04-01 00:13:04 +04:00
|
|
|
if($event_object === false){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$vobject = OC_VObject::parse($event_object['calendardata']);
|
|
|
|
if(is_null($vobject)){
|
|
|
|
return false;
|
2011-12-19 01:58:20 +04:00
|
|
|
}
|
2012-04-01 00:13:04 +04:00
|
|
|
return $vobject;
|
2011-12-19 01:58:20 +04:00
|
|
|
}
|
2012-04-01 00:13:04 +04:00
|
|
|
|
2012-06-30 19:08:00 +04:00
|
|
|
/**
|
2012-04-08 06:35:29 +04:00
|
|
|
* @brief checks if an event was edited and dies if it was
|
|
|
|
* @param (object) $vevent - vevent object of the event
|
|
|
|
* @param (int) $lastmodified - time of last modification as unix timestamp
|
|
|
|
* @return (bool)
|
2012-04-01 00:13:04 +04:00
|
|
|
*/
|
|
|
|
public static function isNotModified($vevent, $lastmodified){
|
2011-12-19 01:58:20 +04:00
|
|
|
$last_modified = $vevent->__get('LAST-MODIFIED');
|
|
|
|
if($last_modified && $lastmodified != $last_modified->getDateTime()->format('U')){
|
2012-05-03 14:23:29 +04:00
|
|
|
OCP\JSON::error(array('modified'=>true));
|
2011-12-19 01:58:20 +04:00
|
|
|
exit;
|
|
|
|
}
|
2012-04-08 06:35:29 +04:00
|
|
|
return true;
|
2011-12-19 01:58:20 +04:00
|
|
|
}
|
2012-04-15 14:43:07 +04:00
|
|
|
|
2012-06-30 19:08:00 +04:00
|
|
|
/**
|
2012-04-15 14:43:07 +04:00
|
|
|
* @brief returns the default categories of ownCloud
|
|
|
|
* @return (array) $categories
|
|
|
|
*/
|
2012-06-11 19:25:03 +04:00
|
|
|
protected static function getDefaultCategories(){
|
2011-12-19 01:58:20 +04:00
|
|
|
return array(
|
|
|
|
self::$l10n->t('Birthday'),
|
|
|
|
self::$l10n->t('Business'),
|
|
|
|
self::$l10n->t('Call'),
|
|
|
|
self::$l10n->t('Clients'),
|
|
|
|
self::$l10n->t('Deliverer'),
|
|
|
|
self::$l10n->t('Holidays'),
|
|
|
|
self::$l10n->t('Ideas'),
|
|
|
|
self::$l10n->t('Journey'),
|
|
|
|
self::$l10n->t('Jubilee'),
|
|
|
|
self::$l10n->t('Meeting'),
|
|
|
|
self::$l10n->t('Other'),
|
|
|
|
self::$l10n->t('Personal'),
|
|
|
|
self::$l10n->t('Projects'),
|
|
|
|
self::$l10n->t('Questions'),
|
|
|
|
self::$l10n->t('Work'),
|
|
|
|
);
|
|
|
|
}
|
2012-04-15 14:43:07 +04:00
|
|
|
|
2012-06-30 19:08:00 +04:00
|
|
|
/**
|
2012-04-15 14:43:07 +04:00
|
|
|
* @brief returns the vcategories object of the user
|
|
|
|
* @return (object) $vcategories
|
|
|
|
*/
|
2012-04-13 01:06:45 +04:00
|
|
|
protected static function getVCategories() {
|
|
|
|
if (is_null(self::$categories)) {
|
|
|
|
self::$categories = new OC_VCategories('calendar', null, self::getDefaultCategories());
|
|
|
|
}
|
|
|
|
return self::$categories;
|
|
|
|
}
|
2012-04-15 14:43:07 +04:00
|
|
|
|
2012-06-30 19:08:00 +04:00
|
|
|
/**
|
2012-04-15 14:43:07 +04:00
|
|
|
* @brief returns the categories of the vcategories object
|
|
|
|
* @return (array) $categories
|
|
|
|
*/
|
2012-06-11 19:25:03 +04:00
|
|
|
public static function getCategoryOptions(){
|
2012-04-13 01:06:45 +04:00
|
|
|
$categories = self::getVCategories()->categories();
|
|
|
|
return $categories;
|
|
|
|
}
|
|
|
|
|
2012-04-13 18:50:11 +04:00
|
|
|
/**
|
|
|
|
* scan events for categories.
|
|
|
|
* @param $events VEVENTs to scan. null to check all events for the current user.
|
2012-04-01 00:13:04 +04:00
|
|
|
*/
|
2012-04-13 18:50:11 +04:00
|
|
|
public static function scanCategories($events = null) {
|
|
|
|
if (is_null($events)) {
|
2012-05-01 20:50:31 +04:00
|
|
|
$calendars = OC_Calendar_Calendar::allCalendars(OCP\USER::getUser());
|
2012-04-13 18:50:11 +04:00
|
|
|
if(count($calendars) > 0) {
|
|
|
|
$events = array();
|
|
|
|
foreach($calendars as $calendar) {
|
|
|
|
$calendar_events = OC_Calendar_Object::all($calendar['id']);
|
|
|
|
$events = $events + $calendar_events;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(is_array($events) && count($events) > 0) {
|
|
|
|
$vcategories = self::getVCategories();
|
|
|
|
$vcategories->delete($vcategories->categories());
|
|
|
|
foreach($events as $event) {
|
|
|
|
$vobject = OC_VObject::parse($event['calendardata']);
|
|
|
|
if(!is_null($vobject)) {
|
2012-04-14 16:55:37 +04:00
|
|
|
self::loadCategoriesFromVCalendar($vobject);
|
2012-04-13 18:50:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-12-19 01:58:20 +04:00
|
|
|
}
|
2012-04-13 18:50:11 +04:00
|
|
|
|
2012-04-13 20:36:20 +04:00
|
|
|
/**
|
|
|
|
* check VEvent for new categories.
|
|
|
|
* @see OC_VCategories::loadFromVObject
|
2012-04-01 00:13:04 +04:00
|
|
|
*/
|
2012-04-13 20:36:20 +04:00
|
|
|
public static function loadCategoriesFromVCalendar(OC_VObject $calendar) {
|
2012-04-14 16:55:37 +04:00
|
|
|
$object = null;
|
|
|
|
if (isset($calendar->VEVENT)) {
|
|
|
|
$object = $calendar->VEVENT;
|
|
|
|
} else
|
|
|
|
if (isset($calendar->VTODO)) {
|
|
|
|
$object = $calendar->VTODO;
|
2012-06-25 00:15:36 +04:00
|
|
|
} else
|
|
|
|
if (isset($calendar->VJOURNAL)) {
|
|
|
|
$object = $calendar->VJOURNAL;
|
2012-04-14 16:55:37 +04:00
|
|
|
}
|
|
|
|
if ($object) {
|
|
|
|
self::getVCategories()->loadFromVObject($object, true);
|
|
|
|
}
|
2012-04-13 20:36:20 +04:00
|
|
|
}
|
2012-06-30 19:08:00 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief returns the options for the repeat rule of an repeating event
|
|
|
|
* @return array - valid inputs for the repeat rule of an repeating event
|
|
|
|
*/
|
2011-12-26 02:19:49 +04:00
|
|
|
public static function getRepeatOptions(){
|
|
|
|
return OC_Calendar_Object::getRepeatOptions(self::$l10n);
|
|
|
|
}
|
2012-04-01 00:13:04 +04:00
|
|
|
|
2012-06-30 19:08:00 +04:00
|
|
|
/**
|
2012-04-08 06:35:29 +04:00
|
|
|
* @brief returns the options for the end of an repeating event
|
|
|
|
* @return array - valid inputs for the end of an repeating events
|
2012-04-01 00:13:04 +04:00
|
|
|
*/
|
2011-12-26 02:19:49 +04:00
|
|
|
public static function getEndOptions(){
|
|
|
|
return OC_Calendar_Object::getEndOptions(self::$l10n);
|
|
|
|
}
|
2012-04-01 00:13:04 +04:00
|
|
|
|
2012-06-30 19:08:00 +04:00
|
|
|
/**
|
2012-04-08 06:35:29 +04:00
|
|
|
* @brief returns the options for an monthly repeating event
|
|
|
|
* @return array - valid inputs for monthly repeating events
|
2012-04-01 00:13:04 +04:00
|
|
|
*/
|
2011-12-26 02:19:49 +04:00
|
|
|
public static function getMonthOptions(){
|
|
|
|
return OC_Calendar_Object::getMonthOptions(self::$l10n);
|
|
|
|
}
|
2012-04-01 00:13:04 +04:00
|
|
|
|
2012-06-30 19:08:00 +04:00
|
|
|
/**
|
2012-04-08 06:35:29 +04:00
|
|
|
* @brief returns the options for an weekly repeating event
|
|
|
|
* @return array - valid inputs for weekly repeating events
|
2012-04-01 00:13:04 +04:00
|
|
|
*/
|
2011-12-26 02:19:49 +04:00
|
|
|
public static function getWeeklyOptions(){
|
|
|
|
return OC_Calendar_Object::getWeeklyOptions(self::$l10n);
|
|
|
|
}
|
2012-04-01 00:13:04 +04:00
|
|
|
|
2012-06-30 19:08:00 +04:00
|
|
|
/**
|
2012-04-08 06:35:29 +04:00
|
|
|
* @brief returns the options for an yearly repeating event
|
|
|
|
* @return array - valid inputs for yearly repeating events
|
2012-04-01 00:13:04 +04:00
|
|
|
*/
|
2011-12-26 02:19:49 +04:00
|
|
|
public static function getYearOptions(){
|
|
|
|
return OC_Calendar_Object::getYearOptions(self::$l10n);
|
|
|
|
}
|
2012-04-01 00:13:04 +04:00
|
|
|
|
2012-06-30 19:08:00 +04:00
|
|
|
/**
|
2012-04-08 06:35:29 +04:00
|
|
|
* @brief returns the options for an yearly repeating event which occurs on specific days of the year
|
|
|
|
* @return array - valid inputs for yearly repeating events
|
2012-04-01 00:13:04 +04:00
|
|
|
*/
|
2011-12-26 02:19:49 +04:00
|
|
|
public static function getByYearDayOptions(){
|
|
|
|
return OC_Calendar_Object::getByYearDayOptions();
|
|
|
|
}
|
2012-04-01 00:13:04 +04:00
|
|
|
|
2012-06-30 19:08:00 +04:00
|
|
|
/**
|
2012-04-08 06:35:29 +04:00
|
|
|
* @brief returns the options for an yearly repeating event which occurs on specific month of the year
|
|
|
|
* @return array - valid inputs for yearly repeating events
|
2012-04-01 00:13:04 +04:00
|
|
|
*/
|
2011-12-26 02:19:49 +04:00
|
|
|
public static function getByMonthOptions(){
|
|
|
|
return OC_Calendar_Object::getByMonthOptions(self::$l10n);
|
|
|
|
}
|
|
|
|
|
2012-06-30 19:08:00 +04:00
|
|
|
/**
|
2012-04-08 06:35:29 +04:00
|
|
|
* @brief returns the options for an yearly repeating event which occurs on specific week numbers of the year
|
|
|
|
* @return array - valid inputs for yearly repeating events
|
2012-04-01 00:13:04 +04:00
|
|
|
*/
|
2011-12-26 02:19:49 +04:00
|
|
|
public static function getByWeekNoOptions(){
|
|
|
|
return OC_Calendar_Object::getByWeekNoOptions();
|
|
|
|
}
|
2012-04-01 00:13:04 +04:00
|
|
|
|
2012-06-30 19:08:00 +04:00
|
|
|
/**
|
2012-04-08 06:35:29 +04:00
|
|
|
* @brief returns the options for an yearly or monthly repeating event which occurs on specific days of the month
|
|
|
|
* @return array - valid inputs for yearly or monthly repeating events
|
2012-04-01 00:13:04 +04:00
|
|
|
*/
|
2011-12-26 02:19:49 +04:00
|
|
|
public static function getByMonthDayOptions(){
|
|
|
|
return OC_Calendar_Object::getByMonthDayOptions();
|
|
|
|
}
|
|
|
|
|
2012-06-30 19:08:00 +04:00
|
|
|
/**
|
2012-04-08 06:35:29 +04:00
|
|
|
* @brief returns the options for an monthly repeating event which occurs on specific weeks of the month
|
|
|
|
* @return array - valid inputs for monthly repeating events
|
2012-04-01 00:13:04 +04:00
|
|
|
*/
|
2011-12-26 02:19:49 +04:00
|
|
|
public static function getWeekofMonth(){
|
|
|
|
return OC_Calendar_Object::getWeekofMonth(self::$l10n);
|
2011-12-19 01:58:20 +04:00
|
|
|
}
|
2012-07-21 02:45:13 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return (string) $timezone as set by user or the default timezone
|
|
|
|
*/
|
|
|
|
public static function getTimezone() {
|
|
|
|
return OCP\Config::getUserValue(OCP\User::getUser(),
|
|
|
|
'calendar',
|
|
|
|
'timezone',
|
|
|
|
date_default_timezone_get());
|
|
|
|
}
|
|
|
|
|
2012-06-30 19:08:00 +04:00
|
|
|
/**
|
2012-04-08 06:35:29 +04:00
|
|
|
* @brief checks the access for a calendar / an event
|
|
|
|
* @param (int) $id - id of the calendar / event
|
|
|
|
* @param (string) $type - type of the id (calendar/event)
|
|
|
|
* @return (string) $access - level of access
|
|
|
|
*/
|
|
|
|
public static function getaccess($id, $type){
|
|
|
|
if($type == self::CALENDAR){
|
|
|
|
$calendar = self::getCalendar($id, false, false);
|
2012-05-01 20:50:31 +04:00
|
|
|
if($calendar['userid'] == OCP\USER::getUser()){
|
2012-04-08 06:35:29 +04:00
|
|
|
return 'owner';
|
|
|
|
}
|
2012-05-01 20:50:31 +04:00
|
|
|
$isshared = OC_Calendar_Share::check_access(OCP\USER::getUser(), $id, OC_Calendar_Share::CALENDAR);
|
2012-04-08 06:35:29 +04:00
|
|
|
if($isshared){
|
2012-05-01 20:50:31 +04:00
|
|
|
$writeaccess = OC_Calendar_Share::is_editing_allowed(OCP\USER::getUser(), $id, OC_Calendar_Share::CALENDAR);
|
2012-04-08 06:35:29 +04:00
|
|
|
if($writeaccess){
|
|
|
|
return 'rw';
|
|
|
|
}else{
|
|
|
|
return 'r';
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}elseif($type == self::EVENT){
|
2012-05-01 20:50:31 +04:00
|
|
|
if(OC_Calendar_Object::getowner($id) == OCP\USER::getUser()){
|
2012-04-08 06:35:29 +04:00
|
|
|
return 'owner';
|
|
|
|
}
|
2012-05-01 20:50:31 +04:00
|
|
|
$isshared = OC_Calendar_Share::check_access(OCP\USER::getUser(), $id, OC_Calendar_Share::EVENT);
|
2012-04-08 06:35:29 +04:00
|
|
|
if($isshared){
|
2012-05-01 20:50:31 +04:00
|
|
|
$writeaccess = OC_Calendar_Share::is_editing_allowed(OCP\USER::getUser(), $id, OC_Calendar_Share::EVENT);
|
2012-04-08 06:35:29 +04:00
|
|
|
if($writeaccess){
|
|
|
|
return 'rw';
|
|
|
|
}else{
|
|
|
|
return 'r';
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-30 19:08:00 +04:00
|
|
|
/**
|
2012-04-08 06:35:29 +04:00
|
|
|
* @brief analyses the parameter for calendar parameter and returns the objects
|
|
|
|
* @param (string) $calendarid - calendarid
|
|
|
|
* @param (int) $start - unixtimestamp of start
|
|
|
|
* @param (int) $end - unixtimestamp of end
|
|
|
|
* @return (array) $events
|
2012-04-01 00:13:04 +04:00
|
|
|
*/
|
2012-04-08 06:35:29 +04:00
|
|
|
public static function getrequestedEvents($calendarid, $start, $end){
|
|
|
|
$events = array();
|
2012-06-14 00:06:22 +04:00
|
|
|
if($calendarid == 'shared_rw' || $calendarid == 'shared_r'){
|
2012-05-01 20:50:31 +04:00
|
|
|
$calendars = OC_Calendar_Share::allSharedwithuser(OCP\USER::getUser(), OC_Calendar_Share::CALENDAR, 1, ($_GET['calendar_id'] == 'shared_rw')?'rw':'r');
|
2012-04-08 06:35:29 +04:00
|
|
|
foreach($calendars as $calendar){
|
|
|
|
$calendarevents = OC_Calendar_Object::allInPeriod($calendar['calendarid'], $start, $end);
|
2012-06-14 00:06:22 +04:00
|
|
|
foreach($calendarevents as $event){
|
|
|
|
$event['summary'] .= ' (' . self::$l10n->t('by') . ' ' . OC_Calendar_Object::getowner($event['id']) . ')';
|
|
|
|
}
|
2012-04-08 06:35:29 +04:00
|
|
|
$events = array_merge($events, $calendarevents);
|
|
|
|
}
|
2012-05-01 20:50:31 +04:00
|
|
|
$singleevents = OC_Calendar_Share::allSharedwithuser(OCP\USER::getUser(), OC_Calendar_Share::EVENT, 1, ($_GET['calendar_id'] == 'shared_rw')?'rw':'r');
|
2012-04-08 06:35:29 +04:00
|
|
|
foreach($singleevents as $singleevent){
|
|
|
|
$event = OC_Calendar_Object::find($singleevent['eventid']);
|
2012-06-21 17:19:49 +04:00
|
|
|
if(!array_key_exists('summary', $event)){
|
|
|
|
$event['summary'] = self::$l10n->t('unnamed');
|
|
|
|
}
|
2012-06-14 00:06:22 +04:00
|
|
|
$event['summary'] .= ' (' . self::$l10n->t('by') . ' ' . OC_Calendar_Object::getowner($event['id']) . ')';
|
2012-04-08 06:54:38 +04:00
|
|
|
$events[] = $event;
|
2012-04-08 06:35:29 +04:00
|
|
|
}
|
|
|
|
}else{
|
2012-06-14 00:06:22 +04:00
|
|
|
if (is_numeric($calendarid)) {
|
|
|
|
$calendar = self::getCalendar($calendarid);
|
2012-05-03 12:46:27 +04:00
|
|
|
OCP\Response::enableCaching(0);
|
|
|
|
OCP\Response::setETagHeader($calendar['ctag']);
|
2012-06-14 00:06:22 +04:00
|
|
|
$events = OC_Calendar_Object::allInPeriod($calendarid, $start, $end);
|
2012-04-08 06:35:29 +04:00
|
|
|
} else {
|
2012-06-14 00:06:22 +04:00
|
|
|
OCP\Util::emitHook('OC_Calendar', 'getEvents', array('calendar_id' => $calendarid, 'events' => &$events));
|
2012-04-08 06:35:29 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $events;
|
|
|
|
}
|
|
|
|
|
2012-06-30 19:08:00 +04:00
|
|
|
/**
|
2012-04-08 06:35:29 +04:00
|
|
|
* @brief generates the output for an event which will be readable for our js
|
|
|
|
* @param (mixed) $event - event object / array
|
2012-06-11 19:25:03 +04:00
|
|
|
* @param (int) $start - DateTime object of start
|
|
|
|
* @param (int) $end - DateTime object of end
|
2012-04-08 06:35:29 +04:00
|
|
|
* @return (array) $output - readable output
|
|
|
|
*/
|
|
|
|
public static function generateEventOutput($event, $start, $end){
|
2012-06-29 17:40:46 +04:00
|
|
|
if(!isset($event['calendardata']) && !isset($event['vevent'])){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if(!isset($event['calendardata']) && isset($event['vevent'])){
|
|
|
|
$event['calendardata'] = "BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:ownCloud's Internal iCal System\n" . $event['vevent']->serialize() . "END:VCALENDAR";
|
2012-06-15 13:25:29 +04:00
|
|
|
}
|
2012-06-29 17:40:46 +04:00
|
|
|
$object = OC_VObject::parse($event['calendardata']);
|
|
|
|
$vevent = $object->VEVENT;
|
2012-06-11 19:25:03 +04:00
|
|
|
$return = array();
|
|
|
|
$id = $event['id'];
|
|
|
|
$allday = ($vevent->DTSTART->getDateType() == Sabre_VObject_Element_DateTime::DATE)?true:false;
|
2012-04-08 06:35:29 +04:00
|
|
|
$last_modified = @$vevent->__get('LAST-MODIFIED');
|
|
|
|
$lastmodified = ($last_modified)?$last_modified->getDateTime()->format('U'):0;
|
2012-06-11 19:25:03 +04:00
|
|
|
$staticoutput = array('id'=>(int)$event['id'],
|
2012-08-03 18:18:33 +04:00
|
|
|
'title' => ($event['summary']!=NULL || $event['summary'] != '')?$event['summary']: self::$l10n->t('unnamed'),
|
|
|
|
'description' => isset($vevent->DESCRIPTION)?$vevent->DESCRIPTION->value:'',
|
2012-06-11 19:25:03 +04:00
|
|
|
'lastmodified'=>$lastmodified,
|
|
|
|
'allDay'=>$allday);
|
2012-06-15 13:39:19 +04:00
|
|
|
if(OC_Calendar_Object::isrepeating($id) && OC_Calendar_Repeat::is_cached_inperiod($event['id'], $start, $end)){
|
|
|
|
$cachedinperiod = OC_Calendar_Repeat::get_inperiod($id, $start, $end);
|
2012-06-11 19:25:03 +04:00
|
|
|
foreach($cachedinperiod as $cachedevent){
|
|
|
|
$dynamicoutput = array();
|
|
|
|
if($allday){
|
|
|
|
$start_dt = new DateTime($cachedevent['startdate'], new DateTimeZone('UTC'));
|
|
|
|
$end_dt = new DateTime($cachedevent['enddate'], new DateTimeZone('UTC'));
|
|
|
|
$dynamicoutput['start'] = $start_dt->format('Y-m-d');
|
|
|
|
$dynamicoutput['end'] = $end_dt->format('Y-m-d');
|
|
|
|
}else{
|
|
|
|
$start_dt = new DateTime($cachedevent['startdate'], new DateTimeZone('UTC'));
|
|
|
|
$end_dt = new DateTime($cachedevent['enddate'], new DateTimeZone('UTC'));
|
|
|
|
$start_dt->setTimezone(new DateTimeZone(self::$tz));
|
|
|
|
$end_dt->setTimezone(new DateTimeZone(self::$tz));
|
|
|
|
$dynamicoutput['start'] = $start_dt->format('Y-m-d H:i:s');
|
|
|
|
$dynamicoutput['end'] = $end_dt->format('Y-m-d H:i:s');
|
|
|
|
}
|
|
|
|
$return[] = array_merge($staticoutput, $dynamicoutput);
|
2012-05-04 01:18:43 +04:00
|
|
|
}
|
2012-06-11 19:25:03 +04:00
|
|
|
}else{
|
2012-06-29 20:13:52 +04:00
|
|
|
if(OC_Calendar_Object::isrepeating($id) || $event['repeating'] == 1){
|
|
|
|
$object->expand($start, $end);
|
|
|
|
}
|
2012-06-18 17:58:01 +04:00
|
|
|
foreach($object->getComponents() as $singleevent){
|
|
|
|
if(!($singleevent instanceof Sabre_VObject_Component_VEvent)){
|
2012-06-11 19:25:03 +04:00
|
|
|
continue;
|
2012-04-08 06:35:29 +04:00
|
|
|
}
|
2012-06-18 17:58:01 +04:00
|
|
|
$dynamicoutput = OC_Calendar_Object::generateStartEndDate($singleevent->DTSTART, OC_Calendar_Object::getDTEndFromVEvent($singleevent), $allday, self::$tz);
|
2012-06-29 17:40:46 +04:00
|
|
|
$return[] = array_merge($staticoutput, $dynamicoutput);
|
2012-04-08 06:35:29 +04:00
|
|
|
}
|
|
|
|
}
|
2012-05-04 01:33:44 +04:00
|
|
|
return $return;
|
2012-02-11 17:02:51 +04:00
|
|
|
}
|
2011-12-19 01:58:20 +04:00
|
|
|
}
|