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