Merge custom fields when merging contacts

This commit is contained in:
Nathan Gray 2010-11-29 15:23:16 +00:00
parent ac415a2385
commit c676cf3cc3

View File

@ -1487,6 +1487,8 @@ class addressbook_bo extends addressbook_so
{ {
$this->error = false; $this->error = false;
$account = null; $account = null;
$custom_fields = config::get_customfields('addressbook', true);
$custom_field_list = $this->read_customfields($ids);
foreach(parent::search(array('id'=>$ids),false) as $contact) // $this->search calls the extended search from ui! foreach(parent::search(array('id'=>$ids),false) as $contact) // $this->search calls the extended search from ui!
{ {
if ($contact['account_id']) if ($contact['account_id'])
@ -1499,6 +1501,9 @@ class addressbook_bo extends addressbook_so
$account = $contact; $account = $contact;
continue; continue;
} }
// Add in custom fields
$contact = array_merge($contact, $custom_field_list[$contact['id']]);
$pos = array_search($contact['id'],$ids); $pos = array_search($contact['id'],$ids);
$contacts[$pos] = $contact; $contacts[$pos] = $contact;
} }
@ -1538,6 +1543,14 @@ class addressbook_bo extends addressbook_so
break; break;
default: default:
// Multi-select custom fields can also be merged
if($name[0] == '#') {
$c_name = substr($name, 1);
if($custom_fields[$c_name]['type'] == 'select' && $custom_fields[$c_name]['rows'] > 1) {
if (!is_array($target[$name])) $target[$name] = $target[$name] ? explode(',',$target[$name]) : array();
$target[$name] = implode(',',array_unique(array_merge($target[$name],is_array($value)?$value:explode(',',$value))));
}
}
if (!$target[$name]) $target[$name] = $value; if (!$target[$name]) $target[$name] = $value;
break; break;
} }