Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add crm_core_match_testing_page() as an entity operation #17

Open
mbovan opened this issue Aug 11, 2015 · 0 comments
Open

Add crm_core_match_testing_page() as an entity operation #17

mbovan opened this issue Aug 11, 2015 · 0 comments

Comments

@mbovan
Copy link
Contributor

mbovan commented Aug 11, 2015

crm_core_match_testing_page() will be removed in #12.

From @Berdir's comment:

This could be a useful feature but should be re-introduced as an entity operation or so with an auto-complete to select a contact or something like that? Probably easier to drop and have a task/issue to add it again?

Here is the old code of crm_core_match.test.inc that has been removed.

<?php

/**
 * @file
 * Contains functionality for testing purposes.
 */

function crm_core_match_testing_page_title($contact) {
  return t('Matching Rules for @contact_name', array('@contact_name' => crm_core_contact_title($contact)));
}

/**
 * Page callback to display match debug info.
 *
 * @param object $contact
 *   CRM Core Contact.
 *
 * @return string
 */
function crm_core_match_testing_page($contact) {
  $output = '';
  $engines = crm_core_match_get_engines();

  // Display engines table.
  $rows = array();
  foreach ($engines as $engine) {
    if ($engine->getStatus()) {
      $rows[] = array(
        'data' => array(
          $engine->getID(),
          $engine->getName(),
          $engine->getDescription(),
          $engine->getMachineName(),
          $engine->getWeight(),
        ),
      );
    }
  }
  $header = array(
    t('Engine ID'),
    t('Engine name'),
    t('Engine description'),
    t('Engine machine name'),
    t('Weight'),
  );
  $output .= theme('table', array(
    'header' => $header,
    'rows' => $rows,
    'empty' => t('No matching engines enabled or associated with contacts of this type.'),
  ));

  foreach ($engines as $engine) {
    $matches = array();
    $engine->execute($contact, $matches);
  }

  if (empty($matches)) {
    $output .= '<h1>No matches currently available.</h1>';
  }
  else {
    $output .= '<h1>Matches:</h1>';

    // Display matched contacts table.
    $rows = array();
    $contacts = crm_core_contact_load_multiple($matches);
    foreach ($contacts as $matched_contact) {
      $uri = $matched_contact->uri();
      $link = l($matched_contact->label(), $uri['path']);
      $rows[] = array(
        'data' => array(
          $matched_contact->contact_id,
          $link,
        ),
      );
    }
    $header = array(
      t('Contact ID'),
      t('Contact Name'),
    );
    $output .= theme('table', array(
      'header' => $header,
      'rows' => $rows,
    ));
  }

  return $output;
}

function crm_core_match_info_page() {
  $output = '';
  $engines = crm_core_match_get_engines();

  // Display engines table.
  $rows = array();
  foreach ($engines as $engine) {
    if ($engine->getStatus()) {
      $rows[] = array(
        'data' => array(
          $engine->getID(),
          $engine->getName(),
          $engine->getDescription(),
          $engine->getMachineName(),
          $engine->getWeight(),
        ),
      );
    }
  }
  $header = array(
    t('Engine ID'),
    t('Engine name'),
    t('Engine description'),
    t('Engine machine name'),
    t('Weight'),
  );
  $output .= theme('table', array(
    'header' => $header,
    'rows' => $rows,
    'empty' => t('No matching engines enabled or associated with contacts of this type.'),
  ));

  if (module_exists('crm_core_default_matching_engine')) {
    $contact_types = crm_core_contact_types(TRUE);
    foreach (array_keys($contact_types) as $contact_type) {
      $rules = crm_core_default_matching_engine_load_field_config($contact_type);
      // Display rules table.
      $rows = array();
      foreach ($rules as $rule) {
        $rows[] = array(
          'data' => array(
            $rule->mrid,
            $rule->field_name,
            $rule->field_type,
            $rule->field_item,
            $rule->operator,
            $rule->options,
            $rule->score,
            $rule->weight,
          ),
        );
      }

      $header = array(
        t('Rule ID'),
        t('Field name'),
        t('Field type'),
        t('Field item'),
        t('Field operator'),
        t('Field options'),
        t('Field score'),
        t('Field weight'),
      );
      $output .= theme('table', array(
        'header' => $header,
        'caption' => t('Matching rules for @contact_type', array(
          '@contact_type' => $contact_types[$contact_type]->name)
        ),
        'rows' => $rows,
        'empty' => t('Matching is not enabled for this contact type.'),
      ));
    }
  }

  return $output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant