/** * This function adds the contact variable in $values to the * parameter list $params. For most cases, $values should have length 1. If * the variable being added is a child of Location, a location_type_id must * also be included. If it is a child of phone, a phone_type must be included. * * @param array $values * The variable(s) to be added. * @param array $params * The structured parameter list. * * @return bool|CRM_Utils_Error */ function _civicrm_api3_deprecated_add_formatted_param(&$values, &$params) { // Crawl through the possible classes: // Contact // Individual // Household // Organization // Location // Address // Email // Phone // IM // Note // Custom // Cache the various object fields static $fields = NULL; if ($fields == NULL) { $fields = array(); } // first add core contact values since for other Civi modules they are not added require_once 'CRM/Contact/BAO/Contact.php'; $contactFields = CRM_Contact_DAO_Contact::fields(); _civicrm_api3_store_values($contactFields, $values, $params); if (isset($values['contact_type'])) { // we're an individual/household/org property $fields[$values['contact_type']] = CRM_Contact_DAO_Contact::fields(); _civicrm_api3_store_values($fields[$values['contact_type']], $values, $params); return TRUE; } if (isset($values['individual_prefix'])) { if (!empty($params['prefix_id'])) { $prefixes = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'prefix_id'); $params['prefix'] = $prefixes[$params['prefix_id']]; } else { $params['prefix'] = $values['individual_prefix']; } return TRUE; } if (isset($values['individual_suffix'])) { if (!empty($params['suffix_id'])) { $suffixes = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'suffix_id'); $params['suffix'] = $suffixes[$params['suffix_id']]; } else { $params['suffix'] = $values['individual_suffix']; } return TRUE; } // CRM-4575 if (isset($values['email_greeting'])) { if (!empty($params['email_greeting_id'])) { $emailGreetingFilter = array('contact_type' => CRM_Utils_Array::value('contact_type', $params), 'greeting_type' => 'email_greeting'); $emailGreetings = CRM_Core_PseudoConstant::greeting($emailGreetingFilter); $params['email_greeting'] = $emailGreetings[$params['email_greeting_id']]; } else { $params['email_greeting'] = $values['email_greeting']; } return TRUE; } if (isset($values['postal_greeting'])) { if (!empty($params['postal_greeting_id'])) { $postalGreetingFilter = array('contact_type' => CRM_Utils_Array::value('contact_type', $params), 'greeting_type' => 'postal_greeting'); $postalGreetings = CRM_Core_PseudoConstant::greeting($postalGreetingFilter); $params['postal_greeting'] = $postalGreetings[$params['postal_greeting_id']]; } else { $params['postal_greeting'] = $values['postal_greeting']; } return TRUE; } if (isset($values['addressee'])) { if (!empty($params['addressee_id'])) { $addresseeFilter = array('contact_type' => CRM_Utils_Array::value('contact_type', $params), 'greeting_type' => 'addressee'); $addressee = CRM_Core_PseudoConstant::addressee($addresseeFilter); $params['addressee'] = $addressee[$params['addressee_id']]; } else { $params['addressee'] = $values['addressee']; } return TRUE; } if (isset($values['gender'])) { if (!empty($params['gender_id'])) { $genders = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id'); $params['gender'] = $genders[$params['gender_id']]; } else { $params['gender'] = $values['gender']; } return TRUE; } if (!empty($values['preferred_communication_method'])) { $comm = array(); $pcm = array_change_key_case(array_flip(CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'preferred_communication_method')), CASE_LOWER); $preffComm = explode(',', $values['preferred_communication_method']); foreach ($preffComm as $v) { $v = strtolower(trim($v)); if (array_key_exists($v, $pcm)) { $comm[$pcm[$v]] = 1; } } $params['preferred_communication_method'] = $comm; return TRUE; } // format the website params. if (!empty($values['url'])) { static $websiteFields; if (!is_array($websiteFields)) { require_once 'CRM/Core/DAO/Website.php'; $websiteFields = CRM_Core_DAO_Website::fields(); } if (!array_key_exists('website', $params) || !is_array($params['website'])) { $params['website'] = array(); } $websiteCount = count($params['website']); _civicrm_api3_store_values($websiteFields, $values, $params['website'][++$websiteCount]); return TRUE; } // get the formatted location blocks into params - w/ 3.0 format, CRM-4605 if (!empty($values['location_type_id'])) { _civicrm_api3_deprecated_add_formatted_location_blocks($values, $params); return TRUE; } if (isset($values['note'])) { // add a note field if (!isset($params['note'])) { $params['note'] = array(); } $noteBlock = count($params['note']) + 1; $params['note'][$noteBlock] = array(); if (!isset($fields['Note'])) { $fields['Note'] = CRM_Core_DAO_Note::fields(); } // get the current logged in civicrm user $session = CRM_Core_Session::singleton(); $userID = $session->get('userID'); if ($userID) { $values['contact_id'] = $userID; } _civicrm_api3_store_values($fields['Note'], $values, $params['note'][$noteBlock]); return TRUE; } // Check for custom field values if (empty($fields['custom'])) { $fields['custom'] =& CRM_Core_BAO_CustomField::getFields(CRM_Utils_Array::value('contact_type', $values), FALSE, FALSE, NULL, NULL, FALSE, FALSE, FALSE); } foreach ($values as $key => $value) { if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) { // check if it's a valid custom field id if (!array_key_exists($customFieldID, $fields['custom'])) { return civicrm_api3_create_error('Invalid custom field ID'); } else { $params[$key] = $value; } } } }
/** * This function adds the contact variable in $values to the * parameter list $params. For most cases, $values should have length 1. If * the variable being added is a child of Location, a location_type_id must * also be included. If it is a child of phone, a phone_type must be included. * * @param array $values The variable(s) to be added * @param array $params The structured parameter list * * @return bool|CRM_Utils_Error * @access public */ function _crm_add_formatted_param(&$values, &$params) { /* Crawl through the possible classes: * Contact * Individual * Household * Organization * Location * Address * Email * Phone * IM * Note * Custom */ /* Cache the various object fields */ static $fields = null; if ($fields == null) { $fields = array(); } if (isset($values['contact_type'])) { /* we're an individual/household/org property */ if (!isset($fields[$values['contact_type']])) { require_once str_replace('_', DIRECTORY_SEPARATOR, 'CRM_Contact_DAO_' . $values['contact_type']) . '.php'; eval('$fields[' . $values['contact_type'] . '] =& CRM_Contact_DAO_' . $values['contact_type'] . '::fields();'); } _crm_store_values($fields[$values['contact_type']], $values, $params); return true; } if (isset($values['individual_prefix'])) { $params['prefix'] = $values['individual_prefix']; return true; } if (isset($values['individual_suffix'])) { $params['suffix'] = $values['individual_suffix']; return true; } if (isset($values['gender'])) { $params['gender'] = $values['gender']; return true; } if (isset($values['location_type_id'])) { /* find and/or initialize the correct location block in $params */ $locBlock = null; if (!isset($params['location'])) { /* if we don't have a location field yet, make one */ $locBlock = 1; $params['location'][$locBlock] = array('location_type_id' => $values['location_type_id'], 'is_primary' => true); } else { /* search through the location array for a matching loc. type */ foreach ($params['location'] as $key => $loc) { if ($loc['location_type_id'] == $values['location_type_id']) { $locBlock = $key; } } /* if no locBlock has the correct type, make a new one */ if ($locBlock == null) { $locBlock = count($params['location']) + 1; $params['location'][$locBlock] = array('location_type_id' => $values['location_type_id']); } } //add location name if (isset($values['name'])) { $params['location'][$locBlock]['name'] = $values['name']; } /* if this is a phone value, find or create the correct block */ if (isset($values['phone'])) { if (!isset($params['location'][$locBlock]['phone'])) { /* if we don't have a phone array yet, make one */ $params['location'][$locBlock]['phone'] = array(); } /* add a new phone block to the array */ $phoneBlock = count($params['location'][$locBlock]['phone']) + 1; $params['location'][$locBlock]['phone'][$phoneBlock] = array(); if (!isset($fields['Phone'])) { $fields['Phone'] = CRM_Core_DAO_Phone::fields(); } _crm_store_values($fields['Phone'], $values, $params['location'][$locBlock]['phone'][$phoneBlock]); if ($phoneBlock == 1) { $params['location'][$locBlock]['phone'][$phoneBlock]['is_primary'] = true; } return true; } /* If this is an email value, create a new block to store it */ if (isset($values['email'])) { if (!isset($params['location'][$locBlock]['email'])) { $params['location'][$locBlock]['email'] = array(); } /* add a new email block */ $emailBlock = count($params['location'][$locBlock]['email']) + 1; $params['location'][$locBlock]['email'][$emailBlock] = array(); if (!isset($fields['Email'])) { $fields['Email'] = CRM_Core_DAO_Email::fields(); } _crm_store_values($fields['Email'], $values, $params['location'][$locBlock]['email'][$emailBlock]); if ($emailBlock == 1) { $params['location'][$locBlock]['email'][$emailBlock]['is_primary'] = true; } return true; } /* if this is an IM value, create a new block */ if (isset($values['im'])) { if (!isset($params['location'][$locBlock]['im'])) { $params['location'][$locBlock]['im'] = array(); } /* add a new IM block */ $imBlock = count($params['location'][$locBlock]['im']) + 1; $params['location'][$locBlock]['im'][$imBlock] = array(); if (!isset($fields['IM'])) { $fields['IM'] = CRM_Core_DAO_IM::fields(); } _crm_store_values($fields['IM'], $values, $params['location'][$locBlock]['im'][$imBlock]); if ($imBlock == 1) { $params['location'][$locBlock]['im'][$imBlock]['is_primary'] = true; } return true; } /* Otherwise we must be an address */ if (!isset($params['location'][$locBlock]['address'])) { $params['location'][$locBlock]['address'] = array(); } if (!isset($fields['Address'])) { $fields['Address'] = CRM_Core_DAO_Address::fields(); } _crm_store_values($fields['Address'], $values, $params['location'][$locBlock]['address']); $ids = array('county', 'country', 'state_province', 'supplemental_address_1', 'supplemental_address_2', 'StateProvince.name'); foreach ($ids as $id) { if (array_key_exists($id, $values)) { $params['location'][$locBlock]['address'][$id] = $values[$id]; } } return true; } if (isset($values['note'])) { /* add a note field */ if (!isset($params['note'])) { $params['note'] = array(); } $noteBlock = count($params['note']) + 1; $params['note'][$noteBlock] = array(); if (!isset($fields['Note'])) { $fields['Note'] = CRM_Core_DAO_Note::fields(); } _crm_store_values($fields['Note'], $values, $params['note'][$noteBlock]); return true; } /* Check for custom field values */ if ($fields['custom'] == null) { $fields['custom'] =& CRM_Core_BAO_CustomField::getFields($values['contact_type']); } foreach ($values as $key => $value) { if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) { /* check if it's a valid custom field id */ if (!array_key_exists($customFieldID, $fields['custom'])) { return _crm_error('Invalid custom field ID'); } if (!isset($params['custom'])) { $params['custom'] = array(); } // fixed for Import $newMulValues = array(); if ($fields['custom'][$customFieldID][3] == 'CheckBox' || $fields['custom'][$customFieldID][3] == 'Multi-Select') { $value = str_replace("|", ",", $value); $mulValues = explode(',', $value); $custuomOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, true); foreach ($mulValues as $v1) { foreach ($custuomOption as $v2) { if (strtolower($v2['label']) == strtolower(trim($v1))) { $newMulValues[] = $v2['value']; } } } $value = implode(CRM_CORE_BAO_CUSTOMOPTION_VALUE_SEPERATOR, $newMulValues); } else { if ($fields['custom'][$customFieldID][3] == 'Select' || $fields['custom'][$customFieldID][3] == 'Radio') { $custuomOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, true); foreach ($custuomOption as $v2) { if (strtolower($v2['label']) == strtolower(trim($value))) { $value = $v2['value']; break; } } } } $customBlock = count($params['custom']) + 1; $params['custom'][$customBlock] = array('custom_field_id' => $customFieldID, 'value' => $value, 'type' => $fields['custom'][$customFieldID][2], 'name' => $fields['custom'][$customFieldID][0]); } } /* Finally, check for contact fields */ if (!isset($fields['Contact'])) { $fields['Contact'] =& CRM_Contact_DAO_Contact::fields(); } _crm_store_values($fields['Contact'], $values, $params); }
/** * This function adds the contact variable in $values to the * parameter list $params. For most cases, $values should have length 1. If * the variable being added is a child of Location, a location_type_id must * also be included. If it is a child of phone, a phone_type must be included. * * @param array $values The variable(s) to be added * @param array $params The structured parameter list * * @return bool|CRM_Utils_Error * @access public */ function _civicrm_add_formatted_param(&$values, &$params) { /* Crawl through the possible classes: * Contact * Individual * Household * Organization * Location * Address * Email * Phone * IM * Note * Custom */ /* Cache the various object fields */ static $fields = null; if ($fields == null) { $fields = array(); } //first add core contact values since for other Civi modules they are not added require_once 'CRM/Contact/BAO/Contact.php'; $contactFields =& CRM_Contact_DAO_Contact::fields(); _civicrm_store_values($contactFields, $values, $params); if (isset($values['contact_type'])) { /* we're an individual/household/org property */ $fields[$values['contact_type']] = CRM_Contact_DAO_Contact::fields(); _civicrm_store_values($fields[$values['contact_type']], $values, $params); return true; } if (isset($values['individual_prefix'])) { if ($params['prefix_id']) { $prefixes = array(); $prefixes = CRM_Core_PseudoConstant::individualPrefix(); $params['prefix'] = $prefixes[$params['prefix_id']]; } else { $params['prefix'] = $values['individual_prefix']; } return true; } if (isset($values['individual_suffix'])) { if ($params['suffix_id']) { $suffixes = array(); $suffixes = CRM_Core_PseudoConstant::individualSuffix(); $params['suffix'] = $suffixes[$params['suffix_id']]; } else { $params['suffix'] = $values['individual_suffix']; } return true; } //CRM-4575 if (isset($values['email_greeting'])) { if ($params['email_greeting_id']) { $emailGreetings = array(); $emailGreetingFilter = array('contact_type' => CRM_Utils_Array::value('contact_type', $params), 'greeting_type' => 'email_greeting'); $emailGreetings = CRM_Core_PseudoConstant::greeting($emailGreetingFilter); $params['email_greeting'] = $emailGreetings[$params['email_greeting_id']]; } else { $params['email_greeting'] = $values['email_greeting']; } return true; } if (isset($values['postal_greeting'])) { if ($params['postal_greeting_id']) { $postalGreetings = array(); $postalGreetingFilter = array('contact_type' => CRM_Utils_Array::value('contact_type', $params), 'greeting_type' => 'postal_greeting'); $postalGreetings = CRM_Core_PseudoConstant::greeting($postalGreetingFilter); $params['postal_greeting'] = $postalGreetings[$params['postal_greeting_id']]; } else { $params['postal_greeting'] = $values['postal_greeting']; } return true; } if (isset($values['addressee'])) { if ($params['addressee_id']) { $addressee = array(); $addresseeFilter = array('contact_type' => CRM_Utils_Array::value('contact_type', $params), 'greeting_type' => 'addressee'); $addressee = CRM_Core_PseudoConstant::addressee($addresseeFilter); $params['addressee'] = $addressee[$params['addressee_id']]; } else { $params['addressee'] = $values['addressee']; } return true; } if (isset($values['gender'])) { if ($params['gender_id']) { $genders = array(); $genders = CRM_Core_PseudoConstant::gender(); $params['gender'] = $genders[$params['gender_id']]; } else { $params['gender'] = $values['gender']; } return true; } if (isset($values['preferred_communication_method'])) { $comm = array(); $preffComm = array(); $pcm = array(); $pcm = array_change_key_case(array_flip(CRM_Core_PseudoConstant::pcm()), CASE_LOWER); $preffComm = explode(',', $values['preferred_communication_method']); foreach ($preffComm as $v) { $v = strtolower(trim($v)); if (array_key_exists($v, $pcm)) { $comm[$pcm[$v]] = 1; } } $params['preferred_communication_method'] = $comm; return true; } // get the formatted location blocks into params - w/ 3.0 format, CRM-4605 if (CRM_Utils_Array::value('location_type_id', $values)) { _civicrm_add_formatted_location_blocks($values, $params); return true; } if (isset($values['note'])) { /* add a note field */ if (!isset($params['note'])) { $params['note'] = array(); } $noteBlock = count($params['note']) + 1; $params['note'][$noteBlock] = array(); if (!isset($fields['Note'])) { $fields['Note'] = CRM_Core_DAO_Note::fields(); } // get the current logged in civicrm user $session =& CRM_Core_Session::singleton(); $userID = $session->get('userID'); if ($userID) { $values['contact_id'] = $userID; } _civicrm_store_values($fields['Note'], $values, $params['note'][$noteBlock]); return true; } /* Check for custom field values */ if ($fields['custom'] == null) { $fields['custom'] =& CRM_Core_BAO_CustomField::getFields($values['contact_type']); } foreach ($values as $key => $value) { if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) { /* check if it's a valid custom field id */ if (!array_key_exists($customFieldID, $fields['custom'])) { return civicrm_create_error('Invalid custom field ID'); } else { $params[$key] = $value; } } } }
/** * returns the list of fields that can be exported * * @access public * return array */ function &export($prefix = false) { if (!$GLOBALS['_CRM_CORE_DAO_NOTE']['_export']) { $GLOBALS['_CRM_CORE_DAO_NOTE']['_export'] = array(); $fields =& CRM_Core_DAO_Note::fields(); foreach ($fields as $name => $field) { if (CRM_Utils_Array::value('export', $field)) { if ($prefix) { $GLOBALS['_CRM_CORE_DAO_NOTE']['_export']['note'] =& $fields[$name]; } else { $GLOBALS['_CRM_CORE_DAO_NOTE']['_export'][$name] =& $fields[$name]; } } } } return $GLOBALS['_CRM_CORE_DAO_NOTE']['_export']; }