From 41b8dd1d9a18282dc497152b655dc090096dd53e Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 28 Oct 2019 18:02:59 +1300 Subject: [PATCH] Convert relationship_start_date & relationship_end_date to datepicker This seems to work OK - look forwards to seeing you kick the tyres on it & see if you find any issues --- CRM/Contact/BAO/Query.php | 25 +++++++++---------- CRM/Contact/BAO/SavedSearch.php | 2 -- CRM/Contact/Form/Search/Criteria.php | 13 ++++++---- CRM/Upgrade/Incremental/SmartGroups.php | 2 ++ CRM/Upgrade/Incremental/php/FiveTwenty.php | 8 ++++++ .../Form/Search/Criteria/Relationship.tpl | 10 ++------ 6 files changed, 32 insertions(+), 28 deletions(-) diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index 849325bf97..bb5665b259 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -511,6 +511,9 @@ class CRM_Contact_BAO_Query { foreach (array_keys($this->legacyHackedFields) as $fieldName) { $this->_fields[$fieldName]['type'] = CRM_Utils_Type::T_STRING; } + $relationMetadata = CRM_Contact_BAO_Relationship::fields(); + $relationFields = array_intersect_key($relationMetadata, array_fill_keys(['relationship_start_date', 'relationship_end_date'], 1)); + $this->_fields = array_merge($relationFields, $this->_fields); $fields = CRM_Core_Component::getQueryFields(!$this->_skipPermission); unset($fields['note']); @@ -1595,6 +1598,8 @@ class CRM_Contact_BAO_Query { 'pledge_create_date_relative', 'pledge_start_date_relative', 'pledge_payment_scheduled_date_relative', + 'relationship_start_date_relative', + 'relationship_end_date_relative', 'membership_join_date_relative', 'membership_start_date_relative', 'membership_end_date_relative', @@ -2020,10 +2025,10 @@ class CRM_Contact_BAO_Query { return; case 'relation_type_id': - case 'relation_start_date_high': - case 'relation_start_date_low': - case 'relation_end_date_high': - case 'relation_end_date_low': + case 'relationship_start_date_high': + case 'relationship_start_date_low': + case 'relationship_end_date_high': + case 'relationship_end_date_low': case 'relation_active_period_date_high': case 'relation_active_period_date_low': case 'relation_target_name': @@ -4377,15 +4382,9 @@ civicrm_relationship.start_date > {$today} * not the main query. */ public function addRelationshipDateClauses($grouping, &$where) { - $dateValues = []; - $dateTypes = [ - 'start_date', - 'end_date', - ]; - - foreach ($dateTypes as $dateField) { - $dateValueLow = $this->getWhereValues('relation_' . $dateField . '_low', $grouping); - $dateValueHigh = $this->getWhereValues('relation_' . $dateField . '_high', $grouping); + foreach (['start_date', 'end_date'] as $dateField) { + $dateValueLow = $this->getWhereValues('relationship_' . $dateField . '_low', $grouping); + $dateValueHigh = $this->getWhereValues('relationship_' . $dateField . '_high', $grouping); if (!empty($dateValueLow)) { $date = date('Ymd', strtotime($dateValueLow[2])); $where[$grouping][] = "civicrm_relationship.$dateField >= $date"; diff --git a/CRM/Contact/BAO/SavedSearch.php b/CRM/Contact/BAO/SavedSearch.php index 4215c09b73..dd6e6b36be 100644 --- a/CRM/Contact/BAO/SavedSearch.php +++ b/CRM/Contact/BAO/SavedSearch.php @@ -403,8 +403,6 @@ LEFT JOIN civicrm_email ON (contact_a.id = civicrm_email.contact_id AND civicrm_ 'birth_date_relative', 'deceased_date_relative', 'relation_date_relative', - 'relation_start_date_relative', - 'relation_end_date_relative', 'relation_action_date_relative', ]; foreach ($formValues as $id => $value) { diff --git a/CRM/Contact/Form/Search/Criteria.php b/CRM/Contact/Form/Search/Criteria.php index 75c139def3..154331dbe0 100644 --- a/CRM/Contact/Form/Search/Criteria.php +++ b/CRM/Contact/Form/Search/Criteria.php @@ -265,8 +265,11 @@ class CRM_Contact_Form_Search_Criteria { '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'], + 'relationship_start_date' => ['name' => 'relationship_start_date', 'template_grouping' => 'relationship'], + 'relationship_end_date' => ['name' => 'relationship_end_date', 'template_grouping' => 'relationship'], ]; - $metadata = civicrm_api3('Contact', 'getfields', [])['values']; + $metadata = civicrm_api3('Relationship', 'getfields', [])['values']; + $metadata = array_merge($metadata, civicrm_api3('Contact', 'getfields', [])['values']); foreach ($fields as $fieldName => $field) { $fields[$fieldName] = array_merge(CRM_Utils_Array::value($fieldName, $metadata, []), $field); } @@ -509,10 +512,13 @@ class CRM_Contact_Form_Search_Criteria { /** * @param CRM_Core_Form_Search $form + * + * @throws \CiviCRM_API3_Exception */ public static function relationship(&$form) { $form->add('hidden', 'hidden_relationship', 1); - + $form->addSearchFieldMetadata(['Relationship' => self::getFilteredSearchFieldMetadata('relationship')]); + $form->addFormFieldsFromMetadata(); $form->add('text', 'relation_description', ts('Description'), ['class' => 'twenty']); $allRelationshipType = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, NULL, TRUE); $form->add('select', 'relation_type_id', ts('Relationship Type'), ['' => ts('- select -')] + $allRelationshipType, FALSE, ['multiple' => TRUE, 'class' => 'crm-select2']); @@ -532,9 +538,6 @@ class CRM_Contact_Form_Search_Criteria { ['id' => 'relation_target_group', 'multiple' => 'multiple', 'class' => 'crm-select2'] ); } - CRM_Core_Form_Date::buildDateRange($form, 'relation_start_date', 1, '_low', '_high', ts('From:'), FALSE, FALSE); - CRM_Core_Form_Date::buildDateRange($form, 'relation_end_date', 1, '_low', '_high', ts('From:'), FALSE, FALSE); - CRM_Core_Form_Date::buildDateRange($form, 'relation_active_period_date', 1, '_low', '_high', ts('From:'), FALSE, FALSE); // Add reltionship dates diff --git a/CRM/Upgrade/Incremental/SmartGroups.php b/CRM/Upgrade/Incremental/SmartGroups.php index 89b701b66d..a8d2ab7c49 100644 --- a/CRM/Upgrade/Incremental/SmartGroups.php +++ b/CRM/Upgrade/Incremental/SmartGroups.php @@ -71,6 +71,8 @@ class CRM_Upgrade_Incremental_SmartGroups { 'case_start_date' => 'case_from', 'case_end_date' => 'case_to', 'mailing_job_start_date' => 'mailing_date', + 'relationship_start_date' => 'relation_start_date', + 'relationship_end_date' => 'relation_end_date', ]; foreach ($fields as $field) { diff --git a/CRM/Upgrade/Incremental/php/FiveTwenty.php b/CRM/Upgrade/Incremental/php/FiveTwenty.php index d786687064..6e63638be4 100644 --- a/CRM/Upgrade/Incremental/php/FiveTwenty.php +++ b/CRM/Upgrade/Incremental/php/FiveTwenty.php @@ -106,6 +106,12 @@ class CRM_Upgrade_Incremental_php_FiveTwenty extends CRM_Upgrade_Incremental_Bas ['old' => 'mailing_date_relative', 'new' => 'mailing_job_start_date_relative'], ['old' => 'mailing_date_high', 'new' => 'mailing_job_start_date_high'], ['old' => 'mailing_date_low', 'new' => 'mailing_job_start_date_low'], + ['old' => 'relation_start_date_low', 'new' => 'relationship_start_date_low'], + ['old' => 'relation_start_date_high', 'new' => 'relationship_start_date_high'], + ['old' => 'relation_start_date_relative', 'new' => 'relationship_start_date_relative'], + ['old' => 'relation_end_date_low', 'new' => 'relationship_end_date_low'], + ['old' => 'relation_end_date_high', 'new' => 'relationship_end_date_high'], + ['old' => 'relation_end_date_relative', 'new' => 'relationship_end_date_relative'], ], ]); $this->addTask('Update smart groups where jcalendar fields have been converted to datepicker', 'updateSmartGroups', [ @@ -115,6 +121,8 @@ class CRM_Upgrade_Incremental_php_FiveTwenty extends CRM_Upgrade_Incremental_Bas 'case_start_date', 'case_end_date', 'mailing_job_start_date', + 'relationship_start_date', + 'relationship_end_date', ], ]); } diff --git a/templates/CRM/Contact/Form/Search/Criteria/Relationship.tpl b/templates/CRM/Contact/Form/Search/Criteria/Relationship.tpl index 14619c0b58..676c44c2bc 100644 --- a/templates/CRM/Contact/Form/Search/Criteria/Relationship.tpl +++ b/templates/CRM/Contact/Form/Search/Criteria/Relationship.tpl @@ -60,16 +60,10 @@ - + {include file="CRM/Core/DatePickerRangeWrapper.tpl" fieldName="relationship_start_date"} - {include file="CRM/Core/DateRange.tpl" fieldName="relation_start_date" from='_low' to='_high'} - - - - - - {include file="CRM/Core/DateRange.tpl" fieldName="relation_end_date" from='_low' to='_high'} + {include file="CRM/Core/DatePickerRangeWrapper.tpl" fieldName="relationship_end_date"} {help id="id-relationship-active-period" file="CRM/Contact/Form/Search/Advanced.hlp"}
-- 2.25.1