From 178774fe28da2898eae37f7325ba4b11089d3ba2 Mon Sep 17 00:00:00 2001 From: eileen Date: Fri, 24 Feb 2017 01:39:06 +1300 Subject: [PATCH] CRM-19490 define non-updated fields in a function for easier transition. Looking to find a way to migrate these as safely as possible. Defining them in one place seems like a good step --- CRM/Core/BAO/UFGroup.php | 53 +++++++++++--------- CRM/Core/Smarty/plugins/modifier.crmDate.php | 2 +- templates/CRM/UF/Form/Fields.tpl | 8 ++- 3 files changed, 34 insertions(+), 29 deletions(-) diff --git a/CRM/Core/BAO/UFGroup.php b/CRM/Core/BAO/UFGroup.php index a1edbefeab..d3664eb451 100644 --- a/CRM/Core/BAO/UFGroup.php +++ b/CRM/Core/BAO/UFGroup.php @@ -518,6 +518,9 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup { ); $formattedField = CRM_Utils_Date::addDateMetadataToField($fieldMetaData, $formattedField); + if (in_array($name, array_keys(self::getNonUpgradedDateFields()))) { + $formattedField['is_legacy_date'] = 1; + } //adding custom field property if (substr($field->field_name, 0, 6) == 'custom' || @@ -1905,6 +1908,7 @@ AND ( entity_id IS NULL OR entity_id <= 0 ) $addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options', TRUE, NULL, TRUE ); + $legacyHandledDateFields = self::getNonUpgradedDateFields(); if (substr($fieldName, 0, 14) === 'state_province') { $form->addChainSelect($name, array('label' => $title, 'required' => $required)); @@ -1967,15 +1971,8 @@ AND ( entity_id IS NULL OR entity_id <= 0 ) } } } - elseif (($fieldName === 'birth_date') || ($fieldName === 'deceased_date')) { - $form->addDate($name, $title, $required, array('formatType' => 'birth')); - } - elseif (in_array($fieldName, array( - 'membership_start_date', - 'membership_end_date', - 'join_date', - ))) { - $form->addDate($name, $title, $required, array('formatType' => 'activityDate')); + elseif (isset($legacyHandledDateFields[$fieldName])) { + $form->addDate($name, $title, $required, array('formatType' => $legacyHandledDateFields[$fieldName])); } elseif (CRM_Utils_Array::value('name', $field) == 'membership_type') { list($orgInfo, $types) = CRM_Member_BAO_MembershipType::getMembershipTypeInfo(); @@ -2151,14 +2148,6 @@ AND ( entity_id IS NULL OR entity_id <= 0 ) CRM_Core_BAO_CustomField::addQuickFormElement($form, $name, $customFieldID, $required, $search, $title); } } - elseif (in_array($fieldName, array( - 'receive_date', - 'receipt_date', - 'thankyou_date', - 'cancel_date', - ))) { - $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime')); - } elseif ($fieldName == 'send_receipt') { $form->addElement('checkbox', $name, $title); } @@ -2230,9 +2219,6 @@ AND ( entity_id IS NULL OR entity_id <= 0 ) ) + CRM_Contribute_PseudoConstant::contributionPage(), $required, 'class="big"' ); } - elseif ($fieldName == 'participant_register_date') { - $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime')); - } elseif ($fieldName == 'activity_status_id') { $form->add('select', $name, $title, array( @@ -2247,9 +2233,6 @@ AND ( entity_id IS NULL OR entity_id <= 0 ) ) + CRM_Campaign_PseudoConstant::engagementLevel(), $required ); } - elseif ($fieldName == 'activity_date_time') { - $form->addDateTime($name, $title, $required, array('formatType' => 'activityDateTime')); - } elseif ($fieldName == 'participant_status') { $cond = NULL; if ($online == TRUE) { @@ -2347,6 +2330,30 @@ AND ( entity_id IS NULL OR entity_id <= 0 ) } } + /** + * Get fields that have not been upgraded to use datepicker. + * + * Fields that use the old code have jcalendar in the tpl and + * the form uses a customised format. We are moving towards datepicker + * which among other things passes dates back and forth using a standardised + * format. Remove fields from here as they are tested and converted. + */ + static public function getNonUpgradedDateFields() { + return array( + 'birth_date' => 'birth', + 'deceased_date' => 'birth', + 'membership_start_date' => 'activityDate', + 'membership_end_date' => 'activityDate', + 'join_date' => 'activityDate', + 'receive_date' => 'activityDateTime', + 'receipt_date' => 'activityDateTime', + 'thankyou_date' => 'activityDateTime', + 'cancel_date' => 'activityDateTime', + 'participant_register_date' => 'activityDateTime', + 'activity_date_time' => 'activityDateTime', + ); + } + /** * Set profile defaults. * diff --git a/CRM/Core/Smarty/plugins/modifier.crmDate.php b/CRM/Core/Smarty/plugins/modifier.crmDate.php index d38e8e6877..8e2afb6a59 100644 --- a/CRM/Core/Smarty/plugins/modifier.crmDate.php +++ b/CRM/Core/Smarty/plugins/modifier.crmDate.php @@ -57,7 +57,7 @@ function smarty_modifier_crmDate($dateString, $dateFormat = NULL, $onlyTime = FA $dateFormat = $config->dateformatTime; } // Handle possibility we only have a date function style date format. - if ($dateFormat && !stristr('%', $dateFormat)) { + if ($dateFormat && !stristr($dateFormat, '%')) { return date($dateFormat, strtotime($dateString)); } diff --git a/templates/CRM/UF/Form/Fields.tpl b/templates/CRM/UF/Form/Fields.tpl index 5d27eae823..e1c342929f 100644 --- a/templates/CRM/UF/Form/Fields.tpl +++ b/templates/CRM/UF/Form/Fields.tpl @@ -89,19 +89,17 @@ {include file="CRM/Profile/Form/GreetingType.tpl"} {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 ( $profileFieldName|substr:-5:5 eq '_date' ) AND - ( $form.formName neq 'Confirm' ) AND - ( $form.formName neq 'ThankYou' ) } - {include file="CRM/common/jcalendar.tpl" elementName=$profileFieldName} {elseif $field.is_datetime_field && $action == 4} {assign var="date_value" value=$form.$profileFieldName.value} - {$date_value|date_format:"%Y-%m-%d"|crmDate:$field.php_datetime_format} + {$date_value|date_format:"%Y-%m-%d"|crmDate:$config->dateformatshortdate} + {elseif $field.is_legacy_date} + {include file="CRM/common/jcalendar.tpl" elementName=$profileFieldName} {elseif $profileFieldName|substr:0:5 eq 'phone'} {assign var="phone_ext_field" value=$profileFieldName|replace:'phone':'phone_ext'} {if $prefix}{$form.$prefix.$profileFieldName.html}{else}{$form.$profileFieldName.html}{/if} -- 2.25.1