summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBart Visscher <bartv@thisnet.nl>2012-04-13 16:50:11 +0200
committerBart Visscher <bartv@thisnet.nl>2012-04-13 21:13:58 +0200
commitf9b7ed3a1f0e3671b0018ead4b303f60460f9ea8 (patch)
tree238afd8811c8a5283a3b27ab840a2fb141c7e5a8
parentb8466d362e54bb96a30411143361198a01816f4d (diff)
downloadnextcloud-server-f9b7ed3a1f0e3671b0018ead4b303f60460f9ea8.tar.gz
nextcloud-server-f9b7ed3a1f0e3671b0018ead4b303f60460f9ea8.zip
Calendar: Implement rescan of Categories
-rw-r--r--apps/calendar/ajax/categories/rescan.php42
-rw-r--r--apps/calendar/lib/app.php27
2 files changed, 69 insertions, 0 deletions
diff --git a/apps/calendar/ajax/categories/rescan.php b/apps/calendar/ajax/categories/rescan.php
new file mode 100644
index 00000000000..0fd878ed8f9
--- /dev/null
+++ b/apps/calendar/ajax/categories/rescan.php
@@ -0,0 +1,42 @@
+<?php
+/**
+ * Copyright (c) 2012 Thomas Tanghus <thomas@tanghus.net>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+require_once('../../../../lib/base.php');
+OC_JSON::checkLoggedIn();
+OC_JSON::checkAppEnabled('calendar');
+
+foreach ($_POST as $key=>$element) {
+ debug('_POST: '.$key.'=>'.print_r($element, true));
+}
+
+function bailOut($msg) {
+ OC_JSON::error(array('data' => array('message' => $msg)));
+ OC_Log::write('calendar','ajax/categories/rescan.php: '.$msg, OC_Log::DEBUG);
+ exit();
+}
+function debug($msg) {
+ OC_Log::write('calendar','ajax/categories/rescan.php: '.$msg, OC_Log::DEBUG);
+}
+
+$calendars = OC_Calendar_Calendar::allCalendars(OC_User::getUser());
+if(count($calendars) == 0) {
+ bailOut(OC_Calendar_App::$l10n->t('No calendars found.'));
+}
+$events = array();
+foreach($calendars as $calendar) {
+ $calendar_events = OC_Calendar_Object::all($calendar['id']);
+ $events = $events + $calendar_events;
+}
+if(count($events) == 0) {
+ bailOut(OC_Calendar_App::$l10n->t('No events found.'));
+}
+
+OC_Calendar_App::scanCategories($events);
+$categories = OC_Calendar_App::getCategoryOptions();
+
+OC_JSON::success(array('data' => array('categories'=>$categories)));
diff --git a/apps/calendar/lib/app.php b/apps/calendar/lib/app.php
index b58b70d2df8..5e803ebf7bf 100644
--- a/apps/calendar/lib/app.php
+++ b/apps/calendar/lib/app.php
@@ -89,6 +89,33 @@ class OC_Calendar_App{
return $categories;
}
+ /**
+ * scan events for categories.
+ * @param $events VEVENTs to scan. null to check all events for the current user.
+ */
+ 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);
+ }
+ }
+ }
+ }
+
public static function getRepeatOptions(){
return OC_Calendar_Object::getRepeatOptions(self::$l10n);
}