Merge pull request #9668 from colemanw/CRM-19864
[civicrm-core.git] / api / v3 / examples / Contact / APIChainedArrayValuesFromSiblingFunction.php
1 <?php
2 /**
3 * Test Generated example demonstrating the Contact.create API.
4 *
5 * This demonstrates the usage of chained api functions. Specifically it has one 'parent function' &
6 * 2 child functions - one receives values from the parent (Contact) and the other child (Tag).
7 *
8 * @return array
9 * API result array
10 */
11 function contact_create_example() {
12 $params = array(
13 'display_name' => 'batman',
14 'contact_type' => 'Individual',
15 'api.tag.create' => array(
16 'name' => '$value.id',
17 'description' => '$value.display_name',
18 'format.only_id' => 1,
19 ),
20 'api.entity_tag.create' => array(
21 'tag_id' => '$value.api.tag.create',
22 ),
23 );
24
25 try{
26 $result = civicrm_api3('Contact', 'create', $params);
27 }
28 catch (CiviCRM_API3_Exception $e) {
29 // Handle error here.
30 $errorMessage = $e->getMessage();
31 $errorCode = $e->getErrorCode();
32 $errorData = $e->getExtraParams();
33 return array(
34 'is_error' => 1,
35 'error_message' => $errorMessage,
36 'error_code' => $errorCode,
37 'error_data' => $errorData,
38 );
39 }
40
41 return $result;
42 }
43
44 /**
45 * Function returns array of result expected from previous function.
46 *
47 * @return array
48 * API result array
49 */
50 function contact_create_expectedresult() {
51
52 $expectedResult = array(
53 'is_error' => 0,
54 'version' => 3,
55 'count' => 1,
56 'id' => 1,
57 'values' => array(
58 '1' => array(
59 'id' => '1',
60 'contact_type' => 'Individual',
61 'contact_sub_type' => '',
62 'do_not_email' => 0,
63 'do_not_phone' => 0,
64 'do_not_mail' => 0,
65 'do_not_sms' => 0,
66 'do_not_trade' => 0,
67 'is_opt_out' => 0,
68 'legal_identifier' => '',
69 'external_identifier' => '',
70 'sort_name' => 'batman',
71 'display_name' => 'batman',
72 'nick_name' => '',
73 'legal_name' => '',
74 'image_URL' => '',
75 'preferred_communication_method' => '',
76 'preferred_language' => 'en_US',
77 'preferred_mail_format' => 'Both',
78 'hash' => '67eac7789eaee00',
79 'api_key' => '',
80 'first_name' => '',
81 'middle_name' => '',
82 'last_name' => '',
83 'prefix_id' => '',
84 'suffix_id' => '',
85 'formal_title' => '',
86 'communication_style_id' => '',
87 'email_greeting_id' => '1',
88 'email_greeting_custom' => '',
89 'email_greeting_display' => '',
90 'postal_greeting_id' => '1',
91 'postal_greeting_custom' => '',
92 'postal_greeting_display' => '',
93 'addressee_id' => '1',
94 'addressee_custom' => '',
95 'addressee_display' => '',
96 'job_title' => '',
97 'gender_id' => '',
98 'birth_date' => '',
99 'is_deceased' => 0,
100 'deceased_date' => '',
101 'household_name' => '',
102 'primary_contact_id' => '',
103 'organization_name' => '',
104 'sic_code' => '',
105 'user_unique_id' => '',
106 'created_date' => '2013-07-28 08:49:19',
107 'modified_date' => '2012-11-14 16:02:35',
108 'api.tag.create' => 6,
109 'api.entity_tag.create' => array(
110 'is_error' => 0,
111 'not_added' => 1,
112 'added' => 1,
113 'total_count' => 2,
114 ),
115 ),
116 ),
117 );
118
119 return $expectedResult;
120 }
121
122 /*
123 * This example has been generated from the API test suite.
124 * The test that created it is called "testChainingValuesCreate"
125 * and can be found at:
126 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContactTest.php
127 *
128 * You can see the outcome of the API tests at
129 * https://test.civicrm.org/job/CiviCRM-master-git/
130 *
131 * To Learn about the API read
132 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
133 *
134 * Browse the api on your own site with the api explorer
135 * http://MYSITE.ORG/path/to/civicrm/api
136 *
137 * Read more about testing here
138 * http://wiki.civicrm.org/confluence/display/CRM/Testing
139 *
140 * API Standards documentation:
141 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
142 */