Short array syntax - auto-convert api dir
[civicrm-core.git] / api / v3 / examples / Contact / APIChainedArrayValuesFromSiblingFunction.php
CommitLineData
6a488035 1<?php
50fb255d 2/**
a828d7b8 3 * Test Generated example demonstrating the Contact.create API.
50fb255d 4 *
5c49fee0
CW
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).
50fb255d 7 *
8 * @return array
9 * API result array
6a488035 10 */
50fb255d 11function contact_create_example() {
cf8f0fff 12 $params = [
50fb255d 13 'display_name' => 'batman',
14 'contact_type' => 'Individual',
cf8f0fff 15 'api.tag.create' => [
6a488035
TO
16 'name' => '$value.id',
17 'description' => '$value.display_name',
18 'format.only_id' => 1,
cf8f0fff
CW
19 ],
20 'api.entity_tag.create' => [
6a488035 21 'tag_id' => '$value.api.tag.create',
cf8f0fff
CW
22 ],
23 ];
6a488035 24
50fb255d 25 try{
a828d7b8 26 $result = civicrm_api3('Contact', 'create', $params);
50fb255d 27 }
28 catch (CiviCRM_API3_Exception $e) {
29 // Handle error here.
30 $errorMessage = $e->getMessage();
31 $errorCode = $e->getErrorCode();
32 $errorData = $e->getExtraParams();
cf8f0fff 33 return [
5be22f39 34 'is_error' => 1,
35 'error_message' => $errorMessage,
50fb255d 36 'error_code' => $errorCode,
37 'error_data' => $errorData,
cf8f0fff 38 ];
50fb255d 39 }
6a488035 40
50fb255d 41 return $result;
6a488035
TO
42}
43
fb32de45 44/**
50fb255d 45 * Function returns array of result expected from previous function.
46 *
47 * @return array
48 * API result array
6a488035 49 */
50fb255d 50function contact_create_expectedresult() {
6a488035 51
cf8f0fff 52 $expectedResult = [
50fb255d 53 'is_error' => 0,
54 'version' => 3,
55 'count' => 1,
1d8ee3d6 56 'id' => 3,
cf8f0fff
CW
57 'values' => [
58 '3' => [
1d8ee3d6 59 'id' => '3',
50fb255d 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' => '',
5be22f39 70 'sort_name' => 'batman',
50fb255d 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,
cf8f0fff 109 'api.entity_tag.create' => [
50fb255d 110 'is_error' => 0,
111 'not_added' => 1,
112 'added' => 1,
113 'total_count' => 2,
cf8f0fff
CW
114 ],
115 ],
116 ],
117 ];
6a488035 118
fb32de45 119 return $expectedResult;
6a488035
TO
120}
121
a828d7b8 122/*
50fb255d 123* This example has been generated from the API test suite.
a828d7b8
CW
124* The test that created it is called "testChainingValuesCreate"
125* and can be found at:
69d79249 126* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContactTest.php
6a488035
TO
127*
128* You can see the outcome of the API tests at
69d79249 129* https://test.civicrm.org/job/CiviCRM-master-git/
6a488035
TO
130*
131* To Learn about the API read
69d79249 132* http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
6a488035 133*
69d79249 134* Browse the api on your own site with the api explorer
41d4d31f 135* http://MYSITE.ORG/path/to/civicrm/api
6a488035
TO
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
b259a4ab 142*/