CRM-11338 further fix on fee amount
[civicrm-core.git] / CRM / Dedupe / Finder.php
index 2e123ebd80aa6c428675f95c7a6bd5a9cd102b0a..2268bf865df9c5ea731e223b561e19ed2ec34e0b 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014                                |
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
  * $Id$
  *
  */
@@ -48,11 +48,12 @@ class CRM_Dedupe_Finder {
    * @param array $cids
    *   Contact ids to limit the search to.
    *
-   * @return array  array of (cid1, cid2, weight) dupe triples
+   * @return array
+   *   array of (cid1, cid2, weight) dupe triples
    */
   public static function dupes($rgid, $cids = array()) {
-    $rgBao             = new CRM_Dedupe_BAO_RuleGroup();
-    $rgBao->id         = $rgid;
+    $rgBao = new CRM_Dedupe_BAO_RuleGroup();
+    $rgBao->id = $rgid;
     $rgBao->contactIds = $cids;
     if (!$rgBao->find(TRUE)) {
       CRM_Core_Error::fatal("Dedupe rule not found for selected contacts");
@@ -91,12 +92,14 @@ class CRM_Dedupe_Finder {
    * @param int $ruleGroupID
    *   The id of the dedupe rule we should be using.
    *
-   * @return array  matching contact ids
+   * @return array
+   *   matching contact ids
    */
-  static function dupesByParams($params,
+  public static function dupesByParams(
+    $params,
     $ctype,
-    $used        = 'Unsupervised',
-    $except      = array(),
+    $used = 'Unsupervised',
+    $except = array(),
     $ruleGroupID = NULL
   ) {
     // If $params is empty there is zero reason to proceed.
@@ -106,8 +109,8 @@ class CRM_Dedupe_Finder {
 
     $foundByID = FALSE;
     if ($ruleGroupID) {
-      $rgBao               = new CRM_Dedupe_BAO_RuleGroup();
-      $rgBao->id           = $ruleGroupID;
+      $rgBao = new CRM_Dedupe_BAO_RuleGroup();
+      $rgBao->id = $ruleGroupID;
       $rgBao->contact_type = $ctype;
       if ($rgBao->find(TRUE)) {
         $foundByID = TRUE;
@@ -115,9 +118,9 @@ class CRM_Dedupe_Finder {
     }
 
     if (!$foundByID) {
-      $rgBao               = new CRM_Dedupe_BAO_RuleGroup();
+      $rgBao = new CRM_Dedupe_BAO_RuleGroup();
       $rgBao->contact_type = $ctype;
-      $rgBao->used         = $used;
+      $rgBao->used = $used;
       if (!$rgBao->find(TRUE)) {
         CRM_Core_Error::fatal("$used rule for $ctype does not exist");
       }
@@ -146,13 +149,14 @@ class CRM_Dedupe_Finder {
    * @param int $gid
    *   Contact group id (currently, works only with non-smart groups).
    *
-   * @return array  array of (cid1, cid2, weight) dupe triples
+   * @return array
+   *   array of (cid1, cid2, weight) dupe triples
    */
   public static function dupesInGroup($rgid, $gid) {
     $cids = array_keys(CRM_Contact_BAO_Group::getMember($gid));
-    if ( !empty($cids) ) {
-    return self::dupes($rgid, $cids);
-  }
+    if (!empty($cids)) {
+      return self::dupes($rgid, $cids);
+    }
     return array();
   }
 
@@ -166,7 +170,8 @@ class CRM_Dedupe_Finder {
    * @param string $ctype
    *   Contact type of the given contact.
    *
-   * @return array  array of dupe contact_ids
+   * @return array
+   *   array of dupe contact_ids
    */
   public static function dupesOfContact($cid, $used = 'Unsupervised', $ctype = NULL) {
     // if not provided, fetch the contact type from the database
@@ -178,8 +183,8 @@ class CRM_Dedupe_Finder {
       }
       $ctype = $dao->contact_type;
     }
-    $rgBao               = new CRM_Dedupe_BAO_RuleGroup();
-    $rgBao->used         = $used;
+    $rgBao = new CRM_Dedupe_BAO_RuleGroup();
+    $rgBao->used = $used;
     $rgBao->contact_type = $ctype;
     if (!$rgBao->find(TRUE)) {
       CRM_Core_Error::fatal("$used rule for $ctype does not exist");
@@ -208,7 +213,8 @@ class CRM_Dedupe_Finder {
    * @param string $ctype
    *   Contact type of the given contact.
    *
-   * @return array  valid $params array for dedupe
+   * @return array
+   *   valid $params array for dedupe
    */
   public static function formatParams($fields, $ctype) {
     $flat = array();
@@ -229,7 +235,9 @@ class CRM_Dedupe_Finder {
 
     // handle {birth,deceased}_date
     foreach (array(
-      'birth_date', 'deceased_date') as $date) {
+               'birth_date',
+               'deceased_date',
+             ) as $date) {
       if (!empty($fields[$date])) {
         $flat[$date] = $fields[$date];
         if (is_array($flat[$date])) {
@@ -299,8 +307,10 @@ class CRM_Dedupe_Finder {
           $fields['location_type_id'] = '';
           // FIXME: we also need to do some hacking for id and name fields, see CRM-3902’s comments
           $fixes = array(
-            'address_name' => 'name', 'country' => 'country_id',
-            'state_province' => 'state_province_id', 'county' => 'county_id',
+            'address_name' => 'name',
+            'country' => 'country_id',
+            'state_province' => 'state_province_id',
+            'county' => 'county_id',
           );
           foreach ($fixes as $orig => $target) {
             if (!empty($flat[$orig])) {
@@ -317,4 +327,5 @@ class CRM_Dedupe_Finder {
     }
     return $params;
   }
+
 }