You are here

function ca_condition_node_field_comparison in Ubercart 6.2

Compare a node field to a specified value using an operator list.

See also

ca_condition_node_field_comparison_form()

1 string reference to 'ca_condition_node_field_comparison'
ca_ca_condition in ca/ca.ca.inc
Implements hook_ca_condition().

File

ca/ca.ca.inc, line 171
This file includes some generic conditions and actions.

Code

function ca_condition_node_field_comparison($node, $settings) {

  // Convert the node to an array.
  $node_array = (array) $node;

  // Store the value of the field we're comparing.
  $field_value = $node_array[$settings['field']];

  // Return the result based on the operator.
  switch ($settings['operator']) {
    case 'equal':
      if ($field_value == $settings['value']) {
        return TRUE;
      }
      break;
    case 'not':
      if ($field_value != $settings['value']) {
        return TRUE;
      }
      break;
    case 'greater':
      if ($field_value > $settings['value']) {
        return TRUE;
      }
      break;
    case 'less':
      if ($field_value < $settings['value']) {
        return TRUE;
      }
      break;
    case 'greater_equal':
      if ($field_value >= $settings['value']) {
        return TRUE;
      }
      break;
    case 'less_equal':
      if ($field_value <= $settings['value']) {
        return TRUE;
      }
      break;
    case 'begins':
      if (strpos($field_value, $settings['value']) === 0) {
        return TRUE;
      }
      break;
    case 'ends':
      if (substr($field_value, -1 * strlen($settings['value'])) === $settings['value']) {
        return TRUE;
      }
      break;
    case 'contains':
      if (strpos($field_value, $settings['value']) !== FALSE) {
        return TRUE;
      }
      break;
    case 'yes':
      if ($field_value) {
        return TRUE;
      }
      break;
    case 'no':
      if (!$field_value) {
        return TRUE;
      }
      break;
  }
  return FALSE;
}