CRM-16782 fix - Fatal error on using IN/NOT IN operator on contribution and membershi...
authormonishdeb <monish.deb@webaccessglobal.com>
Wed, 1 Jul 2015 14:32:14 +0000 (20:02 +0530)
committermonishdeb <monish.deb@webaccessglobal.com>
Wed, 1 Jul 2015 14:35:00 +0000 (20:05 +0530)
https://issues.civicrm.org/jira/browse/CRM-16782

CRM/Contact/BAO/Query.php
CRM/Member/BAO/Query.php
CRM/Member/Form/Search.php
templates/CRM/Member/Form/Search/Common.tpl

index 476a3aeac2ca42e86efee3dda962b9f6a5b8f0e8..8cf4854b9b0af8fa35424f260e62c379cdcbd60e 100644 (file)
@@ -2217,7 +2217,7 @@ class CRM_Contact_BAO_Query {
           if (!in_array($operator, CRM_Core_DAO::acceptedSQLOperators())) {
             //Via Contact get api value is not in array(operator => array(values)) format ONLY for IN/NOT IN operators
             //so this condition will satisfy the search for now
-            if (strstr('IN', $op)) {
+            if (strpos($op, 'IN') !== FALSE) {
               $value = array($op => $value);
             }
             // we don't know when this might happen
@@ -5064,7 +5064,7 @@ SELECT COUNT( conts.total_amount ) as cancel_count,
         $date = "('" . implode("','", $value) . "')";
         $format = implode(', ', $format);
       }
-      elseif ($value) {
+      elseif ($value && (!strstr($op, 'NULL') && !strstr($op, 'EMPTY'))) {
         $date = CRM_Utils_Date::processDate($value);
         if (!$appendTimeStamp) {
           $date = substr($date, 0, 8);
@@ -5203,26 +5203,6 @@ SELECT COUNT( conts.total_amount ) as cancel_count,
         $clause = " (NULLIF($field, '') IS NOT NULL) ";
         return $clause;
 
-      case 'IN':
-      case 'NOT IN':
-        if (isset($dataType)) {
-          if (is_array($value)) {
-            $values = $value;
-          }
-          else {
-            $value = CRM_Utils_Type::escape($value, "String");
-            $values = explode(',', CRM_Utils_Array::value(0, explode(')', CRM_Utils_Array::value(1, explode('(', $value)))));
-          }
-          // supporting multiple values in IN clause
-          $val = array();
-          foreach ($values as $v) {
-            $v = trim($v);
-            $val[] = "'" . CRM_Utils_Type::escape($v, $dataType) . "'";
-          }
-          $value = "(" . implode($val, ",") . ")";
-        }
-        return "$clause $value";
-
       default:
         if (empty($dataType)) {
           $dataType = 'String';
index a4b8798492e7d727eece5138263b9b4f5e97bb8e..8c35a1fd6c12143aa2ef2e7467c4427ffd44d1b3 100644 (file)
@@ -203,34 +203,28 @@ class CRM_Member_BAO_Query {
 
       case 'membership_status':
       case 'member_status_id':
-        if (!is_array($value)) {
-          $status = $value;
-          if (!empty($value)) {
-            $value = array_flip(explode(",", str_replace(array('(', ')'), '', $value)));
-          }
-          else {
-            $value = array();
-          }
+      case 'membership_type':
+      case 'membership_type_id':
+      case 'member_id':
+        if (strpos($name, 'status') !== FALSE) {
+          $name = 'status_id';
+          $qillName = 'Membership Status(s)';
         }
-        else {
-          $status = implode(',', array_keys($value));
-          if (count($value) > 0) {
-            $op = 'IN';
-            $status = "({$status})";
-          }
+        elseif ($name == 'member_id') {
+          $name = 'id';
+          $qillName = 'Membership ID';
         }
-
-        $names = array();
-        $statusTypes = CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'label');
-        foreach ($value as $id => $dontCare) {
-          $names[] = $statusTypes[$id];
+        else {
+          $name = 'membership_type_id';
+          $qillName = 'Memebership Type(s)';
         }
-        $query->_qill[$grouping][] = ts('Membership Status %1', array(1 => $op)) . ' ' . implode(' ' . ts('or') . ' ', $names);
-        $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_membership.status_id",
+        $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_membership.$name",
           $op,
-          $status,
+          $value,
           "Integer"
         );
+        list($op, $value) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Member_DAO_Membership', $name, $value, $op);
+        $query->_qill[$grouping][] = ts('%1 %2 %3', array(1 => $qillName, 2 => $op, 3 => $value));
         $query->_tables['civicrm_membership'] = $query->_whereTables['civicrm_membership'] = 1;
         return;
 
@@ -282,46 +276,6 @@ class CRM_Member_BAO_Query {
         $query->_tables['civicrm_membership'] = $query->_whereTables['civicrm_membership'] = 1;
         return;
 
-      case 'membership_type':
-      case 'member_membership_type_id':
-        if (!is_array($value)) {
-          $mType = $value;
-          if (!empty($value)) {
-            $value = array_flip(explode(",", str_replace(array('(', ')'), '', $value)));
-          }
-          else {
-            $value = array();
-          }
-        }
-        else {
-          $mType = implode(',', array_keys($value));
-          if (count($value) > 0) {
-            $op = 'IN';
-            $mType = "({$mType})";
-          }
-        }
-
-        $names = array();
-        $membershipTypes = CRM_Member_PseudoConstant::membershipType();
-        foreach ($value as $id => $dontCare) {
-          if (!empty($membershipTypes[$id])) {
-            $names[] = $membershipTypes[$id];
-          }
-        }
-        $query->_qill[$grouping][] = ts('Membership Type %1', array(1 => $op)) . ' ' . implode(' ' . ts('or') . ' ', $names);
-        $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_membership.membership_type_id",
-          $op,
-          $mType,
-          "Integer"
-        );
-        $query->_tables['civicrm_membership'] = $query->_whereTables['civicrm_membership'] = 1;
-        return;
-
-      case 'member_id':
-        $query->_where[$grouping][] = " civicrm_membership.id $op $value";
-        $query->_tables['civicrm_membership'] = $query->_whereTables['civicrm_membership'] = 1;
-        return;
-
       case 'member_is_primary':
         if ($value) {
           $query->_where[$grouping][] = " civicrm_membership.owner_membership_id IS NULL";
@@ -436,13 +390,13 @@ class CRM_Member_BAO_Query {
    * @param CRM_Core_Form $form
    */
   public static function buildSearchForm(&$form) {
-    foreach (CRM_Member_PseudoConstant::membershipType() as $id => $Name) {
-      $form->_membershipType = &$form->addElement('checkbox', "member_membership_type_id[$id]", NULL, $Name);
-    }
+    $form->addSelect('status_id',
+      array('entity' => 'membership', 'multiple' => 'multiple', 'label' => ts('Memebership Status(s)'), 'option_url' => NULL, 'placeholder' => ts('- any -'))
+    );
 
-    foreach (CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'label') as $sId => $sName) {
-      $form->_membershipStatus = &$form->addElement('checkbox', "member_status_id[$sId]", NULL, $sName);
-    }
+    $form->addSelect('membership_type_id',
+      array('entity' => 'membership', 'multiple' => 'multiple', 'label' => ts('Memebership Type(s)'), 'option_url' => NULL, 'placeholder' => ts('- any -'))
+    );
 
     $form->addElement('text', 'member_source', ts('Source'));
 
index ec4ae0718a65ee443811b1a132d8439307d4f29a..6d1bfa9b8d983c78706612fb4f8b48e419e18789 100644 (file)
@@ -209,6 +209,21 @@ class CRM_Member_Form_Search extends CRM_Core_Form_Search {
       $this->_formValues["member_test"] = 0;
     }
 
+    $specialParams = array(
+      'status_id',
+      'membership_type_id',
+    );
+    foreach ($specialParams as $element) {
+      $value = CRM_Utils_Array::value($element, $this->_formValues);
+      if (!empty($value) && is_array($value)) {
+        if ($element == 'status_id') {
+          unset($this->_formValues[$element]);
+          $element = 'member_' . $element;
+        }
+        $this->_formValues[$element] = array('IN' => $value);
+      }
+    }
+
     CRM_Core_BAO_CustomValue::fixFieldValueOfTypeMemo($this->_formValues);
 
     $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues);
@@ -282,12 +297,7 @@ class CRM_Member_Form_Search extends CRM_Core_Form_Search {
     );
     if ($status) {
       $status = explode(',', $status);
-      $tempStatus = array();
-      foreach ($status as $value) {
-        $tempStatus[$value] = 1;
-      }
-      $this->_formValues['member_status_id'] = $tempStatus;
-      $this->_defaults['member_status_id'] = $tempStatus;
+      $this->_formValues['status_id'] = $this->_defaults['status_id'] = (array) $status;
     }
 
     $membershipType = CRM_Utils_Request::retrieve('type', 'String',
@@ -295,8 +305,8 @@ class CRM_Member_Form_Search extends CRM_Core_Form_Search {
     );
 
     if ($membershipType) {
-      $this->_formValues['member_membership_type_id'] = array($membershipType => 1);
-      $this->_defaults['member_membership_type_id'] = array($membershipType => 1);
+      $this->_formValues['membership_type_id'] = array($membershipType);
+      $this->_defaults['membership_type_id'] = array($membershipType);
     }
 
     $cid = CRM_Utils_Request::retrieve('cid', 'Positive',
index 8ecc6652ac9edd6fcdbc3a59be7aff85196645ba..638472ec39bb455b89086e2943c44d6beef20975 100644 (file)
  +--------------------------------------------------------------------+
 *}
 <tr>
-  <td><label>{ts}Membership Type(s){/ts}</label><br />
-    <div class="listing-box">
-    {foreach from=$form.member_membership_type_id item="membership_type_val"}
-      <div class="{cycle values='odd-row,even-row'}">
-        {$membership_type_val.html}
-      </div>
-    {/foreach}
-    </div>
+  <td><label>{$form.membership_type_id.label}</label><br />
+      {$form.membership_type_id.html|crmAddClass:twenty}
   </td>
-  <td><label>{ts}Membership Status{/ts}</label><br />
-    <div class="listing-box">
-    {foreach from=$form.member_status_id item="membership_status_val"}
-      <div class="{cycle values='odd-row,even-row'}">
-        {$membership_status_val.html}
-      </div>
-    {/foreach}
-    </div>
+  <td><label>{$form.status_id.label}</label><br />
+      {$form.status_id.html|crmAddClass:twenty}
   </td>
 </tr>