Skip to content

Commit

Permalink
Towards CRM-20759, minor tidy-up
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Jul 2, 2017
1 parent 97e838d commit 857c676
Showing 1 changed file with 18 additions and 32 deletions.
50 changes: 18 additions & 32 deletions CRM/Contact/Import/Parser/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -2278,14 +2278,9 @@ protected function formatContactParameters(&$values, &$params) {
// Custom

// Cache the various object fields
static $fields = NULL;

if ($fields == NULL) {
$fields = array();
}
static $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);

Expand Down Expand Up @@ -2417,50 +2412,41 @@ protected function formatContactParameters(&$values, &$params) {

// get the formatted location blocks into params - w/ 3.0 format, CRM-4605
if (!empty($values['location_type_id'])) {
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)) {
$blockTypes = array(
'phone' => 'Phone',
'email' => 'Email',
'im' => 'IM',
'openid' => 'OpenID',
'phone_ext' => 'Phone',
);
foreach ($blockTypes as $blockEntity => $block) {
if (!array_key_exists($blockEntity, $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($blockEntity, $params) || !is_array($params[$blockEntity])) {
$params[$blockEntity] = array();
}

if (!array_key_exists($block, $fields)) {
$className = "CRM_Core_DAO_$block";
$fields[$block] =& $className::fields();
$fields[$block] = $className::fields();
}

$blockCnt = count($params[$name]);
$blockCnt = count($params[$blockEntity]);

// copy value to dao field name.
if ($name == 'im') {
$values['name'] = $values[$name];
if ($blockEntity == 'im') {
$values['name'] = $values[$blockEntity];
}

_civicrm_api3_store_values($fields[$block], $values,
$params[$name][++$blockCnt]
$params[$blockEntity][++$blockCnt]
);

if (empty($params['id']) && ($blockCnt == 1)) {
$params[$name][$blockCnt]['is_primary'] = TRUE;
$params[$blockEntity][$blockCnt]['is_primary'] = TRUE;
}

// we only process single block at a time.
Expand Down

0 comments on commit 857c676

Please sign in to comment.