more tidy ups
[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, array());
19 $civicrm_email = CRM_Utils_Array::value('civicrm_email', $rg->params, array());
20
21 $params = array(
22 1 => array(CRM_Utils_Array::value('first_name', $civicrm_contact, ''), 'String'),
23 2 => array(CRM_Utils_Array::value('last_name', $civicrm_contact, ''), 'String'),
24 3 => array(CRM_Utils_Array::value('email', $civicrm_email, ''), 'String'),
25 );
26
27 return array(
28 "civicrm_contact.{$rg->name}.{$rg->threshold}" => CRM_Core_DAO::composeQuery("
29 SELECT contact.id as id1, {$rg->threshold} as weight
30 FROM civicrm_contact as contact
31 JOIN civicrm_email as email ON email.contact_id=contact.id
32 WHERE contact_type = 'Individual'
33 AND first_name = %1
34 AND last_name = %2
35 AND email = %3", $params, TRUE),
36 );
37 }
38
39 /**
40 * Internal - what do I do.
41 *
42 * @param object $rg
43 *
44 * @return array
45 */
46 public static function internal($rg) {
47 $query = "
48 SELECT contact1.id as id1, contact2.id as id2, {$rg->threshold} as weight
49 FROM civicrm_contact as contact1
50 JOIN civicrm_email as email1 ON email1.contact_id=contact1.id
51 JOIN civicrm_contact as contact2 ON
52 contact1.first_name = contact2.first_name AND
53 contact1.last_name = contact2.last_name
54 JOIN civicrm_email as email2 ON
55 email2.contact_id=contact2.id AND
56 email1.email=email2.email
57 WHERE contact1.contact_type = 'Individual'
58 AND " . self::internalFilters($rg);
59 return array("civicrm_contact.{$rg->name}.{$rg->threshold}" => $query);
60 }
61 }
62
63 ;