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