X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=api%2Fv3%2FUFGroup.php;h=6f7cc671bce019dbd125a03c687bda7699aee73f;hb=dd3218d2667655b7d271dbc84b20ee3c0e265704;hp=300ce89fb6fbd74c030f23bf09efb2bc835906e7;hpb=c28e17683c9a697a035d17c26f337c2229275673;p=civicrm-core.git diff --git a/api/v3/UFGroup.php b/api/v3/UFGroup.php index 300ce89fb6..6f7cc671bc 100644 --- a/api/v3/UFGroup.php +++ b/api/v3/UFGroup.php @@ -3,7 +3,7 @@ +--------------------------------------------------------------------+ | CiviCRM version 4.6 | +--------------------------------------------------------------------+ - | Copyright CiviCRM LLC (c) 2004-2014 | + | Copyright CiviCRM LLC (c) 2004-2015 | +--------------------------------------------------------------------+ | This file is a part of CiviCRM. | | | @@ -29,8 +29,6 @@ * This api exposes CiviCRM profile group. * * @package CiviCRM_APIv3 - * @subpackage API_UF - * */ /** @@ -67,9 +65,7 @@ function civicrm_api3_uf_group_create($params) { * Returns array of uf groups (profiles) matching a set of one or more group properties. * * @param array $params - * Array of one or more valid. - * property_name=>value pairs. If $params is set - * as null, all surveys will be returned + * Array of properties. If empty, all records will be returned. * * @return array * Array of matching profiles @@ -89,3 +85,76 @@ function civicrm_api3_uf_group_get($params) { function civicrm_api3_uf_group_delete($params) { return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params); } + +/** + * Set default getlist parameters. + * + * @see _civicrm_api3_generic_getlist_defaults + * + * @param array $request + * + * @return array + */ +function _civicrm_api3_uf_group_getlist_defaults(&$request) { + return array( + 'description_field' => array( + 'description', + 'group_type', + ), + 'params' => array( + 'is_active' => 1, + ), + ); +} + +/** + * Format getlist output + * + * @see _civicrm_api3_generic_getlist_output + * + * @param array $result + * @param array $request + * @param string $entity + * @param array $fields + * + * @return array + */ +function _civicrm_api3_uf_group_getlist_output($result, $request, $entity, $fields) { + $output = array(); + if (!empty($result['values'])) { + foreach ($result['values'] as $row) { + $data = array( + 'id' => $row[$request['id_field']], + 'label' => $row[$request['label_field']], + ); + if (!empty($request['description_field'])) { + $data['description'] = array(); + foreach ((array) $request['description_field'] as $field) { + if (!empty($row[$field])) { + // Special formatting for group_type field + if ($field == 'group_type') { + $groupTypes = CRM_UF_Page_Group::extractGroupTypes($row[$field]); + $data['description'][] = CRM_UF_Page_Group::formatGroupTypes($groupTypes); + continue; + } + if (!isset($fields[$field]['pseudoconstant'])) { + $data['description'][] = $row[$field]; + } + else { + $data['description'][] = CRM_Core_PseudoConstant::getLabel( + _civicrm_api3_get_BAO($entity), + $field, + $row[$field] + ); + } + } + } + }; + if (!empty($request['image_field'])) { + $data['image'] = isset($row[$request['image_field']]) ? $row[$request['image_field']] : ''; + } + $output[] = $data; + } + } + return $output; +}