/** * combine all the importable fields from the lower levels object * * The ordering is important, since currently we do not have a weight * scheme. Adding weight is super important and should be done in the * next week or so, before this can be called complete. * * @return array array of importable Fields * @access public */ function &importableFields($contacType = 'Individual', $status = true) { if (!self::$_importableFields) { if (!self::$_importableFields) { self::$_importableFields = array(); } if (!$status) { $fields = array('' => array('title' => ts('- do not import -'))); } else { $fields = array('' => array('title' => ts('- Contribution Fields -'))); } require_once 'CRM/Core/DAO/Note.php'; $note = CRM_Core_DAO_Note::import(); $tmpFields = CRM_Contribute_DAO_Contribution::import(); unset($tmpFields['option_value']); require_once 'CRM/Core/OptionValue.php'; $optionFields = CRM_Core_OptionValue::getFields($mode = 'contribute'); require_once 'CRM/Contact/BAO/Contact.php'; $contactFields = CRM_Contact_BAO_Contact::importableFields($contacType, null); // Using new Dedupe rule. $ruleParams = array('contact_type' => $contacType, 'level' => 'Strict'); require_once 'CRM/Dedupe/BAO/Rule.php'; $fieldsArray = CRM_Dedupe_BAO_Rule::dedupeRuleFields($ruleParams); $tmpConatctField = array(); if (is_array($fieldsArray)) { foreach ($fieldsArray as $value) { //skip if there is no dupe rule if ($value == 'none') { continue; } $tmpConatctField[trim($value)] = $contactFields[trim($value)]; if (!$status) { $title = $tmpConatctField[trim($value)]['title'] . " (match to contact)"; } else { $title = $tmpConatctField[trim($value)]['title']; } $tmpConatctField[trim($value)]['title'] = $title; } } $tmpConatctField['external_identifier'] = $contactFields['external_identifier']; $tmpConatctField['external_identifier']['title'] = $contactFields['external_identifier']['title'] . " (match to contact)"; $tmpFields['contribution_contact_id']['title'] = $tmpFields['contribution_contact_id']['title'] . " (match to contact)"; $fields = array_merge($fields, $tmpConatctField); $fields = array_merge($fields, $tmpFields); $fields = array_merge($fields, $note); $fields = array_merge($fields, $optionFields); require_once 'CRM/Contribute/DAO/ContributionType.php'; $fields = array_merge($fields, CRM_Contribute_DAO_ContributionType::export()); $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport('Contribution')); self::$_importableFields = $fields; } return self::$_importableFields; }
/** * Combine all the importable fields from the lower levels object. * * The ordering is important, since currently we do not have a weight * scheme. Adding weight is super important and should be done in the * next week or so, before this can be called complete. * * @param string $contactType * @param bool $status * * @return array * array of importable Fields */ public static function &importableFields($contactType = 'Individual', $status = TRUE) { if (!self::$_importableFields) { if (!self::$_importableFields) { self::$_importableFields = array(); } if (!$status) { $fields = array('' => array('title' => ts('- do not import -'))); } else { $fields = array('' => array('title' => ts('- Contribution Fields -'))); } $note = CRM_Core_DAO_Note::import(); $tmpFields = CRM_Contribute_DAO_Contribution::import(); unset($tmpFields['option_value']); $optionFields = CRM_Core_OptionValue::getFields($mode = 'contribute'); $contactFields = CRM_Contact_BAO_Contact::importableFields($contactType, NULL); // Using new Dedupe rule. $ruleParams = array('contact_type' => $contactType, 'used' => 'Unsupervised'); $fieldsArray = CRM_Dedupe_BAO_Rule::dedupeRuleFields($ruleParams); $tmpContactField = array(); if (is_array($fieldsArray)) { foreach ($fieldsArray as $value) { //skip if there is no dupe rule if ($value == 'none') { continue; } $customFieldId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $value, 'id', 'column_name'); $value = $customFieldId ? 'custom_' . $customFieldId : $value; $tmpContactField[trim($value)] = $contactFields[trim($value)]; if (!$status) { $title = $tmpContactField[trim($value)]['title'] . ' ' . ts('(match to contact)'); } else { $title = $tmpContactField[trim($value)]['title']; } $tmpContactField[trim($value)]['title'] = $title; } } $tmpContactField['external_identifier'] = $contactFields['external_identifier']; $tmpContactField['external_identifier']['title'] = $contactFields['external_identifier']['title'] . ' ' . ts('(match to contact)'); $tmpFields['contribution_contact_id']['title'] = $tmpFields['contribution_contact_id']['title'] . ' ' . ts('(match to contact)'); $fields = array_merge($fields, $tmpContactField); $fields = array_merge($fields, $tmpFields); $fields = array_merge($fields, $note); $fields = array_merge($fields, $optionFields); $fields = array_merge($fields, CRM_Financial_DAO_FinancialType::export()); $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport('Contribution')); self::$_importableFields = $fields; } return self::$_importableFields; }
/** * combine all the importable fields from the lower levels object * * The ordering is important, since currently we do not have a weight * scheme. Adding weight is super important and should be done in the * next week or so, before this can be called complete. * * @param int $contactType contact Type * @param boolean $status status is used to manipulate first title * @param boolean $showAll if true returns all fields (includes disabled fields) * @param boolean $isProfile if its profile mode * * @return array array of importable Fields * @access public */ function &importableFields($contactType = 'Individual', $status = false, $showAll = false, $isProfile = false) { if (empty($contactType)) { $contactType = 'All'; } $cacheKeyString = "importableFields {$contactType}"; $cacheKeyString .= $status ? "_1" : "_0"; $cacheKeyString .= $showAll ? "_1" : "_0"; $cacheKeyString .= $isProfile ? "_1" : "_0"; if (!self::$_importableFields || !CRM_Utils_Array::value($cacheKeyString, self::$_importableFields)) { if (!self::$_importableFields) { self::$_importableFields = array(); } // check if we can retrieve from database cache require_once 'CRM/Core/BAO/Cache.php'; $fields =& CRM_Core_BAO_Cache::getItem('contact fields', $cacheKeyString); if (!$fields) { $fields = CRM_Contact_DAO_Contact::import(); require_once "CRM/Core/OptionValue.php"; // get the fields thar are meant for contact types if (in_array($contactType, array('Individual', 'Household', 'Organization', 'All'))) { $fields = array_merge($fields, CRM_Core_OptionValue::getFields('', $contactType)); } $locationFields = array_merge(CRM_Core_DAO_Address::import(), CRM_Core_DAO_Phone::import(), CRM_Core_DAO_Email::import(), CRM_Core_DAO_IM::import(true), CRM_Core_DAO_OpenID::import()); foreach ($locationFields as $key => $field) { $locationFields[$key]['hasLocationType'] = true; } $fields = array_merge($fields, $locationFields); $fields = array_merge($fields, CRM_Contact_DAO_Contact::import()); $fields = array_merge($fields, CRM_Core_DAO_Note::import()); if ($contactType != 'All') { $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport($contactType, $showAll, true)); //unset the fields, which are not related to their //contact type. $commonValues = array('Individual' => array('household_name', 'legal_name', 'sic_code', 'organization_name'), 'Household' => array('first_name', 'middle_name', 'last_name', 'job_title', 'gender_id', 'birth_date', 'organization_name', 'legal_name', 'legal_identifier', 'sic_code', 'home_URL', 'is_deceased', 'deceased_date'), 'Organization' => array('first_name', 'middle_name', 'last_name', 'job_title', 'gender_id', 'birth_date', 'household_name', 'email_greeting', 'email_greeting_custom', 'postal_greeting', 'postal_greeting_custom', 'is_deceased', 'deceased_date')); foreach ($commonValues[$contactType] as $value) { unset($fields[$value]); } } else { foreach (array('Individual', 'Household', 'Organization') as $type) { $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport($type, $showAll)); } } if ($isProfile) { $fields = array_merge($fields, array('group' => array('title' => ts('Group(s)')), 'tag' => array('title' => ts('Tag(s)')), 'note' => array('title' => ts('Note(s)')))); } //Sorting fields in alphabetical order(CRM-1507) foreach ($fields as $k => $v) { $sortArray[$k] = $v['title']; } asort($sortArray); $fields = array_merge($sortArray, $fields); CRM_Core_BAO_Cache::setItem($fields, 'contact fields', $cacheKeyString); } self::$_importableFields[$cacheKeyString] = $fields; } if (!$isProfile) { if (!$status) { $fields = array_merge(array('do_not_import' => array('title' => ts('- do not import -'))), self::$_importableFields[$cacheKeyString]); } else { $fields = array_merge(array('' => array('title' => ts('- Contact Fields -'))), self::$_importableFields[$cacheKeyString]); } } return $fields; }
/** * Combine all the importable fields from the lower levels object. * * The ordering is important, since currently we do not have a weight * scheme. Adding weight is super important * * @param int|string $contactType contact Type * @param bool $status * Status is used to manipulate first title. * @param bool $showAll * If true returns all fields (includes disabled fields). * @param bool $isProfile * If its profile mode. * @param bool $checkPermission * If false, do not include permissioning clause (for custom data). * * @param bool $withMultiCustomFields * * @return array * array of importable Fields */ public static function importableFields($contactType = 'Individual', $status = FALSE, $showAll = FALSE, $isProfile = FALSE, $checkPermission = TRUE, $withMultiCustomFields = FALSE) { if (empty($contactType)) { $contactType = 'All'; } $cacheKeyString = "importableFields {$contactType}"; $cacheKeyString .= $status ? '_1' : '_0'; $cacheKeyString .= $showAll ? '_1' : '_0'; $cacheKeyString .= $isProfile ? '_1' : '_0'; $cacheKeyString .= $checkPermission ? '_1' : '_0'; $fields = CRM_Utils_Array::value($cacheKeyString, self::$_importableFields); if (!$fields) { // check if we can retrieve from database cache $fields = CRM_Core_BAO_Cache::getItem('contact fields', $cacheKeyString); } if (!$fields) { $fields = CRM_Contact_DAO_Contact::import(); // get the fields thar are meant for contact types if (in_array($contactType, array('Individual', 'Household', 'Organization', 'All'))) { $fields = array_merge($fields, CRM_Core_OptionValue::getFields('', $contactType)); } $locationFields = array_merge(CRM_Core_DAO_Address::import(), CRM_Core_DAO_Phone::import(), CRM_Core_DAO_Email::import(), CRM_Core_DAO_IM::import(TRUE), CRM_Core_DAO_OpenID::import()); $locationFields = array_merge($locationFields, CRM_Core_BAO_CustomField::getFieldsForImport('Address', FALSE, FALSE, FALSE, FALSE)); foreach ($locationFields as $key => $field) { $locationFields[$key]['hasLocationType'] = TRUE; } $fields = array_merge($fields, $locationFields); $fields = array_merge($fields, CRM_Contact_DAO_Contact::import()); $fields = array_merge($fields, CRM_Core_DAO_Note::import()); //website fields $fields = array_merge($fields, CRM_Core_DAO_Website::import()); $fields['url']['hasWebsiteType'] = TRUE; if ($contactType != 'All') { $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport($contactType, $showAll, TRUE, FALSE, FALSE, $withMultiCustomFields)); //unset the fields, which are not related to their //contact type. $commonValues = array('Individual' => array('household_name', 'legal_name', 'sic_code', 'organization_name'), 'Household' => array('first_name', 'middle_name', 'last_name', 'formal_title', 'job_title', 'gender_id', 'prefix_id', 'suffix_id', 'birth_date', 'organization_name', 'legal_name', 'legal_identifier', 'sic_code', 'home_URL', 'is_deceased', 'deceased_date'), 'Organization' => array('first_name', 'middle_name', 'last_name', 'formal_title', 'job_title', 'gender_id', 'prefix_id', 'suffix_id', 'birth_date', 'household_name', 'is_deceased', 'deceased_date')); foreach ($commonValues[$contactType] as $value) { unset($fields[$value]); } } else { foreach (array('Individual', 'Household', 'Organization') as $type) { $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport($type, $showAll, FALSE, FALSE, FALSE, $withMultiCustomFields)); } } if ($isProfile) { $fields = array_merge($fields, array('group' => array('title' => ts('Group(s)'), 'name' => 'group'), 'tag' => array('title' => ts('Tag(s)'), 'name' => 'tag'), 'note' => array('title' => ts('Note(s)'), 'name' => 'note'), 'communication_style_id' => array('title' => ts('Communication Style'), 'name' => 'communication_style_id'))); } //Sorting fields in alphabetical order(CRM-1507) $fields = CRM_Utils_Array::crmArraySortByField($fields, 'title'); CRM_Core_BAO_Cache::setItem($fields, 'contact fields', $cacheKeyString); } self::$_importableFields[$cacheKeyString] = $fields; if (!$isProfile) { if (!$status) { $fields = array_merge(array('do_not_import' => array('title' => ts('- do not import -'))), self::$_importableFields[$cacheKeyString]); } else { $fields = array_merge(array('' => array('title' => ts('- Contact Fields -'))), self::$_importableFields[$cacheKeyString]); } } return $fields; }
/** * combine all the importable fields from the lower levels object * * The ordering is important, since currently we do not have a weight * scheme. Adding weight is super important and should be done in the * next week or so, before this can be called complete. * * @param int $contactType contact Type * @param boolean $status status is used to manipulate first title * @param boolean $showAll if true returns all fields (includes disabled fields) * * @return array array of importable Fields * @access public */ function &importableFields($contactType = 'Individual', $status = false, $showAll = false) { if (empty($contactType)) { $contactType = 'All'; } if (!$GLOBALS['_CRM_CONTACT_BAO_CONTACT']['_importableFields'] || !CRM_Utils_Array::value($contactType, $GLOBALS['_CRM_CONTACT_BAO_CONTACT']['_importableFields'])) { if (!$GLOBALS['_CRM_CONTACT_BAO_CONTACT']['_importableFields']) { $GLOBALS['_CRM_CONTACT_BAO_CONTACT']['_importableFields'] = array(); } if (!$status) { $fields = array('do_not_import' => array('title' => ts('- do not import -'))); } else { $fields = array('' => array('title' => ts('- Contact Fields -'))); } if ($contactType != 'All') { require_once str_replace('_', DIRECTORY_SEPARATOR, "CRM_Contact_DAO_" . $contactType) . ".php"; eval('$tmpFields = array_merge($fields, CRM_Contact_DAO_' . $contactType . '::import( ));'); $fields = array_merge($fields, $tmpFields); } else { foreach (array('Individual', 'Household', 'Organization') as $type) { require_once str_replace('_', DIRECTORY_SEPARATOR, "CRM_Contact_DAO_" . $type) . ".php"; eval('$tmpFields = array_merge($fields, CRM_Contact_DAO_' . $type . '::import( ));'); $fields = array_merge($fields, $tmpFields); } } // the fields are only meant for Individual contact type if ($contactType == 'Individual' || $contactType == 'All') { $fields = array_merge($fields, CRM_Core_DAO_IndividualPrefix::import(true), CRM_Core_DAO_IndividualSuffix::import(true), CRM_Core_DAO_Gender::import(true)); } $locationFields = array_merge(CRM_Core_DAO_Location::import(), CRM_Core_DAO_Address::import(), CRM_Core_DAO_Phone::import(), CRM_Core_DAO_Email::import(), CRM_Core_DAO_IM::import(true)); foreach ($locationFields as $key => $field) { $locationFields[$key]['hasLocationType'] = true; } $fields = array_merge($fields, $locationFields); $fields = array_merge($fields, CRM_Contact_DAO_Contact::import()); $fields = array_merge($fields, CRM_Core_DAO_Note::import()); if ($contactType != 'All') { $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport($contactType, $showAll)); } else { foreach (array('Individual', 'Household', 'Organization') as $type) { $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport($type, $showAll)); } } $GLOBALS['_CRM_CONTACT_BAO_CONTACT']['_importableFields'][$contactType] = $fields; } return $GLOBALS['_CRM_CONTACT_BAO_CONTACT']['_importableFields'][$contactType]; }