if (isset($ssParams['saved_search_id'])) {
$ssParams['id'] = $ssParams['saved_search_id'];
}
-
+ $params['form_values'] = $params['formValues'];
$savedSearch = CRM_Contact_BAO_SavedSearch::create($params);
$params['saved_search_id'] = $savedSearch->id;
*/
public static function create(&$params) {
$savedSearch = new CRM_Contact_DAO_SavedSearch();
- if (isset($params['formValues']) &&
- !empty($params['formValues'])
- ) {
- $savedSearch->form_values = serialize($params['formValues']);
- }
- else {
- $savedSearch->form_values = NULL;
- }
-
- $savedSearch->is_active = CRM_Utils_Array::value('is_active', $params, 1);
- $savedSearch->mapping_id = CRM_Utils_Array::value('mapping_id', $params, 'null');
- $savedSearch->custom_search_id = CRM_Utils_Array::value('custom_search_id', $params, 'null');
- $savedSearch->id = CRM_Utils_Array::value('id', $params, NULL);
-
+ $savedSearch->copyValues($params, TRUE);
$savedSearch->save();
return $savedSearch;
*/
function civicrm_api3_saved_search_create($params) {
civicrm_api3_verify_one_mandatory($params, NULL, ['form_values', 'where_clause']);
- // 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"] = \CRM_Utils_String::unserialize($params["form_values"]);
- }
- }
$result = _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'SavedSearch');
_civicrm_api3_saved_search_result_cleanup($result);
return $result;
}
+/**
+ * @param array $fields
+ */
+function _civicrm_api3_saved_search_create_spec(&$fields) {
+ $fields['form_values']['api.aliases'][] = 'formValues';
+}
+
/**
* Delete an existing saved search.
*
]);
// create smart group which will contain all Male contacts
- $smartGroupParams = ['formValues' => ['gender_id' => 1]];
+ $smartGroupParams = ['form_values' => ['gender_id' => 1]];
$smartGroupID = $this->smartGroupCreate(
$smartGroupParams,
[
}
else {
$groupIDs[$i] = $this->smartGroupCreate([
- 'formValues' => ['last_name' => (($i == 6) ? 'smart5' : 'smart' . $i)],
+ 'form_values' => ['last_name' => (($i == 6) ? 'smart5' : 'smart' . $i)],
], $params);
}
}
// Setup
$smartGroupParams = [
- 'formValues' => ['contact_type' => ['IN' => ['Individual']]],
+ 'form_values' => ['contact_type' => ['IN' => ['Individual']]],
];
$group = $this->smartGroupCreate($smartGroupParams);
$sms_provider = $this->callAPISuccess('SmsProvider', 'create', [
* @return int
*/
public function smartGroupCreate($smartGroupParams = [], $groupParams = [], $contactType = 'Household') {
- $smartGroupParams = array_merge([
- 'formValues' => ['contact_type' => ['IN' => [$contactType]]],
- ],
- $smartGroupParams);
+ $smartGroupParams = array_merge(['form_values' => ['contact_type' => ['IN' => [$contactType]]]], $smartGroupParams);
$savedSearch = CRM_Contact_BAO_SavedSearch::create($smartGroupParams);
$groupParams['saved_search_id'] = $savedSearch->id;
]);
$ssParams = [
- 'formValues' => [
+ 'form_values' => [
// Child of
'display_relationship_type' => $rtype1['id'] . '_a_b',
'sort_name' => 'Adams',
];
$g1ID = $this->smartGroupCreate($ssParams, ['name' => uniqid(), 'title' => uniqid()]);
$ssParams = [
- 'formValues' => [
+ 'form_values' => [
// Household Member of
'display_relationship_type' => $rtype2['id'] . '_a_b',
],
];
$g2ID = $this->smartGroupCreate($ssParams, ['name' => uniqid(), 'title' => uniqid()]);
$ssParams = [
- 'formValues' => [
+ 'form_values' => [
// Household Member is
'display_relationship_type' => $rtype2['id'] . '_b_a',
],
// the reverse of g2 which adds another layer for overlap at related contact filter
$g3ID = $this->smartGroupCreate($ssParams, ['name' => uniqid(), 'title' => uniqid()]);
CRM_Contact_BAO_GroupContactCache::loadAll();
- $g1Contacts = $this->callAPISuccess('contact', 'get', ['group' => $g1ID]);
- $g2Contacts = $this->callAPISuccess('contact', 'get', ['group' => $g2ID]);
- $g3Contacts = $this->callAPISuccess('contact', 'get', ['group' => $g3ID]);
- $this->assertTrue($g1Contacts['count'] == 1);
- $this->assertTrue($g2Contacts['count'] == 2);
- $this->assertTrue($g3Contacts['count'] == 1);
+ $this->callAPISuccessGetCount('contact', ['group' => $g1ID], 1);
+ $this->callAPISuccessGetCount('contact', ['group' => $g2ID], 2);
+ $this->callAPISuccessGetCount('contact', ['group' => $g3ID], 1);
}
/**
'Payment',
'Order',
//work fine in local
- 'SavedSearch',
'Logging',
];
$this->toBeImplemented['delete'] = [
// View mode is part of the navigation which is not retrieved by the api.
'cant_return' => ['view_mode'],
],
- 'SavedSearch' => [
- // I think the fields below are generated based on form_values.
- 'cant_update' => [
- 'search_custom_id',
- 'where_clause',
- 'select_tables',
- 'where_tables',
- ],
- ],
'StatusPreference' => [
'break_return' => [
'ignore_severity',