Calendar: Implement rescan of Categories

This commit is contained in:
Bart Visscher 2012-04-13 16:50:11 +02:00
parent b8466d362e
commit f9b7ed3a1f
2 changed files with 69 additions and 0 deletions

View file

@ -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)));

View file

@ -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);
}