mirror of https://github.com/nextcloud/calendar
more phpdoc for Utility classes
This commit is contained in:
parent
0142da039b
commit
590b937e3d
|
@ -7,6 +7,4 @@
|
|||
*/
|
||||
namespace OCA\Calendar\Utility;
|
||||
|
||||
class BackendUtility extends Utility{
|
||||
|
||||
}
|
||||
class BackendUtility extends Utility{}
|
|
@ -9,8 +9,18 @@ namespace OCA\Calendar\Utility;
|
|||
|
||||
class CalendarUtility extends Utility{
|
||||
|
||||
/**
|
||||
* seperator for backend and uri
|
||||
* @var string
|
||||
*/
|
||||
const SEPERATOR = '::';
|
||||
|
||||
|
||||
/**
|
||||
* @brief suggest a new uri
|
||||
* @param string $calendarURI
|
||||
* @return string $calendarURI
|
||||
*/
|
||||
public static function suggestURI($calendarURI) {
|
||||
if(substr_count($calendarURI, '-') === 0) {
|
||||
$calendarURI .= '-1';
|
||||
|
@ -30,20 +40,25 @@ class CalendarUtility extends Utility{
|
|||
return $calendarURI;
|
||||
}
|
||||
|
||||
public static function splitURI($publicURI) {
|
||||
if ($publicURI === false || $publicURI === null || $publicURI === '') {
|
||||
|
||||
/**
|
||||
* @brief split $calendarURI
|
||||
* @param string $calendarURI
|
||||
* @return array (backend|uri)
|
||||
*/
|
||||
public static function splitURI($calendarURI) {
|
||||
if ($calendarURI === false || $calendarURI === null || $calendarURI === '') {
|
||||
return array(false, false);
|
||||
}
|
||||
|
||||
if (substr_count($publicURI, self::SEPERATOR) === 0){
|
||||
if (substr_count($calendarURI, self::SEPERATOR) === 0){
|
||||
return array(false, false);
|
||||
}
|
||||
|
||||
list($backend, $realCalendarURI) = explode(self::SEPERATOR, $publicURI, 2);
|
||||
|
||||
return array($backend, $realCalendarURI);
|
||||
return explode(self::SEPERATOR, $calendarURI, 2);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief get uri from backend and calendarURI
|
||||
* @param string $backend
|
||||
|
@ -56,5 +71,4 @@ class CalendarUtility extends Utility{
|
|||
$calendarURI,
|
||||
));
|
||||
}
|
||||
|
||||
}
|
140
utility/json.php
140
utility/json.php
|
@ -10,8 +10,15 @@ namespace OCA\Calendar\Utility;
|
|||
use \OCA\Calendar\Db\ObjectType;
|
||||
use \OCA\Calendar\Db\Permissions;
|
||||
|
||||
use \OCA\Calendar\Db\Timezone;
|
||||
|
||||
class JSONUtility extends Utility{
|
||||
|
||||
/**
|
||||
* @brief get json-encoded user-information
|
||||
* @param string $userId
|
||||
* @return array
|
||||
*/
|
||||
public static function getUserInformation($userId) {
|
||||
if($userId === null) {
|
||||
$userId = \OCP\User::getUser();
|
||||
|
@ -23,6 +30,12 @@ class JSONUtility extends Utility{
|
|||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief parse json-encoded user-information
|
||||
* @param array $value
|
||||
* @return string $userId
|
||||
*/
|
||||
public static function parseUserInformation($value) {
|
||||
if(is_array($value) === false) {
|
||||
return null;
|
||||
|
@ -35,6 +48,12 @@ class JSONUtility extends Utility{
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief get json-encoded component-information
|
||||
* @param integer $components
|
||||
* @return array
|
||||
*/
|
||||
public static function getComponents($components) {
|
||||
return array(
|
||||
'vevent' => (bool) ($components & ObjectType::EVENT),
|
||||
|
@ -43,11 +62,13 @@ class JSONUtility extends Utility{
|
|||
);
|
||||
}
|
||||
|
||||
public static function parseComponents($value) {
|
||||
if(is_array($value) === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief parse json-encoded component-information
|
||||
* @param array $value
|
||||
* @return integer $userId
|
||||
*/
|
||||
public static function parseComponents($value) {
|
||||
$components = 0;
|
||||
|
||||
if(array_key_exists('vevent', $value) && $value['vevent'] === true) {
|
||||
|
@ -63,6 +84,12 @@ class JSONUtility extends Utility{
|
|||
return $components;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief get json-encoded cruds-information
|
||||
* @param integer $cruds
|
||||
* @return array
|
||||
*/
|
||||
public static function getCruds($cruds) {
|
||||
return array(
|
||||
'code' => $cruds,
|
||||
|
@ -74,11 +101,13 @@ class JSONUtility extends Utility{
|
|||
);
|
||||
}
|
||||
|
||||
public static function parseCruds($value) {
|
||||
if(is_array($value) === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief parse json-encoded cruds-information
|
||||
* @param array $value
|
||||
* @return integer $userId
|
||||
*/
|
||||
public static function parseCruds($value) {
|
||||
$cruds = 0;
|
||||
|
||||
//use code if given
|
||||
|
@ -101,50 +130,37 @@ class JSONUtility extends Utility{
|
|||
$cruds += Permissions::SHARE;
|
||||
}
|
||||
}
|
||||
|
||||
return $code;
|
||||
}
|
||||
|
||||
public static function parseCalendarURIForBackend($calendarURI) {
|
||||
list($backend, $uri) = CalendarUtility::splitURI($calendarURI);
|
||||
if($backend === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $backend;
|
||||
}
|
||||
|
||||
public static function parseCalendarURIForURI($calendarURI) {
|
||||
list($backend, $uri) = CalendarUtility::splitURI($calendarURI);
|
||||
if($uri === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $uri;
|
||||
}
|
||||
|
||||
public static function parseCalendarURI($key, $value) {
|
||||
list($backend, $calendarURI) = CalendarUtility::splitURI($value);
|
||||
|
||||
if($backend === false || $calendarURI === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return array(
|
||||
$backend,
|
||||
$calendarURI
|
||||
);
|
||||
}
|
||||
|
||||
public static function getTimeZone($timezone, $convenience) {
|
||||
/**
|
||||
* @brief get json-encoded timezone-information
|
||||
* @param Timezone
|
||||
* @return array
|
||||
*/
|
||||
public static function getTimeZone(Timezone $timezone) {
|
||||
$jsonTimezone = new JSONTimezone($timezone);
|
||||
return $jsonTimezone->serialize($convenience);
|
||||
return $jsonTimezone->serialize();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief parse json-encoded timezone-information
|
||||
* @param array
|
||||
* @return null
|
||||
*/
|
||||
public static function parseTimeZone($value) {
|
||||
//$timezoneReader = new JSONTimezoneReader($value);
|
||||
//return $timezoneReader->getObject();
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief get url for calendar
|
||||
* @param string $calendarURI
|
||||
* @return string
|
||||
*/
|
||||
public static function getURL($calendarURI) {
|
||||
$properties = array(
|
||||
'calendarId' => $calendarURI,
|
||||
|
@ -154,40 +170,18 @@ class JSONUtility extends Utility{
|
|||
return \OCP\Util::linkToAbsolute('', substr($url, 1));
|
||||
}
|
||||
|
||||
public static function getCalDAV($calendarURI, $user) {
|
||||
|
||||
/**
|
||||
* @brief get caldav url for calendar
|
||||
* @param string $calendarURI
|
||||
* @param string $userId
|
||||
* @return array
|
||||
*/
|
||||
public static function getCalDAV($calendarURI, $userId) {
|
||||
$url = \OCP\Util::linkToRemote('caldav');
|
||||
$url .= urlencode($user) . '/';
|
||||
$url .= urlencode($userId) . '/';
|
||||
$url .= $calendarURI . '/';
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
public static function addConvenience(&$vobject) {
|
||||
/*foreach($vobject as &$child) {
|
||||
if(!($child instanceof VEvent) &&
|
||||
!($child instanceof VJournal) &&
|
||||
!($child instanceof VTodo)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(isset($child->{'DTSTART'})) {
|
||||
$dtstart = SabreUtility::getDTStart($vobject);
|
||||
if($dtstart !== null) {
|
||||
$vobject->{'X-OC-DTSTART'} = $dtstart->getDateTime()->format(\DateTime::ISO8601);
|
||||
}
|
||||
|
||||
$dtend = SabreUtility::getDTEnd($vobject);
|
||||
if($dtend !== null) {
|
||||
$vobject->{'X-OC-DTEND'} = $dtend->getDateTime()->format(\DateTime::ISO8601);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
public static function dropAttachements(&$vobject) {
|
||||
|
||||
}
|
||||
|
||||
public static function removeConvenience(&$vobject) {
|
||||
|
||||
}
|
||||
}
|
|
@ -34,6 +34,7 @@ class SabreUtility extends Utility {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief count number of events, journals, todos
|
||||
* @param \OCA\Calendar\Sabre\VObject\Component\VCalendar $vcalendar
|
||||
|
@ -43,6 +44,7 @@ class SabreUtility extends Utility {
|
|||
return self::countSabreObjects($vcalendar, array('VEVENT', 'VJOURNAL', 'VTODO'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief count number of freebusys
|
||||
* @param \OCA\Calendar\Sabre\VObject\Component\VCalendar $vcalendar
|
||||
|
@ -52,6 +54,7 @@ class SabreUtility extends Utility {
|
|||
return self::countSabreObjects($vcalendar, array('VFREEBUSY'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief count number of timezones
|
||||
* @param \OCA\Calendar\Sabre\VObject\Component\VCalendar $vcalendar
|
||||
|
@ -61,6 +64,7 @@ class SabreUtility extends Utility {
|
|||
return self::countSabreObjects($vcalendar, array('VTIMEZONE'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief count number of components by identifier definied in $properties
|
||||
* @param \OCA\Calendar\Sabre\VObject\Component\VCalendar $vcalendar
|
||||
|
@ -84,6 +88,7 @@ class SabreUtility extends Utility {
|
|||
return $count;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief count number of unique UIDs inside a calendar
|
||||
* @param \OCA\Calendar\Sabre\VObject\Component\VCalendar $vcalendar
|
||||
|
@ -107,6 +112,7 @@ class SabreUtility extends Utility {
|
|||
return $numberOfUniqueUIDs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief get dtstart property of object
|
||||
* @param \OCA\Calendar\Sabre\VObject\Component $vobject
|
||||
|
@ -127,6 +133,7 @@ class SabreUtility extends Utility {
|
|||
return $vobject->{'DTSTART'};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief get dtend property of object
|
||||
* @param \OCA\Calendar\Sabre\VObject\Component $vobject
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
/**
|
||||
* Copyright (c) 2014 Georg Ehrke <oc.list@georgehrke.com>
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later.
|
||||
* See the COPYING-README file.
|
||||
*/
|
||||
namespace OCA\Calendar\Utility;
|
||||
|
||||
use \DateTimeZone;
|
||||
|
||||
class TimezoneUtility extends Utility {
|
||||
|
||||
/**
|
||||
* @brief check if a timezone identifier is supported
|
||||
* @param string $timezone
|
||||
* @return boolean
|
||||
*/
|
||||
public static function isTimezoneSupported($timezone) {
|
||||
$supportedTimezones = DateTimeZone::listIdentifiers();
|
||||
return in_array($timezone, $supportedTimezones);
|
||||
}
|
||||
}
|
|
@ -7,11 +7,13 @@
|
|||
*/
|
||||
namespace OCA\Calendar\Utility;
|
||||
|
||||
use \DateTimeZone;
|
||||
use \OCA\Calendar\Sabre\VObject\Component;
|
||||
|
||||
class Utility {
|
||||
|
||||
/**
|
||||
* @brief slugify a string
|
||||
* @param string $string
|
||||
* @param string $string
|
||||
*/
|
||||
public static function slugify($string) {
|
||||
$string = preg_replace('~[^\\pL\d\.]+~u', '-', $string);
|
||||
$string = trim($string, '-');
|
||||
|
@ -30,9 +32,4 @@ class Utility {
|
|||
|
||||
return $string;
|
||||
}
|
||||
|
||||
public static function isTimezoneSupported($timezone) {
|
||||
$supportedTimezones = DateTimeZone::listIdentifiers();
|
||||
return in_array($timezone, $supportedTimezones);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue