r50325 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r50324‎ | r50325 | r50326 >
Date:22:46, 7 May 2009
Author:straussd
Status:deferred
Tags:
Comment:
Forward port older merge logic
Modified paths:
  • /civicrm/trunk/sites/all/modules/civimerge/civimerge.module (modified) (history)

Diff [purge]

Index: civicrm/trunk/sites/all/modules/civimerge/civimerge.module
@@ -75,14 +75,15 @@
7676
7777 function civimerge_block_content_similar($cid, $raw = TRUE) {
7878 civicrm_initialize(true);
79 -
8079 require_once 'CRM/Dedupe/Finder.php';
8180 require_once 'CRM/Contact/DAO/Contact.php';
8281
8382 $content = array();
8483
8584 $start = microtime(TRUE);
86 - $similar = CRM_Dedupe_Finder::dupesOfContact($cid, 'Strict');
 85+
 86+ $similar = civicluster_get_similar($primary_cid);
 87+ //$similar = CRM_Dedupe_Finder::dupesOfContact($cid, 'Strict');
8788 //$content[] = '<div>Similarity check: ' . round(microtime(TRUE) - $start, 2) . 's</div>';
8889
8990 if (!empty($similar)) {
@@ -200,3 +201,102 @@
201202 'query' => 'reset=1&cid=' . $cid . '&oid=' . $oid
202203 );
203204 }
 205+
 206+function civicluster_get_similar($primary_cid)
 207+{
 208+ return _civicluster_get_similar_rough($primary_cid, 10);
 209+}
 210+
 211+function _civicluster_get_similar_rough($primary_cid, $min_score)
 212+{
 213+ $similar = array();
 214+ $similar = _civicluster_update_scores($similar, _civicluster_get_similar_location($primary_cid, 'civicrm_address', 'street_address'), 10);
 215+ //$similar = _civicluster_update_scores($similar, _civicluster_get_similar_location($primary_cid, 'civicrm_address', 'city'));
 216+ $similar = _civicluster_update_scores($similar, _civicluster_get_similar_location($primary_cid, 'civicrm_email', 'email'), 20);
 217+ $similar = _civicluster_update_scores($similar, _civicluster_get_similar_location($primary_cid, 'civicrm_phone', 'phone'), 10);
 218+ $similar = _civicluster_update_scores($similar, _civicluster_get_similar_name($primary_cid, 6), 2);
 219+ $similar = _civicluster_update_scores($similar, _civicluster_get_similar_name($primary_cid, 8), 3);
 220+ $similar = _civicluster_update_scores($similar, _civicluster_get_similar_name($primary_cid, 10), 4);
 221+ $similar = _civicluster_update_scores($similar, _civicluster_get_similar_name($primary_cid, 12), 5);
 222+
 223+ //drupal_set_message(print_r($similar, TRUE));
 224+
 225+ $similar_cids = array();
 226+ foreach($similar as $similar_cid => $score)
 227+ {
 228+ if ($score >= $min_score && $similar_cid != $primary_cid && !civicluster_are_separated($primary_cid, $similar_cid))
 229+ {
 230+ $similar_cids[] = $similar_cid;
 231+ }
 232+ }
 233+
 234+ //drupal_set_message(print_r($similar_cids, TRUE));
 235+
 236+ return $similar_cids;
 237+}
 238+
 239+function _civicluster_get_similar_name($cid, $characters = 100)
 240+{
 241+ if (!is_numeric($cid))
 242+ return array();
 243+
 244+ $sql = 'SELECT sort_name FROM civicrm_contact WHERE id = ' . $cid;
 245+ $res =& CRM_Core_DAO::executeQuery( $sql, CRM_Core_DAO::$_nullArray );
 246+ $row = $res->fetch();
 247+ $sort_name = $row['sort_name'];
 248+
 249+ $sql = 'SELECT id FROM civicrm_contact far WHERE sort_name LIKE "%1%%"';
 250+ $sort_name = substr($sort_name, 0, $characters);
 251+ $params = array(1 => array($sort_name, 'String'));
 252+ $res =& CRM_Core_DAO::executeQuery($sql, $params);
 253+
 254+ $ret = array();
 255+ while ($res->fetch())
 256+ {
 257+ $ret[] = $res->id;
 258+ }
 259+
 260+ //drupal_set_message(print_r($ret, TRUE));
 261+
 262+ return $ret;
 263+}
 264+
 265+function _civicluster_get_similar_location($cid, $table, $field)
 266+{
 267+ if (!is_numeric($cid))
 268+ return array();
 269+
 270+ $sql = 'SELECT farl.entity_id AS contact_id FROM civicrm_location farl ';
 271+ $sql .= 'INNER JOIN ' . $table . ' fara ON fara.location_id = farl.id ';
 272+ $sql .= 'INNER JOIN ' . $table . ' neara ON fara.' . $field . ' = neara.' . $field . ' ';
 273+ $sql .= 'INNER JOIN civicrm_location nearl ON neara.location_id = nearl.id ';
 274+ $sql .= 'WHERE farl.entity_table = "civicrm_contact" AND nearl.entity_table = "civicrm_contact" AND nearl.entity_id = ' . $cid;
 275+ //drupal_set_message($sql);
 276+ $res =& CRM_Core_DAO::executeQuery( $sql, CRM_Core_DAO::$_nullArray );
 277+ $ret = array();
 278+ while ($res->fetch())
 279+ {
 280+ $ret[] = $res->contact_id;
 281+ }
 282+
 283+ //drupal_set_message(print_r($ret, TRUE));
 284+ //echo 'Location ' . $table . '.' . $field . ':' . "\n";
 285+ //print_r($ret);
 286+
 287+ return $ret;
 288+}
 289+
 290+function _civicluster_update_scores($existing, $new, $points = 1)
 291+{
 292+ foreach ($new as $cid)
 293+ {
 294+ if (array_key_exists($cid, $existing))
 295+ {
 296+ $existing[$cid] += $points;
 297+ } else {
 298+ $existing[$cid] = $points;
 299+ }
 300+ }
 301+
 302+ return $existing;
 303+}
\ No newline at end of file

Status & tagging log