Commit | Line | Data |
---|---|---|
b4ee829e | 1 | <?php |
627adbf9 | 2 | |
b4ee829e | 3 | /* |
627adbf9 | 4 | +--------------------------------------------------------------------+ |
fee14197 | 5 | | CiviCRM version 5 | |
627adbf9 JV |
6 | +--------------------------------------------------------------------+ |
7 | | Copyright Chirojeugd-Vlaanderen vzw 2015 | | |
8 | +--------------------------------------------------------------------+ | |
9 | | This file is a part of CiviCRM. | | |
10 | | | | |
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. | | |
14 | | | | |
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. | | |
19 | | | | |
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 | +--------------------------------------------------------------------+ | |
b4ee829e JV |
27 | */ |
28 | ||
29 | /** | |
30 | * This api exposes CiviCRM saved searches. | |
31 | * | |
32 | * @package CiviCRM_APIv3 | |
33 | */ | |
34 | ||
35 | /** | |
627adbf9 | 36 | * Create or update a saved search. |
b4ee829e JV |
37 | * |
38 | * @param array $params | |
627adbf9 | 39 | * Associative array of property name-value pairs to insert in new saved search. |
f90f330b | 40 | * |
7c31ae57 SL |
41 | * @return array |
42 | * api result array | |
627adbf9 | 43 | * {@getfields saved_search_create} |
f90f330b | 44 | * |
45 | * @throws \API_Exception | |
46 | * | |
47 | * @example SavedSearch/Create.php Std create example. | |
627adbf9 | 48 | * @access public |
b4ee829e JV |
49 | */ |
50 | function civicrm_api3_saved_search_create($params) { | |
a25b46e9 | 51 | $result = _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'SavedSearch'); |
d30f435f JV |
52 | _civicrm_api3_saved_search_result_cleanup($result); |
53 | return $result; | |
b4ee829e JV |
54 | } |
55 | ||
fe38e286 CW |
56 | /** |
57 | * @param array $fields | |
58 | */ | |
59 | function _civicrm_api3_saved_search_create_spec(&$fields) { | |
60 | $fields['form_values']['api.aliases'][] = 'formValues'; | |
f90f330b | 61 | $fields['form_values']['api.required'] = TRUE; |
fe38e286 CW |
62 | } |
63 | ||
b4ee829e | 64 | /** |
627adbf9 | 65 | * Delete an existing saved search. |
b4ee829e JV |
66 | * |
67 | * @param array $params | |
627adbf9 JV |
68 | * Associative array of property name-value pairs. $params['id'] should be |
69 | * the ID of the saved search to be deleted. | |
f90f330b | 70 | * |
7c31ae57 SL |
71 | * @return array |
72 | * api result array | |
627adbf9 | 73 | * {@getfields saved_search_delete} |
f90f330b | 74 | * |
75 | * @throws \API_Exception | |
76 | * @throws \CiviCRM_API3_Exception | |
77 | * | |
78 | * @example SavedSearch/Delete.php Std delete example. | |
627adbf9 | 79 | * @access public |
b4ee829e JV |
80 | */ |
81 | function civicrm_api3_saved_search_delete($params) { | |
82 | return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params); | |
83 | } | |
84 | ||
85 | /** | |
86 | * Retrieve one or more saved search(es). | |
87 | * | |
88 | * @param array $params | |
627adbf9 JV |
89 | * An associative array of name-value pairs. |
90 | * @example SavedSearch/Get.php Std get example. | |
7c31ae57 SL |
91 | * @return array |
92 | * api result array | |
627adbf9 JV |
93 | * {@getfields saved_search_get} |
94 | * @access public | |
b4ee829e JV |
95 | */ |
96 | function civicrm_api3_saved_search_get($params) { | |
d30f435f JV |
97 | $result = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); |
98 | _civicrm_api3_saved_search_result_cleanup($result); | |
99 | return $result; | |
100 | } | |
101 | ||
102 | /** | |
db2d6c10 CW |
103 | * Unserialize the form_values field in SavedSearch API results. |
104 | * | |
105 | * Note: APIv4 handles serialization automatically based on metadata. | |
d30f435f JV |
106 | * |
107 | * @param array $result API result to be cleaned up. | |
108 | */ | |
109 | function _civicrm_api3_saved_search_result_cleanup(&$result) { | |
859c2bc3 | 110 | if (isset($result['values']) && is_array($result['values'])) { |
db2d6c10 | 111 | // Only run if there are values (getCount for example does not return values). |
f00c38c8 | 112 | foreach ($result['values'] as $key => $value) { |
db2d6c10 CW |
113 | if (isset($value['form_values'])) { |
114 | $result['values'][$key]['form_values'] = CRM_Utils_String::unserialize($value['form_values']); | |
115 | } | |
f00c38c8 | 116 | } |
d30f435f | 117 | } |
b4ee829e | 118 | } |