aboutsummaryrefslogtreecommitdiffstats
path: root/apps/calendar/lib
diff options
context:
space:
mode:
authorGeorg Ehrke <dev@georgswebsite.de>2012-04-13 16:40:10 -0400
committerGeorg Ehrke <dev@georgswebsite.de>2012-04-13 16:40:10 -0400
commitafcb0aee40230c68dd99f5ea2501b7ba7e444560 (patch)
tree5ccd10e78128c70e71a36ca9080a652a7bd833d5 /apps/calendar/lib
parent02dc34320978bfbcb30dea34b87808837586bb65 (diff)
parentb9f9228a22944184803a8835282862e468812c1d (diff)
downloadnextcloud-server-afcb0aee40230c68dd99f5ea2501b7ba7e444560.tar.gz
nextcloud-server-afcb0aee40230c68dd99f5ea2501b7ba7e444560.zip
fix merge conflicts
Diffstat (limited to 'apps/calendar/lib')
-rw-r--r--apps/calendar/lib/app.php79
-rw-r--r--apps/calendar/lib/calendar.php4
-rw-r--r--apps/calendar/lib/object.php31
3 files changed, 73 insertions, 41 deletions
diff --git a/apps/calendar/lib/app.php b/apps/calendar/lib/app.php
index 58cc34658c6..ee1d39bc662 100644
--- a/apps/calendar/lib/app.php
+++ b/apps/calendar/lib/app.php
@@ -17,6 +17,7 @@ class OC_Calendar_App{
* @brief language object for calendar app
*/
public static $l10n;
+ protected static $categories = null;
/*
* @brief timezone of the user
@@ -106,19 +107,76 @@ class OC_Calendar_App{
}
return true;
}
- /*
- * THIS FUNCTION IS DEPRECATED AND WILL BE REMOVED SOON
- * @brief returns the valid categories
- * @return array - categories
+
+ protected static function getDefaultCategories()
+ {
+ 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'),
+ );
+ }
+
+ protected static function getVCategories() {
+ if (is_null(self::$categories)) {
+ self::$categories = new OC_VCategories('calendar', null, self::getDefaultCategories());
+ }
+ return self::$categories;
+ }
+
+ public static function getCategoryOptions()
+ {
+ $categories = self::getVCategories()->categories();
+ return $categories;
+ }
+
+ /**
+ * scan events for categories.
+ * @param $events VEVENTs to scan. null to check all events for the current user.
*/
- public static function getCategoryOptions(){
- return OC_Calendar_Object::getCategoryOptions(self::$l10n);
+ public static function scanCategories($events = null) {
+ if (is_null($events)) {
+ $calendars = OC_Calendar_Calendar::allCalendars(OC_User::getUser());
+ 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)) {
+ $vcategories->loadFromVObject($vobject->VEVENT, true);
+ }
+ }
+ }
}
-
- /*
- * @brief returns the options for an repeating event
- * @return array - valid inputs for repeating events
+
+ /**
+ * check VEvent for new categories.
+ * @see OC_VCategories::loadFromVObject
*/
+ public static function loadCategoriesFromVCalendar(OC_VObject $calendar) {
+ self::getVCategories()->loadFromVObject($calendar->VEVENT, true);
+ }
+
public static function getRepeatOptions(){
return OC_Calendar_Object::getRepeatOptions(self::$l10n);
}
@@ -244,7 +302,6 @@ class OC_Calendar_App{
* @return (array) $events
*/
public static function getrequestedEvents($calendarid, $start, $end){
-
$events = array();
if($calendarid == 'shared_rw' || $_GET['calendar_id'] == 'shared_r'){
$calendars = OC_Calendar_Share::allSharedwithuser(OC_USER::getUser(), OC_Calendar_Share::CALENDAR, 1, ($_GET['calendar_id'] == 'shared_rw')?'rw':'r');
diff --git a/apps/calendar/lib/calendar.php b/apps/calendar/lib/calendar.php
index 7eeb004d181..321f4c73ba0 100644
--- a/apps/calendar/lib/calendar.php
+++ b/apps/calendar/lib/calendar.php
@@ -44,10 +44,8 @@ class OC_Calendar_Calendar{
/**
* @brief Returns the list of calendars for a specific user.
* @param string $uid User ID
- * @param boolean $active
+ * @param boolean $active Only return calendars with this $active state, default(=null) is don't care
* @return array
- *
- * TODO: what is active for?
*/
public static function allCalendars($uid, $active=null){
$values = array($uid);
diff --git a/apps/calendar/lib/object.php b/apps/calendar/lib/object.php
index ab005bd4a4a..825977c17c5 100644
--- a/apps/calendar/lib/object.php
+++ b/apps/calendar/lib/object.php
@@ -93,6 +93,7 @@ class OC_Calendar_Object{
*/
public static function add($id,$data){
$object = OC_VObject::parse($data);
+ OC_Calendar_App::loadCategoriesFromVCalendar($object);
list($type,$startdate,$enddate,$summary,$repeating,$uid) = self::extractData($object);
if(is_null($uid)){
@@ -139,6 +140,7 @@ class OC_Calendar_Object{
$oldobject = self::find($id);
$object = OC_VObject::parse($data);
+ OC_Calendar_App::loadCategoriesFromVCalendar($object);
list($type,$startdate,$enddate,$summary,$repeating,$uid) = self::extractData($object);
$stmt = OC_DB::prepare( 'UPDATE *PREFIX*calendar_objects SET objecttype=?,startdate=?,enddate=?,repeating=?,summary=?,calendardata=?, lastmodified = ? WHERE id = ?' );
@@ -320,27 +322,6 @@ class OC_Calendar_Object{
return $dtend;
}
- public static function getCategoryOptions($l10n)
- {
- return array(
- $l10n->t('Birthday'),
- $l10n->t('Business'),
- $l10n->t('Call'),
- $l10n->t('Clients'),
- $l10n->t('Deliverer'),
- $l10n->t('Holidays'),
- $l10n->t('Ideas'),
- $l10n->t('Journey'),
- $l10n->t('Jubilee'),
- $l10n->t('Meeting'),
- $l10n->t('Other'),
- $l10n->t('Personal'),
- $l10n->t('Projects'),
- $l10n->t('Questions'),
- $l10n->t('Work'),
- );
- }
-
public static function getRepeatOptions($l10n)
{
return array(
@@ -452,10 +433,6 @@ class OC_Calendar_Object{
$errnum++;
}
- if(isset($request['categories']) && !is_array($request['categories'])){
- $errarr['categories'] = $l10n->t('Not an array');
- }
-
$fromday = substr($request['from'], 0, 2);
$frommonth = substr($request['from'], 3, 2);
$fromyear = substr($request['from'], 6, 4);
@@ -623,7 +600,7 @@ class OC_Calendar_Object{
{
$title = $request["title"];
$location = $request["location"];
- $categories = isset($request["categories"]) ? $request["categories"] : array();
+ $categories = $request["categories"];
$allday = isset($request["allday"]);
$from = $request["from"];
$to = $request["to"];
@@ -795,7 +772,7 @@ class OC_Calendar_Object{
$vevent->setString('LOCATION', $location);
$vevent->setString('DESCRIPTION', $description);
- $vevent->setString('CATEGORIES', join(',', $categories));
+ $vevent->setString('CATEGORIES', $categories);
/*if($repeat == "true"){
$vevent->RRULE = $repeat;