Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
4c6ce474 EM |
2 | /** |
3 | * Class CRM_Dedupe_BAO_QueryBuilder | |
4 | */ | |
6a488035 | 5 | class CRM_Dedupe_BAO_QueryBuilder { |
e0ef6999 EM |
6 | /** |
7 | * @param $rg | |
8 | * @param string $strID1 | |
9 | * @param string $strID2 | |
10 | * | |
11 | * @return string | |
12 | */ | |
d58a19a1 | 13 | public static function internalFilters($rg, $strID1 = 'contact1.id', $strID2 = 'contact2.id') { |
6a488035 TO |
14 | // Add a contact id filter for dedupe by group requests and add logic |
15 | // to remove duplicate results with opposing orders, i.e. 1,2 and 2,1 | |
481a74f4 | 16 | if (!empty($rg->contactIds)) { |
d58a19a1 | 17 | $cids = implode(',', $rg->contactIds); |
6a488035 TO |
18 | return "($strID1 IN ($cids) AND ( $strID2 NOT IN ($cids) OR ($strID2 IN ($cids) AND $strID1 < $strID2) ))"; |
19 | } | |
20 | else { | |
21 | return "($strID1 < $strID2)"; | |
22 | } | |
23 | } | |
96025800 | 24 | |
c232f005 | 25 | /** |
26 | * If a contact list is specified then adjust the query to ensure one contact is in that list. | |
27 | * | |
28 | * Doing an OR join here will lead to a server-killing unindexed query. However, a union will | |
29 | * perform better. | |
30 | * | |
31 | * @param array $contactList | |
32 | * @param string $query | |
33 | * @param string $strID1 | |
34 | * @param string $strID2 | |
35 | * | |
36 | * @return string | |
37 | */ | |
38 | protected static function filterQueryByContactList(array $contactList, $query, $strID1 = 'contact1.id', $strID2 = 'contact2.id') { | |
39 | if (empty($contactList)) { | |
40 | return $query . " AND ($strID1 < $strID2)"; | |
41 | } | |
42 | $contactIDs = implode(',', $contactList); | |
43 | return "$query AND $strID1 IN ($contactIDs) AND $strID1 > $strID2 | |
44 | UNION $query AND $strID1 > $strID2 AND $strID2 IN ($contactIDs) AND $strID1 NOT IN ($contactIDs) | |
45 | "; | |
46 | ||
47 | } | |
48 | ||
353ffa53 | 49 | } |