Merge pull request #14004 from mfb/set-utf8
[civicrm-core.git] / CRM / Dedupe / BAO / QueryBuilder / IndividualSupervised.php
1 <?php
2
3 /**
4 * TODO: How to handle NULL values/records?
5 * Class CRM_Dedupe_BAO_QueryBuilder_IndividualSupervised
6 */
7 class CRM_Dedupe_BAO_QueryBuilder_IndividualSupervised extends CRM_Dedupe_BAO_QueryBuilder {
8
9 /**
10 * Record - what do I do.
11 *
12 * @param object $rg
13 *
14 * @return array
15 */
16 public static function record($rg) {
17
18 $civicrm_contact = CRM_Utils_Array::value('civicrm_contact', $rg->params, []);
19 $civicrm_email = CRM_Utils_Array::value('civicrm_email', $rg->params, []);
20
21 $params = [
22 1 => [
23 CRM_Utils_Array::value('first_name', $civicrm_contact, ''),
24 'String',
25 ],
26 2 => [
27 CRM_Utils_Array::value('last_name', $civicrm_contact, ''),
28 'String',
29 ],
30 3 => [
31 CRM_Utils_Array::value('email', $civicrm_email, ''),
32 'String',
33 ],
34 ];
35
36 return [
37 "civicrm_contact.{$rg->name}.{$rg->threshold}" => CRM_Core_DAO::composeQuery("
38 SELECT contact.id as id1, {$rg->threshold} as weight
39 FROM civicrm_contact as contact
40 JOIN civicrm_email as email ON email.contact_id=contact.id
41 WHERE contact_type = 'Individual'
42 AND first_name = %1
43 AND last_name = %2
44 AND email = %3", $params, TRUE),
45 ];
46 }
47
48 /**
49 * Internal - what do I do.
50 *
51 * @param object $rg
52 *
53 * @return array
54 */
55 public static function internal($rg) {
56 $query = self::filterQueryByContactList($rg->contactIds, "
57 SELECT contact1.id as id1, contact2.id as id2, {$rg->threshold} as weight
58 FROM civicrm_contact as contact1
59 JOIN civicrm_email as email1 ON email1.contact_id=contact1.id
60 JOIN civicrm_contact as contact2 ON
61 contact1.first_name = contact2.first_name AND
62 contact1.last_name = contact2.last_name
63 JOIN civicrm_email as email2 ON
64 email2.contact_id=contact2.id AND
65 email1.email=email2.email
66 WHERE contact1.contact_type = 'Individual'");
67
68 return [
69 "civicrm_contact.{$rg->name}.{$rg->threshold}" => $query,
70 ];
71 }
72
73 }