Merge pull request #6037 from colemanw/CRM-16512
[civicrm-core.git] / api / v3 / examples / UFField / Replace.php
CommitLineData
6a488035 1<?php
50fb255d 2/**
a828d7b8 3 * Test Generated example demonstrating the UFField.replace API.
50fb255d 4 *
50fb255d 5 * @return array
6 * API result array
7 */
8function uf_field_replace_example() {
9 $params = array(
10 'uf_group_id' => 11,
11 'option.autoweight' => '',
12 'values' => array(
ee600d6f 13 '0' => array(
50fb255d 14 'field_name' => 'first_name',
15 'field_type' => 'Contact',
16 'visibility' => 'Public Pages and Listings',
17 'weight' => 3,
18 'label' => 'Test First Name',
19 'is_searchable' => 1,
20 'is_active' => 1,
21 ),
ee600d6f 22 '1' => array(
50fb255d 23 'field_name' => 'country',
24 'field_type' => 'Contact',
25 'visibility' => 'Public Pages and Listings',
26 'weight' => 2,
27 'label' => 'Test Country',
28 'is_searchable' => 1,
29 'is_active' => 1,
30 'location_type_id' => 1,
31 ),
ee600d6f 32 '2' => array(
50fb255d 33 'field_name' => 'phone',
34 'field_type' => 'Contact',
35 'visibility' => 'Public Pages and Listings',
36 'weight' => 1,
37 'label' => 'Test Phone',
38 'is_searchable' => 1,
39 'is_active' => 1,
40 'location_type_id' => 1,
41 'phone_type_id' => 1,
42 ),
6a488035 43 ),
181f536c 44 'check_permissions' => TRUE,
50fb255d 45 );
6a488035 46
50fb255d 47 try{
a828d7b8 48 $result = civicrm_api3('UFField', 'replace', $params);
50fb255d 49 }
50 catch (CiviCRM_API3_Exception $e) {
51 // Handle error here.
52 $errorMessage = $e->getMessage();
53 $errorCode = $e->getErrorCode();
54 $errorData = $e->getExtraParams();
55 return array(
56 'error' => $errorMessage,
57 'error_code' => $errorCode,
58 'error_data' => $errorData,
59 );
60 }
6a488035 61
50fb255d 62 return $result;
6a488035
TO
63}
64
fb32de45 65/**
50fb255d 66 * Function returns array of result expected from previous function.
67 *
68 * @return array
69 * API result array
6a488035 70 */
50fb255d 71function uf_field_replace_expectedresult() {
6a488035 72
ee600d6f 73 $expectedResult = array(
50fb255d 74 'is_error' => 0,
75 'version' => 3,
76 'count' => 3,
77 'values' => array(
ee600d6f 78 '1' => array(
50fb255d 79 'id' => '1',
80 'uf_group_id' => '11',
81 'field_name' => 'first_name',
82 'is_active' => '1',
83 'is_view' => '',
84 'is_required' => '',
85 'weight' => '3',
86 'help_post' => '',
87 'help_pre' => '',
88 'visibility' => 'Public Pages and Listings',
89 'in_selector' => '',
90 'is_searchable' => '1',
91 'location_type_id' => '',
92 'phone_type_id' => '',
93 'website_type_id' => '',
94 'label' => 'Test First Name',
95 'field_type' => 'Contact',
96 'is_reserved' => '',
97 'is_multi_summary' => '',
98 ),
ee600d6f 99 '2' => array(
50fb255d 100 'id' => '2',
101 'uf_group_id' => '11',
102 'field_name' => 'country',
103 'is_active' => '1',
104 'is_view' => '',
105 'is_required' => '',
106 'weight' => '2',
107 'help_post' => '',
108 'help_pre' => '',
109 'visibility' => 'Public Pages and Listings',
110 'in_selector' => '',
111 'is_searchable' => '1',
112 'location_type_id' => '1',
113 'phone_type_id' => '',
114 'website_type_id' => '',
115 'label' => 'Test Country',
116 'field_type' => 'Contact',
117 'is_reserved' => '',
118 'is_multi_summary' => '',
119 ),
ee600d6f 120 '3' => array(
50fb255d 121 'id' => '3',
122 'uf_group_id' => '11',
123 'field_name' => 'phone',
124 'is_active' => '1',
125 'is_view' => '',
126 'is_required' => '',
127 'weight' => '1',
128 'help_post' => '',
129 'help_pre' => '',
130 'visibility' => 'Public Pages and Listings',
131 'in_selector' => '',
132 'is_searchable' => '1',
133 'location_type_id' => '1',
134 'phone_type_id' => '1',
135 'website_type_id' => '',
136 'label' => 'Test Phone',
137 'field_type' => 'Contact',
138 'is_reserved' => '',
139 'is_multi_summary' => '',
140 ),
6a488035 141 ),
50fb255d 142 );
6a488035 143
fb32de45 144 return $expectedResult;
6a488035
TO
145}
146
a828d7b8 147/*
50fb255d 148* This example has been generated from the API test suite.
a828d7b8
CW
149* The test that created it is called "testReplaceUFFields"
150* and can be found at:
69d79249 151* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/UFFieldTest.php
6a488035
TO
152*
153* You can see the outcome of the API tests at
69d79249 154* https://test.civicrm.org/job/CiviCRM-master-git/
6a488035
TO
155*
156* To Learn about the API read
69d79249 157* http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
6a488035 158*
69d79249 159* Browse the api on your own site with the api explorer
41d4d31f 160* http://MYSITE.ORG/path/to/civicrm/api
6a488035
TO
161*
162* Read more about testing here
163* http://wiki.civicrm.org/confluence/display/CRM/Testing
164*
165* API Standards documentation:
166* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
b259a4ab 167*/