Ejemplo n.º 1
0
 public static function getBirthdayEvents($parameters)
 {
     $name = $parameters['calendar_id'];
     if (strpos($name, 'birthday_') != 0) {
         return;
     }
     $info = explode('_', $name);
     $aid = $info[1];
     Addressbook::find($aid);
     foreach (VCard::all($aid) as $contact) {
         try {
             $vcard = VObject\Reader::read($contact['carddata']);
         } catch (Exception $e) {
             continue;
         }
         $birthday = $vcard->BDAY;
         if ($birthday) {
             $date = new \DateTime($birthday);
             $vevent = VObject\Component::create('VEVENT');
             //$vevent->setDateTime('LAST-MODIFIED', new DateTime($vcard->REV));
             $vevent->add('DTSTART');
             $vevent->DTSTART->setDateTime($date, VObject\Property\DateTime::DATE);
             $vevent->add('DURATION', 'P1D');
             $vevent->{'UID'} = substr(md5(rand() . time()), 0, 10);
             // DESCRIPTION?
             $vevent->{'RRULE'} = 'FREQ=YEARLY';
             $title = str_replace('{name}', $vcard->FN, App::$l10n->t('{name}\'s Birthday'));
             $parameters['events'][] = array('id' => 0, 'vevent' => $vevent, 'repeating' => true, 'summary' => $title, 'calendardata' => "BEGIN:VCALENDAR\nVERSION:2.0\n" . "PRODID:ownCloud Contacts " . \OCP\App::getAppVersion('contacts') . "\n" . $vevent->serialize() . "END:VCALENDAR");
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * scan vcards for categories.
  * @param $vccontacts VCards to scan. null to check all vcards for the current user.
  */
 public static function scanCategories($vccontacts = null)
 {
     if (is_null($vccontacts)) {
         $vcaddressbooks = Addressbook::all(\OCP\USER::getUser());
         if (count($vcaddressbooks) > 0) {
             $vcaddressbookids = array();
             foreach ($vcaddressbooks as $vcaddressbook) {
                 if ($vcaddressbook['userid'] === \OCP\User::getUser()) {
                     $vcaddressbookids[] = $vcaddressbook['id'];
                 }
             }
             $start = 0;
             $batchsize = 10;
             $categories = new \OC_VCategories('contact');
             while ($vccontacts = VCard::all($vcaddressbookids, $start, $batchsize)) {
                 $cards = array();
                 foreach ($vccontacts as $vccontact) {
                     $cards[] = array($vccontact['id'], $vccontact['carddata']);
                 }
                 \OCP\Util::writeLog('contacts', __CLASS__ . '::' . __METHOD__ . ', scanning: ' . $batchsize . ' starting from ' . $start, \OCP\Util::DEBUG);
                 // only reset on first batch.
                 $categories->rescan($cards, true, $start == 0 ? true : false);
                 $start += $batchsize;
             }
         }
     }
 }