From 06606cd168369aa3b7e062ef9e34f09b06fc12c0 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 14 Jan 2016 12:17:27 -0500 Subject: [PATCH] CRM-17645 - Add filters for Case entityRef --- CRM/Core/Resources.php | 56 +++++++++++++++++++++++++++++++++--------- js/Common.js | 12 ++++++--- 2 files changed, 52 insertions(+), 16 deletions(-) diff --git a/CRM/Core/Resources.php b/CRM/Core/Resources.php index b9ff1e7f3c..b3f41b74fb 100644 --- a/CRM/Core/Resources.php +++ b/CRM/Core/Resources.php @@ -792,20 +792,32 @@ class CRM_Core_Resources { */ public static function getEntityRefFilters() { $filters = array(); + $config = CRM_Core_Config::singleton(); - $filters['event'] = array( - array('key' => 'event_type_id', 'value' => ts('Event Type')), - array( - 'key' => 'start_date', - 'value' => ts('Start Date'), - 'options' => array( - array('key' => '{">":"now"}', 'value' => ts('Upcoming')), - array('key' => '{"BETWEEN":["now - 3 month","now"]}', 'value' => ts('Past 3 Months')), - array('key' => '{"BETWEEN":["now - 6 month","now"]}', 'value' => ts('Past 6 Months')), - array('key' => '{"BETWEEN":["now - 1 year","now"]}', 'value' => ts('Past Year')), + if (in_array('CiviEvent', $config->enableComponents)) { + $filters['event'] = array( + array('key' => 'event_type_id', 'value' => ts('Event Type')), + array( + 'key' => 'start_date', + 'value' => ts('Start Date'), + 'options' => array( + array('key' => '{">":"now"}', 'value' => ts('Upcoming')), + array( + 'key' => '{"BETWEEN":["now - 3 month","now"]}', + 'value' => ts('Past 3 Months'), + ), + array( + 'key' => '{"BETWEEN":["now - 6 month","now"]}', + 'value' => ts('Past 6 Months'), + ), + array( + 'key' => '{"BETWEEN":["now - 1 year","now"]}', + 'value' => ts('Past Year'), + ), + ), ), - ), - ); + ); + } $filters['activity'] = array( array('key' => 'activity_type_id', 'value' => ts('Activity Type')), @@ -822,6 +834,26 @@ class CRM_Core_Resources { array('key' => 'is_deceased', 'value' => ts('Deceased')), ); + if (in_array('CiviCase', $config->enableComponents)) { + $filters['case'] = array( + array( + 'key' => 'case_id.case_type_id', + 'value' => ts('Case Type'), + 'entity' => 'Case', + ), + array( + 'key' => 'case_id.status_id', + 'value' => ts('Case Status'), + 'entity' => 'Case', + ), + ); + foreach ($filters['contact'] as $filter) { + $filter += array('entity' => 'contact'); + $filter['key'] = 'contact_id.' . $filter['key']; + $filters['case'][] = $filter; + } + } + return $filters; } diff --git a/js/Common.js b/js/Common.js index d821767a77..081dfabdea 100644 --- a/js/Common.js +++ b/js/Common.js @@ -586,10 +586,12 @@ if (!CRM.vars) CRM.vars = {}; combined = _.cloneDeep(params), filter = $.extend({}, $el.data('user-filter') || {}); if (filter.key && filter.value) { + // Fieldname may be prefixed with joins + var fieldName = _.last(filter.key.split('.')); // Special case for contact type/sub-type combo - if (filter.key === 'contact_type' && (filter.value.indexOf('__') > 0)) { - combined.params.contact_type = filter.value.split('__')[0]; - combined.params.contact_sub_type = filter.value.split('__')[1]; + if (fieldName === 'contact_type' && (filter.value.indexOf('__') > 0)) { + combined.params[filter.key] = filter.value.split('__')[0]; + combined.params[filter.key.replace('contact_type', 'contact_sub_type')] = filter.value.split('__')[1]; } else { // Allow json-encoded api filters e.g. {"BETWEEN":[123,456]} combined.params[filter.key] = filter.value.charAt(0) === '{' ? $.parseJSON(filter.value) : filter.value; @@ -871,7 +873,9 @@ if (!CRM.vars) CRM.vars = {}; CRM.utils.setOptions($valField, filterSpec.options, false, filter.value); } else { $valField.prop('disabled', true); - CRM.api3(filterSpec.entity || $el.data('api-entity'), 'getoptions', {field: filter.key, context: 'search', sequential: 1}) + // Fieldname may be prefixed with joins - strip those out + var fieldName = _.last(filter.key.split('.')); + CRM.api3(filterSpec.entity || $el.data('api-entity'), 'getoptions', {field: fieldName, context: 'search', sequential: 1}) .done(function(result) { var entity = $el.data('api-entity').toLowerCase(), globalFilterSpec = _.find(CRM.config.entityRef.filters[entity], {key: filter.key}) || {}; -- 2.25.1