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