CRM-19078: Cannot search memberships by auto-renew OR not-auto-renew
authoryashodha <yashodha.chaku@webaccessglobal.com>
Thu, 14 Jul 2016 08:03:16 +0000 (13:33 +0530)
committeryashodha <yashodha.chaku@webaccessglobal.com>
Thu, 14 Jul 2016 08:03:16 +0000 (13:33 +0530)
----------------------------------------
* CRM-19078: Cannot search memberships by auto-renew OR not-auto-renew
  https://issues.civicrm.org/jira/browse/CRM-19078

CRM/Member/BAO/Query.php
templates/CRM/Member/Form/Search.hlp

index fce002720794de273dc4a3ce26ff18b1ca252e45..7fb821ccb47f8a4c798698559c78b53123cbd99a 100644 (file)
@@ -263,55 +263,65 @@ class CRM_Member_BAO_Query {
         return;
 
       case 'member_auto_renew':
-        $op = "=";
-        if ($value == 1) {
-          $query->_where[$grouping][] = " civicrm_membership.contribution_recur_id IS NULL";
-          $query->_qill[$grouping][] = ts("Membership is NOT Auto-Renew");
-        }
-        elseif ($value == 2) {
-          $query->_where[$grouping][] = " civicrm_membership.contribution_recur_id IS NOT NULL";
-          $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause(
-            "ccr.contribution_status_id",
-            $op,
-            array_search(
-              'In Progress',
-              CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name')
-            ),
-            "Integer"
-          );
-          $query->_qill[$grouping][] = ts("Membership is Auto-Renew and In Progress");
-        }
-        elseif ($value == 3) {
-          $query->_where[$grouping][] = " civicrm_membership.contribution_recur_id IS NOT NULL";
-          $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause(
-            "ccr.contribution_status_id",
-            $op,
-            array_search(
-              'Failed',
-              CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name')
-            ),
-            "Integer"
-          );
-          $query->_qill[$grouping][] = ts("Membership is Auto-Renew and Failed");
-        }
-        elseif ($value == 4) {
-          $query->_where[$grouping][] = " civicrm_membership.contribution_recur_id IS NOT NULL";
-          $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause(
-            "ccr.contribution_status_id",
-            $op,
-            array_search(
-              'Cancelled',
-              CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name')
-            ),
-            "Integer"
-          );
-          $query->_qill[$grouping][] = ts("Membership is Auto-Renew and Cancelled");
+        $op = '=';
+        $where = $qill = array();
+        foreach ($value as $val) {
+          if ($val == 1) {
+            $where[] = ' civicrm_membership.contribution_recur_id IS NULL';
+            $qill[] = ts('Membership is NOT Auto-Renew');
+          }
+          elseif ($val == 2) {
+            $where[] = ' civicrm_membership.contribution_recur_id IS NOT NULL AND ' . CRM_Contact_BAO_Query::buildClause(
+                'ccr.contribution_status_id',
+                $op,
+                array_search(
+                  'In Progress',
+                  CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name')
+                ),
+                'Integer'
+              );
+            $qill[] = ts('Membership is Auto-Renew and In Progress');
+          }
+          elseif ($val == 3) {
+            $where[] = ' civicrm_membership.contribution_recur_id IS NOT NULL AND ' .
+              CRM_Contact_BAO_Query::buildClause(
+                'ccr.contribution_status_id',
+                $op,
+                array_search(
+                  'Failed',
+                  CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name')
+                ),
+                'Integer'
+              );
+            $qill[] = ts('Membership is Auto-Renew and Failed');
+          }
+          elseif ($val == 4) {
+            $where[] = ' civicrm_membership.contribution_recur_id IS NOT NULL AND ' .
+              CRM_Contact_BAO_Query::buildClause(
+                'ccr.contribution_status_id',
+                $op,
+                array_search(
+                  'Cancelled',
+                  CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name')
+                ),
+                'Integer'
+              );
+            $qill[] = ts('Membership is Auto-Renew and Cancelled');
+          }
+          elseif ($val == 5) {
+            $where[] = ' civicrm_membership.contribution_recur_id IS NOT NULL AND ccr.end_date IS NOT NULL AND ccr.end_date < NOW()';
+            $qill[] = ts('Membership is Auto-Renew and Ended');
+          }
+          elseif ($val == 6) {
+            $where[] = ' civicrm_membership.contribution_recur_id IS NOT NULL';
+            $qill[] = ts('Membership is Auto-Renew');
+          }
         }
-        elseif ($value == 5) {
-          $query->_where[$grouping][] = " civicrm_membership.contribution_recur_id IS NOT NULL";
-          $query->_where[$grouping][] = " ccr.end_date IS NOT NULL AND ccr.end_date < NOW()";
-          $query->_qill[$grouping][] = ts("Membership is Auto-Renew and Ended");
+        if (!empty($where)) {
+          $query->_where[$grouping][] = implode(' OR ', $where);
+          $query->_qill[$grouping][] = implode(' OR ', $qill);
         }
+
         $query->_tables['civicrm_membership'] = $query->_whereTables['civicrm_membership'] = 1;
         return;
 
@@ -486,7 +496,9 @@ class CRM_Member_BAO_Query {
         '3' => ts('Failed'),
         '4' => ts('Cancelled'),
         '5' => ts('Ended'),
-      )
+        '6' => ts('Any'),
+      ),
+      FALSE, array('class' => 'crm-select2', 'multiple' => 'multiple', 'placeholder' => ts('- any -'))
     );
 
     $form->addYesNo('member_test', ts('Membership is a Test?'), TRUE);
index 5dd6e9df517ea8c46f9c94e81d9a303d6ee11ad0..9725886304b5ef38460df97d1da54e5abf4103fe 100644 (file)
@@ -53,6 +53,7 @@
     <li>{ts}Select "Failed" to display memberships with failed subscription payment.{/ts}</li>
     <li>{ts}Select "Cancelled" to display memberships with cancelled auto-renew subscriptions.{/ts}</li>
     <li>{ts}Select "Ended" to display memberships with an ended auto-renew subscription.{/ts}</li>
+    <li>{ts}Select "Any" to display memberships with auto-renew subscription irrespective of their status.{/ts}</li>
   </ul>
 {/htxt}