Merge pull request #4737 from eileenmcnaughton/master
[civicrm-core.git] / api / v3 / examples / LocBlock / createEntities.php
CommitLineData
6a488035 1<?php
fb32de45 2/**
89bf81b4 3 * Test Generated example of using loc_block create API
4 * Create entities and locBlock in 1 api call *
6a488035 5 */
89bf81b4 6function loc_block_create_example(){
82adafa2 7$params = array(
82adafa2 8 'email' => array(
6a488035
TO
9 'location_type_id' => 1,
10 'email' => 'test2@loc.block',
11 ),
82adafa2 12 'phone' => array(
6a488035
TO
13 'location_type_id' => 1,
14 'phone' => '987654321',
15 ),
82adafa2 16 'phone_2' => array(
6a488035
TO
17 'location_type_id' => 1,
18 'phone' => '456-7890',
19 ),
82adafa2 20 'address' => array(
6a488035
TO
21 'location_type_id' => 1,
22 'street_address' => '987654321',
23 ),
24);
25
fb32de45 26try{
89bf81b4 27 $result = civicrm_api3('loc_block', 'create', $params);
fb32de45 28}
29catch (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}
6a488035 36
fb32de45 37return $result;
6a488035
TO
38}
39
fb32de45 40/**
6a488035
TO
41 * Function returns array of result expected from previous function
42 */
89bf81b4 43function loc_block_create_expectedresult(){
6a488035 44
82adafa2 45 $expectedResult = array(
6a488035
TO
46 'is_error' => 0,
47 'version' => 3,
48 'count' => 1,
49 'id' => 3,
82adafa2 50 'values' => array(
51 '3' => array(
52 'address' => array(
6a488035
TO
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 ),
82adafa2 60 'email' => array(
89bf81b4 61 'id' => '33',
9f1b81e0 62 'contact_id' => '',
6a488035
TO
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 ),
82adafa2 74 'phone' => array(
6a488035 75 'id' => '3',
9f1b81e0 76 'contact_id' => '',
6a488035
TO
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 ),
82adafa2 86 'phone_2' => array(
6a488035 87 'id' => '4',
9f1b81e0 88 'contact_id' => '',
6a488035
TO
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',
89bf81b4 100 'email_id' => '33',
6a488035
TO
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
fb32de45 111 return $expectedResult;
6a488035
TO
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
69d79249 119* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/LocBlockTest.php
6a488035
TO
120*
121* You can see the outcome of the API tests at
69d79249 122* https://test.civicrm.org/job/CiviCRM-master-git/
6a488035
TO
123*
124* To Learn about the API read
69d79249 125* http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
6a488035 126*
69d79249
E
127* Browse the api on your own site with the api explorer
128* http://MYSITE.ORG/path/to/civicrm/api/explorer
6a488035
TO
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
b259a4ab 135*/