- $cids = array();
- foreach ($foundDupes as $dupe) {
- $cids[$dupe[0]] = 1;
- $cids[$dupe[1]] = 1;
- }
- $cidString = implode(', ', array_keys($cids));
- $sql = "SELECT id, display_name FROM civicrm_contact WHERE id IN ($cidString) ORDER BY sort_name";
- $dao = new CRM_Core_DAO();
- $dao->query($sql);
- $displayNames = array();
- while ($dao->fetch()) {
- $displayNames[$dao->id] = $dao->display_name;
- }
-
- // FIXME: sort the contacts; $displayName
- // is already sort_name-sorted, so use that
- // (also, consider sorting by dupe count first)
- // lobo - change the sort to by threshold value
- // so the more likely dupes are sorted first
- $session = CRM_Core_Session::singleton();
- $userId = $session->get('userID');
- $mainContacts = $permission = array();
-
- foreach ($foundDupes as $dupes) {
- $srcID = $dupes[0];
- $dstID = $dupes[1];
- if ($dstID == $userId) {
- $srcID = $dupes[1];
- $dstID = $dupes[0];
- }
-
- /***
- * Eliminate this since it introduces 3 queries PER merge row
- * and hence is very expensive
- * CRM-8822
- * if ( !array_key_exists( $srcID, $permission ) ) {
- * $permission[$srcID] = CRM_Contact_BAO_Contact_Permission::allow( $srcID, CRM_Core_Permission::EDIT );
- * }
- * if ( !array_key_exists( $dstID, $permission ) ) {
- * $permission[$dstID] = CRM_Contact_BAO_Contact_Permission::allow( $dstID, CRM_Core_Permission::EDIT );
- * }
- *
- * $canMerge = ( $permission[$dstID] && $permission[$srcID] );
- *
- */