From 2b65bb8c772f1744ad5add050a651887e37acc10 Mon Sep 17 00:00:00 2001 From: monishdeb Date: Fri, 24 Jul 2015 20:12:26 +0530 Subject: [PATCH] CRM-16909 fix - "Find Pledges" search filters on "status" are not working https://issues.civicrm.org/jira/browse/CRM-16909 --- CRM/Contribute/BAO/Query.php | 8 +-- CRM/Pledge/BAO/Query.php | 106 ++++++++--------------------------- 2 files changed, 27 insertions(+), 87 deletions(-) diff --git a/CRM/Contribute/BAO/Query.php b/CRM/Contribute/BAO/Query.php index c42904f787..22b57c8001 100644 --- a/CRM/Contribute/BAO/Query.php +++ b/CRM/Contribute/BAO/Query.php @@ -897,12 +897,12 @@ class CRM_Contribute_BAO_Query { // stores the label $form->add('hidden', 'pcp_made_through'); - $statusValues = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'contribution_status'); + $statusValues = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'contribution_status_id'); // Remove status values that are only used for recurring contributions or pledges (In Progress, Overdue). unset($statusValues['5'], $statusValues['6']); - - $form->addSelect('contribution_status_id', - array('entity' => 'contribution', 'multiple' => 'multiple', 'label' => ts('Contribution Status(s)'), 'option_url' => NULL, 'placeholder' => ts('- any -')) + $form->add('select', 'contribution_status_id', + ts('Contribution Status'), $statusValues, + FALSE, array('class' => 'crm-select2', 'multiple' => 'multiple') ); // Add fields for thank you and receipt diff --git a/CRM/Pledge/BAO/Query.php b/CRM/Pledge/BAO/Query.php index cd52b7d4c7..446ff49d93 100644 --- a/CRM/Pledge/BAO/Query.php +++ b/CRM/Pledge/BAO/Query.php @@ -266,88 +266,30 @@ class CRM_Pledge_BAO_Query { ); return; - case 'pledge_status_id': - if (is_array($value)) { - foreach ($value as $k => $v) { - if ($v) { - $val[$k] = $k; - } - } - - $status = implode(',', $val); - - if (count($val) > 0) { - $op = 'IN'; - $status = "({$status})"; - } - } - else { - $status = $value; - } - - $statusValues = CRM_Core_OptionGroup::values('contribution_status'); - - $names = array(); - if (isset($val) && is_array($val)) { - foreach ($val as $id => $dontCare) { - $names[] = $statusValues[$id]; - } - } - else { - if (!empty($value)) { - $names[] = $statusValues[$value]; - } - } - - $query->_qill[$grouping][] = ts('Pledge Status %1', array(1 => $op)) . ' ' . implode(' ' . ts('or') . ' ', $names); - $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause('civicrm_pledge.status_id', - $op, - $status, - 'Integer' - ); - $query->_tables['civicrm_pledge'] = $query->_whereTables['civicrm_pledge'] = 1; - return; - case 'pledge_payment_status_id': - if (is_array($value)) { - foreach ($value as $k => $v) { - if ($v) { - $val[$k] = $k; - } - } - - $status = implode(',', $val); - - if (count($val) > 1) { - $op = 'IN'; - $status = "({$status})"; - } + case 'pledge_status_id': + if ($name == 'pledge_status_id') { + $tableName = 'civicrm_pledge'; + $query->_tables['civicrm_pledge'] = $query->_whereTables['civicrm_pledge'] = 1; + $label = "Pledge Status"; } else { - $status = $value; - } - - $statusValues = CRM_Core_OptionGroup::values('contribution_status'); - - $names = array(); - if (is_array($val)) { - foreach ($val as $id => $dontCare) { - $names[] = $statusValues[$id]; - } + $tableName = 'civicrm_pledge_payment'; + $query->_tables['civicrm_pledge_payment'] = $query->_whereTables['civicrm_pledge_payment'] = 1; + $label = "Pledge Payment Status"; } - else { - if (!empty($value)) { - $names[] = $statusValues[$value]; - } + $name = 'status_id'; + if (!empty($value) && is_array($value) && !in_array(key($value), CRM_Core_DAO::acceptedSQLOperators(), TRUE)) { + $value = array('IN' => $value); } - $query->_qill[$grouping][] = ts('Pledge Payment Status %1', array(1 => $op)) . ' ' . implode(' ' . ts('or') . ' ', $names); - $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause('civicrm_pledge_payment.status_id', + $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("$tableName.$name", $op, - $status, + $value, 'Integer' ); - $query->_tables['civicrm_pledge_payment'] = $query->_whereTables['civicrm_pledge_payment'] = 1; + list($qillop, $qillVal) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Contribute_DAO_Contribution', 'contribution_status_id', $value, $op); + $query->_qill[$grouping][] = ts('%1 %2 %3', array(1 => $label, 2 => $qillop, 3 => $qillVal)); return; case 'pledge_test': @@ -567,20 +509,18 @@ class CRM_Pledge_BAO_Query { // Remove status values that are only used for recurring contributions for now (Failed and In Progress). unset($statusValues['4']); - foreach ($statusValues as $key => $val) { - $status[] = $form->createElement('advcheckbox', $key, NULL, $val); - } - - $form->addGroup($status, 'pledge_status_id', ts('Pledge Status')); + $form->add('select', 'pledge_status_id', + ts('Pledge Status'), $statusValues, + FALSE, array('class' => 'crm-select2', 'multiple' => 'multiple') + ); //unset in progress for payment unset($statusValues['5']); - foreach ($statusValues as $key => $val) { - $paymentStatus[] = $form->createElement('advcheckbox', $key, NULL, $val); - } - - $form->addGroup($paymentStatus, 'pledge_payment_status_id', ts('Pledge Payment Status')); + $form->add('select', 'pledge_payment_status_id', + ts('Pledge Payment Status'), $statusValues, + FALSE, array('class' => 'crm-select2', 'multiple' => 'multiple') + ); $form->add('select', 'pledge_financial_type_id', ts('Financial Type'), -- 2.25.1