From 2732685bace0cd4353c4212050a733bbeffe0a5b Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 27 Feb 2017 15:53:10 +1300 Subject: [PATCH] CRM-19124 Profiles - update birth_date & deceased_date to use datepicker --- CRM/Core/BAO/UFGroup.php | 53 ++++++++++++----------- CRM/Core/SelectValues.php | 2 +- CRM/Utils/Date.php | 5 +-- templates/CRM/Contact/Form/Task/Batch.tpl | 2 - templates/CRM/Profile/Form/Dynamic.tpl | 3 +- templates/CRM/Profile/Form/Search.tpl | 4 +- templates/CRM/UF/Form/Fields.tpl | 3 +- 7 files changed, 33 insertions(+), 39 deletions(-) diff --git a/CRM/Core/BAO/UFGroup.php b/CRM/Core/BAO/UFGroup.php index d3664eb451..87d741f6fc 100644 --- a/CRM/Core/BAO/UFGroup.php +++ b/CRM/Core/BAO/UFGroup.php @@ -537,11 +537,8 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup { if (CRM_Utils_Array::value('html_type', $formattedField) == 'Select Date') { $formattedField['date_format'] = $customFields[$field->field_name]['date_format']; $formattedField['time_format'] = $customFields[$field->field_name]['time_format']; - $formattedField['php_datetime_format'] = CRM_Utils_Date::getPhpDateFormatFromInputStyleDateFormat($customFields[$field->field_name]['date_format']); - if ($formattedField['time_format']) { - $formattedField['php_datetime_format'] .= ' H-i-s'; - } $formattedField['is_datetime_field'] = TRUE; + $formattedField['smarty_view_format'] = CRM_Utils_Date::getDateFieldViewFormat($formattedField['date_format']); } $formattedField['is_multi_summary'] = $field->is_multi_summary; @@ -2288,6 +2285,11 @@ AND ( entity_id IS NULL OR entity_id <= 0 ) if (substr($fieldName, 0, 3) === 'is_' or substr($fieldName, 0, 7) === 'do_not_') { $form->add('advcheckbox', $name, $title, $attributes, $required); } + elseif (CRM_Utils_Array::value('html_type', $field) === 'Select Date') { + $extra = isset($field['datepicker']) ? $field['datepicker']['extra'] : CRM_Utils_Date::getDatePickerExtra($field); + $attributes = isset($field['datepicker']) ? $field['datepicker']['attributes'] : CRM_Utils_Date::getDatePickerAttributes($field); + $form->add('datepicker', $name, $title, $attributes, $required, $extra); + } else { $form->add('text', $name, $title, $attributes, $required); } @@ -2340,8 +2342,6 @@ AND ( entity_id IS NULL OR entity_id <= 0 ) */ static public function getNonUpgradedDateFields() { return array( - 'birth_date' => 'birth', - 'deceased_date' => 'birth', 'membership_start_date' => 'activityDate', 'membership_end_date' => 'activityDate', 'join_date' => 'activityDate', @@ -2404,10 +2404,7 @@ AND ( entity_id IS NULL OR entity_id <= 0 ) if (!empty($details[$name]) || isset($details[$name])) { //to handle custom data (checkbox) to be written // to handle birth/deceased date, greeting_type and few other fields - if (($name == 'birth_date') || ($name == 'deceased_date')) { - list($defaults[$fldName]) = CRM_Utils_Date::setDateDefaults($details[$name], 'birth'); - } - elseif (in_array($name, CRM_Contact_BAO_Contact::$_greetingTypes)) { + if (in_array($name, CRM_Contact_BAO_Contact::$_greetingTypes)) { $defaults[$fldName] = $details[$name . '_id']; $defaults[$name . '_custom'] = $details[$name . '_custom']; } @@ -2463,24 +2460,30 @@ AND ( entity_id IS NULL OR entity_id <= 0 ) break; case 'Select Date': - // CRM-6681, set defult values according to date and time format (if any). - $dateFormat = NULL; - if (!empty($customFields[$customFieldId]['date_format'])) { - $dateFormat = $customFields[$customFieldId]['date_format']; - } - - if (empty($customFields[$customFieldId]['time_format'])) { - list($defaults[$fldName]) = CRM_Utils_Date::setDateDefaults($details[$name], NULL, - $dateFormat - ); + if (!in_array($name, array_keys(self::getNonUpgradedDateFields()))) { + $defaults[$fldName] = $details[$name]; } else { - $timeElement = $fldName . '_time'; - if (substr($fldName, -1) == ']') { - $timeElement = substr($fldName, 0, -1) . '_time]'; + // Do legacy handling. + // CRM-6681, set defult values according to date and time format (if any). + $dateFormat = NULL; + if (!empty($customFields[$customFieldId]['date_format'])) { + $dateFormat = $customFields[$customFieldId]['date_format']; + } + + if (empty($customFields[$customFieldId]['time_format'])) { + list($defaults[$fldName]) = CRM_Utils_Date::setDateDefaults($details[$name], NULL, + $dateFormat + ); + } + else { + $timeElement = $fldName . '_time'; + if (substr($fldName, -1) == ']') { + $timeElement = substr($fldName, 0, -1) . '_time]'; + } + list($defaults[$fldName], $defaults[$timeElement]) = CRM_Utils_Date::setDateDefaults($details[$name], + NULL, $dateFormat, $customFields[$customFieldId]['time_format']); } - list($defaults[$fldName], $defaults[$timeElement]) = CRM_Utils_Date::setDateDefaults($details[$name], - NULL, $dateFormat, $customFields[$customFieldId]['time_format']); } break; diff --git a/CRM/Core/SelectValues.php b/CRM/Core/SelectValues.php index 49e5f4f446..22416b15d2 100644 --- a/CRM/Core/SelectValues.php +++ b/CRM/Core/SelectValues.php @@ -349,7 +349,7 @@ class CRM_Core_SelectValues { } } } - $date['php_datetime_format'] = CRM_Utils_Date::getPhpDateFormatFromInputStyleDateFormat($date['format']); + $date['smarty_view_format'] = CRM_Utils_Date::getDateFieldViewFormat($date['format']); if (!isset($date['time'])) { $date['time'] = FALSE; diff --git a/CRM/Utils/Date.php b/CRM/Utils/Date.php index a7c37d5dfd..af8faf9808 100644 --- a/CRM/Utils/Date.php +++ b/CRM/Utils/Date.php @@ -1010,6 +1010,7 @@ class CRM_Utils_Date { "dd-mm" => 'd-m', "yy-mm" => 'Y-m', "M yy" => 'M Y', + "M Y" => 'M Y', "yy" => 'Y', ); return $dateInputFormats; @@ -1828,11 +1829,7 @@ class CRM_Utils_Date { $field['date_format'] = $dateAttributes['format']; $field['is_datetime_field'] = TRUE; $field['time_format'] = $dateAttributes['time']; - $field['php_datetime_format'] = $dateAttributes['php_datetime_format']; $field['smarty_view_format'] = $dateAttributes['smarty_view_format']; - if ($field['time_format']) { - $field['php_datetime_format'] .= ' H-i-s'; - } } $field['datepicker']['extra'] = self::getDatePickerExtra($field); $field['datepicker']['attributes'] = self::getDatePickerAttributes($field); diff --git a/templates/CRM/Contact/Form/Task/Batch.tpl b/templates/CRM/Contact/Form/Task/Batch.tpl index 74485a1cae..1653ecb883 100644 --- a/templates/CRM/Contact/Form/Task/Batch.tpl +++ b/templates/CRM/Contact/Form/Task/Batch.tpl @@ -73,8 +73,6 @@ {/strip} - {elseif ( $n eq 'birth_date' or $n eq 'deceased_date' ) } - {include file="CRM/common/jcalendar.tpl" elementName=$n elementIndex=$cid batchUpdate=1} {elseif $n|substr:0:5 eq 'phone'} {assign var="phone_ext_field" value=$n|replace:'phone':'phone_ext'} diff --git a/templates/CRM/Profile/Form/Dynamic.tpl b/templates/CRM/Profile/Form/Dynamic.tpl index 477c0c5750..210d97bab5 100644 --- a/templates/CRM/Profile/Form/Dynamic.tpl +++ b/templates/CRM/Profile/Form/Dynamic.tpl @@ -171,8 +171,7 @@  {$form.$phone_ext_field.html} {/if} {else} - {if - ( ( $n eq 'birth_date' ) or ( $n eq 'deceased_date' ) or ( $n eq 'activity_date_time' ) ) and $field.is_view neq 1 } + {if $n eq 'activity_date_time' and $field.is_view neq 1 } {include file="CRM/common/jcalendar.tpl" elementName=$n} {else} {$form.$n.html} diff --git a/templates/CRM/Profile/Form/Search.tpl b/templates/CRM/Profile/Form/Search.tpl index 719327e6ef..02ad086f04 100644 --- a/templates/CRM/Profile/Form/Search.tpl +++ b/templates/CRM/Profile/Form/Search.tpl @@ -65,9 +65,7 @@ {else} - {if ( $n eq 'birth_date' ) or ( $n eq 'deceased_date' ) } - {include file="CRM/common/jcalendar.tpl" elementName=$n} - {elseif $n|substr:0:5 eq 'phone'} + {if $n|substr:0:5 eq 'phone'} {assign var="phone_ext_field" value=$n|replace:'phone':'phone_ext'} {$form.$n.html} {if $form.$phone_ext_field.html} diff --git a/templates/CRM/UF/Form/Fields.tpl b/templates/CRM/UF/Form/Fields.tpl index 4fbe9a4e7e..e16d7305f2 100644 --- a/templates/CRM/UF/Form/Fields.tpl +++ b/templates/CRM/UF/Form/Fields.tpl @@ -90,9 +90,8 @@ {elseif ($profileFieldName eq 'group' && $form.group) || ($profileFieldName eq 'tag' && $form.tag)} {include file="CRM/Contact/Form/Edit/TagsAndGroups.tpl" type=$profileFieldName title=null context="profile"} {elseif $field.is_datetime_field && $action & 4} - {assign var="date_value" value=$form.$profileFieldName.value} - {$date_value|date_format:"%Y-%m-%d"|crmDate:$config->dateformatshortdate} + {$form.$profileFieldName.value|crmDate:$field.smarty_view_format}