CRM-13851 phone search wildcard handling
authorBrian Shaughnessy <brian@lcdservices.biz>
Wed, 27 Nov 2013 20:36:17 +0000 (15:36 -0500)
committerBrian Shaughnessy <brian@lcdservices.biz>
Wed, 27 Nov 2013 20:36:17 +0000 (15:36 -0500)
CRM/Contact/BAO/Query.php

index 5d5a8174c3e0f335b676e43de37aa5307556bf65..d670cd4b5fb1592beb1d9aac96a4511f19a4600c 100644 (file)
@@ -3183,11 +3183,15 @@ WHERE  id IN ( $groupIDs )
    */
   function phone_numeric(&$values) {
     list($name, $op, $value, $grouping, $wildcard) = $values;
-    // Strip non-numeric characters
-    $number = preg_replace('/[^\d]/', '', $value);
+    // Strip non-numeric characters; allow wildcards
+    $number = preg_replace('/[^\d%]/', '', $value);
     if ($number) {
+      if ( strpos($number, '%') === FALSE ) {
+        $number = "%$number%";
+      }
+
       $this->_qill[$grouping][] = ts('Phone number contains') . " $number";
-      $this->_where[$grouping][] = self::buildClause('civicrm_phone.phone_numeric', 'LIKE', "%$number%", 'String');
+      $this->_where[$grouping][] = self::buildClause('civicrm_phone.phone_numeric', 'LIKE', "$number", 'String');
       $this->_tables['civicrm_phone'] = $this->_whereTables['civicrm_phone'] = 1;
     }
   }