projects
/
civicrm-core.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge pull request #2792 from deepak-srivastava/dedupe-hooks
[civicrm-core.git]
/
api
/
v3
/
Generic
/
Getlist.php
diff --git
a/api/v3/Generic/Getlist.php
b/api/v3/Generic/Getlist.php
index 12bad54b9f5499e7f0a530ee26b1dac4b19a73a4..7a5255f3bb77bc9a5c16fa1dcfa1ce91f789a36a 100644
(file)
--- a/
api/v3/Generic/Getlist.php
+++ b/
api/v3/Generic/Getlist.php
@@
-2,9
+2,9
@@
/*
+--------------------------------------------------------------------+
/*
+--------------------------------------------------------------------+
-| CiviCRM version 4.
4
|
+| CiviCRM version 4.
5
|
+--------------------------------------------------------------------+
+--------------------------------------------------------------------+
-| Copyright CiviCRM LLC (c) 2004-201
3
|
+| Copyright CiviCRM LLC (c) 2004-201
4
|
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
@@
-50,12
+50,15
@@
function civicrm_api3_generic_getList($apiRequest) {
$fnName = function_exists($fnName) ? $fnName : '_civicrm_api3_generic_getlist_output';
$values = $fnName($result, $request);
$fnName = function_exists($fnName) ? $fnName : '_civicrm_api3_generic_getlist_output';
$values = $fnName($result, $request);
- $output = array(
+ $output = array('page_num' => $request['page_num']);
+
+ // Limit is set for searching but not fetching by id
+ if (!empty($request['params']['options']['limit'])) {
// If we have an extra result then this is not the last page
// If we have an extra result then this is not the last page
- 'more_results' => isset($values[10]),
- 'page_num' => $request['page_num'],
- );
- unset($values[10]);
+ $last = $request['params']['options']['limit'] - 1;
+ $output['more_results'] = isset($values[$last]);
+
unset($values[$last]
);
+ }
return civicrm_api3_create_success($values, $request['params'], $entity, 'getlist', CRM_Core_DAO::$_nullObject, $output);
}
return civicrm_api3_create_success($values, $request['params'], $entity, 'getlist', CRM_Core_DAO::$_nullObject, $output);
}
@@
-73,8
+76,10
@@
function _civicrm_api3_generic_getList_defaults($entity, &$request) {
'page_num' => 1,
'input' => '',
'image_field' => NULL,
'page_num' => 1,
'input' => '',
'image_field' => NULL,
- 'id_field' => 'id',
+ 'id_field' => $entity == 'option_value' ? 'value' : 'id',
+ 'description_field' => array(),
'params' => array(),
'params' => array(),
+ 'extra' => array(),
);
// Find main field from meta
foreach (array('sort_name', 'title', 'label', 'name') as $field) {
);
// Find main field from meta
foreach (array('sort_name', 'title', 'label', 'name') as $field) {
@@
-83,10
+88,10
@@
function _civicrm_api3_generic_getList_defaults($entity, &$request) {
break;
}
}
break;
}
}
+ // Find fields to be used for the description
foreach (array('description') as $field) {
if (isset($fields[$field])) {
foreach (array('description') as $field) {
if (isset($fields[$field])) {
- $defaults['description_field'] = $field;
- break;
+ $defaults['description_field'][] = $field;
}
}
$resultsPerPage = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'search_autocomplete_count', NULL, 10);
}
}
$resultsPerPage = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'search_autocomplete_count', NULL, 10);
@@
-108,9
+113,11
@@
function _civicrm_api3_generic_getList_defaults($entity, &$request) {
}
// When looking up a field e.g. displaying existing record
if (!empty($request['id'])) {
}
// When looking up a field e.g. displaying existing record
if (!empty($request['id'])) {
- if (is_string($request['id']) && strpos(
',', $request['id']
)) {
- $request['id'] = explode(',',
$request['id']
);
+ if (is_string($request['id']) && strpos(
$request['id'], ','
)) {
+ $request['id'] = explode(',',
trim($request['id'], ', ')
);
}
}
+ // Don't run into search limits when prefilling selection
+ unset($params['options']['limit'], $params['options']['offset'], $request['params']['options']['limit'], $request['params']['options']['offset']);
$params[$request['id_field']] = is_array($request['id']) ? array('IN' => $request['id']) : $request['id'];
}
$request['params'] += $params;
$params[$request['id_field']] = is_array($request['id']) ? array('IN' => $request['id']) : $request['id'];
}
$request['params'] += $params;
@@
-127,9
+134,9
@@
function _civicrm_api3_generic_getlist_params(&$request) {
$fieldsToReturn[] = $request['image_field'];
}
if (!empty($request['description_field'])) {
$fieldsToReturn[] = $request['image_field'];
}
if (!empty($request['description_field'])) {
- $fieldsToReturn
[] = $request['description_field']
;
+ $fieldsToReturn
= array_merge($fieldsToReturn, (array) $request['description_field'])
;
}
}
- $request['params']['return'] =
$fieldsToReturn
;
+ $request['params']['return'] =
array_unique(array_merge($fieldsToReturn, $request['extra']))
;
}
/**
}
/**
@@
-149,11
+156,19
@@
function _civicrm_api3_generic_getlist_output($result, $request) {
'label' => $row[$request['label_field']],
);
if (!empty($request['description_field'])) {
'label' => $row[$request['label_field']],
);
if (!empty($request['description_field'])) {
- $data['description'] = isset($row[$request['description_field']]) ? $row[$request['description_field']] : '';
+ $data['description'] = array();
+ foreach ((array) $request['description_field'] as $field) {
+ if (!empty($row[$field])) {
+ $data['description'][] = $row[$field];
+ }
+ }
};
if (!empty($request['image_field'])) {
$data['image'] = isset($row[$request['image_field']]) ? $row[$request['image_field']] : '';
};
if (!empty($request['image_field'])) {
$data['image'] = isset($row[$request['image_field']]) ? $row[$request['image_field']] : '';
- };
+ }
+ foreach ($request['extra'] as $field) {
+ $data['extra'][$field] = isset($row[$field]) ? $row[$field] : NULL;
+ }
$output[] = $data;
}
}
$output[] = $data;
}
}