X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=api%2Fv3%2FContact.php;h=bbd2f5e7c41f848eea70174d2899c78ae1c5092d;hb=6628866da4eb17b8ff190928d8afdbee11526ae6;hp=e0e7e8d620d18c04dccdb5fce9afca79e66206cb;hpb=fac14a5c5e0f267d1df084081bdd80c37a9e9875;p=civicrm-core.git diff --git a/api/v3/Contact.php b/api/v3/Contact.php index e0e7e8d620..bbd2f5e7c4 100644 --- a/api/v3/Contact.php +++ b/api/v3/Contact.php @@ -1,9 +1,9 @@ $params['current_employer'], + ); $dedupParams = CRM_Dedupe_Finder::formatParams($organizationParams, 'Organization'); @@ -351,6 +352,17 @@ function _civicrm_api3_contact_check_params( &$params, $dupeCheck = true, $dupeE if (empty($params['employer_id']) && (count($dupeIds) > 1)) { throw new API_Exception('Found more than one Organisation with same Name.'); } + + if ($dupeIds) { + $params['employer_id'] = $dupeIds[0]; + } + else { + $result = civicrm_api3('contact', 'create', array( + 'organization_name' => $params['current_employer'], + 'contact_type' => 'Organization' + )); + $params['employer_id'] = $result['id']; + } } return NULL; @@ -891,7 +903,7 @@ WHERE $whereClause /** - * Overrides _civicrm_api3_generic_getlist_params. + * @see _civicrm_api3_generic_getlist_params * * @param $request array */ @@ -923,15 +935,18 @@ function _civicrm_api3_contact_getlist_params(&$request) { if(!in_array($searchField, $list)) { $list[] = $searchField; } + $request['description_field'] = $list; $list[] = 'contact_type'; - $request['params']['return'] = $list; + $request['params']['return'] = array_unique(array_merge($list, $request['extra'])); $request['params']['options']['sort'] = 'sort_name'; // Contact api doesn't support array(LIKE => 'foo') syntax - $request['params'][$request['search_field']] = $request['input']; + if (!empty($request['input'])) { + $request['params'][$request['search_field']] = $request['input']; + } } /** - * Overrides _civicrm_api3_generic_getlist_output + * @see _civicrm_api3_generic_getlist_output * * @param $result array * @param $request array @@ -941,24 +956,36 @@ function _civicrm_api3_contact_getlist_params(&$request) { function _civicrm_api3_contact_getlist_output($result, $request) { $output = array(); if (!empty($result['values'])) { + $addressFields = array_intersect(array('street_address', 'city', 'state_province', 'country'), $request['params']['return']); foreach ($result['values'] as $row) { $data = array( 'id' => $row[$request['id_field']], 'label' => $row[$request['label_field']], + 'description' => array(), ); - $description = array(); - foreach ($request['params']['return'] as $item) { - if (!strpos($item, '_name') && $item != 'contact_type' && !empty($row[$item])) { - $description[] = $row[$item]; + foreach ($request['description_field'] as $item) { + if (!strpos($item, '_name') && !in_array($item, $addressFields) && !empty($row[$item])) { + $data['description'][] = $row[$item]; + } + } + $address = array(); + foreach($addressFields as $item) { + if (!empty($row[$item])) { + $address[] = $row[$item]; } } - $data['description'] = implode(' :: ', $description); + if ($address) { + $data['description'][] = implode(' ', $address); + } if (!empty($request['image_field'])) { $data['image'] = isset($row[$request['image_field']]) ? $row[$request['image_field']] : ''; } else { $data['icon_class'] = $row['contact_type']; } + foreach ($request['extra'] as $field) { + $data['extra'][$field] = isset($row[$field]) ? $row[$field] : NULL; + } $output[] = $data; } }