crm_core-8.x-3.x-dev/modules/crm_core_match/src/Plugin/crm_core_match/field/DateFieldHandler.php
modules/crm_core_match/src/Plugin/crm_core_match/field/DateFieldHandler.php
<?php
namespace Drupal\crm_core_match\Plugin\crm_core_match\field;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\crm_core_contact\ContactInterface;
/**
* Class for evaluating date fields.
*/
class DateFieldHandler extends FieldHandlerBase {
use StringTranslationTrait;
/**
* {@inheritdoc}
*/
public function getOperators($property = 'value') {
$operators = [
'=' => $this->t('Equals'),
'>=' => $this->t('Greater than'),
'<=' => $this->t('Less than'),
];
return $operators;
}
/**
* {@inheritdoc}
*
* @todo Update to new query API.
*/
public function match(ContactInterface $contact, $property = 'value') {
$results = [];
$field_item = 'value';
$field = field_get_items('crm_core_contact', $contact, $rule->field_name);
$needle = $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;
}
}
/**
* Just extender of DateMatchField to catch field type.
*/
class DateTimeFieldHandler extends DateFieldHandler {
}
/**
* Just extender of DateMatchField to catch field type.
*/
class DateStampFieldHandler extends DateFieldHandler {
}
