You are here

class DateMatchField in CRM Core 7

Class for evaluating date fields.

Hierarchy

Expanded class hierarchy of DateMatchField

File

modules/crm_core_default_matching_engine/includes/DateMatchField.inc, line 11
Implementation of DefaultMatchingEngineFieldTypeInterface for date fields.

View source
class DateMatchField extends DefaultMatchingEngineFieldType {

  /**
   * Defines logical operators to use with this field.
   *
   * This operators would be interpreted in fieldQuery() method.
   *
   * @param array $field_info
   *   Array returned by field_info_field($field_name).
   *
   * @return array
   *   Assoc array of operators.
   */
  public function operators($field_info = NULL) {
    $operators = array(
      '=' => t('Equals'),
      '>=' => t('Greater than'),
      '<=' => t('Less than'),
    );
    return $operators;
  }

  /**
   * Field query to search matches.
   *
   * @param object $contact
   *   CRM Core contact entity.
   * @param object $rule
   *   Matching rule object.
   *
   * @return array
   *   Founded matches.
   */
  public function fieldQuery($contact, $rule) {
    $results = array();
    $field_item = 'value';
    $field = field_get_items('crm_core_contact', $contact, $rule->field_name);
    $needle = isset($field[0]['value']) ? $field[0]['value'] : '';
    if (!empty($needle)) {
      $query = new EntityFieldQuery();
      $query
        ->entityCondition('entity_type', 'crm_core_contact')
        ->entityCondition('bundle', $contact->type)
        ->entityCondition('entity_id', $contact->contact_id, '<>')
        ->fieldCondition($rule->field_name, $field_item, $needle, $rule->operator);
      $results = $query
        ->execute();
    }
    return isset($results['crm_core_contact']) ? array_keys($results['crm_core_contact']) : $results;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DateMatchField::fieldQuery public function Field query to search matches. Overrides DefaultMatchingEngineFieldType::fieldQuery
DateMatchField::operators public function Defines logical operators to use with this field. Overrides DefaultMatchingEngineFieldType::operators
DefaultMatchingEngineFieldType::fieldRender public function Template used to render fields matching rules configuration form. Overrides DefaultMatchingEngineFieldTypeInterface::fieldRender 4
DefaultMatchingEngineFieldType::WEIGHT_DELTA constant