Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev/core#561 Convert birth_date & deceased_date to datepicker #15635

Merged
merged 1 commit into from
Oct 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion CRM/Contact/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -1601,6 +1601,8 @@ public static function convertFormValues(&$formValues, $wildcard = 0, $useEquals
'case_start_date_relative',
'case_end_date_relative',
'mailing_job_start_date_relative',
'birth_date_relative',
'deceased_date_relative',
];
// Handle relative dates first
foreach (array_keys($formValues) as $id) {
Expand Down Expand Up @@ -7045,7 +7047,12 @@ protected function buildRelativeDateQuery(&$values) {
}
else {
// we have start and end dates.
$this->_where[$grouping][] = $fieldSpec['where'] . " BETWEEN '{$dates[0]}' AND '{$dates[1]}'";
$where = $fieldSpec['where'];
if ($fieldSpec['table_name'] === 'civicrm_contact') {
// Special handling for contact table as it has a known alias in advanced search.
$where = str_replace('civicrm_contact.', 'contact_a.', $where);
}
$this->_where[$grouping][] = $where . " BETWEEN '{$dates[0]}' AND '{$dates[1]}'";

$this->_qill[$grouping][] = ts('%1 is ', [$fieldSpec['title']]) . $filters[$value] . ' (' . ts("between %1 and %2", [
CRM_Utils_Date::customFormat($dates[0]),
Expand Down
40 changes: 30 additions & 10 deletions CRM/Contact/Form/Search/Criteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ class CRM_Contact_Form_Search_Criteria {
* @param CRM_Contact_Form_Search_Advanced $form
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public static function basic(&$form) {
$form->addSearchFieldMetadata(['Contact' => self::getSearchFieldMetadata()]);
$form->addSearchFieldMetadata(['Contact' => self::getFilteredSearchFieldMetadata('basic')]);
$form->addFormFieldsFromMetadata();
self::setBasicSearchFields($form);
$form->addElement('hidden', 'hidden_basic', 1);
Expand Down Expand Up @@ -262,6 +263,8 @@ public static function getSearchFieldMetadata() {
'sort_name' => ['title' => ts('Complete OR Partial Name'), 'template_grouping' => 'basic'],
'email' => ['title' => ts('Complete OR Partial Email'), 'entity' => 'Email', 'template_grouping' => 'basic'],
'contact_tags' => ['name' => 'contact_tags', 'type' => CRM_Utils_Type::T_INT, 'is_pseudofield' => TRUE, 'template_grouping' => 'basic'],
'birth_date' => ['name' => 'birth_date', 'template_grouping' => 'demographic'],
'deceased_date' => ['name' => 'deceased_date', 'template_grouping' => 'demographic'],
];
$metadata = civicrm_api3('Contact', 'getfields', [])['values'];
foreach ($fields as $fieldName => $field) {
Expand All @@ -270,17 +273,35 @@ public static function getSearchFieldMetadata() {
return $fields;
}

/**
* Get search field metadata filtered by the template grouping field.
*
* @param string $filter
*
* @return array
* @throws \CiviCRM_API3_Exception
*/
public static function getFilteredSearchFieldMetadata($filter) {
$fields = self::getSearchFieldMetadata();
foreach ($fields as $index => $field) {
if ($field['template_grouping'] !== $filter) {
unset($fields[$index]);
}
}
return $fields;
}

/**
* Defines the fields that can be displayed for the basic search section.
*
* @param CRM_Core_Form $form
*
* @throws \CiviCRM_API3_Exception
*/
protected static function setBasicSearchFields($form) {
$searchFields = [];
foreach (self::getSearchFieldMetadata() as $fieldName => $field) {
if ($field['template_grouping'] === 'basic') {
$searchFields[$fieldName] = $field;
}
foreach (self::getFilteredSearchFieldMetadata('basic') as $fieldName => $field) {
$searchFields[$fieldName] = $field;
}
$form->assign('basicSearchFields', array_merge(self::getBasicSearchFields(), $searchFields));
}
Expand Down Expand Up @@ -525,9 +546,13 @@ public static function relationship(&$form) {

/**
* @param CRM_Core_Form_Search $form
*
* @throws \CiviCRM_API3_Exception
*/
public static function demographics(&$form) {
$form->add('hidden', 'hidden_demographics', 1);
$form->addSearchFieldMetadata(['Contact' => self::getFilteredSearchFieldMetadata('demographic')]);
$form->addFormFieldsFromMetadata();
// radio button for gender
$genderOptions = [];
$gender = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id');
Expand All @@ -544,11 +569,6 @@ public static function demographics(&$form) {
$form->add('number', 'age_high', ts('Max Age'), ['class' => 'four', 'min' => 0]);
$form->addRule('age_high', ts('Please enter a positive integer'), 'positiveInteger');
$form->add('datepicker', 'age_asof_date', ts('As of'), NULL, FALSE, ['time' => FALSE]);

CRM_Core_Form_Date::buildDateRange($form, 'birth_date', 1, '_low', '_high', ts('From'), FALSE, FALSE, 'birth');

CRM_Core_Form_Date::buildDateRange($form, 'deceased_date', 1, '_low', '_high', ts('From'), FALSE, FALSE, 'birth');

// radio button for is_deceased
$form->addYesNo('is_deceased', ts('Deceased'), TRUE);
}
Expand Down
2 changes: 2 additions & 0 deletions CRM/Upgrade/Incremental/php/FiveTwenty.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ public function upgrade_5_20_alpha1($rev) {
]);
$this->addTask('Update smart groups where jcalendar fields have been converted to datepicker', 'updateSmartGroups', [
'datepickerConversion' => [
'birth_date',
'deceased_date',
'case_start_date',
'case_end_date',
'mailing_job_start_date',
Expand Down
16 changes: 3 additions & 13 deletions templates/CRM/Contact/Form/Search/Criteria/Demographics.tpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{*
+--------------------------------------------------------------------+
| CiviCRM version 5
| CiviCRM version 5
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2019 |
+--------------------------------------------------------------------+
Expand All @@ -26,12 +26,7 @@
<div id="demographics" class="form-item">
<table class="form-layout">
<tr>
<td>
<label>{ts}Birth Dates{/ts}</label>
</td>
</tr>
<tr>
{include file="CRM/Core/DateRange.tpl" fieldName="birth_date" from='_low' to='_high'}
{include file="CRM/Core/DatePickerRangeWrapper.tpl" fieldName="birth_date"}
</tr>
<tr>
<td>
Expand All @@ -48,12 +43,7 @@
</td>
</tr>
<tr>
<td>
<label>{ts}Deceased Dates{/ts}</label>
</td>
</tr>
<tr>
{include file="CRM/Core/DateRange.tpl" fieldName="deceased_date" from='_low' to='_high'}
{include file="CRM/Core/DatePickerRangeWrapper.tpl" fieldName="deceased_date"}
</tr>
<tr>
<td>
Expand Down