whitespace fixups
[civicrm-core.git] / api / v3 / Generic / Getlist.php
index 779c4c0738b614a6b9d30b76e385112082e2554c..8f27f2cf2855e95269a2c85b28a8f2cdf2b9c172 100644 (file)
@@ -2,9 +2,9 @@
 
 /*
  +--------------------------------------------------------------------+
-| CiviCRM version 4.4                                                |
+| CiviCRM version 4.5                                                |
 +--------------------------------------------------------------------+
-| Copyright CiviCRM LLC (c) 2004-2013                                |
+| Copyright CiviCRM LLC (c) 2004-2014                                |
 +--------------------------------------------------------------------+
 | This file is a part of CiviCRM.                                    |
 |                                                                    |
@@ -34,9 +34,9 @@
 function civicrm_api3_generic_getList($apiRequest) {
   $entity = _civicrm_api_get_entity_name_from_camel($apiRequest['entity']);
   $request = $apiRequest['params'];
-  
+
   _civicrm_api3_generic_getList_defaults($entity, $request);
-  
+
   // Hey api, would you like to format the search params?
   $fnName = "_civicrm_api3_{$entity}_getlist_params";
   $fnName = function_exists($fnName) ? $fnName : '_civicrm_api3_generic_getlist_params';
@@ -53,9 +53,9 @@ function civicrm_api3_generic_getList($apiRequest) {
   $output = array('page_num' => $request['page_num']);
 
   // Limit is set for searching but not fetching by id
-  if (!empty($request['params']['limit'])) {
+  if (!empty($request['params']['options']['limit'])) {
     // If we have an extra result then this is not the last page
-    $last = $request['params']['limit'] - 1;
+    $last = $request['params']['options']['limit'] - 1;
     $output['more_results'] = isset($values[$last]);
     unset($values[$last]);
   }
@@ -82,7 +82,7 @@ function _civicrm_api3_generic_getList_defaults($entity, &$request) {
     'extra' => array(),
   );
   // Find main field from meta
-  foreach (array('sort_name', 'title', 'label', 'name') as $field) {
+  foreach (array('sort_name', 'title', 'label', 'name', 'subject') as $field) {
     if (isset($fields[$field])) {
       $defaults['label_field'] = $defaults['search_field'] = $field;
       break;
@@ -113,11 +113,12 @@ function _civicrm_api3_generic_getList_defaults($entity, &$request) {
   }
   // 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['limit'], $params['offset'], $request['params']['limit'], $request['params']['offset']);
+    $params['options']['limit'] = NULL;
+    unset($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;