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