Merge remote-tracking branch 'upstream/4.5' into 4.5-4.6-2015-04-13-16-08-08
[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 'error' => $errorMessage,
35 'error_code' => $errorCode,
36 'error_data' => $errorData,
37 );
38 }
39
40 return $result;
41 }
42
43 /**
44 * Function returns array of result expected from previous function.
45 *
46 * @return array
47 * API result array
48 */
49 function contact_create_expectedresult() {
50
51 $expectedResult = array(
52 'is_error' => 0,
53 'version' => 3,
54 'count' => 1,
55 'id' => 1,
56 'values' => array(
57 '1' => array(
58 'id' => '1',
59 'contact_type' => 'Individual',
60 'contact_sub_type' => '',
61 'do_not_email' => 0,
62 'do_not_phone' => 0,
63 'do_not_mail' => 0,
64 'do_not_sms' => 0,
65 'do_not_trade' => 0,
66 'is_opt_out' => 0,
67 'legal_identifier' => '',
68 'external_identifier' => '',
69 'sort_name' => '',
70 'display_name' => 'batman',
71 'nick_name' => '',
72 'legal_name' => '',
73 'image_URL' => '',
74 'preferred_communication_method' => '',
75 'preferred_language' => 'en_US',
76 'preferred_mail_format' => 'Both',
77 'hash' => '67eac7789eaee00',
78 'api_key' => '',
79 'first_name' => '',
80 'middle_name' => '',
81 'last_name' => '',
82 'prefix_id' => '',
83 'suffix_id' => '',
84 'formal_title' => '',
85 'communication_style_id' => '',
86 'email_greeting_id' => '1',
87 'email_greeting_custom' => '',
88 'email_greeting_display' => '',
89 'postal_greeting_id' => '1',
90 'postal_greeting_custom' => '',
91 'postal_greeting_display' => '',
92 'addressee_id' => '1',
93 'addressee_custom' => '',
94 'addressee_display' => '',
95 'job_title' => '',
96 'gender_id' => '',
97 'birth_date' => '',
98 'is_deceased' => 0,
99 'deceased_date' => '',
100 'household_name' => '',
101 'primary_contact_id' => '',
102 'organization_name' => '',
103 'sic_code' => '',
104 'user_unique_id' => '',
105 'created_date' => '2013-07-28 08:49:19',
106 'modified_date' => '2012-11-14 16:02:35',
107 'api.tag.create' => 6,
108 'api.entity_tag.create' => array(
109 'is_error' => 0,
110 'not_added' => 1,
111 'added' => 1,
112 'total_count' => 2,
113 ),
114 ),
115 ),
116 );
117
118 return $expectedResult;
119 }
120
121 /*
122 * This example has been generated from the API test suite.
123 * The test that created it is called "testChainingValuesCreate"
124 * and can be found at:
125 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContactTest.php
126 *
127 * You can see the outcome of the API tests at
128 * https://test.civicrm.org/job/CiviCRM-master-git/
129 *
130 * To Learn about the API read
131 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
132 *
133 * Browse the api on your own site with the api explorer
134 * http://MYSITE.ORG/path/to/civicrm/api
135 *
136 * Read more about testing here
137 * http://wiki.civicrm.org/confluence/display/CRM/Testing
138 *
139 * API Standards documentation:
140 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
141 */