Implement showing Birthdays of contacts in the calendar

This commit is contained in:
Bart Visscher 2012-03-01 20:51:59 +01:00
parent fe3bcb5fe2
commit f914cd0144
4 changed files with 67 additions and 6 deletions

View File

@ -30,16 +30,26 @@ OC_JSON::checkAppEnabled('calendar');
$start = DateTime::createFromFormat('U', $_GET['start']);
$end = DateTime::createFromFormat('U', $_GET['end']);
$calendar = OC_Calendar_App::getCalendar($_GET['calendar_id']);
OC_Response::enableCaching(0);
OC_Response::setETagHeader($calendar['ctag']);
$calendar_id = $_GET['calendar_id'];
if (is_numeric($calendar_id)) {
$calendar = OC_Calendar_App::getCalendar($calendar_id);
OC_Response::enableCaching(0);
OC_Response::setETagHeader($calendar['ctag']);
$events = OC_Calendar_Object::allInPeriod($calendar_id, $start, $end);
} else {
$events = array();
OC_Hook::emit('OC_Calendar', 'getEvents', array('calendar_id' => $calendar_id, 'events' => &$events));
}
$events = OC_Calendar_Object::allInPeriod($_GET['calendar_id'], $start, $end);
$user_timezone = OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'timezone', date_default_timezone_get());
$return = array();
foreach($events as $event){
$object = OC_VObject::parse($event['calendardata']);
$vevent = $object->VEVENT;
if (isset($event['calendardata'])) {
$object = OC_VObject::parse($event['calendardata']);
$vevent = $object->VEVENT;
} else {
$vevent = $event['vevent'];
}
$return_event = create_return_event($event, $vevent);

View File

@ -9,16 +9,20 @@
require_once ('../../lib/base.php');
OC_Util::checkLoggedIn();
OC_Util::checkAppEnabled('calendar');
// Create default calendar ...
$calendars = OC_Calendar_Calendar::allCalendars(OC_User::getUser(), 1);
if( count($calendars) == 0){
OC_Calendar_Calendar::addCalendar(OC_User::getUser(),'Default calendar');
$calendars = OC_Calendar_Calendar::allCalendars(OC_User::getUser(), 1);
}
$eventSources = array();
foreach($calendars as $calendar){
$eventSources[] = OC_Calendar_Calendar::getEventSourceInfo($calendar);
}
OC_Hook::emit('OC_Calendar', 'getSources', array('sources' => &$eventSources));
//Fix currentview for fullcalendar
if(OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'currentview', 'month') == "oneweekview"){
OC_Preferences::setValue(OC_USER::getUser(), "calendar", "currentview", "agendaWeek");

View File

@ -5,6 +5,8 @@ OC::$CLASSPATH['OC_Contacts_VCard'] = 'apps/contacts/lib/vcard.php';
OC::$CLASSPATH['OC_Contacts_Hooks'] = 'apps/contacts/lib/hooks.php';
OC::$CLASSPATH['OC_Connector_Sabre_CardDAV'] = 'apps/contacts/lib/connector_sabre.php';
OC_HOOK::connect('OC_User', 'post_deleteUser', 'OC_Contacts_Hooks', 'deleteUser');
OC_HOOK::connect('OC_Calendar', 'getEvents', 'OC_Contacts_Hooks', 'getBirthdayEvents');
OC_HOOK::connect('OC_Calendar', 'getSources', 'OC_Contacts_Hooks', 'getCalenderSources');
OC_App::register( array(
'order' => 10,

View File

@ -38,4 +38,49 @@ class OC_Contacts_Hooks{
return true;
}
static public function getCalenderSources($parameters) {
$base_url = OC_Helper::linkTo('calendar', 'ajax/events.php').'?calendar_id=';
foreach(OC_Contacts_Addressbook::all(OC_User::getUser()) as $addressbook) {
$parameters['sources'][] =
array(
'url' => $base_url.'birthday_'. $addressbook['id'],
'backgroundColor' => '#cccccc',
'borderColor' => '#888',
'textColor' => 'black',
'cache' => true,
'editable' => false,
);
}
}
static public function getBirthdayEvents($parameters) {
$name = $parameters['calendar_id'];
if (strpos('birthday_', $name) != 0) {
return;
}
$info = explode('_', $name);
$aid = $info[1];
OC_Contacts_App::getAddressbook($aid);
foreach(OC_Contacts_VCard::all($aid) as $card){
$vcard = OC_VObject::parse($card['carddata']);
$birthday = $vcard->BDAY;
if ($birthday) {
$date = new DateTime($birthday);
$vevent = new OC_VObject('VEVENT');
$vevent->setDateTime('LAST-MODIFIED', new DateTime($vcard->REV));
$vevent->setDateTime('DTSTART', $date, Sabre_VObject_Element_DateTime::DATE);
$vevent->setString('DURATION', 'P1D');
// DESCRIPTION?
$vevent->setString('RRULE', 'FREQ=YEARLY');
$title = str_replace('{name}', $vcard->getAsString('FN'), OC_Contacts_App::$l10n->t('{name}\'s Birthday'));
$parameters['events'][] = array(
'id' => 0,//$card['id'],
'vevent' => $vevent,
'repeating' => true,
'summary' => $title,
);
}
}
}
}