CRM/Core add missing comment blocks (autogenerated)
[civicrm-core.git] / CRM / Dedupe / BAO / QueryBuilder / IndividualGeneral.php
CommitLineData
6a488035
TO
1<?php
2
3// TODO: How to handle NULL values/records?
4c6ce474
EM
4/**
5 * Class CRM_Dedupe_BAO_QueryBuilder_IndividualGeneral
6 */
6a488035
TO
7class CRM_Dedupe_BAO_QueryBuilder_IndividualGeneral extends CRM_Dedupe_BAO_QueryBuilder {
8 static function record($rg) {
9 $civicrm_contact = CRM_Utils_Array::value('civicrm_contact', $rg->params);
10 $civicrm_address = CRM_Utils_Array::value('civicrm_address', $rg->params);
11
12 // Since definitely have first and last name, escape them upfront.
13 $first_name = CRM_Core_DAO::escapeString(CRM_Utils_Array::value('first_name', $civicrm_contact, ''));
14 $last_name = CRM_Core_DAO::escapeString(CRM_Utils_Array::value('last_name', $civicrm_contact, ''));
15 $street_address = CRM_Core_DAO::escapeString(CRM_Utils_Array::value('street_address', $civicrm_address, ''));
16
17 $query = "
18 SELECT contact1.id id1, {$rg->threshold} as weight
19 FROM civicrm_contact AS contact1
20 JOIN civicrm_address AS address1 ON contact1.id=address1.contact_id
21 WHERE contact1.contact_type = 'Individual'
22 AND contact1.first_name = '$first_name'
23 AND contact1.last_name = '$last_name'
24 AND address1.street_address = '$street_address'
25 ";
26
27 if ($birth_date = CRM_Core_DAO::escapeString(CRM_Utils_Array::value('birth_date', $civicrm_contact, ''))) {
28 $query .= " AND (contact1.birth_date IS NULL or contact1.birth_date = '$birth_date')\n";
29 }
30
31 if ($suffix_id = CRM_Core_DAO::escapeString(CRM_Utils_Array::value('suffix_id', $civicrm_contact, ''))) {
32 $query .= " AND (contact1.suffix_id IS NULL or contact1.suffix_id = $suffix_id)\n";
33 }
34
35 if ($middle_name = CRM_Core_DAO::escapeString(CRM_Utils_Array::value('middle_name', $civicrm_contact, ''))) {
36 $query .= " AND (contact1.middle_name IS NULL or contact1.middle_name = '$middle_name')\n";
37 }
38
39 return array("civicrm_contact.{$rg->name}.{$rg->threshold}" => $query);
40 }
41
42 static function internal($rg) {
43 $query = "
44 SELECT contact1.id id1, contact2.id id2, {$rg->threshold} weight
45 FROM civicrm_contact AS contact1
46 JOIN civicrm_contact AS contact2 ON (
47 contact1.first_name = contact2.first_name AND
48 contact1.last_name = contact2.last_name AND
49 contact1.contact_type = contact2.contact_type)
50 JOIN civicrm_address AS address1 ON address1.contact_id = contact1.id
51 JOIN civicrm_address AS address2 ON (
52 address2.contact_id = contact2.id AND
53 address2.street_address = address1.street_address)
54 WHERE contact1.contact_type = 'Individual'
55 AND (contact1.suffix_id IS NULL OR contact2.suffix_id IS NULL OR contact1.suffix_id = contact2.suffix_id)
56 AND (contact1.middle_name IS NULL OR contact2.middle_name IS NULL OR contact1.middle_name = contact2.middle_name)
57 AND (contact1.birth_date IS NULL OR contact2.birth_date IS NULL OR contact1.birth_date = contact2.birth_date)
58 AND " . self::internalFilters($rg);
59 return array("civicrm_contact.{$rg->name}.{$rg->threshold}" => $query);
60 }
61}
62
63
64