Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
8c9251b3 | 6 | | Copyright CiviCRM LLC (c) 2004-2018 | |
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 | |
8c9251b3 | 31 | * @copyright CiviCRM LLC (c) 2004-2018 |
6a488035 TO |
32 | */ |
33 | class CRM_Contact_Form_Search_Criteria { | |
8a4f27dc | 34 | /** |
100fef9d | 35 | * @param CRM_Core_Form $form |
8a4f27dc | 36 | */ |
00be9182 | 37 | public static function basic(&$form) { |
6a488035 TO |
38 | $form->addElement('hidden', 'hidden_basic', 1); |
39 | ||
40 | if ($form->_searchOptions['contactType']) { | |
46b3417a | 41 | $contactTypes = CRM_Contact_BAO_ContactType::getSelectElements(); |
6a488035 TO |
42 | |
43 | if ($contactTypes) { | |
44 | $form->add('select', 'contact_type', ts('Contact Type(s)'), $contactTypes, FALSE, | |
02ddf039 | 45 | array('id' => 'contact_type', 'multiple' => 'multiple', 'class' => 'crm-select2', 'style' => 'width: 100%;') |
6a488035 TO |
46 | ); |
47 | } | |
48 | } | |
49 | ||
50 | if ($form->_searchOptions['groups']) { | |
51 | // multiselect for groups | |
52 | if ($form->_group) { | |
53 | // Arrange groups into hierarchical listing (child groups follow their parents and have indentation spacing in title) | |
f828fa2c | 54 | $groupHierarchy = CRM_Contact_BAO_Group::getGroupsHierarchy($form->_group, NULL, ' ', TRUE); |
6a488035 TO |
55 | |
56 | $form->add('select', 'group', ts('Groups'), $groupHierarchy, FALSE, | |
02ddf039 | 57 | array('id' => 'group', 'multiple' => 'multiple', 'class' => 'crm-select2') |
6a488035 TO |
58 | ); |
59 | $groupOptions = CRM_Core_BAO_OptionValue::getOptionValuesAssocArrayFromName('group_type'); | |
60 | $form->add('select', 'group_type', ts('Group Types'), $groupOptions, FALSE, | |
02ddf039 | 61 | array('id' => 'group_type', 'multiple' => 'multiple', 'class' => 'crm-select2') |
6a488035 | 62 | ); |
353ffa53 | 63 | $form->add('hidden', 'group_search_selected', 'group'); |
6a488035 TO |
64 | } |
65 | } | |
66 | ||
67 | if ($form->_searchOptions['tags']) { | |
68 | // multiselect for categories | |
69 | $contactTags = CRM_Core_BAO_Tag::getTags(); | |
70 | ||
71 | if ($contactTags) { | |
72 | $form->add('select', 'contact_tags', ts('Tags'), $contactTags, FALSE, | |
02ddf039 | 73 | array('id' => 'contact_tags', 'multiple' => 'multiple', 'class' => 'crm-select2', 'style' => 'width: 100%;') |
6a488035 TO |
74 | ); |
75 | } | |
76 | ||
77 | $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_contact'); | |
4dff5e17 | 78 | CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_contact', NULL, TRUE, FALSE); |
f828fa2c | 79 | |
6a488035 TO |
80 | $used_for = CRM_Core_OptionGroup::values('tag_used_for'); |
81 | $tagsTypes = array(); | |
ab8a593e | 82 | $showAllTagTypes = FALSE; |
6a488035 TO |
83 | foreach ($used_for as $key => $value) { |
84 | //check tags for every type and find if there are any defined | |
85 | $tags = CRM_Core_BAO_Tag::getTagsUsedFor($key, FALSE, TRUE, NULL); | |
86 | // check if there are tags other than contact type, if no - keep checkbox hidden on adv search | |
87 | // we will hide searching contact by attachments tags until it will be implemented in core | |
88 | if (count($tags) && $key != 'civicrm_file' && $key != 'civicrm_contact') { | |
89 | //if tags exists then add type to display in adv search form help text | |
f828fa2c | 90 | $tagsTypes[] = ts($value); |
4eeb9a5b | 91 | $showAllTagTypes = TRUE; |
6a488035 TO |
92 | } |
93 | } | |
94 | $tagTypesText = implode(" or ", $tagsTypes); | |
95 | if ($showAllTagTypes) { | |
96 | $form->add('checkbox', 'all_tag_types', ts('Include tags used for %1', array(1 => $tagTypesText))); | |
353ffa53 | 97 | $form->add('hidden', 'tag_types_text', $tagTypesText); |
6a488035 TO |
98 | } |
99 | } | |
100 | ||
101 | // add text box for last name, first name, street name, city | |
102 | $form->addElement('text', 'sort_name', ts('Find...'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); | |
103 | ||
104 | // add text box for last name, first name, street name, city | |
105 | $form->add('text', 'email', ts('Contact Email'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); | |
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 | ||
6a488035 | 113 | //added internal ID |
092cb9c5 | 114 | $form->add('number', 'contact_id', ts('Contact ID'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'id') + array('min' => 1)); |
5a0739f2 | 115 | $form->addRule('contact_id', ts('Please enter valid Contact ID'), 'positiveInteger'); |
6a488035 TO |
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 | ||
89595c92 | 120 | if (CRM_Core_Permission::check('access deleted contacts') and Civi::settings()->get('contact_undelete')) { |
6a488035 TO |
121 | $form->add('checkbox', 'deleted_contacts', ts('Search in Trash') . '<br />' . ts('(deleted contacts)')); |
122 | } | |
123 | ||
124 | // add checkbox for cms users only | |
8a4f27dc | 125 | $form->addYesNo('uf_user', ts('CMS User?'), TRUE); |
6a488035 TO |
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 = array('Participant', 'Contribution', 'Membership'); | |
135 | ||
136 | // get component profiles | |
137 | $componentProfiles = array(); | |
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 = array(); | |
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 | ||
3c0ec132 | 150 | $form->add('select', |
6a488035 | 151 | 'uf_group_id', |
e2b3c0e3 | 152 | ts('Views For Display Contacts'), |
6a488035 | 153 | array( |
317fceb4 | 154 | '0' => ts('- default view -'), |
3c0ec132 TM |
155 | ) + $searchProfiles, |
156 | FALSE, | |
157 | array('class' => 'crm-select2') | |
6a488035 TO |
158 | ); |
159 | ||
160 | $componentModes = CRM_Contact_Form_Search::getModeSelect(); | |
e30af20d | 161 | $form->assign('component_mappings', json_encode(CRM_Contact_Form_Search::getModeToComponentMapping())); |
6a488035 | 162 | if (count($componentModes) > 1) { |
3c0ec132 | 163 | $form->add('select', |
6a488035 TO |
164 | 'component_mode', |
165 | ts('Display Results As'), | |
3c0ec132 | 166 | $componentModes, |
ae1f4229 | 167 | FALSE, |
3c0ec132 | 168 | array('class' => 'crm-select2') |
6a488035 TO |
169 | ); |
170 | } | |
171 | ||
3c0ec132 | 172 | $form->addRadio( |
6a488035 TO |
173 | 'operator', |
174 | ts('Search Operator'), | |
6ea503d4 | 175 | array( |
eda34f9b MW |
176 | CRM_Contact_BAO_Query::SEARCH_OPERATOR_AND => ts('AND'), |
177 | CRM_Contact_BAO_Query::SEARCH_OPERATOR_OR => ts('OR'), | |
3c0ec132 TM |
178 | ), |
179 | array('allowClear' => FALSE) | |
6a488035 TO |
180 | ); |
181 | ||
182 | // add the option to display relationships | |
183 | $rTypes = CRM_Core_PseudoConstant::relationshipType(); | |
184 | $rSelect = array('' => 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'), | |
aae123ba CW |
198 | $rSelect, |
199 | array('class' => 'crm-select2') | |
6a488035 TO |
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 | array( | |
211 | 'id' => 'privacy_options', | |
212 | 'multiple' => 'multiple', | |
02ddf039 | 213 | 'class' => 'crm-select2', |
6a488035 TO |
214 | ) |
215 | ); | |
216 | ||
217 | $form->addElement('select', | |
218 | 'privacy_operator', | |
219 | ts('Operator'), | |
6ea503d4 TO |
220 | array( |
221 | 'OR' => ts('OR'), | |
6a488035 TO |
222 | 'AND' => ts('AND'), |
223 | ) | |
224 | ); | |
225 | ||
226 | $options = array( | |
227 | 1 => ts('Exclude'), | |
228 | 2 => ts('Include by Privacy Option(s)'), | |
229 | ); | |
b847e6e7 | 230 | $form->addRadio('privacy_toggle', ts('Privacy Options'), $options, array('allowClear' => FALSE)); |
6a488035 TO |
231 | |
232 | // preferred communication method | |
6a488035 | 233 | |
ba8f6a69 | 234 | $onHold[] = $form->createElement('advcheckbox', 'on_hold', NULL, ''); |
6a488035 TO |
235 | $form->addGroup($onHold, 'email_on_hold', ts('Email On Hold')); |
236 | ||
7cc09daf | 237 | $form->addSelect('preferred_communication_method', |
238 | array('entity' => 'contact', 'multiple' => 'multiple', 'label' => ts('Preferred Communication Method'), 'option_url' => NULL, 'placeholder' => ts('- any -'))); | |
6a488035 TO |
239 | |
240 | //CRM-6138 Preferred Language | |
76773c5a | 241 | $form->addSelect('preferred_language', array('class' => 'twenty', 'context' => 'search')); |
6a488035 TO |
242 | |
243 | // Phone search | |
d79be26c | 244 | $form->addElement('text', 'phone_numeric', ts('Phone'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Phone', 'phone')); |
b2b0530a | 245 | $locationType = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'); |
b4f964d9 | 246 | $phoneType = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id'); |
3c0ec132 TM |
247 | $form->add('select', 'phone_location_type_id', ts('Phone Location'), array('' => ts('- any -')) + $locationType, FALSE, array('class' => 'crm-select2')); |
248 | $form->add('select', 'phone_phone_type_id', ts('Phone Type'), array('' => ts('- any -')) + $phoneType, FALSE, array('class' => 'crm-select2')); | |
6a488035 TO |
249 | } |
250 | ||
251 | ||
86538308 | 252 | /** |
12fbb7b3 | 253 | * @param CRM_Core_Form $form |
86538308 | 254 | */ |
00be9182 | 255 | public static function location(&$form) { |
12fbb7b3 | 256 | $config = CRM_Core_Config::singleton(); |
6a488035 TO |
257 | // Build location criteria based on _submitValues if |
258 | // available; otherwise, use $form->_formValues. | |
259 | $formValues = $form->_submitValues; | |
260 | ||
261 | if (empty($formValues) && !empty($form->_formValues)) { | |
262 | $formValues = $form->_formValues; | |
263 | } | |
264 | ||
265 | $form->addElement('hidden', 'hidden_location', 1); | |
266 | ||
267 | $addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, | |
268 | 'address_options', TRUE, NULL, TRUE | |
269 | ); | |
270 | ||
271 | $attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Address'); | |
272 | ||
273 | $elements = array( | |
274 | 'street_address' => array(ts('Street Address'), $attributes['street_address'], NULL, NULL), | |
539853b9 AS |
275 | 'supplemental_address_1' => array(ts('Supplemental Address 1'), $attributes['supplemental_address_1'], NULL, NULL), |
276 | 'supplemental_address_2' => array(ts('Supplemental Address 2'), $attributes['supplemental_address_2'], NULL, NULL), | |
207f62c6 | 277 | 'supplemental_address_3' => array(ts('Supplemental Address 3'), $attributes['supplemental_address_3'], NULL, NULL), |
6a488035 | 278 | 'city' => array(ts('City'), $attributes['city'], NULL, NULL), |
d79be26c | 279 | 'postal_code' => array(ts('Postal Code'), $attributes['postal_code'], NULL, NULL), |
6a488035 | 280 | 'country' => array(ts('Country'), $attributes['country_id'], 'country', FALSE), |
757069de | 281 | 'state_province' => array(ts('State/Province'), $attributes['state_province_id'], 'stateProvince', TRUE), |
c927c151 | 282 | 'county' => array(ts('County'), $attributes['county_id'], 'county', TRUE), |
6a488035 TO |
283 | 'address_name' => array(ts('Address Name'), $attributes['address_name'], NULL, NULL), |
284 | 'street_number' => array(ts('Street Number'), $attributes['street_number'], NULL, NULL), | |
285 | 'street_name' => array(ts('Street Name'), $attributes['street_name'], NULL, NULL), | |
286 | 'street_unit' => array(ts('Apt/Unit/Suite'), $attributes['street_unit'], NULL, NULL), | |
287 | ); | |
288 | ||
289 | $parseStreetAddress = CRM_Utils_Array::value('street_address_parsing', $addressOptions, 0); | |
290 | $form->assign('parseStreetAddress', $parseStreetAddress); | |
291 | foreach ($elements as $name => $v) { | |
292 | list($title, $attributes, $select, $multiSelect) = $v; | |
293 | ||
294 | if (in_array($name, | |
353ffa53 TO |
295 | array('street_number', 'street_name', 'street_unit') |
296 | )) { | |
6a488035 TO |
297 | if (!$parseStreetAddress) { |
298 | continue; | |
299 | } | |
300 | } | |
301 | elseif (!$addressOptions[$name]) { | |
302 | continue; | |
303 | } | |
304 | ||
305 | if (!$attributes) { | |
306 | $attributes = $attributes[$name]; | |
307 | } | |
308 | ||
309 | if ($select) { | |
c927c151 CW |
310 | if ($select == 'stateProvince' || $select == 'county') { |
311 | $element = $form->addChainSelect($name); | |
6a488035 TO |
312 | } |
313 | else { | |
314 | $selectElements = array('' => ts('- any -')) + CRM_Core_PseudoConstant::$select(); | |
02ddf039 | 315 | $element = $form->add('select', $name, $title, $selectElements, FALSE, array('class' => 'crm-select2')); |
6a488035 TO |
316 | } |
317 | if ($multiSelect) { | |
318 | $element->setMultiple(TRUE); | |
319 | } | |
320 | } | |
321 | else { | |
322 | $form->addElement('text', $name, $title, $attributes); | |
323 | } | |
324 | ||
325 | if ($addressOptions['postal_code']) { | |
12fbb7b3 CW |
326 | $attr = array('class' => 'six') + (array) CRM_Utils_Array::value('postal_code', $attributes); |
327 | $form->addElement('text', 'postal_code_low', NULL, $attr + array('placeholder' => ts('From'))); | |
328 | $form->addElement('text', 'postal_code_high', NULL, $attr + array('placeholder' => ts('To'))); | |
6a488035 TO |
329 | } |
330 | } | |
331 | ||
332 | // extend addresses with proximity search | |
4882d275 | 333 | if (CRM_Utils_GeocodeProvider::getUsableClassName()) { |
12fbb7b3 CW |
334 | $form->addElement('text', 'prox_distance', ts('Find contacts within'), array('class' => 'six')); |
335 | $form->addElement('select', 'prox_distance_unit', NULL, array( | |
336 | 'miles' => ts('Miles'), | |
21dfd5f5 | 337 | 'kilos' => ts('Kilometers'), |
12fbb7b3 CW |
338 | )); |
339 | $form->addRule('prox_distance', ts('Please enter positive number as a distance'), 'numeric'); | |
340 | } | |
6a488035 | 341 | |
76773c5a | 342 | $form->addSelect('world_region', array('entity' => 'address', 'context' => 'search')); |
6a488035 | 343 | |
d8a8bb0b | 344 | // select for location type |
b2b0530a | 345 | $locationType = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'); |
d8a8bb0b CW |
346 | $form->add('select', 'location_type', ts('Address Location'), $locationType, FALSE, array( |
347 | 'multiple' => TRUE, | |
348 | 'class' => 'crm-select2', | |
349 | 'placeholder' => ts('Primary'), | |
350 | )); | |
6a488035 | 351 | |
86a0d21e CW |
352 | // custom data extending addresses |
353 | CRM_Core_BAO_Query::addCustomFormFields($form, array('Address')); | |
6a488035 TO |
354 | } |
355 | ||
86538308 | 356 | /** |
c490a46a | 357 | * @param CRM_Core_Form $form |
86538308 | 358 | */ |
00be9182 | 359 | public static function activity(&$form) { |
6a488035 TO |
360 | $form->add('hidden', 'hidden_activity', 1); |
361 | CRM_Activity_BAO_Query::buildSearchForm($form); | |
362 | } | |
363 | ||
86538308 | 364 | /** |
c490a46a | 365 | * @param CRM_Core_Form $form |
86538308 | 366 | */ |
00be9182 | 367 | public static function changeLog(&$form) { |
6a488035 TO |
368 | $form->add('hidden', 'hidden_changeLog', 1); |
369 | ||
370 | // block for change log | |
371 | $form->addElement('text', 'changed_by', ts('Modified By'), NULL); | |
372 | ||
373 | $dates = array(1 => ts('Added'), 2 => ts('Modified')); | |
672decaf | 374 | $form->addRadio('log_date', NULL, $dates, array('allowClear' => TRUE)); |
6a488035 | 375 | |
672decaf | 376 | CRM_Core_Form_Date::buildDateRange($form, 'log_date', 1, '_low', '_high', ts('From:'), FALSE, FALSE); |
6a488035 TO |
377 | } |
378 | ||
86538308 | 379 | /** |
c490a46a | 380 | * @param CRM_Core_Form $form |
86538308 | 381 | */ |
00be9182 | 382 | public static function task(&$form) { |
6a488035 TO |
383 | $form->add('hidden', 'hidden_task', 1); |
384 | } | |
385 | ||
86538308 EM |
386 | /** |
387 | * @param $form | |
388 | */ | |
00be9182 | 389 | public static function relationship(&$form) { |
6a488035 TO |
390 | $form->add('hidden', 'hidden_relationship', 1); |
391 | ||
392 | $allRelationshipType = array(); | |
393 | $allRelationshipType = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, NULL, TRUE); | |
026242fc | 394 | $form->add('select', 'relation_type_id', ts('Relationship Type'), array('' => ts('- select -')) + $allRelationshipType, FALSE, array('multiple' => TRUE, 'class' => 'crm-select2')); |
6a488035 | 395 | $form->addElement('text', 'relation_target_name', ts('Target Contact'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); |
5ea73a9f | 396 | // relation status |
9e4a7990 | 397 | $relStatusOption = array(ts('Active'), ts('Inactive'), ts('All')); |
6a488035 TO |
398 | $form->addRadio('relation_status', ts('Relationship Status'), $relStatusOption); |
399 | $form->setDefaults(array('relation_status' => 0)); | |
5ea73a9f | 400 | // relation permission |
481a74f4 | 401 | $relPermissionOption = array(ts('Any'), ts('Yes'), ts('No')); |
5ea73a9f DG |
402 | $form->addRadio('relation_permission', ts('Permissioned Relationship?'), $relPermissionOption); |
403 | $form->setDefaults(array('relation_permission' => 0)); | |
6a488035 TO |
404 | |
405 | //add the target group | |
406 | if ($form->_group) { | |
407 | $form->add('select', 'relation_target_group', ts('Target Contact(s) in Group'), $form->_group, FALSE, | |
02ddf039 | 408 | array('id' => 'relation_target_group', 'multiple' => 'multiple', 'class' => 'crm-select2') |
6a488035 TO |
409 | ); |
410 | } | |
ad682134 | 411 | CRM_Core_Form_Date::buildDateRange($form, 'relation_start_date', 1, '_low', '_high', ts('From:'), FALSE, FALSE); |
412 | CRM_Core_Form_Date::buildDateRange($form, 'relation_end_date', 1, '_low', '_high', ts('From:'), FALSE, FALSE); | |
6a488035 | 413 | |
eea5db81 | 414 | CRM_Core_Form_Date::buildDateRange($form, 'relation_active_period_date', 1, '_low', '_high', ts('From:'), FALSE, FALSE); |
415 | ||
6a488035 TO |
416 | // Add reltionship dates |
417 | CRM_Core_Form_Date::buildDateRange($form, 'relation_date', 1, '_low', '_high', ts('From:'), FALSE, FALSE); | |
418 | ||
419 | // add all the custom searchable fields | |
86a0d21e | 420 | CRM_Core_BAO_Query::addCustomFormFields($form, array('Relationship')); |
6a488035 TO |
421 | } |
422 | ||
86538308 EM |
423 | /** |
424 | * @param $form | |
425 | */ | |
00be9182 | 426 | public static function demographics(&$form) { |
6a488035 TO |
427 | $form->add('hidden', 'hidden_demographics', 1); |
428 | // radio button for gender | |
429 | $genderOptions = array(); | |
26cf88b5 | 430 | $gender = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id'); |
6a488035 TO |
431 | foreach ($gender as $key => $var) { |
432 | $genderOptions[$key] = $form->createElement('radio', NULL, | |
433 | ts('Gender'), $var, $key, | |
434 | array('id' => "civicrm_gender_{$var}_{$key}") | |
435 | ); | |
436 | } | |
b847e6e7 | 437 | $form->addGroup($genderOptions, 'gender_id', ts('Gender'))->setAttribute('allowClear', TRUE); |
6a488035 | 438 | |
4b9de8a1 | 439 | $form->add('text', 'age_low', ts('Min Age'), array('size' => 6)); |
c4a7c967 | 440 | $form->addRule('age_low', ts('Please enter a positive integer'), 'positiveInteger'); |
4b9de8a1 | 441 | $form->add('text', 'age_high', ts('Max Age'), array('size' => 6)); |
c4a7c967 | 442 | $form->addRule('age_high', ts('Please enter a positive integer'), 'positiveInteger'); |
443 | $form->addDate('age_asof_date', ts('Age as of Date'), FALSE, array('formatType' => 'searchDate')); | |
444 | ||
6a488035 TO |
445 | CRM_Core_Form_Date::buildDateRange($form, 'birth_date', 1, '_low', '_high', ts('From'), FALSE, FALSE, 'birth'); |
446 | ||
447 | CRM_Core_Form_Date::buildDateRange($form, 'deceased_date', 1, '_low', '_high', ts('From'), FALSE, FALSE, 'birth'); | |
448 | ||
6a488035 | 449 | // radio button for is_deceased |
481a74f4 | 450 | $form->addYesNo('is_deceased', ts('Deceased'), TRUE); |
6a488035 TO |
451 | } |
452 | ||
86538308 EM |
453 | /** |
454 | * @param $form | |
455 | */ | |
00be9182 | 456 | public static function notes(&$form) { |
6a488035 TO |
457 | $form->add('hidden', 'hidden_notes', 1); |
458 | ||
459 | $options = array( | |
460 | 2 => ts('Body Only'), | |
461 | 3 => ts('Subject Only'), | |
462 | 6 => ts('Both'), | |
463 | ); | |
464 | $form->addRadio('note_option', '', $options); | |
465 | ||
466 | $form->addElement('text', 'note', ts('Note Text'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); | |
467 | ||
468 | $form->setDefaults(array('note_option' => 6)); | |
469 | } | |
470 | ||
471 | /** | |
5a409b50 | 472 | * Generate the custom Data Fields based for those with is_searchable = 1. |
6a488035 | 473 | * |
5a409b50 | 474 | * @param CRM_Contact_Form_Search $form |
6a488035 | 475 | */ |
00be9182 | 476 | public static function custom(&$form) { |
6a488035 TO |
477 | $form->add('hidden', 'hidden_custom', 1); |
478 | $extends = array_merge(array('Contact', 'Individual', 'Household', 'Organization'), | |
479 | CRM_Contact_BAO_ContactType::subTypes() | |
480 | ); | |
481 | $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, | |
482 | $extends | |
483 | ); | |
484 | ||
485 | $form->assign('groupTree', $groupDetails); | |
486 | ||
487 | foreach ($groupDetails as $key => $group) { | |
488 | $_groupTitle[$key] = $group['name']; | |
489 | CRM_Core_ShowHideBlocks::links($form, $group['name'], '', ''); | |
490 | ||
6a488035 TO |
491 | foreach ($group['fields'] as $field) { |
492 | $fieldId = $field['id']; | |
493 | $elementName = 'custom_' . $fieldId; | |
0b77ccc2 CW |
494 | if ($field['data_type'] == 'Date' && $field['is_search_range']) { |
495 | CRM_Core_Form_Date::buildDateRange($form, $elementName, 1, '_from', '_to', ts('From:'), FALSE); | |
496 | } | |
497 | else { | |
498 | CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, TRUE); | |
499 | } | |
6a488035 TO |
500 | } |
501 | } | |
6a488035 TO |
502 | } |
503 | ||
86538308 EM |
504 | /** |
505 | * @param $form | |
506 | */ | |
00be9182 | 507 | public static function CiviCase(&$form) { |
6a488035 TO |
508 | //Looks like obsolete code, since CiviCase is a component, but might be used by HRD |
509 | $form->add('hidden', 'hidden_CiviCase', 1); | |
510 | CRM_Case_BAO_Query::buildSearchForm($form); | |
511 | } | |
96025800 | 512 | |
6a488035 | 513 | } |