private function buildVcardResponse(VCard $vcard) { // Build response $response = new Response($vcard->getOutput()); foreach ($vcard->getHeaders(true) as $key => $val) { $response->headers->set($key, $val); } return $response; }
/** * 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; }
/* For licensing terms, see /license.txt */ /** * VCard Generator * @package chamilo.social * @author José Loguercio Silva <*****@*****.**> */ require_once '../inc/global.inc.php'; use JeroenDesloovere\VCard\VCard; api_block_anonymous_users(); if (isset($_REQUEST['userId'])) { $userId = intval($_REQUEST['userId']); } else { api_not_allowed(); } // Return User Info to vCard Export $userInfo = api_get_user_info($userId, true, false, true); // Pre-Loaded User Info $firstname = $userInfo['firstname']; $lastname = $userInfo['lastname']; $email = $userInfo['email']; $phone = $userInfo['phone']; $language = get_lang('Language') . ': ' . $userInfo['language']; // Instance the vCard Class $vcard = new VCard(); // Adding the User Info to the vCard $vcard->addName($lastname, $firstname); $vcard->addEmail($email); $vcard->addPhoneNumber($phone, 'CELL'); $vcard->addNote($language); // Generate the vCard return $vcard->download();
<?php /** * VCard generator test - can save to file or output as a download * * @author Jeroen Desloovere <*****@*****.**> */ require_once __DIR__ . '/../vendor/autoload.php'; require_once __DIR__ . '/../src/VCard.php'; use JeroenDesloovere\VCard\VCard; // define vcard $vcard = new VCard(); // define variables $firstname = 'Jeroen'; $lastname = 'Desloovere'; $additional = ''; $prefix = ''; $suffix = ''; // add personal data $vcard->addName($lastname, $firstname, $additional, $prefix, $suffix); // add work data $vcard->addCompany('Siesqo'); $vcard->addJobtitle('Web Developer'); $vcard->addEmail('*****@*****.**'); $vcard->addPhoneNumber(1234121212, 'PREF;WORK'); $vcard->addPhoneNumber(123456789, 'WORK'); $vcard->addAddress(null, null, 'street', 'worktown', null, 'workpostcode', 'Belgium'); $vcard->addURL('http://www.jeroendesloovere.be'); $vcard->addPhoto(__DIR__ . '/assets/landscape.jpeg'); //$vcard->addPhoto('https://raw.githubusercontent.com/jeroendesloovere/vcard/master/tests/image.jpg'); // return vcard as a string
/** * Test special first name and last name */ public function testSpecialFirstNameAndLastName2() { $this->vcard->addName($this->lastName3, $this->firstName3); $this->assertEquals('garcon-jeroen', $this->vcard->getFilename()); }
private function _createVcardData(VCardModel $vcardModel) { $vcard = new VCard(); $vcard->addName($vcardModel->lastName, $vcardModel->firstName, $vcardModel->additional, $vcardModel->prefix, $vcardModel->suffix); if ($vcardModel->company) { $vcard->addCompany($vcardModel->company); } if ($vcardModel->jobTitle) { $vcard->addJobtitle($vcardModel->jobTitle); } if ($vcardModel->url and is_array($vcardModel->url)) { foreach ($vcardModel->url as $url) { if ($url instanceof VCard_UrlModel) { if ($url->validate()) { $vcard->addUrl($url->address, $url->type); } } } } if ($vcardModel->address and is_array($vcardModel->address)) { foreach ($vcardModel->address as $address) { if ($address instanceof VCard_AddressModel) { if ($address->validate()) { $vcard->addAddress($address->name, $address->extended, $address->street, $address->city, $address->region, $address->zip, $address->country, $address->type); } } } } if ($vcardModel->phoneNumber and is_array($vcardModel->phoneNumber)) { foreach ($vcardModel->phoneNumber as $phoneNumber) { if ($phoneNumber instanceof VCard_PhoneNumberModel) { if ($phoneNumber->validate()) { $vcard->addPhoneNumber($phoneNumber->number, $phoneNumber->type); } } } } if ($vcardModel->email and is_array($vcardModel->email)) { foreach ($vcardModel->email as $email) { if ($email instanceof VCard_EmailModel) { if ($email->validate()) { $vcard->addEmail($email->address, $email->type); } } } } if ($vcardModel->photo) { $vcard->addPhoto($vcardModel->photo); } if ($vcardModel->note) { $vcard->addNote($vcardModel->note); } return $vcard; }
public function testIteration() { // Prepare a VCard DB. $db = ''; $vcard = new VCard(); $vcard->addName("Admiraal", "Wouter"); $db .= $vcard->buildVCard(); $vcard = new VCard(); $vcard->addName("Lorem", "Ipsum"); $db .= $vcard->buildVCard(); $parser = new VCardParser($db); foreach ($parser as $i => $card) { $this->assertEquals($card->fullname, $i == 0 ? "Wouter Admiraal" : "Ipsum Lorem"); } }