Пример #1
0
 private function generateVcard($user) {
   $card = new Vpdi_Vcard();
   
   $name = new Vpdi_Vcard_Name();
   $name->family = $user['lastname'];
   $name->given  = $user['firstname'];
   //$name->fullname =  ;
   $card->setName($name);
   
   $add = new Vpdi_Vcard_Address();
   $add->street = $user['address1'];
   $add->extended = $user['address2'];
   $add->locality = $user['town'];
   $add->postalcode = $user['zipcode'];
   $add->pobox = $user['expresspostal'];
   //$add->country = 'FRANCE';
   $add->location[] = 'work';
   $card->addAddress($add);
   
   if (!empty($user['phone'])) {
     $phone = new Vpdi_Vcard_Phone($user['phone']);
     $phone->location[] = 'work';
     $card->addPhone($phone);
   }
   
   if (!empty($user['mobile'])) {
     $mobile = new Vpdi_Vcard_Phone($user['mobile']);
     $mobile->location[] = 'cell';
     $card->addPhone($mobile);
   }
   
   if (!empty($user['email'])) {
     $email = new Vpdi_Vcard_Email($user['email']);
     $email->location[] = 'work';
     $card->addEmail($email);
   }
   
   $card[] = new Vpdi_Property('caluri', $this->getCalUri($user));
   
   return $card;
 }
Пример #2
0
  public function toVcard() {
    $name = new Vpdi_Vcard_Name();
    $name->family = $this->lastname;
    $name->given  = $this->firstname;
    if (!empty($this->kind)) {
      $name->prefixes = $this->kind;
    }
    
    $card = new Vpdi_Vcard();
    $card->setName($name);
    $card->addProperty(new Vpdi_Property('x-obm-uid', $this->id));
    
    $simpleProps = array('function' => 'role', 'title' => 'title');
    foreach ($simpleProps as $db => $v) {
      if (!empty($this->$db)) {
        $card->addProperty(new Vpdi_Property($v, $this->$db));
      }
    }

    // x-obm-* (OBM specific properties)
    $obmSpecificProps = array('commonname','mname','company_id','company','market_id','suffix',
      'aka','sound','manager','assistant','spouse','category','service',
      'mailok','newsletter', 'comment');
    foreach ($obmSpecificProps as $prop) {
      if (!empty($this->$prop)) {
        $card->addProperty(new Vpdi_Property("x-obm-{$prop}", str_replace("\r\n", '\n', (trim($this->$prop)))));        
      }
    }
    if (!empty($this->date)) {
      $card->addProperty(new Vpdi_Property('x-obm-date', $this->date->get(Of_date::DATE_ISO)));
    }
    if (!empty($this->anniversary)) {
      $card->addProperty(new Vpdi_Property('x-obm-anniversary', $this->anniversary->get(Of_date::DATE_ISO)));
    }

    //$card->addProperty(new Vpdi_Property('org', $this->company));
    
    if (!empty($this->birthday)) {
      $card->addProperty(new Vpdi_Property('bday', $this->birthday->get(Of_date::DATE_ISO)));
    }

    foreach ($this->phone as $phone) {
      $ph = new Vpdi_Vcard_Phone($phone['number']);
      $ph->location = $phone['label'];
      $card->addPhone($ph);
    }
    foreach ($this->email as $email) {
      $em = new Vpdi_Vcard_Email($email['address']);
      $em->location = $email['label'];
      $card->addEmail($em);
    }
    foreach ($this->address as $address) {
      $ad = new Vpdi_Vcard_Address();
      $ad->location = $address['label'];
      $ad->street = str_replace("\r", "\n", str_replace("\r\n", "\n", (trim($address['street']))));
      $ad->postalcode = $address['zipcode'];
      $ad->pobox = $address['expresspostal'];
      $ad->locality = $address['town'];
      $ad->country = $address['country'];
      $card->addAddress($ad);
    }
    foreach ($this->im as $impp) {
      $card->addImpp(new Vpdi_Vcard_Impp(strtolower($impp['protocol']).':'.$impp['address']));
    }
    foreach ($this->website as $www) {
      if (in_array('URL', $www['label'])) {
        $card->addProperty(new Vpdi_Property('url', $www['url']));
      } elseif (in_array('BLOG', $www['label'])) {
        $card->addProperty(new Vpdi_Property('x-obm-blog', $www['url']));
      }
    }
    
    return $card;
  }