static function importableFields($contactType = 'HRJobContractRevision', $status = FALSE, $showAll = FALSE, $isProfile = FALSE, $checkPermission = TRUE, $withMultiCustomFields = FALSE) { if (empty($contactType)) { $contactType = 'HRJobContractRevision'; } $cacheKeyString = ""; $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) { $fields = CRM_Hrjobcontract_DAO_HRJobContractRevision::import(); $fields = array_merge($fields, CRM_Hrjobcontract_DAO_HRJobContractRevision::import()); //Sorting fields in alphabetical order(CRM-1507) $fields = CRM_Utils_Array::crmArraySortByField($fields, 'title'); $fields = CRM_Utils_Array::index(array('name'), $fields); CRM_Core_BAO_Cache::setItem($fields, 'contact fields', $cacheKeyString); } self::$_importableFields[$cacheKeyString] = $fields; if (!$isProfile) { $fields = array_merge(array('do_not_import' => array('title' => ts('- do not import -'))), 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 $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 * @param boolean $checkPermission if false, do not include permissioning clause (for custom data) * * @return array array of importable Fields * @access public * @static */ static function importableFields($contactType = 'HRJobLeave', $status = FALSE, $showAll = FALSE, $isProfile = FALSE, $checkPermission = TRUE, $withMultiCustomFields = FALSE) { if (empty($contactType)) { $contactType = 'HRJobLeave'; } $cacheKeyString = ""; $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) { $fields = CRM_HRJob_DAO_HRJobLeave::import(); $fields = array_merge($fields, CRM_HRJOB_DAO_HRJOBLEAVE::import()); foreach ($fields as $key => $v) { $fields[$key]['hasLocationType'] = TRUE; } //Sorting fields in alphabetical order $fields = CRM_Utils_Array::crmArraySortByField($fields, 'title'); $fields = CRM_Utils_Array::index(array('name'), $fields); CRM_Core_BAO_Cache::setItem($fields, 'contact fields', $cacheKeyString); } self::$_importableFields[$cacheKeyString] = $fields; if (!$isProfile) { $fields = array_merge(array('do_not_import' => array('title' => ts('- do not import -'))), self::$_importableFields[$cacheKeyString]); } return $fields; }
/** * Build the form object. */ public function buildQuickForm() { parent::buildQuickForm(); if (!empty($this->_varNames)) { foreach ($this->_varNames as $groupName => $groupValues) { $formName = CRM_Utils_String::titleToVar($groupName); $this->assign('formName', $formName); $fields = array(); foreach ($groupValues as $fieldName => $fieldValue) { $fields[$fieldName] = $fieldValue; switch ($fieldValue['html_type']) { case 'text': $this->addElement('text', $fieldName, $fieldValue['title'], array('maxlength' => 64, 'size' => 32)); break; case 'textarea': case 'checkbox': $this->add($fieldValue['html_type'], $fieldName, $fieldValue['title']); break; case 'radio': $options = CRM_Core_OptionGroup::values($fieldName, FALSE, FALSE, TRUE); $this->addRadio($fieldName, $fieldValue['title'], $options, NULL, ' '); break; case 'checkboxes': $options = array_flip(CRM_Core_OptionGroup::values($fieldName, FALSE, FALSE, TRUE)); $newOptions = array(); foreach ($options as $key => $val) { $newOptions[$key] = $val; } $this->addCheckBox($fieldName, $fieldValue['title'], $newOptions, NULL, NULL, NULL, NULL, array(' ', ' ', '<br/>')); break; case 'select': $this->addElement('select', $fieldName, $fieldValue['title'], $fieldValue['option_values']); break; case 'wysiwyg': $this->add('wysiwyg', $fieldName, $fieldValue['title'], $fieldValue['attributes']); break; case 'entity_reference': $this->addEntityRef($fieldName, $fieldValue['title'], CRM_Utils_Array::value('options', $fieldValue, array())); } } $fields = CRM_Utils_Array::crmArraySortByField($fields, 'weight'); $this->assign('fields', $fields); } } $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')))); if ($this->_action == CRM_Core_Action::VIEW) { $this->freeze(); } }
/** * 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; }
/** * Get a list of fields which can be added to profiles. * * @param int $gid : UF group ID * @param array $defaults : Form defaults * @return array, multidimensional; e.g. $result['FieldGroup']['field_name']['label'] */ public static function getAvailableFields($gid = NULL, $defaults = array()) { $fields = array('Contact' => array(), 'Individual' => CRM_Contact_BAO_Contact::importableFields('Individual', FALSE, FALSE, TRUE, TRUE, TRUE), 'Household' => CRM_Contact_BAO_Contact::importableFields('Household', FALSE, FALSE, TRUE, TRUE, TRUE), 'Organization' => CRM_Contact_BAO_Contact::importableFields('Organization', FALSE, FALSE, TRUE, TRUE, TRUE)); // include hook injected fields $fields['Contact'] = array_merge($fields['Contact'], CRM_Contact_BAO_Query_Hook::singleton()->getFields()); // add current employer for individuals $fields['Individual']['current_employer'] = array('name' => 'organization_name', 'title' => ts('Current Employer')); $addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options', TRUE, NULL, TRUE); if (!$addressOptions['county']) { unset($fields['Individual']['county'], $fields['Household']['county'], $fields['Organization']['county']); } // break out common contact fields array CRM-3037. // from a UI perspective this makes very little sense foreach ($fields['Individual'] as $key => $value) { if (!empty($fields['Household'][$key]) && !empty($fields['Organization'][$key])) { $fields['Contact'][$key] = $value; unset($fields['Individual'][$key], $fields['Household'][$key], $fields['Organization'][$key]); } } // Internal field not exposed to forms unset($fields['Contact']['contact_type']); unset($fields['Contact']['master_id']); // convert phone extension in to psedo-field phone + phone extension //unset extension unset($fields['Contact']['phone_ext']); //add psedo field $fields['Contact']['phone_and_ext'] = array('name' => 'phone_and_ext', 'title' => ts('Phone and Extension'), 'hasLocationType' => 1); // include Subtypes For Profile $subTypes = CRM_Contact_BAO_ContactType::subTypeInfo(); foreach ($subTypes as $name => $val) { //custom fields for sub type $subTypeFields = CRM_Core_BAO_CustomField::getFieldsForImport($name, FALSE, FALSE, FALSE, TRUE, TRUE); if (array_key_exists($val['parent'], $fields)) { $fields[$name] = $fields[$val['parent']] + $subTypeFields; } else { $fields[$name] = $subTypeFields; } } if (CRM_Core_Permission::access('CiviContribute')) { $contribFields = CRM_Contribute_BAO_Contribution::getContributionFields(FALSE); if (!empty($contribFields)) { unset($contribFields['is_test']); unset($contribFields['is_pay_later']); unset($contribFields['contribution_id']); $contribFields['contribution_note'] = array('name' => 'contribution_note', 'title' => ts('Contribution Note')); $fields['Contribution'] = array_merge($contribFields, self::getContribBatchEntryFields()); } } if (CRM_Core_Permission::access('CiviEvent')) { $participantFields = CRM_Event_BAO_Query::getParticipantFields(); if ($participantFields) { // Remove fields not supported by profiles CRM_Utils_Array::remove($participantFields, 'external_identifier', 'event_id', 'participant_contact_id', 'participant_role_id', 'participant_status_id', 'participant_is_test', 'participant_fee_level', 'participant_id', 'participant_is_pay_later', 'participant_campaign'); if (isset($participantFields['participant_campaign_id'])) { $participantFields['participant_campaign_id']['title'] = ts('Campaign'); } $fields['Participant'] = $participantFields; } } if (CRM_Core_Permission::access('CiviMember')) { $membershipFields = CRM_Member_BAO_Membership::getMembershipFields(); // Remove fields not supported by profiles CRM_Utils_Array::remove($membershipFields, 'membership_id', 'membership_type_id', 'member_is_test', 'is_override', 'status_id', 'member_is_pay_later'); if ($gid && CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $gid, 'name') == 'membership_batch_entry') { $fields['Membership'] = array_merge($membershipFields, self::getMemberBatchEntryFields()); } else { $fields['Membership'] = $membershipFields; } } if (CRM_Core_Permission::access('CiviCase')) { $caseFields = CRM_Case_BAO_Query::getFields(TRUE); $caseFields = array_merge($caseFields, CRM_Core_BAO_CustomField::getFieldsForImport('Case')); if ($caseFields) { // Remove fields not supported by profiles CRM_Utils_Array::remove($caseFields, 'case_id', 'case_type', 'case_start_date', 'case_end_date', 'case_role', 'case_status', 'case_deleted'); } $fields['Case'] = $caseFields; } $activityFields = CRM_Activity_BAO_Activity::getProfileFields(); if ($activityFields) { // campaign related fields. if (isset($activityFields['activity_campaign_id'])) { $activityFields['activity_campaign_id']['title'] = ts('Campaign'); } $fields['Activity'] = $activityFields; } $fields['Formatting']['format_free_html_' . rand(1000, 9999)] = array('name' => 'free_html', 'import' => FALSE, 'export' => FALSE, 'title' => 'Free HTML'); // Sort by title foreach ($fields as &$values) { $values = CRM_Utils_Array::crmArraySortByField($values, 'title'); } //group selected and unwanted fields list $ufFields = $gid ? CRM_Core_BAO_UFGroup::getFields($gid, FALSE, NULL, NULL, NULL, TRUE, NULL, TRUE) : array(); $groupFieldList = array_merge($ufFields, array('note', 'email_greeting_custom', 'postal_greeting_custom', 'addressee_custom', 'id')); //unset selected fields foreach ($groupFieldList as $key => $value) { if (is_int($key)) { unset($fields['Individual'][$value], $fields['Household'][$value], $fields['Organization'][$value]); continue; } if (!empty($defaults['field_name']) && $defaults['field_name']['0'] == $value['field_type'] && $defaults['field_name']['1'] == $key) { continue; } unset($fields[$value['field_type']][$key]); } 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 $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 * @param boolean $checkPermission if false, do not include permissioning clause (for custom data) * * @return array array of importable Fields * @access public * @static */ static function importableFields($contactType = 'Individual', $status = FALSE, $showAll = FALSE, $isProfile = FALSE, $checkPermission = TRUE, $withMultiCustomFields = FALSE) { $cacheKeyString = ""; $cacheKeyString .= $status ? '_1' : '_0'; $cacheKeyString .= $showAll ? '_1' : '_0'; $cacheKeyString .= $isProfile ? '_1' : '_0'; $cacheKeyString .= $checkPermission ? '_1' : '_0'; $contactType = 'Individual'; $fields = CRM_Utils_Array::value($cacheKeyString, self::$_importableFields); if (!$fields) { $fields = CRM_Appraisals_DAO_AppraisalCycle::import(); $tmpContactField = $contactFields = array(); $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); if (is_array($fieldsArray)) { foreach ($fieldsArray as $value) { $customFieldId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $value, 'id', 'column_name'); $value = $customFieldId ? 'custom_' . $customFieldId : $value; $tmpContactField[trim($value)] = CRM_Utils_Array::value(trim($value), $contactFields); if (!$status) { $title = $tmpContactField[trim($value)]['title'] . ' (match to contact)'; } else { $title = $tmpContactField[trim($value)]['title']; } $tmpContactField[trim($value)]['title'] = $title; } } $extIdentifier = CRM_Utils_Array::value('external_identifier', $contactFields); if ($extIdentifier) { $tmpContactField['external_identifier'] = $extIdentifier; $tmpContactField['external_identifier']['title'] = CRM_Utils_Array::value('title', $extIdentifier) . ' (match to contact)'; } $fields = array_merge($fields, $tmpContactField); //Sorting fields in alphabetical order(CRM-1507) $fields = CRM_Utils_Array::crmArraySortByField($fields, 'title'); $fields = CRM_Utils_Array::index(array('name'), $fields); CRM_Core_BAO_Cache::setItem($fields, 'contact fields', $cacheKeyString); } self::$_importableFields[$cacheKeyString] = $fields; if (!$isProfile) { $fields = array_merge(array('do_not_import' => array('title' => ts('- do not import -'))), self::$_importableFields[$cacheKeyString]); } return $fields; }