CRM-13122 ensure fix is tested, also remove obvious cruft from api & update examples...
[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 ),
9f1b81e0 311 'prefix_id' => array(
312 'name' => 'prefix_id',
313 'type' => 1,
314 'title' => 'Individual Prefix',
315 'import' => true,
316 'where' => 'civicrm_contact.prefix_id',
317 'headerPattern' => '/^(prefix|title)/i',
318 'dataPattern' => '/^(mr|ms|mrs|sir|dr)\.?$/i',
319 'export' => true,
320 'pseudoconstant' => array(
321 'optionGroupName' => 'individual_prefix',
322 ),
323 ),
324 'suffix_id' => array(
325 'name' => 'suffix_id',
326 'type' => 1,
327 'title' => 'Individual Suffix',
328 'import' => true,
329 'where' => 'civicrm_contact.suffix_id',
330 'headerPattern' => '/^suffix$/i',
331 'dataPattern' => '/^(sr|jr)\.?|i{2,}$/',
332 'export' => true,
333 'pseudoconstant' => array(
334 'optionGroupName' => 'individual_suffix',
335 ),
336 ),
7a7cc10b 337 'email_greeting_id' => array(
6a488035
TO
338 'name' => 'email_greeting_id',
339 'type' => 1,
340 'title' => 'Email Greeting ID',
341 ),
7a7cc10b 342 'email_greeting_custom' => array(
6a488035
TO
343 'name' => 'email_greeting_custom',
344 'type' => 2,
345 'title' => 'Email Greeting Custom',
346 'maxlength' => 128,
347 'size' => 45,
348 'import' => true,
349 'where' => 'civicrm_contact.email_greeting_custom',
350 ),
7a7cc10b 351 'email_greeting_display' => array(
6a488035
TO
352 'name' => 'email_greeting_display',
353 'type' => 2,
354 'title' => 'Email Greeting',
355 'maxlength' => 255,
356 'size' => 45,
357 ),
7a7cc10b 358 'postal_greeting_id' => array(
6a488035
TO
359 'name' => 'postal_greeting_id',
360 'type' => 1,
361 'title' => 'Postal Greeting ID',
362 ),
7a7cc10b 363 'postal_greeting_custom' => array(
6a488035
TO
364 'name' => 'postal_greeting_custom',
365 'type' => 2,
366 'title' => 'Postal Greeting Custom',
367 'maxlength' => 128,
368 'size' => 45,
369 'import' => true,
370 'where' => 'civicrm_contact.postal_greeting_custom',
371 ),
7a7cc10b 372 'postal_greeting_display' => array(
6a488035
TO
373 'name' => 'postal_greeting_display',
374 'type' => 2,
375 'title' => 'Postal Greeting',
376 'maxlength' => 255,
377 'size' => 45,
378 ),
7a7cc10b 379 'addressee_id' => array(
6a488035
TO
380 'name' => 'addressee_id',
381 'type' => 1,
382 'title' => 'Addressee ID',
383 ),
7a7cc10b 384 'addressee_custom' => array(
6a488035
TO
385 'name' => 'addressee_custom',
386 'type' => 2,
387 'title' => 'Addressee Custom',
388 'maxlength' => 128,
389 'size' => 45,
390 'import' => true,
391 'where' => 'civicrm_contact.addressee_custom',
392 ),
7a7cc10b 393 'addressee_display' => array(
6a488035
TO
394 'name' => 'addressee_display',
395 'type' => 2,
396 'title' => 'Addressee',
397 'maxlength' => 255,
398 'size' => 45,
399 ),
7a7cc10b 400 'job_title' => array(
6a488035
TO
401 'name' => 'job_title',
402 'type' => 2,
403 'title' => 'Job Title',
404 'maxlength' => 255,
405 'size' => 20,
406 'import' => true,
407 'where' => 'civicrm_contact.job_title',
408 'headerPattern' => '/^job|(j(ob\s)?title)$/i',
409 'dataPattern' => '//',
410 'export' => true,
411 ),
7a7cc10b 412 'gender_id' => array(
6a488035
TO
413 'name' => 'gender_id',
414 'type' => 1,
415 'title' => 'Gender',
7a7cc10b 416 'import' => true,
417 'where' => 'civicrm_contact.gender_id',
418 'headerPattern' => '/^gender$/i',
419 'export' => true,
420 'pseudoconstant' => array(
6a488035
TO
421 'optionGroupName' => 'gender',
422 ),
6a488035 423 ),
7a7cc10b 424 'birth_date' => array(
6a488035
TO
425 'name' => 'birth_date',
426 'type' => 4,
427 'title' => 'Birth Date',
428 'import' => true,
429 'where' => 'civicrm_contact.birth_date',
430 'headerPattern' => '/^birth|(b(irth\s)?date)|D(\W*)O(\W*)B(\W*)$/i',
431 'dataPattern' => '/\d{4}-?\d{2}-?\d{2}/',
432 'export' => true,
433 ),
7a7cc10b 434 'is_deceased' => array(
6a488035
TO
435 'name' => 'is_deceased',
436 'type' => 16,
437 'title' => 'Is Deceased',
438 'import' => true,
439 'where' => 'civicrm_contact.is_deceased',
440 'headerPattern' => '/i(s\s)?d(eceased)$/i',
441 'export' => true,
442 ),
7a7cc10b 443 'deceased_date' => array(
6a488035
TO
444 'name' => 'deceased_date',
445 'type' => 4,
446 'title' => 'Deceased Date',
447 'import' => true,
448 'where' => 'civicrm_contact.deceased_date',
449 'headerPattern' => '/^deceased|(d(eceased\s)?date)$/i',
450 'export' => true,
451 ),
7a7cc10b 452 'household_name' => array(
6a488035
TO
453 'name' => 'household_name',
454 'type' => 2,
455 'title' => 'Household Name',
456 'maxlength' => 128,
457 'size' => 30,
458 'import' => true,
459 'where' => 'civicrm_contact.household_name',
460 'headerPattern' => '/^household|(h(ousehold\s)?name)$/i',
461 'dataPattern' => '/^\w+$/',
462 'export' => true,
463 ),
7a7cc10b 464 'primary_contact_id' => array(
6a488035
TO
465 'name' => 'primary_contact_id',
466 'type' => 1,
467 'title' => 'Household Primary Contact ID',
468 'FKClassName' => 'CRM_Contact_DAO_Contact',
469 ),
7a7cc10b 470 'organization_name' => array(
6a488035
TO
471 'name' => 'organization_name',
472 'type' => 2,
473 'title' => 'Organization Name',
474 'maxlength' => 128,
475 'size' => 30,
476 'import' => true,
477 'where' => 'civicrm_contact.organization_name',
478 'headerPattern' => '/^organization|(o(rganization\s)?name)$/i',
479 'dataPattern' => '/^\w+$/',
480 'export' => true,
481 ),
7a7cc10b 482 'sic_code' => array(
6a488035
TO
483 'name' => 'sic_code',
484 'type' => 2,
485 'title' => 'Sic Code',
486 'maxlength' => 8,
487 'size' => 8,
488 'import' => true,
489 'where' => 'civicrm_contact.sic_code',
490 'headerPattern' => '/^sic|(s(ic\s)?code)$/i',
491 'export' => true,
492 ),
7a7cc10b 493 'user_unique_id' => array(
6a488035
TO
494 'name' => 'user_unique_id',
495 'type' => 2,
496 'title' => 'Unique ID (OpenID)',
497 'maxlength' => 255,
498 'size' => 45,
499 'import' => true,
500 'where' => 'civicrm_contact.user_unique_id',
501 'headerPattern' => '/^Open\s?ID|u(niq\w*)?\s?ID/i',
502 'dataPattern' => '/^[\w\/\:\.]+$/',
503 'export' => true,
504 'rule' => 'url',
505 ),
7a7cc10b 506 'created_date' => array(
6a488035
TO
507 'name' => 'created_date',
508 'type' => 256,
509 'title' => 'Created Date',
510 'required' => '',
511 'default' => 'UL',
512 ),
7a7cc10b 513 'modified_date' => array(
6a488035
TO
514 'name' => 'modified_date',
515 'type' => 256,
516 'title' => 'Modified Date',
517 'required' => '',
518 'default' => 'URRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAM',
519 ),
7a7cc10b 520 'source' => array(
6a488035
TO
521 'name' => 'source',
522 'type' => 2,
523 'title' => 'Source of Contact Data',
524 'maxlength' => 255,
525 'size' => 30,
526 'import' => true,
527 'where' => 'civicrm_contact.source',
528 'headerPattern' => '/(S(ource\s)?o(f\s)?C(ontact\s)?Data)$/i',
529 'export' => true,
530 'uniqueName' => 'contact_source',
531 ),
7a7cc10b 532 'employer_id' => array(
6a488035
TO
533 'name' => 'employer_id',
534 'type' => 1,
535 'title' => 'Current Employer ID',
536 'export' => true,
537 'where' => 'civicrm_contact.employer_id',
538 'FKClassName' => 'CRM_Contact_DAO_Contact',
539 'uniqueName' => 'current_employer_id',
540 ),
7a7cc10b 541 'is_deleted' => array(
6a488035
TO
542 'name' => 'is_deleted',
543 'type' => 16,
544 'title' => 'Contact is in Trash',
545 'required' => true,
546 'export' => true,
547 'where' => 'civicrm_contact.is_deleted',
548 'uniqueName' => 'contact_is_deleted',
549 ),
7a7cc10b 550 'custom_1' => array(
7f6d3dd3 551 'label' => 'Our special field',
6a488035
TO
552 'groupTitle' => 'select_test_g',
553 'data_type' => 'String',
554 'html_type' => 'Select',
555 'text_length' => '',
556 'options_per_line' => '',
557 'custom_group_id' => '1',
558 'extends' => 'Contact',
559 'is_search_range' => 0,
560 'extends_entity_column_value' => '',
561 'extends_entity_column_id' => '',
562 'is_view' => 0,
563 'is_multiple' => 0,
fb32de45 564 'option_group_id' => '99',
6a488035
TO
565 'date_format' => '',
566 'time_format' => '',
53ca8fd7 567 'name' => 'custom_1',
7a7cc10b 568 'options' => array(
6a488035
TO
569 '1' => 'Label1',
570 '2' => 'Label2',
571 ),
572 ),
7a7cc10b 573 'current_employer' => array(
6a488035
TO
574 'title' => 'Current Employer',
575 'description' => 'Name of Current Employer',
576 ),
7a7cc10b 577 'dupe_check' => array(
578 'title' => 'Check for Duplicates',
579 'description' => 'Throw error if contact create matches dedupe rule',
580 ),
6a488035
TO
581 ),
582);
583
fb32de45 584 return $expectedResult;
6a488035
TO
585}
586
587
588/*
589* This example has been generated from the API test suite. The test that created it is called
590*
591* testCustomFieldCreateWithOptionValues and can be found in
592* http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/ContactTest.php
593*
594* You can see the outcome of the API tests at
595* http://tests.dev.civicrm.org/trunk/results-api_v3
596*
597* To Learn about the API read
598* http://book.civicrm.org/developer/current/techniques/api/
599*
600* and review the wiki at
601* http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs
602*
603* Read more about testing here
604* http://wiki.civicrm.org/confluence/display/CRM/Testing
605*
606* API Standards documentation:
607* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards
608*/