Commit | Line | Data |
---|---|---|
9dec4e61 | 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', | |
c3d3e837 | 9 | 'profile_id' => 27, |
9dec4e61 | 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( | |
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' => '', | |
54 | 'name' => 'custom_1', | |
9dec4e61 | 55 | 'type' => 2, |
c3d3e837 | 56 | 'api.required' => '1', |
b259a4ab | 57 | 'title' => 'first_name', |
c3d3e837 E |
58 | 'help_pre' => '', |
59 | 'help_post' => '', | |
29fbb90a | 60 | 'entity' => 'contact', |
b259a4ab | 61 | 'weight' => '1', |
29fbb90a | 62 | 'api.aliases' => array(), |
9dec4e61 | 63 | ), |
b259a4ab EM |
64 | 'postal_code-1' => array( |
65 | 'name' => 'postal_code', | |
9dec4e61 | 66 | 'type' => 2, |
b259a4ab EM |
67 | 'title' => 'State Province', |
68 | 'maxlength' => 12, | |
69 | 'size' => 12, | |
9dec4e61 | 70 | 'import' => true, |
b259a4ab EM |
71 | 'where' => 'civicrm_address.postal_code', |
72 | 'headerPattern' => '/postal|zip/i', | |
73 | 'dataPattern' => '/\\d?\\d{4}(-\\d{4})?/', | |
9dec4e61 | 74 | 'export' => true, |
b259a4ab | 75 | 'api.required' => 0, |
c3d3e837 E |
76 | 'help_pre' => '', |
77 | 'help_post' => '', | |
b259a4ab EM |
78 | 'entity' => 'address', |
79 | 'weight' => '2', | |
29fbb90a | 80 | 'api.aliases' => array(), |
9dec4e61 | 81 | ), |
b259a4ab EM |
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 | ), | |
c3d3e837 | 92 | 'api.required' => '1', |
c3d3e837 E |
93 | 'help_pre' => '', |
94 | 'help_post' => '', | |
29fbb90a | 95 | 'entity' => 'address', |
b259a4ab EM |
96 | 'weight' => '3', |
97 | 'api.aliases' => array(), | |
98 | ), | |
99 | 'country-1' => array( | |
9dec4e61 | 100 | 'name' => 'country_id', |
101 | 'type' => 1, | |
b259a4ab | 102 | 'title' => 'Country', |
9dec4e61 | 103 | 'FKClassName' => 'CRM_Core_DAO_Country', |
104 | 'pseudoconstant' => array( | |
105 | 'table' => 'civicrm_country', | |
106 | 'keyColumn' => 'id', | |
107 | 'labelColumn' => 'name', | |
108 | 'nameColumn' => 'iso_code', | |
109 | ), | |
b259a4ab EM |
110 | 'api.required' => '1', |
111 | 'help_pre' => '', | |
112 | 'help_post' => '', | |
113 | 'entity' => 'address', | |
114 | 'weight' => '4', | |
29fbb90a | 115 | 'api.aliases' => array(), |
9dec4e61 | 116 | ), |
b259a4ab EM |
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, | |
c3d3e837 | 128 | 'api.required' => '1', |
c3d3e837 E |
129 | 'help_pre' => '', |
130 | 'help_post' => '', | |
b259a4ab EM |
131 | 'entity' => 'phone', |
132 | 'weight' => '5', | |
29fbb90a | 133 | 'api.aliases' => array(), |
9dec4e61 | 134 | ), |
b259a4ab EM |
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', | |
c3d3e837 E |
148 | 'help_pre' => '', |
149 | 'help_post' => '', | |
b259a4ab EM |
150 | 'entity' => 'email', |
151 | 'weight' => '6', | |
152 | 'api.aliases' => array( | |
153 | '0' => 'email-Primary', | |
154 | ), | |
155 | ), | |
156 | 'last_name' => array( | |
157 | 'name' => 'last_name', | |
9dec4e61 | 158 | 'type' => 2, |
b259a4ab EM |
159 | 'title' => 'Last Name', |
160 | 'maxlength' => 64, | |
161 | 'size' => 30, | |
9dec4e61 | 162 | 'import' => true, |
b259a4ab EM |
163 | 'where' => 'civicrm_contact.last_name', |
164 | 'headerPattern' => '/^last|(l(ast\\s)?name)$/i', | |
165 | 'dataPattern' => '/^\\w+(\\s\\w+)?+$/', | |
9dec4e61 | 166 | 'export' => true, |
b259a4ab EM |
167 | 'api.required' => '1', |
168 | 'help_pre' => '', | |
169 | 'help_post' => '', | |
170 | 'entity' => 'contact', | |
171 | 'weight' => '7', | |
29fbb90a | 172 | 'api.aliases' => array(), |
9dec4e61 | 173 | ), |
b259a4ab EM |
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, | |
c3d3e837 | 185 | 'api.required' => '1', |
c3d3e837 E |
186 | 'help_pre' => '', |
187 | 'help_post' => '', | |
29fbb90a | 188 | 'entity' => 'contact', |
b259a4ab | 189 | 'weight' => '8', |
29fbb90a | 190 | 'api.aliases' => array(), |
9dec4e61 | 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 | |
69d79249 | 206 | * https://github.com/civicrm/civicrm-core/blob/master/tests/phpunit/api/v3/ProfileTest.php |
9dec4e61 | 207 | * |
208 | * You can see the outcome of the API tests at | |
69d79249 | 209 | * https://test.civicrm.org/job/CiviCRM-master-git/ |
9dec4e61 | 210 | * |
211 | * To Learn about the API read | |
69d79249 | 212 | * http://wiki.civicrm.org/confluence/display/CRMDOC/Using+the+API |
9dec4e61 | 213 | * |
69d79249 E |
214 | * Browse the api on your own site with the api explorer |
215 | * http://MYSITE.ORG/path/to/civicrm/api/explorer | |
9dec4e61 | 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 | |
b259a4ab | 222 | */ |