Merge pull request #1259 from kurund/eval-fixes
[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 'email_greeting_id' => '1',
72 'email_greeting_custom' => '',
73 'email_greeting_display' => '',
74 'postal_greeting_id' => '1',
75 'postal_greeting_custom' => '',
76 'postal_greeting_display' => '',
77 'addressee_id' => '1',
78 'addressee_custom' => '',
79 'addressee_display' => '',
80 'job_title' => '',
81 'gender_id' => '',
82 'birth_date' => '',
83 'is_deceased' => 0,
84 'deceased_date' => '',
85 'household_name' => '',
86 'primary_contact_id' => '',
87 'organization_name' => '',
88 'sic_code' => '',
89 'user_unique_id' => '',
90 'created_date' => '2013-07-28 08:49:19',
91 'modified_date' => '2012-11-14 16:02:35',
92 'api.tag.create' => 6,
93 'api.entity_tag.create' => array(
94 'is_error' => 0,
95 'not_added' => 1,
96 'added' => 1,
97 'total_count' => 2,
98 ),
99 ),
100 ),
101 );
102
103 return $expectedResult;
104 }
105
106
107 /*
108 * This example has been generated from the API test suite. The test that created it is called
109 *
110 * testChainingValuesCreate and can be found in
111 * http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/ContactTest.php
112 *
113 * You can see the outcome of the API tests at
114 * http://tests.dev.civicrm.org/trunk/results-api_v3
115 *
116 * To Learn about the API read
117 * http://book.civicrm.org/developer/current/techniques/api/
118 *
119 * and review the wiki at
120 * http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs
121 *
122 * Read more about testing here
123 * http://wiki.civicrm.org/confluence/display/CRM/Testing
124 *
125 * API Standards documentation:
126 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
127 */