Merge pull request #13942 from civicrm/5.12
[civicrm-core.git] / api / v3 / examples / Profile / Get.php
... / ...
CommitLineData
1<?php
2/**
3 * Test Generated example demonstrating the Profile.get API.
4 *
5 * @return array
6 * API result array
7 */
8function profile_get_example() {
9 $params = [
10 'profile_id' => [
11 '0' => 15,
12 '1' => 1,
13 '2' => 'Billing',
14 ],
15 'contact_id' => 3,
16 ];
17
18 try{
19 $result = civicrm_api3('Profile', 'get', $params);
20 }
21 catch (CiviCRM_API3_Exception $e) {
22 // Handle error here.
23 $errorMessage = $e->getMessage();
24 $errorCode = $e->getErrorCode();
25 $errorData = $e->getExtraParams();
26 return [
27 'is_error' => 1,
28 'error_message' => $errorMessage,
29 'error_code' => $errorCode,
30 'error_data' => $errorData,
31 ];
32 }
33
34 return $result;
35}
36
37/**
38 * Function returns array of result expected from previous function.
39 *
40 * @return array
41 * API result array
42 */
43function profile_get_expectedresult() {
44
45 $expectedResult = [
46 'is_error' => 0,
47 'version' => 3,
48 'count' => 3,
49 'values' => [
50 '15' => [
51 'postal_code-1' => '90210',
52 'state_province-1' => '1021',
53 'country-1' => '1228',
54 'phone-1-1' => '021 512 755',
55 'email-Primary' => 'abc1.xyz1@yahoo.com',
56 'last_name' => 'xyz1',
57 'first_name' => 'abc1',
58 'email-primary' => 'abc1.xyz1@yahoo.com',
59 ],
60 '1' => [
61 'first_name' => 'abc1',
62 'last_name' => 'xyz1',
63 'street_address-1' => '5 Saint Helier St',
64 'city-1' => 'Gotham City',
65 'postal_code-1' => '90210',
66 'country-1' => '1228',
67 'state_province-1' => '1021',
68 ],
69 'Billing' => [
70 'billing_first_name' => 'abc1',
71 'billing_middle_name' => 'J.',
72 'billing_last_name' => 'xyz1',
73 'billing_street_address-5' => '5 Saint Helier St',
74 'billing_city-5' => 'Gotham City',
75 'billing_state_province_id-5' => '1021',
76 'billing_country_id-5' => '1228',
77 'billing_postal_code-5' => '90210',
78 'billing-email-5' => 'abc1.xyz1@yahoo.com',
79 'email-5' => 'abc1.xyz1@yahoo.com',
80 ],
81 ],
82 ];
83
84 return $expectedResult;
85}
86
87/*
88* This example has been generated from the API test suite.
89* The test that created it is called "testProfileGetMultiple"
90* and can be found at:
91* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ProfileTest.php
92*
93* You can see the outcome of the API tests at
94* https://test.civicrm.org/job/CiviCRM-master-git/
95*
96* To Learn about the API read
97* http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
98*
99* Browse the api on your own site with the api explorer
100* http://MYSITE.ORG/path/to/civicrm/api
101*
102* Read more about testing here
103* http://wiki.civicrm.org/confluence/display/CRM/Testing
104*
105* API Standards documentation:
106* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
107*/