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