JeroenDesloovere\VCard\VCard::addName PHP Method

addName() public method

Add name
public addName ( $lastName = '', $firstName = '', $additional = '', $prefix = '', $suffix = '' )
    public function addName($lastName = '', $firstName = '', $additional = '', $prefix = '', $suffix = '')
    {
        // define values with non-empty values
        $values = array_filter(array($prefix, $firstName, $additional, $lastName, $suffix));
        // define filename
        $this->setFilename($values);
        // set property
        $property = $lastName . ';' . $firstName . ';' . $additional . ';' . $prefix . ';' . $suffix;
        $this->setProperty('name', 'N' . $this->getCharsetString(), $property);
        // is property FN set?
        if (!$this->hasProperty('FN')) {
            // set property
            $this->setProperty('fullname', 'FN' . $this->getCharsetString(), trim(implode(' ', $values)));
        }
        return $this;
    }

Usage Example

 /**
  * Returns a vcard for a profile
  * @param $profile
  * @param $includePhoto
  * @return VCard
  */
 public function getVCard($profile, $includePhoto)
 {
     $vcard = new VCard();
     $vcard->addName($profile['lastName'], $profile['firstName'])->addCompany($profile['company'])->addAddress('', '', $profile['address']['street'], $profile['address']['city'], $profile['address']['region'], $profile['address']['zip'], $profile['address']['country'])->addEmail($profile['email'])->addURL($profile['url'])->addPhoneNumber($profile['phone']['work'], 'WORK')->addPhoneNumber($profile['phone']['mobile'], 'CELL')->addJobtitle($profile['jobTitle']);
     // Add photo
     if ($profile['photo'] != null) {
         $photoUri = null;
         if ($includePhoto) {
             // Generate filesystem URI
             $webDir = $this->kernelRootDir . '/../web/';
             $photoUri = $webDir . $profile['photo'];
         } else {
             // Generate absolute public URI
             $photoUri = $this->request->getUriForPath('/' . $profile['photo']);
         }
         $vcard->addPhoto($photoUri, $includePhoto);
     }
     return $vcard;
 }
All Usage Examples Of JeroenDesloovere\VCard\VCard::addName