Merge pull request #1217 from samuelsov/CRM-10606
[civicrm-core.git] / api / v3 / examples / Contact / GetFieldsOptions.php
CommitLineData
6a488035 1<?php
fb32de45 2/**
3 * Test Generated example of using contact GetFields API
4 * Demonstrate retrieving metadata with custom field options *
6a488035
TO
5 */
6function contact_getfields_example(){
7a7cc10b 7$params = array(
8 'options' => array(
6a488035
TO
9 'get_options' => 'custom_1',
10 ),
6a488035
TO
11 'action' => 'create',
12);
13
fb32de45 14try{
15 $result = civicrm_api3('contact', 'GetFields', $params);
16}
17catch (CiviCRM_API3_Exception $e) {
18 // handle error here
19 $errorMessage = $e->getMessage();
20 $errorCode = $e->getErrorCode();
21 $errorData = $e->getExtraParams();
22 return array('error' => $errorMessage, 'error_code' => $errorCode, 'error_data' => $errorData);
23}
6a488035 24
fb32de45 25return $result;
6a488035
TO
26}
27
fb32de45 28/**
6a488035
TO
29 * Function returns array of result expected from previous function
30 */
31function contact_getfields_expectedresult(){
32
7a7cc10b 33 $expectedResult = array(
6a488035
TO
34 'is_error' => 0,
35 'version' => 3,
7a7cc10b 36 'count' => 53,
37 'values' => array(
38 'id' => array(
6a488035
TO
39 'name' => 'id',
40 'type' => 1,
41 'title' => 'Internal Contact ID',
42 'required' => true,
43 'import' => true,
44 'where' => 'civicrm_contact.id',
45 'headerPattern' => '/internal|contact?|id$/i',
46 'export' => true,
7a7cc10b 47 'api.aliases' => array(
6a488035
TO
48 '0' => 'contact_id',
49 ),
50 ),
7a7cc10b 51 'contact_type' => array(
6a488035
TO
52 'name' => 'contact_type',
53 'type' => 2,
54 'title' => 'Contact Type',
55 'maxlength' => 64,
56 'size' => 30,
57 'export' => true,
58 'where' => 'civicrm_contact.contact_type',
7a7cc10b 59 'pseudoconstant' => array(
60 'table' => 'civicrm_contact_type',
6a488035
TO
61 'keyColumn' => 'name',
62 'labelColumn' => 'label',
7a7cc10b 63 'condition' => 'parent_id IS NULL',
6a488035
TO
64 ),
65 'api.required' => 1,
6a488035 66 ),
7a7cc10b 67 'contact_sub_type' => array(
6a488035
TO
68 'name' => 'contact_sub_type',
69 'type' => 2,
70 'title' => 'Contact Subtype',
71 'maxlength' => 255,
72 'size' => 45,
73 'import' => true,
74 'where' => 'civicrm_contact.contact_sub_type',
75 'headerPattern' => '/C(ontact )?(subtype|sub-type|sub type)/i',
76 'export' => true,
7a7cc10b 77 'pseudoconstant' => array(
78 'table' => 'civicrm_contact_type',
79 'keyColumn' => 'name',
80 'labelColumn' => 'label',
81 'condition' => 'parent_id IS NOT NULL',
82 ),
6a488035 83 ),
7a7cc10b 84 'do_not_email' => array(
6a488035
TO
85 'name' => 'do_not_email',
86 'type' => 16,
87 'title' => 'Do Not Email',
88 'import' => true,
89 'where' => 'civicrm_contact.do_not_email',
90 'headerPattern' => '/d(o )?(not )?(email)/i',
91 'dataPattern' => '/^\d{1,}$/',
92 'export' => true,
93 ),
7a7cc10b 94 'do_not_phone' => array(
6a488035
TO
95 'name' => 'do_not_phone',
96 'type' => 16,
97 'title' => 'Do Not Phone',
98 'import' => true,
99 'where' => 'civicrm_contact.do_not_phone',
100 'headerPattern' => '/d(o )?(not )?(call|phone)/i',
101 'dataPattern' => '/^\d{1,}$/',
102 'export' => true,
103 ),
7a7cc10b 104 'do_not_mail' => array(
6a488035
TO
105 'name' => 'do_not_mail',
106 'type' => 16,
107 'title' => 'Do Not Mail',
108 'import' => true,
109 'where' => 'civicrm_contact.do_not_mail',
110 'headerPattern' => '/^(d(o\s)?n(ot\s)?mail)|(\w*)?bulk\s?(\w*)$/i',
111 'dataPattern' => '/^\d{1,}$/',
112 'export' => true,
113 ),
7a7cc10b 114 'do_not_sms' => array(
6a488035
TO
115 'name' => 'do_not_sms',
116 'type' => 16,
117 'title' => 'Do Not Sms',
118 'import' => true,
119 'where' => 'civicrm_contact.do_not_sms',
120 'headerPattern' => '/d(o )?(not )?(sms)/i',
121 'dataPattern' => '/^\d{1,}$/',
122 'export' => true,
123 ),
7a7cc10b 124 'do_not_trade' => array(
6a488035
TO
125 'name' => 'do_not_trade',
126 'type' => 16,
127 'title' => 'Do Not Trade',
128 'import' => true,
129 'where' => 'civicrm_contact.do_not_trade',
130 'headerPattern' => '/d(o )?(not )?(trade)/i',
131 'dataPattern' => '/^\d{1,}$/',
132 'export' => true,
133 ),
7a7cc10b 134 'is_opt_out' => array(
6a488035
TO
135 'name' => 'is_opt_out',
136 'type' => 16,
137 'title' => 'No Bulk Emails (User Opt Out)',
138 'required' => true,
139 'import' => true,
140 'where' => 'civicrm_contact.is_opt_out',
141 'export' => true,
142 ),
7a7cc10b 143 'legal_identifier' => array(
6a488035
TO
144 'name' => 'legal_identifier',
145 'type' => 2,
146 'title' => 'Legal Identifier',
147 'maxlength' => 32,
148 'size' => 20,
149 'import' => true,
150 'where' => 'civicrm_contact.legal_identifier',
151 'headerPattern' => '/legal\s?id/i',
152 'dataPattern' => '/\w+?\d{5,}/',
153 'export' => true,
154 ),
7a7cc10b 155 'external_identifier' => array(
6a488035
TO
156 'name' => 'external_identifier',
157 'type' => 2,
158 'title' => 'External Identifier',
159 'maxlength' => 32,
160 'size' => 8,
161 'import' => true,
162 'where' => 'civicrm_contact.external_identifier',
163 'headerPattern' => '/external\s?id/i',
164 'dataPattern' => '/^\d{11,}$/',
165 'export' => true,
166 ),
7a7cc10b 167 'sort_name' => array(
6a488035
TO
168 'name' => 'sort_name',
169 'type' => 2,
170 'title' => 'Sort Name',
171 'maxlength' => 128,
172 'size' => 30,
173 'export' => true,
174 'where' => 'civicrm_contact.sort_name',
175 ),
7a7cc10b 176 'display_name' => array(
6a488035
TO
177 'name' => 'display_name',
178 'type' => 2,
179 'title' => 'Display Name',
180 'maxlength' => 128,
181 'size' => 30,
182 'export' => true,
183 'where' => 'civicrm_contact.display_name',
184 ),
7a7cc10b 185 'nick_name' => array(
6a488035
TO
186 'name' => 'nick_name',
187 'type' => 2,
7a7cc10b 188 'title' => 'Nickname',
6a488035
TO
189 'maxlength' => 128,
190 'size' => 30,
191 'import' => true,
192 'where' => 'civicrm_contact.nick_name',
193 'headerPattern' => '/n(ick\s)name|nick$/i',
194 'dataPattern' => '/^\w+$/',
195 'export' => true,
196 ),
7a7cc10b 197 'legal_name' => array(
6a488035
TO
198 'name' => 'legal_name',
199 'type' => 2,
200 'title' => 'Legal Name',
201 'maxlength' => 128,
202 'size' => 30,
203 'import' => true,
204 'where' => 'civicrm_contact.legal_name',
205 'headerPattern' => '/^legal|(l(egal\s)?name)$/i',
206 'export' => true,
207 ),
7a7cc10b 208 'image_URL' => array(
6a488035
TO
209 'name' => 'image_URL',
210 'type' => 2,
211 'title' => 'Image Url',
212 'maxlength' => 255,
213 'size' => 45,
214 'import' => true,
215 'where' => 'civicrm_contact.image_URL',
216 'export' => true,
217 ),
7a7cc10b 218 'preferred_communication_method' => array(
6a488035
TO
219 'name' => 'preferred_communication_method',
220 'type' => 2,
221 'title' => 'Preferred Communication Method',
222 'maxlength' => 255,
223 'size' => 45,
224 'import' => true,
225 'where' => 'civicrm_contact.preferred_communication_method',
226 'headerPattern' => '/^p(ref\w*\s)?c(omm\w*)|( meth\w*)$/i',
227 'dataPattern' => '/^\w+$/',
228 'export' => true,
7a7cc10b 229 'pseudoconstant' => array(
230 'optionGroupName' => 'preferred_communication_method',
231 ),
6a488035 232 ),
7a7cc10b 233 'preferred_language' => array(
6a488035
TO
234 'name' => 'preferred_language',
235 'type' => 2,
236 'title' => 'Preferred Language',
237 'maxlength' => 5,
238 'size' => 6,
239 'import' => true,
240 'where' => 'civicrm_contact.preferred_language',
241 'headerPattern' => '/^lang/i',
242 'export' => true,
7a7cc10b 243 'pseudoconstant' => array(
244 'optionGroupName' => 'languages',
245 'keyColumn' => 'name',
246 ),
6a488035 247 ),
7a7cc10b 248 'preferred_mail_format' => array(
6a488035
TO
249 'name' => 'preferred_mail_format',
250 'type' => 2,
251 'title' => 'Preferred Mail Format',
252 'import' => true,
253 'where' => 'civicrm_contact.preferred_mail_format',
254 'headerPattern' => '/^p(ref\w*\s)?m(ail\s)?f(orm\w*)$/i',
255 'export' => true,
256 'default' => 'Both',
257 'enumValues' => 'Text, HTML, Both',
6a488035 258 ),
7a7cc10b 259 'hash' => array(
6a488035
TO
260 'name' => 'hash',
261 'type' => 2,
262 'title' => 'Contact Hash',
263 'maxlength' => 32,
264 'size' => 20,
265 'export' => true,
266 'where' => 'civicrm_contact.hash',
267 ),
7a7cc10b 268 'api_key' => array(
6a488035
TO
269 'name' => 'api_key',
270 'type' => 2,
271 'title' => 'Api Key',
272 'maxlength' => 32,
273 'size' => 20,
274 ),
7a7cc10b 275 'first_name' => array(
6a488035
TO
276 'name' => 'first_name',
277 'type' => 2,
278 'title' => 'First Name',
279 'maxlength' => 64,
280 'size' => 30,
281 'import' => true,
282 'where' => 'civicrm_contact.first_name',
283 'headerPattern' => '/^first|(f(irst\s)?name)$/i',
284 'dataPattern' => '/^\w+$/',
285 'export' => true,
286 ),
7a7cc10b 287 'middle_name' => array(
6a488035
TO
288 'name' => 'middle_name',
289 'type' => 2,
290 'title' => 'Middle Name',
291 'maxlength' => 64,
292 'size' => 20,
293 'import' => true,
294 'where' => 'civicrm_contact.middle_name',
295 'headerPattern' => '/^middle|(m(iddle\s)?name)$/i',
296 'dataPattern' => '/^\w+$/',
297 'export' => true,
298 ),
7a7cc10b 299 'last_name' => array(
6a488035
TO
300 'name' => 'last_name',
301 'type' => 2,
302 'title' => 'Last Name',
303 'maxlength' => 64,
304 'size' => 30,
305 'import' => true,
306 'where' => 'civicrm_contact.last_name',
307 'headerPattern' => '/^last|(l(ast\s)?name)$/i',
308 'dataPattern' => '/^\w+(\s\w+)?+$/',
309 'export' => true,
310 ),
7a7cc10b 311 'email_greeting_id' => array(
6a488035
TO
312 'name' => 'email_greeting_id',
313 'type' => 1,
314 'title' => 'Email Greeting ID',
315 ),
7a7cc10b 316 'email_greeting_custom' => array(
6a488035
TO
317 'name' => 'email_greeting_custom',
318 'type' => 2,
319 'title' => 'Email Greeting Custom',
320 'maxlength' => 128,
321 'size' => 45,
322 'import' => true,
323 'where' => 'civicrm_contact.email_greeting_custom',
324 ),
7a7cc10b 325 'email_greeting_display' => array(
6a488035
TO
326 'name' => 'email_greeting_display',
327 'type' => 2,
328 'title' => 'Email Greeting',
329 'maxlength' => 255,
330 'size' => 45,
331 ),
7a7cc10b 332 'postal_greeting_id' => array(
6a488035
TO
333 'name' => 'postal_greeting_id',
334 'type' => 1,
335 'title' => 'Postal Greeting ID',
336 ),
7a7cc10b 337 'postal_greeting_custom' => array(
6a488035
TO
338 'name' => 'postal_greeting_custom',
339 'type' => 2,
340 'title' => 'Postal Greeting Custom',
341 'maxlength' => 128,
342 'size' => 45,
343 'import' => true,
344 'where' => 'civicrm_contact.postal_greeting_custom',
345 ),
7a7cc10b 346 'postal_greeting_display' => array(
6a488035
TO
347 'name' => 'postal_greeting_display',
348 'type' => 2,
349 'title' => 'Postal Greeting',
350 'maxlength' => 255,
351 'size' => 45,
352 ),
7a7cc10b 353 'addressee_id' => array(
6a488035
TO
354 'name' => 'addressee_id',
355 'type' => 1,
356 'title' => 'Addressee ID',
357 ),
7a7cc10b 358 'addressee_custom' => array(
6a488035
TO
359 'name' => 'addressee_custom',
360 'type' => 2,
361 'title' => 'Addressee Custom',
362 'maxlength' => 128,
363 'size' => 45,
364 'import' => true,
365 'where' => 'civicrm_contact.addressee_custom',
366 ),
7a7cc10b 367 'addressee_display' => array(
6a488035
TO
368 'name' => 'addressee_display',
369 'type' => 2,
370 'title' => 'Addressee',
371 'maxlength' => 255,
372 'size' => 45,
373 ),
7a7cc10b 374 'job_title' => array(
6a488035
TO
375 'name' => 'job_title',
376 'type' => 2,
377 'title' => 'Job Title',
378 'maxlength' => 255,
379 'size' => 20,
380 'import' => true,
381 'where' => 'civicrm_contact.job_title',
382 'headerPattern' => '/^job|(j(ob\s)?title)$/i',
383 'dataPattern' => '//',
384 'export' => true,
385 ),
7a7cc10b 386 'gender_id' => array(
6a488035
TO
387 'name' => 'gender_id',
388 'type' => 1,
389 'title' => 'Gender',
7a7cc10b 390 'import' => true,
391 'where' => 'civicrm_contact.gender_id',
392 'headerPattern' => '/^gender$/i',
393 'export' => true,
394 'pseudoconstant' => array(
6a488035
TO
395 'optionGroupName' => 'gender',
396 ),
6a488035 397 ),
7a7cc10b 398 'birth_date' => array(
6a488035
TO
399 'name' => 'birth_date',
400 'type' => 4,
401 'title' => 'Birth Date',
402 'import' => true,
403 'where' => 'civicrm_contact.birth_date',
404 'headerPattern' => '/^birth|(b(irth\s)?date)|D(\W*)O(\W*)B(\W*)$/i',
405 'dataPattern' => '/\d{4}-?\d{2}-?\d{2}/',
406 'export' => true,
407 ),
7a7cc10b 408 'is_deceased' => array(
6a488035
TO
409 'name' => 'is_deceased',
410 'type' => 16,
411 'title' => 'Is Deceased',
412 'import' => true,
413 'where' => 'civicrm_contact.is_deceased',
414 'headerPattern' => '/i(s\s)?d(eceased)$/i',
415 'export' => true,
416 ),
7a7cc10b 417 'deceased_date' => array(
6a488035
TO
418 'name' => 'deceased_date',
419 'type' => 4,
420 'title' => 'Deceased Date',
421 'import' => true,
422 'where' => 'civicrm_contact.deceased_date',
423 'headerPattern' => '/^deceased|(d(eceased\s)?date)$/i',
424 'export' => true,
425 ),
7a7cc10b 426 'household_name' => array(
6a488035
TO
427 'name' => 'household_name',
428 'type' => 2,
429 'title' => 'Household Name',
430 'maxlength' => 128,
431 'size' => 30,
432 'import' => true,
433 'where' => 'civicrm_contact.household_name',
434 'headerPattern' => '/^household|(h(ousehold\s)?name)$/i',
435 'dataPattern' => '/^\w+$/',
436 'export' => true,
437 ),
7a7cc10b 438 'primary_contact_id' => array(
6a488035
TO
439 'name' => 'primary_contact_id',
440 'type' => 1,
441 'title' => 'Household Primary Contact ID',
442 'FKClassName' => 'CRM_Contact_DAO_Contact',
443 ),
7a7cc10b 444 'organization_name' => array(
6a488035
TO
445 'name' => 'organization_name',
446 'type' => 2,
447 'title' => 'Organization Name',
448 'maxlength' => 128,
449 'size' => 30,
450 'import' => true,
451 'where' => 'civicrm_contact.organization_name',
452 'headerPattern' => '/^organization|(o(rganization\s)?name)$/i',
453 'dataPattern' => '/^\w+$/',
454 'export' => true,
455 ),
7a7cc10b 456 'sic_code' => array(
6a488035
TO
457 'name' => 'sic_code',
458 'type' => 2,
459 'title' => 'Sic Code',
460 'maxlength' => 8,
461 'size' => 8,
462 'import' => true,
463 'where' => 'civicrm_contact.sic_code',
464 'headerPattern' => '/^sic|(s(ic\s)?code)$/i',
465 'export' => true,
466 ),
7a7cc10b 467 'user_unique_id' => array(
6a488035
TO
468 'name' => 'user_unique_id',
469 'type' => 2,
470 'title' => 'Unique ID (OpenID)',
471 'maxlength' => 255,
472 'size' => 45,
473 'import' => true,
474 'where' => 'civicrm_contact.user_unique_id',
475 'headerPattern' => '/^Open\s?ID|u(niq\w*)?\s?ID/i',
476 'dataPattern' => '/^[\w\/\:\.]+$/',
477 'export' => true,
478 'rule' => 'url',
479 ),
7a7cc10b 480 'created_date' => array(
6a488035
TO
481 'name' => 'created_date',
482 'type' => 256,
483 'title' => 'Created Date',
484 'required' => '',
485 'default' => 'UL',
486 ),
7a7cc10b 487 'modified_date' => array(
6a488035
TO
488 'name' => 'modified_date',
489 'type' => 256,
490 'title' => 'Modified Date',
491 'required' => '',
492 'default' => 'URRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAM',
493 ),
7a7cc10b 494 'source' => array(
6a488035
TO
495 'name' => 'source',
496 'type' => 2,
497 'title' => 'Source of Contact Data',
498 'maxlength' => 255,
499 'size' => 30,
500 'import' => true,
501 'where' => 'civicrm_contact.source',
502 'headerPattern' => '/(S(ource\s)?o(f\s)?C(ontact\s)?Data)$/i',
503 'export' => true,
504 'uniqueName' => 'contact_source',
505 ),
fb32de45 506 'prefix_id' => array(
507 'name' => 'prefix_id',
508 'type' => 1,
509 'title' => 'Individual Prefix',
510 'import' => true,
511 'where' => 'civicrm_contact.prefix_id',
512 'headerPattern' => '/^(prefix|title)/i',
513 'dataPattern' => '/^(mr|ms|mrs|sir|dr)\.?$/i',
514 'export' => true,
515 'pseudoconstant' => array(
516 'optionGroupName' => 'individual_prefix',
517 ),
518 'uniqueName' => 'individual_prefix_id',
519 ),
520 'suffix_id' => array(
521 'name' => 'suffix_id',
522 'type' => 1,
523 'title' => 'Individual Suffix',
524 'import' => true,
525 'where' => 'civicrm_contact.suffix_id',
526 'headerPattern' => '/^suffix$/i',
527 'dataPattern' => '/^(sr|jr)\.?|i{2,}$/',
528 'export' => true,
529 'pseudoconstant' => array(
530 'optionGroupName' => 'individual_suffix',
531 ),
532 'uniqueName' => 'individual_suffix_id',
533 ),
7a7cc10b 534 'employer_id' => array(
6a488035
TO
535 'name' => 'employer_id',
536 'type' => 1,
537 'title' => 'Current Employer ID',
538 'export' => true,
539 'where' => 'civicrm_contact.employer_id',
540 'FKClassName' => 'CRM_Contact_DAO_Contact',
541 'uniqueName' => 'current_employer_id',
542 ),
7a7cc10b 543 'is_deleted' => array(
6a488035
TO
544 'name' => 'is_deleted',
545 'type' => 16,
546 'title' => 'Contact is in Trash',
547 'required' => true,
548 'export' => true,
549 'where' => 'civicrm_contact.is_deleted',
550 'uniqueName' => 'contact_is_deleted',
551 ),
7a7cc10b 552 'custom_1' => array(
7f6d3dd3 553 'label' => 'Our special field',
6a488035
TO
554 'groupTitle' => 'select_test_g',
555 'data_type' => 'String',
556 'html_type' => 'Select',
557 'text_length' => '',
558 'options_per_line' => '',
559 'custom_group_id' => '1',
560 'extends' => 'Contact',
561 'is_search_range' => 0,
562 'extends_entity_column_value' => '',
563 'extends_entity_column_id' => '',
564 'is_view' => 0,
565 'is_multiple' => 0,
fb32de45 566 'option_group_id' => '99',
6a488035
TO
567 'date_format' => '',
568 'time_format' => '',
53ca8fd7 569 'name' => 'custom_1',
7a7cc10b 570 'options' => array(
6a488035
TO
571 '1' => 'Label1',
572 '2' => 'Label2',
573 ),
574 ),
7a7cc10b 575 'current_employer' => array(
6a488035
TO
576 'title' => 'Current Employer',
577 'description' => 'Name of Current Employer',
578 ),
7a7cc10b 579 'dupe_check' => array(
580 'title' => 'Check for Duplicates',
581 'description' => 'Throw error if contact create matches dedupe rule',
582 ),
6a488035
TO
583 ),
584);
585
fb32de45 586 return $expectedResult;
6a488035
TO
587}
588
589
590/*
591* This example has been generated from the API test suite. The test that created it is called
592*
593* testCustomFieldCreateWithOptionValues and can be found in
594* http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/ContactTest.php
595*
596* You can see the outcome of the API tests at
597* http://tests.dev.civicrm.org/trunk/results-api_v3
598*
599* To Learn about the API read
600* http://book.civicrm.org/developer/current/techniques/api/
601*
602* and review the wiki at
603* http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs
604*
605* Read more about testing here
606* http://wiki.civicrm.org/confluence/display/CRM/Testing
607*
608* API Standards documentation:
609* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
610*/