You are here

class DefaultMatchingEngine in CRM Core 7

DefaultMatchingEngine class

Extends CrmCoreMatchEngine to provide rules for identifying duplicate contacts.

Hierarchy

Expanded class hierarchy of DefaultMatchingEngine

File

modules/crm_core_default_matching_engine/includes/DefaultMatchingEngine.inc, line 268

View source
class DefaultMatchingEngine extends CrmCoreMatchEngine {

  /**
   * Constructor: sets basic variables.
   */
  public function __construct() {
    $this->name = t('Default Matching Engine');
    $this->machineName = 'default_matching_engine';
    $description = 'This is a simple matching engine from CRM Core. Allows administrators to specify matching' . ' rules for individual contact types on a field-by-field basis.';
    $this->description = t($description);
    $this->settings = array(
      array(
        'name' => 'settings',
        'path' => 'admin/config/crm-core/match/default_match',
        'label' => t('Configuration'),
      ),
    );
  }

  /**
   * Applies logical rules for identifying matches in the database.
   *
   * Any matching engine should implement this to apply it's unique matching logic.
   * Variables are passed in by reference, so it's not necessary to return anything.
   * Accepts a list of matches and contact information to identify potential duplicates.
   *
   * @see CrmCoreMatchEngineInterface::execute()
   */
  public function execute(&$contact, &$ids = array()) {
    if ($this->status) {
      $base_config = crm_core_default_matching_engine_load_contact_type_config($contact->type);

      // Check if match is enabled for this contact type.
      if ($base_config['status']) {
        $matching_rules = crm_core_default_matching_engine_load_field_config($contact->type);
        $contact_fields = field_info_instances('crm_core_contact', $contact->type);
        $results = array();
        foreach ($matching_rules as $matching_rule) {
          if (isset($contact_fields[$matching_rule->field_name])) {
            $rule_matches = array();
            $field_match_handler_class = $matching_rule->field_type . 'MatchField';
            if (class_exists($field_match_handler_class)) {
              $field_match_handler = new $field_match_handler_class();
              $rule_matches = $field_match_handler
                ->fieldQuery($contact, $matching_rule);
            }
            foreach ($rule_matches as $matched_id) {
              $results[$matched_id][$matching_rule->mrid] = $matching_rule->score;
            }
          }
        }
        foreach ($results as $id => $rule_matches) {
          $total_score = array_sum($rule_matches);
          if ($total_score >= $base_config['threshold']) {
            $ids[] = $id;
          }
        }
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CrmCoreMatchEngine::$description protected property A short description of what the matching engine does.
CrmCoreMatchEngine::$eid protected property Engine ID.
CrmCoreMatchEngine::$machineName protected property The machine name used for the matching engine
CrmCoreMatchEngine::$name protected property The human readable name for the matching engine
CrmCoreMatchEngine::$settings protected property An array listing settings pages for the matching engine.
CrmCoreMatchEngine::$status protected property Engine status.
CrmCoreMatchEngine::$weight protected property Engine weight when applying matching.
CrmCoreMatchEngine::getDescription public function Returns engine description.
CrmCoreMatchEngine::getID public function Returns engine ID.
CrmCoreMatchEngine::getMachineName public function Returns engine machine readable name.
CrmCoreMatchEngine::getName public function Returns engine human readable name.
CrmCoreMatchEngine::getSettings public function Returns engine settings.
CrmCoreMatchEngine::getStatus public function Returns engine status.
CrmCoreMatchEngine::getWeight public function Returns engine weight.
CrmCoreMatchEngine::setID public function Set engine ID.
CrmCoreMatchEngine::setStatus public function Set engine status.
CrmCoreMatchEngine::setWeight public function Set engine weigth.
DefaultMatchingEngine::execute public function Applies logical rules for identifying matches in the database. Overrides CrmCoreMatchEngine::execute
DefaultMatchingEngine::__construct public function Constructor: sets basic variables. Overrides CrmCoreMatchEngine::__construct