From 37653fa096544a06446a48a1217d9fb5db3f400c Mon Sep 17 00:00:00 2001 From: monishdeb Date: Fri, 21 Aug 2015 19:58:30 +0530 Subject: [PATCH] CRM-17057 fix - Advanced Search does not respect the selected Case Status filter https://issues.civicrm.org/jira/browse/CRM-17057 --- CRM/Case/BAO/Query.php | 85 +++++++---------------- templates/CRM/Case/Form/Search/Common.tpl | 20 ++---- 2 files changed, 29 insertions(+), 76 deletions(-) diff --git a/CRM/Case/BAO/Query.php b/CRM/Case/BAO/Query.php index ecb716c5e7..29136dac06 100644 --- a/CRM/Case/BAO/Query.php +++ b/CRM/Case/BAO/Query.php @@ -253,67 +253,30 @@ class CRM_Case_BAO_Query { list($name, $op, $value, $grouping, $wildcard) = $values; $val = $names = array(); switch ($name) { - case 'case_status': - case 'case_status_id': - $statuses = CRM_Case_PseudoConstant::caseStatus(); - // Standardize input from checkboxes or single value - if (is_array($value) && $query->_mode == CRM_Contact_BAO_Query::MODE_CASE) { - $value = array_keys($value, 1); - } - foreach ((array) $value as $k) { - if ($k && isset($statuses[$k])) { - $val[$k] = $k; - $names[] = $statuses[$k]; - } - elseif ($k && ($v = CRM_Utils_Array::key($k, $statuses))) { - $val[$v] = $v; - $names[] = $k; - } - } - if ($val) { - $query->_where[$grouping][] = "civicrm_case.status_id IN (" . implode(',', $val) . ")"; - } - else { - $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause('civicrm_case.status_id', $op, $value, "Integer"); - } - $query->_qill[$grouping][] = ts('Case Status is %1', array(1 => implode(' ' . ts('or') . ' ', $names))); - $query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1; - return; case 'case_type_id': case 'case_type': - $caseTypes = CRM_Case_PseudoConstant::caseType('title', FALSE); + case 'case_status': + case 'case_status_id': + case 'case_id': - if (is_array($value)) { - foreach ($value as $k => $v) { - if ($v) { - $val[$k] = $k; - $names[] = $caseTypes[$k]; - } - } - } - elseif (is_numeric($value)) { - $val[$value] = $value; - $names[] = $value; - } - elseif ($caseTypeId = CRM_Utils_Array::key($value, $caseTypes)) { - $val[$caseTypeId] = $caseTypeId; - $names[] = $caseTypes[$caseTypeId]; + if (strpos($name, 'type')) { + $name = 'case_type_id'; + $label = 'Case Type(s)'; } - - if ($val) { - $query->_where[$grouping][] = "(civicrm_case.case_type_id IN (" . implode(',', $val) . "))"; + elseif (strpos($name, 'status')) { + $name = 'status_id'; + $label = 'Case Status(s)'; } else { - $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause('civicrm_case.case_type_id', $op, $value, "Integer"); + $name = 'id'; + $label = 'Case ID'; } - $query->_qill[$grouping][] = ts('Case Type is %1', array(1 => implode(' ' . ts('or') . ' ', $names))); - $query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1; - return; + $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_case.{$name}", $op, $value, "Integer"); + list($op, $value) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Case_DAO_Case', $name, $value, $op); - case 'case_id': - $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_case.id", $op, $value, 'Int'); + $query->_qill[$grouping][] = ts('%1 %2 %3', array(1 => $label, 2 => $op, 3 => $value)); $query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1; return; @@ -707,15 +670,17 @@ case_relation_type.id = case_relationship.relationship_type_id )"; $configured = CRM_Case_BAO_Case::isCaseConfigured(); $form->assign('notConfigured', !$configured['configured']); - $caseTypes = CRM_Case_PseudoConstant::caseType('title', FALSE); - foreach ($caseTypes as $id => $name) { - $form->addElement('checkbox', "case_type_id[$id]", NULL, $name); - } - - $statuses = CRM_Case_PseudoConstant::caseStatus('label', FALSE); - foreach ($statuses as $id => $name) { - $form->addElement('checkbox', "case_status_id[$id]", NULL, $name); - } + $form->add('select', 'case_type_id', + ts('Case Type'), + CRM_Case_PseudoConstant::caseType('title', FALSE), + FALSE, array('class' => 'crm-select2', 'multiple' => 'multiple') + ); + + $form->add('select', 'case_status_id', + ts('Case Status'), + CRM_Case_PseudoConstant::caseStatus('label', FALSE), + FALSE, array('class' => 'crm-select2', 'multiple' => 'multiple') + ); CRM_Core_Form_Date::buildDateRange($form, 'case_from', 1, '_start_date_low', '_start_date_high', ts('From'), FALSE); CRM_Core_Form_Date::buildDateRange($form, 'case_to', 1, '_end_date_low', '_end_date_high', ts('From'), FALSE); diff --git a/templates/CRM/Case/Form/Search/Common.tpl b/templates/CRM/Case/Form/Search/Common.tpl index 36ba8e5fb8..d3ef46face 100644 --- a/templates/CRM/Case/Form/Search/Common.tpl +++ b/templates/CRM/Case/Form/Search/Common.tpl @@ -35,25 +35,13 @@ -
-
- {foreach from=$form.case_type_id item="case_type_id_val"} -
- {$case_type_id_val.html} -
- {/foreach} -

+
+ {$form.case_type_id.html} -
-
- {foreach from=$form.case_status_id item="case_status_id_val"} -
- {$case_status_id_val.html} -
- {/foreach} -
+
+ {$form.case_status_id.html} {if $accessAllCases}
{$form.case_owner.html} -- 2.25.1