4 +--------------------------------------------------------------------+
6 +--------------------------------------------------------------------+
7 | Copyright Chirojeugd-Vlaanderen vzw 2015 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
30 * This api exposes CiviCRM saved searches.
32 * @package CiviCRM_APIv3
36 * Create or update a saved search.
38 * @param array $params
39 * Associative array of property name-value pairs to insert in new saved search.
43 * {@getfields saved_search_create}
45 * @throws \API_Exception
47 * @example SavedSearch/Create.php Std create example.
50 function civicrm_api3_saved_search_create($params) {
51 $result = _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__
), $params, 'SavedSearch');
52 _civicrm_api3_saved_search_result_cleanup($result);
57 * @param array $fields
59 function _civicrm_api3_saved_search_create_spec(&$fields) {
60 $fields['form_values']['api.aliases'][] = 'formValues';
61 $fields['form_values']['api.required'] = TRUE;
65 * Delete an existing saved search.
67 * @param array $params
68 * Associative array of property name-value pairs. $params['id'] should be
69 * the ID of the saved search to be deleted.
73 * {@getfields saved_search_delete}
75 * @throws \API_Exception
76 * @throws \CiviCRM_API3_Exception
78 * @example SavedSearch/Delete.php Std delete example.
81 function civicrm_api3_saved_search_delete($params) {
82 return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__
), $params);
86 * Retrieve one or more saved search(es).
88 * @param array $params
89 * An associative array of name-value pairs.
90 * @example SavedSearch/Get.php Std get example.
93 * {@getfields saved_search_get}
96 function civicrm_api3_saved_search_get($params) {
97 $result = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__
), $params);
98 _civicrm_api3_saved_search_result_cleanup($result);
103 * Unserialize the form_values field in SavedSearch API results.
105 * Note: APIv4 handles serialization automatically based on metadata.
107 * @param array $result API result to be cleaned up.
109 function _civicrm_api3_saved_search_result_cleanup(&$result) {
110 if (isset($result['values']) && is_array($result['values'])) {
111 // Only run if there are values (getCount for example does not return values).
112 foreach ($result['values'] as $key => $value) {
113 if (isset($value['form_values'])) {
114 $result['values'][$key]['form_values'] = CRM_Utils_String
::unserialize($value['form_values']);