/** * Return a set of SQL queries whose cummulative weights will mark matched * records for the RuleGroup::threasholdQuery() to retrieve. */ public function tableQuery() { // make sure we've got a fetched dbrecord, not sure if this is enforced if (!$this->name == NULL || $this->is_reserved == NULL) { $this->find(TRUE); } // Reserved Rule Groups can optionally get special treatment by // implementing an optimization class and returning a query array. if ($this->is_reserved && CRM_Utils_File::isIncludable("CRM/Dedupe/BAO/QueryBuilder/{$this->name}.php")) { include_once "CRM/Dedupe/BAO/QueryBuilder/{$this->name}.php"; $class = "CRM_Dedupe_BAO_QueryBuilder_{$this->name}"; $command = empty($this->params) ? 'internal' : 'record'; $queries = call_user_func(array($class, $command), $this); } else { // All other rule groups have queries generated by the member dedupe // rules defined in the administrative interface. // Find all rules contained by this script sorted by weight so that // their execution can be short circuited on RuleGroup::fillTable() $bao = new CRM_Dedupe_BAO_Rule(); $bao->dedupe_rule_group_id = $this->id; $bao->orderBy('rule_weight DESC'); $bao->find(); // Generate a SQL query for each rule in the rule group that is // tailored to respect the param and contactId options provided. $queries = array(); while ($bao->fetch()) { $bao->contactIds = $this->contactIds; $bao->params = $this->params; // Skipping empty rules? Empty rules shouldn't exist; why check? if ($query = $bao->sql()) { $queries["{$bao->rule_table}.{$bao->rule_field}.{$bao->rule_weight}"] = $query; } } } // if there are no rules in this rule group // add an empty query fulfilling the pattern if (!$queries) { $queries = array('SELECT 0 id1, 0 id2, 0 weight LIMIT 0'); $this->noRules = TRUE; } return $queries; }
/** * Return the SQL query for creating the temporary table. */ function tableQuery() { require_once 'CRM/Dedupe/BAO/Rule.php'; $bao = new CRM_Dedupe_BAO_Rule(); $bao->dedupe_rule_group_id = $this->id; $bao->orderBy('rule_weight DESC'); $bao->find(); $queries = array(); while ($bao->fetch()) { $bao->contactIds = $this->contactIds; $bao->params = $this->params; if ($query = $bao->sql()) { $queries["{$bao->rule_table}.{$bao->rule_field}.{$bao->rule_weight}"] = $query; } } // if there are no rules in this rule group, add an empty query fulfilling the pattern if (!$queries) { $queries = array('SELECT 0 id1, 0 id2, 0 weight LIMIT 0'); $this->noRules = true; } return $queries; }