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