本文整理汇总了PHP中CRM_Core_DAO_Address::fields方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_DAO_Address::fields方法的具体用法?PHP CRM_Core_DAO_Address::fields怎么用?PHP CRM_Core_DAO_Address::fields使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Core_DAO_Address
的用法示例。
在下文中一共展示了CRM_Core_DAO_Address::fields方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _civicrm_format_params_v2_to_v3
/**
* function convert params to v3.0 format before add location.
*/
function _civicrm_format_params_v2_to_v3(&$params, $locationTypeId = null)
{
// get the loc type id.
if (!$locationTypeId) {
// get location type.
$locationTypeId = CRM_Utils_Array::value('location_type_id', $params);
if (!$locationTypeId && array_key_exists('location_type', $params)) {
require_once 'CRM/Core/PseudoConstant.php';
$locTypes =& CRM_Core_PseudoConstant::locationType();
$locType = $params['location_type'];
if (is_array($params['location_type'])) {
$locType = array_pop($params['location_type']);
}
$locationTypeId = CRM_Utils_Array::key($locType, $locTypes);
}
}
// convert params into v3.0 format.
$primary = $billing = array();
$blocks = array('Email', 'Phone', 'IM', 'OpenID');
// format params array.
$firstBlockCount = null;
foreach ($blocks as $block) {
require_once str_replace('_', DIRECTORY_SEPARATOR, "CRM_Core_DAO_" . $block) . ".php";
eval('$fields =& CRM_Core_DAO_' . $block . '::fields( );');
$name = strtolower($block);
$blockCount = 0;
if (CRM_Utils_Array::value($name, $params)) {
if (is_array($params[$name])) {
$values = $params[$name];
$params[$name] = array();
foreach ($values as $val) {
_civicrm_store_values($fields, $val, $params[$name][++$blockCount]);
// check for primary and billing.
if (CRM_Utils_Array::value('is_primary', $val)) {
$primary[$name][$blockCount] = true;
}
if (CRM_Utils_Array::value('is_billing', $val)) {
$primary[$name][$blockCount] = true;
}
if (!$firstBlockCount) {
$firstBlockCount = $blockCount;
}
}
} else {
//need to get ids.
if (in_array($name, array('im', 'phone'))) {
require_once 'CRM/Core/PseudoConstant.php';
if ($name == 'im') {
CRM_Utils_Array::lookupValue($params, 'provider', CRM_Core_PseudoConstant::IMProvider(), true);
} else {
CRM_Utils_Array::lookupValue($params, 'phone_type', CRM_Core_PseudoConstant::phoneType(), true);
}
}
$locValues[$name] = array();
_civicrm_store_values($fields, $params, $locValues[$name][++$blockCount]);
$params[$name] = $locValues[$name];
$firstBlockCount = $blockCount;
unset($locValues[$name]);
}
// make first block as default primary when is_primary
// is not set in sub array and set in main params array.
if (!CRM_Utils_Array::value($name, $primary) && CRM_Utils_Array::value('is_primary', $params)) {
$primary[$name][$firstBlockCount] = true;
$params[$name][$firstBlockCount]['is_primary'] = true;
}
if (!CRM_Utils_Array::value($name, $billing) && CRM_Utils_Array::value('is_billing', $params)) {
$billing[$name][$firstBlockCount] = true;
$params[$name][$firstBlockCount]['is_billing'] = true;
}
}
}
//get the address fields.
$addressCount = 1;
$ids = array('county', 'country_id', 'country', 'state_province_id', 'state_province', 'supplemental_address_1', 'supplemental_address_2', 'StateProvince.name', 'city', 'street_address');
$addressTaken = false;
foreach ($ids as $id) {
if (array_key_exists($id, $params)) {
if (!$addressTaken) {
require_once 'CRM/Core/DAO/Address.php';
$fields =& CRM_Core_DAO_Address::fields();
_civicrm_store_values($fields, $params, $params['address'][$addressCount]);
$addressTaken = true;
}
$params['address'][$addressCount][$id] = $params[$id];
unset($params[$id]);
}
}
// format state and country.
foreach (array('state_province', 'country') as $field) {
$fName = $field == 'state_province' ? 'stateProvinceAbbreviation' : 'countryIsoCode';
if (CRM_Utils_Array::value('address', $params) && CRM_Utils_Array::value($field, $params['address'][$addressCount]) && is_numeric($params['address'][$addressCount][$field])) {
$fValue =& $params['address'][$addressCount][$field];
eval('$fValue = CRM_Core_PseudoConstant::' . $fName . '( $fValue );');
//kill the reference.
unset($fValue);
}
}
//.........这里部分代码省略.........
示例2: copyHouseholdAddress
/**
* Function to Copy household address, if use_household_address option is checked.
*
* @param array $params the input form values
*
* @return void
* @access public
* @static
*/
static function copyHouseholdAddress(&$params)
{
if ($params['shared_household']) {
$params['mail_to_household_id'] = $params['shared_household'];
}
if (!$params['mail_to_household_id']) {
CRM_Core_Error::statusBounce(ts("Shared Household-ID not found."));
}
$locParams = array('version' => '3.0', 'contact_id' => $params['mail_to_household_id']);
$location_types = array();
require_once 'api/v2/Location.php';
$values =& _civicrm_location_get($locParams, $location_types);
$addressFields = CRM_Core_DAO_Address::fields();
foreach ($addressFields as $key => $val) {
if (!CRM_Utils_Array::value($key, $values['address'][1])) {
$values['address'][1][$key] = "";
}
}
if ($is_billing = $params['address'][1]['is_billing']) {
$values['address'][1]['is_billing'] = $is_billing;
}
if ($values['address'][1]['country_id'] == "null") {
$values['address'][1]['country_id'] = 0;
}
if ($values['address'][1]['state_province_id'] == "null") {
$values['address'][1]['state_province_id'] = 0;
}
$params['address'][1] = $values['address'][1];
// unset all the ids and unwanted fields
$unsetFields = array('id', 'location_id', 'timezone', 'note');
foreach ($unsetFields as $fld) {
unset($params['address'][1][$fld]);
}
}
示例3: _civicrm_api3_deprecated_add_formatted_location_blocks
/**
* This function format location blocks w/ v3.0 format.
*
* @param array $values
* The variable(s) to be added.
* @param array $params
* The structured parameter list.
*
* @return bool
*/
function _civicrm_api3_deprecated_add_formatted_location_blocks(&$values, &$params)
{
static $fields = NULL;
if ($fields == NULL) {
$fields = array();
}
foreach (array('Phone', 'Email', 'IM', 'OpenID', 'Phone_Ext') as $block) {
$name = strtolower($block);
if (!array_key_exists($name, $values)) {
continue;
}
if ($name == 'phone_ext') {
$block = 'Phone';
}
// block present in value array.
if (!array_key_exists($name, $params) || !is_array($params[$name])) {
$params[$name] = array();
}
if (!array_key_exists($block, $fields)) {
$className = "CRM_Core_DAO_{$block}";
$fields[$block] =& $className::fields();
}
$blockCnt = count($params[$name]);
// copy value to dao field name.
if ($name == 'im') {
$values['name'] = $values[$name];
}
_civicrm_api3_store_values($fields[$block], $values, $params[$name][++$blockCnt]);
if (empty($params['id']) && $blockCnt == 1) {
$params[$name][$blockCnt]['is_primary'] = TRUE;
}
// we only process single block at a time.
return TRUE;
}
// handle address fields.
if (!array_key_exists('address', $params) || !is_array($params['address'])) {
$params['address'] = array();
}
$addressCnt = 1;
foreach ($params['address'] as $cnt => $addressBlock) {
if (CRM_Utils_Array::value('location_type_id', $values) == CRM_Utils_Array::value('location_type_id', $addressBlock)) {
$addressCnt = $cnt;
break;
}
$addressCnt++;
}
if (!array_key_exists('Address', $fields)) {
require_once 'CRM/Core/DAO/Address.php';
$fields['Address'] = CRM_Core_DAO_Address::fields();
}
// Note: we doing multiple value formatting here for address custom fields, plus putting into right format.
// The actual formatting (like date, country ..etc) for address custom fields is taken care of while saving
// the address in CRM_Core_BAO_Address::create method
if (!empty($values['location_type_id'])) {
static $customFields = array();
if (empty($customFields)) {
$customFields = CRM_Core_BAO_CustomField::getFields('Address');
}
// make a copy of values, as we going to make changes
$newValues = $values;
foreach ($values as $key => $val) {
$customFieldID = CRM_Core_BAO_CustomField::getKeyID($key);
if ($customFieldID && array_key_exists($customFieldID, $customFields)) {
// mark an entry in fields array since we want the value of custom field to be copied
$fields['Address'][$key] = NULL;
$htmlType = CRM_Utils_Array::value('html_type', $customFields[$customFieldID]);
switch ($htmlType) {
case 'CheckBox':
case 'AdvMulti-Select':
case 'Multi-Select':
if ($val) {
$mulValues = explode(',', $val);
$customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, TRUE);
$newValues[$key] = array();
foreach ($mulValues as $v1) {
foreach ($customOption as $v2) {
if (strtolower($v2['label']) == strtolower(trim($v1)) || strtolower($v2['value']) == strtolower(trim($v1))) {
if ($htmlType == 'CheckBox') {
$newValues[$key][$v2['value']] = 1;
} else {
$newValues[$key][] = $v2['value'];
}
}
}
}
}
break;
}
}
}
//.........这里部分代码省略.........
示例4: _civicrm_add_formatted_location_blocks
/**
* This function format location blocks w/ v3.0 format.
*
* @param array $values The variable(s) to be added
* @param array $params The structured parameter list
*
* @return bool
* @access public
*/
function _civicrm_add_formatted_location_blocks(&$values, &$params)
{
static $fields = null;
if ($fields == null) {
$fields = array();
}
foreach (array('Phone', 'Email', 'IM', 'OpenID') as $block) {
$name = strtolower($block);
if (!array_key_exists($name, $values)) {
continue;
}
// block present in value array.
if (!array_key_exists($name, $params) || !is_array($params[$name])) {
$params[$name] = array();
}
if (!array_key_exists($block, $fields)) {
require_once str_replace('_', DIRECTORY_SEPARATOR, "CRM_Core_DAO_" . $block) . ".php";
eval('$fields[$block] =& CRM_Core_DAO_' . $block . '::fields( );');
}
$blockCnt = count($params[$name]);
// copy value to dao field name.
if ($name == 'im') {
$values['name'] = $values[$name];
}
_civicrm_store_values($fields[$block], $values, $params[$name][++$blockCnt]);
if ($blockCnt == 1) {
$params[$name][$blockCnt]['is_primary'] = true;
}
// we only process single block at a time.
return true;
}
// handle address fields.
if (!array_key_exists('address', $params) || !is_array($params['address'])) {
$params['address'] = array();
}
$addressCnt = 1;
foreach ($params['address'] as $cnt => $addressBlock) {
if (CRM_Utils_Array::value('location_type_id', $values) == CRM_Utils_Array::value('location_type_id', $addressBlock)) {
$addressCnt = $cnt;
break;
}
$addressCnt++;
}
if (!array_key_exists('Address', $fields)) {
require_once 'CRM/Core/DAO/Address.php';
$fields['Address'] =& CRM_Core_DAO_Address::fields();
}
_civicrm_store_values($fields['Address'], $values, $params['address'][$addressCnt]);
$addressFields = array('county', 'country', 'state_province', 'supplemental_address_1', 'supplemental_address_2', 'StateProvince.name');
foreach ($addressFields as $field) {
if (array_key_exists($field, $values)) {
if (!array_key_exists('address', $params)) {
$params['address'] = array();
}
$params['address'][$addressCnt][$field] = $values[$field];
}
}
if ($addressCnt == 1) {
$params['address'][$addressCnt]['is_primary'] = true;
}
return true;
}
示例5: _crm_add_formatted_param
/**
* 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();
//.........这里部分代码省略.........
示例6: array
/**
* returns the list of fields that can be exported
*
* @access public
* return array
*/
function &export($prefix = false)
{
if (!$GLOBALS['_CRM_CORE_DAO_ADDRESS']['_export']) {
$GLOBALS['_CRM_CORE_DAO_ADDRESS']['_export'] = array();
$fields =& CRM_Core_DAO_Address::fields();
foreach ($fields as $name => $field) {
if (CRM_Utils_Array::value('export', $field)) {
if ($prefix) {
$GLOBALS['_CRM_CORE_DAO_ADDRESS']['_export']['address'] =& $fields[$name];
} else {
$GLOBALS['_CRM_CORE_DAO_ADDRESS']['_export'][$name] =& $fields[$name];
}
}
}
$GLOBALS['_CRM_CORE_DAO_ADDRESS']['_export'] = array_merge($GLOBALS['_CRM_CORE_DAO_ADDRESS']['_export'], CRM_Core_DAO_StateProvince::export(true));
$GLOBALS['_CRM_CORE_DAO_ADDRESS']['_export'] = array_merge($GLOBALS['_CRM_CORE_DAO_ADDRESS']['_export'], CRM_Core_DAO_Country::export(true));
}
return $GLOBALS['_CRM_CORE_DAO_ADDRESS']['_export'];
}
示例7: crm_update_location
/**
* Update a specified location with the provided property values.
*
* @param object $contact A valid Contact object (passed by reference).
* @param string $location_id Valid (db-level) id for location to be updated.
* @param Array $params Associative array of property name/value pairs to be updated
*
* @return Location object with updated property values
*
* @access public
*
*/
function crm_update_location(&$contact, $location_id, $params)
{
_crm_initialize();
if (!isset($contact->id)) {
return _crm_error('$contact is not valid contact datatype');
}
$locationId = (int) $location_id;
if ($locationId == 0) {
return _crm_error('missing or invalid $location_id');
}
// $locationNumber is the contact-level number of the location (1, 2, 3, etc.)
$locationNumber = null;
$locations =& crm_get_locations($contact);
foreach ($locations as $locNumber => $locValue) {
if ($locValue->id == $locationId) {
$locationNumber = $locNumber;
break;
}
}
if (!$locationNumber) {
return _crm_error('invalid $location_id');
}
$values = array('contact_id' => $contact->id, 'location' => array($locationNumber => array()));
$loc =& $values['location'][$locationNumber];
$loc['address'] = array();
require_once 'CRM/Core/DAO/Address.php';
$fields =& CRM_Core_DAO_Address::fields();
_crm_store_values($fields, $params, $loc['address']);
//$ids = array( 'county', 'country_id', 'state_province_id', 'supplemental_address_1', 'supplemental_address_2', 'StateProvince.name' );
$ids = array('county', 'country_id', 'country', 'state_province_id', 'state_province', 'supplemental_address_1', 'supplemental_address_2', 'StateProvince.name', 'street_address');
foreach ($ids as $id) {
if (array_key_exists($id, $params)) {
$loc['address'][$id] = $params[$id];
}
}
if (is_numeric($loc['address']['state_province'])) {
$loc['address']['state_province'] = CRM_Core_PseudoConstant::stateProvinceAbbreviation($loc['address']['state_province']);
}
if (is_numeric($loc['address']['country'])) {
$loc['address']['country'] = CRM_Core_PseudoConstant::countryIsoCode($loc['address']['country']);
}
if (array_key_exists('location_type_id', $params)) {
$loc['location_type_id'] = $params['location_type_id'];
}
if (array_key_exists('location_type', $params)) {
$locTypes =& CRM_Core_PseudoConstant::locationType();
$loc['location_type_id'] = CRM_Utils_Array::key($params['location_type'], $locTypes);
}
if (array_key_exists('name', $params)) {
$loc['name'] = $params['name'];
}
if (array_key_exists('is_primary', $params)) {
$loc['is_primary'] = (int) $params['is_primary'];
}
$loc['id'] = $locationId;
$blocks = array('Email', 'Phone', 'IM');
foreach ($blocks as $block) {
$name = strtolower($block);
$loc[$name] = array();
if ($params[$name]) {
$count = 1;
foreach ($params[$name] as $val) {
CRM_Core_DAO::storeValues($val, $loc[$name][$count++]);
}
}
}
$par = array('id' => $contact->id, 'contact_id' => $contact->id);
$contact = CRM_Contact_BAO_Contact::retrieve($par, $defaults, $ids);
CRM_Contact_BAO_Contact::resolveDefaults($values, true);
$location = CRM_Core_BAO_Location::add($values, $ids, $locationNumber);
return $location;
}
示例8: _civicrm_add_formatted_location_blocks
/**
* This function format location blocks w/ v3.0 format.
*
* @param array $values The variable(s) to be added
* @param array $params The structured parameter list
*
* @return bool
* @access public
*/
function _civicrm_add_formatted_location_blocks(&$values, &$params)
{
static $fields = NULL;
if ($fields == NULL) {
$fields = array();
}
foreach (array('Phone', 'Email', 'IM', 'OpenID') as $block) {
$name = strtolower($block);
if (!array_key_exists($name, $values)) {
continue;
}
// block present in value array.
if (!array_key_exists($name, $params) || !is_array($params[$name])) {
$params[$name] = array();
}
if (!array_key_exists($block, $fields)) {
require_once str_replace('_', DIRECTORY_SEPARATOR, "CRM_Core_DAO_" . $block) . ".php";
eval('$fields[$block] =& CRM_Core_DAO_' . $block . '::fields( );');
}
$blockCnt = count($params[$name]);
// copy value to dao field name.
if ($name == 'im') {
$values['name'] = $values[$name];
}
_civicrm_store_values($fields[$block], $values, $params[$name][++$blockCnt]);
if (!CRM_Utils_Array::value('id', $params) && $blockCnt == 1) {
$params[$name][$blockCnt]['is_primary'] = TRUE;
}
// we only process single block at a time.
return TRUE;
}
// handle address fields.
if (!array_key_exists('address', $params) || !is_array($params['address'])) {
$params['address'] = array();
}
$addressCnt = 1;
foreach ($params['address'] as $cnt => $addressBlock) {
if (CRM_Utils_Array::value('location_type_id', $values) == CRM_Utils_Array::value('location_type_id', $addressBlock)) {
$addressCnt = $cnt;
break;
}
$addressCnt++;
}
if (!array_key_exists('Address', $fields)) {
require_once 'CRM/Core/DAO/Address.php';
$fields['Address'] = CRM_Core_DAO_Address::fields();
}
_civicrm_store_values($fields['Address'], $values, $params['address'][$addressCnt]);
$addressFields = array('county', 'country', 'state_province', 'supplemental_address_1', 'supplemental_address_2', 'StateProvince.name');
foreach ($addressFields as $field) {
if (array_key_exists($field, $values)) {
if (!array_key_exists('address', $params)) {
$params['address'] = array();
}
$params['address'][$addressCnt][$field] = $values[$field];
}
}
//Handle Address Custom data
$fields['address_custom'] = CRM_Core_BAO_CustomField::getFields('Address');
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['address_custom'])) {
$type = $fields['address_custom'][$customFieldID]['html_type'];
_civicrm_add_custom_formatted_param($customFieldID, $key, $value, $params['address'][$addressCnt], $type);
} else {
return civicrm_create_error('Invalid custom field ID');
}
}
}
if ($addressCnt == 1) {
$params['address'][$addressCnt]['is_primary'] = TRUE;
}
return TRUE;
}