Пример #1
0
 /**
  * Heart of the vCard data assignment process. The runner gets all the meta
  * data for the contact and calls the writeVcard method to output the vCard
  * to the user.
  *
  * @return void
  */
 function run()
 {
     $this->preProcess();
     $params = array();
     $defaults = array();
     $ids = array();
     $params['id'] = $params['contact_id'] = $this->_contactId;
     $contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults, $ids);
     // now that we have the contact's data - let's build the vCard
     // TODO: non-US-ASCII support (requires changes to the Contact_Vcard_Build class)
     $vcardNames = CRM_Core_PseudoConstant::locationVcardName();
     $vcard = new Contact_Vcard_Build('2.1');
     if ($defaults['contact_type'] == 'Individual') {
         $vcard->setName(CRM_Utils_Array::value('last_name', $defaults), CRM_Utils_Array::value('first_name', $defaults), CRM_Utils_Array::value('middle_name', $defaults), CRM_Utils_Array::value('prefix', $defaults), CRM_Utils_Array::value('suffix', $defaults));
     } elseif ($defaults['contact_type'] == 'Organization') {
         $vcard->setName($defaults['organization_name'], '', '', '', '');
     } elseif ($defaults['contact_type'] == 'Household') {
         $vcard->setName($defaults['household_name'], '', '', '', '');
     }
     $vcard->setFormattedName($defaults['display_name']);
     $vcard->setSortString($defaults['sort_name']);
     if (CRM_Utils_Array::value('nick_name', $defaults)) {
         $vcard->addNickname($defaults['nick_name']);
     }
     if (CRM_Utils_Array::value('job_title', $defaults)) {
         $vcard->setTitle($defaults['job_title']);
     }
     if (CRM_Utils_Array::value('birth_date_display', $defaults)) {
         $vcard->setBirthday(CRM_Utils_Array::value('birth_date_display', $defaults));
     }
     if (CRM_Utils_Array::value('home_URL', $defaults)) {
         $vcard->setURL($defaults['home_URL']);
     }
     // TODO: $vcard->setGeo($lat, $lon);
     if (CRM_Utils_Array::value('address', $defaults)) {
         $stateProvices = CRM_Core_PseudoConstant::stateProvince();
         $countries = CRM_Core_PseudoConstant::country();
         foreach ($defaults['address'] as $location) {
             // we don't keep PO boxes in separate fields
             $pob = '';
             $extend = CRM_Utils_Array::value('supplemental_address_1', $location);
             if (CRM_Utils_Array::value('supplemental_address_2', $location)) {
                 $extend .= ', ' . $location['supplemental_address_2'];
             }
             $street = CRM_Utils_Array::value('street_address', $location);
             $locality = CRM_Utils_Array::value('city', $location);
             $region = NULL;
             if (CRM_Utils_Array::value('state_province_id', $location)) {
                 $region = $stateProvices[CRM_Utils_Array::value('state_province_id', $location)];
             }
             $country = NULL;
             if (CRM_Utils_Array::value('country_id', $location)) {
                 $country = $countries[CRM_Utils_Array::value('country_id', $location)];
             }
             $postcode = CRM_Utils_Array::value('postal_code', $location);
             if (CRM_Utils_Array::value('postal_code_suffix', $location)) {
                 $postcode .= '-' . $location['postal_code_suffix'];
             }
             $vcard->addAddress($pob, $extend, $street, $locality, $region, $postcode, $country);
             $vcardName = $vcardNames[$location['location_type_id']];
             if ($vcardName) {
                 $vcard->addParam('TYPE', $vcardName);
             }
             if (CRM_Utils_Array::value('is_primary', $location)) {
                 $vcard->addParam('TYPE', 'PREF');
             }
         }
     }
     if (CRM_Utils_Array::value('phone', $defaults)) {
         foreach ($defaults['phone'] as $phone) {
             $vcard->addTelephone($phone['phone']);
             $vcardName = $vcardNames[$phone['location_type_id']];
             if ($vcardName) {
                 $vcard->addParam('TYPE', $vcardName);
             }
             if ($phone['is_primary']) {
                 $vcard->addParam('TYPE', 'PREF');
             }
         }
     }
     if (CRM_Utils_Array::value('email', $defaults)) {
         foreach ($defaults['email'] as $email) {
             $vcard->addEmail($email['email']);
             $vcardName = $vcardNames[$email['location_type_id']];
             if ($vcardName) {
                 $vcard->addParam('TYPE', $vcardName);
             }
             if ($email['is_primary']) {
                 $vcard->addParam('TYPE', 'PREF');
             }
         }
     }
     // all that's left is sending the vCard to the browser
     $filename = CRM_Utils_String::munge($defaults['display_name']);
     $vcard->send($filename . '.vcf', 'attachment', 'utf-8');
     CRM_Utils_System::civiExit();
 }
 /**
  *
  * Get the values for pseudoconstants for name->value and reverse.
  *
  * @param array   $defaults (reference) the default values, some of which need to be resolved.
  * @param boolean $reverse  true if we want to resolve the values in the reverse direction (value -> name)
  *
  * @return none
  * @access public
  * @static
  */
 static function resolveDefaults(&$defaults, $reverse = FALSE)
 {
     // hack for birth_date
     if (CRM_Utils_Array::value('birth_date', $defaults)) {
         if (is_array($defaults['birth_date'])) {
             $defaults['birth_date'] = CRM_Utils_Date::format($defaults['birth_date'], '-');
         }
     }
     CRM_Utils_Array::lookupValue($defaults, 'prefix', CRM_Core_PseudoConstant::individualPrefix(), $reverse);
     CRM_Utils_Array::lookupValue($defaults, 'suffix', CRM_Core_PseudoConstant::individualSuffix(), $reverse);
     CRM_Utils_Array::lookupValue($defaults, 'gender', CRM_Core_PseudoConstant::gender(), $reverse);
     //lookup value of email/postal greeting, addressee, CRM-4575
     foreach (self::$_greetingTypes as $greeting) {
         $filterCondition = array('contact_type' => CRM_Utils_Array::value('contact_type', $defaults), 'greeting_type' => $greeting);
         CRM_Utils_Array::lookupValue($defaults, $greeting, CRM_Core_PseudoConstant::greeting($filterCondition), $reverse);
     }
     $blocks = array('address', 'im', 'phone');
     foreach ($blocks as $name) {
         if (!array_key_exists($name, $defaults) || !is_array($defaults[$name])) {
             continue;
         }
         foreach ($defaults[$name] as $count => &$values) {
             //get location type id.
             CRM_Utils_Array::lookupValue($values, 'location_type', CRM_Core_PseudoConstant::locationType(), $reverse);
             if ($name == 'address') {
                 // FIXME: lookupValue doesn't work for vcard_name
                 if (CRM_Utils_Array::value('location_type_id', $values)) {
                     $vcardNames = CRM_Core_PseudoConstant::locationVcardName();
                     $values['vcard_name'] = $vcardNames[$values['location_type_id']];
                 }
                 if (!CRM_Utils_Array::lookupValue($values, 'country', CRM_Core_PseudoConstant::country(), $reverse) && $reverse) {
                     CRM_Utils_Array::lookupValue($values, 'country', CRM_Core_PseudoConstant::countryIsoCode(), $reverse);
                 }
                 // CRM-7597
                 // if we find a country id above, we need to restrict it to that country
                 // rather than the list of all countries
                 if (!empty($values['country_id'])) {
                     $stateProvinceList = CRM_Core_PseudoConstant::stateProvinceForCountry($values['country_id']);
                 } else {
                     $stateProvinceList = CRM_Core_PseudoConstant::stateProvince();
                 }
                 if (!CRM_Utils_Array::lookupValue($values, 'state_province', $stateProvinceList, $reverse) && $reverse) {
                     if (!empty($values['country_id'])) {
                         $stateProvinceList = CRM_Core_PseudoConstant::stateProvinceForCountry($values['country_id'], 'abbreviation');
                     } else {
                         $stateProvinceList = CRM_Core_PseudoConstant::stateProvinceAbbreviation();
                     }
                     CRM_Utils_Array::lookupValue($values, 'state_province', $stateProvinceList, $reverse);
                 }
                 if (!empty($values['state_province_id'])) {
                     $countyList = CRM_Core_PseudoConstant::countyForState($values['state_province_id']);
                 } else {
                     $countyList = CRM_Core_PseudoConstant::county();
                 }
                 CRM_Utils_Array::lookupValue($values, 'county', $countyList, $reverse);
             }
             if ($name == 'im') {
                 CRM_Utils_Array::lookupValue($values, 'provider', CRM_Core_PseudoConstant::IMProvider(), $reverse);
             }
             if ($name == 'phone') {
                 CRM_Utils_Array::lookupValue($values, 'phone_type', CRM_Core_PseudoConstant::phoneType(), $reverse);
             }
             //kill the reference.
             unset($values);
         }
     }
 }
Пример #3
0
 /**
  *
  * Get the values for pseudoconstants for name->value and reverse.
  *
  * @param array   $defaults (reference) the default values, some of which need to be resolved.
  * @param boolean $reverse  true if we want to resolve the values in the reverse direction (value -> name)
  *
  * @return none
  * @access public
  * @static
  */
 static function resolveDefaults(&$defaults, $reverse = false)
 {
     // hack for birth_date
     if (CRM_Utils_Array::value('birth_date', $defaults)) {
         if (is_array($defaults['birth_date'])) {
             $defaults['birth_date'] = CRM_Utils_Date::format($defaults['birth_date'], '-');
         }
     }
     CRM_Utils_Array::lookupValue($defaults, 'prefix', CRM_Core_PseudoConstant::individualPrefix(), $reverse);
     CRM_Utils_Array::lookupValue($defaults, 'suffix', CRM_Core_PseudoConstant::individualSuffix(), $reverse);
     CRM_Utils_Array::lookupValue($defaults, 'gender', CRM_Core_PseudoConstant::gender(), $reverse);
     //lookup value of email/postal greeting, addressee, CRM-4575
     $filterCondition = array('contact_type' => CRM_Utils_Array::value('contact_type', $defaults), 'greeting_type' => 'email_greeting');
     CRM_Utils_Array::lookupValue($defaults, 'email_greeting', CRM_Core_PseudoConstant::greeting($filterCondition), $reverse);
     $filterCondition = array('contact_type' => CRM_Utils_Array::value('contact_type', $defaults), 'greeting_type' => 'postal_greeting');
     CRM_Utils_Array::lookupValue($defaults, 'postal_greeting', CRM_Core_PseudoConstant::greeting($filterCondition), $reverse);
     $filterCondition = array('contact_type' => CRM_Utils_Array::value('contact_type', $defaults), 'greeting_type' => 'addressee');
     CRM_Utils_Array::lookupValue($defaults, 'addressee', CRM_Core_PseudoConstant::greeting($filterCondition), $reverse);
     $blocks = array('address', 'im', 'phone');
     foreach ($blocks as $name) {
         if (!array_key_exists($name, $defaults) || !is_array($defaults[$name])) {
             continue;
         }
         foreach ($defaults[$name] as $count => &$values) {
             //get location type id.
             CRM_Utils_Array::lookupValue($values, 'location_type', CRM_Core_PseudoConstant::locationType(), $reverse);
             if ($name == 'address') {
                 // FIXME: lookupValue doesn't work for vcard_name
                 if (CRM_Utils_Array::value('location_type_id', $values)) {
                     $vcardNames =& CRM_Core_PseudoConstant::locationVcardName();
                     $values['vcard_name'] = $vcardNames[$values['location_type_id']];
                 }
                 if (!CRM_Utils_Array::lookupValue($values, 'state_province', CRM_Core_PseudoConstant::stateProvince(), $reverse) && $reverse) {
                     CRM_Utils_Array::lookupValue($values, 'state_province', CRM_Core_PseudoConstant::stateProvinceAbbreviation(), $reverse);
                 }
                 if (!CRM_Utils_Array::lookupValue($values, 'country', CRM_Core_PseudoConstant::country(), $reverse) && $reverse) {
                     CRM_Utils_Array::lookupValue($values, 'country', CRM_Core_PseudoConstant::countryIsoCode(), $reverse);
                 }
                 CRM_Utils_Array::lookupValue($values, 'county', CRM_Core_PseudoConstant::county(), $reverse);
             }
             if ($name == 'im') {
                 CRM_Utils_Array::lookupValue($values, 'provider', CRM_Core_PseudoConstant::IMProvider(), $reverse);
             }
             if ($name == 'phone') {
                 CRM_Utils_Array::lookupValue($values, 'phone_type', CRM_Core_PseudoConstant::phoneType(), $reverse);
             }
             //kill the reference.
             unset($values);
         }
     }
 }
Пример #4
0
 /**
  *
  * Get the values for pseudoconstants for name->value and reverse.
  *
  * @param array   $defaults (reference) the default values, some of which need to be resolved.
  * @param boolean $reverse  true if we want to resolve the values in the reverse direction (value -> name)
  *
  * @return none
  * @access public
  * @static
  */
 function resolveDefaults(&$defaults, $reverse = false)
 {
     // hack for birth_date
     if (CRM_Utils_Array::value('birth_date', $defaults)) {
         if (is_array($defaults['birth_date'])) {
             $defaults['birth_date'] = CRM_Utils_Date::format($defaults['birth_date'], '-');
         }
     }
     if (CRM_Utils_Array::value('prefix', $defaults)) {
         CRM_Contact_BAO_Contact::lookupValue($defaults, 'prefix', CRM_Core_PseudoConstant::individualPrefix(), $reverse);
     }
     if (CRM_Utils_Array::value('suffix', $defaults)) {
         CRM_Contact_BAO_Contact::lookupValue($defaults, 'suffix', CRM_Core_PseudoConstant::individualSuffix(), $reverse);
     }
     if (CRM_Utils_Array::value('gender', $defaults)) {
         CRM_Contact_BAO_Contact::lookupValue($defaults, 'gender', CRM_Core_PseudoConstant::gender(), $reverse);
     }
     if (array_key_exists('location', $defaults)) {
         $locations =& $defaults['location'];
         foreach ($locations as $index => $location) {
             $location =& $locations[$index];
             CRM_Contact_BAO_Contact::lookupValue($location, 'location_type', CRM_Core_PseudoConstant::locationType(), $reverse);
             // FIXME: lookupValue doesn't work for vcard_name
             $vcardNames =& CRM_Core_PseudoConstant::locationVcardName();
             $location['vcard_name'] = $vcardNames[$location['location_type_id']];
             if (array_key_exists('address', $location)) {
                 if (!CRM_Contact_BAO_Contact::lookupValue($location['address'], 'state_province', CRM_Core_PseudoConstant::stateProvince(), $reverse) && $reverse) {
                     CRM_Contact_BAO_Contact::lookupValue($location['address'], 'state_province', CRM_Core_PseudoConstant::stateProvinceAbbreviation(), $reverse);
                 }
                 if (!CRM_Contact_BAO_Contact::lookupValue($location['address'], 'country', CRM_Core_PseudoConstant::country(), $reverse) && $reverse) {
                     CRM_Contact_BAO_Contact::lookupValue($location['address'], 'country', CRM_Core_PseudoConstant::countryIsoCode(), $reverse);
                 }
                 CRM_Contact_BAO_Contact::lookupValue($location['address'], 'county', CRM_Core_SelectValues::county(), $reverse);
             }
             if (array_key_exists('im', $location)) {
                 $ims =& $location['im'];
                 foreach ($ims as $innerIndex => $im) {
                     $im =& $ims[$innerIndex];
                     CRM_Contact_BAO_Contact::lookupValue($im, 'provider', CRM_Core_PseudoConstant::IMProvider(), $reverse);
                     unset($im);
                 }
             }
             unset($location);
         }
     }
 }