Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
fb32de45 | 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). * | |
6a488035 TO |
6 | */ |
7 | function contact_create_example(){ | |
edb0d67a | 8 | $params = array( |
6a488035 TO |
9 | 'display_name' => 'batman', |
10 | 'contact_type' => 'Individual', | |
edb0d67a | 11 | 'api.tag.create' => array( |
6a488035 TO |
12 | 'name' => '$value.id', |
13 | 'description' => '$value.display_name', | |
14 | 'format.only_id' => 1, | |
15 | ), | |
edb0d67a | 16 | 'api.entity_tag.create' => array( |
6a488035 TO |
17 | 'tag_id' => '$value.api.tag.create', |
18 | ), | |
19 | ); | |
20 | ||
fb32de45 | 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 | } | |
6a488035 | 31 | |
fb32de45 | 32 | return $result; |
6a488035 TO |
33 | } |
34 | ||
fb32de45 | 35 | /** |
6a488035 TO |
36 | * Function returns array of result expected from previous function |
37 | */ | |
38 | function contact_create_expectedresult(){ | |
39 | ||
edb0d67a | 40 | $expectedResult = array( |
6a488035 TO |
41 | 'is_error' => 0, |
42 | 'version' => 3, | |
43 | 'count' => 1, | |
44 | 'id' => 1, | |
edb0d67a | 45 | 'values' => array( |
46 | '1' => array( | |
6a488035 TO |
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' => '', | |
9f1b81e0 | 71 | 'prefix_id' => '', |
72 | 'suffix_id' => '', | |
89bf81b4 | 73 | 'formal_title' => '', |
74 | 'communication_style_id' => '', | |
6a488035 TO |
75 | 'email_greeting_id' => '1', |
76 | 'email_greeting_custom' => '', | |
77 | 'email_greeting_display' => '', | |
78 | 'postal_greeting_id' => '1', | |
79 | 'postal_greeting_custom' => '', | |
80 | 'postal_greeting_display' => '', | |
81 | 'addressee_id' => '1', | |
82 | 'addressee_custom' => '', | |
83 | 'addressee_display' => '', | |
84 | 'job_title' => '', | |
85 | 'gender_id' => '', | |
86 | 'birth_date' => '', | |
87 | 'is_deceased' => 0, | |
88 | 'deceased_date' => '', | |
89 | 'household_name' => '', | |
90 | 'primary_contact_id' => '', | |
91 | 'organization_name' => '', | |
92 | 'sic_code' => '', | |
93 | 'user_unique_id' => '', | |
f27f2724 | 94 | 'created_date' => '2013-07-28 08:49:19', |
6a488035 TO |
95 | 'modified_date' => '2012-11-14 16:02:35', |
96 | 'api.tag.create' => 6, | |
edb0d67a | 97 | 'api.entity_tag.create' => array( |
6a488035 TO |
98 | 'is_error' => 0, |
99 | 'not_added' => 1, | |
100 | 'added' => 1, | |
101 | 'total_count' => 2, | |
102 | ), | |
103 | ), | |
104 | ), | |
105 | ); | |
106 | ||
fb32de45 | 107 | return $expectedResult; |
6a488035 TO |
108 | } |
109 | ||
110 | ||
111 | /* | |
112 | * This example has been generated from the API test suite. The test that created it is called | |
113 | * | |
114 | * testChainingValuesCreate and can be found in | |
69d79249 | 115 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ContactTest.php |
6a488035 TO |
116 | * |
117 | * You can see the outcome of the API tests at | |
69d79249 | 118 | * https://test.civicrm.org/job/CiviCRM-master-git/ |
6a488035 TO |
119 | * |
120 | * To Learn about the API read | |
69d79249 | 121 | * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API |
6a488035 | 122 | * |
69d79249 E |
123 | * Browse the api on your own site with the api explorer |
124 | * http://MYSITE.ORG/path/to/civicrm/api/explorer | |
6a488035 TO |
125 | * |
126 | * Read more about testing here | |
127 | * http://wiki.civicrm.org/confluence/display/CRM/Testing | |
128 | * | |
129 | * API Standards documentation: | |
130 | * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards | |
b259a4ab | 131 | */ |