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