X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=api%2Fv3%2FSavedSearch.php;h=c502ef9a1ace5b7f6ef56bb97480d82350aa3632;hb=cc7968d8a8cc3b6008257018642334d5424be8d9;hp=d999004370fc55058871666576ea9bcc38b52855;hpb=627adbf9a46d9a1240738dbed4d836e3a43ac66c;p=civicrm-core.git diff --git a/api/v3/SavedSearch.php b/api/v3/SavedSearch.php index d999004370..c502ef9a1a 100644 --- a/api/v3/SavedSearch.php +++ b/api/v3/SavedSearch.php @@ -43,7 +43,25 @@ * @access public */ function civicrm_api3_saved_search_create($params) { - return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params); + // The create function of the dao expects a 'formValues' that is + // not serialized. The get function returns form_values, that is + // serialized. + // So for the create API, I guess it should work for serialized and + // unserialized form_values. + + if (isset($params["form_values"])) { + if (is_array($params["form_values"])) { + $params["formValues"] = $params["form_values"]; + } + else { + // Assume that form_values is serialized. + $params["formValues"] = unserialize($params["form_values"]); + } + } + + $result = _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params); + _civicrm_api3_saved_search_result_cleanup($result); + return $result; } /** @@ -72,5 +90,22 @@ function civicrm_api3_saved_search_delete($params) { * @access public */ function civicrm_api3_saved_search_get($params) { - return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); + $result = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); + _civicrm_api3_saved_search_result_cleanup($result); + return $result; +} + +/** + * This function unserializes the form_values in an SavedSearch API result. + * + * @param array $result API result to be cleaned up. + */ +function _civicrm_api3_saved_search_result_cleanup(&$result) { + if (isset($result['values']) && is_array($result['values'])) { + // Only clean up the values if there are values. (A getCount operation + // for example does not return values.) + foreach ($result['values'] as $key => $value) { + $result['values'][$key]['form_values'] = unserialize($value['form_values']); + } + } }