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