Merge pull request #2749 from monishdeb/HR-317
[civicrm-core.git] / api / v3 / examples / Profile / GetFields.php
1 <?php
2 /**
3 * Test Generated example of using profile getfields API
4 * demonstrates retrieving profile fields passing in an id *
5 */
6 function profile_getfields_example(){
7 $params = array(
8 'action' => 'submit',
9 'profile_id' => 27,
10 );
11
12 try{
13 $result = civicrm_api3('profile', 'getfields', $params);
14 }
15 catch (CiviCRM_API3_Exception $e) {
16 // handle error here
17 $errorMessage = $e->getMessage();
18 $errorCode = $e->getErrorCode();
19 $errorData = $e->getExtraParams();
20 return array('error' => $errorMessage, 'error_code' => $errorCode, 'error_data' => $errorData);
21 }
22
23 return $result;
24 }
25
26 /**
27 * Function returns array of result expected from previous function
28 */
29 function profile_getfields_expectedresult(){
30
31 $expectedResult = array(
32 'is_error' => 0,
33 'version' => 3,
34 'count' => 9,
35 'values' => array(
36 'custom_1' => array(
37 'label' => '_addCustomFieldToProfile',
38 'groupTitle' => '_addCustomFie',
39 'data_type' => 'String',
40 'html_type' => 'Text',
41 'default_value' => 'defaultValue',
42 'text_length' => '',
43 'options_per_line' => '',
44 'custom_group_id' => '1',
45 'extends' => 'Contact',
46 'is_search_range' => 0,
47 'extends_entity_column_value' => '',
48 'extends_entity_column_id' => '',
49 'is_view' => 0,
50 'is_multiple' => 0,
51 'option_group_id' => '',
52 'date_format' => '',
53 'time_format' => '',
54 'name' => 'custom_1',
55 'type' => 2,
56 'api.required' => '1',
57 'title' => 'first_name',
58 'help_pre' => '',
59 'help_post' => '',
60 'entity' => 'contact',
61 'weight' => '1',
62 'api.aliases' => array(),
63 ),
64 'postal_code-1' => array(
65 'name' => 'postal_code',
66 'type' => 2,
67 'title' => 'State Province',
68 'maxlength' => 12,
69 'size' => 12,
70 'import' => true,
71 'where' => 'civicrm_address.postal_code',
72 'headerPattern' => '/postal|zip/i',
73 'dataPattern' => '/\\d?\\d{4}(-\\d{4})?/',
74 'export' => true,
75 'api.required' => 0,
76 'help_pre' => '',
77 'help_post' => '',
78 'entity' => 'address',
79 'weight' => '2',
80 'api.aliases' => array(),
81 ),
82 'state_province-1' => array(
83 'name' => 'state_province_id',
84 'type' => 1,
85 'title' => 'State Province',
86 'FKClassName' => 'CRM_Core_DAO_StateProvince',
87 'pseudoconstant' => array(
88 'table' => 'civicrm_state_province',
89 'keyColumn' => 'id',
90 'labelColumn' => 'name',
91 ),
92 'api.required' => '1',
93 'help_pre' => '',
94 'help_post' => '',
95 'entity' => 'address',
96 'weight' => '3',
97 'api.aliases' => array(),
98 ),
99 'country-1' => array(
100 'name' => 'country_id',
101 'type' => 1,
102 'title' => 'Country',
103 'FKClassName' => 'CRM_Core_DAO_Country',
104 'pseudoconstant' => array(
105 'table' => 'civicrm_country',
106 'keyColumn' => 'id',
107 'labelColumn' => 'name',
108 'nameColumn' => 'iso_code',
109 ),
110 'api.required' => '1',
111 'help_pre' => '',
112 'help_post' => '',
113 'entity' => 'address',
114 'weight' => '4',
115 'api.aliases' => array(),
116 ),
117 'phone-1-1' => array(
118 'name' => 'phone',
119 'type' => 2,
120 'title' => 'Phone',
121 'maxlength' => 32,
122 'size' => 20,
123 'import' => true,
124 'where' => 'civicrm_phone.phone',
125 'headerPattern' => '/phone/i',
126 'dataPattern' => '/^[\\d\\(\\)\\-\\.\\s]+$/',
127 'export' => true,
128 'api.required' => '1',
129 'help_pre' => '',
130 'help_post' => '',
131 'entity' => 'phone',
132 'weight' => '5',
133 'api.aliases' => array(),
134 ),
135 'email-primary' => array(
136 'name' => 'email',
137 'type' => 2,
138 'title' => 'Email',
139 'maxlength' => 254,
140 'size' => 20,
141 'import' => true,
142 'where' => 'civicrm_email.email',
143 'headerPattern' => '/e.?mail/i',
144 'dataPattern' => '/^[a-zA-Z][\\w\\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\\w\\.-]*[a-zA-Z0-9]\\.[a-zA-Z][a-zA-Z\\.]*[a-zA-Z]$/',
145 'export' => true,
146 'rule' => 'email',
147 'api.required' => '1',
148 'help_pre' => '',
149 'help_post' => '',
150 'entity' => 'email',
151 'weight' => '6',
152 'api.aliases' => array(
153 '0' => 'email-Primary',
154 ),
155 ),
156 'last_name' => array(
157 'name' => 'last_name',
158 'type' => 2,
159 'title' => 'Last Name',
160 'maxlength' => 64,
161 'size' => 30,
162 'import' => true,
163 'where' => 'civicrm_contact.last_name',
164 'headerPattern' => '/^last|(l(ast\\s)?name)$/i',
165 'dataPattern' => '/^\\w+(\\s\\w+)?+$/',
166 'export' => true,
167 'api.required' => '1',
168 'help_pre' => '',
169 'help_post' => '',
170 'entity' => 'contact',
171 'weight' => '7',
172 'api.aliases' => array(),
173 ),
174 'first_name' => array(
175 'name' => 'first_name',
176 'type' => 2,
177 'title' => 'First Name',
178 'maxlength' => 64,
179 'size' => 30,
180 'import' => true,
181 'where' => 'civicrm_contact.first_name',
182 'headerPattern' => '/^first|(f(irst\\s)?name)$/i',
183 'dataPattern' => '/^\\w+$/',
184 'export' => true,
185 'api.required' => '1',
186 'help_pre' => '',
187 'help_post' => '',
188 'entity' => 'contact',
189 'weight' => '8',
190 'api.aliases' => array(),
191 ),
192 'profile_id' => array(
193 'api.required' => true,
194 ),
195 ),
196 );
197
198 return $expectedResult;
199 }
200
201
202 /*
203 * This example has been generated from the API test suite. The test that created it is called
204 *
205 * testGetFields and can be found in
206 * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ProfileTest.php
207 *
208 * You can see the outcome of the API tests at
209 * https://test.civicrm.org/job/CiviCRM-master-git/
210 *
211 * To Learn about the API read
212 * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
213 *
214 * Browse the api on your own site with the api explorer
215 * http://MYSITE.ORG/path/to/civicrm/api/explorer
216 *
217 * Read more about testing here
218 * http://wiki.civicrm.org/confluence/display/CRM/Testing
219 *
220 * API Standards documentation:
221 * http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
222 */