diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index ab90299b2d5a..287bd508018f 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -1600,41 +1600,6 @@ public static function convertFormValues(&$formValues, $wildcard = 0, $useEquals } self::filterCountryFromValuesIfStateExists($formValues); - // We shouldn't have to whitelist fields to not hack but here we are, for now. - $nonLegacyDateFields = [ - 'participant_register_date_relative', - 'receive_date_relative', - 'pledge_end_date_relative', - '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', - 'case_start_date_relative', - 'case_end_date_relative', - 'mailing_job_start_date_relative', - 'birth_date_relative', - 'deceased_date_relative', - 'relation_active_period_date_relative', - ]; - // Handle relative dates first - foreach (array_keys($formValues) as $id) { - if ( - !in_array($id, $nonLegacyDateFields) && ( - preg_match('/_date_relative$/', $id)) - ) { - $dateComponent = explode('_date_relative', $id); - $fromRange = "{$dateComponent[0]}_date_low"; - $toRange = "{$dateComponent[0]}_date_high"; - - if (array_key_exists($fromRange, $formValues) && array_key_exists($toRange, $formValues)) { - CRM_Contact_BAO_Query::fixDateValues($formValues[$id], $formValues[$fromRange], $formValues[$toRange]); - } - } - } foreach ($formValues as $id => $values) { if (self::isAlreadyProcessedForQueryFormat($values)) { @@ -1692,13 +1657,6 @@ public static function convertFormValues(&$formValues, $wildcard = 0, $useEquals ) { self::convertCustomRelativeFields($formValues, $params, $values, $id); } - elseif ( - !in_array($id, $nonLegacyDateFields) && ( - preg_match('/_date_relative$/', $id)) - ) { - // Already handled in previous loop - continue; - } elseif (in_array($id, $entityReferenceFields) && !empty($values) && is_string($values) && (strpos($values, ',') != FALSE)) { $params[] = [$id, 'IN', explode(',', $values), 0, 0]; @@ -3999,15 +3957,8 @@ public function changeLog(&$values) { $name = $targetName[4] ? "%$name%" : $name; $this->_where[$grouping][] = "contact_b_log.sort_name LIKE '%$name%'"; $this->_tables['civicrm_log'] = $this->_whereTables['civicrm_log'] = 1; - $fieldTitle = ts('Added By'); - foreach ($this->_params as $params) { - if ($params[0] == 'log_date') { - if ($params[2] == 2) { - $fieldTitle = ts('Modified By'); - } - break; - } - } + $fieldTitle = ts('Altered By'); + list($qillop, $qillVal) = self::buildQillForFieldValue(NULL, 'changed_by', $name, 'LIKE'); $this->_qill[$grouping][] = ts("%1 %2 '%3'", [ 1 => $fieldTitle, @@ -5298,6 +5249,10 @@ public function dateQueryBuilder( // @todo - remove dateFormat - pretty sure it's never passed in... list($name, $op, $value, $grouping, $wildcard) = $values; + if ($tableName === 'civicrm_contact') { + // Special handling for contact table as it has a known alias in advanced search. + $tableName = 'contact_a'; + } if ($name == "{$fieldName}_low" || $name == "{$fieldName}_high" ) { diff --git a/CRM/Contact/BAO/SavedSearch.php b/CRM/Contact/BAO/SavedSearch.php index c929be0e911c..2819b8d04b92 100644 --- a/CRM/Contact/BAO/SavedSearch.php +++ b/CRM/Contact/BAO/SavedSearch.php @@ -386,35 +386,6 @@ protected function assignTestValue($fieldName, &$fieldDef, $counter) { } } - /** - * Store relative dates in separate array format - * - * @param array $queryParams - * @param array $formValues - * @deprecated - */ - public static function saveRelativeDates(&$queryParams, $formValues) { - // This is required only until all fields are converted to datepicker fields as the new format is truer to the - // form format and simply saves (e.g) custom_3_relative => "this.year" - $relativeDates = ['relative_dates' => []]; - $specialDateFields = [ - 'log_date_relative', - ]; - foreach ($formValues as $id => $value) { - if (in_array($id, $specialDateFields) && !empty($value)) { - $entityName = strstr($id, '_date', TRUE); - if (empty($entityName)) { - $entityName = strstr($id, '_relative', TRUE); - } - $relativeDates['relative_dates'][$entityName] = $value; - } - } - // merge with original queryParams if relative date value(s) found - if (count($relativeDates['relative_dates'])) { - $queryParams = array_merge($queryParams, $relativeDates); - } - } - /** * Store search variables in $queryParams which were skipped while processing query params, * precisely at CRM_Contact_BAO_Query::fixWhereValues(...). But these variable are required in diff --git a/CRM/Contact/Form/Search/Criteria.php b/CRM/Contact/Form/Search/Criteria.php index 243286cdfc05..8a5221bd3a32 100644 --- a/CRM/Contact/Form/Search/Criteria.php +++ b/CRM/Contact/Form/Search/Criteria.php @@ -263,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'], + 'created_date' => ['name' => 'created_date', 'template_grouping' => 'changeLog'], + 'modified_date' => ['name' => 'modified_date', 'template_grouping' => 'changeLog'], 'birth_date' => ['name' => 'birth_date', 'template_grouping' => 'demographic'], 'deceased_date' => ['name' => 'deceased_date', 'template_grouping' => 'demographic'], 'is_deceased' => ['is_deceased', 'template_grouping' => 'demographic'], @@ -503,17 +505,15 @@ public static function activity(&$form) { /** * @param CRM_Core_Form $form + * + * @throws \CiviCRM_API3_Exception */ public static function changeLog(&$form) { $form->add('hidden', 'hidden_changeLog', 1); - + $form->addSearchFieldMetadata(['Contact' => self::getFilteredSearchFieldMetadata('changeLog')]); + $form->addFormFieldsFromMetadata(); // block for change log $form->addElement('text', 'changed_by', ts('Modified By'), NULL); - - $dates = [1 => ts('Added'), 2 => ts('Modified')]; - $form->addRadio('log_date', NULL, $dates, ['allowClear' => TRUE]); - - CRM_Core_Form_Date::buildDateRange($form, 'log_date', 1, '_low', '_high', ts('From:'), FALSE, FALSE); } /** diff --git a/CRM/Contact/Form/Task/SaveSearch.php b/CRM/Contact/Form/Task/SaveSearch.php index 1b888a6b53f8..758379ded531 100644 --- a/CRM/Contact/Form/Task/SaveSearch.php +++ b/CRM/Contact/Form/Task/SaveSearch.php @@ -191,7 +191,6 @@ public function postProcess() { // Ideally per CRM-17075 we will use entity reference fields heavily in the form layer & convert to the // sql operator syntax at the query layer. if (!$isSearchBuilder) { - CRM_Contact_BAO_SavedSearch::saveRelativeDates($queryParams, $formValues); CRM_Contact_BAO_SavedSearch::saveSkippedElement($queryParams, $formValues); $savedSearch->form_values = serialize($queryParams); } diff --git a/templates/CRM/Contact/Form/Search/Criteria/ChangeLog.tpl b/templates/CRM/Contact/Form/Search/Criteria/ChangeLog.tpl index 3d0621e29176..e8b8dfd67216 100644 --- a/templates/CRM/Contact/Form/Search/Criteria/ChangeLog.tpl +++ b/templates/CRM/Contact/Form/Search/Criteria/ChangeLog.tpl @@ -26,49 +26,16 @@
- {$form.log_date.html} - | -||
- - + | + + {$form.changed_by.html} | - - + {include file="CRM/Core/DatePickerRangeWrapper.tpl" fieldName="created_date"} | -
- {$form.changed_by.html} + {include file="CRM/Core/DatePickerRangeWrapper.tpl" fieldName="modified_date"} | - {include file="CRM/Core/DateRange.tpl" fieldName="log_date" from='_low' to='_high'}