CRM-15988 - Update generated examples
[civicrm-core.git] / api / v3 / examples / LocBlock / CreateEntities.php
1 <?php
2 /**
3 * Test Generated example demonstrating the LocBlock.create API.
4 *
5 * Create entities and locBlock in 1 api call.
6 *
7 * @return array
8 * API result array
9 */
10 function loc_block_create_example() {
11 $params = array(
12 'email' => array(
13 'location_type_id' => 1,
14 'email' => 'test2@loc.block',
15 ),
16 'phone' => array(
17 'location_type_id' => 1,
18 'phone' => '987654321',
19 ),
20 'phone_2' => array(
21 'location_type_id' => 1,
22 'phone' => '456-7890',
23 ),
24 'address' => array(
25 'location_type_id' => 1,
26 'street_address' => '987654321',
27 ),
28 );
29
30 try{
31 $result = civicrm_api3('LocBlock', 'create', $params);
32 }
33 catch (CiviCRM_API3_Exception $e) {
34 // Handle error here.
35 $errorMessage = $e->getMessage();
36 $errorCode = $e->getErrorCode();
37 $errorData = $e->getExtraParams();
38 return array(
39 'error' => $errorMessage,
40 'error_code' => $errorCode,
41 'error_data' => $errorData,
42 );
43 }
44
45 return $result;
46 }
47
48 /**
49 * Function returns array of result expected from previous function.
50 *
51 * @return array
52 * API result array
53 */
54 function loc_block_create_expectedresult() {
55
56 $expectedResult = array(
57 'is_error' => 0,
58 'version' => 3,
59 'count' => 1,
60 'id' => 3,
61 'values' => array(
62 '3' => array(
63 'address' => array(
64 'id' => '3',
65 'location_type_id' => '1',
66 'is_primary' => 0,
67 'is_billing' => 0,
68 'street_address' => '987654321',
69 'manual_geo_code' => 0,
70 ),
71 'email' => array(
72 'id' => '4',
73 'contact_id' => '',
74 'location_type_id' => '1',
75 'email' => 'test2@loc.block',
76 'is_primary' => 0,
77 'is_billing' => '',
78 'on_hold' => '',
79 'is_bulkmail' => '',
80 'hold_date' => '',
81 'reset_date' => '',
82 'signature_text' => '',
83 'signature_html' => '',
84 ),
85 'phone' => array(
86 'id' => '3',
87 'contact_id' => '',
88 'location_type_id' => '1',
89 'is_primary' => 0,
90 'is_billing' => '',
91 'mobile_provider_id' => '',
92 'phone' => '987654321',
93 'phone_ext' => '',
94 'phone_numeric' => '',
95 'phone_type_id' => '',
96 ),
97 'phone_2' => array(
98 'id' => '4',
99 'contact_id' => '',
100 'location_type_id' => '1',
101 'is_primary' => 0,
102 'is_billing' => '',
103 'mobile_provider_id' => '',
104 'phone' => '456-7890',
105 'phone_ext' => '',
106 'phone_numeric' => '',
107 'phone_type_id' => '',
108 ),
109 'id' => '3',
110 'address_id' => '3',
111 'email_id' => '4',
112 'phone_id' => '3',
113 'im_id' => '',
114 'address_2_id' => '',
115 'email_2_id' => '',
116 'phone_2_id' => '4',
117 'im_2_id' => '',
118 ),
119 ),
120 );
121
122 return $expectedResult;
123 }
124
125 /*
126 * This example has been generated from the API test suite.
127 * The test that created it is called "testCreateLocBlockEntities"
128 * and can be found at:
129 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/LocBlockTest.php
130 *
131 * You can see the outcome of the API tests at
132 * https://test.civicrm.org/job/CiviCRM-master-git/
133 *
134 * To Learn about the API read
135 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
136 *
137 * Browse the api on your own site with the api explorer
138 * http://MYSITE.ORG/path/to/civicrm/api
139 *
140 * Read more about testing here
141 * http://wiki.civicrm.org/confluence/display/CRM/Testing
142 *
143 * API Standards documentation:
144 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
145 */