summaryrefslogtreecommitdiffstats
path: root/apps/contacts/lib/hooks.php
diff options
context:
space:
mode:
authorBart Visscher <bartv@thisnet.nl>2012-03-01 20:51:59 +0100
committerBart Visscher <bartv@thisnet.nl>2012-03-01 21:00:22 +0100
commitf914cd014432f0883b0fde9ca0826d32393a07a9 (patch)
treea151bc9ec61629867309f92d5574fd33f46a2960 /apps/contacts/lib/hooks.php
parentfe3bcb5fe2acfdddde52b849a7ce8cf8a02c2e6a (diff)
downloadnextcloud-server-f914cd014432f0883b0fde9ca0826d32393a07a9.tar.gz
nextcloud-server-f914cd014432f0883b0fde9ca0826d32393a07a9.zip
Implement showing Birthdays of contacts in the calendar
Diffstat (limited to 'apps/contacts/lib/hooks.php')
-rw-r--r--apps/contacts/lib/hooks.php45
1 files changed, 45 insertions, 0 deletions
diff --git a/apps/contacts/lib/hooks.php b/apps/contacts/lib/hooks.php
index 155cf40f914..10ae82bbf4f 100644
--- a/apps/contacts/lib/hooks.php
+++ b/apps/contacts/lib/hooks.php
@@ -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,
+ );
+ }
+ }
+ }
}