static function defaultReturnProperties($mode) { $properties = null; if ($mode & CRM_Contact_BAO_Query::MODE_ACTIVITY) { $properties = array('activity_id' => 1, 'contact_type' => 1, 'contact_sub_type' => 1, 'sort_name' => 1, 'display_name' => 1, 'activity_type' => 1, 'activity_subject' => 1, 'activity_date_time' => 1, 'activity_duration' => 1, 'activity_location' => 1, 'activity_details' => 1, 'activity_status' => 1, 'source_contact_id' => 1, 'source_record_id' => 1, 'activity_is_test' => 1); // also get all the custom activity properties require_once "CRM/Core/BAO/CustomField.php"; $fields = CRM_Core_BAO_CustomField::getFieldsForImport('Activity'); if (!empty($fields)) { foreach ($fields as $name => $dontCare) { $properties[$name] = 1; } } } return $properties; }
/** * Combine all the exportable fields from the lower level objects. * * @param bool $checkPermission * * @return array * array of exportable Fields */ public static function &exportableFields($checkPermission = TRUE) { if (!self::$_exportableFields) { if (!self::$_exportableFields) { self::$_exportableFields = array(); } $participantFields = CRM_Event_DAO_Participant::export(); $eventFields = CRM_Event_DAO_Event::export(); $noteField = array('participant_note' => array('title' => 'Participant Note', 'name' => 'participant_note', 'type' => CRM_Utils_Type::T_STRING)); $participantStatus = array('participant_status' => array('title' => 'Participant Status', 'name' => 'participant_status', 'type' => CRM_Utils_Type::T_STRING)); $participantRole = array('participant_role' => array('title' => 'Participant Role', 'name' => 'participant_role', 'type' => CRM_Utils_Type::T_STRING)); $discountFields = CRM_Core_DAO_Discount::export(); $fields = array_merge($participantFields, $participantStatus, $participantRole, $eventFields, $noteField, $discountFields); // add custom data $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport('Participant', FALSE, FALSE, FALSE, $checkPermission)); self::$_exportableFields = $fields; } return self::$_exportableFields; }
/** * Get list of membership fields for profile. * * For now we only allow custom membership fields to be in * profile * * @param null $mode * FIXME: This param is ignored * * @return array * the list of membership fields */ public static function getMembershipFields($mode = NULL) { $fields = CRM_Member_DAO_Membership::export(); unset($fields['membership_contact_id']); $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport('Membership')); $membershipType = CRM_Member_DAO_MembershipType::export(); $membershipStatus = CRM_Member_DAO_MembershipStatus::export(); $fields = array_merge($fields, $membershipType, $membershipStatus); return $fields; }
/** * Get the exportable fields for Activities. * * @param string $name * If it is called by case $name = Case else $name = Activity. * * @return array * array of exportable Fields */ public static function &exportableFields($name = 'Activity') { if (!isset(self::$_exportableFields[$name])) { self::$_exportableFields[$name] = array(); // TODO: ideally we should retrieve all fields from xml, in this case since activity processing is done // my case hence we have defined fields as case_* if ($name == 'Activity') { $exportableFields = CRM_Activity_DAO_Activity::export(); $exportableFields['source_contact_id']['title'] = ts('Source Contact ID'); $exportableFields['source_contact'] = array('title' => ts('Source Contact'), 'type' => CRM_Utils_Type::T_STRING); $Activityfields = array('activity_type' => array('title' => ts('Activity Type'), 'name' => 'activity_type', 'type' => CRM_Utils_Type::T_STRING, 'searchByLabel' => TRUE), 'activity_status' => array('title' => ts('Activity Status'), 'name' => 'activity_status', 'type' => CRM_Utils_Type::T_STRING, 'searchByLabel' => TRUE)); $fields = array_merge($Activityfields, $exportableFields); } else { // Set title to activity fields. $fields = array('case_activity_subject' => array('title' => ts('Activity Subject'), 'type' => CRM_Utils_Type::T_STRING), 'case_source_contact_id' => array('title' => ts('Activity Reporter'), 'type' => CRM_Utils_Type::T_STRING), 'case_recent_activity_date' => array('title' => ts('Activity Actual Date'), 'type' => CRM_Utils_Type::T_DATE), 'case_scheduled_activity_date' => array('title' => ts('Activity Scheduled Date'), 'type' => CRM_Utils_Type::T_DATE), 'case_recent_activity_type' => array('title' => ts('Activity Type'), 'type' => CRM_Utils_Type::T_STRING), 'case_activity_status' => array('title' => ts('Activity Status'), 'type' => CRM_Utils_Type::T_STRING), 'case_activity_duration' => array('title' => ts('Activity Duration'), 'type' => CRM_Utils_Type::T_INT), 'case_activity_medium_id' => array('title' => ts('Activity Medium'), 'type' => CRM_Utils_Type::T_INT), 'case_activity_details' => array('title' => ts('Activity Details'), 'type' => CRM_Utils_Type::T_TEXT), 'case_activity_is_auto' => array('title' => ts('Activity Auto-generated?'), 'type' => CRM_Utils_Type::T_BOOLEAN)); } // add custom data for case activities $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport('Activity')); self::$_exportableFields[$name] = $fields; } return self::$_exportableFields[$name]; }
/** * Function to get list of contribution fields for profile * For now we only allow custom contribution fields to be in * profile * * @return return the list of contribution fields * @static * @access public */ static function getContributionFields() { $contributionFields =& CRM_Contribute_DAO_Contribution::export(); require_once 'CRM/Core/OptionValue.php'; $contributionFields = array_merge($contributionFields, CRM_Core_OptionValue::getFields($mode = 'contribute')); require_once 'CRM/Contribute/DAO/ContributionType.php'; $contributionFields = array_merge($contributionFields, CRM_Contribute_DAO_ContributionType::export()); foreach ($contributionFields as $key => $var) { if ($key == 'contribution_contact_id') { continue; } $fields[$key] = $var; } $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport('Contribution')); return $fields; }
/** * If the return Properties are set in a hierarchy, traverse the hierarchy to get * the return values * * @return void * @access public */ function addHierarchicalElements() { if (!CRM_Utils_Array::value('location', $this->_returnProperties)) { return; } if (!is_array($this->_returnProperties['location'])) { return; } $locationTypes = CRM_Core_PseudoConstant::locationType(); $processed = array(); $index = 0; // CRM_Core_Error::debug( 'd', $this->_fields ); // CRM_Core_Error::debug( 'r', $this->_returnProperties ); $addressCustomFields = CRM_Core_BAO_CustomField::getFieldsForImport('Address'); $addressCustomFieldIds = array(); foreach ($this->_returnProperties['location'] as $name => $elements) { $lCond = self::getPrimaryCondition($name); if (!$lCond) { $locationTypeId = array_search($name, $locationTypes); if ($locationTypeId === FALSE) { continue; } $lCond = "location_type_id = {$locationTypeId}"; $this->_useDistinct = TRUE; //commented for CRM-3256 $this->_useGroupBy = TRUE; } $name = str_replace(' ', '_', $name); $tName = "{$name}-location_type"; $ltName = "`{$name}-location_type`"; $this->_select["{$tName}_id"] = "`{$tName}`.id as `{$tName}_id`"; $this->_select["{$tName}"] = "`{$tName}`.name as `{$tName}`"; $this->_element["{$tName}_id"] = 1; $this->_element["{$tName}"] = 1; $locationTypeName = $tName; $locationTypeJoin = array(); $addAddress = FALSE; $addWhereCount = 0; foreach ($elements as $elementFullName => $dontCare) { $index++; $elementName = $elementCmpName = $elementFullName; if (substr($elementCmpName, 0, 5) == 'phone') { $elementCmpName = 'phone'; } if (in_array($elementCmpName, array_keys($addressCustomFields))) { if ($cfID = CRM_Core_BAO_CustomField::getKeyID($elementCmpName)) { $addressCustomFieldIds[$cfID][$name] = 1; } } //add address table only once if ((in_array($elementCmpName, self::$_locationSpecificFields) || !empty($addressCustomFieldIds)) && !$addAddress && !in_array($elementCmpName, array('email', 'phone', 'im', 'openid'))) { $tName = "{$name}-address"; $aName = "`{$name}-address`"; $this->_select["{$tName}_id"] = "`{$tName}`.id as `{$tName}_id`"; $this->_element["{$tName}_id"] = 1; $addressJoin = "\nLEFT JOIN civicrm_address {$aName} ON ({$aName}.contact_id = contact_a.id AND {$aName}.{$lCond})"; $this->_tables[$tName] = $addressJoin; $locationTypeJoin[$tName] = " ( {$aName}.location_type_id = {$ltName}.id ) "; $processed[$aName] = 1; $addAddress = TRUE; } $cond = $elementType = ''; if (strpos($elementName, '-') !== FALSE) { // this is either phone, email or IM list($elementName, $elementType) = explode('-', $elementName); if ($elementName != 'phone' && $elementName != 'im') { $cond = self::getPrimaryCondition($elementType); } if (!$cond && $elementName == 'phone') { $cond = "phone_type_id = '{$elementType}'"; } elseif (!$cond && $elementName == 'im') { // IM service provider id, CRM-3140 $cond = "provider_id = '{$elementType}'"; } $elementType = '-' . $elementType; } $field = CRM_Utils_Array::value($elementName, $this->_fields); // hack for profile, add location id if (!$field) { if ($elementType && !is_numeric($elementType)) { if (is_numeric($name)) { $field = CRM_Utils_Array::value($elementName . "-Primary{$elementType}", $this->_fields); } else { $field = CRM_Utils_Array::value($elementName . "-{$locationTypeId}{$elementType}", $this->_fields); } } elseif (is_numeric($name)) { //this for phone type to work if ($elementName == "phone") { $field = CRM_Utils_Array::value($elementName . "-Primary" . $elementType, $this->_fields); } else { $field = CRM_Utils_Array::value($elementName . "-Primary", $this->_fields); } } else { //this is for phone type to work for profile edit if ($elementName == "phone") { $field = CRM_Utils_Array::value($elementName . "-{$locationTypeId}{$elementType}", $this->_fields); } else { $field = CRM_Utils_Array::value($elementName . "-{$locationTypeId}", $this->_fields); } } } // check if there is a value, if so also add to where Clause $addWhere = FALSE; if ($this->_params) { $nm = $elementName; if (isset($locationTypeId)) { $nm .= "-{$locationTypeId}"; } if (!is_numeric($elementType)) { $nm .= "{$elementType}"; } foreach ($this->_params as $id => $values) { if ($values[0] == $nm || in_array($elementName, array('phone', 'im')) && strpos($values[0], $nm) !== FALSE) { $addWhere = TRUE; $addWhereCount++; break; } } } if ($field && isset($field['where'])) { list($tableName, $fieldName) = explode('.', $field['where'], 2); $tName = $name . '-' . substr($tableName, 8) . $elementType; $fieldName = $fieldName; if (isset($tableName)) { $this->_select["{$tName}_id"] = "`{$tName}`.id as `{$tName}_id`"; $this->_element["{$tName}_id"] = 1; if (substr($tName, -15) == '-state_province') { // FIXME: hack to fix CRM-1900 $a = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_format'); if (substr_count($a, 'state_province_name') > 0) { $this->_select["{$name}-{$elementFullName}"] = "`{$tName}`.name as `{$name}-{$elementFullName}`"; } else { $this->_select["{$name}-{$elementFullName}"] = "`{$tName}`.abbreviation as `{$name}-{$elementFullName}`"; } } else { if (substr($elementFullName, 0, 2) == 'im') { $provider = "{$name}-{$elementFullName}-provider_id"; $this->_select[$provider] = "`{$tName}`.provider_id as `{$name}-{$elementFullName}-provider_id`"; $this->_element[$provider] = 1; } $this->_select["{$name}-{$elementFullName}"] = "`{$tName}`.{$fieldName} as `{$name}-{$elementFullName}`"; } $this->_element["{$name}-{$elementFullName}"] = 1; if (!CRM_Utils_Array::value("`{$tName}`", $processed)) { $processed["`{$tName}`"] = 1; $newName = $tableName . '_' . $index; switch ($tableName) { case 'civicrm_phone': case 'civicrm_email': case 'civicrm_im': case 'civicrm_openid': $this->_tables[$tName] = "\nLEFT JOIN {$tableName} `{$tName}` ON contact_a.id = `{$tName}`.contact_id AND `{$tName}`.{$lCond}"; // this special case to add phone type if ($cond) { $phoneTypeCondition = " AND `{$tName}`.{$cond} "; //gross hack to pickup corrupted data also, CRM-7603 if (strpos($cond, 'phone_type_id') !== FALSE) { $phoneTypeCondition = " AND ( `{$tName}`.{$cond} OR `{$tName}`.phone_type_id IS NULL ) "; } $this->_tables[$tName] .= $phoneTypeCondition; } //build locationType join $locationTypeJoin[$tName] = " ( `{$tName}`.location_type_id = {$ltName}.id )"; if ($addWhere) { $this->_whereTables[$tName] = $this->_tables[$tName]; } break; case 'civicrm_state_province': $this->_tables[$tName] = "\nLEFT JOIN {$tableName} `{$tName}` ON `{$tName}`.id = {$aName}.state_province_id"; if ($addWhere) { $this->_whereTables["{$name}-address"] = $addressJoin; $this->_whereTables[$tName] = $this->_tables[$tName]; } break; case 'civicrm_country': $this->_tables[$newName] = "\nLEFT JOIN {$tableName} `{$tName}` ON `{$tName}`.id = {$aName}.country_id"; if ($addWhere) { $this->_whereTables["{$name}-address"] = $addressJoin; $this->_whereTables[$newName] = $this->_tables[$newName]; } break; case 'civicrm_county': $this->_tables[$newName] = "\nLEFT JOIN {$tableName} `{$tName}` ON `{$tName}`.id = {$aName}.county_id"; if ($addWhere) { $this->_whereTables["{$name}-address"] = $addressJoin; $this->_whereTables[$newName] = $this->_tables[$newName]; } break; default: if ($addWhere) { $this->_whereTables["{$name}-address"] = $addressJoin; } break; } } } } } // add location type join $ltypeJoin = "\nLEFT JOIN civicrm_location_type {$ltName} ON ( " . implode('OR', $locationTypeJoin) . " )"; $this->_tables[$locationTypeName] = $ltypeJoin; // table should be present in $this->_whereTables, // to add its condition in location type join, CRM-3939. if ($addWhereCount) { $locClause = array(); foreach ($this->_whereTables as $tableName => $clause) { if (CRM_Utils_Array::value($tableName, $locationTypeJoin)) { $locClause[] = $locationTypeJoin[$tableName]; } } if (!empty($locClause)) { $this->_whereTables[$locationTypeName] = "\nLEFT JOIN civicrm_location_type {$ltName} ON ( " . implode('OR', $locClause) . " )"; } } } if (!empty($addressCustomFieldIds)) { $cfIDs = $addressCustomFieldIds; $customQuery = new CRM_Core_BAO_CustomQuery($cfIDs); foreach ($addressCustomFieldIds as $cfID => $locTypeName) { foreach ($locTypeName as $name => $dnc) { $fieldName = "{$name}-custom_{$cfID}"; $tName = "{$name}-address-custom-{$cfID}"; $aName = "`{$name}-address-custom-{$cfID}`"; $this->_select["{$tName}_id"] = "`{$tName}`.id as `{$tName}_id`"; $this->_element["{$tName}_id"] = 1; $this->_select[$fieldName] = "`{$tName}`.{$customQuery->_fields[$cfID]['column_name']} as `{$fieldName}`"; $this->_element[$fieldName] = 1; $this->_tables[$tName] = "\nLEFT JOIN {$customQuery->_fields[$cfID]['table_name']} {$aName} ON ({$aName}.entity_id = `{$name}-address`.id)"; } } } }
/** * Get list of contribution fields for profile. * For now we only allow custom contribution fields to be in * profile * * @param bool $addExtraFields * True if special fields needs to be added. * * @return array * the list of contribution fields */ public static function getContributionFields($addExtraFields = TRUE) { $contributionFields = CRM_Contribute_DAO_Contribution::export(); $contributionFields = array_merge($contributionFields, CRM_Core_OptionValue::getFields($mode = 'contribute')); if ($addExtraFields) { $contributionFields = array_merge($contributionFields, self::getSpecialContributionFields()); } $contributionFields = array_merge($contributionFields, CRM_Financial_DAO_FinancialType::export()); foreach ($contributionFields as $key => $var) { if ($key == 'contribution_contact_id') { continue; } elseif ($key == 'contribution_campaign_id') { $var['title'] = ts('Campaign'); } $fields[$key] = $var; } $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport('Contribution')); return $fields; }
/** * combine all the exportable fields from the lower levels object * * @return array array of exportable Fields * @access public */ function &exportableFields() { if (!self::$_exportableFields) { if (!self::$_exportableFields) { self::$_exportableFields = array(); } $fields = array(); require_once 'CRM/Core/DAO/Note.php'; $participantFields = CRM_Event_DAO_Participant::export(); $noteField = array('participant_note' => array('title' => 'Participant Note', 'name' => 'participant_note')); $participantStatus = array('participant_status' => array('title' => 'Participant Status', 'name' => 'participant_status')); $participantRole = array('participant_role' => array('title' => 'Participant Role', 'name' => 'participant_role')); require_once 'CRM/Core/DAO/Discount.php'; $discountFields = CRM_Core_DAO_Discount::export(); $fields = array_merge($participantFields, $participantStatus, $participantRole, $noteField, $discountFields); // add custom data $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport('Participant')); self::$_exportableFields = $fields; } return self::$_exportableFields; }
static function defaultReturnProperties($mode) { $properties = null; if ($mode & CRM_Contact_BAO_Query::MODE_CONTRIBUTE) { $properties = array('contact_type' => 1, 'contact_sub_type' => 1, 'sort_name' => 1, 'display_name' => 1, 'contribution_type' => 1, 'contribution_source' => 1, 'receive_date' => 1, 'thankyou_date' => 1, 'cancel_date' => 1, 'total_amount' => 1, 'accounting_code' => 1, 'payment_instrument' => 1, 'check_number' => 1, 'non_deductible_amount' => 1, 'fee_amount' => 1, 'net_amount' => 1, 'trxn_id' => 1, 'invoice_id' => 1, 'currency' => 1, 'cancel_date' => 1, 'cancel_reason' => 1, 'receipt_date' => 1, 'thankyou_date' => 1, 'product_name' => 1, 'sku' => 1, 'product_option' => 1, 'fulfilled_date' => 1, 'contribution_start_date' => 1, 'contribution_end_date' => 1, 'is_test' => 1, 'is_pay_later' => 1, 'contribution_status_id' => 1, 'contribution_recur_id' => 1, 'amount_level' => 1, 'contribution_note' => 1); // also get all the custom contribution properties require_once "CRM/Core/BAO/CustomField.php"; $fields = CRM_Core_BAO_CustomField::getFieldsForImport('Contribution'); if (!empty($fields)) { foreach ($fields as $name => $dontCare) { $properties[$name] = 1; } } } return $properties; }
/** * Function to set profile defaults * * @params int $contactId contact id * @params array $fields associative array of fields * @params array $defaults defaults array * @params boolean $singleProfile true for single profile else false(batch update) * @params int $componentId id for specific components like contribute, event etc * * @return null * @static * @access public */ static function setProfileDefaults($contactId, &$fields, &$defaults, $singleProfile = true, $componentId = null, $component = null) { if (!$componentId) { //get the contact details require_once 'CRM/Contact/BAO/Contact.php'; list($contactDetails, $options) = CRM_Contact_BAO_Contact::getHierContactDetails($contactId, $fields); $details = $contactDetails[$contactId]; require_once 'CRM/Contact/Form/Edit/TagsAndGroups.php'; //start of code to set the default values foreach ($fields as $name => $field) { //set the field name depending upon the profile mode(single/batch) if ($singleProfile) { $fldName = $name; } else { $fldName = "field[{$contactId}][{$name}]"; } if ($name == 'group') { CRM_Contact_Form_Edit_TagsAndGroups::setDefaults($contactId, $defaults, CRM_Contact_Form_Edit_TagsAndGroups::GROUP, $fldName); } if ($name == 'tag') { CRM_Contact_Form_Edit_TagsAndGroups::setDefaults($contactId, $defaults, CRM_Contact_Form_Edit_TagsAndGroups::TAG, $fldName); } if (CRM_Utils_Array::value($name, $details) || isset($details[$name])) { //to handle custom data (checkbox) to be written // to handle gender / suffix / prefix / greeting_type if ($name == 'gender') { $defaults[$fldName] = $details['gender_id']; } else { if ($name == 'individual_prefix') { $defaults[$fldName] = $details['individual_prefix_id']; } else { if ($name == 'individual_suffix') { $defaults[$fldName] = $details['individual_suffix_id']; } else { if ($name == 'birth_date' || $name == 'deceased_date') { list($defaults[$fldName]) = CRM_Utils_Date::setDateDefaults($details[$name], 'birth'); } else { if ($name == 'email_greeting') { $defaults[$fldName] = $details['email_greeting_id']; $defaults['email_greeting_custom'] = $details['email_greeting_custom']; } else { if ($name == 'postal_greeting') { $defaults[$fldName] = $details['postal_greeting_id']; $defaults['postal_greeting_custom'] = $details['postal_greeting_custom']; } else { if ($name == 'addressee') { $defaults[$fldName] = $details['addressee_id']; $defaults['addressee_custom'] = $details['addressee_custom']; } else { if ($name == 'preferred_communication_method') { $v = explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $details[$name]); foreach ($v as $item) { if ($item) { $defaults[$fldName . "[{$item}]"] = 1; } } } else { if ($name == 'world_region') { $defaults[$fldName] = $details['worldregion_id']; } else { if ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($name)) { //fix for custom fields $customFields = CRM_Core_BAO_CustomField::getFields(CRM_Utils_Array::value('Individual', $values)); // hack to add custom data for components $components = array("Contribution", "Participant", "Membership"); foreach ($components as $value) { $customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFieldsForImport($value)); } switch ($customFields[$customFieldId]['html_type']) { case 'Multi-Select State/Province': case 'Multi-Select Country': case 'AdvMulti-Select': case 'Multi-Select': $v = explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $details[$name]); foreach ($v as $item) { if ($item) { $defaults[$fldName][$item] = $item; } } break; case 'CheckBox': $v = explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $details[$name]); foreach ($v as $item) { if ($item) { $defaults[$fldName][$item] = 1; // seems like we need this for QF style checkboxes in profile where its multiindexed // CRM-2969 $defaults["{$fldName}[{$item}]"] = 1; } } break; case 'Autocomplete-Select': if ($customFields[$customFieldId]['data_type'] == "ContactReference") { require_once 'CRM/Contact/BAO/Contact.php'; if (is_numeric($details[$name])) { $defaults[$fldName . '_id'] = $details[$name]; $defaults[$fldName] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $details[$name], 'sort_name'); } } else { $label = CRM_Core_BAO_CustomOption::getOptionLabel($customFieldId, $details[$name]); $defaults[$fldName . '_id'] = $details[$name]; $defaults[$fldName] = $label; } break; case 'Select Date': list($defaults[$fldName], $defaults[substr($fldName, 0, -1) . '_time]']) = CRM_Utils_Date::setDateDefaults($details[$name]); break; default: $defaults[$fldName] = $details[$name]; break; } } else { $defaults[$fldName] = $details[$name]; } } } } } } } } } } } else { list($fieldName, $locTypeId, $phoneTypeId) = CRM_Utils_System::explode('-', $name, 3); if (is_array($details)) { foreach ($details as $key => $value) { // when we fixed CRM-5319 - get primary loc // type as per loc field and removed below code. if ($locTypeId == 'Primary') { $locTypeId = CRM_Contact_BAO_Contact::getPrimaryLocationType($contactId); } if (is_numeric($locTypeId)) { //fixed for CRM-665 if ($locTypeId == CRM_Utils_Array::value('location_type_id', $value)) { if (CRM_Utils_Array::value($fieldName, $value)) { //to handle stateprovince and country if ($fieldName == 'state_province') { $defaults[$fldName] = $value['state_province_id']; } else { if ($fieldName == 'county') { $defaults[$fldName] = $value['county_id']; } else { if ($fieldName == 'country') { $defaults[$fldName] = $value['country_id']; if (!isset($value['country_id']) || !$value['country_id']) { $config =& CRM_Core_Config::singleton(); if ($config->defaultContactCountry) { $defaults[$fldName] = $config->defaultContactCountry; } } } else { if ($fieldName == 'phone') { if ($phoneTypeId) { if ($value['phone'][$phoneTypeId]) { $defaults[$fldName] = $value['phone'][$phoneTypeId]; } } else { $defaults[$fldName] = $value['phone']; } } else { if ($fieldName == 'email') { //adding the first email (currently we don't support multiple emails of same location type) $defaults[$fldName] = $value['email']; } else { if ($fieldName == 'im') { //adding the first im (currently we don't support multiple ims of same location type) $defaults[$fldName] = $value['im']; $defaults[$fldName . "-provider_id"] = $value['im_provider_id']; } else { $defaults[$fldName] = $value[$fieldName]; } } } } } } } } } } } } } if (CRM_Core_Permission::access('Quest', false)) { require_once 'CRM/Quest/BAO/Student.php'; // Checking whether the database contains quest_student table. // Now there are two different schemas for core and quest. // So if only core schema in use then withought following check gets the DB error. $student = new CRM_Quest_BAO_Student(); $tableStudent = $student->getTableName(); if ($tableStudent) { //set student defaults CRM_Quest_BAO_Student::retrieve($details, $studentDefaults, $ids); $studentFields = array('educational_interest', 'college_type', 'college_interest', 'test_tutoring'); foreach ($studentFields as $fld) { if ($studentDefaults[$fld]) { $values = explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $studentDefaults[$fld]); } $studentDefaults[$fld] = array(); if (is_array($values)) { foreach ($values as $v) { $studentDefaults[$fld][$v] = 1; } } } foreach ($fields as $name => $field) { $fldName = "field[{$contactId}][{$name}]"; if (array_key_exists($name, $studentDefaults)) { $defaults[$fldName] = $studentDefaults[$name]; } } } } } //Handling Contribution Part of the batch profile if (CRM_Core_Permission::access('CiviContribute') && $component == 'Contribute') { self::setComponentDefaults($fields, $componentId, $component, $defaults); } //Handling Event Participation Part of the batch profile if (CRM_Core_Permission::access('CiviEvent') && $component == 'Event') { self::setComponentDefaults($fields, $componentId, $component, $defaults); } //Handling membership Part of the batch profile if (CRM_Core_Permission::access('CiviMember') && $component == 'Membership') { self::setComponentDefaults($fields, $componentId, $component, $defaults); } }
/** * default set of return properties * * @return void * @access public */ function &defaultReturnProperties($mode = 1) { if (!isset($GLOBALS['_CRM_CONTACT_BAO_QUERY']['_defaultReturnProperties'])) { $GLOBALS['_CRM_CONTACT_BAO_QUERY']['_defaultReturnProperties'] = array(); if ($mode & CRM_CONTACT_BAO_QUERY_MODE_CONTACTS) { $properties = array('home_URL' => 1, 'image_URL' => 1, 'legal_identifier' => 1, 'external_identifier' => 1, 'contact_type' => 1, 'sort_name' => 1, 'display_name' => 1, 'nick_name' => 1, 'first_name' => 1, 'middle_name' => 1, 'last_name' => 1, 'prefix' => 1, 'suffix' => 1, 'birth_date' => 1, 'gender' => 1, 'street_address' => 1, 'supplemental_address_1' => 1, 'supplemental_address_2' => 1, 'city' => 1, 'postal_code' => 1, 'postal_code_suffix' => 1, 'state_province' => 1, 'country' => 1, 'geo_code_1' => 1, 'geo_code_2' => 1, 'email' => 1, 'phone' => 1, 'im' => 1); $GLOBALS['_CRM_CONTACT_BAO_QUERY']['_defaultReturnProperties'] = array_merge($GLOBALS['_CRM_CONTACT_BAO_QUERY']['_defaultReturnProperties'], $properties); } if ($mode & CRM_CONTACT_BAO_QUERY_MODE_CONTRIBUTE) { $properties = array('contact_type' => 1, 'sort_name' => 1, 'display_name' => 1, 'contribution_type' => 1, 'source' => 1, 'receive_date' => 1, 'thankyou_date' => 1, 'cancel_date' => 1, 'total_amount' => 1, 'accounting_code' => 1, 'payment_instrument' => 1, 'non_deductible_amount' => 1, 'fee_amount' => 1, 'net_amount' => 1, 'trxn_id' => 1, 'invoice_id' => 1, 'currency' => 1, 'cancel_date' => 1, 'cancel_reason' => 1, 'receipt_date' => 1, 'thankyou_date' => 1, 'source' => 1, 'name' => 1, 'sku' => 1, 'product_option' => 1, 'fulfilled_date' => 1, 'start_date' => 1, 'end_date' => 1); // also get all the custom contribution properties $fields = CRM_Core_BAO_CustomField::getFieldsForImport('Contribution'); if (!empty($fields)) { foreach ($fields as $name => $dontCare) { $properties[$name] = 1; } } $GLOBALS['_CRM_CONTACT_BAO_QUERY']['_defaultReturnProperties'] = array_merge($GLOBALS['_CRM_CONTACT_BAO_QUERY']['_defaultReturnProperties'], $properties); } } return $GLOBALS['_CRM_CONTACT_BAO_QUERY']['_defaultReturnProperties']; }
/** * Function to actually build the form * * @return void * @access public */ public function buildQuickForm() { if ($this->_action & CRM_Core_Action::DELETE) { $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete Profile Field'), 'spacing' => ' ', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel')))); return; } if (isset($this->_id)) { $params = array('id' => $this->_id); CRM_Core_BAO_UFField::retrieve($params, $defaults); // set it to null if so (avoids crappy E_NOTICE errors below $defaults['location_type_id'] = CRM_Utils_Array::value('location_type_id', $defaults); $specialFields = array('street_address', 'supplemental_address_1', 'supplemental_address_2', 'city', 'postal_code', 'postal_code_suffix', 'geo_code_1', 'geo_code_2', 'state_province', 'country', 'county', 'phone', 'email', 'im', 'address_name'); if (!$defaults['location_type_id'] && in_array($defaults['field_name'], $specialFields)) { $defaults['location_type_id'] = 0; } $defaults['field_name'] = array($defaults['field_type'], $defaults['field_name'], $defaults['location_type_id'], CRM_Utils_Array::value('phone_type_id', $defaults)); $this->_gid = $defaults['uf_group_id']; } else { $defaults['is_active'] = 1; } if ($this->_action & CRM_Core_Action::ADD) { $fieldValues = array('uf_group_id' => $this->_gid); $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_UFField', $fieldValues); } // lets trim all the whitespace $this->applyFilter('__ALL__', 'trim'); //hidden field to catch the group id in profile $this->add('hidden', 'group_id', $this->_gid); //hidden field to catch the field id in profile $this->add('hidden', 'field_id', $this->_id); $fields = array(); $fields['Individual'] =& CRM_Contact_BAO_Contact::importableFields('Individual', false, false, true); $fields['Household'] =& CRM_Contact_BAO_Contact::importableFields('Household', false, false, true); $fields['Organization'] =& CRM_Contact_BAO_Contact::importableFields('Organization', false, false, true); // add current employer for individuals $fields['Individual']['current_employer'] = array('name' => 'organization_name', 'title' => ts('Current Employer')); // unset unwanted fields $unsetFieldArray = array('note', 'email_greeting_custom', 'postal_greeting_custom', 'addressee_custom', 'id'); foreach ($unsetFieldArray as $value) { unset($fields['Individual'][$value]); unset($fields['Household'][$value]); unset($fields['Organization'][$value]); } require_once 'CRM/Core/BAO/Preferences.php'; $addressOptions = CRM_Core_BAO_Preferences::valueOptions('address_options', true, null, true); if (!$addressOptions['county']) { unset($fields['Individual']['county']); unset($fields['Household']['county']); unset($fields['Organization']['county']); } //build the common contact fields array CRM-3037. foreach ($fields['Individual'] as $key => $value) { if (CRM_Utils_Array::value($key, $fields['Household']) && CRM_Utils_Array::value($key, $fields['Organization'])) { $fields['Contact'][$key] = $value; //as we move common fields to contacts. There fore these fields //are unset from resoective array's. unset($fields['Individual'][$key]); unset($fields['Household'][$key]); unset($fields['Organization'][$key]); } } // add current employer for individuals $fields['Contact']['id'] = array('name' => 'id', 'title' => ts('Internal Contact ID')); unset($fields['Contact']['contact_type']); // since we need a hierarchical list to display contact types & subtypes, // this is what we going to display in first selector $contactTypes = CRM_Contact_BAO_ContactType::getSelectElements(false, false); unset($contactTypes['']); // 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); if (array_key_exists($val['parent'], $fields)) { $fields[$name] = $fields[$val['parent']] + $subTypeFields; } else { $fields[$name] = $subTypeFields; } } unset($subTypes); if (CRM_Core_Permission::access('Quest')) { require_once 'CRM/Quest/BAO/Student.php'; $fields['Student'] =& CRM_Quest_BAO_Student::exportableFields(); } if (CRM_Core_Permission::access('CiviContribute')) { $contribFields =& CRM_Contribute_BAO_Contribution::getContributionFields(); if (!empty($contribFields)) { unset($contribFields['is_test']); unset($contribFields['is_pay_later']); unset($contribFields['contribution_id']); $fields['Contribution'] =& $contribFields; } } if (CRM_Core_Permission::access('CiviEvent')) { require_once 'CRM/Event/BAO/Query.php'; $participantFields =& CRM_Event_BAO_Query::getParticipantFields(true); if (!empty($participantFields)) { unset($participantFields['external_identifier']); unset($participantFields['event_id']); unset($participantFields['participant_contact_id']); unset($participantFields['participant_is_test']); unset($participantFields['participant_fee_level']); unset($participantFields['participant_id']); unset($participantFields['participant_is_pay_later']); $fields['Participant'] =& $participantFields; } } if (CRM_Core_Permission::access('CiviMember')) { require_once 'CRM/Member/BAO/Membership.php'; $membershipFields =& CRM_Member_BAO_Membership::getMembershipFields(); unset($membershipFields['membership_id']); unset($membershipFields['join_date']); unset($membershipFields['membership_start_date']); unset($membershipFields['membership_type_id']); unset($membershipFields['membership_end_date']); unset($membershipFields['member_is_test']); unset($membershipFields['is_override']); unset($membershipFields['status_id']); unset($membershipFields['member_is_pay_later']); $fields['Membership'] =& $membershipFields; } $noSearchable = array(); foreach ($fields as $key => $value) { foreach ($value as $key1 => $value1) { //CRM-2676, replacing the conflict for same custom field name from different custom group. require_once 'CRM/Core/BAO/CustomField.php'; if ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($key1)) { $customGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $customFieldId, 'custom_group_id'); $customGroupName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $customGroupId, 'title'); $this->_mapperFields[$key][$key1] = $value1['title'] . ' :: ' . $customGroupName; } else { $this->_mapperFields[$key][$key1] = $value1['title']; } $hasLocationTypes[$key][$key1] = CRM_Utils_Array::value('hasLocationType', $value1); // hide the 'is searchable' field for 'File' custom data if (isset($value1['data_type']) && isset($value1['html_type']) && ($value1['data_type'] == 'File' && $value1['html_type'] == 'File' || $value1['data_type'] == 'Link' && $value1['html_type'] == 'Link')) { if (!in_array($value1['title'], $noSearchable)) { $noSearchable[] = $value1['title']; } } } } $this->assign('noSearchable', $noSearchable); require_once 'CRM/Core/BAO/LocationType.php'; $this->_location_types =& CRM_Core_PseudoConstant::locationType(); $defaultLocationType =& CRM_Core_BAO_LocationType::getDefault(); /* FIXME: dirty hack to make the default option show up first. This * avoids a mozilla browser bug with defaults on dynamically constructed * selector widgets. */ if ($defaultLocationType) { $defaultLocation = $this->_location_types[$defaultLocationType->id]; unset($this->_location_types[$defaultLocationType->id]); $this->_location_types = array($defaultLocationType->id => $defaultLocation) + $this->_location_types; } $this->_location_types = array('Primary') + $this->_location_types; $contactTypes = !empty($contactTypes) ? array('Contact' => 'Contacts') + $contactTypes : array(); $sel1 = array('' => '- select -') + $contactTypes; if (CRM_Core_Permission::access('Quest')) { $sel1['Student'] = 'Students'; } if (CRM_Core_Permission::access('CiviEvent')) { $sel1['Participant'] = 'Participants'; } if (!empty($contribFields)) { $sel1['Contribution'] = 'Contributions'; } if (!empty($membershipFields)) { $sel1['Membership'] = 'Membership'; } foreach ($sel1 as $key => $sel) { if ($key) { $sel2[$key] = $this->_mapperFields[$key]; } } $sel3[''] = null; $phoneTypes = CRM_Core_PseudoConstant::phoneType(); ksort($phoneTypes); foreach ($sel1 as $k => $sel) { if ($k) { foreach ($this->_location_types as $key => $value) { $sel4[$k]['phone'][$key] =& $phoneTypes; } } } foreach ($sel1 as $k => $sel) { if ($k) { if (is_array($this->_mapperFields[$k])) { foreach ($this->_mapperFields[$k] as $key => $value) { if ($hasLocationTypes[$k][$key]) { $sel3[$k][$key] = $this->_location_types; } else { $sel3[$key] = null; } } } } } $this->_defaults = array(); $js = "<script type='text/javascript'>\n"; $formName = "document.{$this->_name}"; $alreadyMixProfile = false; if (CRM_Core_BAO_UFField::checkProfileType($this->_gid)) { $alreadyMixProfile = true; } $this->assign('alreadyMixProfile', $alreadyMixProfile); $attributes = array('onclick' => "showLabel();mixProfile();", 'onblur' => 'showLabel();mixProfile();'); $sel =& $this->addElement('hierselect', "field_name", ts('Field Name'), $attributes); $formValues = array(); $formValues = $this->exportValues(); if (empty($formValues)) { for ($k = 1; $k < 4; $k++) { if (!$defaults['field_name'][$k]) { $js .= "{$formName}['field_name[{$k}]'].style.display = 'none';\n"; } } } else { if (!empty($formValues['field_name'])) { foreach ($formValues['field_name'] as $value) { for ($k = 1; $k < 4; $k++) { if (!isset($formValues['field_name'][$k]) || !$formValues['field_name'][$k]) { $js .= "{$formName}['field_name[{$k}]'].style.display = 'none';\n"; } else { $js .= "{$formName}['field_name[{$k}]'].style.display = '';\n"; } } } } else { for ($k = 1; $k < 4; $k++) { if (!isset($defaults['field_name'][$k])) { $js .= "{$formName}['field_name[{$k}]'].style.display = 'none';\n"; } } } } foreach ($sel2 as $k => $v) { if (is_array($sel2[$k])) { asort($sel2[$k]); } } $sel->setOptions(array($sel1, $sel2, $sel3, $sel4)); $js .= "</script>\n"; $this->assign('initHideBoxes', $js); $this->add('select', 'visibility', ts('Visibility'), CRM_Core_SelectValues::ufVisibility(), true, array("onChange" => "showHideSeletorSearch(this.value);")); //CRM-4363 $js = array('onclick' => "mixProfile();"); // should the field appear in selectors (as a column)? $this->add('checkbox', 'in_selector', ts('Results Column?'), null, null, $js); $this->add('checkbox', 'is_searchable', ts('Searchable?'), null, null, $js); // weight $this->add('text', 'weight', ts('Order'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField', 'weight'), true); $this->addRule('weight', ts('is a numeric field'), 'numeric'); $this->add('textarea', 'help_post', ts('Field Help'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField', 'help_post')); // listings title $this->add('text', 'listings_title', ts('Listings Title'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField', 'listings_title')); $this->addRule('listings_title', ts('Please enter a valid title for this field when displayed in user listings.'), 'title'); $this->add('checkbox', 'is_required', ts('Required?')); $this->add('checkbox', 'is_active', ts('Active?')); $this->add('checkbox', 'is_view', ts('View Only?')); // $this->add( 'checkbox', 'is_registration', ts( 'Display in Registration Form?' ) ); //$this->add( 'checkbox', 'is_match' , ts( 'Key to Match Contacts?' ) ); $this->add('text', 'label', ts('Field Label'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_UFField', 'label')); $js = null; if ($this->_hasSearchableORInSelector) { $js = array('onclick' => "return verify( );"); } // add buttons $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'isDefault' => true, 'js' => $js), array('type' => 'next', 'name' => ts('Save and New'), 'subName' => 'new', 'js' => $js), array('type' => 'cancel', 'name' => ts('Cancel')))); $this->addFormRule(array('CRM_UF_Form_Field', 'formRule'), $this); // if view mode pls freeze it with the done button. if ($this->_action & CRM_Core_Action::VIEW) { $this->freeze(); $this->addElement('button', 'done', ts('Done'), array('onclick' => "location.href='civicrm/admin/uf/group/field?reset=1&action=browse&gid=" . $this->_gid . "'")); } $this->setDefaults($defaults); }
/** * extracts the parameters from the request and constructs information for * the selector object to do a query * * @return void * @access public * */ function preProcess() { $this->_search = true; $search = CRM_Utils_Request::retrieve('search', 'Boolean', $this, false, 0, 'GET'); if (isset($search) && $search == 0) { $this->_search = false; } $this->_gid = $this->get('gid'); $this->_profileIds = $this->get('profileIds'); $gids = explode(',', CRM_Utils_Request::retrieve('gid', 'String', CRM_Core_DAO::$_nullObject, false, 0, 'GET')); if (count($gids) > 1 && !$this->_profileIds && empty($this->_profileIds)) { if (!empty($gids)) { foreach ($gids as $pfId) { $this->_profileIds[] = CRM_Utils_Type::escape($pfId, 'Positive'); } } // check if we are rendering mixed profiles require_once 'CRM/Core/BAO/UFGroup.php'; if (CRM_Core_BAO_UFGroup::checkForMixProfiles($this->_profileIds)) { CRM_Core_Error::fatal(ts('You cannot combine profiles of multiple types.')); } $this->_gid = $this->_profileIds[0]; $this->set('profileIds', $this->_profileIds); $this->set('gid', $this->_gid); } if (!$this->_gid) { $this->_gid = CRM_Utils_Request::retrieve('gid', 'Positive', $this, false, 0, 'GET'); } require_once 'CRM/Core/BAO/UFGroup.php'; if (empty($this->_profileIds)) { $gids = $this->_gid; } else { $gids = $this->_profileIds; } $this->_fields = CRM_Core_BAO_UFGroup::getListingFields(CRM_Core_Action::UPDATE, CRM_Core_BAO_UFGroup::PUBLIC_VISIBILITY | CRM_Core_BAO_UFGroup::LISTINGS_VISIBILITY, false, $gids, false, 'Profile', CRM_Core_Permission::SEARCH); $this->_customFields = CRM_Core_BAO_CustomField::getFieldsForImport(null); $this->_params = array(); $resetArray = array('group', 'tag', 'preferred_communication_method', 'do_not_phone', 'do_not_email', 'do_not_mail', 'do_not_sms', 'do_not_trade', 'gender'); foreach ($this->_fields as $name => $field) { if (substr($name, 0, 6) == 'custom' && CRM_Utils_Array::value('is_search_range', $field)) { $from = CRM_Utils_Request::retrieve($name . '_from', 'String', $this, false, null, 'REQUEST'); $to = CRM_Utils_Request::retrieve($name . '_to', 'String', $this, false, null, 'REQUEST'); $value = array(); if ($from && $to) { $value['from'] = $from; $value['to'] = $to; } else { if ($from) { $value['from'] = $from; } else { if ($to) { $value['to'] = $to; } } } } else { if (substr($name, 0, 7) == 'custom_' && CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', substr($name, 7), 'html_type') == 'TextArea') { $value = trim(CRM_Utils_Request::retrieve($name, 'String', $this, false, null, 'REQUEST')); if (!empty($value) && !(substr($value, 0, 1) == '%' && substr($value, -1, 1) == '%')) { $value = '%' . $value . '%'; } } else { if (CRM_Utils_Array::value('html_type', $field) == 'Multi-Select State/Province' || CRM_Utils_Array::value('html_type', $field) == 'Multi-Select Country') { $value = CRM_Utils_Request::retrieve($name, 'String', $this, false, null, 'REQUEST'); if (!is_array($value)) { $value = explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, substr($value, 1, -1)); } } else { $value = CRM_Utils_Request::retrieve($name, 'String', $this, false, null, 'REQUEST'); } } } if (($name == 'group' || $name == 'tag') && !empty($value) && !is_array($value)) { $v = explode(',', $value); $value = array(); foreach ($v as $item) { $value[$item] = 1; } } $customField = CRM_Utils_Array::value($name, $this->_customFields); if (!empty($_POST) && !CRM_Utils_Array::value($name, $_POST)) { if ($customField) { // reset checkbox/radio because a form does not send null checkbox values if (in_array($customField['html_type'], array('Multi-Select', 'CheckBox', 'Multi-Select State/Province', 'Multi-Select Country', 'Radio'))) { // only reset on a POST submission if we dont see any value $value = null; $this->set($name, $value); } } else { if (in_array($name, $resetArray)) { $value = null; $this->set($name, $value); } } } if (isset($value) && $value != null) { if (!is_array($value)) { $value = trim($value); } $this->_params[$name] = $this->_fields[$name]['value'] = $value; } } // set the prox params // need to ensure proximity searching is enabled $proximityVars = array('street_address', 'city', 'postal_code', 'state_province_id', 'country_id', 'distance', 'distance_unit'); foreach ($proximityVars as $var) { $value = CRM_Utils_Request::retrieve("prox_{$var}", 'String', $this, false, null, 'REQUEST'); if ($value) { $this->_params["prox_{$var}"] = $value; } } // set the params in session $session = CRM_Core_Session::singleton(); $session->set('profileParams', $this->_params); }
/** * @param $mode * @param bool $includeCustomFields * * @return array|null */ public static function defaultReturnProperties($mode, $includeCustomFields = TRUE) { $properties = NULL; if ($mode & CRM_Contact_BAO_Query::MODE_ACTIVITY) { $properties = array('activity_id' => 1, 'contact_type' => 1, 'contact_sub_type' => 1, 'sort_name' => 1, 'display_name' => 1, 'activity_type' => 1, 'activity_type_id' => 1, 'activity_subject' => 1, 'activity_date_time' => 1, 'activity_duration' => 1, 'activity_location' => 1, 'activity_details' => 1, 'activity_status' => 1, 'source_contact' => 1, 'source_record_id' => 1, 'activity_is_test' => 1, 'activity_campaign_id' => 1, 'result' => 1, 'activity_engagement_level' => 1, 'parent_id' => 1); if ($includeCustomFields) { // also get all the custom activity properties $fields = CRM_Core_BAO_CustomField::getFieldsForImport('Activity'); if (!empty($fields)) { foreach ($fields as $name => $dontCare) { $properties[$name] = 1; } } } } return $properties; }
/** * Build the form object. */ public function buildQuickForm() { //to save the current mappings if (!$this->get('savedMapping')) { $saveDetailsName = ts('Save this field mapping'); $this->applyFilter('saveMappingName', 'trim'); $this->add('text', 'saveMappingName', ts('Name')); $this->add('text', 'saveMappingDesc', ts('Description')); } else { $savedMapping = $this->get('savedMapping'); list($mappingName, $mappingContactType, $mappingLocation, $mappingPhoneType, $mappingImProvider, $mappingRelation, $mappingOperator, $mappingValue, $mappingWebsiteType) = CRM_Core_BAO_Mapping::getMappingFields($savedMapping); //get loaded Mapping Fields $mappingName = CRM_Utils_Array::value(1, $mappingName); $mappingContactType = CRM_Utils_Array::value(1, $mappingContactType); $mappingLocation = CRM_Utils_Array::value(1, $mappingLocation); $mappingPhoneType = CRM_Utils_Array::value(1, $mappingPhoneType); $mappingImProvider = CRM_Utils_Array::value(1, $mappingImProvider); $mappingRelation = CRM_Utils_Array::value(1, $mappingRelation); $mappingWebsiteType = CRM_Utils_Array::value(1, $mappingWebsiteType); $this->assign('loadedMapping', $savedMapping); $this->set('loadedMapping', $savedMapping); $params = array('id' => $savedMapping); $temp = array(); $mappingDetails = CRM_Core_BAO_Mapping::retrieve($params, $temp); $this->assign('savedName', $mappingDetails->name); $this->add('hidden', 'mappingId', $savedMapping); $this->addElement('checkbox', 'updateMapping', ts('Update this field mapping'), NULL); $saveDetailsName = ts('Save as a new field mapping'); $this->add('text', 'saveMappingName', ts('Name')); $this->add('text', 'saveMappingDesc', ts('Description')); } $this->addElement('checkbox', 'saveMapping', $saveDetailsName, NULL, array('onclick' => "showSaveDetails(this)")); $this->addFormRule(array('CRM_Contact_Import_Form_MapField', 'formRule')); //-------- end of saved mapping stuff --------- $defaults = array(); $mapperKeys = array_keys($this->_mapperFields); $hasColumnNames = !empty($this->_columnNames); $columnPatterns = $this->get('columnPatterns'); $dataPatterns = $this->get('dataPatterns'); $hasLocationTypes = $this->get('fieldTypes'); $this->_location_types = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'); $defaultLocationType = CRM_Core_BAO_LocationType::getDefault(); // Pass default location to js if ($defaultLocationType) { $this->assign('defaultLocationType', $defaultLocationType->id); $this->assign('defaultLocationTypeLabel', $this->_location_types[$defaultLocationType->id]); } /* Initialize all field usages to false */ foreach ($mapperKeys as $key) { $this->_fieldUsed[$key] = FALSE; } $sel1 = $this->_mapperFields; $sel2[''] = NULL; $phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id'); $imProviders = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'); $websiteTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Website', 'website_type_id'); foreach ($this->_location_types as $key => $value) { $sel3['phone'][$key] =& $phoneTypes; //build array for IM service provider type for contact $sel3['im'][$key] =& $imProviders; } $sel4 = NULL; // store and cache all relationship types $contactRelation = new CRM_Contact_DAO_RelationshipType(); $contactRelation->find(); while ($contactRelation->fetch()) { $contactRelationCache[$contactRelation->id] = array(); $contactRelationCache[$contactRelation->id]['contact_type_a'] = $contactRelation->contact_type_a; $contactRelationCache[$contactRelation->id]['contact_sub_type_a'] = $contactRelation->contact_sub_type_a; $contactRelationCache[$contactRelation->id]['contact_type_b'] = $contactRelation->contact_type_b; $contactRelationCache[$contactRelation->id]['contact_sub_type_b'] = $contactRelation->contact_sub_type_b; } $highlightedFields = $highlightedRelFields = array(); $highlightedFields['email'] = 'All'; $highlightedFields['external_identifier'] = 'All'; $highlightedFields['first_name'] = 'Individual'; $highlightedFields['last_name'] = 'Individual'; $highlightedFields['household_name'] = 'Household'; $highlightedFields['organization_name'] = 'Organization'; foreach ($mapperKeys as $key) { // check if there is a _a_b or _b_a in the key if (strpos($key, '_a_b') || strpos($key, '_b_a')) { list($id, $first, $second) = explode('_', $key); } else { $id = $first = $second = NULL; } if ($first == 'a' && $second == 'b' || $first == 'b' && $second == 'a') { $cType = $contactRelationCache[$id]["contact_type_{$second}"]; //CRM-5125 for contact subtype specific relationshiptypes $cSubType = NULL; if (!empty($contactRelationCache[$id]["contact_sub_type_{$second}"])) { $cSubType = $contactRelationCache[$id]["contact_sub_type_{$second}"]; } if (!$cType) { $cType = 'All'; } $relatedFields = array(); $relatedFields = CRM_Contact_BAO_Contact::importableFields($cType); unset($relatedFields['']); $values = array(); foreach ($relatedFields as $name => $field) { $values[$name] = $field['title']; if (isset($hasLocationTypes[$name])) { $sel3[$key][$name] = $this->_location_types; } elseif ($name == 'url') { $sel3[$key][$name] = $websiteTypes; } else { $sel3[$name] = NULL; } } //fix to append custom group name to field name, CRM-2676 if (empty($this->_formattedFieldNames[$cType]) || $cType == $this->_contactType) { $this->_formattedFieldNames[$cType] = $this->formatCustomFieldName($values); } $this->_formattedFieldNames[$cType] = array_merge($values, $this->_formattedFieldNames[$cType]); //Modified the Relationship fields if the fields are //present in dedupe rule if ($this->_onDuplicate != CRM_Import_Parser::DUPLICATE_NOCHECK && !empty($this->_dedupeFields[$cType]) && is_array($this->_dedupeFields[$cType])) { static $cTypeArray = array(); if ($cType != $this->_contactType && !in_array($cType, $cTypeArray)) { foreach ($this->_dedupeFields[$cType] as $val) { if ($valTitle = CRM_Utils_Array::value($val, $this->_formattedFieldNames[$cType])) { $this->_formattedFieldNames[$cType][$val] = $valTitle . ' (match to contact)'; } } $cTypeArray[] = $cType; } } foreach ($highlightedFields as $k => $v) { if ($v == $cType || $v == 'All') { $highlightedRelFields[$key][] = $k; } } $this->assign('highlightedRelFields', $highlightedRelFields); $sel2[$key] = $this->_formattedFieldNames[$cType]; if (!empty($cSubType)) { //custom fields for sub type $subTypeFields = CRM_Core_BAO_CustomField::getFieldsForImport($cSubType); if (!empty($subTypeFields)) { $subType = NULL; foreach ($subTypeFields as $customSubTypeField => $details) { $subType[$customSubTypeField] = $details['title']; $sel2[$key] = array_merge($sel2[$key], $this->formatCustomFieldName($subType)); } } } foreach ($this->_location_types as $k => $value) { $sel4[$key]['phone'][$k] =& $phoneTypes; //build array of IM service provider for related contact $sel4[$key]['im'][$k] =& $imProviders; } } else { $options = NULL; if (!empty($hasLocationTypes[$key])) { $options = $this->_location_types; } elseif ($key == 'url') { $options = $websiteTypes; } $sel2[$key] = $options; } } $js = "<script type='text/javascript'>\n"; $formName = 'document.forms.' . $this->_name; //used to warn for mismatch column count or mismatch mapping $warning = 0; for ($i = 0; $i < $this->_columnCount; $i++) { $sel =& $this->addElement('hierselect', "mapper[{$i}]", ts('Mapper for Field %1', array(1 => $i)), NULL); $jsSet = FALSE; if ($this->get('savedMapping')) { if (isset($mappingName[$i])) { if ($mappingName[$i] != ts('- do not import -')) { if (isset($mappingRelation[$i])) { // relationship mapping switch ($this->get('contactType')) { case CRM_Import_Parser::CONTACT_INDIVIDUAL: $contactType = 'Individual'; break; case CRM_Import_Parser::CONTACT_HOUSEHOLD: $contactType = 'Household'; break; case CRM_Import_Parser::CONTACT_ORGANIZATION: $contactType = 'Organization'; } //CRM-5125 $contactSubType = NULL; if ($this->get('contactSubType')) { $contactSubType = $this->get('contactSubType'); } $relations = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, $contactType, FALSE, 'label', TRUE, $contactSubType); foreach ($relations as $key => $var) { if ($key == $mappingRelation[$i]) { $relation = $key; break; } } $contactDetails = strtolower(str_replace(" ", "_", $mappingName[$i])); $websiteTypeId = isset($mappingWebsiteType[$i]) ? $mappingWebsiteType[$i] : NULL; $locationId = isset($mappingLocation[$i]) ? $mappingLocation[$i] : 0; $phoneType = isset($mappingPhoneType[$i]) ? $mappingPhoneType[$i] : NULL; //get provider id from saved mappings $imProvider = isset($mappingImProvider[$i]) ? $mappingImProvider[$i] : NULL; if ($websiteTypeId) { $defaults["mapper[{$i}]"] = array($relation, $contactDetails, $websiteTypeId); if (!$websiteTypeId) { $js .= "{$formName}['mapper[{$i}][2]'].style.display = 'none';\n"; } } else { // default for IM/phone when mapping with relation is true $typeId = NULL; if (isset($phoneType)) { $typeId = $phoneType; } elseif (isset($imProvider)) { $typeId = $imProvider; } $defaults["mapper[{$i}]"] = array($relation, $contactDetails, $locationId, $typeId); if (!$locationId) { $js .= "{$formName}['mapper[{$i}][2]'].style.display = 'none';\n"; } } // fix for edge cases, CRM-4954 if ($contactDetails == 'image_url') { $contactDetails = str_replace('url', 'URL', $contactDetails); } if (!$contactDetails) { $js .= "{$formName}['mapper[{$i}][1]'].style.display = 'none';\n"; } if (!$phoneType && !$imProvider) { $js .= "{$formName}['mapper[{$i}][3]'].style.display = 'none';\n"; } //$js .= "{$formName}['mapper[$i][3]'].style.display = 'none';\n"; $jsSet = TRUE; } else { $mappingHeader = array_keys($this->_mapperFields, $mappingName[$i]); $websiteTypeId = isset($mappingWebsiteType[$i]) ? $mappingWebsiteType[$i] : NULL; $locationId = isset($mappingLocation[$i]) ? $mappingLocation[$i] : 0; $phoneType = isset($mappingPhoneType[$i]) ? $mappingPhoneType[$i] : NULL; // get IM service provider id $imProvider = isset($mappingImProvider[$i]) ? $mappingImProvider[$i] : NULL; if ($websiteTypeId) { if (!$websiteTypeId) { $js .= "{$formName}['mapper[{$i}][1]'].style.display = 'none';\n"; } $defaults["mapper[{$i}]"] = array($mappingHeader[0], $websiteTypeId); } else { if (!$locationId) { $js .= "{$formName}['mapper[{$i}][1]'].style.display = 'none';\n"; } //default for IM/phone without related contact $typeId = NULL; if (isset($phoneType)) { $typeId = $phoneType; } elseif (isset($imProvider)) { $typeId = $imProvider; } $defaults["mapper[{$i}]"] = array($mappingHeader[0], $locationId, $typeId); } if (!$phoneType && !$imProvider) { $js .= "{$formName}['mapper[{$i}][2]'].style.display = 'none';\n"; } $js .= "{$formName}['mapper[{$i}][3]'].style.display = 'none';\n"; $jsSet = TRUE; } } else { $defaults["mapper[{$i}]"] = array(); } if (!$jsSet) { for ($k = 1; $k < 4; $k++) { $js .= "{$formName}['mapper[{$i}][{$k}]'].style.display = 'none';\n"; } } } else { // this load section to help mapping if we ran out of saved columns when doing Load Mapping $js .= "swapOptions({$formName}, 'mapper[{$i}]', 0, 3, 'hs_mapper_0_');\n"; if ($hasColumnNames) { $defaults["mapper[{$i}]"] = array($this->defaultFromColumnName($this->_columnNames[$i], $columnPatterns)); } else { $defaults["mapper[{$i}]"] = array($this->defaultFromData($dataPatterns, $i)); } } //end of load mapping } else { $js .= "swapOptions({$formName}, 'mapper[{$i}]', 0, 3, 'hs_mapper_0_');\n"; if ($hasColumnNames) { // do array search first to see if has mapped key $columnKey = ''; $columnKey = array_search($this->_columnNames[$i], $this->_mapperFields); if (isset($this->_fieldUsed[$columnKey])) { $defaults["mapper[{$i}]"] = $columnKey; $this->_fieldUsed[$key] = TRUE; } else { // Infer the default from the column names if we have them $defaults["mapper[{$i}]"] = array($this->defaultFromColumnName($this->_columnNames[$i], $columnPatterns), 0); } } else { // Otherwise guess the default from the form of the data $defaults["mapper[{$i}]"] = array($this->defaultFromData($dataPatterns, $i), 0); } } $sel->setOptions(array($sel1, $sel2, $sel3, $sel4)); } $js .= "</script>\n"; $this->assign('initHideBoxes', $js); //set warning if mismatch in more than if (isset($mappingName) && $this->_columnCount != count($mappingName)) { $warning++; } if ($warning != 0 && $this->get('savedMapping')) { $session = CRM_Core_Session::singleton(); $session->setStatus(ts('The data columns in this import file appear to be different from the saved mapping. Please verify that you have selected the correct saved mapping before continuing.')); } else { $session = CRM_Core_Session::singleton(); $session->setStatus(NULL); } $this->setDefaults($defaults); $this->addButtons(array(array('type' => 'back', 'name' => ts('Previous')), array('type' => 'next', 'name' => ts('Continue'), 'spacing' => ' ', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')))); }
static function defaultReturnProperties($mode) { $properties = null; if ($mode & CRM_Contact_BAO_Query::MODE_MEMBER) { $properties = array('contact_type' => 1, 'contact_sub_type' => 1, 'sort_name' => 1, 'display_name' => 1, 'membership_type_id' => 1, 'member_is_test' => 1, 'member_is_pay_later' => 1, 'join_date' => 1, 'membership_start_date' => 1, 'membership_end_date' => 1, 'membership_source' => 1, 'status_id' => 1, 'membership_id' => 1, 'owner_membership_id' => 1); // also get all the custom membership properties require_once "CRM/Core/BAO/CustomField.php"; $fields = CRM_Core_BAO_CustomField::getFieldsForImport('Membership'); if (!empty($fields)) { foreach ($fields as $name => $dontCare) { $properties[$name] = 1; } } } return $properties; }
/** * extracts the parameters from the request and constructs information for * the selector object to do a query * * @return void * @access public * */ function preProcess() { $this->_search = true; $search = CRM_Utils_Request::retrieve('search', 'Boolean', $this, false, 0, 'GET'); if (isset($search) && $search == 0) { $this->_search = false; } $this->_gid = CRM_Utils_Request::retrieve('gid', 'Positive', $this, true, 0, 'GET'); require_once 'CRM/Core/BAO/UFGroup.php'; $this->_fields = CRM_Core_BAO_UFGroup::getListingFields(CRM_Core_Action::UPDATE, CRM_Core_BAO_UFGroup::PUBLIC_VISIBILITY | CRM_Core_BAO_UFGroup::LISTINGS_VISIBILITY, false, $this->_gid, false, 'Profile', CRM_Core_Permission::SEARCH); $this->_customFields = CRM_Core_BAO_CustomField::getFieldsForImport(null); $this->_params = array(); $resetArray = array('group', 'tag', 'preferred_communication_method', 'do_not_phone', 'do_not_email', 'do_not_mail', 'do_not_sms', 'do_not_trade', 'gender'); foreach ($this->_fields as $name => $field) { if (substr($name, 0, 6) == 'custom' && CRM_Utils_Array::value('is_search_range', $field)) { $from = CRM_Utils_Request::retrieve($name . '_from', 'String', $this, false, null, 'REQUEST'); $to = CRM_Utils_Request::retrieve($name . '_to', 'String', $this, false, null, 'REQUEST'); $value = array(); if ($from && $to) { $value['from'] = $from; $value['to'] = $to; } else { if ($from) { $value['from'] = $from; } else { if ($to) { $value['to'] = $to; } } } } else { if (substr($name, 0, 7) == 'custom_' && CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', substr($name, 7), 'html_type') == 'TextArea') { $value = trim(CRM_Utils_Request::retrieve($name, 'String', $this, false, null, 'REQUEST')); if (!empty($value) && !(substr($value, 0, 1) == '%' && substr($value, -1, 1) == '%')) { $value = '%' . $value . '%'; } } else { if (CRM_Utils_Array::value('html_type', $field) == 'Multi-Select State/Province' || CRM_Utils_Array::value('html_type', $field) == 'Multi-Select Country') { $value = CRM_Utils_Request::retrieve($name, 'String', $this, false, null, 'REQUEST'); if (!is_array($value)) { $value = explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, substr($value, 1, -1)); } } else { $value = CRM_Utils_Request::retrieve($name, 'String', $this, false, null, 'REQUEST'); } } } if (($name == 'group' || $name == 'tag') && !empty($value) && !is_array($value)) { $v = explode(',', $value); $value = array(); foreach ($v as $item) { $value[$item] = 1; } } $customField = CRM_Utils_Array::value($name, $this->_customFields); if (!empty($_POST) && !CRM_Utils_Array::value($name, $_POST)) { if ($customField) { // reset checkbox/radio because a form does not send null checkbox values if (in_array($customField['html_type'], array('Multi-Select', 'CheckBox', 'Multi-Select State/Province', 'Multi-Select Country', 'Radio'))) { // only reset on a POST submission if we dont see any value $value = null; $this->set($name, $value); } } else { if (in_array($name, $resetArray)) { $value = null; $this->set($name, $value); } } } if (isset($value) && $value != null) { if (!is_array($value)) { $value = trim($value); } $this->_params[$name] = $this->_fields[$name]['value'] = $value; } } // set the params in session $session =& CRM_Core_Session::singleton(); $session->set('profileParams', $this->_params); }
/** * Set profile defaults. * * @param int $contactId * Contact id. * @param array $fields * Associative array of fields. * @param array $defaults * Defaults array. * @param bool $singleProfile * True for single profile else false(batch update). * @param int $componentId * Id for specific components like contribute, event etc. * @param null $component */ public static function setProfileDefaults($contactId, &$fields, &$defaults, $singleProfile = TRUE, $componentId = NULL, $component = NULL) { if (!$componentId) { //get the contact details list($contactDetails, $options) = CRM_Contact_BAO_Contact::getHierContactDetails($contactId, $fields); $details = CRM_Utils_Array::value($contactId, $contactDetails); $multipleFields = array('website' => 'url'); //start of code to set the default values foreach ($fields as $name => $field) { // skip pseudo fields if (substr($name, 0, 9) == 'phone_ext') { continue; } //set the field name depending upon the profile mode(single/batch) if ($singleProfile) { $fldName = $name; } else { $fldName = "field[{$contactId}][{$name}]"; } if ($name == 'group') { CRM_Contact_Form_Edit_TagsAndGroups::setDefaults($contactId, $defaults, CRM_Contact_Form_Edit_TagsAndGroups::GROUP, $fldName); } if ($name == 'tag') { CRM_Contact_Form_Edit_TagsAndGroups::setDefaults($contactId, $defaults, CRM_Contact_Form_Edit_TagsAndGroups::TAG, $fldName); } if (!empty($details[$name]) || isset($details[$name])) { //to handle custom data (checkbox) to be written // to handle birth/deceased date, greeting_type and few other fields if ($name == 'birth_date' || $name == 'deceased_date') { list($defaults[$fldName]) = CRM_Utils_Date::setDateDefaults($details[$name], 'birth'); } elseif (in_array($name, CRM_Contact_BAO_Contact::$_greetingTypes)) { $defaults[$fldName] = $details[$name . '_id']; $defaults[$name . '_custom'] = $details[$name . '_custom']; } elseif ($name == 'preferred_communication_method') { $v = explode(CRM_Core_DAO::VALUE_SEPARATOR, $details[$name]); foreach ($v as $item) { if ($item) { $defaults[$fldName . "[{$item}]"] = 1; } } } elseif ($name == 'contact_sub_type') { $defaults[$fldName] = explode(CRM_Core_DAO::VALUE_SEPARATOR, trim($details[$name], CRM_Core_DAO::VALUE_SEPARATOR)); } elseif ($name == 'world_region') { $defaults[$fldName] = $details['worldregion_id']; } elseif ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($name)) { //fix for custom fields $customFields = CRM_Core_BAO_CustomField::getFields(CRM_Utils_Array::value('contact_type', $details)); // hack to add custom data for components $components = array('Contribution', 'Participant', 'Membership', 'Activity'); foreach ($components as $value) { $customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFieldsForImport($value)); } switch ($customFields[$customFieldId]['html_type']) { case 'Multi-Select State/Province': case 'Multi-Select Country': case 'AdvMulti-Select': case 'Multi-Select': $v = explode(CRM_Core_DAO::VALUE_SEPARATOR, $details[$name]); foreach ($v as $item) { if ($item) { $defaults[$fldName][$item] = $item; } } break; case 'CheckBox': $v = explode(CRM_Core_DAO::VALUE_SEPARATOR, $details[$name]); foreach ($v as $item) { if ($item) { $defaults[$fldName][$item] = 1; // seems like we need this for QF style checkboxes in profile where its multiindexed // CRM-2969 $defaults["{$fldName}[{$item}]"] = 1; } } break; case 'Select Date': // CRM-6681, set defult values according to date and time format (if any). $dateFormat = NULL; if (!empty($customFields[$customFieldId]['date_format'])) { $dateFormat = $customFields[$customFieldId]['date_format']; } if (empty($customFields[$customFieldId]['time_format'])) { list($defaults[$fldName]) = CRM_Utils_Date::setDateDefaults($details[$name], NULL, $dateFormat); } else { $timeElement = $fldName . '_time'; if (substr($fldName, -1) == ']') { $timeElement = substr($fldName, 0, -1) . '_time]'; } list($defaults[$fldName], $defaults[$timeElement]) = CRM_Utils_Date::setDateDefaults($details[$name], NULL, $dateFormat, $customFields[$customFieldId]['time_format']); } break; default: $defaults[$fldName] = $details[$name]; break; } } else { $defaults[$fldName] = $details[$name]; } } else { $blocks = array('email', 'phone', 'im', 'openid'); list($fieldName, $locTypeId, $phoneTypeId) = CRM_Utils_System::explode('-', $name, 3); if (!in_array($fieldName, $multipleFields)) { if (is_array($details)) { foreach ($details as $key => $value) { // when we fixed CRM-5319 - get primary loc // type as per loc field and removed below code. $primaryLocationType = FALSE; if ($locTypeId == 'Primary') { if (is_array($value) && array_key_exists($fieldName, $value)) { $primaryLocationType = TRUE; if (in_array($fieldName, $blocks)) { $locTypeId = CRM_Contact_BAO_Contact::getPrimaryLocationType($contactId, FALSE, $fieldName); } else { $locTypeId = CRM_Contact_BAO_Contact::getPrimaryLocationType($contactId, FALSE, 'address'); } } } // fixed for CRM-665 if (is_numeric($locTypeId)) { if ($primaryLocationType || $locTypeId == CRM_Utils_Array::value('location_type_id', $value)) { if (!empty($value[$fieldName])) { //to handle stateprovince and country if ($fieldName == 'state_province') { $defaults[$fldName] = $value['state_province_id']; } elseif ($fieldName == 'county') { $defaults[$fldName] = $value['county_id']; } elseif ($fieldName == 'country') { if (!isset($value['country_id']) || !$value['country_id']) { $config = CRM_Core_Config::singleton(); if ($config->defaultContactCountry) { $defaults[$fldName] = $config->defaultContactCountry; } } else { $defaults[$fldName] = $value['country_id']; } } elseif ($fieldName == 'phone') { if ($phoneTypeId) { if (isset($value['phone'][$phoneTypeId])) { $defaults[$fldName] = $value['phone'][$phoneTypeId]; } if (isset($value['phone_ext'][$phoneTypeId])) { $defaults[str_replace('phone', 'phone_ext', $fldName)] = $value['phone_ext'][$phoneTypeId]; } } else { $phoneDefault = CRM_Utils_Array::value('phone', $value); // CRM-9216 if (!is_array($phoneDefault)) { $defaults[$fldName] = $phoneDefault; } } } elseif ($fieldName == 'email') { //adding the first email (currently we don't support multiple emails of same location type) $defaults[$fldName] = $value['email']; } elseif ($fieldName == 'im') { //adding the first im (currently we don't support multiple ims of same location type) $defaults[$fldName] = $value['im']; $defaults[$fldName . '-provider_id'] = $value['im_provider_id']; } else { $defaults[$fldName] = $value[$fieldName]; } } elseif (substr($fieldName, 0, 14) === 'address_custom' && CRM_Utils_Array::value(substr($fieldName, 8), $value)) { $defaults[$fldName] = $value[substr($fieldName, 8)]; } } } } } } else { if (is_array($details)) { if ($fieldName === 'url' && !empty($details['website']) && !empty($details['website'][$locTypeId])) { $defaults[$fldName] = CRM_Utils_Array::value('url', $details['website'][$locTypeId]); } } } } } } //Handling Contribution Part of the batch profile if (CRM_Core_Permission::access('CiviContribute') && $component == 'Contribute') { self::setComponentDefaults($fields, $componentId, $component, $defaults); } //Handling Event Participation Part of the batch profile if (CRM_Core_Permission::access('CiviEvent') && $component == 'Event') { self::setComponentDefaults($fields, $componentId, $component, $defaults); } //Handling membership Part of the batch profile if (CRM_Core_Permission::access('CiviMember') && $component == 'Membership') { self::setComponentDefaults($fields, $componentId, $component, $defaults); } //Handling Activity Part of the batch profile if ($component == 'Activity') { self::setComponentDefaults($fields, $componentId, $component, $defaults); } }
/** * @param $mode * @param bool $includeCustomFields * * @return array|NULL */ public static function defaultReturnProperties($mode, $includeCustomFields = TRUE) { $properties = NULL; if ($mode & CRM_Contact_BAO_Query::MODE_CONTRIBUTE) { $properties = array('contact_type' => 1, 'contact_sub_type' => 1, 'sort_name' => 1, 'display_name' => 1, 'financial_type' => 1, 'contribution_source' => 1, 'receive_date' => 1, 'thankyou_date' => 1, 'cancel_date' => 1, 'total_amount' => 1, 'accounting_code' => 1, 'payment_instrument' => 1, 'payment_instrument_id' => 1, 'check_number' => 1, 'non_deductible_amount' => 1, 'fee_amount' => 1, 'net_amount' => 1, 'trxn_id' => 1, 'invoice_id' => 1, 'currency' => 1, 'cancel_reason' => 1, 'receipt_date' => 1, 'product_name' => 1, 'sku' => 1, 'product_option' => 1, 'fulfilled_date' => 1, 'contribution_start_date' => 1, 'contribution_end_date' => 1, 'is_test' => 1, 'is_pay_later' => 1, 'contribution_status' => 1, 'contribution_status_id' => 1, 'contribution_recur_id' => 1, 'amount_level' => 1, 'contribution_note' => 1, 'contribution_batch' => 1, 'contribution_campaign_id' => 1); if (self::isSoftCreditOptionEnabled()) { $properties = array_merge($properties, self::softCreditReturnProperties()); } if ($includeCustomFields) { // also get all the custom contribution properties $fields = CRM_Core_BAO_CustomField::getFieldsForImport('Contribution'); if (!empty($fields)) { foreach ($fields as $name => $dontCare) { $properties[$name] = 1; } } } } return $properties; }
/** * Function to get list of membership fields for profile * For now we only allow custom membership fields to be in * profile * * @return return the list of membership fields * @static * @access public */ static function getMembershipFields() { $fields = CRM_Member_DAO_Membership::export(); unset($fields['membership_contact_id']); $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport('Membership')); require_once 'CRM/Member/DAO/MembershipType.php'; $membershipType = CRM_Member_DAO_MembershipType::export(); require_once 'CRM/Member/DAO/MembershipStatus.php'; $membershipStatus = CRM_Member_DAO_MembershipStatus::export(); $fields = array_merge($fields, $membershipType, $membershipStatus); return $fields; }
/** * combine all the exportable fields from the lower levels object * * @return array array of exportable Fields * @access public * @static */ static function &exportableFields() { if (!self::$_exportableFields) { if (!self::$_exportableFields) { self::$_exportableFields = array(); } $fields = CRM_Pledge_DAO_Pledge::export(); $fields = array_merge($fields, CRM_Pledge_DAO_PledgePayment::export()); //set title to calculated fields $calculatedFields = array('pledge_total_paid' => array('title' => ts('Total Paid')), 'pledge_balance_amount' => array('title' => ts('Balance Amount')), 'pledge_next_pay_date' => array('title' => ts('Next Payment Date')), 'pledge_next_pay_amount' => array('title' => ts('Next Payment Amount')), 'pledge_payment_paid_amount' => array('title' => ts('Paid Amount')), 'pledge_payment_paid_date' => array('title' => ts('Paid Date')), 'pledge_payment_status' => array('title' => ts('Pledge Payment Status'), 'name' => 'pledge_payment_status', 'data_type' => CRM_Utils_Type::T_STRING)); $pledgeFields = array('pledge_status' => array('title' => 'Pledge Status', 'name' => 'pledge_status', 'data_type' => CRM_Utils_Type::T_STRING), 'pledge_frequency_unit' => array('title' => 'Pledge Frequency Unit', 'name' => 'pledge_frequency_unit', 'data_type' => CRM_Utils_Type::T_ENUM), 'pledge_frequency_interval' => array('title' => 'Pledge Frequency Interval', 'name' => 'pledge_frequency_interval', 'data_type' => CRM_Utils_Type::T_INT), 'pledge_contribution_page_id' => array('title' => 'Pledge Contribution Page Id', 'name' => 'pledge_contribution_page_id', 'data_type' => CRM_Utils_Type::T_INT)); $fields = array_merge($fields, $pledgeFields, $calculatedFields); // add custom data $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport('Pledge')); self::$_exportableFields = $fields; } return self::$_exportableFields; }
/** * 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; }
/** * the initializer code, called before the processing * * @return void * @access public */ function init() { require_once 'CRM/Contact/BAO/Contact.php'; $fields =& CRM_Contact_BAO_Contact::importableFields($this->_contactType); //CRM-5125 //supporting import for contact subtypes if (!empty($this->_contactSubType)) { //custom fields for sub type $subTypeFields = CRM_Core_BAO_CustomField::getFieldsForImport($this->_contactSubType); if (!empty($subTypeFields)) { foreach ($subTypeFields as $customSubTypeField => $details) { $fields[$customSubTypeField] = $details; } } } //Relationship importables $this->_relationships = $relations = CRM_Contact_BAO_Relationship::getContactRelationshipType(null, null, null, $this->_contactType, false, 'label', true, $this->_contactSubType); asort($relations); foreach ($relations as $key => $var) { list($type) = explode('_', $key); $relationshipType[$key]['title'] = $var; $relationshipType[$key]['headerPattern'] = '/' . preg_quote($var, '/') . '/'; $relationshipType[$key]['import'] = true; $relationshipType[$key]['relationship_type_id'] = $type; $relationshipType[$key]['related'] = true; } if (!empty($relationshipType)) { $fields = array_merge($fields, array('related' => array('title' => ts('- related contact info -'))), $relationshipType); } foreach ($fields as $name => $field) { $this->addField($name, $field['title'], CRM_Utils_Array::value('type', $field), CRM_Utils_Array::value('headerPattern', $field), CRM_Utils_Array::value('dataPattern', $field), CRM_Utils_Array::value('hasLocationType', $field)); } $this->_newContacts = array(); $this->setActiveFields($this->_mapperKeys); $this->setActiveFieldLocationTypes($this->_mapperLocType); $this->setActiveFieldPhoneTypes($this->_mapperPhoneType); //set active fields of IM provider of contact $this->setActiveFieldImProviders($this->_mapperImProvider); //related info $this->setActiveFieldRelated($this->_mapperRelated); $this->setActiveFieldRelatedContactType($this->_mapperRelatedContactType); $this->setActiveFieldRelatedContactDetails($this->_mapperRelatedContactDetails); $this->setActiveFieldRelatedContactLocType($this->_mapperRelatedContactLocType); $this->setActiveFieldRelatedContactPhoneType($this->_mapperRelatedContactPhoneType); //set active fields of IM provider of related contact $this->setActiveFieldRelatedContactImProvider($this->_mapperRelatedContactImProvider); $this->_phoneIndex = -1; $this->_emailIndex = -1; $this->_firstNameIndex = -1; $this->_lastNameIndex = -1; $this->_householdNameIndex = -1; $this->_organizationNameIndex = -1; $this->_externalIdentifierIndex = -1; $index = 0; foreach ($this->_mapperKeys as $key) { if (substr($key, 0, 5) == 'email' && substr($key, 0, 14) != 'email_greeting') { $this->_emailIndex = $index; $this->_allEmails = array(); } if (substr($key, 0, 5) == 'phone') { $this->_phoneIndex = $index; } if ($key == 'first_name') { $this->_firstNameIndex = $index; } if ($key == 'last_name') { $this->_lastNameIndex = $index; } if ($key == 'household_name') { $this->_householdNameIndex = $index; } if ($key == 'organization_name') { $this->_organizationNameIndex = $index; } if ($key == 'external_identifier') { $this->_externalIdentifierIndex = $index; $this->_allExternalIdentifiers = array(); } $index++; } $this->_updateWithId = false; if (in_array('id', $this->_mapperKeys) || $this->_externalIdentifierIndex >= 0 && in_array($this->_onDuplicate, array(CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::DUPLICATE_FILL))) { $this->_updateWithId = true; } require_once 'CRM/Core/BAO/Preferences.php'; $this->_parseStreetAddress = CRM_Utils_Array::value('street_address_parsing', CRM_Core_BAO_Preferences::valueOptions('address_options'), false); }
/** * @param $mode * @param bool $includeCustomFields * * @return array|null */ public static function defaultReturnProperties($mode, $includeCustomFields = TRUE) { $properties = NULL; if ($mode & CRM_Contact_BAO_Query::MODE_CASE) { $properties = array('contact_type' => 1, 'contact_sub_type' => 1, 'contact_id' => 1, 'sort_name' => 1, 'display_name' => 1, 'case_id' => 1, 'case_activity_subject' => 1, 'case_subject' => 1, 'case_status' => 1, 'case_type' => 1, 'case_role' => 1, 'case_deleted' => 1, 'case_recent_activity_date' => 1, 'case_recent_activity_type' => 1, 'case_scheduled_activity_date' => 1, 'phone' => 1); if ($includeCustomFields) { // also get all the custom case properties $fields = CRM_Core_BAO_CustomField::getFieldsForImport('Case'); if (!empty($fields)) { foreach ($fields as $name => $dontCare) { $properties[$name] = 1; } } } } return $properties; }
/** * Get default return properties. * * @param string $mode * @param bool $includeCustomFields * * @return array|null */ public static function defaultReturnProperties($mode, $includeCustomFields = TRUE) { $properties = NULL; if ($mode & CRM_Contact_BAO_Query::MODE_MEMBER) { $properties = array('contact_type' => 1, 'contact_sub_type' => 1, 'sort_name' => 1, 'display_name' => 1, 'membership_type' => 1, 'member_is_test' => 1, 'member_is_pay_later' => 1, 'join_date' => 1, 'membership_start_date' => 1, 'membership_end_date' => 1, 'membership_source' => 1, 'membership_status' => 1, 'membership_id' => 1, 'owner_membership_id' => 1, 'max_related' => 1, 'membership_recur_id' => 1, 'member_campaign_id' => 1, 'member_is_override' => 1); if ($includeCustomFields) { // also get all the custom membership properties $fields = CRM_Core_BAO_CustomField::getFieldsForImport('Membership'); if (!empty($fields)) { foreach ($fields as $name => $dontCare) { $properties[$name] = 1; } } } } return $properties; }
/** * This includes any extra fields that might need for export etc. */ public static function extraReturnProperties($mode) { $properties = NULL; if ($mode & CRM_Contact_BAO_Query::MODE_PLEDGE) { $properties = array('pledge_balance_amount' => 1, 'pledge_payment_id' => 1, 'pledge_payment_scheduled_amount' => 1, 'pledge_payment_scheduled_date' => 1, 'pledge_payment_paid_amount' => 1, 'pledge_payment_paid_date' => 1, 'pledge_payment_reminder_date' => 1, 'pledge_payment_reminder_count' => 1, 'pledge_payment_status_id' => 1, 'pledge_payment_status' => 1); // also get all the custom pledge properties $fields = CRM_Core_BAO_CustomField::getFieldsForImport('Pledge'); if (!empty($fields)) { foreach ($fields as $name => $dontCare) { $properties[$name] = 1; } } } return $properties; }
/** * Class constructor * * @param $customSearchClass * @param array $formValues array of form values imported * @param array $params array of parameters for query * @param null $returnProperties * @param \const|int $action - action of search basic or advanced. * * @param bool $includeContactIds * @param bool $searchDescendentGroups * @param string $searchContext * @param null $contextMenu * * @return CRM_Contact_Selector * @access public */ function __construct($customSearchClass, $formValues = NULL, $params = NULL, $returnProperties = NULL, $action = CRM_Core_Action::NONE, $includeContactIds = FALSE, $searchDescendentGroups = TRUE, $searchContext = 'search', $contextMenu = NULL) { //don't build query constructor, if form is not submitted $force = CRM_Utils_Request::retrieve('force', 'Boolean', CRM_Core_DAO::$_nullObject); if (empty($formValues) && !$force) { return; } // submitted form values $this->_formValues =& $formValues; $this->_params =& $params; $this->_returnProperties =& $returnProperties; $this->_contextMenu =& $contextMenu; $this->_context = $searchContext; // type of selector $this->_action = $action; $this->_searchContext = $searchContext; $this->_ufGroupID = CRM_Utils_Array::value('uf_group_id', $this->_formValues); if ($this->_ufGroupID) { $this->_fields = CRM_Core_BAO_UFGroup::getListingFields(CRM_Core_Action::VIEW, CRM_Core_BAO_UFGroup::PUBLIC_VISIBILITY | CRM_Core_BAO_UFGroup::LISTINGS_VISIBILITY, FALSE, $this->_ufGroupID); self::$_columnHeaders = NULL; $this->_customFields = CRM_Core_BAO_CustomField::getFieldsForImport('Individual'); $this->_returnProperties = CRM_Contact_BAO_Contact::makeHierReturnProperties($this->_fields); $this->_returnProperties['contact_type'] = 1; $this->_returnProperties['contact_sub_type'] = 1; $this->_returnProperties['sort_name'] = 1; } $displayRelationshipType = CRM_Utils_Array::value('display_relationship_type', $this->_formValues); $operator = CRM_Utils_Array::value('operator', $this->_formValues, 'AND'); // rectify params to what proximity search expects if there is a value for prox_distance // CRM-7021 if (!empty($this->_params)) { CRM_Contact_BAO_ProximityQuery::fixInputParams($this->_params); } $this->_query = new CRM_Contact_BAO_Query($this->_params, $this->_returnProperties, NULL, $includeContactIds, FALSE, CRM_Contact_BAO_Query::MODE_CONTACTS, FALSE, $searchDescendentGroups, FALSE, $displayRelationshipType, $operator); $this->_options =& $this->_query->_options; }
/** * Combine all the exportable fields from the lower levels object. * * Currently we are using importable fields as exportable fields * * @param int|string $contactType contact Type * @param bool $status * True while exporting primary contacts. * @param bool $export * True when used during export. * @param bool $search * True when used during search, might conflict with export param?. * * @param bool $withMultiRecord * * @return array * array of exportable Fields */ public static function &exportableFields($contactType = 'Individual', $status = FALSE, $export = FALSE, $search = FALSE, $withMultiRecord = FALSE) { if (empty($contactType)) { $contactType = 'All'; } $cacheKeyString = "exportableFields {$contactType}"; $cacheKeyString .= $export ? '_1' : '_0'; $cacheKeyString .= $status ? '_1' : '_0'; $cacheKeyString .= $search ? '_1' : '_0'; //CRM-14501 it turns out that the impact of permissioning here is sometimes inconsistent. The field that //calculates custom fields takes into account the logged in user & caches that for all users //as an interim fix we will cache the fields by contact $cacheKeyString .= '_' . CRM_Core_Session::getLoggedInContactID(); if (!self::$_exportableFields || !CRM_Utils_Array::value($cacheKeyString, self::$_exportableFields)) { if (!self::$_exportableFields) { self::$_exportableFields = array(); } // check if we can retrieve from database cache $fields = CRM_Core_BAO_Cache::getItem('contact fields', $cacheKeyString); if (!$fields) { $fields = CRM_Contact_DAO_Contact::export(); // The fields are meant for contact types. if (in_array($contactType, array('Individual', 'Household', 'Organization', 'All'))) { $fields = array_merge($fields, CRM_Core_OptionValue::getFields('', $contactType)); } // add current employer for individuals $fields = array_merge($fields, array('current_employer' => array('name' => 'organization_name', 'title' => ts('Current Employer')))); $locationType = array('location_type' => array('name' => 'location_type', 'where' => 'civicrm_location_type.name', 'title' => ts('Location Type'))); $IMProvider = array('im_provider' => array('name' => 'im_provider', 'where' => 'civicrm_im.provider_id', 'title' => ts('IM Provider'))); $locationFields = array_merge($locationType, CRM_Core_DAO_Address::export(), CRM_Core_DAO_Phone::export(), CRM_Core_DAO_Email::export(), $IMProvider, CRM_Core_DAO_IM::export(TRUE), CRM_Core_DAO_OpenID::export()); $locationFields = array_merge($locationFields, CRM_Core_BAO_CustomField::getFieldsForImport('Address')); foreach ($locationFields as $key => $field) { $locationFields[$key]['hasLocationType'] = TRUE; } $fields = array_merge($fields, $locationFields); //add world region $fields = array_merge($fields, CRM_Core_DAO_Worldregion::export()); $fields = array_merge($fields, CRM_Contact_DAO_Contact::export()); //website fields $fields = array_merge($fields, CRM_Core_DAO_Website::export()); if ($contactType != 'All') { $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport($contactType, $status, FALSE, $search, TRUE, $withMultiRecord)); } else { foreach (array('Individual', 'Household', 'Organization') as $type) { $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport($type, FALSE, FALSE, $search, TRUE, $withMultiRecord)); } } //fix for CRM-791 if ($export) { $fields = array_merge($fields, array('groups' => array('title' => ts('Group(s)'), 'name' => 'groups'), 'tags' => array('title' => ts('Tag(s)'), 'name' => 'tags'), 'notes' => array('title' => ts('Note(s)'), 'name' => 'notes'))); } else { $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'))); } //Sorting fields in alphabetical order(CRM-1507) foreach ($fields as $k => $v) { $sortArray[$k] = CRM_Utils_Array::value('title', $v); } $fields = array_merge($sortArray, $fields); //unset the field which are not related to their contact type. if ($contactType != 'All') { $commonValues = array('Individual' => array('household_name', 'legal_name', 'sic_code', 'organization_name', 'email_greeting_custom', 'postal_greeting_custom', 'addressee_custom'), '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', 'current_employer', 'email_greeting_custom', 'postal_greeting_custom', 'addressee_custom', 'prefix_id', 'suffix_id'), 'Organization' => array('first_name', 'middle_name', 'last_name', 'formal_title', 'job_title', 'gender_id', 'prefix_id', 'suffix_id', 'birth_date', 'household_name', 'email_greeting_custom', 'postal_greeting_custom', 'prefix_id', 'suffix_id', 'gender_id', 'addressee_custom', 'is_deceased', 'deceased_date', 'current_employer')); foreach ($commonValues[$contactType] as $value) { unset($fields[$value]); } } CRM_Core_BAO_Cache::setItem($fields, 'contact fields', $cacheKeyString); } self::$_exportableFields[$cacheKeyString] = $fields; } if (!$status) { $fields = self::$_exportableFields[$cacheKeyString]; } else { $fields = array_merge(array('' => array('title' => ts('- Contact Fields -'))), self::$_exportableFields[$cacheKeyString]); } return $fields; }
/** * @param $mode * @param bool $includeCustomFields * * @return array|null */ public static function defaultReturnProperties($mode, $includeCustomFields = TRUE) { $properties = NULL; if ($mode & CRM_Contact_BAO_Query::MODE_EVENT) { $properties = array('contact_type' => 1, 'contact_sub_type' => 1, 'sort_name' => 1, 'display_name' => 1, 'event_id' => 1, 'event_title' => 1, 'event_start_date' => 1, 'event_end_date' => 1, 'event_type' => 1, 'participant_id' => 1, 'participant_status' => 1, 'participant_status_id' => 1, 'participant_role' => 1, 'participant_role_id' => 1, 'participant_note' => 1, 'participant_register_date' => 1, 'participant_source' => 1, 'participant_fee_level' => 1, 'participant_is_test' => 1, 'participant_is_pay_later' => 1, 'participant_fee_amount' => 1, 'participant_discount_name' => 1, 'participant_fee_currency' => 1, 'participant_registered_by_id' => 1, 'participant_campaign_id' => 1); if ($includeCustomFields) { // also get all the custom participant properties $fields = CRM_Core_BAO_CustomField::getFieldsForImport('Participant'); if (!empty($fields)) { foreach ($fields as $name => $dontCare) { $properties[$name] = 1; } } } } return $properties; }
/** * Function to get list of membership fields for profile * For now we only allow custom membership fields to be in * profile * * @return return the list of membership fields * @static * @access public */ static function getMembershipFields() { $fields = CRM_Member_DAO_Membership::export(); unset($fields['membership_contact_id']); $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport('Membership')); return $fields; }