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