Merge branch 4.5 into master
[civicrm-core.git] / api / v3 / examples / Profile / GetFields.php
CommitLineData
9dec4e61 1<?php
2/**
3 * Test Generated example of using profile getfields API
4 * demonstrates retrieving profile fields passing in an id *
5 */
6function profile_getfields_example(){
7$params = array(
8 'action' => 'submit',
c3d3e837 9 'profile_id' => 27,
9dec4e61 10);
11
12try{
13 $result = civicrm_api3('profile', 'getfields', $params);
14}
15catch (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
23return $result;
24}
25
26/**
27 * Function returns array of result expected from previous function
28 */
29function profile_getfields_expectedresult(){
30
31 $expectedResult = array(
32 'is_error' => 0,
33 'version' => 3,
34 'count' => 9,
35 'values' => array(
b259a4ab
EM
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' => '',
89bf81b4 54 'is_required' => 0,
b259a4ab 55 'name' => 'custom_1',
89bf81b4 56 'title' => 'first_name',
9dec4e61 57 'type' => 2,
c3d3e837 58 'api.required' => '1',
c3d3e837
E
59 'help_pre' => '',
60 'help_post' => '',
29fbb90a 61 'entity' => 'contact',
b259a4ab 62 'weight' => '1',
29fbb90a 63 'api.aliases' => array(),
9dec4e61 64 ),
b259a4ab
EM
65 'postal_code-1' => array(
66 'name' => 'postal_code',
9dec4e61 67 'type' => 2,
b259a4ab
EM
68 'title' => 'State Province',
69 'maxlength' => 12,
70 'size' => 12,
9dec4e61 71 'import' => true,
b259a4ab
EM
72 'where' => 'civicrm_address.postal_code',
73 'headerPattern' => '/postal|zip/i',
74 'dataPattern' => '/\\d?\\d{4}(-\\d{4})?/',
9dec4e61 75 'export' => true,
b259a4ab 76 'api.required' => 0,
c3d3e837
E
77 'help_pre' => '',
78 'help_post' => '',
b259a4ab
EM
79 'entity' => 'address',
80 'weight' => '2',
29fbb90a 81 'api.aliases' => array(),
9dec4e61 82 ),
b259a4ab
EM
83 'state_province-1' => array(
84 'name' => 'state_province_id',
85 'type' => 1,
86 'title' => 'State Province',
87 'FKClassName' => 'CRM_Core_DAO_StateProvince',
89bf81b4 88 'html' => array(
89 'type' => 'Select',
90 ),
b259a4ab
EM
91 'pseudoconstant' => array(
92 'table' => 'civicrm_state_province',
93 'keyColumn' => 'id',
94 'labelColumn' => 'name',
95 ),
c3d3e837 96 'api.required' => '1',
c3d3e837
E
97 'help_pre' => '',
98 'help_post' => '',
29fbb90a 99 'entity' => 'address',
b259a4ab
EM
100 'weight' => '3',
101 'api.aliases' => array(),
102 ),
103 'country-1' => array(
9dec4e61 104 'name' => 'country_id',
105 'type' => 1,
b259a4ab 106 'title' => 'Country',
9dec4e61 107 'FKClassName' => 'CRM_Core_DAO_Country',
89bf81b4 108 'html' => array(
109 'type' => 'Select',
110 ),
9dec4e61 111 'pseudoconstant' => array(
112 'table' => 'civicrm_country',
113 'keyColumn' => 'id',
114 'labelColumn' => 'name',
115 'nameColumn' => 'iso_code',
116 ),
b259a4ab
EM
117 'api.required' => '1',
118 'help_pre' => '',
119 'help_post' => '',
120 'entity' => 'address',
121 'weight' => '4',
29fbb90a 122 'api.aliases' => array(),
9dec4e61 123 ),
b259a4ab
EM
124 'phone-1-1' => array(
125 'name' => 'phone',
126 'type' => 2,
127 'title' => 'Phone',
128 'maxlength' => 32,
129 'size' => 20,
130 'import' => true,
131 'where' => 'civicrm_phone.phone',
132 'headerPattern' => '/phone/i',
133 'dataPattern' => '/^[\\d\\(\\)\\-\\.\\s]+$/',
134 'export' => true,
c3d3e837 135 'api.required' => '1',
c3d3e837
E
136 'help_pre' => '',
137 'help_post' => '',
b259a4ab
EM
138 'entity' => 'phone',
139 'weight' => '5',
29fbb90a 140 'api.aliases' => array(),
9dec4e61 141 ),
b259a4ab
EM
142 'email-primary' => array(
143 'name' => 'email',
144 'type' => 2,
145 'title' => 'Email',
146 'maxlength' => 254,
147 'size' => 20,
148 'import' => true,
149 'where' => 'civicrm_email.email',
150 'headerPattern' => '/e.?mail/i',
151 '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]$/',
152 'export' => true,
153 'rule' => 'email',
89bf81b4 154 'html' => array(
155 'type' => 'Text',
156 ),
b259a4ab 157 'api.required' => '1',
c3d3e837
E
158 'help_pre' => '',
159 'help_post' => '',
b259a4ab
EM
160 'entity' => 'email',
161 'weight' => '6',
162 'api.aliases' => array(
163 '0' => 'email-Primary',
164 ),
165 ),
166 'last_name' => array(
167 'name' => 'last_name',
9dec4e61 168 'type' => 2,
b259a4ab
EM
169 'title' => 'Last Name',
170 'maxlength' => 64,
171 'size' => 30,
9dec4e61 172 'import' => true,
b259a4ab
EM
173 'where' => 'civicrm_contact.last_name',
174 'headerPattern' => '/^last|(l(ast\\s)?name)$/i',
175 'dataPattern' => '/^\\w+(\\s\\w+)?+$/',
9dec4e61 176 'export' => true,
89bf81b4 177 'html' => array(
178 'type' => 'Text',
179 ),
b259a4ab
EM
180 'api.required' => '1',
181 'help_pre' => '',
182 'help_post' => '',
183 'entity' => 'contact',
184 'weight' => '7',
29fbb90a 185 'api.aliases' => array(),
9dec4e61 186 ),
b259a4ab
EM
187 'first_name' => array(
188 'name' => 'first_name',
189 'type' => 2,
190 'title' => 'First Name',
191 'maxlength' => 64,
192 'size' => 30,
193 'import' => true,
194 'where' => 'civicrm_contact.first_name',
195 'headerPattern' => '/^first|(f(irst\\s)?name)$/i',
196 'dataPattern' => '/^\\w+$/',
197 'export' => true,
89bf81b4 198 'html' => array(
199 'type' => 'Text',
200 ),
c3d3e837 201 'api.required' => '1',
c3d3e837
E
202 'help_pre' => '',
203 'help_post' => '',
29fbb90a 204 'entity' => 'contact',
b259a4ab 205 'weight' => '8',
29fbb90a 206 'api.aliases' => array(),
9dec4e61 207 ),
208 'profile_id' => array(
209 'api.required' => true,
89bf81b4 210 'title' => 'Profile ID',
9dec4e61 211 ),
212 ),
213);
214
215 return $expectedResult;
216}
217
218
219/*
220* This example has been generated from the API test suite. The test that created it is called
221*
222* testGetFields and can be found in
69d79249 223* https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ProfileTest.php
9dec4e61 224*
225* You can see the outcome of the API tests at
69d79249 226* https://test.civicrm.org/job/CiviCRM-master-git/
9dec4e61 227*
228* To Learn about the API read
69d79249 229* http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API
9dec4e61 230*
69d79249
E
231* Browse the api on your own site with the api explorer
232* http://MYSITE.ORG/path/to/civicrm/api/explorer
9dec4e61 233*
234* Read more about testing here
235* http://wiki.civicrm.org/confluence/display/CRM/Testing
236*
237* API Standards documentation:
238* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
b259a4ab 239*/