Short array syntax - auto-convert api dir
[civicrm-core.git] / api / v3 / examples / SavedSearch / Create.php
CommitLineData
1d8ee3d6 1<?php
2/**
3 * Test Generated example demonstrating the SavedSearch.create API.
4 *
5 * @return array
6 * API result array
7 */
8function saved_search_create_example() {
cf8f0fff
CW
9 $params = [
10 'form_values' => [
1d8ee3d6 11 'relation_type_id' => '6_a_b',
12 'relation_target_name' => 'Default Organization',
cf8f0fff
CW
13 ],
14 'api.Group.create' => [
1d8ee3d6 15 'name' => 'my_smartgroup',
16 'title' => 'my smartgroup',
17 'description' => 'Volunteers for the default organization',
18 'saved_search_id' => '$value.id',
19 'is_active' => 1,
20 'visibility' => 'User and User Admin Only',
21 'is_hidden' => 0,
22 'is_reserved' => 0,
cf8f0fff
CW
23 ],
24 ];
1d8ee3d6 25
26 try{
27 $result = civicrm_api3('SavedSearch', 'create', $params);
28 }
29 catch (CiviCRM_API3_Exception $e) {
30 // Handle error here.
31 $errorMessage = $e->getMessage();
32 $errorCode = $e->getErrorCode();
33 $errorData = $e->getExtraParams();
cf8f0fff 34 return [
1d8ee3d6 35 'is_error' => 1,
36 'error_message' => $errorMessage,
37 'error_code' => $errorCode,
38 'error_data' => $errorData,
cf8f0fff 39 ];
1d8ee3d6 40 }
41
42 return $result;
43}
44
45/**
46 * Function returns array of result expected from previous function.
47 *
48 * @return array
49 * API result array
50 */
51function saved_search_create_expectedresult() {
52
cf8f0fff 53 $expectedResult = [
1d8ee3d6 54 'is_error' => 0,
55 'version' => 3,
56 'count' => 1,
57 'id' => 3,
cf8f0fff
CW
58 'values' => [
59 '3' => [
1d8ee3d6 60 'id' => '3',
cf8f0fff 61 'form_values' => [
1d8ee3d6 62 'relation_type_id' => '6_a_b',
63 'relation_target_name' => 'Default Organization',
cf8f0fff 64 ],
1d8ee3d6 65 'mapping_id' => '',
66 'search_custom_id' => '',
67 'where_clause' => '',
68 'select_tables' => '',
69 'where_tables' => '',
cf8f0fff 70 'api.Group.create' => [
1d8ee3d6 71 'is_error' => 0,
72 'version' => 3,
73 'count' => 1,
74 'id' => 1,
cf8f0fff
CW
75 'values' => [
76 '0' => [
1d8ee3d6 77 'id' => '1',
78 'name' => 'my_smartgroup',
79 'title' => 'my smartgroup',
80 'description' => 'Volunteers for the default organization',
81 'source' => '',
82 'saved_search_id' => '3',
83 'is_active' => '1',
84 'visibility' => 'User and User Admin Only',
85 'where_clause' => ' ( ( `civicrm_group_contact_cache_1`.group_id IN (\"1\") ) ) ',
86 'select_tables' => 'a:8:{s:15:\"civicrm_contact\";i:1;s:15:\"civicrm_address\";i:1;s:15:\"civicrm_country\";i:1;s:13:\"civicrm_email\";i:1;s:13:\"civicrm_phone\";i:1;s:10:\"civicrm_im\";i:1;s:19:\"civicrm_worldregion\";i:1;s:31:\"`civicrm_group_contact_cache_1`\";s:132:\" LEFT JOIN civicrm_group_contact_cache `civicrm_group_contact_cache_1` ON contact_a.id = `civicrm_group_contact_cache_1`.contact_id \";}',
87 'where_tables' => 'a:2:{s:15:\"civicrm_contact\";i:1;s:31:\"`civicrm_group_contact_cache_1`\";s:132:\" LEFT JOIN civicrm_group_contact_cache `civicrm_group_contact_cache_1` ON contact_a.id = `civicrm_group_contact_cache_1`.contact_id \";}',
88 'group_type' => '',
89 'cache_date' => '',
90 'refresh_date' => '',
91 'parents' => '',
92 'children' => '',
93 'is_hidden' => 0,
94 'is_reserved' => 0,
95 'created_id' => '',
96 'modified_id' => '',
cf8f0fff
CW
97 ],
98 ],
99 ],
100 ],
101 ],
102 ];
1d8ee3d6 103
104 return $expectedResult;
105}
106
107/*
108* This example has been generated from the API test suite.
109* The test that created it is called "testCreateSavedSearchWithSmartGroup"
110* and can be found at:
111* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/SavedSearchTest.php
112*
113* You can see the outcome of the API tests at
114* https://test.civicrm.org/job/CiviCRM-master-git/
115*
116* To Learn about the API read
117* http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
118*
119* Browse the api on your own site with the api explorer
120* http://MYSITE.ORG/path/to/civicrm/api
121*
122* Read more about testing here
123* http://wiki.civicrm.org/confluence/display/CRM/Testing
124*
125* API Standards documentation:
126* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
127*/