-
-
Notifications
You must be signed in to change notification settings - Fork 828
/
Copy pathCriteria.php
639 lines (564 loc) · 25 KB
/
Criteria.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 5 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2019 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2019
*/
class CRM_Contact_Form_Search_Criteria {
/**
* @param CRM_Contact_Form_Search_Advanced $form
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public static function basic(&$form) {
$form->addSearchFieldMetadata(['Contact' => self::getFilteredSearchFieldMetadata('basic')]);
$form->addFormFieldsFromMetadata();
self::setBasicSearchFields($form);
$form->addElement('hidden', 'hidden_basic', 1);
if ($form->_searchOptions['contactType']) {
$contactTypes = CRM_Contact_BAO_ContactType::getSelectElements();
if ($contactTypes) {
$form->add('select', 'contact_type', ts('Contact Type(s)'), $contactTypes, FALSE,
['id' => 'contact_type', 'multiple' => 'multiple', 'class' => 'crm-select2', 'style' => 'width: 100%;']
);
}
}
if ($form->_searchOptions['groups']) {
// multiselect for groups
if ($form->_group) {
// Arrange groups into hierarchical listing (child groups follow their parents and have indentation spacing in title)
$groupHierarchy = CRM_Contact_BAO_Group::getGroupsHierarchy($form->_group, NULL, ' ', TRUE);
$form->add('select', 'group', ts('Groups'), $groupHierarchy, FALSE,
['id' => 'group', 'multiple' => 'multiple', 'class' => 'crm-select2']
);
$groupOptions = CRM_Core_BAO_OptionValue::getOptionValuesAssocArrayFromName('group_type');
$form->add('select', 'group_type', ts('Group Types'), $groupOptions, FALSE,
['id' => 'group_type', 'multiple' => 'multiple', 'class' => 'crm-select2']
);
$form->add('hidden', 'group_search_selected', 'group');
}
}
if ($form->_searchOptions['tags']) {
// multiselect for categories
$contactTags = CRM_Core_BAO_Tag::getTags();
if ($contactTags) {
$form->add('select', 'contact_tags', ts('Select Tag(s)'), $contactTags, FALSE,
['id' => 'contact_tags', 'multiple' => 'multiple', 'class' => 'crm-select2', 'style' => 'width: 100%;']
);
}
$parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_contact');
CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_contact', NULL, TRUE, FALSE);
$used_for = CRM_Core_OptionGroup::values('tag_used_for');
$tagsTypes = [];
$showAllTagTypes = FALSE;
foreach ($used_for as $key => $value) {
//check tags for every type and find if there are any defined
$tags = CRM_Core_BAO_Tag::getTagsUsedFor($key, FALSE, TRUE, NULL);
// check if there are tags other than contact type, if no - keep checkbox hidden on adv search
// we will hide searching contact by attachments tags until it will be implemented in core
if (count($tags) && $key != 'civicrm_file' && $key != 'civicrm_contact') {
//if tags exists then add type to display in adv search form help text
$tagsTypes[] = $value;
$showAllTagTypes = TRUE;
}
}
$tagTypesText = implode(" or ", $tagsTypes);
if ($showAllTagTypes) {
$form->add('checkbox', 'all_tag_types', ts('Include tags used for %1', [1 => $tagTypesText]));
$form->add('hidden', 'tag_types_text', $tagTypesText);
}
}
//added contact source
$form->add('text', 'contact_source', ts('Contact Source'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'contact_source'));
//added job title
$form->addElement('text', 'job_title', ts('Job Title'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'job_title'));
//added internal ID
$form->add('number', 'contact_id', ts('Contact ID'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'id') + ['min' => 1]);
$form->addRule('contact_id', ts('Please enter valid Contact ID'), 'positiveInteger');
//added external ID
$form->addElement('text', 'external_identifier', ts('External ID'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'external_identifier'));
if (CRM_Core_Permission::check('access deleted contacts') and Civi::settings()->get('contact_undelete')) {
$form->add('checkbox', 'deleted_contacts', ts('Search in Trash') . '<br />' . ts('(deleted contacts)'));
}
// add checkbox for cms users only
$form->addYesNo('uf_user', ts('CMS User?'), TRUE);
// tag all search
$form->add('text', 'tag_search', ts('All Tags'));
// add search profiles
// FIXME: This is probably a part of profiles - need to be
// FIXME: eradicated from here when profiles are reworked.
$types = ['Participant', 'Contribution', 'Membership'];
// get component profiles
$componentProfiles = [];
$componentProfiles = CRM_Core_BAO_UFGroup::getProfiles($types);
$ufGroups = CRM_Core_BAO_UFGroup::getModuleUFGroup('Search Profile', 1);
$accessibleUfGroups = CRM_Core_Permission::ufGroup(CRM_Core_Permission::VIEW);
$searchProfiles = [];
foreach ($ufGroups as $key => $var) {
if (!array_key_exists($key, $componentProfiles) && in_array($key, $accessibleUfGroups)) {
$searchProfiles[$key] = $var['title'];
}
}
$form->add('select',
'uf_group_id',
ts('Views For Display Contacts'),
[
'0' => ts('- default view -'),
] + $searchProfiles,
FALSE,
['class' => 'crm-select2']
);
$componentModes = CRM_Contact_Form_Search::getModeSelect();
$form->assign('component_mappings', json_encode(CRM_Contact_Form_Search::getModeToComponentMapping()));
if (count($componentModes) > 1) {
$form->add('select',
'component_mode',
ts('Display Results As'),
$componentModes,
FALSE,
['class' => 'crm-select2']
);
}
$form->addRadio(
'operator',
ts('Search Operator'),
[
CRM_Contact_BAO_Query::SEARCH_OPERATOR_AND => ts('AND'),
CRM_Contact_BAO_Query::SEARCH_OPERATOR_OR => ts('OR'),
],
['allowClear' => FALSE]
);
// add the option to display relationships
$rTypes = CRM_Core_PseudoConstant::relationshipType();
$rSelect = ['' => ts('- Select Relationship Type-')];
foreach ($rTypes as $rid => $rValue) {
if ($rValue['label_a_b'] == $rValue['label_b_a']) {
$rSelect[$rid] = $rValue['label_a_b'];
}
else {
$rSelect["{$rid}_a_b"] = $rValue['label_a_b'];
$rSelect["{$rid}_b_a"] = $rValue['label_b_a'];
}
}
$form->addElement('select',
'display_relationship_type',
ts('Display Results as Relationship'),
$rSelect,
['class' => 'crm-select2']
);
// checkboxes for DO NOT phone, email, mail
// we take labels from SelectValues
$t = CRM_Core_SelectValues::privacy();
$form->add('select',
'privacy_options',
ts('Privacy'),
$t,
FALSE,
[
'id' => 'privacy_options',
'multiple' => 'multiple',
'class' => 'crm-select2',
]
);
$form->addElement('select',
'privacy_operator',
ts('Operator'),
[
'OR' => ts('OR'),
'AND' => ts('AND'),
]
);
$options = [
1 => ts('Exclude'),
2 => ts('Include by Privacy Option(s)'),
];
$form->addRadio('privacy_toggle', ts('Privacy Options'), $options, ['allowClear' => FALSE]);
// preferred communication method
if (Civi::settings()->get('civimail_multiple_bulk_emails')) {
$form->addSelect('email_on_hold',
['entity' => 'email', 'multiple' => 'multiple', 'label' => ts('Email On Hold'), 'options' => CRM_Core_PseudoConstant::emailOnHoldOptions()]);
}
else {
$form->add('advcheckbox', 'email_on_hold', ts('Email On Hold'));
}
$form->addSelect('preferred_communication_method',
['entity' => 'contact', 'multiple' => 'multiple', 'label' => ts('Preferred Communication Method'), 'option_url' => NULL, 'placeholder' => ts('- any -')]);
//CRM-6138 Preferred Language
$form->addSelect('preferred_language', ['class' => 'twenty', 'context' => 'search']);
// Phone search
$form->addElement('text', 'phone_numeric', ts('Phone'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Phone', 'phone'));
$locationType = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
$phoneType = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id');
$form->add('select', 'phone_location_type_id', ts('Phone Location'), ['' => ts('- any -')] + $locationType, FALSE, ['class' => 'crm-select2']);
$form->add('select', 'phone_phone_type_id', ts('Phone Type'), ['' => ts('- any -')] + $phoneType, FALSE, ['class' => 'crm-select2']);
}
/**
* Get the metadata for fields to be included on the contact search form.
*
* @throws \CiviCRM_API3_Exception
*/
public static function getSearchFieldMetadata() {
$fields = [
'sort_name' => ['title' => ts('Complete OR Partial Name'), 'template_grouping' => 'basic'],
'email' => ['title' => ts('Complete OR Partial Email'), 'entity' => 'Email', 'template_grouping' => 'basic'],
'contact_tags' => ['name' => 'contact_tags', 'type' => CRM_Utils_Type::T_INT, 'is_pseudofield' => TRUE, 'template_grouping' => 'basic'],
'birth_date' => ['name' => 'birth_date', 'template_grouping' => 'demographic'],
'deceased_date' => ['name' => 'deceased_date', 'template_grouping' => 'demographic'],
'relationship_start_date' => ['name' => 'relationship_start_date', 'template_grouping' => 'relationship'],
'relationship_end_date' => ['name' => 'relationship_end_date', 'template_grouping' => 'relationship'],
];
$metadata = civicrm_api3('Relationship', 'getfields', [])['values'];
$metadata = array_merge($metadata, civicrm_api3('Contact', 'getfields', [])['values']);
foreach ($fields as $fieldName => $field) {
$fields[$fieldName] = array_merge(CRM_Utils_Array::value($fieldName, $metadata, []), $field);
}
return $fields;
}
/**
* Get search field metadata filtered by the template grouping field.
*
* @param string $filter
*
* @return array
* @throws \CiviCRM_API3_Exception
*/
public static function getFilteredSearchFieldMetadata($filter) {
$fields = self::getSearchFieldMetadata();
foreach ($fields as $index => $field) {
if ($field['template_grouping'] !== $filter) {
unset($fields[$index]);
}
}
return $fields;
}
/**
* Defines the fields that can be displayed for the basic search section.
*
* @param CRM_Core_Form $form
*
* @throws \CiviCRM_API3_Exception
*/
protected static function setBasicSearchFields($form) {
$searchFields = [];
foreach (self::getFilteredSearchFieldMetadata('basic') as $fieldName => $field) {
$searchFields[$fieldName] = $field;
}
$form->assign('basicSearchFields', array_merge(self::getBasicSearchFields(), $searchFields));
}
/**
* Return list of basic contact fields that can be displayed for the basic search section.
*
*/
public static function getBasicSearchFields() {
$userFramework = CRM_Core_Config::singleton()->userFramework;
return [
// For now an empty array is still left in place for ordering.
'sort_name' => [],
'email' => ['name' => 'email'],
'contact_type' => ['name' => 'contact_type'],
'group' => [
'name' => 'group',
'template' => 'CRM/Contact/Form/Search/Criteria/Fields/group.tpl',
],
'contact_tags' => ['name' => 'contact_tags'],
'tag_types_text' => ['name' => 'tag_types_text'],
'tag_search' => [
'name' => 'tag_search',
'help' => ['id' => 'id-all-tags'],
],
'tag_set' => [
'name' => 'tag_set',
'is_custom' => TRUE,
'template' => 'CRM/Contact/Form/Search/Criteria/Fields/tag_set.tpl',
],
'all_tag_types' => [
'name' => 'all_tag_types',
'class' => 'search-field__span-3 search-field__checkbox',
'help' => ['id' => 'id-all-tag-types'],
],
'phone_numeric' => [
'name' => 'phone_numeric',
'description' => ts('Punctuation and spaces are ignored.'),
],
'phone_location_type_id' => ['name' => 'phone_location_type_id'],
'phone_phone_type_id' => ['name' => 'phone_phone_type_id'],
'privacy_toggle' => [
'name' => 'privacy_toggle',
'class' => 'search-field__span-2',
'template' => 'CRM/Contact/Form/Search/Criteria/Fields/privacy_toggle.tpl',
],
'preferred_communication_method' => [
'name' => 'preferred_communication_method',
'template' => 'CRM/Contact/Form/Search/Criteria/Fields/preferred_communication_method.tpl',
],
'contact_source' => [
'name' => 'contact_source',
'help' => ['id' => 'id-source', 'file' => 'CRM/Contact/Form/Contact'],
],
'job_title' => ['name' => 'job_title'],
'preferred_language' => ['name' => 'preferred_language'],
'contact_id' => [
'name' => 'contact_id',
'help' => ['id' => 'id-contact-id', 'file' => 'CRM/Contact/Form/Contact'],
],
'external_identifier' => [
'name' => 'external_identifier',
'help' => ['id' => 'id-external-id', 'file' => 'CRM/Contact/Form/Contact'],
],
'uf_user' => [
'name' => 'uf_user',
'description' => ts('Does the contact have a %1 Account?', [$userFramework]),
],
];
}
/**
* @param CRM_Core_Form $form
*/
public static function location(&$form) {
$config = CRM_Core_Config::singleton();
// Build location criteria based on _submitValues if
// available; otherwise, use $form->_formValues.
$formValues = $form->_submitValues;
if (empty($formValues) && !empty($form->_formValues)) {
$formValues = $form->_formValues;
}
$form->addElement('hidden', 'hidden_location', 1);
$addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
'address_options', TRUE, NULL, TRUE
);
$attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Address');
$elements = [
'street_address' => [ts('Street Address'), $attributes['street_address'], NULL, NULL],
'supplemental_address_1' => [ts('Supplemental Address 1'), $attributes['supplemental_address_1'], NULL, NULL],
'supplemental_address_2' => [ts('Supplemental Address 2'), $attributes['supplemental_address_2'], NULL, NULL],
'supplemental_address_3' => [ts('Supplemental Address 3'), $attributes['supplemental_address_3'], NULL, NULL],
'city' => [ts('City'), $attributes['city'], NULL, NULL],
'postal_code' => [ts('Postal Code'), $attributes['postal_code'], NULL, NULL],
'country' => [ts('Country'), $attributes['country_id'], 'country', FALSE],
'state_province' => [ts('State/Province'), $attributes['state_province_id'], 'stateProvince', TRUE],
'county' => [ts('County'), $attributes['county_id'], 'county', TRUE],
'address_name' => [ts('Address Name'), $attributes['address_name'], NULL, NULL],
'street_number' => [ts('Street Number'), $attributes['street_number'], NULL, NULL],
'street_name' => [ts('Street Name'), $attributes['street_name'], NULL, NULL],
'street_unit' => [ts('Apt/Unit/Suite'), $attributes['street_unit'], NULL, NULL],
];
$parseStreetAddress = CRM_Utils_Array::value('street_address_parsing', $addressOptions, 0);
$form->assign('parseStreetAddress', $parseStreetAddress);
foreach ($elements as $name => $v) {
list($title, $attributes, $select, $multiSelect) = $v;
if (in_array($name,
['street_number', 'street_name', 'street_unit']
)) {
if (!$parseStreetAddress) {
continue;
}
}
elseif (!$addressOptions[$name]) {
continue;
}
if (!$attributes) {
$attributes = $attributes[$name];
}
if ($select) {
if ($select == 'stateProvince' || $select == 'county') {
$element = $form->addChainSelect($name);
}
else {
$selectElements = ['' => ts('- any -')] + CRM_Core_PseudoConstant::$select();
$element = $form->add('select', $name, $title, $selectElements, FALSE, ['class' => 'crm-select2']);
}
if ($multiSelect) {
$element->setMultiple(TRUE);
}
}
else {
$form->addElement('text', $name, $title, $attributes);
}
if ($addressOptions['postal_code']) {
$attr = ['class' => 'six'] + (array) CRM_Utils_Array::value('postal_code', $attributes);
$form->addElement('text', 'postal_code_low', NULL, $attr + ['placeholder' => ts('From')]);
$form->addElement('text', 'postal_code_high', NULL, $attr + ['placeholder' => ts('To')]);
}
}
// extend addresses with proximity search
if (CRM_Utils_GeocodeProvider::getUsableClassName()) {
$form->addElement('text', 'prox_distance', ts('Find contacts within'), ['class' => 'six']);
$form->addElement('select', 'prox_distance_unit', NULL, [
'miles' => ts('Miles'),
'kilos' => ts('Kilometers'),
]);
$form->addRule('prox_distance', ts('Please enter positive number as a distance'), 'numeric');
}
$form->addSelect('world_region', ['entity' => 'address', 'context' => 'search']);
// select for location type
$locationType = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
$form->add('select', 'location_type', ts('Address Location'), $locationType, FALSE, [
'multiple' => TRUE,
'class' => 'crm-select2',
'placeholder' => ts('Primary'),
]);
// custom data extending addresses
CRM_Core_BAO_Query::addCustomFormFields($form, ['Address']);
}
/**
* @param CRM_Core_Form $form
*/
public static function activity(&$form) {
$form->add('hidden', 'hidden_activity', 1);
CRM_Activity_BAO_Query::buildSearchForm($form);
}
/**
* @param CRM_Core_Form $form
*/
public static function changeLog(&$form) {
$form->add('hidden', 'hidden_changeLog', 1);
// block for change log
$form->addElement('text', 'changed_by', ts('Modified By'), NULL);
$dates = [1 => ts('Added'), 2 => ts('Modified')];
$form->addRadio('log_date', NULL, $dates, ['allowClear' => TRUE]);
CRM_Core_Form_Date::buildDateRange($form, 'log_date', 1, '_low', '_high', ts('From:'), FALSE, FALSE);
}
/**
* @param CRM_Core_Form $form
*/
public static function task(&$form) {
$form->add('hidden', 'hidden_task', 1);
}
/**
* @param CRM_Core_Form_Search $form
*
* @throws \CiviCRM_API3_Exception
*/
public static function relationship(&$form) {
$form->add('hidden', 'hidden_relationship', 1);
$form->addSearchFieldMetadata(['Relationship' => self::getFilteredSearchFieldMetadata('relationship')]);
$form->addFormFieldsFromMetadata();
$form->add('text', 'relation_description', ts('Description'), ['class' => 'twenty']);
$allRelationshipType = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, NULL, TRUE);
$form->add('select', 'relation_type_id', ts('Relationship Type'), ['' => ts('- select -')] + $allRelationshipType, FALSE, ['multiple' => TRUE, 'class' => 'crm-select2']);
$form->addElement('text', 'relation_target_name', ts('Target Contact'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
// relation status
$relStatusOption = [ts('Active'), ts('Inactive'), ts('All')];
$form->addRadio('relation_status', ts('Relationship Status'), $relStatusOption);
$form->setDefaults(['relation_status' => 0]);
// relation permission
$allRelationshipPermissions = CRM_Contact_BAO_Relationship::buildOptions('is_permission_a_b');
$form->add('select', 'relation_permission', ts('Permissioned Relationship'),
['' => ts('- select -')] + $allRelationshipPermissions, FALSE, ['multiple' => TRUE, 'class' => 'crm-select2']);
//add the target group
if ($form->_group) {
$form->add('select', 'relation_target_group', ts('Target Contact(s) in Group'), $form->_group, FALSE,
['id' => 'relation_target_group', 'multiple' => 'multiple', 'class' => 'crm-select2']
);
}
CRM_Core_Form_Date::buildDateRange($form, 'relation_active_period_date', 1, '_low', '_high', ts('From:'), FALSE, FALSE);
// Add reltionship dates
CRM_Core_Form_Date::buildDateRange($form, 'relation_date', 1, '_low', '_high', ts('From:'), FALSE, FALSE);
// add all the custom searchable fields
CRM_Core_BAO_Query::addCustomFormFields($form, ['Relationship']);
}
/**
* @param CRM_Core_Form_Search $form
*
* @throws \CiviCRM_API3_Exception
*/
public static function demographics(&$form) {
$form->add('hidden', 'hidden_demographics', 1);
$form->addSearchFieldMetadata(['Contact' => self::getFilteredSearchFieldMetadata('demographic')]);
$form->addFormFieldsFromMetadata();
// radio button for gender
$genderOptions = [];
$gender = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id');
foreach ($gender as $key => $var) {
$genderOptions[$key] = $form->createElement('radio', NULL,
ts('Gender'), $var, $key,
['id' => "civicrm_gender_{$var}_{$key}"]
);
}
$form->addGroup($genderOptions, 'gender_id', ts('Gender'))->setAttribute('allowClear', TRUE);
$form->add('number', 'age_low', ts('Min Age'), ['class' => 'four', 'min' => 0]);
$form->addRule('age_low', ts('Please enter a positive integer'), 'positiveInteger');
$form->add('number', 'age_high', ts('Max Age'), ['class' => 'four', 'min' => 0]);
$form->addRule('age_high', ts('Please enter a positive integer'), 'positiveInteger');
$form->add('datepicker', 'age_asof_date', ts('As of'), NULL, FALSE, ['time' => FALSE]);
// radio button for is_deceased
$form->addYesNo('is_deceased', ts('Deceased'), TRUE);
}
/**
* @param $form
*/
public static function notes(&$form) {
$form->add('hidden', 'hidden_notes', 1);
$options = [
2 => ts('Body Only'),
3 => ts('Subject Only'),
6 => ts('Both'),
];
$form->addRadio('note_option', '', $options);
$form->addElement('text', 'note', ts('Note Text'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
$form->setDefaults(['note_option' => 6]);
}
/**
* Generate the custom Data Fields based for those with is_searchable = 1.
*
* @param CRM_Contact_Form_Search $form
*/
public static function custom(&$form) {
$form->add('hidden', 'hidden_custom', 1);
$extends = array_merge(['Contact', 'Individual', 'Household', 'Organization'],
CRM_Contact_BAO_ContactType::subTypes()
);
$groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE,
$extends
);
$form->assign('groupTree', $groupDetails);
foreach ($groupDetails as $key => $group) {
$_groupTitle[$key] = $group['name'];
CRM_Core_ShowHideBlocks::links($form, $group['name'], '', '');
foreach ($group['fields'] as $field) {
$fieldId = $field['id'];
$elementName = 'custom_' . $fieldId;
if ($field['data_type'] == 'Date' && $field['is_search_range']) {
CRM_Core_Form_Date::buildDateRange($form, $elementName, 1, '_from', '_to', ts('From:'), FALSE);
}
else {
CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, TRUE);
}
}
}
}
/**
* @param $form
*/
public static function CiviCase(&$form) {
//Looks like obsolete code, since CiviCase is a component, but might be used by HRD
$form->add('hidden', 'hidden_CiviCase', 1);
CRM_Case_BAO_Query::buildSearchForm($form);
}
}